# HG changeset patch # User Markus Mützel # Date 1675100163 -3600 # Node ID 7860fcc69082c27229496eb42b7d10c9ac51bae4 # Parent 0aa88d03fa50c33549de00e0881ed5c90a295925# Parent 17d568574e1cd86c8ea3c76d625a10c5e10b6406 maint: Merge stable to default. diff -r 17d568574e1c -r 7860fcc69082 .github/workflows/make.yaml --- a/.github/workflows/make.yaml Mon Jan 30 18:30:33 2023 +0100 +++ b/.github/workflows/make.yaml Mon Jan 30 18:36:03 2023 +0100 @@ -82,7 +82,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: @@ -245,7 +245,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? @@ -486,7 +486,7 @@ 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. @@ -733,7 +733,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 17d568574e1c -r 7860fcc69082 Makefile.am --- a/Makefile.am Mon Jan 30 18:30:33 2023 +0100 +++ b/Makefile.am Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 build-aux/mk-opts.pl --- a/build-aux/mk-opts.pl Mon Jan 30 18:30:33 2023 +0100 +++ b/build-aux/mk-opts.pl Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 build-aux/module.mk --- a/build-aux/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/build-aux/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 build-aux/stl_algo.h-fixed --- a/build-aux/stl_algo.h-fixed Mon Jan 30 18:30:33 2023 +0100 +++ /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 17d568574e1c -r 7860fcc69082 build-aux/subst-config-vals.in.sh --- a/build-aux/subst-config-vals.in.sh Mon Jan 30 18:30:33 2023 +0100 +++ b/build-aux/subst-config-vals.in.sh Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 build-aux/subst-cross-config-vals.in.sh --- a/build-aux/subst-cross-config-vals.in.sh Mon Jan 30 18:30:33 2023 +0100 +++ b/build-aux/subst-cross-config-vals.in.sh Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 configure.ac --- a/configure.ac Mon Jan 30 18:30:33 2023 +0100 +++ b/configure.ac Mon Jan 30 18:36:03 2023 +0100 @@ -27,7 +27,7 @@ ### Initialize Autoconf AC_PREREQ([2.65]) -AC_INIT([GNU Octave], [8.0.91], [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_MAJOR_VERSION=9 OCTAVE_MINOR_VERSION=0 -OCTAVE_PATCH_VERSION=91 +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. @@ -2672,7 +2662,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." @@ -3037,8 +3027,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" @@ -3283,7 +3273,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 17d568574e1c -r 7860fcc69082 doc/interpreter/contributors.in --- a/doc/interpreter/contributors.in Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/contributors.in Mon Jan 30 18:36:03 2023 +0100 @@ -101,6 +101,7 @@ Massimiliano Fasi Stephen Fegan Ramon Garcia Fernandez +Kasper H. Filtenborg Torsten Finke David Finkel Guillaume Flandin diff -r 17d568574e1c -r 7860fcc69082 doc/interpreter/external.txi --- a/doc/interpreter/external.txi Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/external.txi Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 doc/interpreter/geometryimages.m --- a/doc/interpreter/geometryimages.m Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/geometryimages.m Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 doc/interpreter/interpimages.m --- a/doc/interpreter/interpimages.m Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/interpimages.m Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 doc/interpreter/linalg.txi --- a/doc/interpreter/linalg.txi Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/linalg.txi Mon Jan 30 18:36:03 2023 +0100 @@ -211,6 +211,8 @@ @DOCSTRING(kron) +@DOCSTRING(tensorprod) + @DOCSTRING(blkmm) @DOCSTRING(sylvester) diff -r 17d568574e1c -r 7860fcc69082 doc/interpreter/module.mk --- a/doc/interpreter/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 doc/interpreter/plotimages.m --- a/doc/interpreter/plotimages.m Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/plotimages.m Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 doc/interpreter/sparseimages.m --- a/doc/interpreter/sparseimages.m Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/sparseimages.m Mon Jan 30 18:36:03 2023 +0100 @@ -256,8 +256,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 17d568574e1c -r 7860fcc69082 doc/interpreter/splineimages.m --- a/doc/interpreter/splineimages.m Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/interpreter/splineimages.m Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 doc/liboctave/range.texi --- a/doc/liboctave/range.texi Mon Jan 30 18:30:33 2023 +0100 +++ b/doc/liboctave/range.texi Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 etc/NEWS.8.md diff -r 17d568574e1c -r 7860fcc69082 etc/NEWS.9.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/etc/NEWS.9.md Mon Jan 30 18:36:03 2023 +0100 @@ -0,0 +1,93 @@ +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. + +### Graphical User Interface + +### Graphics backend + +### Matlab compatibility + +### Alphabetical list of new functions added in Octave 9 + +* `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 + -----------------|-------------|------------ + +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 was removed from 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. + +### 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 17d568574e1c -r 7860fcc69082 etc/module.mk --- a/etc/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/etc/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 examples/code/embedded.cc --- a/examples/code/embedded.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/examples/code/embedded.cc Mon Jan 30 18:36:03 2023 +0100 @@ -5,7 +5,7 @@ #include int -main (void) +main () { // Create interpreter. diff -r 17d568574e1c -r 7860fcc69082 examples/code/make_int.cc --- a/examples/code/make_int.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/examples/code/make_int.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - octave_integer (void) + octave_integer () : octave_base_dld_value (), scalar (0) { } octave_integer (int i) @@ -46,9 +46,9 @@ octave_integer (const octave_integer& s) : octave_base_dld_value (), scalar (s.scalar) { } - ~octave_integer (void) = default; + ~octave_integer () = default; - octave_base_value * clone (void) { return new octave_integer (*this); } + octave_base_value * clone () { return new octave_integer (*this); } #if 0 void *operator new (std::size_t size); @@ -58,28 +58,28 @@ 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 +92,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 17d568574e1c -r 7860fcc69082 examples/code/standalone.cc --- a/examples/code/standalone.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/examples/code/standalone.cc Mon Jan 30 18:36:03 2023 +0100 @@ -2,7 +2,7 @@ #include int -main (void) +main () { std::cout << "Hello Octave world!\n"; diff -r 17d568574e1c -r 7860fcc69082 examples/code/standalonebuiltin.cc --- a/examples/code/standalonebuiltin.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/examples/code/standalonebuiltin.cc Mon Jan 30 18:36:03 2023 +0100 @@ -3,7 +3,7 @@ #include int -main (void) +main () { int n = 2; Matrix a_matrix = Matrix (n, n); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/BaseControl.cc --- a/libgui/graphics/BaseControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/BaseControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -41,302 +41,301 @@ OCTAVE_BEGIN_NAMESPACE(octave) -static void -updatePalette (const uicontrol::properties& props, QWidget *w) -{ - QPalette p = w->palette (); + static void + updatePalette (const uicontrol::properties& props, QWidget *w) + { + QPalette p = w->palette (); - if (props.style_is ("edit") - || props.style_is ("listbox")) - { - Matrix bg_color = props.get_backgroundcolor_rgb (); - // Matlab compatibility: Default color is ignored, and rendered as - // white ([1.0, 1.0, 1.0]). See bug #58261. - if (bg_color(0) == bg_color(1) && bg_color(0) == bg_color(2) - && (std::abs (bg_color(1) - 0.94) < .005)) - bg_color.fill (1.0); + if (props.style_is ("edit") + || props.style_is ("listbox")) + { + Matrix bg_color = props.get_backgroundcolor_rgb (); + // Matlab compatibility: Default color is ignored, and rendered as + // white ([1.0, 1.0, 1.0]). See bug #58261. + if (bg_color(0) == bg_color(1) && bg_color(0) == bg_color(2) + && (std::abs (bg_color(1) - 0.94) < .005)) + bg_color.fill (1.0); - p.setColor (QPalette::Active, QPalette::Base, - Utils::fromRgb (bg_color)); - p.setColor (QPalette::Inactive, QPalette::Base, - Utils::fromRgb (bg_color)); - p.setColor (QPalette::Active, QPalette::Text, - Utils::fromRgb (props.get_foregroundcolor_rgb ())); - p.setColor (QPalette::Inactive, QPalette::Text, - Utils::fromRgb (props.get_foregroundcolor_rgb ())); - } - else if (props.style_is ("popupmenu")) - { - // popupmenu (QComboBox) is a listbox with a button. - // This requires setting colors for both. - 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 ()); - w->setStyleSheet(qss); - return; - } - else if (props.style_is ("radiobutton") - || props.style_is ("checkbox")) - { - p.setColor (QPalette::Active, QPalette::Button, - Utils::fromRgb (props.get_backgroundcolor_rgb ())); - p.setColor (QPalette::Inactive, QPalette::Button, - Utils::fromRgb (props.get_backgroundcolor_rgb ())); - p.setColor (QPalette::Active, QPalette::WindowText, - Utils::fromRgb (props.get_foregroundcolor_rgb ())); - p.setColor (QPalette::Inactive, QPalette::WindowText, - Utils::fromRgb (props.get_foregroundcolor_rgb ())); - } - else if (props.style_is ("pushbutton") - || props.style_is ("togglebutton")) - { - 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 ()); - w->setStyleSheet(qss); - return; - } - else - { - p.setColor (QPalette::Active, QPalette::Window, - Utils::fromRgb (props.get_backgroundcolor_rgb ())); - p.setColor (QPalette::Inactive, QPalette::Window, - Utils::fromRgb (props.get_backgroundcolor_rgb ())); - p.setColor (QPalette::Active, QPalette::WindowText, - Utils::fromRgb (props.get_foregroundcolor_rgb ())); - p.setColor (QPalette::Inactive, QPalette::WindowText, - Utils::fromRgb (props.get_foregroundcolor_rgb ())); - } + p.setColor (QPalette::Active, QPalette::Base, + Utils::fromRgb (bg_color)); + p.setColor (QPalette::Inactive, QPalette::Base, + Utils::fromRgb (bg_color)); + p.setColor (QPalette::Active, QPalette::Text, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::Text, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + } + else if (props.style_is ("popupmenu")) + { + // popupmenu (QComboBox) is a listbox with a button. + // This requires setting colors for both. + 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 ()); + w->setStyleSheet(qss); + return; + } + else if (props.style_is ("radiobutton") + || props.style_is ("checkbox")) + { + p.setColor (QPalette::Active, QPalette::Button, + Utils::fromRgb (props.get_backgroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::Button, + Utils::fromRgb (props.get_backgroundcolor_rgb ())); + p.setColor (QPalette::Active, QPalette::WindowText, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::WindowText, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + } + else if (props.style_is ("pushbutton") + || props.style_is ("togglebutton")) + { + 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 ()); + w->setStyleSheet(qss); + return; + } + else + { + p.setColor (QPalette::Active, QPalette::Window, + Utils::fromRgb (props.get_backgroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::Window, + Utils::fromRgb (props.get_backgroundcolor_rgb ())); + p.setColor (QPalette::Active, QPalette::WindowText, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::WindowText, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + } - w->setPalette (p); -} + w->setPalette (p); + } -BaseControl::BaseControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, QWidget *w) - : Object (oct_qobj, interp, go, w), m_normalizedFont (false), - m_keyPressHandlerDefined (false) -{ - qObject ()->setObjectName ("UIControl"); - init (w); -} - -void -BaseControl::init (QWidget *w, bool callBase) -{ - if (callBase) - Object::init (w, callBase); - - uicontrol::properties& up = properties (); + BaseControl::BaseControl (octave::interpreter& interp, + const graphics_object& go, QWidget *w) + : Object (interp, go, w), m_normalizedFont (false), + m_keyPressHandlerDefined (false) + { + qObject ()->setObjectName ("UIControl"); + init (w); + } - Matrix bb = up.get_boundingbox (false); - w->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), - octave::math::round (bb(2)), octave::math::round (bb(3))); - w->setFont (Utils::computeFont (up, bb(3))); - updatePalette (up, w); - if (up.enable_is ("inactive")) - w->blockSignals (true); - else - w->setEnabled (up.enable_is ("on")); - w->setToolTip (Utils::fromStdString (up.get_tooltipstring ())); - w->setVisible (up.is_visible ()); - m_keyPressHandlerDefined = ! up.get_keypressfcn ().isempty (); + void + BaseControl::init (QWidget *w, bool callBase) + { + if (callBase) + Object::init (w, callBase); - w->installEventFilter (this); + uicontrol::properties& up = properties (); - m_normalizedFont = up.fontunits_is ("normalized"); -} - -BaseControl::~BaseControl (void) -{ } - -void -BaseControl::redraw (void) -{ - update (uicontrol::properties::ID_POSITION); -} - -void -BaseControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QWidget *w = qWidget (); + Matrix bb = up.get_boundingbox (false); + w->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), + octave::math::round (bb(2)), octave::math::round (bb(3))); + w->setFont (Utils::computeFont (up, bb(3))); + updatePalette (up, w); + if (up.enable_is ("inactive")) + w->blockSignals (true); + else + w->setEnabled (up.enable_is ("on")); + w->setToolTip (Utils::fromStdString (up.get_tooltipstring ())); + w->setVisible (up.is_visible ()); + m_keyPressHandlerDefined = ! up.get_keypressfcn ().isempty (); - switch (pId) - { - case uicontrol::properties::ID_POSITION: - { - Matrix bb = up.get_boundingbox (false); - w->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), - octave::math::round (bb(2)), octave::math::round (bb(3))); - } - break; + w->installEventFilter (this); + + m_normalizedFont = up.fontunits_is ("normalized"); + } + + BaseControl::~BaseControl () + { } - case uicontrol::properties::ID_FONTNAME: - case uicontrol::properties::ID_FONTSIZE: - case uicontrol::properties::ID_FONTWEIGHT: - case uicontrol::properties::ID_FONTANGLE: - w->setFont (Utils::computeFont (up)); - break; + void + BaseControl::redraw () + { + update (uicontrol::properties::ID_POSITION); + } - case uicontrol::properties::ID_FONTUNITS: - // FIXME: We shouldn't have to do anything, octave should update - // the "fontsize" property automatically to the new units. - // Hence the actual font used shouldn't change. - m_normalizedFont = up.fontunits_is ("normalized"); - break; - - case uicontrol::properties::ID_BACKGROUNDCOLOR: - case uicontrol::properties::ID_FOREGROUNDCOLOR: - updatePalette (up, w); - break; + void + BaseControl::update (int pId) + { + uicontrol::properties& up = properties (); + QWidget *w = qWidget (); - case uicontrol::properties::ID_ENABLE: - if (up.enable_is ("inactive")) + switch (pId) + { + case uicontrol::properties::ID_POSITION: { - w->blockSignals (true); - w->setEnabled (true); + Matrix bb = up.get_boundingbox (false); + w->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), + octave::math::round (bb(2)), octave::math::round (bb(3))); } - else - { - w->blockSignals (false); - w->setEnabled (up.enable_is ("on")); - } - break; + break; - case uicontrol::properties::ID_TOOLTIPSTRING: - w->setToolTip (Utils::fromStdString (up.get_tooltipstring ())); - break; - - case base_properties::ID_VISIBLE: - w->setVisible (up.is_visible ()); - break; + case uicontrol::properties::ID_FONTNAME: + case uicontrol::properties::ID_FONTSIZE: + case uicontrol::properties::ID_FONTWEIGHT: + case uicontrol::properties::ID_FONTANGLE: + w->setFont (Utils::computeFont (up)); + break; - case uicontrol::properties::ID_KEYPRESSFCN: - m_keyPressHandlerDefined = ! up.get_keypressfcn ().isempty (); - break; + case uicontrol::properties::ID_FONTUNITS: + // FIXME: We shouldn't have to do anything, octave should update + // the "fontsize" property automatically to the new units. + // Hence the actual font used shouldn't change. + m_normalizedFont = up.fontunits_is ("normalized"); + break; - case uicontrol::properties::ID___FOCUS__: - if (up.is___focus__ ()) - w->setFocus (); - else - w->clearFocus (); - break; + case uicontrol::properties::ID_BACKGROUNDCOLOR: + case uicontrol::properties::ID_FOREGROUNDCOLOR: + updatePalette (up, w); + break; - default: - break; - } -} - -bool -BaseControl::eventFilter (QObject *watched, QEvent *xevent) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - switch (xevent->type ()) - { - case QEvent::Resize: - if (m_normalizedFont) - { - octave::autolock guard (gh_mgr.graphics_lock ()); - - qWidget ()->setFont (Utils::computeFont - (properties ())); - } - break; - - case QEvent::MouseButtonPress: - { - octave::autolock guard (gh_mgr.graphics_lock ()); - - QMouseEvent *m = dynamic_cast (xevent); - graphics_object go = object (); - uicontrol::properties& up = Utils::properties (go); - graphics_object fig = go.get_ancestor ("figure"); - if (fig) + case uicontrol::properties::ID_ENABLE: + if (up.enable_is ("inactive")) + { + w->blockSignals (true); + w->setEnabled (true); + } + else { - emit gh_set_event (fig.get_handle (), "currentobject", - m_handle.value (), false); + w->blockSignals (false); + w->setEnabled (up.enable_is ("on")); + } + break; + + case uicontrol::properties::ID_TOOLTIPSTRING: + w->setToolTip (Utils::fromStdString (up.get_tooltipstring ())); + break; - if (m->button () != Qt::LeftButton || ! up.enable_is ("on")) - { - emit gh_set_event (fig.get_handle (), "selectiontype", - Utils::figureSelectionType (m), false); - emit gh_set_event (fig.get_handle (), "currentpoint", - Utils::figureCurrentPoint (fig, m), - false); - emit gh_callback_event (fig.get_handle (), - "windowbuttondownfcn"); - emit gh_callback_event (m_handle, "buttondownfcn"); + case base_properties::ID_VISIBLE: + w->setVisible (up.is_visible ()); + break; + + case uicontrol::properties::ID_KEYPRESSFCN: + m_keyPressHandlerDefined = ! up.get_keypressfcn ().isempty (); + break; + + case uicontrol::properties::ID___FOCUS__: + if (up.is___focus__ ()) + w->setFocus (); + else + w->clearFocus (); + break; - if (m->button () == Qt::RightButton) - ContextMenu::executeAt (m_interpreter, up, m->globalPos ()); - } - else - { - if (up.style_is ("listbox")) - emit gh_set_event (fig.get_handle (), "selectiontype", - Utils::figureSelectionType (m), - false); - else - emit gh_set_event (fig.get_handle (), "selectiontype", - octave_value ("normal"), false); - } + default: + break; + } + } + + bool + BaseControl::eventFilter (QObject *watched, QEvent *xevent) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + switch (xevent->type ()) + { + case QEvent::Resize: + if (m_normalizedFont) + { + octave::autolock guard (gh_mgr.graphics_lock ()); + + qWidget ()->setFont (Utils::computeFont + (properties ())); } - } - break; + break; - case QEvent::MouseMove: - if (qWidget ()->hasMouseTracking ()) + case QEvent::MouseButtonPress: { octave::autolock guard (gh_mgr.graphics_lock ()); QMouseEvent *m = dynamic_cast (xevent); graphics_object go = object (); + uicontrol::properties& up = Utils::properties (go); graphics_object fig = go.get_ancestor ("figure"); - if (fig) { - emit gh_set_event (fig.get_handle (), "currentpoint", - Utils::figureCurrentPoint (fig, m), false); - emit gh_callback_event (fig.get_handle (), - "windowbuttonmotionfcn"); + emit gh_set_event (fig.get_handle (), "currentobject", + m_handle.value (), false); + + if (m->button () != Qt::LeftButton || ! up.enable_is ("on")) + { + emit gh_set_event (fig.get_handle (), "selectiontype", + Utils::figureSelectionType (m), false); + emit gh_set_event (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig, m), + false); + emit gh_callback_event (fig.get_handle (), + "windowbuttondownfcn"); + emit gh_callback_event (m_handle, "buttondownfcn"); + + if (m->button () == Qt::RightButton) + ContextMenu::executeAt (m_interpreter, up, m->globalPos ()); + } + else + { + if (up.style_is ("listbox")) + emit gh_set_event (fig.get_handle (), "selectiontype", + Utils::figureSelectionType (m), + false); + else + emit gh_set_event (fig.get_handle (), "selectiontype", + octave_value ("normal"), false); + } } } - break; + break; + + case QEvent::MouseMove: + if (qWidget ()->hasMouseTracking ()) + { + octave::autolock guard (gh_mgr.graphics_lock ()); - case QEvent::KeyPress: - if (m_keyPressHandlerDefined) - { - octave::autolock guard (gh_mgr.graphics_lock ()); + QMouseEvent *m = dynamic_cast (xevent); + graphics_object go = object (); + graphics_object fig = go.get_ancestor ("figure"); - octave_scalar_map keyData = - Utils::makeKeyEventStruct (dynamic_cast (xevent)); - graphics_object fig = object ().get_ancestor ("figure"); + if (fig) + { + emit gh_set_event (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig, m), false); + emit gh_callback_event (fig.get_handle (), + "windowbuttonmotionfcn"); + } + } + break; - emit gh_set_event (fig.get_handle (), "currentcharacter", - keyData.getfield ("Character"), false); - emit gh_callback_event (m_handle, "keypressfcn", keyData); - } - break; + case QEvent::KeyPress: + if (m_keyPressHandlerDefined) + { + octave::autolock guard (gh_mgr.graphics_lock ()); - case QEvent::FocusIn: - emit gh_set_event (m_handle, "__focus__", "on", false); - break; + octave_scalar_map keyData = + Utils::makeKeyEventStruct (dynamic_cast (xevent)); + graphics_object fig = object ().get_ancestor ("figure"); + + emit gh_set_event (fig.get_handle (), "currentcharacter", + keyData.getfield ("Character"), false); + emit gh_callback_event (m_handle, "keypressfcn", keyData); + } + break; - case QEvent::FocusOut: - emit gh_set_event (m_handle, "__focus__", "off", false); - break; + case QEvent::FocusIn: + emit gh_set_event (m_handle, "__focus__", "on", false); + break; - default: - break; - } + case QEvent::FocusOut: + emit gh_set_event (m_handle, "__focus__", "off", false); + break; - return Object::eventFilter (watched, xevent); -} + default: + break; + } + + return Object::eventFilter (watched, xevent); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/BaseControl.h --- a/libgui/graphics/BaseControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/BaseControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,29 +33,28 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class BaseControl : public Object -{ -public: - BaseControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QWidget *w); - ~BaseControl (void); + class BaseControl : public Object + { + public: + BaseControl (octave::interpreter& interp, + const graphics_object& go, QWidget *w); + ~BaseControl (); - Container * innerContainer (void) { return nullptr; } + Container * innerContainer () { return nullptr; } - bool eventFilter (QObject *watched, QEvent *e); + bool eventFilter (QObject *watched, QEvent *e); -protected: - void init (QWidget *w, bool callBase = false); - void redraw (void); - void update (int pId); + protected: + void init (QWidget *w, bool callBase = false); + void redraw (); + void update (int pId); -private: - bool m_normalizedFont; - bool m_keyPressHandlerDefined; -}; + private: + bool m_normalizedFont; + bool m_keyPressHandlerDefined; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ButtonControl.cc --- a/libgui/graphics/ButtonControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ButtonControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,117 +39,116 @@ OCTAVE_BEGIN_NAMESPACE(octave) -ButtonControl::ButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, - QAbstractButton *btn) -: BaseControl (oct_qobj, interp, go, btn), m_blockCallback (false) -{ - uicontrol::properties& up = properties (); - - QString str = Utils::fromStdString (up.get_string_string ()); - str.replace ("&", "&&"); - btn->setText (str); - if (btn->isCheckable () || up.style_is ("togglebutton")) - { - btn->setCheckable (true); - - Matrix value = up.get_value ().matrix_value (); - - if (value.numel () > 0 && value(0) == up.get_max ()) - btn->setChecked (true); - } + ButtonControl::ButtonControl (octave::interpreter& interp, + const graphics_object& go, + QAbstractButton *btn) + : BaseControl (interp, go, btn), m_blockCallback (false) + { + uicontrol::properties& up = properties (); - connect (btn, &QAbstractButton::clicked, this, &ButtonControl::clicked); - connect (btn, &QAbstractButton::toggled, this, &ButtonControl::toggled); -} - -ButtonControl::~ButtonControl (void) -{ } + QString str = Utils::fromStdString (up.get_string_string ()); + str.replace ("&", "&&"); + btn->setText (str); + if (btn->isCheckable () || up.style_is ("togglebutton")) + { + btn->setCheckable (true); -void -ButtonControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QAbstractButton *btn = qWidget (); + Matrix value = up.get_value ().matrix_value (); - switch (pId) - { - case uicontrol::properties::ID_STRING: - { - QString str = Utils::fromStdString (up.get_string_string ()); - str.replace ("&", "&&"); - btn->setText (str); - break; + if (value.numel () > 0 && value(0) == up.get_max ()) + btn->setChecked (true); } - case uicontrol::properties::ID_VALUE: - m_blockCallback = true; - if (btn->isCheckable ()) - { - Matrix value = up.get_value ().matrix_value (); + connect (btn, &QAbstractButton::clicked, this, &ButtonControl::clicked); + connect (btn, &QAbstractButton::toggled, this, &ButtonControl::toggled); + } - if (value.numel () > 0) - { - double dValue = value(0); + ButtonControl::~ButtonControl () + { } + + void + ButtonControl::update (int pId) + { + uicontrol::properties& up = properties (); + QAbstractButton *btn = qWidget (); - if (dValue != 0.0 && dValue != 1.0) - warning ("button value not within valid display range"); - else if (dValue == up.get_min () && btn->isChecked ()) - { - btn->setChecked (false); - if (up.style_is ("radiobutton") || up.style_is ("togglebutton")) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + switch (pId) + { + case uicontrol::properties::ID_STRING: + { + QString str = Utils::fromStdString (up.get_string_string ()); + str.replace ("&", "&&"); + btn->setText (str); + break; + } - Object *parent = Object::parentObject (m_interpreter, gh_mgr.get_object (up.get___myhandle__ ())); - ButtonGroup *btnGroup = dynamic_cast(parent); - if (btnGroup) - btnGroup->selectNothing (); - } - } - else if (dValue == up.get_max () && ! btn->isChecked ()) - btn->setChecked (true); - } - } - m_blockCallback = false; - break; + case uicontrol::properties::ID_VALUE: + m_blockCallback = true; + if (btn->isCheckable ()) + { + Matrix value = up.get_value ().matrix_value (); + + if (value.numel () > 0) + { + double dValue = value(0); + + if (dValue != 0.0 && dValue != 1.0) + warning ("button value not within valid display range"); + else if (dValue == up.get_min () && btn->isChecked ()) + { + btn->setChecked (false); + if (up.style_is ("radiobutton") || up.style_is ("togglebutton")) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - default: - BaseControl::update (pId); - break; - } -} + Object *parent = Object::parentObject (m_interpreter, gh_mgr.get_object (up.get___myhandle__ ())); + ButtonGroup *btnGroup = dynamic_cast(parent); + if (btnGroup) + btnGroup->selectNothing (); + } + } + else if (dValue == up.get_max () && ! btn->isChecked ()) + btn->setChecked (true); + } + } + m_blockCallback = false; + break; -void -ButtonControl::toggled (bool checked) -{ - QAbstractButton *btn = qWidget (); + default: + BaseControl::update (pId); + break; + } + } - if (! m_blockCallback && btn->isCheckable ()) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); + void + ButtonControl::toggled (bool checked) + { + QAbstractButton *btn = qWidget (); - uicontrol::properties& up = properties (); + if (! m_blockCallback && btn->isCheckable ()) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + uicontrol::properties& up = properties (); + + Matrix oldValue = up.get_value ().matrix_value (); + double newValue = (checked ? up.get_max () : up.get_min ()); - Matrix oldValue = up.get_value ().matrix_value (); - double newValue = (checked ? up.get_max () : up.get_min ()); + if (oldValue.numel () != 1 || (newValue != oldValue(0))) + emit gh_set_event (m_handle, "value", newValue, false); + emit gh_callback_event (m_handle, "callback"); + } + } - if (oldValue.numel () != 1 || (newValue != oldValue(0))) - emit gh_set_event (m_handle, "value", newValue, false); + void + ButtonControl::clicked () + { + QAbstractButton *btn = qWidget (); + + if (! btn->isCheckable ()) emit gh_callback_event (m_handle, "callback"); - } -} - -void -ButtonControl::clicked (void) -{ - QAbstractButton *btn = qWidget (); - - if (! btn->isCheckable ()) - emit gh_callback_event (m_handle, "callback"); -} + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ButtonControl.h --- a/libgui/graphics/ButtonControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ButtonControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,28 +32,27 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class ButtonControl : public BaseControl -{ - Q_OBJECT + class ButtonControl : public BaseControl + { + Q_OBJECT + + public: + ButtonControl (octave::interpreter& interp, + const graphics_object& go, QAbstractButton *btn); + ~ButtonControl (); -public: - ButtonControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QAbstractButton *btn); - ~ButtonControl (void); - -protected: - void update (int pId); + protected: + void update (int pId); -private slots: - void clicked (void); - void toggled (bool checked); + private slots: + void clicked (); + void toggled (bool checked); -private: - bool m_blockCallback; -}; + private: + bool m_blockCallback; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ButtonGroup.cc --- a/libgui/graphics/ButtonGroup.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ButtonGroup.cc Mon Jan 30 18:36:03 2023 +0100 @@ -45,487 +45,482 @@ #include "QtHandlesUtils.h" #include "qt-graphics-toolkit.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" - #include "interpreter.h" #include "oct-map.h" OCTAVE_BEGIN_NAMESPACE(octave) -static int -frameStyleFromProperties (const uibuttongroup::properties& pp) -{ - if (pp.bordertype_is ("none")) - return QFrame::NoFrame; - else if (pp.bordertype_is ("etchedin")) - return (QFrame::Box | QFrame::Sunken); - else if (pp.bordertype_is ("etchedout")) - return (QFrame::Box | QFrame::Raised); - else if (pp.bordertype_is ("beveledin")) - return (QFrame::Panel | QFrame::Sunken); - else if (pp.bordertype_is ("beveledout")) - return (QFrame::Panel | QFrame::Raised); - else - return (QFrame::Panel | QFrame::Plain); -} + static int + frameStyleFromProperties (const uibuttongroup::properties& pp) + { + if (pp.bordertype_is ("none")) + return QFrame::NoFrame; + else if (pp.bordertype_is ("etchedin")) + return (QFrame::Box | QFrame::Sunken); + else if (pp.bordertype_is ("etchedout")) + return (QFrame::Box | QFrame::Raised); + else if (pp.bordertype_is ("beveledin")) + return (QFrame::Panel | QFrame::Sunken); + else if (pp.bordertype_is ("beveledout")) + return (QFrame::Panel | QFrame::Raised); + else + return (QFrame::Panel | QFrame::Plain); + } -static void -setupPalette (const uibuttongroup::properties& pp, QPalette& p) -{ - p.setColor (QPalette::Window, - Utils::fromRgb (pp.get_backgroundcolor_rgb ())); - p.setColor (QPalette::WindowText, - Utils::fromRgb (pp.get_foregroundcolor_rgb ())); - p.setColor (QPalette::Light, - Utils::fromRgb (pp.get_highlightcolor_rgb ())); - p.setColor (QPalette::Dark, - Utils::fromRgb (pp.get_shadowcolor_rgb ())); -} + static void + setupPalette (const uibuttongroup::properties& pp, QPalette& p) + { + p.setColor (QPalette::Window, + Utils::fromRgb (pp.get_backgroundcolor_rgb ())); + p.setColor (QPalette::WindowText, + Utils::fromRgb (pp.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Light, + Utils::fromRgb (pp.get_highlightcolor_rgb ())); + p.setColor (QPalette::Dark, + Utils::fromRgb (pp.get_shadowcolor_rgb ())); + } -static int -borderWidthFromProperties (const uibuttongroup::properties& pp) -{ - int bw = 0; + static int + borderWidthFromProperties (const uibuttongroup::properties& pp) + { + int bw = 0; - if (! pp.bordertype_is ("none")) - { - bw = octave::math::round (pp.get_borderwidth ()); - if (pp.bordertype_is ("etchedin") || pp.bordertype_is ("etchedout")) - bw *= 2; - } + if (! pp.bordertype_is ("none")) + { + bw = octave::math::round (pp.get_borderwidth ()); + if (pp.bordertype_is ("etchedin") || pp.bordertype_is ("etchedout")) + bw *= 2; + } - return bw; -} + return bw; + } -ButtonGroup * -ButtonGroup::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + ButtonGroup * + ButtonGroup::create (octave::interpreter& interp, const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - { - QFrame *frame = new QFrame (container); - return new ButtonGroup (oct_qobj, interp, go, - new QButtonGroup (frame), frame); - } - } + if (container) + { + QFrame *frame = new QFrame (container); + return new ButtonGroup (interp, go, + new QButtonGroup (frame), frame); + } + } - return nullptr; -} + return nullptr; + } -ButtonGroup::ButtonGroup (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, - QButtonGroup *buttongroup, QFrame *frame) - : Object (oct_qobj, interp, go, frame), m_hiddenbutton (nullptr), - m_container (nullptr), m_title (nullptr), m_blockUpdates (false) -{ - uibuttongroup::properties& pp = properties (); + ButtonGroup::ButtonGroup (octave::interpreter& interp, + const graphics_object& go, + QButtonGroup *buttongroup, QFrame *frame) + : Object (interp, go, frame), m_hiddenbutton (nullptr), + m_container (nullptr), m_title (nullptr), m_blockUpdates (false) + { + uibuttongroup::properties& pp = properties (); - frame->setObjectName ("UIButtonGroup"); - frame->setAutoFillBackground (true); - Matrix bb = pp.get_boundingbox (false); - frame->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), - octave::math::round (bb(2)), octave::math::round (bb(3))); - frame->setFrameStyle (frameStyleFromProperties (pp)); - frame->setLineWidth (octave::math::round (pp.get_borderwidth ())); - QPalette pal = frame->palette (); - setupPalette (pp, pal); - frame->setPalette (pal); - m_buttongroup = buttongroup; - m_hiddenbutton = new QRadioButton (frame); - m_hiddenbutton->hide (); - m_buttongroup->addButton (m_hiddenbutton); + frame->setObjectName ("UIButtonGroup"); + frame->setAutoFillBackground (true); + Matrix bb = pp.get_boundingbox (false); + frame->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), + octave::math::round (bb(2)), octave::math::round (bb(3))); + frame->setFrameStyle (frameStyleFromProperties (pp)); + frame->setLineWidth (octave::math::round (pp.get_borderwidth ())); + QPalette pal = frame->palette (); + setupPalette (pp, pal); + frame->setPalette (pal); + m_buttongroup = buttongroup; + m_hiddenbutton = new QRadioButton (frame); + m_hiddenbutton->hide (); + m_buttongroup->addButton (m_hiddenbutton); + + m_container = new Container (frame, interp); + m_container->canvas (m_handle); + + connect (m_container, SIGNAL (interpeter_event (const fcn_callback&)), + this, SIGNAL (interpeter_event (const fcn_callback&))); + + connect (m_container, SIGNAL (interpeter_event (const meth_callback&)), + this, SIGNAL (interpeter_event (const meth_callback&))); - m_container = new Container (frame, oct_qobj, interp); - m_container->canvas (m_handle); - - connect (m_container, SIGNAL (interpeter_event (const fcn_callback&)), - this, SIGNAL (interpeter_event (const fcn_callback&))); + if (frame->hasMouseTracking ()) + { + for (auto *w : frame->findChildren ()) + w->setMouseTracking (true); + for (auto *w : buttongroup->findChildren ()) + w->setMouseTracking (true); + } - connect (m_container, SIGNAL (interpeter_event (const meth_callback&)), - this, SIGNAL (interpeter_event (const meth_callback&))); + QString title = Utils::fromStdString (pp.get_title ()); + if (! title.isEmpty ()) + { + m_title = new QLabel (title, frame); + m_title->setAutoFillBackground (true); + m_title->setContentsMargins (4, 0, 4, 0); + m_title->setPalette (pal); + m_title->setFont (Utils::computeFont (pp, bb(3))); + } - if (frame->hasMouseTracking ()) - { - for (auto *w : frame->findChildren ()) - w->setMouseTracking (true); - for (auto *w : buttongroup->findChildren ()) - w->setMouseTracking (true); - } + frame->installEventFilter (this); + m_container->installEventFilter (this); - QString title = Utils::fromStdString (pp.get_title ()); - if (! title.isEmpty ()) - { - m_title = new QLabel (title, frame); - m_title->setAutoFillBackground (true); - m_title->setContentsMargins (4, 0, 4, 0); - m_title->setPalette (pal); - m_title->setFont (Utils::computeFont (pp, bb(3))); - } - - frame->installEventFilter (this); - m_container->installEventFilter (this); + if (pp.is_visible ()) + { + 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 ())); + } + else + frame->hide (); - if (pp.is_visible ()) - { - 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))); - } - else - frame->hide (); + connect (m_buttongroup, + QOverload::of (&QButtonGroup::buttonClicked), + this, &ButtonGroup::buttonClicked); + } - connect (m_buttongroup, - QOverload::of (&QButtonGroup::buttonClicked), - this, &ButtonGroup::buttonClicked); -} + ButtonGroup::~ButtonGroup () + { } + + bool + ButtonGroup::eventFilter (QObject *watched, QEvent *xevent) + { + if (! m_blockUpdates) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); -ButtonGroup::~ButtonGroup (void) -{ } + if (watched == qObject ()) + { + switch (xevent->type ()) + { + case QEvent::Resize: + { + octave::autolock guard (gh_mgr.graphics_lock ()); -bool -ButtonGroup::eventFilter (QObject *watched, QEvent *xevent) -{ - if (! m_blockUpdates) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + graphics_object go = object (); - if (watched == qObject ()) - { - switch (xevent->type ()) - { - case QEvent::Resize: - { - octave::autolock guard (gh_mgr.graphics_lock ()); + if (go.valid_object ()) + { + if (m_title) + { + const uibuttongroup::properties& pp = + Utils::properties (go); - graphics_object go = object (); + if (pp.fontunits_is ("normalized")) + { + QFrame *frame = qWidget (); - if (go.valid_object ()) - { - if (m_title) - { - const uibuttongroup::properties& pp = - Utils::properties (go); + m_title->setFont (Utils::computeFont + (pp, frame->height ())); + m_title->resize (m_title->sizeHint ()); + } + } + updateLayout (); + } + } + break; - if (pp.fontunits_is ("normalized")) - { - QFrame *frame = qWidget (); + case QEvent::MouseButtonPress: + { + QMouseEvent *m = dynamic_cast (xevent); - m_title->setFont (Utils::computeFont - (pp, frame->height ())); - m_title->resize (m_title->sizeHint ()); - } - } - updateLayout (); - } + if (m->button () == Qt::RightButton) + { + octave::autolock guard (gh_mgr.graphics_lock ()); + + ContextMenu::executeAt (m_interpreter, properties (), + m->globalPos ()); + } + } + break; + + default: + break; } - break; - - case QEvent::MouseButtonPress: + } + else if (watched == m_container) + { + switch (xevent->type ()) { - QMouseEvent *m = dynamic_cast (xevent); - - if (m->button () == Qt::RightButton) + case QEvent::Resize: + if (qWidget ()->isVisible ()) { octave::autolock guard (gh_mgr.graphics_lock ()); - ContextMenu::executeAt (m_interpreter, properties (), - m->globalPos ()); + properties ().update_boundingbox (); } + break; + + default: + break; } - break; + } + } + + return false; + } + + void + ButtonGroup::update (int pId) + { + uibuttongroup::properties& pp = properties (); + QFrame *frame = qWidget (); + + m_blockUpdates = true; + + switch (pId) + { + case uibuttongroup::properties::ID_POSITION: + { + Matrix bb = pp.get_boundingbox (false); - default: - break; - } + frame->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), + octave::math::round (bb(2)), octave::math::round (bb(3))); + updateLayout (); } - else if (watched == m_container) + break; + + case uibuttongroup::properties::ID_BORDERWIDTH: + frame->setLineWidth (octave::math::round (pp.get_borderwidth ())); + updateLayout (); + break; + + case uibuttongroup::properties::ID_BACKGROUNDCOLOR: + case uibuttongroup::properties::ID_FOREGROUNDCOLOR: + case uibuttongroup::properties::ID_HIGHLIGHTCOLOR: + case uibuttongroup::properties::ID_SHADOWCOLOR: + { + QPalette pal = frame->palette (); + + setupPalette (pp, pal); + frame->setPalette (pal); + if (m_title) + m_title->setPalette (pal); + } + break; + + case uibuttongroup::properties::ID_TITLE: { - switch (xevent->type ()) + QString title = Utils::fromStdString (pp.get_title ()); + + if (title.isEmpty ()) + { + if (m_title) + delete m_title; + m_title = nullptr; + } + else { - case QEvent::Resize: - if (qWidget ()->isVisible ()) + if (! m_title) + { + QPalette pal = frame->palette (); + + m_title = new QLabel (title, frame); + m_title->setAutoFillBackground (true); + m_title->setContentsMargins (4, 0, 4, 0); + m_title->setPalette (pal); + m_title->setFont (Utils::computeFont (pp)); + m_title->show (); + } + else { - octave::autolock guard (gh_mgr.graphics_lock ()); + m_title->setText (title); + m_title->resize (m_title->sizeHint ()); + } + } + updateLayout (); + } + break; + + case uibuttongroup::properties::ID_TITLEPOSITION: + updateLayout (); + break; + + case uibuttongroup::properties::ID_BORDERTYPE: + frame->setFrameStyle (frameStyleFromProperties (pp)); + updateLayout (); + break; - properties ().update_boundingbox (); - } - break; + case uibuttongroup::properties::ID_FONTNAME: + case uibuttongroup::properties::ID_FONTSIZE: + case uibuttongroup::properties::ID_FONTWEIGHT: + case uibuttongroup::properties::ID_FONTANGLE: + if (m_title) + { + m_title->setFont (Utils::computeFont (pp)); + m_title->resize (m_title->sizeHint ()); + updateLayout (); + } + break; + + case uibuttongroup::properties::ID_VISIBLE: + frame->setVisible (pp.is_visible ()); + updateLayout (); + break; + + case uibuttongroup::properties::ID_SELECTEDOBJECT: + { + graphics_handle h = pp.get_selectedobject (); - default: - break; + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object go = gh_mgr.get_object (h); + + Object *selectedObject = qt_graphics_toolkit::toolkitObject (go); + ToggleButtonControl *toggle = static_cast + (selectedObject); + RadioButtonControl *radio = static_cast(selectedObject); + if (toggle) + { + go.get_properties ().set ("value", 1); + } + else if (radio) + { + go.get_properties ().set ("value", 1); + } + else + { + m_hiddenbutton->setChecked (true); } } - } - - return false; -} - -void -ButtonGroup::update (int pId) -{ - uibuttongroup::properties& pp = properties (); - QFrame *frame = qWidget (); + break; - m_blockUpdates = true; - - switch (pId) - { - case uibuttongroup::properties::ID_POSITION: - { - Matrix bb = pp.get_boundingbox (false); - - frame->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), - octave::math::round (bb(2)), octave::math::round (bb(3))); - updateLayout (); + default: + break; } - break; + + m_blockUpdates = false; + } - case uibuttongroup::properties::ID_BORDERWIDTH: - frame->setLineWidth (octave::math::round (pp.get_borderwidth ())); - updateLayout (); - break; + void + ButtonGroup::redraw () + { + update (uibuttongroup::properties::ID_POSITION); + + // FIXME: is it really necessary to update the opengl canvas here? + Canvas *canvas = m_container->canvas (m_handle); + + if (canvas) + canvas->redraw (); + } - case uibuttongroup::properties::ID_BACKGROUNDCOLOR: - case uibuttongroup::properties::ID_FOREGROUNDCOLOR: - case uibuttongroup::properties::ID_HIGHLIGHTCOLOR: - case uibuttongroup::properties::ID_SHADOWCOLOR: - { - QPalette pal = frame->palette (); + void + ButtonGroup::updateLayout () + { + uibuttongroup::properties& pp = properties (); + QFrame *frame = qWidget (); + + Matrix bb = pp.get_boundingbox (true); + int bw = borderWidthFromProperties (pp); - setupPalette (pp, pal); - frame->setPalette (pal); - if (m_title) - m_title->setPalette (pal); - } - break; + frame->setFrameRect (QRect (octave::math::round (bb(0)) - bw, + octave::math::round (bb(1)) - bw, + octave::math::round (bb(2)) + 2*bw, octave::math::round (bb(3)) + 2*bw)); + m_container->setGeometry (octave::math::round (bb(0)), + octave::math::round (bb(1)), + octave::math::round (bb(2)), octave::math::round (bb(3))); - case uibuttongroup::properties::ID_TITLE: - { - QString title = Utils::fromStdString (pp.get_title ()); + if (m_blockUpdates) + pp.update_boundingbox (); - if (title.isEmpty ()) - { - if (m_title) - delete m_title; - m_title = nullptr; - } - else - { - if (! m_title) - { - QPalette pal = frame->palette (); - - m_title = new QLabel (title, frame); - m_title->setAutoFillBackground (true); - m_title->setContentsMargins (4, 0, 4, 0); - m_title->setPalette (pal); - m_title->setFont (Utils::computeFont (pp)); - m_title->show (); - } - else - { - m_title->setText (title); - m_title->resize (m_title->sizeHint ()); - } - } - updateLayout (); - } - break; + if (m_title) + { + QSize sz = m_title->sizeHint (); + int offset = 5; - case uibuttongroup::properties::ID_TITLEPOSITION: - updateLayout (); - break; - - case uibuttongroup::properties::ID_BORDERTYPE: - frame->setFrameStyle (frameStyleFromProperties (pp)); - updateLayout (); - break; + if (pp.titleposition_is ("lefttop")) + m_title->move (bw+offset, 0); + else if (pp.titleposition_is ("righttop")) + m_title->move (frame->width () - bw - offset - sz.width (), 0); + else if (pp.titleposition_is ("leftbottom")) + m_title->move (bw+offset, frame->height () - sz.height ()); + else if (pp.titleposition_is ("rightbottom")) + m_title->move (frame->width () - bw - offset - sz.width (), + frame->height () - sz.height ()); + else if (pp.titleposition_is ("centertop")) + m_title->move (frame->width () / 2 - sz.width () / 2, 0); + else if (pp.titleposition_is ("centerbottom")) + m_title->move (frame->width () / 2 - sz.width () / 2, + frame->height () - sz.height ()); + } + } - case uibuttongroup::properties::ID_FONTNAME: - case uibuttongroup::properties::ID_FONTSIZE: - case uibuttongroup::properties::ID_FONTWEIGHT: - case uibuttongroup::properties::ID_FONTANGLE: - if (m_title) - { - m_title->setFont (Utils::computeFont (pp)); - m_title->resize (m_title->sizeHint ()); - updateLayout (); - } - break; + void + ButtonGroup::selectNothing () + { + m_hiddenbutton->setChecked (true); + } - case uibuttongroup::properties::ID_VISIBLE: - frame->setVisible (pp.is_visible ()); - updateLayout (); - break; + void + ButtonGroup::addButton (QAbstractButton *btn) + { + m_buttongroup->addButton (btn); + connect (btn, &QAbstractButton::toggled, this, &ButtonGroup::buttonToggled); + } - case uibuttongroup::properties::ID_SELECTEDOBJECT: + void + ButtonGroup::buttonToggled (bool toggled) + { + Q_UNUSED (toggled); + if (! m_blockUpdates) { - graphics_handle h = pp.get_selectedobject (); - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); octave::autolock guard (gh_mgr.graphics_lock ()); - graphics_object go = gh_mgr.get_object (h); + uibuttongroup::properties& bp = properties (); - Object *selectedObject = qt_graphics_toolkit::toolkitObject (go); - ToggleButtonControl *toggle = static_cast - (selectedObject); - RadioButtonControl *radio = static_cast(selectedObject); - if (toggle) - { - go.get_properties ().set ("value", 1); - } - else if (radio) - { - go.get_properties ().set ("value", 1); - } - else - { - m_hiddenbutton->setChecked (true); - } - } - break; + graphics_handle oldValue = bp.get_selectedobject (); - default: - break; - } - - m_blockUpdates = false; -} + QAbstractButton *checkedBtn = m_buttongroup->checkedButton (); -void -ButtonGroup::redraw (void) -{ - update (uibuttongroup::properties::ID_POSITION); - - // FIXME: is it really necessary to update the opengl canvas here? - Canvas *canvas = m_container->canvas (m_handle); - - if (canvas) - canvas->redraw (); -} - -void -ButtonGroup::updateLayout (void) -{ - uibuttongroup::properties& pp = properties (); - QFrame *frame = qWidget (); + graphics_handle newValue = graphics_handle (); + if (checkedBtn != m_hiddenbutton) + { + Object *checkedObj = Object::fromQObject (checkedBtn); + newValue = checkedObj->properties ().get___myhandle__ (); + } - Matrix bb = pp.get_boundingbox (true); - int bw = borderWidthFromProperties (pp); + if (oldValue != newValue) + emit gh_set_event (m_handle, "selectedobject", + newValue.as_octave_value (), false); + } + } - frame->setFrameRect (QRect (octave::math::round (bb(0)) - bw, - octave::math::round (bb(1)) - bw, - octave::math::round (bb(2)) + 2*bw, octave::math::round (bb(3)) + 2*bw)); - m_container->setGeometry (octave::math::round (bb(0)), - octave::math::round (bb(1)), - octave::math::round (bb(2)), octave::math::round (bb(3))); - - if (m_blockUpdates) - pp.update_boundingbox (); - - if (m_title) - { - QSize sz = m_title->sizeHint (); - int offset = 5; + void + ButtonGroup::buttonClicked (QAbstractButton *btn) + { + Q_UNUSED (btn); - if (pp.titleposition_is ("lefttop")) - m_title->move (bw+offset, 0); - else if (pp.titleposition_is ("righttop")) - m_title->move (frame->width () - bw - offset - sz.width (), 0); - else if (pp.titleposition_is ("leftbottom")) - m_title->move (bw+offset, frame->height () - sz.height ()); - else if (pp.titleposition_is ("rightbottom")) - m_title->move (frame->width () - bw - offset - sz.width (), - frame->height () - sz.height ()); - else if (pp.titleposition_is ("centertop")) - m_title->move (frame->width () / 2 - sz.width () / 2, 0); - else if (pp.titleposition_is ("centerbottom")) - m_title->move (frame->width () / 2 - sz.width () / 2, - frame->height () - sz.height ()); - } -} + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + uibuttongroup::properties& bp = properties (); -void -ButtonGroup::selectNothing (void) -{ - m_hiddenbutton->setChecked (true); -} - -void -ButtonGroup::addButton (QAbstractButton *btn) -{ - m_buttongroup->addButton (btn); - connect (btn, &QAbstractButton::toggled, this, &ButtonGroup::buttonToggled); -} + graphics_handle oldValue = bp.get_selectedobject (); -void -ButtonGroup::buttonToggled (bool toggled) -{ - Q_UNUSED (toggled); - if (! m_blockUpdates) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - uibuttongroup::properties& bp = properties (); - - graphics_handle oldValue = bp.get_selectedobject (); + QAbstractButton *checkedBtn = m_buttongroup->checkedButton (); + Object *checkedObj = Object::fromQObject (checkedBtn); + graphics_handle newValue = checkedObj->properties ().get___myhandle__ (); - QAbstractButton *checkedBtn = m_buttongroup->checkedButton (); - - graphics_handle newValue = graphics_handle (); - if (checkedBtn != m_hiddenbutton) - { - Object *checkedObj = Object::fromQObject (checkedBtn); - newValue = checkedObj->properties ().get___myhandle__ (); - } - - if (oldValue != newValue) - emit gh_set_event (m_handle, "selectedobject", - newValue.as_octave_value (), false); - } -} - -void -ButtonGroup::buttonClicked (QAbstractButton *btn) -{ - Q_UNUSED (btn); - - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - uibuttongroup::properties& bp = properties (); - - graphics_handle oldValue = bp.get_selectedobject (); - - QAbstractButton *checkedBtn = m_buttongroup->checkedButton (); - Object *checkedObj = Object::fromQObject (checkedBtn); - graphics_handle newValue = checkedObj->properties ().get___myhandle__ (); - - if (oldValue != newValue) - { - octave_scalar_map eventData; - eventData.setfield ("OldValue", oldValue.as_octave_value ()); - eventData.setfield ("NewValue", newValue.as_octave_value ()); - eventData.setfield ("Source", bp.get___myhandle__ ().as_octave_value ()); - eventData.setfield ("EventName", "SelectionChanged"); - octave_value selectionChangedEventObject (eventData); - emit gh_callback_event (m_handle, "selectionchangedfcn", - selectionChangedEventObject); - } -} + if (oldValue != newValue) + { + octave_scalar_map eventData; + eventData.setfield ("OldValue", oldValue.as_octave_value ()); + eventData.setfield ("NewValue", newValue.as_octave_value ()); + eventData.setfield ("Source", bp.get___myhandle__ ().as_octave_value ()); + eventData.setfield ("EventName", "SelectionChanged"); + octave_value selectionChangedEventObject (eventData); + emit gh_callback_event (m_handle, "selectionchangedfcn", + selectionChangedEventObject); + } + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ButtonGroup.h --- a/libgui/graphics/ButtonGroup.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ButtonGroup.h Mon Jan 30 18:36:03 2023 +0100 @@ -36,51 +36,50 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; + + class Container; -class Container; - -class ButtonGroup : public Object -{ - Q_OBJECT + class ButtonGroup : public Object + { + Q_OBJECT -public: - ButtonGroup (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QButtonGroup *buttongroup, - QFrame *frame); - ~ButtonGroup (void); + public: + ButtonGroup (octave::interpreter& interp, + const graphics_object& go, QButtonGroup *buttongroup, + QFrame *frame); + ~ButtonGroup (); - Container * innerContainer (void) { return m_container; } + Container * innerContainer () { return m_container; } - bool eventFilter (QObject *watched, QEvent *event); + bool eventFilter (QObject *watched, QEvent *event); - static ButtonGroup * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static ButtonGroup * + create (octave::interpreter& interp, + const graphics_object& go); - void addButton (QAbstractButton *btn); + void addButton (QAbstractButton *btn); - void selectNothing (void); + void selectNothing (); -protected: - void update (int pId); - void redraw (void); + protected: + void update (int pId); + void redraw (); -private slots: - void buttonToggled (bool toggled); - void buttonClicked (QAbstractButton *btn); + private slots: + void buttonToggled (bool toggled); + void buttonClicked (QAbstractButton *btn); -private: - void updateLayout (void); + private: + void updateLayout (); -private: - QButtonGroup *m_buttongroup; - QRadioButton *m_hiddenbutton; - Container *m_container; - QLabel *m_title; - bool m_blockUpdates; -}; + private: + QButtonGroup *m_buttongroup; + QRadioButton *m_hiddenbutton; + Container *m_container; + QLabel *m_title; + bool m_blockUpdates; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Canvas.cc --- a/libgui/graphics/Canvas.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Canvas.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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" @@ -53,1044 +53,1036 @@ OCTAVE_BEGIN_NAMESPACE(octave) -void -Canvas::redraw (bool sync) -{ - QWidget *w = qWidget (); + void + Canvas::redraw (bool sync) + { + QWidget *w = qWidget (); - if (w) - { - if (sync) - w->repaint (); - else - w->update (); - } -} + if (w) + { + if (sync) + w->repaint (); + else + w->update (); + } + } -void -Canvas::blockRedraw (bool block) -{ - m_redrawBlocked = block; -} + void + Canvas::blockRedraw (bool block) + { + m_redrawBlocked = block; + } -QCursor -Canvas::make_cursor (const QString& name, int hot_x, int hot_y) -{ - octave::resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + QCursor + Canvas::make_cursor (const QString& name, int hot_x, int hot_y) + { + gui_settings settings; - QIcon icon = rmgr.icon (name); + QIcon icon = settings.icon (name); - return QCursor (icon.pixmap (22, 22), hot_x, hot_y); -} + return QCursor (icon.pixmap (22, 22), hot_x, hot_y); + } -void -Canvas::setCursor (MouseMode mode, std::string fallback, - QImage cdata, Matrix hotspot) -{ - QWidget *w = qWidget (); - QCursor cursor = Qt::ArrowCursor; - if (w) - { - switch (mode) - { - case NoMode: + void + Canvas::setCursor (MouseMode mode, std::string fallback, + QImage cdata, Matrix hotspot) + { + QWidget *w = qWidget (); + QCursor cursor = Qt::ArrowCursor; + if (w) + { + switch (mode) { - cursor = Qt::ArrowCursor; + case NoMode: + { + cursor = Qt::ArrowCursor; - if (fallback == "arrow") - cursor = Qt::ArrowCursor; - else if (fallback == "botl") - cursor = make_cursor ("bottom_left_corner", 5, 16); - else if (fallback == "botr") - cursor = make_cursor ("bottom_right_corner", 16, 16); - else if (fallback == "bottom") - cursor = make_cursor ("bottom_side", 11, 16); - else if (fallback == "circle") - cursor = make_cursor ("circle", 10, 10); - else if (fallback == "cross" || fallback == "crosshair") - cursor = make_cursor ("cross", 10, 10); - else if (fallback == "custom") - { - if (hotspot(0) > cdata.width () || hotspot(0) < 1.0 - || hotspot(1) > cdata.height () || hotspot(1) < 1.0) - hotspot = Matrix (1, 2, 1); + if (fallback == "arrow") + cursor = Qt::ArrowCursor; + else if (fallback == "botl") + cursor = make_cursor ("bottom_left_corner", 5, 16); + else if (fallback == "botr") + cursor = make_cursor ("bottom_right_corner", 16, 16); + else if (fallback == "bottom") + cursor = make_cursor ("bottom_side", 11, 16); + else if (fallback == "circle") + cursor = make_cursor ("circle", 10, 10); + else if (fallback == "cross" || fallback == "crosshair") + cursor = make_cursor ("cross", 10, 10); + else if (fallback == "custom") + { + if (hotspot(0) > cdata.width () || hotspot(0) < 1.0 + || hotspot(1) > cdata.height () || hotspot(1) < 1.0) + hotspot = Matrix (1, 2, 1); - cursor = QCursor (QPixmap::fromImage (cdata), - static_cast (hotspot(1) - 1), - static_cast (hotspot(0) - 1)); - } - else if (fallback == "fleur") - cursor = make_cursor ("fleur", 10, 4); - else if (fallback == "hand") - cursor = make_cursor ("hand2", 7, 3); - else if (fallback == "ibeam") - cursor = Qt::IBeamCursor; - else if (fallback == "left") - cursor = make_cursor ("left_side", 4, 10); - else if (fallback == "right") - cursor = make_cursor ("right_side", 17, 10); - else if (fallback == "top") - cursor = make_cursor ("top_side", 11, 4); - else if (fallback == "topl") - cursor = make_cursor ("top_left_corner", 4, 4); - else if (fallback == "topr") - cursor = make_cursor ("top_right_corner", 16, 4); - else if (fallback == "watch") - cursor = Qt::BusyCursor; - } - break; - case SelectMode: - cursor = Qt::ArrowCursor; - break; + cursor = QCursor (QPixmap::fromImage (cdata), + static_cast (hotspot(1) - 1), + static_cast (hotspot(0) - 1)); + } + else if (fallback == "fleur") + cursor = make_cursor ("fleur", 10, 4); + else if (fallback == "hand") + cursor = make_cursor ("hand2", 7, 3); + else if (fallback == "ibeam") + cursor = Qt::IBeamCursor; + else if (fallback == "left") + cursor = make_cursor ("left_side", 4, 10); + else if (fallback == "right") + cursor = make_cursor ("right_side", 17, 10); + else if (fallback == "top") + cursor = make_cursor ("top_side", 11, 4); + else if (fallback == "topl") + cursor = make_cursor ("top_left_corner", 4, 4); + else if (fallback == "topr") + cursor = make_cursor ("top_right_corner", 16, 4); + else if (fallback == "watch") + cursor = Qt::BusyCursor; + } + break; + case SelectMode: + cursor = Qt::ArrowCursor; + break; + + case PanMode: + cursor = make_cursor ("figure-pan"); + break; + + case RotateMode: + cursor = make_cursor ("figure-rotate"); + break; + + case TextMode: + cursor = Qt::IBeamCursor; + break; + + case ZoomInMode: + cursor = make_cursor ("figure-zoom-in", 9, 9); + break; - case PanMode: - cursor = make_cursor ("figure-pan"); - break; + case ZoomOutMode: + cursor = make_cursor ("figure-zoom-out", 9, 9); + break; - case RotateMode: - cursor = make_cursor ("figure-rotate"); - break; + default: + cursor = Qt::ArrowCursor; + break; + } + w->setCursor (cursor); + } + } - case TextMode: - cursor = Qt::IBeamCursor; - break; + /* + 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, + const graphics_object& obj, QMouseEvent *event) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - case ZoomInMode: - cursor = make_cursor ("figure-zoom-in", 9, 9); - break; - - case ZoomOutMode: - cursor = make_cursor ("figure-zoom-out", 9, 9); - break; + octave::autolock guard (gh_mgr.graphics_lock ()); - default: - cursor = Qt::ArrowCursor; - break; - } - w->setCursor (cursor); - } -} + emit gh_set_event (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig, event), false); + + Matrix children = obj.get_properties ().get_children (); + octave_idx_type num_children = children.numel (); + + for (int i = 0; i < num_children; i++) + { + graphics_object childObj (gh_mgr.get_object (children(i))); -/* - 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, - const graphics_object& obj, QMouseEvent *event) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + if (childObj.isa ("axes")) + { + axes::properties& ap = Utils::properties (childObj); + Matrix x_zlim = ap.get_transform_zlim (); + graphics_xform x_form = ap.get_transform (); - octave::autolock guard (gh_mgr.graphics_lock ()); + ColumnVector p1 = x_form.untransform (event->x (), event->y (), + x_zlim(0)); + ColumnVector p2 = x_form.untransform (event->x (), event->y (), + x_zlim(1)); - emit gh_set_event (fig.get_handle (), "currentpoint", - Utils::figureCurrentPoint (fig, event), false); + Matrix cp (2, 3, 0.0); + + cp(0, 0) = p1(0); cp(0, 1) = p1(1); cp(0, 2) = p1(2); + cp(1, 0) = p2(0); cp(1, 1) = p2(1); cp(1, 2) = p2(2); - Matrix children = obj.get_properties ().get_children (); - octave_idx_type num_children = children.numel (); + emit gh_set_event (childObj.get_handle (), "currentpoint", cp, + false); + } + } + } - for (int i = 0; i < num_children; i++) - { - graphics_object childObj (gh_mgr.get_object (children(i))); + void + Canvas::updateCurrentPoint (const graphics_object& fig, + const graphics_object& obj) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - if (childObj.isa ("axes")) - { - axes::properties& ap = Utils::properties (childObj); - Matrix x_zlim = ap.get_transform_zlim (); - graphics_xform x_form = ap.get_transform (); + octave::autolock guard (gh_mgr.graphics_lock ()); + + emit gh_set_event (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig), false); - ColumnVector p1 = x_form.untransform (event->x (), event->y (), - x_zlim(0)); - ColumnVector p2 = x_form.untransform (event->x (), event->y (), - x_zlim(1)); + Matrix children = obj.get_properties ().get_children (); + octave_idx_type num_children = children.numel (); - Matrix cp (2, 3, 0.0); - - cp(0, 0) = p1(0); cp(0, 1) = p1(1); cp(0, 2) = p1(2); - cp(1, 0) = p2(0); cp(1, 1) = p2(1); cp(1, 2) = p2(2); + for (int i = 0; i < num_children; i++) + { + graphics_object childObj (gh_mgr.get_object (children(i))); - emit gh_set_event (childObj.get_handle (), "currentpoint", cp, - false); - } - } -} + if (childObj.isa ("axes")) + { + // FIXME: QCursor::pos() may give inaccurate results with + // asynchronous window systems like X11 over ssh. + QWidget *w = qWidget (); + QPoint p = w->mapFromGlobal (QCursor::pos ()); + axes::properties& ap = Utils::properties (childObj); + Matrix x_zlim = ap.get_transform_zlim (); + graphics_xform x_form = ap.get_transform (); -void -Canvas::updateCurrentPoint (const graphics_object& fig, - const graphics_object& obj) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + ColumnVector p1 = x_form.untransform (p.x (), p.y (), x_zlim(0)); + ColumnVector p2 = x_form.untransform (p.x (), p.y (), x_zlim(1)); + + Matrix cp (2, 3, 0.0); + + cp(0, 0) = p1(0); cp(0, 1) = p1(1); cp(0, 2) = p1(2); + cp(1, 0) = p2(0); cp(1, 1) = p2(1); cp(1, 2) = p2(2); - octave::autolock guard (gh_mgr.graphics_lock ()); - - emit gh_set_event (fig.get_handle (), "currentpoint", - Utils::figureCurrentPoint (fig), false); + emit gh_set_event (childObj.get_handle (), "currentpoint", cp, + false); + } + } + } - Matrix children = obj.get_properties ().get_children (); - octave_idx_type num_children = children.numel (); + static void + autoscale_axes (gh_manager& gh_mgr, axes::properties& ap) + { + octave::autolock guard (gh_mgr.graphics_lock ()); - for (int i = 0; i < num_children; i++) - { - graphics_object childObj (gh_mgr.get_object (children(i))); + // Reset zoom stack + ap.clear_zoom_stack (false); + + ap.set_xlimmode ("auto"); + ap.set_ylimmode ("auto"); + ap.set_zlimmode ("auto"); + } - if (childObj.isa ("axes")) - { - // FIXME: QCursor::pos() may give inaccurate results with - // asynchronous window systems like X11 over ssh. - QWidget *w = qWidget (); - QPoint p = w->mapFromGlobal (QCursor::pos ()); - axes::properties& ap = Utils::properties (childObj); - Matrix x_zlim = ap.get_transform_zlim (); - graphics_xform x_form = ap.get_transform (); + void + Canvas::canvasPaintEvent () + { + if (! m_redrawBlocked) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + draw (m_handle); - ColumnVector p1 = x_form.untransform (p.x (), p.y (), x_zlim(0)); - ColumnVector p2 = x_form.untransform (p.x (), p.y (), x_zlim(1)); - - Matrix cp (2, 3, 0.0); + if ((m_mouseMode == ZoomInMode && m_mouseAxes.ok ()) || m_rectMode) + drawZoomBox (m_mouseAnchor, m_mouseCurrent); + } + } - cp(0, 0) = p1(0); cp(0, 1) = p1(1); cp(0, 2) = p1(2); - cp(1, 0) = p2(0); cp(1, 1) = p2(1); cp(1, 2) = p2(2); + static bool + pan_enabled (const graphics_object figObj) + { + // Getting pan mode property: + octave_value ov_pm + = Utils::properties
(figObj).get___pan_mode__ (); - emit gh_set_event (childObj.get_handle (), "currentpoint", cp, - false); - } - } -} + octave_scalar_map pm = ov_pm.scalar_map_value (); -static void -autoscale_axes (gh_manager& gh_mgr, axes::properties& ap) -{ - octave::autolock guard (gh_mgr.graphics_lock ()); + return pm.contents ("Enable").string_value () == "on"; + } - // Reset zoom stack - ap.clear_zoom_stack (false); + static std::string + pan_mode (const graphics_object figObj) + { + // Getting pan mode property: + octave_value ov_pm + = Utils::properties
(figObj).get___pan_mode__ (); + + octave_scalar_map pm = ov_pm.scalar_map_value (); - ap.set_xlimmode ("auto"); - ap.set_ylimmode ("auto"); - ap.set_zlimmode ("auto"); -} + return pm.contents ("Motion").string_value (); + } -void -Canvas::canvasPaintEvent (void) -{ - if (! m_redrawBlocked) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + static bool + zoom_enabled (const graphics_object figObj) + { + // Getting zoom mode property: + octave_value ov_zm + = Utils::properties
(figObj).get___zoom_mode__ (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave_scalar_map zm = ov_zm.scalar_map_value (); - draw (m_handle); + return zm.contents ("Enable").string_value () == "on"; + } - if ((m_mouseMode == ZoomInMode && m_mouseAxes.ok ()) || m_rectMode) - drawZoomBox (m_mouseAnchor, m_mouseCurrent); - } -} + static std::string + zoom_mode (const graphics_object figObj) + { + // Getting zoom mode property: + octave_value ov_zm + = Utils::properties
(figObj).get___zoom_mode__ (); -static bool -pan_enabled (const graphics_object figObj) -{ - // Getting pan mode property: - octave_value ov_pm - = Utils::properties
(figObj).get___pan_mode__ (); + octave_scalar_map zm = ov_zm.scalar_map_value (); + + return zm.contents ("Motion").string_value (); + } - octave_scalar_map pm = ov_pm.scalar_map_value (); - - return pm.contents ("Enable").string_value () == "on"; -} + void + Canvas::select_object (graphics_object obj, QMouseEvent *event, + graphics_object& currentObj, graphics_object& axesObj, + bool axes_only, std::vector omit) + { + QList axesList; + Matrix children = obj.get_properties ().get_all_children (); + octave_idx_type num_children = children.numel (); -static std::string -pan_mode (const graphics_object figObj) -{ - // Getting pan mode property: - octave_value ov_pm - = Utils::properties
(figObj).get___pan_mode__ (); + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + for (int i = 0; i < num_children; i++) + { + graphics_object childObj (gh_mgr.get_object (children(i))); - octave_scalar_map pm = ov_pm.scalar_map_value (); - - return pm.contents ("Motion").string_value (); -} - -static bool -zoom_enabled (const graphics_object figObj) -{ - // Getting zoom mode property: - octave_value ov_zm - = Utils::properties
(figObj).get___zoom_mode__ (); + if (childObj.isa ("axes")) + { + auto p = omit.begin (); + bool omitfound = false; + while (p != omit.end () && ! omitfound) + { + omitfound = (childObj.get ("tag").string_value () == *p); + p++; + } + if (! omitfound) + axesList.append (childObj); + } + else if (childObj.isa ("uicontrol") || childObj.isa ("uipanel") + || childObj.isa ("uibuttongroup") || childObj.isa ("uitable")) + { + Matrix bb = childObj.get_properties ().get_boundingbox (false); + QRectF r (bb(0), bb(1), bb(2), bb(3)); - octave_scalar_map zm = ov_zm.scalar_map_value (); - - return zm.contents ("Enable").string_value () == "on"; -} + r.adjust (-5, -5, 5, 5); -static std::string -zoom_mode (const graphics_object figObj) -{ - // Getting zoom mode property: - octave_value ov_zm - = Utils::properties
(figObj).get___zoom_mode__ (); + bool rect_contains_pos = r.contains (event->localPos ()); + if (rect_contains_pos) + { + currentObj = childObj; + break; + } + } + } - octave_scalar_map zm = ov_zm.scalar_map_value (); - - return zm.contents ("Motion").string_value (); -} + if (axes_only) + { + QPoint pt = event->pos (); -void -Canvas::select_object (graphics_object obj, QMouseEvent *event, - graphics_object& currentObj, graphics_object& axesObj, - bool axes_only, std::vector omit) -{ - QList axesList; - Matrix children = obj.get_properties ().get_all_children (); - octave_idx_type num_children = children.numel (); + for (QList::ConstIterator it = axesList.begin (); + it != axesList.end (); ++it) + { + const axes::properties& ap = + dynamic_cast ((*it).get_properties ()); - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - for (int i = 0; i < num_children; i++) - { - graphics_object childObj (gh_mgr.get_object (children(i))); + ColumnVector p0 = ap.pixel2coord (pt.x (), pt.y ()); + Matrix xlim = ap.get_xlim ().matrix_value (); + Matrix ylim = ap.get_ylim ().matrix_value (); - if (childObj.isa ("axes")) - { - auto p = omit.begin (); - bool omitfound = false; - while (p != omit.end () && ! omitfound) - { - omitfound = (childObj.get ("tag").string_value () == *p); - p++; - } - if (! omitfound) - axesList.append (childObj); - } - else if (childObj.isa ("uicontrol") || childObj.isa ("uipanel") - || childObj.isa ("uibuttongroup") || childObj.isa ("uitable")) - { - Matrix bb = childObj.get_properties ().get_boundingbox (false); - QRectF r (bb(0), bb(1), bb(2), bb(3)); + if (xlim(0) < p0(0) && xlim(1) > p0(0) + && ylim(0) < p0(1) && ylim(1) > p0(1)) + { + axesObj = *it; + return; + } + } + } + else if (! currentObj) + { + for (QList::ConstIterator it = axesList.begin (); + it != axesList.end (); ++it) + { + graphics_object go = selectFromAxes (*it, event->pos ()); - r.adjust (-5, -5, 5, 5); + if (go) + { + currentObj = go; + axesObj = *it; + } + // FIXME: is this really necessary? the axes object should + // have been selected through selectFromAxes anyway + else if (it->get_properties ().is_hittest ()) + { + Matrix bb = it->get_properties ().get_boundingbox (true); + QRectF r (bb(0), bb(1), bb(2), bb(3)); - bool rect_contains_pos = r.contains (event->localPos ()); - if (rect_contains_pos) - { - currentObj = childObj; - break; - } - } - } + // Allow a rectangle (e.g., Zoom box) to be slightly outside + // the axes and still select it. + r.adjust (-20, -20, 20, 20); + + bool rect_contains_pos = r.contains (event->localPos ()); + if (rect_contains_pos) + axesObj = *it; + } - if (axes_only) - { - QPoint pt = event->pos (); + if (axesObj && currentObj) + break; + } + } + } - for (QList::ConstIterator it = axesList.begin (); - it != axesList.end (); ++it) - { - const axes::properties& ap = - dynamic_cast ((*it).get_properties ()); + void + Canvas::canvasMouseMoveEvent (QMouseEvent *event) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object ax = gh_mgr.get_object (m_mouseAxes); - ColumnVector p0 = ap.pixel2coord (pt.x (), pt.y ()); - Matrix xlim = ap.get_xlim ().matrix_value (); - Matrix ylim = ap.get_ylim ().matrix_value (); + if (m_mouseMode != NoMode && (ax.valid_object () || m_mouseMode == TextMode)) + { + switch (m_mouseMode) + { + case RotateMode: + { + axes::properties& ap = Utils::properties (ax); - if (xlim(0) < p0(0) && xlim(1) > p0(0) - && ylim(0) < p0(1) && ylim(1) > p0(1)) - { - axesObj = *it; - return; + ap.rotate3d (m_mouseCurrent.x (), event->x (), + m_mouseCurrent.y (), event->y ()); + + // Update current mouse position + m_mouseCurrent = event->pos (); + + // Force immediate redraw + redraw (true); } - } - } - else if (! currentObj) - { - for (QList::ConstIterator it = axesList.begin (); - it != axesList.end (); ++it) - { - graphics_object go = selectFromAxes (*it, event->pos ()); + break; + case TextMode: + case ZoomInMode: + case ZoomOutMode: + m_mouseCurrent = event->pos (); + redraw (true); + break; - if (go) + case PanMode: { - currentObj = go; - axesObj = *it; - } - // FIXME: is this really necessary? the axes object should - // have been selected through selectFromAxes anyway - else if (it->get_properties ().is_hittest ()) - { - Matrix bb = it->get_properties ().get_boundingbox (true); - QRectF r (bb(0), bb(1), bb(2), bb(3)); + axes::properties& ap = Utils::properties (ax); + + graphics_object figObj (ax.get_ancestor ("figure")); + + std::string mode = pan_mode (figObj); - // Allow a rectangle (e.g., Zoom box) to be slightly outside - // the axes and still select it. - r.adjust (-20, -20, 20, 20); + ColumnVector p0 = ap.pixel2coord (m_mouseCurrent.x (), + m_mouseCurrent.y ()); + ColumnVector p1 = ap.pixel2coord (event->x (), + event->y ()); - bool rect_contains_pos = r.contains (event->localPos ()); - if (rect_contains_pos) - axesObj = *it; + ap.translate_view (mode, p0(0), p1(0), p0(1), p1(1)); + + // Update current mouse position + m_mouseCurrent = event->pos (); + + // Force immediate redraw + redraw (true); } - if (axesObj && currentObj) + default: break; - } - } -} + } + } + else if (m_mouseMode == NoMode) + { + graphics_object obj = gh_mgr.get_object (m_handle); -void -Canvas::canvasMouseMoveEvent (QMouseEvent *event) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + if (obj.valid_object ()) + { + graphics_object figObj (obj.get_ancestor ("figure")); - octave::autolock guard (gh_mgr.graphics_lock ()); + if (figObj.valid_object () + && ! figObj.get ("windowbuttonmotionfcn").isempty ()) + { + updateCurrentPoint (figObj, obj, event); + emit gh_callback_event (figObj.get_handle (), + "windowbuttonmotionfcn"); + } + } + } - graphics_object ax = gh_mgr.get_object (m_mouseAxes); + // Update mouse coordinates in the figure window status bar + graphics_object obj = gh_mgr.get_object (m_handle); + graphics_object figObj = obj.get_ancestor ("figure"); - if (m_mouseMode != NoMode && (ax.valid_object () || m_mouseMode == TextMode)) - { - switch (m_mouseMode) - { - case RotateMode: + if (figObj.valid_object () && obj.valid_object ()) + { + graphics_object currentObj, axesObj; + std::vector omit = {"legend", "colorbar", "scribeoverlay"}; + select_object (obj, event, currentObj, axesObj, true, omit); + + if (axesObj.valid_object ()) { - axes::properties& ap = Utils::properties (ax); + // FIXME: should we use signal/slot mechanism instead of + // directly calling parent fig methods + Figure *fig = + dynamic_cast
(qt_graphics_toolkit::toolkitObject (figObj)); + axes::properties& ap = Utils::properties (axesObj); - ap.rotate3d (m_mouseCurrent.x (), event->x (), - m_mouseCurrent.y (), event->y ()); - - // Update current mouse position - m_mouseCurrent = event->pos (); + if (fig) + fig->updateStatusBar (ap.pixel2coord (event->x (), event->y ())); + } + } + } - // Force immediate redraw - redraw (true); - } - break; - case TextMode: - case ZoomInMode: - case ZoomOutMode: - m_mouseCurrent = event->pos (); - redraw (true); - break; + void + Canvas::canvasMouseDoubleClickEvent (QMouseEvent *event) + { + // same processing as normal click, but event type is MouseButtonDblClick + canvasMousePressEvent (event); + } + + static double + button_number (QMouseEvent *event) + { + double retval = 0; - case PanMode: - { - axes::properties& ap = Utils::properties (ax); + switch (event->button ()) + { + case Qt::LeftButton: + retval = 1; + break; + + case Qt::MiddleButton: + retval = 2; + break; + + case Qt::RightButton: + retval = 3; + break; - graphics_object figObj (ax.get_ancestor ("figure")); + default: + break; + } + + return retval; + } - std::string mode = pan_mode (figObj); + void + Canvas::canvasMousePressEvent (QMouseEvent *event) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); - ColumnVector p0 = ap.pixel2coord (m_mouseCurrent.x (), - m_mouseCurrent.y ()); - ColumnVector p1 = ap.pixel2coord (event->x (), - event->y ()); + graphics_object obj = gh_mgr.get_object (m_handle); + + bool isdblclick = (event->type () == QEvent::MouseButtonDblClick); - ap.translate_view (mode, p0(0), p1(0), p0(1), p1(1)); + if (obj.valid_object ()) + { + graphics_object figObj (obj.get_ancestor ("figure")); - // Update current mouse position - m_mouseCurrent = event->pos (); - - // Force immediate redraw - redraw (true); + // Any click in a figure canvas makes it current + if (figObj) + { + graphics_object root = gh_mgr.get_object (0); + Utils::properties (root) + .set_currentfigure (figObj.get_handle ().as_octave_value ()); } - default: - break; - } - } - else if (m_mouseMode == NoMode) - { - graphics_object obj = gh_mgr.get_object (m_handle); - - if (obj.valid_object ()) - { - graphics_object figObj (obj.get_ancestor ("figure")); + graphics_object currentObj, axesObj; - if (figObj.valid_object () - && ! figObj.get ("windowbuttonmotionfcn").isempty ()) - { - updateCurrentPoint (figObj, obj, event); - emit gh_callback_event (figObj.get_handle (), - "windowbuttonmotionfcn"); - } - } - } - - // Update mouse coordinates in the figure window status bar - graphics_object obj = gh_mgr.get_object (m_handle); - graphics_object figObj = obj.get_ancestor ("figure"); + // Retrieve selected object. + select_object (obj, event, currentObj, axesObj); - if (figObj.valid_object () && obj.valid_object ()) - { - graphics_object currentObj, axesObj; - std::vector omit = {"legend", "colorbar", "scribeoverlay"}; - select_object (obj, event, currentObj, axesObj, true, omit); - - if (axesObj.valid_object ()) - { - // FIXME: should we use signal/slot mechanism instead of - // directly calling parent fig methods - Figure *fig = - dynamic_cast
(qt_graphics_toolkit::toolkitObject (figObj)); - axes::properties& ap = Utils::properties (axesObj); - - if (fig) - fig->updateStatusBar (ap.pixel2coord (event->x (), event->y ())); - } - } -} - -void -Canvas::canvasMouseDoubleClickEvent (QMouseEvent *event) -{ - // same processing as normal click, but event type is MouseButtonDblClick - canvasMousePressEvent (event); -} + // currentObj may be invalid if, e.g., all objects under the mouse + // click had "hittest" -> "off" or "pickableparts" -> "none". In that + // case, replace with underlying figObj which always accepts mouse + // clicks. + if (! currentObj.valid_object ()) + currentObj = figObj; + else if (! currentObj.get_properties ().is_hittest ()) + { + // Objects with "hittest"->"off" pass the mouse event to their + // parent and so on. + graphics_object tmpgo; + tmpgo = gh_mgr.get_object (currentObj.get_parent ()); + while (tmpgo && ! tmpgo.get_properties ().is_hittest ()) + tmpgo = gh_mgr.get_object (tmpgo.get_parent ()); -static double -button_number (QMouseEvent *event) -{ - double retval = 0; - - switch (event->button ()) - { - case Qt::LeftButton: - retval = 1; - break; - - case Qt::MiddleButton: - retval = 2; - break; - - case Qt::RightButton: - retval = 3; - break; - - default: - break; - } - - return retval; -} + if (tmpgo && tmpgo.get_handle () != 0.0) + currentObj = tmpgo; + else + currentObj = graphics_object (); + } -void -Canvas::canvasMousePressEvent (QMouseEvent *event) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - graphics_object obj = gh_mgr.get_object (m_handle); - - bool isdblclick = (event->type () == QEvent::MouseButtonDblClick); + // 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"; - if (obj.valid_object ()) - { - graphics_object figObj (obj.get_ancestor ("figure")); + if (valid_axes) + Utils::properties
(figObj) + .set_currentaxes (axesObj.get_handle ().as_octave_value ()); - // Any click in a figure canvas makes it current - if (figObj) - { - graphics_object root = gh_mgr.get_object (0); - Utils::properties (root) - .set_currentfigure (figObj.get_handle ().as_octave_value ()); - } + Figure *fig = dynamic_cast
(qt_graphics_toolkit::toolkitObject (figObj)); - graphics_object currentObj, axesObj; + MouseMode newMouseMode = NoMode; - // Retrieve selected object. - select_object (obj, event, currentObj, axesObj); + if (fig) + newMouseMode = fig->mouseMode (); - // currentObj may be invalid if, e.g., all objects under the mouse - // click had "hittest" -> "off" or "pickableparts" -> "none". In that - // case, replace with underlying figObj which always accepts mouse - // clicks. - if (! currentObj.valid_object ()) - currentObj = figObj; - else if (! currentObj.get_properties ().is_hittest ()) - { - // Objects with "hittest"->"off" pass the mouse event to their - // parent and so on. - graphics_object tmpgo; - tmpgo = gh_mgr.get_object (currentObj.get_parent ()); - while (tmpgo && ! tmpgo.get_properties ().is_hittest ()) - tmpgo = gh_mgr.get_object (tmpgo.get_parent ()); - - if (tmpgo && tmpgo.get_handle () != 0.0) - currentObj = tmpgo; - else - currentObj = graphics_object (); - } - - // 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"; + switch (newMouseMode) + { + case NoMode: + { + // Update the figure "currentobject" + auto& fprop = Utils::properties
(figObj); - if (valid_axes) - Utils::properties
(figObj) - .set_currentaxes (axesObj.get_handle ().as_octave_value ()); - - Figure *fig = dynamic_cast
(qt_graphics_toolkit::toolkitObject (figObj)); - - MouseMode newMouseMode = NoMode; - - if (fig) - newMouseMode = fig->mouseMode (); + if (currentObj + && currentObj.get_properties ().handlevisibility_is ("on")) + fprop.set_currentobject (currentObj.get_handle () + .as_octave_value ()); + else + fprop.set_currentobject (Matrix ()); - switch (newMouseMode) - { - case NoMode: - { - // Update the figure "currentobject" - auto& fprop = Utils::properties
(figObj); + // Update figure "selectiontype" and "currentpoint" + emit gh_set_event (figObj.get_handle (), "selectiontype", + Utils::figureSelectionType (event, isdblclick), + false); - if (currentObj - && currentObj.get_properties ().handlevisibility_is ("on")) - fprop.set_currentobject (currentObj.get_handle () - .as_octave_value ()); - else - fprop.set_currentobject (Matrix ()); - - // Update figure "selectiontype" and "currentpoint" - emit gh_set_event (figObj.get_handle (), "selectiontype", - Utils::figureSelectionType (event, isdblclick), - false); - - updateCurrentPoint (figObj, obj, event); + updateCurrentPoint (figObj, obj, event); - emit gh_callback_event (figObj.get_handle (), - "windowbuttondownfcn", - button_number (event)); - - // Execute the "buttondownfcn" of the selected object. If the - // latter is empty then execute the figure "buttondownfcn" - if (currentObj && ! currentObj.get ("buttondownfcn").isempty ()) - emit gh_callback_event (currentObj.get_handle (), - "buttondownfcn", button_number (event)); - else if (figObj && ! figObj.get ("buttondownfcn").isempty ()) emit gh_callback_event (figObj.get_handle (), - "buttondownfcn", button_number (event)); - - // Show context menu of the selected object - if (currentObj && event->button () == Qt::RightButton) - ContextMenu::executeAt (m_interpreter, - currentObj.get_properties (), - event->globalPos ()); - } - break; + "windowbuttondownfcn", + button_number (event)); - case TextMode: - { - if (event->modifiers () == Qt::NoModifier) - { - switch (event->buttons ()) - { - case Qt::LeftButton: - m_mouseAnchor = m_mouseCurrent = event->pos (); - m_mouseMode = newMouseMode; - m_rectMode = true; - } - } - redraw (false); - } - break; + // Execute the "buttondownfcn" of the selected object. If the + // latter is empty then execute the figure "buttondownfcn" + if (currentObj && ! currentObj.get ("buttondownfcn").isempty ()) + emit gh_callback_event (currentObj.get_handle (), + "buttondownfcn", button_number (event)); + else if (figObj && ! figObj.get ("buttondownfcn").isempty ()) + emit gh_callback_event (figObj.get_handle (), + "buttondownfcn", button_number (event)); - case PanMode: - case RotateMode: - case ZoomInMode: - case ZoomOutMode: - if (valid_axes) - { - bool redraw_figure = true; + // Show context menu of the selected object + if (currentObj && event->button () == Qt::RightButton) + ContextMenu::executeAt (m_interpreter, + currentObj.get_properties (), + event->globalPos ()); + } + break; - if (isdblclick) - { - if (event->button () == Qt::LeftButton) - { - axes::properties& ap = Utils::properties (axesObj); - - autoscale_axes (gh_mgr, ap); - } - else - { - redraw_figure = false; - } - } - else if (event->modifiers () == Qt::NoModifier) + case TextMode: + { + if (event->modifiers () == Qt::NoModifier) { switch (event->buttons ()) { case Qt::LeftButton: m_mouseAnchor = m_mouseCurrent = event->pos (); - m_mouseAxes = axesObj.get_handle (); m_mouseMode = newMouseMode; - m_clickMode = newMouseMode == ZoomInMode; - break; + m_rectMode = true; + } + } + redraw (false); + } + break; - case Qt::RightButton: - if (newMouseMode == ZoomInMode) - { - m_mouseAnchor = m_mouseCurrent = event->pos (); - m_mouseAxes = axesObj.get_handle (); - m_mouseMode = newMouseMode; - m_clickMode = false; - } + case PanMode: + case RotateMode: + case ZoomInMode: + case ZoomOutMode: + if (valid_axes) + { + bool redraw_figure = true; - break; - - case Qt::MiddleButton: + if (isdblclick) + { + if (event->button () == Qt::LeftButton) { - axes::properties& ap = - Utils::properties (axesObj); + axes::properties& ap = Utils::properties (axesObj); autoscale_axes (gh_mgr, ap); } - break; + else + { + redraw_figure = false; + } + } + else if (event->modifiers () == Qt::NoModifier) + { + switch (event->buttons ()) + { + case Qt::LeftButton: + m_mouseAnchor = m_mouseCurrent = event->pos (); + m_mouseAxes = axesObj.get_handle (); + m_mouseMode = newMouseMode; + m_clickMode = newMouseMode == ZoomInMode; + break; - default: - redraw_figure = false; - break; - } - } - else if (event->modifiers () == Qt::ShiftModifier) - { - switch (event->buttons ()) - { - case Qt::LeftButton: - if (newMouseMode == ZoomInMode) - { - m_mouseAnchor = m_mouseCurrent = event->pos (); - m_mouseAxes = axesObj.get_handle (); - m_mouseMode = newMouseMode; - m_clickMode = false; - } - break; + case Qt::RightButton: + if (newMouseMode == ZoomInMode) + { + m_mouseAnchor = m_mouseCurrent = event->pos (); + m_mouseAxes = axesObj.get_handle (); + m_mouseMode = newMouseMode; + m_clickMode = false; + } + + break; - default: - redraw_figure = false; - break; - } - } + case Qt::MiddleButton: + { + axes::properties& ap = + Utils::properties (axesObj); - if (redraw_figure) - redraw (false); - } - break; + autoscale_axes (gh_mgr, ap); + } + break; - default: - break; - } - } - -} - -void -Canvas::canvasMouseReleaseEvent (QMouseEvent *event) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - if ((m_mouseMode == ZoomInMode || m_mouseMode == ZoomOutMode) - && m_mouseAxes.ok ()) - { - octave::autolock guard (gh_mgr.graphics_lock ()); + default: + redraw_figure = false; + break; + } + } + else if (event->modifiers () == Qt::ShiftModifier) + { + switch (event->buttons ()) + { + case Qt::LeftButton: + if (newMouseMode == ZoomInMode) + { + m_mouseAnchor = m_mouseCurrent = event->pos (); + m_mouseAxes = axesObj.get_handle (); + m_mouseMode = newMouseMode; + m_clickMode = false; + } + break; - graphics_object ax = gh_mgr.get_object (m_mouseAxes); + default: + redraw_figure = false; + break; + } + } - if (ax.valid_object ()) - { - axes::properties& ap = Utils::properties (ax); - - graphics_object obj = gh_mgr.get_object (m_handle); + if (redraw_figure) + redraw (false); + } + break; - graphics_object figObj (obj.get_ancestor ("figure")); + default: + break; + } + } - std::string zm = zoom_mode (figObj); + } - if (m_mouseAnchor == event->pos ()) - { - double factor = (m_clickMode ? 2.0 : 0.5); + void + Canvas::canvasMouseReleaseEvent (QMouseEvent *event) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - ColumnVector p1 = ap.pixel2coord (event->x (), event->y ()); + if ((m_mouseMode == ZoomInMode || m_mouseMode == ZoomOutMode) + && m_mouseAxes.ok ()) + { + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object ax = gh_mgr.get_object (m_mouseAxes); - ap.zoom_about_point (zm, p1(0), p1(1), factor); - } - else if (m_mouseMode == ZoomInMode) - { - ColumnVector p0 = ap.pixel2coord (m_mouseAnchor.x (), - m_mouseAnchor.y ()); - ColumnVector p1 = ap.pixel2coord (event->x (), - event->y ()); + if (ax.valid_object ()) + { + axes::properties& ap = Utils::properties (ax); + + graphics_object obj = gh_mgr.get_object (m_handle); + + graphics_object figObj (obj.get_ancestor ("figure")); - Matrix xl (1, 2, 0.0); - Matrix yl (1, 2, 0.0); + std::string zm = zoom_mode (figObj); + + if (m_mouseAnchor == event->pos ()) + { + double factor = (m_clickMode ? 2.0 : 0.5); + + ColumnVector p1 = ap.pixel2coord (event->x (), event->y ()); - xl(0) = std::min (p0(0), p1(0)); - xl(1) = std::max (p0(0), p1(0)); - yl(0) = std::min (p0(1), p1(1)); - yl(1) = std::max (p0(1), p1(1)); - - ap.zoom (zm, xl, yl); - } + ap.zoom_about_point (zm, p1(0), p1(1), factor); + } + else if (m_mouseMode == ZoomInMode) + { + ColumnVector p0 = ap.pixel2coord (m_mouseAnchor.x (), + m_mouseAnchor.y ()); + ColumnVector p1 = ap.pixel2coord (event->x (), + event->y ()); - redraw (false); - } - } - else if (m_mouseMode == NoMode) - { - octave::autolock guard (gh_mgr.graphics_lock ()); + Matrix xl (1, 2, 0.0); + Matrix yl (1, 2, 0.0); - graphics_object obj = gh_mgr.get_object (m_handle); - - if (obj.valid_object ()) - { - graphics_object figObj (obj.get_ancestor ("figure")); + xl(0) = std::min (p0(0), p1(0)); + xl(1) = std::max (p0(0), p1(0)); + yl(0) = std::min (p0(1), p1(1)); + yl(1) = std::max (p0(1), p1(1)); - updateCurrentPoint (figObj, obj, event); - emit gh_callback_event (figObj.get_handle (), "windowbuttonupfcn"); - } - } - else if (m_mouseMode == TextMode) - { - octave::autolock guard (gh_mgr.graphics_lock ()); + ap.zoom (zm, xl, yl); + } - graphics_object figObj - = gh_mgr.get_object (m_handle).get_ancestor ("figure"); + redraw (false); + } + } + else if (m_mouseMode == NoMode) + { + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object obj = gh_mgr.get_object (m_handle); - if (figObj.valid_object ()) - { - QWidget *w = qWidget (); - if (w) - { - Matrix bb = figObj.get ("position").matrix_value (); - bb(0) = m_mouseAnchor.x () / bb(2); - bb(1) = 1.0 - (m_mouseAnchor.y () / bb(3)); - bb(2) = (event->x () - m_mouseAnchor.x ()) / bb(2); - bb(3) = (m_mouseAnchor.y () - event->y ()) / bb(3); + if (obj.valid_object ()) + { + graphics_object figObj (obj.get_ancestor ("figure")); - octave_value_list props = ovl ("textbox", bb); + updateCurrentPoint (figObj, obj, event); + emit gh_callback_event (figObj.get_handle (), "windowbuttonupfcn"); + } + } + else if (m_mouseMode == TextMode) + { + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object figObj + = gh_mgr.get_object (m_handle).get_ancestor ("figure"); - annotation_dialog anno_dlg (m_octave_qobj, w, props); + if (figObj.valid_object ()) + { + QWidget *w = qWidget (); + if (w) + { + Matrix bb = figObj.get ("position").matrix_value (); + bb(0) = m_mouseAnchor.x () / bb(2); + bb(1) = 1.0 - (m_mouseAnchor.y () / bb(3)); + bb(2) = (event->x () - m_mouseAnchor.x ()) / bb(2); + bb(3) = (m_mouseAnchor.y () - event->y ()) / bb(3); - if (anno_dlg.exec () == QDialog::Accepted) - { - props = anno_dlg.get_properties (); - props.prepend (figObj.get_handle ().as_octave_value ()); - - emit interpreter_event - ([=] (octave::interpreter& interp) - { - // INTERPRETER THREAD + octave_value_list props = ovl ("textbox", bb); - interp.feval ("annotation", props); + annotation_dialog anno_dlg (w, props); + + if (anno_dlg.exec () == QDialog::Accepted) + { + props = anno_dlg.get_properties (); + props.prepend (figObj.get_handle ().as_octave_value ()); - redraw (); - }); - } - } - } - } - m_rectMode = false; - m_mouseAxes = graphics_handle (); - m_mouseMode = NoMode; -} + emit interpreter_event + ([=] (octave::interpreter& interp) + { + // INTERPRETER THREAD + + interp.feval ("annotation", props); -void -Canvas::canvasWheelEvent (QWheelEvent *event) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + redraw (); + }); + } + } + } + } + m_rectMode = false; + m_mouseAxes = graphics_handle (); + m_mouseMode = NoMode; + } - octave::autolock guard (gh_mgr.graphics_lock ()); - - graphics_object obj = gh_mgr.get_object (m_handle); + void + Canvas::canvasWheelEvent (QWheelEvent *event) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - if (obj.valid_object ()) - { - std::string mode; + octave::autolock guard (gh_mgr.graphics_lock ()); - graphics_object figObj (obj.get_ancestor ("figure")); + graphics_object obj = gh_mgr.get_object (m_handle); - graphics_object axesObj; + if (obj.valid_object ()) + { + std::string mode; - Matrix children = obj.get_properties ().get_children (); - octave_idx_type num_children = children.numel (); + graphics_object figObj (obj.get_ancestor ("figure")); + + graphics_object axesObj; - for (int i = 0; i < num_children; i++) - { - graphics_object childObj (gh_mgr.get_object (children(i))); + Matrix children = obj.get_properties ().get_children (); + octave_idx_type num_children = children.numel (); - if (childObj.isa ("axes")) - { + for (int i = 0; i < num_children; i++) + { + graphics_object childObj (gh_mgr.get_object (children(i))); + + if (childObj.isa ("axes")) + { #if defined (HAVE_QWHEELEVENT_POSITION) - QPoint pos = event->position().toPoint (); + QPoint pos = event->position().toPoint (); #else - QPoint pos = event->pos (); + QPoint pos = event->pos (); #endif - graphics_object go = selectFromAxes (childObj, pos); + graphics_object go = selectFromAxes (childObj, pos); - if (go) - { - axesObj = childObj; - break; - } - } - } + if (go) + { + axesObj = childObj; + break; + } + } + } - if (axesObj) - { - MouseMode newMouseMode = NoMode; + if (axesObj) + { + MouseMode newMouseMode = NoMode; - Figure *fig = dynamic_cast
(qt_graphics_toolkit::toolkitObject (figObj)); + Figure *fig = dynamic_cast
(qt_graphics_toolkit::toolkitObject (figObj)); - if (fig) - newMouseMode = fig->mouseMode (); + if (fig) + newMouseMode = fig->mouseMode (); - if (axesObj.get_properties ().handlevisibility_is ("on")) - { - Utils::properties
(figObj) + if (axesObj.get_properties ().handlevisibility_is ("on")) + { + Utils::properties
(figObj) .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 + if (zoom_enabled (figObj)) + { + if (event->angleDelta().y () > 0) newMouseMode = ZoomInMode; else newMouseMode = ZoomOutMode; - mode = zoom_mode (figObj); - } - else if (pan_enabled (figObj)) - { - newMouseMode = PanMode; + mode = zoom_mode (figObj); + } + else if (pan_enabled (figObj)) + { + newMouseMode = PanMode; - mode = pan_mode (figObj); - } - } + mode = pan_mode (figObj); + } + } - bool redrawFigure = true; + bool redrawFigure = true; - switch (newMouseMode) - { - case ZoomInMode: - case ZoomOutMode: + switch (newMouseMode) { - axes::properties& ap = Utils::properties (axesObj); + case ZoomInMode: + case ZoomOutMode: + { + axes::properties& ap = Utils::properties (axesObj); - // Control how fast to zoom when using scroll wheel. - double wheel_zoom_speed = ap.get_mousewheelzoom (); + // Control how fast to zoom when using scroll wheel. + double wheel_zoom_speed = ap.get_mousewheelzoom (); - // Determine if we're zooming in or out. - double factor = (newMouseMode == ZoomInMode - ? 1 / (1.0 - wheel_zoom_speed) - : 1.0 - wheel_zoom_speed); - - // FIXME: should we zoom about point for 2D plots? + // Determine if we're zooming in or out. + double factor = (newMouseMode == ZoomInMode + ? 1 / (1.0 - wheel_zoom_speed) + : 1.0 - wheel_zoom_speed); - ap.zoom (mode, factor); - } - break; + // FIXME: should we zoom about point for 2D plots? + + ap.zoom (mode, factor); + } + break; - case PanMode: - { - axes::properties& ap = Utils::properties (axesObj); + case PanMode: + { + 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 + double factor = (event->angleDelta().y () > 0 ? 0.1 : -0.1); - if (event->modifiers () == Qt::NoModifier - && mode != "horizontal") - ap.pan ("vertical", factor); - else if (event->modifiers () == Qt::ShiftModifier - && mode != "vertical") - ap.pan ("horizontal", factor); - } - break; + if (event->modifiers () == Qt::NoModifier + && mode != "horizontal") + ap.pan ("vertical", factor); + else if (event->modifiers () == Qt::ShiftModifier + && mode != "vertical") + ap.pan ("horizontal", factor); + } + break; - default: - redrawFigure = false; - break; - } + default: + redrawFigure = false; + break; + } - if (redrawFigure) - redraw (false); - } + if (redrawFigure) + redraw (false); + } - if (! figObj.get ("windowscrollwheelfcn").isempty ()) - { - octave_scalar_map eventData = Utils::makeScrollEventStruct (event); - emit gh_callback_event (m_handle, "windowscrollwheelfcn", - eventData); - } - } -} + if (! figObj.get ("windowscrollwheelfcn").isempty ()) + { + octave_scalar_map eventData = Utils::makeScrollEventStruct (event); + emit gh_callback_event (m_handle, "windowscrollwheelfcn", + eventData); + } + } + } -bool -Canvas::canvasKeyPressEvent (QKeyEvent *event) -{ - if (m_eventMask & KeyPress) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + bool + Canvas::canvasKeyPressEvent (QKeyEvent *event) + { + if (m_eventMask & KeyPress) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - graphics_object obj = gh_mgr.get_object (m_handle); + graphics_object obj = gh_mgr.get_object (m_handle); - if (obj.valid_object ()) - { - graphics_object figObj (obj.get_ancestor ("figure")); + if (obj.valid_object ()) + { + graphics_object figObj (obj.get_ancestor ("figure")); - updateCurrentPoint (figObj, obj); + updateCurrentPoint (figObj, obj); - octave_scalar_map eventData = Utils::makeKeyEventStruct (event); + octave_scalar_map eventData = Utils::makeKeyEventStruct (event); - emit gh_set_event (figObj.get_handle (), "currentcharacter", - eventData.getfield ("Character"), false); - emit gh_callback_event (figObj.get_handle (), "keypressfcn", - eventData); - } + emit gh_set_event (figObj.get_handle (), "currentcharacter", + eventData.getfield ("Character"), false); + emit gh_callback_event (figObj.get_handle (), "keypressfcn", + eventData); + } - return true; - } + return true; + } - return false; -} + return false; + } -bool -Canvas::canvasKeyReleaseEvent (QKeyEvent *event) -{ - if (! event->isAutoRepeat () && (m_eventMask & KeyRelease)) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + bool + Canvas::canvasKeyReleaseEvent (QKeyEvent *event) + { + if (! event->isAutoRepeat () && (m_eventMask & KeyRelease)) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - graphics_object obj = gh_mgr.get_object (m_handle); + graphics_object obj = gh_mgr.get_object (m_handle); - if (obj.valid_object ()) - { - graphics_object figObj (obj.get_ancestor ("figure")); - emit gh_callback_event (figObj.get_handle (), "keyreleasefcn", - Utils::makeKeyEventStruct (event)); - } + if (obj.valid_object ()) + { + graphics_object figObj (obj.get_ancestor ("figure")); + emit gh_callback_event (figObj.get_handle (), "keyreleasefcn", + Utils::makeKeyEventStruct (event)); + } - return true; - } + return true; + } - return false; -} + return false; + } -Canvas * -Canvas::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_handle& handle, QWidget *parent, - const std::string& /* name */) -{ - // Only OpenGL - return new GLCanvas (oct_qobj, interp, handle, parent); -} + Canvas * + Canvas::create (octave::interpreter& interp, + const graphics_handle& handle, QWidget *parent, + const std::string& /* name */) + { + // Only OpenGL + return new GLCanvas (interp, handle, parent); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Canvas.h --- a/libgui/graphics/Canvas.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Canvas.h Mon Jan 30 18:36:03 2023 +0100 @@ -43,129 +43,123 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class Canvas : public QObject -{ - Q_OBJECT + class Canvas : public QObject + { + Q_OBJECT -public: - enum EventMask + public: + enum EventMask { KeyPress = 0x01, KeyRelease = 0x02 }; -public: - virtual ~Canvas (void) = default; + public: + virtual ~Canvas () = default; - void redraw (bool sync = false); - void blockRedraw (bool block = true); + void redraw (bool sync = false); + void blockRedraw (bool block = true); - void print (const QString& file_cmd, const QString& term) - { - do_print (file_cmd, term, m_handle); - } + void print (const QString& file_cmd, const QString& term) + { + do_print (file_cmd, term, m_handle); + } - void addEventMask (int m) { m_eventMask |= m; } - void clearEventMask (int m) { m_eventMask &= (~m); } - void setEventMask (int m) { m_eventMask = m; } + void addEventMask (int m) { m_eventMask |= m; } + void clearEventMask (int m) { m_eventMask &= (~m); } + void setEventMask (int m) { m_eventMask = m; } - void setCursor (MouseMode mode, std::string fallback, - QImage cdata, Matrix hotspot); + 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); + static Canvas * + 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: + signals: + + void interpreter_event (const octave::fcn_callback& fcn); + void interpreter_event (const octave::meth_callback& meth); - void interpreter_event (const octave::fcn_callback& fcn); - void interpreter_event (const octave::meth_callback& meth); + void gh_callback_event (const graphics_handle& h, const std::string& name); - void gh_callback_event (const graphics_handle& h, const std::string& name); + void gh_callback_event (const graphics_handle& h, const std::string& name, + const octave_value& data); - void gh_callback_event (const graphics_handle& h, const std::string& name, - const octave_value& data); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value); - - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit, - bool redraw_figure); -protected: - virtual void draw (const graphics_handle& handle) = 0; - virtual void drawZoomBox (const QPoint& p1, const QPoint& p2) = 0; - virtual void resize (int x, int y, int width, int height) = 0; - virtual graphics_object selectFromAxes (const graphics_object& ax, - const QPoint& pt) = 0; - virtual uint8NDArray do_getPixels (const graphics_handle& handle) = 0; - virtual void do_print (const QString& file_cmd, const QString& term, - const graphics_handle& handle) = 0; + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit, + bool redraw_figure); + protected: + virtual void draw (const graphics_handle& handle) = 0; + virtual void drawZoomBox (const QPoint& p1, const QPoint& p2) = 0; + virtual void resize (int x, int y, int width, int height) = 0; + virtual graphics_object selectFromAxes (const graphics_object& ax, + const QPoint& pt) = 0; + virtual uint8NDArray do_getPixels (const graphics_handle& handle) = 0; + virtual void do_print (const QString& file_cmd, const QString& term, + 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) - { } + protected: + + 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) + { } - void canvasToggleAxes (const graphics_handle& handle); - void canvasToggleGrid (const graphics_handle& handle); - void canvasAutoAxes (const graphics_handle& handle); - void canvasPaintEvent (void); - void canvasMouseDoubleClickEvent (QMouseEvent *event); - void canvasMouseMoveEvent (QMouseEvent *event); - void canvasMousePressEvent (QMouseEvent *event); - void canvasMouseReleaseEvent (QMouseEvent *event); - void canvasWheelEvent (QWheelEvent *event); - bool canvasKeyPressEvent (QKeyEvent *event); - bool canvasKeyReleaseEvent (QKeyEvent *event); + public: + void canvasToggleAxes (const graphics_handle& handle); + void canvasToggleGrid (const graphics_handle& handle); + void canvasAutoAxes (const graphics_handle& handle); + void canvasPaintEvent (); + void canvasMouseDoubleClickEvent (QMouseEvent *event); + void canvasMouseMoveEvent (QMouseEvent *event); + void canvasMousePressEvent (QMouseEvent *event); + void canvasMouseReleaseEvent (QMouseEvent *event); + void canvasWheelEvent (QWheelEvent *event); + bool canvasKeyPressEvent (QKeyEvent *event); + bool canvasKeyReleaseEvent (QKeyEvent *event); - void updateCurrentPoint (const graphics_object& fig, - const graphics_object& obj, QMouseEvent *event); - void updateCurrentPoint (const graphics_object& fig, - const graphics_object& obj); + void updateCurrentPoint (const graphics_object& fig, + const graphics_object& obj, QMouseEvent *event); + void updateCurrentPoint (const graphics_object& fig, + const graphics_object& obj); - void select_object (graphics_object obj, QMouseEvent *event, - graphics_object& currentObj, graphics_object& axesObj, - bool axes_only = false, - std::vector omit = std::vector ()); + void select_object (graphics_object obj, QMouseEvent *event, + graphics_object& currentObj, graphics_object& axesObj, + bool axes_only = false, + std::vector omit = std::vector ()); -protected: - octave::base_qobject& m_octave_qobj; - octave::interpreter& m_interpreter; + protected: -private: + 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; - MouseMode m_mouseMode; - bool m_clickMode; // True: ZoomIn, False: ZoomOut - QPoint m_mouseAnchor; - QPoint m_mouseCurrent; - graphics_handle m_mouseAxes; - int m_eventMask; - bool m_rectMode; -}; + graphics_handle m_handle; + bool m_redrawBlocked; + MouseMode m_mouseMode; + bool m_clickMode; // True: ZoomIn, False: ZoomOut + QPoint m_mouseAnchor; + QPoint m_mouseCurrent; + graphics_handle m_mouseAxes; + int m_eventMask; + bool m_rectMode; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/CheckBoxControl.cc --- a/libgui/graphics/CheckBoxControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/CheckBoxControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,66 +32,62 @@ #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, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + CheckBoxControl * + CheckBoxControl::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - return new CheckBoxControl (oct_qobj, interp, go, - new QCheckBox (container)); - } + if (container) + return new CheckBoxControl (interp, go, + new QCheckBox (container)); + } - return nullptr; -} + return nullptr; + } -CheckBoxControl::CheckBoxControl (octave::base_qobject& oct_obj, - octave::interpreter& interp, - const graphics_object& go, QCheckBox *box) - : ButtonControl (oct_obj, interp, go, box) -{ - uicontrol::properties& up = properties (); + CheckBoxControl::CheckBoxControl (octave::interpreter& interp, + const graphics_object& go, QCheckBox *box) + : ButtonControl (interp, go, box) + { + uicontrol::properties& up = properties (); - box->setAutoFillBackground (true); - if (up.enable_is ("inactive")) - box->setCheckable (false); -} + box->setAutoFillBackground (true); + if (up.enable_is ("inactive")) + box->setCheckable (false); + } -CheckBoxControl::~CheckBoxControl (void) -{ } + CheckBoxControl::~CheckBoxControl () + { } -void -CheckBoxControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QCheckBox *box = qWidget (); + void + CheckBoxControl::update (int pId) + { + uicontrol::properties& up = properties (); + QCheckBox *box = qWidget (); - switch (pId) - { - case uicontrol::properties::ID_ENABLE: + switch (pId) { - if (up.enable_is ("inactive")) - box->setCheckable (false); - else - box->setCheckable (true); + case uicontrol::properties::ID_ENABLE: + { + if (up.enable_is ("inactive")) + box->setCheckable (false); + else + box->setCheckable (true); + ButtonControl::update (pId); + } + break; + + default: ButtonControl::update (pId); + break; } - break; - - default: - ButtonControl::update (pId); - break; - } -} + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/CheckBoxControl.h --- a/libgui/graphics/CheckBoxControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/CheckBoxControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,24 +32,22 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class CheckBoxControl : public ButtonControl -{ -public: - CheckBoxControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, - QCheckBox *box); - ~CheckBoxControl (void); + class CheckBoxControl : public ButtonControl + { + public: + CheckBoxControl (octave::interpreter& interp, const graphics_object& go, + QCheckBox *box); + ~CheckBoxControl (); - static CheckBoxControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static CheckBoxControl * + create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); -}; + protected: + void update (int pId); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Container.cc --- a/libgui/graphics/Container.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Container.cc Mon Jan 30 18:36:03 2023 +0100 @@ -40,149 +40,147 @@ 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) -{ - setFocusPolicy (Qt::ClickFocus); -} + Container::Container (QWidget *xparent, octave::interpreter& interp) + : ContainerBase (xparent), m_interpreter (interp), m_canvas (nullptr) + { + setFocusPolicy (Qt::ClickFocus); + } -Container::~Container (void) -{ } + Container::~Container () + { } + + Canvas * + Container::canvas (const graphics_handle& gh, bool xcreate) + { + if (! m_canvas && xcreate) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); -Canvas * -Container::canvas (const graphics_handle& gh, bool xcreate) -{ - if (! m_canvas && xcreate) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object go = gh_mgr.get_object (gh); - octave::autolock guard (gh_mgr.graphics_lock ()); + if (go) + { + graphics_object fig = go.get_ancestor ("figure"); - graphics_object go = gh_mgr.get_object (gh); - - if (go) - { - graphics_object fig = go.get_ancestor ("figure"); + m_canvas = Canvas::create (m_interpreter, gh, this, + fig.get ("renderer").string_value ()); - m_canvas = Canvas::create (m_octave_qobj, m_interpreter, gh, this, - fig.get ("renderer").string_value ()); + connect (m_canvas, QOverload::of (&Canvas::interpreter_event), + this, QOverload::of (&Container::interpreter_event)); - connect (m_canvas, QOverload::of (&Canvas::interpreter_event), - this, QOverload::of (&Container::interpreter_event)); + connect (m_canvas, QOverload::of (&Canvas::interpreter_event), + this, QOverload::of (&Container::interpreter_event)); - connect (m_canvas, QOverload::of (&Canvas::interpreter_event), - this, QOverload::of (&Container::interpreter_event)); + connect (m_canvas, + SIGNAL (gh_callback_event (const graphics_handle&, + const std::string&)), + this, + SIGNAL (gh_callback_event (const graphics_handle&, + const std::string&))); - connect (m_canvas, - SIGNAL (gh_callback_event (const graphics_handle&, - const std::string&)), - this, - SIGNAL (gh_callback_event (const graphics_handle&, - const std::string&))); + connect (m_canvas, + SIGNAL (gh_callback_event (const graphics_handle&, + const std::string&, + const octave_value&)), + this, + SIGNAL (gh_callback_event (const graphics_handle&, + const std::string&, + const octave_value&))); - connect (m_canvas, - SIGNAL (gh_callback_event (const graphics_handle&, - const std::string&, - const octave_value&)), - this, - SIGNAL (gh_callback_event (const graphics_handle&, - const std::string&, - const octave_value&))); + connect (m_canvas, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&)), + this, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&))); - connect (m_canvas, - SIGNAL (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&)), - this, - SIGNAL (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&))); - - connect (m_canvas, - SIGNAL (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&, bool)), - this, - SIGNAL (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&, bool))); + connect (m_canvas, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&, bool)), + this, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&, bool))); - connect (m_canvas, - SIGNAL (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&, bool, bool)), - this, - SIGNAL (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&, bool, bool))); + connect (m_canvas, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&, bool, bool)), + this, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&, bool, bool))); - QWidget *canvasWidget = m_canvas->qWidget (); + QWidget *canvasWidget = m_canvas->qWidget (); - canvasWidget->lower (); - canvasWidget->show (); - canvasWidget->setGeometry (0, 0, width (), height ()); - } - } + canvasWidget->lower (); + canvasWidget->show (); + canvasWidget->setGeometry (0, 0, width (), height ()); + } + } - return m_canvas; -} + return m_canvas; + } -void -Container::resizeEvent (QResizeEvent * /* event */) -{ - if (m_canvas) - m_canvas->qWidget ()->setGeometry (0, 0, width (), height ()); + void + Container::resizeEvent (QResizeEvent * /* event */) + { + if (m_canvas) + m_canvas->qWidget ()->setGeometry (0, 0, width (), height ()); - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - for (auto *qObj : children ()) - { - if (qObj->isWidgetType ()) - { - Object *obj = Object::fromQObject (qObj); + for (auto *qObj : children ()) + { + if (qObj->isWidgetType ()) + { + Object *obj = Object::fromQObject (qObj); - if (obj) - { - graphics_object go = obj->object (); + if (obj) + { + graphics_object go = obj->object (); - if (go.valid_object ()) - { - Matrix bb = go.get_properties ().get_boundingbox (false); + if (go.valid_object ()) + { + Matrix bb = go.get_properties ().get_boundingbox (false); - obj->qWidget ()->setGeometry - (octave::math::round (bb(0)), - octave::math::round (bb(1)), - octave::math::round (bb(2)), - octave::math::round (bb(3))); - } - } - } - } -} + obj->qWidget ()->setGeometry + (octave::math::round (bb(0)), + octave::math::round (bb(1)), + octave::math::round (bb(2)), + octave::math::round (bb(3))); + } + } + } + } + } -void -Container::childEvent (QChildEvent *xevent) -{ - // Enable mouse tracking in child widgets as they are added if the - // container also has mouse tracking enabled. There is no need to - // do this when child objects are removed. + void + Container::childEvent (QChildEvent *xevent) + { + // Enable mouse tracking in child widgets as they are added if the + // container also has mouse tracking enabled. There is no need to + // do this when child objects are removed. - if (xevent->added ()) - { - QObject *obj = xevent->child (); + if (xevent->added ()) + { + QObject *obj = xevent->child (); - if (obj && obj->isWidgetType ()) - { - QWidget *widget = qobject_cast (obj); + if (obj && obj->isWidgetType ()) + { + QWidget *widget = qobject_cast (obj); - if (widget) - widget->setMouseTracking (hasMouseTracking ()); - } - } -} + if (widget) + widget->setMouseTracking (hasMouseTracking ()); + } + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Container.h --- a/libgui/graphics/Container.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Container.h Mon Jan 30 18:36:03 2023 +0100 @@ -35,55 +35,48 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -} + DECLARE_GENERICEVENTNOTIFY_SENDER(ContainerBase, QWidget); + + class Canvas; -OCTAVE_BEGIN_NAMESPACE(octave) - -DECLARE_GENERICEVENTNOTIFY_SENDER(ContainerBase, QWidget); - -class Canvas; + class Container : public ContainerBase + { + Q_OBJECT -class Container : public ContainerBase -{ - Q_OBJECT + public: + Container (QWidget *parent, octave::interpreter& interp); + ~Container (); + + Canvas * canvas (const graphics_handle& handle, bool create = true); -public: - Container (QWidget *parent, octave::base_qobject& oct_qobj, - octave::interpreter& interp); - ~Container (void); + signals: - Canvas * canvas (const graphics_handle& handle, bool create = true); + void interpreter_event (const octave::fcn_callback& fcn); + void interpreter_event (const octave::meth_callback& meth); -signals: - - void interpreter_event (const octave::fcn_callback& fcn); - void interpreter_event (const octave::meth_callback& meth); + void gh_callback_event (const graphics_handle& h, const std::string& name); - void gh_callback_event (const graphics_handle& h, const std::string& name); - - void gh_callback_event (const graphics_handle& h, const std::string& name, - const octave_value& data); + void gh_callback_event (const graphics_handle& h, const std::string& name, + const octave_value& data); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit, - bool redraw_figure); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit, + bool redraw_figure); -protected: - void childEvent (QChildEvent *event); - void resizeEvent (QResizeEvent *event); + protected: + void childEvent (QChildEvent *event); + void resizeEvent (QResizeEvent *event); -private: - octave::base_qobject& m_octave_qobj; - octave::interpreter& m_interpreter; - Canvas *m_canvas; -}; + private: + octave::interpreter& m_interpreter; + Canvas *m_canvas; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ContextMenu.cc --- a/libgui/graphics/ContextMenu.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ContextMenu.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,118 +33,114 @@ #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) -{ - Object *xparent = parentObject (interp, go); + ContextMenu * + ContextMenu::create (octave::interpreter& interp, const graphics_object& go) + { + Object *xparent = parentObject (interp, go); - if (xparent) - { - QWidget *w = xparent->qWidget (); + if (xparent) + { + QWidget *w = xparent->qWidget (); - return new ContextMenu (oct_qobj, interp, go, new QMenu (w)); - } + return new ContextMenu (interp, go, new QMenu (w)); + } - return nullptr; -} + return nullptr; + } -ContextMenu::ContextMenu (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, QMenu *xmenu) - : Object (oct_qobj, interp, go, xmenu) -{ - xmenu->setAutoFillBackground (true); + ContextMenu::ContextMenu (octave::interpreter& interp, + const graphics_object& go, QMenu *xmenu) + : Object (interp, go, xmenu) + { + xmenu->setAutoFillBackground (true); - connect (xmenu, &QMenu::aboutToShow, this, &ContextMenu::aboutToShow); - connect (xmenu, &QMenu::aboutToHide, this, &ContextMenu::aboutToHide); -} + connect (xmenu, &QMenu::aboutToShow, this, &ContextMenu::aboutToShow); + connect (xmenu, &QMenu::aboutToHide, this, &ContextMenu::aboutToHide); + } -ContextMenu::~ContextMenu (void) -{ } + ContextMenu::~ContextMenu () + { } -void -ContextMenu::update (int pId) -{ - uicontextmenu::properties& up = properties (); - QMenu *xmenu = qWidget (); + void + ContextMenu::update (int pId) + { + uicontextmenu::properties& up = properties (); + QMenu *xmenu = qWidget (); - switch (pId) - { - case base_properties::ID_VISIBLE: - if (up.is_visible ()) - { - Matrix pos = up.get_position ().matrix_value (); - QWidget *parentW = xmenu->parentWidget (); - QPoint pt; + switch (pId) + { + case base_properties::ID_VISIBLE: + if (up.is_visible ()) + { + Matrix pos = up.get_position ().matrix_value (); + QWidget *parentW = xmenu->parentWidget (); + QPoint pt; - pt.rx () = octave::math::round (pos(0)); - pt.ry () = parentW->height () - octave::math::round (pos(1)); - pt = parentW->mapToGlobal (pt); + pt.rx () = octave::math::round (pos(0)); + pt.ry () = parentW->height () - octave::math::round (pos(1)); + pt = parentW->mapToGlobal (pt); - xmenu->popup (pt); - } - else - xmenu->hide (); - break; - default: - Object::update (pId); - break; - } -} + xmenu->popup (pt); + } + else + xmenu->hide (); + break; + default: + Object::update (pId); + break; + } + } -void -ContextMenu::aboutToShow (void) -{ - emit gh_callback_event (m_handle, "callback"); - emit gh_set_event (m_handle, "visible", "on", false); -} + void + ContextMenu::aboutToShow () + { + emit gh_callback_event (m_handle, "callback"); + emit gh_set_event (m_handle, "visible", "on", false); + } -void -ContextMenu::aboutToHide (void) -{ - emit gh_set_event (m_handle, "visible", "off", false); -} + void + ContextMenu::aboutToHide () + { + emit gh_set_event (m_handle, "visible", "off", false); + } -QWidget * -ContextMenu::menu (void) -{ - return qWidget (); -} + QWidget * + ContextMenu::menu () + { + return qWidget (); + } -void -ContextMenu::executeAt (octave::interpreter& interp, - const base_properties& props, const QPoint& pt) -{ - graphics_handle h = props.get_uicontextmenu (); + void + ContextMenu::executeAt (octave::interpreter& interp, + const base_properties& props, const QPoint& pt) + { + graphics_handle h = props.get_uicontextmenu (); - if (h.ok ()) - { - gh_manager& gh_mgr = interp.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + if (h.ok ()) + { + gh_manager& gh_mgr = interp.get_gh_manager (); + octave::autolock guard (gh_mgr.graphics_lock ()); - graphics_object go = gh_mgr.get_object (h); + graphics_object go = gh_mgr.get_object (h); - if (go.valid_object ()) - { - ContextMenu *cMenu = - dynamic_cast (qt_graphics_toolkit::toolkitObject (go)); + if (go.valid_object ()) + { + ContextMenu *cMenu = + dynamic_cast (qt_graphics_toolkit::toolkitObject (go)); - if (cMenu) - { - QMenu *menu = cMenu->qWidget (); + if (cMenu) + { + QMenu *menu = cMenu->qWidget (); - if (menu) - menu->popup (pt); - } - } - } -} + if (menu) + menu->popup (pt); + } + } + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ContextMenu.h --- a/libgui/graphics/ContextMenu.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ContextMenu.h Mon Jan 30 18:36:03 2023 +0100 @@ -35,36 +35,35 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; + + class ContextMenu : public Object, public MenuContainer + { + Q_OBJECT -class ContextMenu : public Object, public MenuContainer -{ - Q_OBJECT + public: + ContextMenu (octave::interpreter& interp, + const graphics_object& go, QMenu *menu); + ~ContextMenu (); -public: - ContextMenu (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QMenu *menu); - ~ContextMenu (void); + static ContextMenu * + create (octave::interpreter& interp, + const graphics_object& go); - static ContextMenu * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static void executeAt (octave::interpreter& interp, + const base_properties& props, const QPoint& pt); - static void executeAt (octave::interpreter& interp, - const base_properties& props, const QPoint& pt); + Container * innerContainer () { return nullptr; } - Container * innerContainer (void) { return nullptr; } + QWidget * menu (); - QWidget * menu (void); - -protected: - void update (int pId); + protected: + void update (int pId); -private slots: - void aboutToShow (void); - void aboutToHide (void); -}; + private slots: + void aboutToShow (); + void aboutToHide (); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/EditControl.cc --- a/libgui/graphics/EditControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/EditControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,280 +34,275 @@ #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) -{ - Object *parent = parentObject (interp, go); + EditControl * + EditControl::create (octave::interpreter& interp, const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - { - uicontrol::properties& up = Utils::properties (go); + if (container) + { + uicontrol::properties& up = Utils::properties (go); - if ((up.get_max () - up.get_min ()) > 1) - return new EditControl (oct_qobj, interp, go, - new TextEdit (container)); - else - return new EditControl (oct_qobj, interp, go, - new QLineEdit (container)); - } - } + if ((up.get_max () - up.get_min ()) > 1) + return new EditControl (interp, go, + new TextEdit (container)); + else + return new EditControl (interp, go, + new QLineEdit (container)); + } + } - return nullptr; -} + return nullptr; + } -EditControl::EditControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, QLineEdit *edit) - : BaseControl (oct_qobj, interp, go, edit), m_multiLine (false), - m_textChanged (false) -{ - init (edit); -} + EditControl::EditControl (octave::interpreter& interp, + const graphics_object& go, QLineEdit *edit) + : BaseControl (interp, go, edit), m_multiLine (false), + m_textChanged (false) + { + init (edit); + } -void -EditControl::init (QLineEdit *edit, bool callBase) -{ - if (callBase) - BaseControl::init (edit, callBase); + void + EditControl::init (QLineEdit *edit, bool callBase) + { + if (callBase) + BaseControl::init (edit, callBase); - m_multiLine = false; - initCommon (edit); + m_multiLine = false; + initCommon (edit); - uicontrol::properties& up = properties (); + uicontrol::properties& up = properties (); - if (up.enable_is ("inactive")) - edit->setReadOnly (true); - else - edit->setEnabled (up.enable_is ("on")); - edit->setText (Utils::fromStdString (up.get_string_string ())); - edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), - up.get_verticalalignment ())); + if (up.enable_is ("inactive")) + edit->setReadOnly (true); + else + edit->setEnabled (up.enable_is ("on")); + edit->setText (Utils::fromStdString (up.get_string_string ())); + edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), + up.get_verticalalignment ())); - connect (edit, &QLineEdit::textEdited, - this, &EditControl::textChanged); - connect (edit, &QLineEdit::editingFinished, - this, &EditControl::editingFinished); - connect (edit, &QLineEdit::returnPressed, - this, &EditControl::returnPressed); -} + connect (edit, &QLineEdit::textEdited, + this, &EditControl::textChanged); + connect (edit, &QLineEdit::editingFinished, + this, &EditControl::editingFinished); + connect (edit, &QLineEdit::returnPressed, + this, &EditControl::returnPressed); + } -EditControl::EditControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, TextEdit *edit) - : BaseControl (oct_qobj, interp, go, edit), m_multiLine (true), - m_textChanged (false) -{ - init (edit); -} + EditControl::EditControl (octave::interpreter& interp, + const graphics_object& go, TextEdit *edit) + : BaseControl (interp, go, edit), m_multiLine (true), + m_textChanged (false) + { + init (edit); + } -void -EditControl::init (TextEdit *edit, bool callBase) -{ - if (callBase) - BaseControl::init (edit, callBase); + void + EditControl::init (TextEdit *edit, bool callBase) + { + if (callBase) + BaseControl::init (edit, callBase); - m_multiLine = true; - initCommon (edit); + m_multiLine = true; + initCommon (edit); - uicontrol::properties& up = properties (); + uicontrol::properties& up = properties (); - if (up.enable_is ("inactive")) - edit->setReadOnly (true); - else - edit->setEnabled (up.enable_is ("on")); - edit->setAcceptRichText (false); - edit->setPlainText (Utils::fromStringVector - (up.get_string_vector ()).join ("\n")); - edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), - up.get_verticalalignment ())); + if (up.enable_is ("inactive")) + edit->setReadOnly (true); + else + edit->setEnabled (up.enable_is ("on")); + edit->setAcceptRichText (false); + edit->setPlainText (Utils::fromStringVector + (up.get_string_vector ()).join ("\n")); + edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), + up.get_verticalalignment ())); - connect (edit, &TextEdit::textChanged, - this, &EditControl::textChanged); - connect (edit, &TextEdit::editingFinished, - this, &EditControl::editingFinished); - connect (edit, &TextEdit::returnPressed, - this, &EditControl::returnPressed); -} + connect (edit, &TextEdit::textChanged, + this, &EditControl::textChanged); + connect (edit, &TextEdit::editingFinished, + this, &EditControl::editingFinished); + connect (edit, &TextEdit::returnPressed, + this, &EditControl::returnPressed); + } -EditControl::~EditControl (void) -{ } + EditControl::~EditControl () + { } -void -EditControl::initCommon (QWidget *) -{ - m_textChanged = false; -} + void + EditControl::initCommon (QWidget *) + { + m_textChanged = false; + } -void -EditControl::update (int pId) -{ - bool handled = false; + void + EditControl::update (int pId) + { + bool handled = false; - if (m_multiLine) - handled = updateMultiLine (pId); - else - handled = updateSingleLine (pId); + if (m_multiLine) + handled = updateMultiLine (pId); + else + handled = updateSingleLine (pId); - if (! handled) - { - switch (pId) - { - default: - BaseControl::update (pId); - break; - } - } -} + if (! handled) + { + switch (pId) + { + default: + BaseControl::update (pId); + break; + } + } + } -bool -EditControl::updateSingleLine (int pId) -{ - uicontrol::properties& up = properties (); - QLineEdit *edit = qWidget (); + bool + EditControl::updateSingleLine (int pId) + { + uicontrol::properties& up = properties (); + QLineEdit *edit = qWidget (); - switch (pId) - { - case uicontrol::properties::ID_STRING: - edit->setText (Utils::fromStdString (up.get_string_string ())); - return true; + switch (pId) + { + case uicontrol::properties::ID_STRING: + edit->setText (Utils::fromStdString (up.get_string_string ())); + return true; - case uicontrol::properties::ID_HORIZONTALALIGNMENT: - case uicontrol::properties::ID_VERTICALALIGNMENT: - edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), - up.get_verticalalignment ())); - return true; + case uicontrol::properties::ID_HORIZONTALALIGNMENT: + case uicontrol::properties::ID_VERTICALALIGNMENT: + edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), + up.get_verticalalignment ())); + return true; - case uicontrol::properties::ID_ENABLE: - if (up.enable_is ("inactive")) - edit->setReadOnly (true); - else - { - edit->setReadOnly (false); - edit->setEnabled (up.enable_is ("on")); - } - return true; + case uicontrol::properties::ID_ENABLE: + if (up.enable_is ("inactive")) + edit->setReadOnly (true); + else + { + edit->setReadOnly (false); + edit->setEnabled (up.enable_is ("on")); + } + return true; - case uicontrol::properties::ID_MIN: - case uicontrol::properties::ID_MAX: - if ((up.get_max () - up.get_min ()) > 1) - { - QWidget *container = edit->parentWidget (); + case uicontrol::properties::ID_MIN: + case uicontrol::properties::ID_MAX: + if ((up.get_max () - up.get_min ()) > 1) + { + QWidget *container = edit->parentWidget (); - delete edit; - init (new TextEdit (container), true); - } - return true; + delete edit; + init (new TextEdit (container), true); + } + return true; - default: - break; - } + default: + break; + } - return false; -} + return false; + } -bool -EditControl::updateMultiLine (int pId) -{ - uicontrol::properties& up = properties (); - TextEdit *edit = qWidget (); + bool + EditControl::updateMultiLine (int pId) + { + uicontrol::properties& up = properties (); + TextEdit *edit = qWidget (); - switch (pId) - { - case uicontrol::properties::ID_STRING: - edit->setPlainText (Utils::fromStringVector - (up.get_string_vector ()).join ("\n")); - return true; + switch (pId) + { + case uicontrol::properties::ID_STRING: + edit->setPlainText (Utils::fromStringVector + (up.get_string_vector ()).join ("\n")); + return true; - case uicontrol::properties::ID_HORIZONTALALIGNMENT: - case uicontrol::properties::ID_VERTICALALIGNMENT: - edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), - up.get_verticalalignment ())); - return true; + case uicontrol::properties::ID_HORIZONTALALIGNMENT: + case uicontrol::properties::ID_VERTICALALIGNMENT: + edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), + up.get_verticalalignment ())); + return true; - case uicontrol::properties::ID_ENABLE: - if (up.enable_is ("inactive")) - edit->setReadOnly (true); - else - { - edit->setReadOnly (false); - edit->setEnabled (up.enable_is ("on")); - } - return true; + case uicontrol::properties::ID_ENABLE: + if (up.enable_is ("inactive")) + edit->setReadOnly (true); + else + { + edit->setReadOnly (false); + edit->setEnabled (up.enable_is ("on")); + } + return true; - case uicontrol::properties::ID_MIN: - case uicontrol::properties::ID_MAX: - if ((up.get_max () - up.get_min ()) <= 1) - { - QWidget *container = edit->parentWidget (); + case uicontrol::properties::ID_MIN: + case uicontrol::properties::ID_MAX: + if ((up.get_max () - up.get_min ()) <= 1) + { + QWidget *container = edit->parentWidget (); - delete edit; - init (new QLineEdit (container), true); - } - return true; + delete edit; + init (new QLineEdit (container), true); + } + return true; - default: - break; - } + default: + break; + } - return false; -} + return false; + } -void -EditControl::textChanged (void) -{ - m_textChanged = true; -} + void + EditControl::textChanged () + { + m_textChanged = true; + } -void -EditControl::returnPressed (void) -{ - QString txt = (m_multiLine - ? qWidget ()->toPlainText () - : qWidget ()->text ()); + void + EditControl::returnPressed () + { + QString txt = (m_multiLine + ? qWidget ()->toPlainText () + : qWidget ()->text ()); - if (m_textChanged) - { - if (m_multiLine) - emit gh_set_event (m_handle, "string", - Utils::toCellString (txt.split ("\n")), false); - else - emit gh_set_event (m_handle, "string", - Utils::toStdString (txt), false); + if (m_textChanged) + { + if (m_multiLine) + emit gh_set_event (m_handle, "string", + Utils::toCellString (txt.split ("\n")), false); + else + emit gh_set_event (m_handle, "string", + Utils::toStdString (txt), false); - m_textChanged = false; - } + m_textChanged = false; + } - if (txt.length () > 0) - emit gh_callback_event (m_handle, "callback"); -} + if (txt.length () > 0) + emit gh_callback_event (m_handle, "callback"); + } -void -EditControl::editingFinished (void) -{ - if (m_textChanged) - { - QString txt = (m_multiLine - ? qWidget ()->toPlainText () - : qWidget ()->text ()); - if (m_multiLine) - emit gh_set_event (m_handle, "string", - Utils::toCellString (txt.split ("\n")), false); - else - emit gh_set_event (m_handle, "string", Utils::toStdString (txt), - false); - emit gh_callback_event (m_handle, "callback"); + void + EditControl::editingFinished () + { + if (m_textChanged) + { + QString txt = (m_multiLine + ? qWidget ()->toPlainText () + : qWidget ()->text ()); + if (m_multiLine) + emit gh_set_event (m_handle, "string", + Utils::toCellString (txt.split ("\n")), false); + else + emit gh_set_event (m_handle, "string", Utils::toStdString (txt), + false); + emit gh_callback_event (m_handle, "callback"); - m_textChanged = false; - } -} + m_textChanged = false; + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/EditControl.h --- a/libgui/graphics/EditControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/EditControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,47 +33,46 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; + + class TextEdit; -class TextEdit; - -class EditControl : public BaseControl -{ - Q_OBJECT + class EditControl : public BaseControl + { + Q_OBJECT -public: - EditControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QLineEdit *edit); + public: + EditControl (octave::interpreter& interp, + const graphics_object& go, QLineEdit *edit); - EditControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, TextEdit *edit); + EditControl (octave::interpreter& interp, + const graphics_object& go, TextEdit *edit); - ~EditControl (void); + ~EditControl (); - static EditControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static EditControl * + create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); + protected: + void update (int pId); -private: - void init (QLineEdit *edit, bool callBase = false); - void init (TextEdit *edit, bool callBase = false); - void initCommon (QWidget *widget); - bool updateSingleLine (int pId); - bool updateMultiLine (int pId); + private: + void init (QLineEdit *edit, bool callBase = false); + void init (TextEdit *edit, bool callBase = false); + void initCommon (QWidget *widget); + bool updateSingleLine (int pId); + bool updateMultiLine (int pId); -private slots: - void textChanged (void); - void editingFinished (void); - void returnPressed (void); + private slots: + void textChanged (); + void editingFinished (); + void returnPressed (); -private: - bool m_multiLine; - bool m_textChanged; -}; + private: + bool m_multiLine; + bool m_textChanged; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Figure.cc --- a/libgui/graphics/Figure.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Figure.cc Mon Jan 30 18:36:03 2023 +0100 @@ -43,10 +43,8 @@ #include #include #include -#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO) -# include -# include -#endif +#include +#include #include "Canvas.h" #include "Container.h" @@ -67,840 +65,859 @@ OCTAVE_BEGIN_NAMESPACE(octave) -DECLARE_GENERICEVENTNOTIFY_SENDER(MenuBar, QMenuBar); + DECLARE_GENERICEVENTNOTIFY_SENDER(MenuBar, QMenuBar); + + static QRect + boundingBoxToRect (const Matrix& bb) + { + QRect r; + + if (bb.numel () == 4) + { + r = QRect (octave::math::round (bb(0)), octave::math::round (bb(1)), + octave::math::round (bb(2)), octave::math::round (bb(3))); + if (! r.isValid ()) + r = QRect (); + } + + return r; + } -static QRect -boundingBoxToRect (const Matrix& bb) -{ - QRect r; + static QImage + pointer_to_qimage (const Matrix& cdata) + { + QImage retval (cdata.rows (), cdata.columns (), QImage::Format_ARGB32); + QColor tmp ("White"); + QColor black ("Black"); + QColor white ("White"); + for (octave_idx_type ii = 0; ii < cdata.rows (); ii++) + for (octave_idx_type jj = 0; jj < cdata.columns (); jj++) + { + if (cdata(ii, jj) == 1.0) + tmp = black; + else if (cdata(ii, jj) == 2.0) + tmp = white; + else + tmp.setAlpha (0); + + retval.setPixel (jj, ii, tmp.rgba ()); + } + + return retval; + } - if (bb.numel () == 4) - { - r = QRect (octave::math::round (bb(0)), octave::math::round (bb(1)), - octave::math::round (bb(2)), octave::math::round (bb(3))); - if (! r.isValid ()) - r = QRect (); - } + Figure * + Figure::create (octave::interpreter& interp, + const graphics_object& go) + { + return new Figure (interp, go, new FigureWindow ()); + } + + Figure::Figure (octave::interpreter& interp, + const graphics_object& go, FigureWindow *win) + : 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, interp); + win->setCentralWidget (m_container); + + connect (m_container, QOverload::of (&Container::interpreter_event), + this, QOverload::of (&Figure::interpreter_event)); + + connect (m_container, QOverload::of (&Container::interpreter_event), + this, QOverload::of (&Figure::interpreter_event)); + + figure::properties& fp = properties
(); - return r; -} + // Adjust figure position + m_innerRect = boundingBoxToRect (fp.get_boundingbox (true)); + m_outerRect = boundingBoxToRect (fp.get_boundingbox (false)); + + set_geometry (m_innerRect); + + // Menubar + m_menuBar = new MenuBar (win); + win->setMenuBar (m_menuBar); + m_menuBar->addReceiver (this); + m_menuBar->setStyleSheet (m_menuBar->styleSheet () + global_menubar_style); + + // Status bar + m_statusBar = win->statusBar (); + m_statusBar->setVisible (false); + + if (fp.toolbar_is ("figure") + || (fp.toolbar_is ("auto") && fp.menubar_is ("figure"))) + showFigureStatusBar (true); + + // Enable mouse tracking unconditionally + enableMouseTracking (); + + // When this constructor gets called all properties are already + // set, even non default. We force "update" here to get things right. + + // Figure title + update (figure::properties::ID_NUMBERTITLE); -static QImage -pointer_to_qimage (const Matrix& cdata) -{ - QImage retval (cdata.rows (), cdata.columns (), QImage::Format_ARGB32); - QColor tmp ("White"); - QColor black ("Black"); - QColor white ("White"); - for (octave_idx_type ii = 0; ii < cdata.rows (); ii++) - for (octave_idx_type jj = 0; jj < cdata.columns (); jj++) + // Decide what keyboard events we listen to + Canvas *canvas = m_container->canvas (m_handle); + if (canvas) + canvas->setEventMask (0); + update (figure::properties::ID_KEYPRESSFCN); + update (figure::properties::ID_KEYRELEASEFCN); + + // modal style + update (figure::properties::ID_WINDOWSTYLE); + + // Handle resizing constraints + update (figure::properties::ID_RESIZE); + + // Custom pointer data + update (figure::properties::ID_POINTERSHAPECDATA); + + // Visibility + update (figure::properties::ID_VISIBLE); + + connect (this, &Figure::asyncUpdate, this, &Figure::updateContainer); + + // Register for the signal that indicates when a window has moved + // to a different screen + connect (win, &FigureWindow::figureWindowShown, + this, &Figure::figureWindowShown); + + win->addReceiver (this); + m_container->addReceiver (this); + } + + Figure::~Figure () + { } + + QString + Figure::fileName () + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + const figure::properties& fp = properties
(); + + std::string name = fp.get_filename (); + + return QString::fromStdString (name); + } + + void + Figure::setFileName (const QString& name) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + figure::properties& fp = properties
(); + + fp.set_filename (name.toStdString ()); + } + + MouseMode + Figure::mouseMode () + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + const figure::properties& fp = properties
(); + + std::string mode = fp.get___mouse_mode__ (); + + if (mode == "zoom") { - if (cdata(ii, jj) == 1.0) - tmp = black; - else if (cdata(ii, jj) == 2.0) - tmp = white; - else - tmp.setAlpha (0); + octave_scalar_map zm = fp.get___zoom_mode__ ().scalar_map_value (); + + std::string direction = zm.getfield ("Direction").string_value (); + + mode += ' ' + direction; + } - retval.setPixel (jj, ii, tmp.rgba ()); + if (mode == "rotate") + return RotateMode; + else if (mode == "zoom in") + return ZoomInMode; + else if (mode == "zoom out") + return ZoomOutMode; + else if (mode == "pan") + return PanMode; + else if (mode == "text") + return TextMode; + + return NoMode; + } + + void + Figure::set_geometry (QRect r) + { + QMainWindow *win = qWidget (); + + if (! m_resizable) + { + win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); + win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); } - return retval; -} + // Unlock window if it is maximized or full-screen + int state = win->windowState (); + if (state == Qt::WindowFullScreen || state == Qt::WindowMaximized) + win->setWindowState (Qt::WindowNoState); -Figure * -Figure::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go) -{ - return new Figure (oct_qobj, interp, go, new FigureWindow ()); -} - -Figure::Figure (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, FigureWindow *win) - : Object (oct_qobj, 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); - win->setCentralWidget (m_container); + win->setGeometry (r); - connect (m_container, QOverload::of (&Container::interpreter_event), - this, QOverload::of (&Figure::interpreter_event)); - - connect (m_container, QOverload::of (&Container::interpreter_event), - this, QOverload::of (&Figure::interpreter_event)); - - figure::properties& fp = properties
(); - - // Adjust figure position - m_innerRect = boundingBoxToRect (fp.get_boundingbox (true)); - m_outerRect = boundingBoxToRect (fp.get_boundingbox (false)); + if (! m_resizable) + { + win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); + win->setFixedSize(win->size ()); + } + } - set_geometry (m_innerRect); - - // Menubar - m_menuBar = new MenuBar (win); - win->setMenuBar (m_menuBar); - m_menuBar->addReceiver (this); - m_menuBar->setStyleSheet (m_menuBar->styleSheet () + global_menubar_style); - - // Status bar - m_statusBar = win->statusBar (); - m_statusBar->setVisible (false); + Container * + Figure::innerContainer () + { + return m_container; + } - if (fp.toolbar_is ("figure") - || (fp.toolbar_is ("auto") && fp.menubar_is ("figure"))) - showFigureStatusBar (true); - - // Enable mouse tracking unconditionally - enableMouseTracking (); - - // When this constructor gets called all properties are already - // set, even non default. We force "update" here to get things right. + void + Figure::redraw () + { + Canvas *canvas = m_container->canvas (m_handle); - // Figure title - update (figure::properties::ID_NUMBERTITLE); - - // Decide what keyboard events we listen to - m_container->canvas (m_handle)->setEventMask (0); - update (figure::properties::ID_KEYPRESSFCN); - update (figure::properties::ID_KEYRELEASEFCN); - - // modal style - update (figure::properties::ID_WINDOWSTYLE); + if (canvas) + canvas->redraw (); - // Handle resizing constraints - update (figure::properties::ID_RESIZE); - - // Custom pointer data - update (figure::properties::ID_POINTERSHAPECDATA); - - // Visibility - update (figure::properties::ID_VISIBLE); - - connect (this, &Figure::asyncUpdate, this, &Figure::updateContainer); + for (auto *qobj : qWidget ()->findChildren ()) + { + if (qobj->objectName () == "UIPanel" + || qobj->objectName () == "UIButtonGroup" + || qobj->objectName () == "UIControl" + || qobj->objectName () == "UITable") + { + Object *obj = Object::fromQObject (qobj); - // Register for the signal that indicates when a window has moved - // to a different screen - connect (win, &FigureWindow::figureWindowShown, - this, &Figure::figureWindowShown); + if (obj) + obj->slotRedraw (); + } + } + } - win->addReceiver (this); - m_container->addReceiver (this); -} - -Figure::~Figure (void) -{ } + void + Figure::show () + { + QWidget *win = qWidget (); -QString -Figure::fileName (void) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - const figure::properties& fp = properties
(); + win->activateWindow (); + win->raise (); + } - std::string name = fp.get_filename (); - - return QString::fromStdString (name); -} - -void -Figure::setFileName (const QString& name) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); + void + Figure::print (const QString& file_cmd, const QString& term) + { + Canvas *canvas = m_container->canvas (m_handle); - figure::properties& fp = properties
(); - - fp.set_filename (name.toStdString ()); -} - -MouseMode -Figure::mouseMode (void) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + if (canvas) + canvas->print (file_cmd, term); + } - octave::autolock guard (gh_mgr.graphics_lock ()); - - const figure::properties& fp = properties
(); - - std::string mode = fp.get___mouse_mode__ (); + uint8NDArray + Figure::slotGetPixels () + { + uint8NDArray retval; + Canvas *canvas = m_container->canvas (m_handle); - if (mode == "zoom") - { - octave_scalar_map zm = fp.get___zoom_mode__ ().scalar_map_value (); - - std::string direction = zm.getfield ("Direction").string_value (); + if (canvas) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - mode += ' ' + direction; - } + gh_mgr.process_events (); + octave::autolock guard (gh_mgr.graphics_lock ()); + retval = canvas->getPixels (); + } - if (mode == "rotate") - return RotateMode; - else if (mode == "zoom in") - return ZoomInMode; - else if (mode == "zoom out") - return ZoomOutMode; - else if (mode == "pan") - return PanMode; - else if (mode == "text") - return TextMode; + return retval; + } - return NoMode; -} - -void -Figure::set_geometry (QRect r) -{ - QMainWindow *win = qWidget (); + void + Figure::beingDeleted () + { + Canvas *canvas = m_container->canvas (m_handle.value (), false); - if (! m_resizable) - { - win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); - win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); - } + if (canvas) + canvas->blockRedraw (true); - // Unlock window if it is maximized or full-screen - int state = win->windowState (); - if (state == Qt::WindowFullScreen || state == Qt::WindowMaximized) - win->setWindowState (Qt::WindowNoState); - - win->setGeometry (r); + m_container->removeReceiver (this); + qWidget ()->removeReceiver (this); + } - if (! m_resizable) - { - win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); - win->setFixedSize(win->size ()); - } -} + void + Figure::update (int pId) + { + if (m_blockUpdates) + return; -Container * -Figure::innerContainer (void) -{ - return m_container; -} + figure::properties& fp = properties
(); + + if (fp.is___printing__ ()) + return; -void -Figure::redraw (void) -{ - Canvas *canvas = m_container->canvas (m_handle); - - if (canvas) - canvas->redraw (); + QMainWindow *win = qWidget (); - for (auto *qobj : qWidget ()->findChildren ()) - { - if (qobj->objectName () == "UIPanel" - || qobj->objectName () == "UIButtonGroup" - || qobj->objectName () == "UIControl" - || qobj->objectName () == "UITable") - { - Object *obj = Object::fromQObject (qobj); + // If the window doesn't exist, there's nothing we can do. + if (! win) + return; + + m_blockUpdates = true; - if (obj) - obj->slotRedraw (); - } - } -} - -void -Figure::show (void) -{ - QWidget *win = qWidget (); + switch (pId) + { + case figure::properties::ID_POSITION: + { + m_innerRect = boundingBoxToRect (fp.get_boundingbox (true)); + int toffset = 0; + int boffset = 0; - win->activateWindow (); - win->raise (); -} + for (auto *tb : win->findChildren ()) + if (! tb->isHidden ()) + toffset += tb->sizeHint ().height (); -void -Figure::print (const QString& file_cmd, const QString& term) -{ - Canvas *canvas = m_container->canvas (m_handle); - - if (canvas) - canvas->print (file_cmd, term); -} + if (! m_menuBar->isHidden ()) + toffset += m_menuBar->sizeHint ().height (); -uint8NDArray -Figure::slotGetPixels (void) -{ - uint8NDArray retval; - Canvas *canvas = m_container->canvas (m_handle); - - if (canvas) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + if (! m_statusBar->isHidden ()) + boffset += m_statusBar->sizeHint ().height (); - gh_mgr.process_events (); - octave::autolock guard (gh_mgr.graphics_lock ()); - retval = canvas->getPixels (); - } + set_geometry (m_innerRect.adjusted (0, -toffset, 0, boffset)); + } + break; - return retval; -} - -void -Figure::beingDeleted (void) -{ - Canvas *canvas = m_container->canvas (m_handle.value (), false); + case figure::properties::ID_NAME: + case figure::properties::ID_NUMBERTITLE: + win->setWindowTitle (Utils::fromStdString (fp.get_title ())); + break; - if (canvas) - canvas->blockRedraw (true); - - m_container->removeReceiver (this); - qWidget ()->removeReceiver (this); -} + case figure::properties::ID_VISIBLE: + if (fp.is_visible ()) + { + QTimer::singleShot (0, win, &QMainWindow::show); + if (! fp.is___gl_window__ ()) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); -void -Figure::update (int pId) -{ - if (m_blockUpdates) - return; - - figure::properties& fp = properties
(); - - if (fp.is___printing__ ()) - return; - - QMainWindow *win = qWidget (); - - // If the window doesn't exist, there's nothing we can do. - if (! win) - return; + octave::autolock guard (gh_mgr.graphics_lock ()); + fp.set ("__gl_window__", "on"); + } + } + else + win->hide (); + break; - m_blockUpdates = true; - - switch (pId) - { - case figure::properties::ID_POSITION: - { - m_innerRect = boundingBoxToRect (fp.get_boundingbox (true)); - int toffset = 0; - int boffset = 0; - - for (auto *tb : win->findChildren ()) - if (! tb->isHidden ()) - toffset += tb->sizeHint ().height (); - - if (! m_menuBar->isHidden ()) - toffset += m_menuBar->sizeHint ().height (); - - if (! m_statusBar->isHidden ()) - boffset += m_statusBar->sizeHint ().height (); + case figure::properties::ID_RESIZE: + if (fp.is_resize ()) + { + win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); + win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); + m_resizable = true; + } + else + { + win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); + win->setFixedSize(win->size ()); + m_resizable = false; + } + break; - set_geometry (m_innerRect.adjusted (0, -toffset, 0, boffset)); - } - break; - - case figure::properties::ID_NAME: - case figure::properties::ID_NUMBERTITLE: - win->setWindowTitle (Utils::fromStdString (fp.get_title ())); - break; - - case figure::properties::ID_VISIBLE: - if (fp.is_visible ()) - { - QTimer::singleShot (0, win, &QMainWindow::show); - if (! fp.is___gl_window__ ()) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - fp.set ("__gl_window__", "on"); - } - } - else - win->hide (); - break; + case figure::properties::ID_MENUBAR: + case figure::properties::ID_TOOLBAR: + if (fp.toolbar_is ("none")) + showFigureStatusBar (false); + else if (fp.toolbar_is ("figure")) + showFigureStatusBar (true); + else // "auto" + showFigureStatusBar (fp.menubar_is ("figure")); + break; - case figure::properties::ID_RESIZE: - if (fp.is_resize ()) + case figure::properties::ID_KEYPRESSFCN: { - win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); - win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); - m_resizable = true; - } - else - { - win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); - win->setFixedSize(win->size ()); - m_resizable = false; - } - break; + Canvas *canvas = m_container->canvas (m_handle); + + if (canvas) + { + if (fp.get_keypressfcn ().isempty ()) + canvas->clearEventMask (Canvas::KeyPress); + else + canvas->addEventMask (Canvas::KeyPress); + } - case figure::properties::ID_MENUBAR: - case figure::properties::ID_TOOLBAR: - if (fp.toolbar_is ("none")) - showFigureStatusBar (false); - else if (fp.toolbar_is ("figure")) - showFigureStatusBar (true); - else // "auto" - showFigureStatusBar (fp.menubar_is ("figure")); - break; + // Signal the change to uipanels as well + for (auto *qobj : qWidget ()->findChildren ()) + { + if (qobj->objectName () == "UIPanel") + { + Object *obj = Object::fromQObject (qobj); - 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); - - if (obj) - { - if (fp.get_keypressfcn ().isempty ()) - obj->innerContainer ()->canvas (m_handle)-> - clearEventMask (Canvas::KeyPress); - else - obj->innerContainer ()->canvas (m_handle)-> - 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); + } } } } - break; + 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 ()) + case figure::properties::ID_KEYRELEASEFCN: { - if (qobj->objectName () == "UIPanel") + Canvas *canvas = m_container->canvas (m_handle); + + if (canvas) { - Object *obj = Object::fromQObject (qobj); - - if (obj) + 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") { - if (fp.get_keypressfcn ().isempty ()) - obj->innerContainer ()->canvas (m_handle)-> - clearEventMask (Canvas::KeyRelease); - else - obj->innerContainer ()->canvas (m_handle)-> - addEventMask (Canvas::KeyRelease); + 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: - if (fp.windowstyle_is ("modal")) - { - bool is_visible = win->isVisible (); - - // if window is already visible, need to hide and reshow it in order to - // make it use the modal settings - if (is_visible) - win->setVisible (false); - - win->setWindowModality (Qt::ApplicationModal); - win->setVisible (is_visible); - } - else - win->setWindowModality (Qt::NonModal); - - break; + break; - case figure::properties::ID_POINTERSHAPECDATA: - m_pointer_cdata = - pointer_to_qimage (fp.get_pointershapecdata ().matrix_value ()); - if (fp.get_pointer () != "custom") - break; - OCTAVE_FALLTHROUGH; - - case figure::properties::ID_POINTER: - 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()); - break; - - default: - break; - } - - m_blockUpdates = false; -} + case figure::properties::ID_WINDOWSTYLE: + if (fp.windowstyle_is ("modal")) + { + bool is_visible = win->isVisible (); -void -Figure::showFigureStatusBar (bool visible) -{ - if (m_statusBar - && (! m_statusBar->isHidden ()) != visible) - { - int dy = m_statusBar->sizeHint ().height (); - QRect r = qWidget ()->geometry (); - - if (! visible) - r.adjust (0, 0, 0, -dy); - else - r.adjust (0, 0, 0, dy); - - m_blockUpdates = true; - set_geometry (r); - m_statusBar->setVisible (visible); - m_blockUpdates = false; - - updateBoundingBox (false); - } -} + // if window is already visible, need to hide and reshow it in order to + // make it use the modal settings + if (is_visible) + win->setVisible (false); -void -Figure::updateFigureHeight (int dh) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - graphics_object go = object (); - - if (go.valid_object () && dh != 0) - { - QRect r = qWidget ()->geometry (); - - r.adjust (0, dh, 0, 0); - - m_blockUpdates = true; - set_geometry (r); - m_blockUpdates = false; - - updateBoundingBox (false); - } -} - -void -Figure::updateStatusBar (ColumnVector pt) -{ - if (! m_statusBar->isHidden ()) - m_statusBar->showMessage (QString ("(%1, %2)") - .arg (pt(0), 0, 'g', 5) - .arg (pt(1), 0, 'g', 5)); -} + win->setWindowModality (Qt::ApplicationModal); + win->setVisible (is_visible); + } + else + win->setWindowModality (Qt::NonModal); -void -Figure::do_connections (const QObject *receiver, const QObject * /* emitter */) -{ - Object::do_connections (receiver); - Object::do_connections (receiver, m_container->canvas (m_handle)); -} - -QWidget * -Figure::menu (void) -{ - return qWidget ()->menuBar (); -} - -void -Figure::updateBoundingBox (bool internal, int flags) -{ - QWidget *win = qWidget (); - Matrix bb (1, 4); - std::string prop; - - if (internal) - { - prop = "position"; - QRect r = m_innerRect; + break; - if (flags & UpdateBoundingBoxPosition) - r.moveTopLeft (win->mapToGlobal (m_container->pos ())); - if (flags & UpdateBoundingBoxSize) - r.setSize (m_container->size ()); - - if (r.isValid () && r != m_innerRect) - { - m_innerRect = r; - - bb(0) = r.x (); - bb(1) = r.y (); - bb(2) = r.width (); - bb(3) = r.height (); - } - else - return; - } - else - { - prop = "outerposition"; - QRect r = m_outerRect; - - if (flags & UpdateBoundingBoxPosition) - r.moveTopLeft (win->pos ()); - if (flags & UpdateBoundingBoxSize) - r.setSize (win->frameGeometry ().size ()); + case figure::properties::ID_POINTERSHAPECDATA: + m_pointer_cdata = + pointer_to_qimage (fp.get_pointershapecdata ().matrix_value ()); + if (fp.get_pointer () != "custom") + break; + OCTAVE_FALLTHROUGH; - if (r.isValid () && r != m_outerRect) - { - m_outerRect = r; - - bb(0) = r.x (); - bb(1) = r.y (); - bb(2) = r.width (); - bb(3) = r.height (); - } - else - return; - } - - figure::properties& fp = properties
(); - - emit gh_set_event (m_handle, prop, fp.bbox2position (bb), false, - prop == "position"); -} - -bool -Figure::eventNotifyBefore (QObject *obj, QEvent *xevent) -{ - if (! m_blockUpdates) - { - // Clicking the toolbar or the menubar makes this figure current - if (xevent->type () == QEvent::MouseButtonPress) + case figure::properties::ID_POINTER: + case figure::properties::ID_POINTERSHAPEHOTSPOT: + case figure::properties::ID___MOUSE_MODE__: + case figure::properties::ID___ZOOM_MODE__: { - figure::properties& fp = properties
(); - - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - graphics_object root = gh_mgr.get_object (0); - - if (fp.get_handlevisibility () == "on") - root.set ("currentfigure", - fp.get___myhandle__ ().as_octave_value ()); - } + Canvas *canvas = m_container->canvas (m_handle); - if (obj == m_container) - { - // Do nothing... - } - else if (obj == m_menuBar) - { - switch (xevent->type ()) - { - case QEvent::ActionAdded: - case QEvent::ActionChanged: - case QEvent::ActionRemoved: - m_previousHeight = m_menuBar->sizeHint ().height (); - - default: - break; - } + if (canvas) + canvas->setCursor (mouseMode (), fp.get_pointer (), + m_pointer_cdata, + fp.get_pointershapehotspot ().matrix_value()); } - else - { - switch (xevent->type ()) - { - case QEvent::Close: - xevent->ignore (); - emit gh_callback_event (m_handle, "closerequestfcn"); - return true; + break; + + default: + break; + } + + m_blockUpdates = false; + } + + void + Figure::showFigureStatusBar (bool visible) + { + if (m_statusBar + && (! m_statusBar->isHidden ()) != visible) + { + int dy = m_statusBar->sizeHint ().height (); + QRect r = qWidget ()->geometry (); + + if (! visible) + r.adjust (0, 0, 0, -dy); + else + r.adjust (0, 0, 0, dy); - default: - break; - } - } - } + m_blockUpdates = true; + set_geometry (r); + m_statusBar->setVisible (visible); + m_blockUpdates = false; + + updateBoundingBox (false); + } + } - return false; -} + void + Figure::updateFigureHeight (int dh) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + graphics_object go = object (); + + if (go.valid_object () && dh != 0) + { + QRect r = qWidget ()->geometry (); + + r.adjust (0, dh, 0, 0); -void -Figure::eventNotifyAfter (QObject *watched, QEvent *xevent) -{ - if (! m_blockUpdates) - { - if (watched == m_container) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + m_blockUpdates = true; + set_geometry (r); + m_blockUpdates = false; + + updateBoundingBox (false); + } + } + + void + Figure::updateStatusBar (ColumnVector pt) + { + if (! m_statusBar->isHidden ()) + m_statusBar->showMessage (QString ("(%1, %2)") + .arg (pt(0), 0, 'g', 5) + .arg (pt(1), 0, 'g', 5)); + } - switch (xevent->type ()) - { - case QEvent::Resize: - updateBoundingBox (true, UpdateBoundingBoxSize); - break; + void + Figure::do_connections (const QObject *receiver, const QObject * /* emitter */) + { + Object::do_connections (receiver); + Object::do_connections (receiver, m_container->canvas (m_handle)); + } + + QWidget * + Figure::menu () + { + return qWidget ()->menuBar (); + } - case QEvent::ChildAdded: - if (dynamic_cast (xevent)->child - ()->isWidgetType()) - { - octave::autolock guard (gh_mgr.graphics_lock ()); - update (figure::properties::ID_TOOLBAR); + void + Figure::updateBoundingBox (bool internal, int flags) + { + QWidget *win = qWidget (); + Matrix bb (1, 4); + std::string prop; - enableMouseTracking (); - } - break; + if (internal) + { + prop = "position"; + QRect r = m_innerRect; + + if (flags & UpdateBoundingBoxPosition) + r.moveTopLeft (win->mapToGlobal (m_container->pos ())); + if (flags & UpdateBoundingBoxSize) + r.setSize (m_container->size ()); - case QEvent::ChildRemoved: - if (dynamic_cast (xevent)->child - ()->isWidgetType()) - { - octave::autolock guard (gh_mgr.graphics_lock ()); - update (figure::properties::ID_TOOLBAR); - } - break; + if (r.isValid () && r != m_innerRect) + { + m_innerRect = r; + + bb(0) = r.x (); + bb(1) = r.y (); + bb(2) = r.width (); + bb(3) = r.height (); + } + else + return; + } + else + { + prop = "outerposition"; + QRect r = m_outerRect; + + if (flags & UpdateBoundingBoxPosition) + r.moveTopLeft (win->pos ()); + if (flags & UpdateBoundingBoxSize) + r.setSize (win->frameGeometry ().size ()); + + if (r.isValid () && r != m_outerRect) + { + m_outerRect = r; + + bb(0) = r.x (); + bb(1) = r.y (); + bb(2) = r.width (); + bb(3) = r.height (); + } + else + return; + } + + figure::properties& fp = properties
(); - default: - break; - } - } - else if (watched == m_menuBar) - { - switch (xevent->type ()) - { - case QEvent::ActionAdded: - case QEvent::ActionChanged: - case QEvent::ActionRemoved: - // The menubar may have been resized if no action is visible + emit gh_set_event (m_handle, prop, fp.bbox2position (bb), false, + prop == "position"); + } + + bool + Figure::eventNotifyBefore (QObject *obj, QEvent *xevent) + { + if (! m_blockUpdates) + { + // Clicking the toolbar or the menubar makes this figure current + if (xevent->type () == QEvent::MouseButtonPress) + { + figure::properties& fp = properties
(); + + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + graphics_object root = gh_mgr.get_object (0); + + if (fp.get_handlevisibility () == "on") + root.set ("currentfigure", + fp.get___myhandle__ ().as_octave_value ()); + } + + if (obj == m_container) + { + // Do nothing... + } + else if (obj == m_menuBar) + { + switch (xevent->type ()) { - QAction *a = dynamic_cast (xevent)->action (); - int currentHeight = m_menuBar->sizeHint ().height (); - if (currentHeight != m_previousHeight - && ! a->isSeparator ()) - updateFigureHeight (m_previousHeight - currentHeight); + case QEvent::ActionAdded: + case QEvent::ActionChanged: + case QEvent::ActionRemoved: + m_previousHeight = m_menuBar->sizeHint ().height (); + + default: + break; } - break; - - default: - break; - } - } - else - { - switch (xevent->type ()) - { - case QEvent::Move: - updateBoundingBox (false, UpdateBoundingBoxPosition); - updateBoundingBox (true, UpdateBoundingBoxPosition); - break; + } + else + { + switch (xevent->type ()) + { + case QEvent::Close: + xevent->ignore (); + emit gh_callback_event (m_handle, "closerequestfcn"); + return true; - case QEvent::Resize: - updateBoundingBox (false, UpdateBoundingBoxSize); - break; + default: + break; + } + } + } - default: - break; - } - } - } -} - -void -Figure::addCustomToolBar (QToolBar *bar, bool visible, bool isdefault) -{ - QMainWindow *win = qWidget (); + return false; + } - if (isdefault) - m_figureToolBar = bar; + void + Figure::eventNotifyAfter (QObject *watched, QEvent *xevent) + { + if (! m_blockUpdates) + { + if (watched == m_container) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - if (! visible) - win->addToolBar (bar); - else - { - QSize sz = bar->sizeHint (); - QRect r = win->geometry (); + switch (xevent->type ()) + { + case QEvent::Resize: + updateBoundingBox (true, UpdateBoundingBoxSize); + break; - r.adjust (0, -sz.height (), 0, 0); + case QEvent::ChildAdded: + if (dynamic_cast (xevent)->child + ()->isWidgetType()) + { + octave::autolock guard (gh_mgr.graphics_lock ()); + update (figure::properties::ID_TOOLBAR); - m_blockUpdates = true; - set_geometry (r); - win->addToolBarBreak (); - win->addToolBar (bar); - m_blockUpdates = false; + enableMouseTracking (); + } + break; - updateBoundingBox (false); - } -} + case QEvent::ChildRemoved: + if (dynamic_cast (xevent)->child + ()->isWidgetType()) + { + octave::autolock guard (gh_mgr.graphics_lock ()); + update (figure::properties::ID_TOOLBAR); + } + break; -void -Figure::showCustomToolBar (QToolBar *bar, bool visible) -{ - QMainWindow *win = qWidget (); - - if ((! bar->isHidden ()) != visible) - { - QSize sz = bar->sizeHint (); - QRect r = win->geometry (); - - if (visible) - r.adjust (0, -sz.height (), 0, 0); - else - r.adjust (0, sz.height (), 0, 0); + default: + break; + } + } + else if (watched == m_menuBar) + { + switch (xevent->type ()) + { + case QEvent::ActionAdded: + case QEvent::ActionChanged: + case QEvent::ActionRemoved: + // The menubar may have been resized if no action is visible + { + QAction *a = dynamic_cast (xevent)->action (); + int currentHeight = m_menuBar->sizeHint ().height (); + if (currentHeight != m_previousHeight + && ! a->isSeparator ()) + updateFigureHeight (m_previousHeight - currentHeight); + } + break; - m_blockUpdates = true; - set_geometry (r); - bar->setVisible (visible); - m_blockUpdates = false; + default: + break; + } + } + else + { + switch (xevent->type ()) + { + case QEvent::Move: + updateBoundingBox (false, UpdateBoundingBoxPosition); + updateBoundingBox (true, UpdateBoundingBoxPosition); + break; - updateBoundingBox (false); - } -} + case QEvent::Resize: + updateBoundingBox (false, UpdateBoundingBoxSize); + break; -void -Figure::updateContainer (void) -{ - redraw (); -} + default: + break; + } + } + } + } + + void + Figure::addCustomToolBar (QToolBar *bar, bool visible, bool isdefault) + { + QMainWindow *win = qWidget (); + + if (isdefault) + m_figureToolBar = bar; -void -Figure::figureWindowShown () -{ -#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO) - QWindow *window = qWidget ()->windowHandle (); - QScreen *screen = window->screen (); + if (! visible) + win->addToolBar (bar); + else + { + QSize sz = bar->sizeHint (); + QRect r = win->geometry (); + + r.adjust (0, -sz.height (), 0, 0); - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + m_blockUpdates = true; + set_geometry (r); + win->addToolBarBreak (); + win->addToolBar (bar); + m_blockUpdates = false; - octave::autolock guard (gh_mgr.graphics_lock ()); + updateBoundingBox (false); + } + } + + void + Figure::showCustomToolBar (QToolBar *bar, bool visible) + { + QMainWindow *win = qWidget (); - figure::properties& fp = properties
(); - fp.set___device_pixel_ratio__ (screen->devicePixelRatio ()); + if ((! bar->isHidden ()) != visible) + { + QSize sz = bar->sizeHint (); + QRect r = win->geometry (); - connect (window, &QWindow::screenChanged, this, &Figure::screenChanged); -#endif -} + if (visible) + r.adjust (0, -sz.height (), 0, 0); + else + r.adjust (0, sz.height (), 0, 0); -void -Figure::screenChanged (QScreen *screen) -{ -#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO) - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + m_blockUpdates = true; + set_geometry (r); + bar->setVisible (visible); + m_blockUpdates = false; - octave::autolock guard (gh_mgr.graphics_lock ()); + updateBoundingBox (false); + } + } + + void + Figure::updateContainer () + { + redraw (); + } - figure::properties& fp = properties
(); - double old_dpr = fp.get___device_pixel_ratio__ (); - double new_dpr = screen->devicePixelRatio (); - if (old_dpr != new_dpr) - { - fp.set___device_pixel_ratio__ (new_dpr); + void + Figure::figureWindowShown () + { + QWindow *window = qWidget ()->windowHandle (); + QScreen *screen = window->screen (); + + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + figure::properties& fp = properties
(); + fp.set___device_pixel_ratio__ (screen->devicePixelRatio ()); + + connect (window, &QWindow::screenChanged, this, &Figure::screenChanged); + } + + void + Figure::screenChanged (QScreen *screen) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); - // For some obscure reason, changing the __device_pixel_ratio__ property - // from the GUI thread does not necessarily trigger a redraw. Force it. - redraw (); - } -#else - octave_unused_parameter (screen); -#endif -} + figure::properties& fp = properties
(); + double old_dpr = fp.get___device_pixel_ratio__ (); + double new_dpr = screen->devicePixelRatio (); + if (old_dpr != new_dpr) + { + fp.set___device_pixel_ratio__ (new_dpr); + + // For some obscure reason, changing the __device_pixel_ratio__ property + // from the GUI thread does not necessarily trigger a redraw. Force it. + redraw (); + } + } -void -Figure::enableMouseTracking (void) -{ - // Enable mouse tracking on every widgets - m_container->setMouseTracking (true); - m_container->canvas (m_handle)->qWidget ()->setMouseTracking (true); - for (auto *w : m_container->findChildren ()) - w->setMouseTracking (true); -} + void + Figure::enableMouseTracking () + { + // Enable mouse tracking on every widgets + m_container->setMouseTracking (true); + + Canvas *canvas = m_container->canvas (m_handle); + + if (canvas) + canvas->qWidget ()->setMouseTracking (true); + + for (auto *w : m_container->findChildren ()) + w->setMouseTracking (true); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Figure.h --- a/libgui/graphics/Figure.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Figure.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,10 +39,9 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -enum MouseMode + enum MouseMode { NoMode, RotateMode, @@ -53,94 +52,94 @@ TextMode }; -class Container; -class FigureWindow; -class MenuBar; -class ToolBar; + class Container; + class FigureWindow; + class MenuBar; + class ToolBar; -class Figure : - public Object, - public MenuContainer, - public GenericEventNotifyReceiver -{ - Q_OBJECT + class Figure : + public Object, + public MenuContainer, + public GenericEventNotifyReceiver + { + Q_OBJECT - friend class ToolBar; + friend class ToolBar; -public: - Figure (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, FigureWindow *win); - ~Figure (void); + public: + Figure (octave::interpreter& interp, + const graphics_object& go, FigureWindow *win); + ~Figure (); - static Figure * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static Figure * + create (octave::interpreter& interp, + const graphics_object& go); - QString fileName (void); - void setFileName (const QString& name); + QString fileName (); + void setFileName (const QString& name); - MouseMode mouseMode (void); + MouseMode mouseMode (); - Container * innerContainer (void); - QWidget * menu (void); - void updateStatusBar (ColumnVector pt); + Container * innerContainer (); + QWidget * menu (); + void updateStatusBar (ColumnVector pt); - void do_connections (const QObject *receiver, - const QObject *emitter = nullptr); + void do_connections (const QObject *receiver, + const QObject *emitter = nullptr); - bool eventNotifyBefore (QObject *watched, QEvent *event); - void eventNotifyAfter (QObject *watched, QEvent *event); + bool eventNotifyBefore (QObject *watched, QEvent *event); + void eventNotifyAfter (QObject *watched, QEvent *event); -protected: - enum UpdateBoundingBoxFlag + protected: + enum UpdateBoundingBoxFlag { UpdateBoundingBoxPosition = 0x1, UpdateBoundingBoxSize = 0x2, UpdateBoundingBoxAll = 0x3 }; -protected: - void redraw (void); - void show (void); - void print (const QString& file_cmd, const QString& term); - void update (int pId); - void updateBoundingBox (bool internal = false, int flags = 0); - void beingDeleted (void); + protected: + 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 (); -private: - void showFigureStatusBar (bool visible); - void addCustomToolBar (QToolBar *bar, bool visible, bool isdefault); - void showCustomToolBar (QToolBar *bar, bool visible); - void set_geometry (QRect r); + private: + void showFigureStatusBar (bool visible); + void addCustomToolBar (QToolBar *bar, bool visible, bool isdefault); + 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 figureWindowShown (); - void screenChanged (QScreen *); + private slots: + void updateFigureHeight (int delta_h); + void updateContainer (); + void figureWindowShown (); + void screenChanged (QScreen *); -public slots: - uint8NDArray slotGetPixels (void); + public slots: + uint8NDArray slotGetPixels (); -signals: - void asyncUpdate (void); - void interpreter_event (const octave::fcn_callback& fcn); - void interpreter_event (const octave::meth_callback& meth); + signals: + void asyncUpdate (); + void interpreter_event (const octave::fcn_callback& fcn); + void interpreter_event (const octave::meth_callback& meth); -private: - Container *m_container; - bool m_blockUpdates; - QToolBar *m_figureToolBar; - MenuBar *m_menuBar; - QStatusBar *m_statusBar; - QRect m_innerRect; - QRect m_outerRect; - QImage m_pointer_cdata; - int m_previousHeight; - bool m_resizable; -}; + private: + Container *m_container; + bool m_blockUpdates; + QToolBar *m_figureToolBar; + MenuBar *m_menuBar; + QStatusBar *m_statusBar; + QRect m_innerRect; + QRect m_outerRect; + QImage m_pointer_cdata; + int m_previousHeight; + bool m_resizable; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/FigureWindow.cc --- a/libgui/graphics/FigureWindow.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/FigureWindow.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/FigureWindow.h --- a/libgui/graphics/FigureWindow.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/FigureWindow.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/GLCanvas.cc --- a/libgui/graphics/GLCanvas.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/GLCanvas.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,288 +37,345 @@ 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 + GLWidget::GLWidget (Canvas& parent_canvas, QWidget *parent) + : QOpenGLWidget (parent), m_parent_canvas (parent_canvas), + m_glfcns (), m_renderer (m_glfcns) + { + setFocusPolicy (Qt::ClickFocus); + setFocus (); + } + + GLWidget::~GLWidget () { } -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) -{ - setFocusPolicy (Qt::ClickFocus); - setFocus (); -} + 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? -GLCanvas::~GLCanvas (void) -{ } + 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::initializeGL (void) -{ - m_glfcns.init (); -} + void + GLWidget::draw (graphics_object go) + { + if (go) + { + begin_rendering (); -void -GLCanvas::draw (const graphics_handle& gh) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + unwind_action reset_current ([=] () { end_rendering (); }); - octave::autolock guard (gh_mgr.graphics_lock ()); - - graphics_object go = gh_mgr.get_object (gh); + 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); - if (go) - { - 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); - } -} + m_renderer.draw (go); + } + } + + uint8NDArray + GLWidget::do_getPixels (graphics_object go) + { + uint8NDArray retval; -uint8NDArray -GLCanvas::do_getPixels (const graphics_handle& gh) -{ - uint8NDArray retval; + if (go && go.isa ("figure")) + { + Matrix pos = go.get ("position").matrix_value (); + double dpr = go.get ("__device_pixel_ratio__").double_value (); + pos(2) *= dpr; + pos(3) *= dpr; - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + begin_rendering (); - graphics_object go = gh_mgr.get_object (gh); + unwind_action reset_current ([=] () { end_rendering (); }); - if (go && go.isa ("figure")) - { - Matrix pos = go.get ("position").matrix_value (); - double dpr = go.get ("__device_pixel_ratio__").double_value (); - pos(2) *= dpr; - pos(3) *= dpr; + // 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 + // suitably large frame. + if (go.get ("visible").string_value () == "off" + || go.get ("__printing__").string_value () == "on") + { + QOpenGLFramebufferObject + fbo (pos(2), pos(3), + QOpenGLFramebufferObject::Attachment::Depth); - // Make sure we have a valid current context - if (! begin_rendering ()) - return retval; + fbo.bind (); + + unwind_action release_fbo ([&] () { fbo.release (); }); - // 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 - // suitably large frame. - if (go.get ("visible").string_value () == "off" - || go.get ("__printing__").string_value () == "on") - { - OCTAVE_QT_OPENGL_FBO - fbo (pos(2), pos(3), - OCTAVE_QT_OPENGL_FBO::Attachment::Depth); + m_renderer.set_viewport (pos(2), pos(3)); + m_renderer.set_device_pixel_ratio (dpr); + m_renderer.draw (go); - fbo.bind (); + retval = m_renderer.get_pixels (pos(2), pos(3)); + } + else + { + m_renderer.set_viewport (pos(2), pos(3)); + m_renderer.set_device_pixel_ratio (dpr); + m_renderer.draw (go); - 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)); + retval = m_renderer.get_pixels (pos(2), pos(3)); + } + } + + return retval; + } - 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)); - } + void + GLWidget::do_print (const QString& file_cmd, const QString& term, + graphics_object go) + { + if (go.valid_object ()) + { + begin_rendering (); - end_rendering (); - } + unwind_action reset_current ([=] () { end_rendering (); }); - return retval; -} + graphics_object fig (go.get_ancestor ("figure")); -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); + 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; - if (go.valid_object ()) - { - graphics_object fig (go.get_ancestor ("figure")); + QOpenGLFramebufferObject + fbo (pos(2), pos(3), + QOpenGLFramebufferObject::Attachment::Depth); - // Make sure we have a valid current context - if (! begin_rendering ()) - error ("print: no valid OpenGL offscreen context"); + fbo.bind (); - try - { - if (fig.get ("visible").string_value () == "on") + unwind_action release_fbo ([&] () { fbo.release (); }); + 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; + } + } + } + + graphics_object + GLWidget::selectFromAxes (const graphics_object& ax, const QPoint& pt) + { + if (ax) + { + begin_rendering (); - OCTAVE_QT_OPENGL_FBO - fbo (pos(2), pos(3), - OCTAVE_QT_OPENGL_FBO::Attachment::Depth); + unwind_action reset_current ([=] () { end_rendering (); }); + + octave::opengl_selector s (m_glfcns); + + s.set_viewport (width (), height ()); - fbo.bind (); + graphics_object go = s.select (ax, pt.x (), height () - pt.y (), + octave::select_ignore_hittest); + + doneCurrent (); + } - octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (), - term.toStdString ()); + return graphics_object (); + } - fbo.release (); - } - } - catch (octave::execution_exception& ee) - { - emit interpreter_event - ([=] (void) - { - // INTERPRETER THREAD - throw ee; - }); - } + void + GLWidget::drawZoomBox (const QPoint& p1, const QPoint& p2) + { + Matrix overlaycolor (3, 1); + overlaycolor(0) = 0.45; + overlaycolor(1) = 0.62; + overlaycolor(2) = 0.81; + double overlayalpha = 0.1; + Matrix bordercolor = overlaycolor; + double borderalpha = 0.9; + double borderwidth = 1.5; - end_rendering (); - } -} + m_renderer.draw_zoom_box (width (), height (), + p1.x (), p1.y (), p2.x (), p2.y (), + overlaycolor, overlayalpha, + bordercolor, borderalpha, borderwidth); + } + + void + GLWidget::paintGL () + { + m_parent_canvas.canvasPaintEvent (); + } -graphics_object -GLCanvas::selectFromAxes (const graphics_object& ax, const QPoint& pt) -{ - makeCurrent (); + void + GLWidget::mouseDoubleClickEvent (QMouseEvent *xevent) + { + m_parent_canvas.canvasMouseDoubleClickEvent (xevent); + } + + void + GLWidget::mouseMoveEvent (QMouseEvent *xevent) + { + m_parent_canvas.canvasMouseMoveEvent (xevent); + } - if (ax) - { - octave::opengl_selector s (m_glfcns); + void + GLWidget::mousePressEvent (QMouseEvent *xevent) + { + m_parent_canvas.canvasMousePressEvent (xevent); + } - s.set_viewport (width (), height ()); - return s.select (ax, pt.x (), height () - pt.y (), - octave::select_ignore_hittest); - } - - return graphics_object (); -} + void + GLWidget::mouseReleaseEvent (QMouseEvent *xevent) + { + m_parent_canvas.canvasMouseReleaseEvent (xevent); + } -void -GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2) -{ - Matrix overlaycolor (3, 1); - overlaycolor(0) = 0.45; - overlaycolor(1) = 0.62; - overlaycolor(2) = 0.81; - double overlayalpha = 0.1; - Matrix bordercolor = overlaycolor; - double borderalpha = 0.9; - double borderwidth = 1.5; + void + GLWidget::wheelEvent (QWheelEvent *xevent) + { + m_parent_canvas.canvasWheelEvent (xevent); + } + + void + GLWidget::keyPressEvent (QKeyEvent *xevent) + { + if (! m_parent_canvas.canvasKeyPressEvent (xevent)) + QOpenGLWidget::keyPressEvent (xevent); + } - m_renderer.draw_zoom_box (width (), height (), - p1.x (), p1.y (), p2.x (), p2.y (), - overlaycolor, overlayalpha, - bordercolor, borderalpha, borderwidth); -} + void + GLWidget::keyReleaseEvent (QKeyEvent *xevent) + { + if (! m_parent_canvas.canvasKeyReleaseEvent (xevent)) + QOpenGLWidget::keyReleaseEvent (xevent); + } -void -GLCanvas::paintGL (void) -{ - canvasPaintEvent (); -} + bool + GLWidget::begin_rendering () + { + bool retval = true; + + if (! isValid ()) + { + // FIXME: Is this really the right way to manager offscreen + // rendering for printing? + + static bool os_ctx_ok = true; -void -GLCanvas::mouseDoubleClickEvent (QMouseEvent *xevent) -{ - canvasMouseDoubleClickEvent (xevent); -} + 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; + return false; + } + } -void -GLCanvas::mouseMoveEvent (QMouseEvent *xevent) -{ - canvasMouseMoveEvent (xevent); -} + retval = m_os_context.makeCurrent (&m_os_surface); + } + else + makeCurrent (); -void -GLCanvas::mousePressEvent (QMouseEvent *xevent) -{ - canvasMousePressEvent (xevent); -} + return retval; + } + + void + GLWidget::end_rendering () + { + doneCurrent (); + } -void -GLCanvas::mouseReleaseEvent (QMouseEvent *xevent) -{ - canvasMouseReleaseEvent (xevent); -} + 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::wheelEvent (QWheelEvent *xevent) -{ - canvasWheelEvent (xevent); -} + void + GLCanvas::draw (const graphics_handle& gh) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); -void -GLCanvas::keyPressEvent (QKeyEvent *xevent) -{ - if (! canvasKeyPressEvent (xevent)) - OCTAVE_QT_OPENGL_WIDGET::keyPressEvent (xevent); -} + graphics_object go = gh_mgr.get_object (gh); + + m_glwidget->draw (go); + } + + uint8NDArray + GLCanvas::do_getPixels (const graphics_handle& gh) + { + uint8NDArray retval; -void -GLCanvas::keyReleaseEvent (QKeyEvent *xevent) -{ - if (! canvasKeyReleaseEvent (xevent)) - OCTAVE_QT_OPENGL_WIDGET::keyReleaseEvent (xevent); -} + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + graphics_object go = gh_mgr.get_object (gh); + + return m_glwidget->do_getPixels (go); + } -bool -GLCanvas::begin_rendering (void) -{ - bool retval = true; + 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); - if (! isValid ()) - { -# if defined (HAVE_QT_OFFSCREEN) - 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; - return false; - } - } + try + { + m_glwidget->do_print (file_cmd, term, go); + } + catch (octave::execution_exception& ee) + { + emit interpreter_event + ([=] () + { + // INTERPRETER THREAD + throw ee; + }); + } + } - retval = m_os_context.makeCurrent (&m_os_surface); -# else - retval = false; -# endif - } - else - makeCurrent (); + 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); + } - return retval; -} + bool + GLCanvas::begin_rendering () + { + return m_glwidget->begin_rendering (); + } -void -GLCanvas::end_rendering (void) -{ - doneCurrent (); -} + void + GLCanvas::end_rendering () + { + m_glwidget->end_rendering (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/GLCanvas.h --- a/libgui/graphics/GLCanvas.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/GLCanvas.h Mon Jan 30 18:36:03 2023 +0100 @@ -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,54 +38,81 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -} + class GLWidget : public QOpenGLWidget + { + Q_OBJECT + + public: -OCTAVE_BEGIN_NAMESPACE(octave) + GLWidget (Canvas& parent_canvas, QWidget *parent); + + ~GLWidget (); + + void initializeGL (); -class GLCanvas : public OCTAVE_QT_OPENGL_WIDGET, public Canvas -{ -public: - GLCanvas (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_handle& handle, QWidget *parent); - ~GLCanvas (void); + 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); + + bool begin_rendering (); + void end_rendering (); - void initializeGL (void); + protected: + + 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: - void draw (const graphics_handle& handle); - uint8NDArray do_getPixels (const graphics_handle& handle); - void do_print (const QString& file_cmd, const QString& term, - const graphics_handle& handle); - 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); - QWidget * qWidget (void) { return this; } + 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::interpreter& interp, const graphics_handle& handle, + QWidget *parent); + + ~GLCanvas (); -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); - -private: + void draw (const graphics_handle& handle); + uint8NDArray do_getPixels (const graphics_handle& handle); + void do_print (const QString& file_cmd, const QString& term, + const graphics_handle& handle); + 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); - bool begin_rendering (void); - void end_rendering (void); + QWidget * qWidget () { return m_glwidget; } - octave::qopengl_functions m_glfcns; - octave::opengl_renderer m_renderer; + private: -# if defined (HAVE_QT_OFFSCREEN) - QOpenGLContext m_os_context; - QOffscreenSurface m_os_surface; -# endif -}; + GLWidget *m_glwidget; + + bool begin_rendering (); + void end_rendering (); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/GenericEventNotify.h --- a/libgui/graphics/GenericEventNotify.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/GenericEventNotify.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/KeyMap.cc --- a/libgui/graphics/KeyMap.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/KeyMap.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,7 @@ namespace KeyMap { - QMap makeKeyMapper (void) + QMap makeKeyMapper () { QMap keyMapper; diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ListBoxControl.cc --- a/libgui/graphics/ListBoxControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ListBoxControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -35,256 +35,252 @@ #include "ListBoxControl.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) -static void -updateSelection (QListWidget *list, const Matrix& value) -{ - octave_idx_type n = value.numel (); - int lc = list->count (); - - list->clearSelection (); - - for (octave_idx_type i = 0; i < n; i++) - { - int idx = octave::math::round (value(i)); + static void + updateSelection (QListWidget *list, const Matrix& value) + { + octave_idx_type n = value.numel (); + int lc = list->count (); - if (1 <= idx && idx <= lc) - { - list->item (idx-1)->setSelected (true); - list->scrollToItem (list->item (idx-1)); - if (i == 0 - && list->selectionMode () == QAbstractItemView::SingleSelection) - break; - } - else - { - // Invalid selection. - list->clearSelection (); - break; - } - } -} + list->clearSelection (); -ListBoxControl * -ListBoxControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); - - if (parent) - { - Container *container = parent->innerContainer (); - - if (container) - return new ListBoxControl (oct_qobj, interp, go, - new QListWidget (container)); - } - - return nullptr; -} - -ListBoxControl::ListBoxControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, QListWidget *list) - : BaseControl (oct_qobj, interp, go, list), m_blockCallback (false), - m_selectionChanged (false) -{ - uicontrol::properties& up = properties (); + for (octave_idx_type i = 0; i < n; i++) + { + int idx = octave::math::round (value(i)); - list->addItems (Utils::fromStringVector (up.get_string_vector ())); - if ((up.get_max () - up.get_min ()) > 1) - list->setSelectionMode (QAbstractItemView::ExtendedSelection); - else - list->setSelectionMode (QAbstractItemView::SingleSelection); - Matrix value = up.get_value ().matrix_value (); - if (value.numel () > 0) - { - octave_idx_type n = value.numel (); - int lc = list->count (); - - for (octave_idx_type i = 0; i < n; i++) - { - int idx = octave::math::round (value(i)); - - if (1 <= idx && idx <= lc) - { - list->item (idx-1)->setSelected (true); - list->scrollToItem (list->item (idx-1)); - if (i == 0 && (list->selectionMode () - == QAbstractItemView::SingleSelection)) - break; - } - } - } - - list->viewport ()->installEventFilter (this); + if (1 <= idx && idx <= lc) + { + list->item (idx-1)->setSelected (true); + list->scrollToItem (list->item (idx-1)); + if (i == 0 + && list->selectionMode () == QAbstractItemView::SingleSelection) + break; + } + else + { + // Invalid selection. + list->clearSelection (); + break; + } + } + } - connect (list, &QListWidget::itemSelectionChanged, - this, &ListBoxControl::itemSelectionChanged); - connect (list, &QListWidget::activated, - this, &ListBoxControl::itemActivated); - connect (list, &QListWidget::itemPressed, - this, &ListBoxControl::itemPressed); -} - -ListBoxControl::~ListBoxControl (void) -{ } - -void -ListBoxControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QListWidget *list = qWidget (); + ListBoxControl * + ListBoxControl::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); - switch (pId) - { - case uicontrol::properties::ID_STRING: - m_blockCallback = true; - list->clear (); - list->addItems (Utils::fromStringVector (up.get_string_vector ())); - updateSelection (list, up.get_value ().matrix_value ()); - m_blockCallback = false; - break; + if (parent) + { + Container *container = parent->innerContainer (); - case uicontrol::properties::ID_MIN: - case uicontrol::properties::ID_MAX: - if ((up.get_max () - up.get_min ()) > 1) - list->setSelectionMode (QAbstractItemView::ExtendedSelection); - else - list->setSelectionMode (QAbstractItemView::SingleSelection); - break; - - case uicontrol::properties::ID_LISTBOXTOP: - { - int idx = octave::math::fix (up.get_listboxtop ()); - if (idx > 0) - list->scrollToItem (list->item (idx-1), - QAbstractItemView::PositionAtTop); - break; + if (container) + return new ListBoxControl (interp, go, + new QListWidget (container)); } - case uicontrol::properties::ID_VALUE: - m_blockCallback = true; - updateSelection (list, up.get_value ().matrix_value ()); - m_blockCallback = false; - break; + return nullptr; + } - default: - BaseControl::update (pId); - break; - } -} + ListBoxControl::ListBoxControl (octave::interpreter& interp, + const graphics_object& go, QListWidget *list) + : BaseControl (interp, go, list), m_blockCallback (false), + m_selectionChanged (false) + { + uicontrol::properties& up = properties (); -void -ListBoxControl::sendSelectionChange () -{ - if (! m_blockCallback) - { - QListWidget *list = qWidget (); + list->addItems (Utils::fromStringVector (up.get_string_vector ())); + if ((up.get_max () - up.get_min ()) > 1) + list->setSelectionMode (QAbstractItemView::ExtendedSelection); + else + list->setSelectionMode (QAbstractItemView::SingleSelection); + Matrix value = up.get_value ().matrix_value (); + if (value.numel () > 0) + { + octave_idx_type n = value.numel (); + int lc = list->count (); - QModelIndexList l = list->selectionModel ()->selectedIndexes (); - Matrix value (dim_vector (1, l.size ())); - int i = 0; - - for (const auto& idx : l) - value(i++) = idx.row () + 1; + for (octave_idx_type i = 0; i < n; i++) + { + int idx = octave::math::round (value(i)); - emit gh_set_event (m_handle, "value", octave_value (value), false); - emit gh_callback_event (m_handle, "callback"); - } + if (1 <= idx && idx <= lc) + { + list->item (idx-1)->setSelected (true); + list->scrollToItem (list->item (idx-1)); + if (i == 0 && (list->selectionMode () + == QAbstractItemView::SingleSelection)) + break; + } + } + } - m_selectionChanged = false; -} + list->viewport ()->installEventFilter (this); -void -ListBoxControl::itemSelectionChanged (void) -{ - if (! m_blockCallback) - m_selectionChanged = true; -} + connect (list, &QListWidget::itemSelectionChanged, + this, &ListBoxControl::itemSelectionChanged); + connect (list, &QListWidget::activated, + this, &ListBoxControl::itemActivated); + connect (list, &QListWidget::itemPressed, + this, &ListBoxControl::itemPressed); + } + + ListBoxControl::~ListBoxControl () + { } + + void + ListBoxControl::update (int pId) + { + uicontrol::properties& up = properties (); + QListWidget *list = qWidget (); -void -ListBoxControl::itemActivated (const QModelIndex&) -{ - m_selectionChanged = true; -} -void -ListBoxControl::itemPressed (QListWidgetItem *) -{ - m_selectionChanged = true; -} + switch (pId) + { + case uicontrol::properties::ID_STRING: + m_blockCallback = true; + list->clear (); + list->addItems (Utils::fromStringVector (up.get_string_vector ())); + updateSelection (list, up.get_value ().matrix_value ()); + m_blockCallback = false; + break; -bool -ListBoxControl::eventFilter (QObject *watched, QEvent *e) -{ - // listbox change - if (watched == m_qobject) - { - switch (e->type ()) + case uicontrol::properties::ID_MIN: + case uicontrol::properties::ID_MAX: + if ((up.get_max () - up.get_min ()) > 1) + list->setSelectionMode (QAbstractItemView::ExtendedSelection); + else + list->setSelectionMode (QAbstractItemView::SingleSelection); + break; + + case uicontrol::properties::ID_LISTBOXTOP: { - case QEvent::KeyRelease: - if (m_selectionChanged) - sendSelectionChange (); - m_selectionChanged = false; - break; - - default: + int idx = octave::math::fix (up.get_listboxtop ()); + if (idx > 0) + list->scrollToItem (list->item (idx-1), + QAbstractItemView::PositionAtTop); break; } - return Object::eventFilter (watched, e); - } - // listbox viewport - else - { - bool override_return = false; - QListWidget *list = qWidget (); + case uicontrol::properties::ID_VALUE: + m_blockCallback = true; + updateSelection (list, up.get_value ().matrix_value ()); + m_blockCallback = false; + break; + + default: + BaseControl::update (pId); + break; + } + } - switch (e->type ()) - { - case QEvent::MouseButtonPress: - { - QMouseEvent *m = dynamic_cast (e); + void + ListBoxControl::sendSelectionChange () + { + if (! m_blockCallback) + { + QListWidget *list = qWidget (); + + QModelIndexList l = list->selectionModel ()->selectedIndexes (); + Matrix value (dim_vector (1, l.size ())); + int i = 0; + + for (const auto& idx : l) + value(i++) = idx.row () + 1; + + emit gh_set_event (m_handle, "value", octave_value (value), false); + emit gh_callback_event (m_handle, "callback"); + } - if (m->button () & Qt::RightButton) - override_return = true; - else - { - if (! list->indexAt (m->pos ()).isValid ()) - override_return = true; - m_selectionChanged = true; - } - break; - } - case QEvent::MouseButtonRelease: + m_selectionChanged = false; + } + + void + ListBoxControl::itemSelectionChanged () + { + if (! m_blockCallback) + m_selectionChanged = true; + } + + void + ListBoxControl::itemActivated (const QModelIndex&) + { + m_selectionChanged = true; + } + void + ListBoxControl::itemPressed (QListWidgetItem *) + { + m_selectionChanged = true; + } + + bool + ListBoxControl::eventFilter (QObject *watched, QEvent *e) + { + // listbox change + if (watched == m_qobject) + { + switch (e->type ()) { - QMouseEvent *m = dynamic_cast (e); - - if (m->button () & Qt::RightButton) - override_return = true; - - else if (! list->indexAt (m->pos ()).isValid ()) - { - list->setCurrentRow (list->count () - 1); - override_return = true; - } - + case QEvent::KeyRelease: if (m_selectionChanged) sendSelectionChange (); m_selectionChanged = false; + break; + default: break; } - default: - break; + + return Object::eventFilter (watched, e); + } + // listbox viewport + else + { + bool override_return = false; + QListWidget *list = qWidget (); + + switch (e->type ()) + { + case QEvent::MouseButtonPress: + { + QMouseEvent *m = dynamic_cast (e); - } - return BaseControl::eventFilter (watched, e) || override_return; - } -} + if (m->button () & Qt::RightButton) + override_return = true; + else + { + if (! list->indexAt (m->pos ()).isValid ()) + override_return = true; + m_selectionChanged = true; + } + break; + } + case QEvent::MouseButtonRelease: + { + QMouseEvent *m = dynamic_cast (e); + + if (m->button () & Qt::RightButton) + override_return = true; + + else if (! list->indexAt (m->pos ()).isValid ()) + { + list->setCurrentRow (list->count () - 1); + override_return = true; + } + + if (m_selectionChanged) + sendSelectionChange (); + m_selectionChanged = false; + + break; + } + default: + break; + + } + return BaseControl::eventFilter (watched, e) || override_return; + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ListBoxControl.h --- a/libgui/graphics/ListBoxControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ListBoxControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -34,37 +34,35 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; + + class ListBoxControl : public BaseControl + { + Q_OBJECT -class ListBoxControl : public BaseControl -{ - Q_OBJECT + public: + ListBoxControl (octave::interpreter& interp, const graphics_object& go, + QListWidget *list); + ~ListBoxControl (); -public: - ListBoxControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, - QListWidget *list); - ~ListBoxControl (void); + static ListBoxControl * + create (octave::interpreter& interp, + const graphics_object& go); - static ListBoxControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); - -protected: - void update (int pId); - bool eventFilter (QObject *watched, QEvent *e); - void sendSelectionChange (); + protected: + void update (int pId); + bool eventFilter (QObject *watched, QEvent *e); + void sendSelectionChange (); -private slots: - void itemSelectionChanged (void); - void itemActivated (const QModelIndex&); - void itemPressed (QListWidgetItem *); + private slots: + void itemSelectionChanged (); + void itemActivated (const QModelIndex&); + void itemPressed (QListWidgetItem *); -private: - bool m_blockCallback; - bool m_selectionChanged; -}; + private: + bool m_blockCallback; + bool m_selectionChanged; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Logger.cc --- a/libgui/graphics/Logger.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Logger.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/Logger.h --- a/libgui/graphics/Logger.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Logger.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/Menu.cc --- a/libgui/graphics/Menu.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Menu.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,209 +36,102 @@ #include "Menu.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) -static QKeySequence -accelSequence (const uimenu::properties& up) -{ - std::string s (up.get_accelerator ()); - - if (! s.empty ()) - { - char c = s[0]; - int keyMod = Qt::CTRL; + static QKeySequence + accelSequence (const uimenu::properties& up) + { + std::string s (up.get_accelerator ()); - if (c >= 'A' && c <= 'Z') - keyMod |= Qt::SHIFT; - if (c >= 'a' && c <= 'z') - c -= ('a' - 'A'); - if (c >= 'A' && c <= 'Z') - return QKeySequence (keyMod | static_cast (c)); - } + if (! s.empty ()) + { + char c = s[0]; + int keyMod = Qt::CTRL; - return QKeySequence (); -} + if (c >= 'A' && c <= 'Z') + keyMod |= Qt::SHIFT; + if (c >= 'a' && c <= 'z') + c -= ('a' - 'A'); + if (c >= 'A' && c <= 'Z') + return QKeySequence (keyMod | static_cast (c)); + } -Menu * -Menu::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go) -{ - Object *parent_obj = parentObject (interp, go); + return QKeySequence (); + } - if (parent_obj) - { - QObject *qObj = parent_obj->qObject (); + Menu * + Menu::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent_obj = parentObject (interp, go); - if (qObj) - return new Menu (oct_qobj, interp, go, new QAction (qObj), - parent_obj); - } - - return nullptr; -} + if (parent_obj) + { + QObject *qObj = parent_obj->qObject (); -Menu::Menu (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QAction *action, Object *xparent) - : Object (oct_qobj, interp, go, action), m_parent (nullptr), - m_separator (nullptr) -{ - uimenu::properties& up = properties (); + if (qObj) + return new Menu (interp, go, new QAction (qObj), + parent_obj); + } - action->setText (Utils::fromStdString (up.get_text ())); + return nullptr; + } - if (up.is_checked ()) - { - action->setCheckable (true); - action->setChecked (up.is_checked ()); - } + Menu::Menu (octave::interpreter& interp, + const graphics_object& go, QAction *action, Object *xparent) + : Object (interp, go, action), m_parent (nullptr), + m_separator (nullptr) + { + uimenu::properties& up = properties (); - action->setEnabled (up.is_enable ()); - action->setShortcut (accelSequence (up)); - action->setVisible (up.is_visible ()); + action->setText (Utils::fromStdString (up.get_text ())); - if (up.is_separator ()) - { - m_separator = new QAction (action); - m_separator->setSeparator (true); - m_separator->setVisible (up.is_visible ()); - } + if (up.is_checked ()) + { + action->setCheckable (true); + action->setChecked (up.is_checked ()); + } - MenuContainer *menuContainer = dynamic_cast (xparent); - - if (menuContainer) - m_parent = menuContainer->menu (); + action->setEnabled (up.is_enable ()); + action->setShortcut (accelSequence (up)); + action->setVisible (up.is_visible ()); - if (m_parent) - { - int pos = static_cast (up.get_position ()); + if (up.is_separator ()) + { + m_separator = new QAction (action); + m_separator->setSeparator (true); + m_separator->setVisible (up.is_visible ()); + } - if (pos <= 0) - { - if (m_separator) - m_parent->insertAction (nullptr, m_separator); - m_parent->insertAction (nullptr, action); + MenuContainer *menuContainer = dynamic_cast (xparent); - int count = 0; + if (menuContainer) + m_parent = menuContainer->menu (); - for (auto *a : m_parent->actions ()) - if (! a->isSeparator ()) - count++; + if (m_parent) + { + int pos = static_cast (up.get_position ()); - up.get_property ("position").set - (octave_value (static_cast (count)), true, false); - } - else - { + if (pos <= 0) + { + if (m_separator) + m_parent->insertAction (nullptr, m_separator); + m_parent->insertAction (nullptr, action); - int count = 0; - QAction *before = nullptr; + int count = 0; - for (auto *a : m_parent->actions ()) - { + for (auto *a : m_parent->actions ()) if (! a->isSeparator ()) - { - count++; - if (pos <= count) - { - before = a; - break; - } - } - } - - if (m_separator) - m_parent->insertAction (before, m_separator); - m_parent->insertAction (before, action); - - if (before) - updateSiblingPositions (); - else - up.get_property ("position").set - (octave_value (static_cast (count+1)), true, false); - } - } - - connect (action, &QAction::triggered, this, &Menu::actionTriggered); -} - -Menu::~Menu (void) -{ } - -void -Menu::update (int pId) -{ - uimenu::properties& up = properties (); - QAction *action = qWidget (); - - switch (pId) - { - case uimenu::properties::ID_TEXT: - action->setText (Utils::fromStdString (up.get_text ())); - break; + count++; - case uimenu::properties::ID_CHECKED: - if (up.is_checked ()) - { - action->setCheckable (true); - action->setChecked (up.is_checked ()); - } - else - { - action->setChecked (false); - action->setCheckable (false); - } - break; - - case uimenu::properties::ID_ENABLE: - action->setEnabled (up.is_enable ()); - break; - - case uimenu::properties::ID_ACCELERATOR: - if (! action->menu ()) - action->setShortcut (accelSequence (up)); - break; + up.get_property ("position").set + (octave_value (static_cast (count)), true, false); + } + else + { - case uimenu::properties::ID_SEPARATOR: - if (up.is_separator ()) - { - if (! m_separator) - { - m_separator = new QAction (action); - m_separator->setSeparator (true); - m_separator->setVisible (up.is_visible ()); - if (m_parent) - m_parent->insertAction (action, m_separator); - } - } - else - { - if (m_separator) - delete m_separator; - m_separator = nullptr; - } - break; - - case uimenu::properties::ID_VISIBLE: - action->setVisible (up.is_visible ()); - if (m_separator) - m_separator->setVisible (up.is_visible ()); - break; - - case uimenu::properties::ID_POSITION: - { - if (m_separator) - m_parent->removeAction (m_separator); - - m_parent->removeAction (action); - - int pos = static_cast (up.get_position ()); - QAction *before = nullptr; - - if (pos > 0) - { int count = 0; + QAction *before = nullptr; for (auto *a : m_parent->actions ()) { @@ -252,88 +145,193 @@ } } } - } - if (m_separator) - m_parent->insertAction (before, m_separator); - - m_parent->insertAction (before, action); + if (m_separator) + m_parent->insertAction (before, m_separator); + m_parent->insertAction (before, action); - updateSiblingPositions (); + if (before) + updateSiblingPositions (); + else + up.get_property ("position").set + (octave_value (static_cast (count+1)), true, false); + } } - break; - default: - Object::update (pId); - break; - } -} + connect (action, &QAction::triggered, this, &Menu::actionTriggered); + } + + Menu::~Menu () + { } -QWidget * -Menu::menu (void) -{ - QAction *action = qWidget (); - QMenu *action_menu = action->menu (); + void + Menu::update (int pId) + { + uimenu::properties& up = properties (); + QAction *action = qWidget (); + + switch (pId) + { + case uimenu::properties::ID_TEXT: + action->setText (Utils::fromStdString (up.get_text ())); + break; - if (! action_menu) - { - action_menu = new QMenu (action->parentWidget ()); - action->setMenu (action_menu); - action->setShortcut (QKeySequence ()); - connect (action_menu, &QMenu::aboutToShow, this, &Menu::actionHovered); - } + case uimenu::properties::ID_CHECKED: + if (up.is_checked ()) + { + action->setCheckable (true); + action->setChecked (up.is_checked ()); + } + else + { + action->setChecked (false); + action->setCheckable (false); + } + break; - return action_menu; -} + case uimenu::properties::ID_ENABLE: + action->setEnabled (up.is_enable ()); + break; -void -Menu::actionTriggered (void) -{ - QAction *action = qWidget (); + case uimenu::properties::ID_ACCELERATOR: + if (! action->menu ()) + action->setShortcut (accelSequence (up)); + break; - if (action->isCheckable ()) - action->setChecked (! action->isChecked ()); - emit gh_callback_event (m_handle, "menuselectedfcn"); -} - -void -Menu::actionHovered (void) -{ - emit gh_callback_event (m_handle, "menuselectedfcn"); -} + case uimenu::properties::ID_SEPARATOR: + if (up.is_separator ()) + { + if (! m_separator) + { + m_separator = new QAction (action); + m_separator->setSeparator (true); + m_separator->setVisible (up.is_visible ()); + if (m_parent) + m_parent->insertAction (action, m_separator); + } + } + else + { + if (m_separator) + delete m_separator; + m_separator = nullptr; + } + break; -void -Menu::updateSiblingPositions (void) -{ - if (m_parent) - { - double count = 1.0; + case uimenu::properties::ID_VISIBLE: + action->setVisible (up.is_visible ()); + if (m_separator) + m_separator->setVisible (up.is_visible ()); + break; - for (auto *a : m_parent->actions ()) + case uimenu::properties::ID_POSITION: { - if (! a->isSeparator ()) - { - Object *aObj = Object::fromQObject (a); + if (m_separator) + m_parent->removeAction (m_separator); + + m_parent->removeAction (action); - if (aObj) - { - graphics_object go = aObj->object (); + int pos = static_cast (up.get_position ()); + QAction *before = nullptr; + + if (pos > 0) + { + int count = 0; - // Probably overkill as a uimenu child can only be another - // uimenu object. - if (go.isa ("uimenu")) + for (auto *a : m_parent->actions ()) + { + if (! a->isSeparator ()) { - uimenu::properties& up = Utils::properties (go); - - up.get_property ("position").set - (octave_value (count), true, false); + count++; + if (pos <= count) + { + before = a; + break; + } } } + } - count++; - } + if (m_separator) + m_parent->insertAction (before, m_separator); + + m_parent->insertAction (before, action); + + updateSiblingPositions (); } - } -} + break; + + default: + Object::update (pId); + break; + } + } + + QWidget * + Menu::menu () + { + QAction *action = qWidget (); + QMenu *action_menu = action->menu (); + + if (! action_menu) + { + action_menu = new QMenu (action->parentWidget ()); + action->setMenu (action_menu); + action->setShortcut (QKeySequence ()); + connect (action_menu, &QMenu::aboutToShow, this, &Menu::actionHovered); + } + + return action_menu; + } + + void + Menu::actionTriggered () + { + QAction *action = qWidget (); + + if (action->isCheckable ()) + action->setChecked (! action->isChecked ()); + emit gh_callback_event (m_handle, "menuselectedfcn"); + } + + void + Menu::actionHovered () + { + emit gh_callback_event (m_handle, "menuselectedfcn"); + } + + void + Menu::updateSiblingPositions () + { + if (m_parent) + { + double count = 1.0; + + for (auto *a : m_parent->actions ()) + { + if (! a->isSeparator ()) + { + Object *aObj = Object::fromQObject (a); + + if (aObj) + { + graphics_object go = aObj->object (); + + // Probably overkill as a uimenu child can only be another + // uimenu object. + if (go.isa ("uimenu")) + { + uimenu::properties& up = Utils::properties (go); + + up.get_property ("position").set + (octave_value (count), true, false); + } + } + + count++; + } + } + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Menu.h --- a/libgui/graphics/Menu.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Menu.h Mon Jan 30 18:36:03 2023 +0100 @@ -35,40 +35,39 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class Menu : public Object, public MenuContainer -{ - Q_OBJECT + class Menu : public Object, public MenuContainer + { + Q_OBJECT -public: - Menu (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QAction *action, Object *parent); - ~Menu (void); + public: + Menu (octave::interpreter& interp, + const graphics_object& go, QAction *action, Object *parent); + ~Menu (); - static Menu * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static Menu * + create (octave::interpreter& interp, + const graphics_object& go); + + Container * innerContainer () { return nullptr; } - Container * innerContainer (void) { return nullptr; } + QWidget * menu (); - QWidget * menu (void); - -protected: - void update (int pId); + protected: + void update (int pId); -private slots: - void actionTriggered (void); - void actionHovered (void); + private slots: + void actionTriggered (); + void actionHovered (); -private: - void updateSiblingPositions (void); + private: + void updateSiblingPositions (); -private: - QWidget *m_parent; - QAction *m_separator; -}; + private: + QWidget *m_parent; + QAction *m_separator; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/MenuContainer.h --- a/libgui/graphics/MenuContainer.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/MenuContainer.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,7 +33,7 @@ class MenuContainer { public: - virtual QWidget * menu (void) = 0; + virtual QWidget * menu () = 0; }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Object.cc --- a/libgui/graphics/Object.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Object.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,6 @@ #include "Object.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" #include "qt-graphics-toolkit.h" #include "graphics.h" @@ -40,246 +39,246 @@ OCTAVE_BEGIN_NAMESPACE(octave) -Object::Object (octave::base_qobject& oct_qobj, 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) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + Object::Object (octave::interpreter& interp, + const graphics_object& go, QObject *obj) + : QObject (), m_interpreter (interp), m_go (go), + m_handle (go.get_handle ()), m_qobject (nullptr) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - if (! guard) - qCritical ("octave::Object::Object: " - "creating Object (h=%g) without a valid lock!!!", - m_handle.value ()); + if (! guard) + qCritical ("octave::Object::Object: " + "creating Object (h=%g) without a valid lock!!!", + m_handle.value ()); - init (obj); -} + init (obj); + } -void -Object::init (QObject *obj, bool) -{ - if (m_qobject) - qCritical ("octave::Object::init: " - "resetting QObject while in invalid state"); + void + Object::init (QObject *obj, bool) + { + if (m_qobject) + qCritical ("octave::Object::init: " + "resetting QObject while in invalid state"); - m_qobject = obj; + m_qobject = obj; - if (m_qobject) - { - m_qobject->setProperty ("octave::Object", - QVariant::fromValue (this)); - connect (m_qobject, &QObject::destroyed, - this, &Object::objectDestroyed); - } -} + if (m_qobject) + { + m_qobject->setProperty ("octave::Object", + QVariant::fromValue (this)); + connect (m_qobject, &QObject::destroyed, + this, &Object::objectDestroyed); + } + } -Object::~Object (void) -{ } + Object::~Object () + { } -graphics_object -Object::object (void) const -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + graphics_object + Object::object () const + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock (), false); + octave::autolock guard (gh_mgr.graphics_lock (), false); - if (! guard) - qCritical ("octave::Object::object: " - "accessing graphics object (h=%g) without a valid lock!!!", - m_handle.value ()); + if (! guard) + qCritical ("octave::Object::object: " + "accessing graphics object (h=%g) without a valid lock!!!", + m_handle.value ()); - return m_go; -} + return m_go; + } -void -Object::slotUpdate (int pId) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void + Object::slotUpdate (int pId) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - switch (pId) - { + 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). - case base_properties::ID_BEINGDELETED: - beingDeleted (); - break; + case base_properties::ID_BEINGDELETED: + beingDeleted (); + break; - default: - if (object ().valid_object ()) - update (pId); - break; - } -} + default: + if (object ().valid_object ()) + update (pId); + break; + } + } -void -Object::slotFinalize (void) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void + Object::slotFinalize () + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - finalize (); -} + finalize (); + } -void -Object::slotRedraw (void) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void + Object::slotRedraw () + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - if (object ().valid_object ()) - redraw (); -} + if (object ().valid_object ()) + redraw (); + } -void -Object::slotShow (void) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void + Object::slotShow () + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - if (object ().valid_object ()) - show (); -} + if (object ().valid_object ()) + show (); + } -void -Object::slotPrint (const QString& file_cmd, const QString& term) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void + Object::slotPrint (const QString& file_cmd, const QString& term) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - if (object ().valid_object ()) - print (file_cmd, term); -} + if (object ().valid_object ()) + print (file_cmd, term); + } -void -Object::update (int /* pId */) -{ } + void + Object::update (int /* pId */) + { } -void -Object::finalize (void) -{ - if (m_qobject) - { - delete m_qobject; - m_qobject = nullptr; - } - deleteLater (); -} + void + Object::finalize () + { + if (m_qobject) + { + delete m_qobject; + m_qobject = nullptr; + } + deleteLater (); + } -void -Object::redraw (void) -{ } + void + Object::redraw () + { } + + void + Object::show () + { } -void -Object::show (void) -{ } + void + Object::print (const QString& /* file_cmd */, const QString& /* term */) + { } -void -Object::print (const QString& /* file_cmd */, const QString& /* term */) -{ } + void + Object::beingDeleted () + { } -void -Object::beingDeleted (void) -{ } - -void Object::objectDestroyed (QObject *obj) -{ - if (obj && obj == m_qobject) - m_qobject = nullptr; -} + void Object::objectDestroyed (QObject *obj) + { + if (obj && obj == m_qobject) + m_qobject = nullptr; + } -Object * -Object::parentObject (octave::interpreter& interp, const graphics_object& go) -{ - gh_manager& gh_mgr = interp.get_gh_manager (); + Object * + Object::parentObject (octave::interpreter& interp, const graphics_object& go) + { + gh_manager& gh_mgr = interp.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - Object *parent = qt_graphics_toolkit::toolkitObject - (gh_mgr.get_object (go.get_parent ())); + Object *parent = qt_graphics_toolkit::toolkitObject + (gh_mgr.get_object (go.get_parent ())); + + return parent; + } - return parent; -} + Object * + Object::fromQObject (QObject *obj) + { + QVariant v = obj->property ("octave::Object"); -Object * -Object::fromQObject (QObject *obj) -{ - QVariant v = obj->property ("octave::Object"); + if (v.isValid ()) + return reinterpret_cast (qvariant_cast (v)); + + return nullptr; + } - if (v.isValid ()) - return reinterpret_cast (qvariant_cast (v)); - - return nullptr; -} + void + Object::do_connections (const QObject *receiver, const QObject *emitter) + { + if (! emitter) + emitter = this; -void -Object::do_connections (const QObject *receiver, const QObject *emitter) -{ - if (! emitter) - emitter = this; + connect (emitter, + SIGNAL (interpreter_event (const octave::fcn_callback&)), + receiver, + SLOT (interpreter_event (const octave::fcn_callback&))); - connect (emitter, - SIGNAL (interpreter_event (const octave::fcn_callback&)), - receiver, - SLOT (interpreter_event (const octave::fcn_callback&))); - - connect (emitter, - SIGNAL (interpreter_event (const octave::meth_callback&)), - receiver, - SLOT (interpreter_event (const octave::meth_callback&))); + connect (emitter, + SIGNAL (interpreter_event (const octave::meth_callback&)), + receiver, + SLOT (interpreter_event (const octave::meth_callback&))); - connect (emitter, - SIGNAL (gh_callback_event (const graphics_handle&, - const std::string&)), - receiver, - SLOT (gh_callback_event (const graphics_handle&, - const std::string&))); + connect (emitter, + SIGNAL (gh_callback_event (const graphics_handle&, + const std::string&)), + receiver, + SLOT (gh_callback_event (const graphics_handle&, + const std::string&))); - connect (emitter, - SIGNAL (gh_callback_event (const graphics_handle&, + connect (emitter, + SIGNAL (gh_callback_event (const graphics_handle&, + const std::string&, + const octave_value&)), + receiver, + SLOT (gh_callback_event (const graphics_handle&, const std::string&, - const octave_value&)), - receiver, - SLOT (gh_callback_event (const graphics_handle&, - const std::string&, - const octave_value&))); + const octave_value&))); - connect (emitter, - SIGNAL (gh_set_event (const graphics_handle&, + connect (emitter, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&)), + receiver, + SLOT (gh_set_event (const graphics_handle&, const std::string&, - const octave_value&)), - receiver, - SLOT (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&))); + const octave_value&))); - connect (emitter, - SIGNAL (gh_set_event (const graphics_handle&, + connect (emitter, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&, bool)), + receiver, + SLOT (gh_set_event (const graphics_handle&, const std::string&, - const octave_value&, bool)), - receiver, - SLOT (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&, bool))); + const octave_value&, bool))); - connect (emitter, - SIGNAL (gh_set_event (const graphics_handle&, + connect (emitter, + SIGNAL (gh_set_event (const graphics_handle&, + const std::string&, + const octave_value&, + bool, bool)), + receiver, + SLOT (gh_set_event (const graphics_handle&, const std::string&, const octave_value&, - bool, bool)), - receiver, - SLOT (gh_set_event (const graphics_handle&, - const std::string&, - const octave_value&, - bool, bool))); -} + bool, bool))); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Object.h --- a/libgui/graphics/Object.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Object.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,123 +37,121 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; - -class Container; -class ObjectProxy; - -class Object : public QObject -{ - Q_OBJECT + class interpreter; -public: - Object (octave::base_qobject& qobj, octave::interpreter& interp, - const graphics_object& go, QObject *obj = nullptr); - - virtual ~Object (void); + class Container; + class ObjectProxy; - base_properties& properties (void) - { return object ().get_properties (); } - - const base_properties& properties (void) const - { return object ().get_properties (); } - - template - typename T::properties& properties (void) + class Object : public QObject { - return dynamic_cast - (object ().get_properties ()); - } + Q_OBJECT + + public: + Object (octave::interpreter& interp, const graphics_object& go, + QObject *obj = nullptr); + + virtual ~Object (); - template - const typename T::properties& properties (void) const - { - return dynamic_cast - (object ().get_properties ()); - } + base_properties& properties () + { return object ().get_properties (); } + + const base_properties& properties () const + { return object ().get_properties (); } - graphics_object object (void) const; - - virtual QObject * qObject (void) { return m_qobject; } + template + typename T::properties& properties () + { + return dynamic_cast + (object ().get_properties ()); + } - template - T * qWidget (void) { return qobject_cast(qObject ()); } + template + const typename T::properties& properties () const + { + return dynamic_cast + (object ().get_properties ()); + } - virtual Container * innerContainer (void) = 0; + graphics_object object () const; - static Object * fromQObject (QObject *obj); + virtual QObject * qObject () { return m_qobject; } + + template + T * qWidget () { return qobject_cast(qObject ()); } - virtual void do_connections (const QObject *receiver, - const QObject *emitter = nullptr); + virtual Container * innerContainer () = 0; -signals: + static Object * fromQObject (QObject *obj); + + virtual void do_connections (const QObject *receiver, + const QObject *emitter = nullptr); - void interpreter_event (const octave::fcn_callback& fcn); - void interpreter_event (const octave::meth_callback& meth); + signals: - void gh_callback_event (const graphics_handle& h, const std::string& name); + void interpreter_event (const octave::fcn_callback& fcn); + void interpreter_event (const octave::meth_callback& meth); + + void gh_callback_event (const graphics_handle& h, const std::string& name); - void gh_callback_event (const graphics_handle& h, const std::string& name, - const octave_value& data); + void gh_callback_event (const graphics_handle& h, const std::string& name, + const octave_value& data); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit, - bool redraw_figure); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit, + bool redraw_figure); -public slots: - void slotUpdate (int pId); - void slotFinalize (void); - void slotRedraw (void); - void slotShow (void); - void slotPrint (const QString& file_cmd, const QString& term); + public slots: + void slotUpdate (int pId); + void slotFinalize (); + void slotRedraw (); + void slotShow (); + void slotPrint (const QString& file_cmd, const QString& term); - void objectDestroyed (QObject *obj = nullptr); + void objectDestroyed (QObject *obj = nullptr); -protected: - static Object * - parentObject (octave::interpreter& interp, const graphics_object& go); + protected: + static Object * + parentObject (octave::interpreter& interp, const graphics_object& go); - void init (QObject *obj, bool callBase = false); + 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 print (const QString& file_cmd, const QString& term); + virtual void update (int pId); + 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: + protected: - octave::base_qobject& m_octave_qobj; - octave::interpreter& m_interpreter; + octave::interpreter& m_interpreter; - // Store the graphics object directly so that it will exist when - // we need it. Previously, it was possible for the graphics - // toolkit to get a handle to a figure, then have the interpreter - // thread delete the corresponding object before the graphics - // toolkit (GUI) thread had a chance to display it. It should be OK - // to store this object and use it in both threads (graphics_object - // uses a std::shared_ptr) provided that we protect access with - // mutex locks. - graphics_object m_go; + // Store the graphics object directly so that it will exist when + // we need it. Previously, it was possible for the graphics + // toolkit to get a handle to a figure, then have the interpreter + // thread delete the corresponding object before the graphics + // toolkit (GUI) thread had a chance to display it. It should be OK + // to store this object and use it in both threads (graphics_object + // uses a std::shared_ptr) provided that we protect access with + // mutex locks. + graphics_object m_go; - // Handle to the graphics object. This may be redundant now. - // Also, the whole ObjectProxy thing may not need to store a - // pointer now? Maybe we can just have a lookup table from figure - // handle to Object? What does the FLTK toolkit do? Why does - // this seem to be so complicated? - graphics_handle m_handle; + // Handle to the graphics object. This may be redundant now. + // Also, the whole ObjectProxy thing may not need to store a + // pointer now? Maybe we can just have a lookup table from figure + // handle to Object? What does the FLTK toolkit do? Why does + // this seem to be so complicated? + graphics_handle m_handle; - QObject *m_qobject; -}; + QObject *m_qobject; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ObjectProxy.cc --- a/libgui/graphics/ObjectProxy.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ObjectProxy.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/ObjectProxy.h --- a/libgui/graphics/ObjectProxy.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ObjectProxy.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/Panel.cc --- a/libgui/graphics/Panel.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Panel.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,391 +39,389 @@ #include "Panel.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - #include "graphics.h" #include "interpreter.h" OCTAVE_BEGIN_NAMESPACE(octave) -static int -frameStyleFromProperties (const uipanel::properties& pp) -{ - if (pp.bordertype_is ("none")) - return QFrame::NoFrame; - else if (pp.bordertype_is ("etchedin")) - return (QFrame::Box | QFrame::Sunken); - else if (pp.bordertype_is ("etchedout")) - return (QFrame::Box | QFrame::Raised); - else if (pp.bordertype_is ("beveledin")) - return (QFrame::Panel | QFrame::Sunken); - else if (pp.bordertype_is ("beveledout")) - return (QFrame::Panel | QFrame::Raised); - else - return (QFrame::Panel | QFrame::Plain); -} + static int + frameStyleFromProperties (const uipanel::properties& pp) + { + if (pp.bordertype_is ("none")) + return QFrame::NoFrame; + else if (pp.bordertype_is ("etchedin")) + return (QFrame::Box | QFrame::Sunken); + else if (pp.bordertype_is ("etchedout")) + return (QFrame::Box | QFrame::Raised); + else if (pp.bordertype_is ("beveledin")) + return (QFrame::Panel | QFrame::Sunken); + else if (pp.bordertype_is ("beveledout")) + return (QFrame::Panel | QFrame::Raised); + else + return (QFrame::Panel | QFrame::Plain); + } -static void -setupPalette (const uipanel::properties& pp, QPalette& p) -{ - p.setColor (QPalette::Window, - Utils::fromRgb (pp.get_backgroundcolor_rgb ())); - p.setColor (QPalette::WindowText, - Utils::fromRgb (pp.get_foregroundcolor_rgb ())); - p.setColor (QPalette::Light, - Utils::fromRgb (pp.get_highlightcolor_rgb ())); - p.setColor (QPalette::Dark, - Utils::fromRgb (pp.get_shadowcolor_rgb ())); -} + static void + setupPalette (const uipanel::properties& pp, QPalette& p) + { + p.setColor (QPalette::Window, + Utils::fromRgb (pp.get_backgroundcolor_rgb ())); + p.setColor (QPalette::WindowText, + Utils::fromRgb (pp.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Light, + Utils::fromRgb (pp.get_highlightcolor_rgb ())); + p.setColor (QPalette::Dark, + Utils::fromRgb (pp.get_shadowcolor_rgb ())); + } -static int -borderWidthFromProperties (const uipanel::properties& pp) -{ - int bw = 0; + static int + borderWidthFromProperties (const uipanel::properties& pp) + { + int bw = 0; - if (! pp.bordertype_is ("none")) - { - bw = octave::math::round (pp.get_borderwidth ()); - if (pp.bordertype_is ("etchedin") || pp.bordertype_is ("etchedout")) - bw *= 2; - } + if (! pp.bordertype_is ("none")) + { + bw = octave::math::round (pp.get_borderwidth ()); + if (pp.bordertype_is ("etchedin") || pp.bordertype_is ("etchedout")) + bw *= 2; + } + + return bw; + } - return bw; -} + Panel * + Panel::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); -Panel * -Panel::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + if (parent) + { + Container *container = parent->innerContainer (); - if (parent) - { - Container *container = parent->innerContainer (); + if (container) + return new Panel (interp, go, new QFrame (container)); + } + + return nullptr; + } - if (container) - return new Panel (oct_qobj, interp, go, new QFrame (container)); - } - - return nullptr; -} + Panel::Panel (octave::interpreter& interp, + const graphics_object& go, QFrame *frame) + : Object (interp, go, frame), m_container (nullptr), + m_title (nullptr), m_blockUpdates (false), + m_previous_bbox (Matrix (1, 4, 0)) + { + uipanel::properties& pp = properties (); -Panel::Panel (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QFrame *frame) - : Object (oct_qobj, interp, go, frame), m_container (nullptr), - m_title (nullptr), m_blockUpdates (false), - m_previous_bbox (Matrix (1, 4, 0)) -{ - uipanel::properties& pp = properties (); + frame->setObjectName ("UIPanel"); + frame->setAutoFillBackground (true); + Matrix bb = pp.get_boundingbox (false); + frame->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), + octave::math::round (bb(2)), octave::math::round (bb(3))); + frame->setFrameStyle (frameStyleFromProperties (pp)); + frame->setLineWidth (octave::math::round (pp.get_borderwidth ())); + QPalette pal = frame->palette (); + setupPalette (pp, pal); + frame->setPalette (pal); - frame->setObjectName ("UIPanel"); - frame->setAutoFillBackground (true); - Matrix bb = pp.get_boundingbox (false); - frame->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)), - octave::math::round (bb(2)), octave::math::round (bb(3))); - frame->setFrameStyle (frameStyleFromProperties (pp)); - frame->setLineWidth (octave::math::round (pp.get_borderwidth ())); - QPalette pal = frame->palette (); - setupPalette (pp, pal); - frame->setPalette (pal); + m_container = new Container (frame, interp); + m_container->canvas (m_handle); + + connect (m_container, SIGNAL (interpeter_event (const fcn_callback&)), + this, SIGNAL (interpeter_event (const fcn_callback&))); - m_container = new Container (frame, oct_qobj, interp); - m_container->canvas (m_handle); + connect (m_container, SIGNAL (interpeter_event (const meth_callback&)), + this, SIGNAL (interpeter_event (const meth_callback&))); + + if (frame->hasMouseTracking ()) + { + for (auto *w : frame->findChildren ()) + w->setMouseTracking (true); + } - connect (m_container, SIGNAL (interpeter_event (const fcn_callback&)), - this, SIGNAL (interpeter_event (const fcn_callback&))); - - connect (m_container, SIGNAL (interpeter_event (const meth_callback&)), - this, SIGNAL (interpeter_event (const meth_callback&))); + QString title = Utils::fromStdString (pp.get_title ()); + if (! title.isEmpty ()) + { + m_title = new QLabel (title, frame); + m_title->setAutoFillBackground (true); + m_title->setContentsMargins (4, 0, 4, 0); + m_title->setPalette (pal); + m_title->setFont (Utils::computeFont (pp, bb(3))); + } - if (frame->hasMouseTracking ()) - { - for (auto *w : frame->findChildren ()) - w->setMouseTracking (true); - } + frame->installEventFilter (this); + m_container->installEventFilter (this); + + graphics_object fig (go.get_ancestor ("figure")); + if (! fig.get ("keypressfcn").isempty ()) + m_container->canvas (m_handle)->addEventMask (Canvas::KeyPress); + + if (! fig.get ("keyreleasefcn").isempty ()) + m_container->canvas (m_handle)->addEventMask (Canvas::KeyRelease); - QString title = Utils::fromStdString (pp.get_title ()); - if (! title.isEmpty ()) - { - m_title = new QLabel (title, frame); - m_title->setAutoFillBackground (true); - m_title->setContentsMargins (4, 0, 4, 0); - m_title->setPalette (pal); - m_title->setFont (Utils::computeFont (pp, bb(3))); - } + if (pp.is_visible ()) + QTimer::singleShot (0, frame, &QFrame::show); + else + frame->hide (); + } - frame->installEventFilter (this); - m_container->installEventFilter (this); + Panel::~Panel () + { } - graphics_object fig (go.get_ancestor ("figure")); - if (! fig.get ("keypressfcn").isempty ()) - m_container->canvas (m_handle)->addEventMask (Canvas::KeyPress); - - if (! fig.get ("keyreleasefcn").isempty ()) - m_container->canvas (m_handle)->addEventMask (Canvas::KeyRelease); + bool + Panel::eventFilter (QObject *watched, QEvent *xevent) + { + if (! m_blockUpdates) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - if (pp.is_visible ()) - QTimer::singleShot (0, frame, &QFrame::show); - else - frame->hide (); -} + if (watched == qObject ()) + { + switch (xevent->type ()) + { + case QEvent::Resize: + { + octave::autolock guard (gh_mgr.graphics_lock ()); -Panel::~Panel (void) -{ } + graphics_object go = object (); -bool -Panel::eventFilter (QObject *watched, QEvent *xevent) -{ - if (! m_blockUpdates) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + if (go.valid_object ()) + { + if (m_title) + { + const uipanel::properties& pp = + Utils::properties (go); + + if (pp.fontunits_is ("normalized")) + { + QFrame *frame = qWidget (); - if (watched == qObject ()) - { - switch (xevent->type ()) - { - case QEvent::Resize: - { - octave::autolock guard (gh_mgr.graphics_lock ()); + m_title->setFont (Utils::computeFont + (pp, frame->height ())); + m_title->resize (m_title->sizeHint ()); + } + } + updateLayout (); + } + } + break; - graphics_object go = object (); + case QEvent::MouseButtonPress: + { + QMouseEvent *m = dynamic_cast (xevent); - if (go.valid_object ()) - { - if (m_title) - { - const uipanel::properties& pp = - Utils::properties (go); + if (m->button () == Qt::RightButton) + { + octave::autolock guard (gh_mgr.graphics_lock ()); - if (pp.fontunits_is ("normalized")) - { - QFrame *frame = qWidget (); + graphics_object go = object (); - m_title->setFont (Utils::computeFont - (pp, frame->height ())); - m_title->resize (m_title->sizeHint ()); - } - } - updateLayout (); - } + if (go.valid_object ()) + ContextMenu::executeAt (m_interpreter, + go.get_properties (), + m->globalPos ()); + } + } + break; + + default: + break; } - break; - - case QEvent::MouseButtonPress: + } + else if (watched == m_container) + { + switch (xevent->type ()) { - QMouseEvent *m = dynamic_cast (xevent); - - if (m->button () == Qt::RightButton) + case QEvent::Resize: + if (qWidget ()->isVisible ()) { octave::autolock guard (gh_mgr.graphics_lock ()); graphics_object go = object (); if (go.valid_object ()) - ContextMenu::executeAt (m_interpreter, - go.get_properties (), - m->globalPos ()); + go.get_properties ().update_boundingbox (); } + break; + + default: + break; } - break; + } + } + + return false; + } - default: - break; - } - } - else if (watched == m_container) + void + Panel::update (int pId) + { + uipanel::properties& pp = properties (); + QFrame *frame = qWidget (); + + m_blockUpdates = true; + + switch (pId) + { + case uipanel::properties::ID_POSITION: { - switch (xevent->type ()) + Matrix bb = pp.get_boundingbox (false); + if (m_previous_bbox(0) != bb(0) || m_previous_bbox(1) != bb(1) + || m_previous_bbox(2) != bb(2) || m_previous_bbox(3) != bb(3)) { - case QEvent::Resize: - if (qWidget ()->isVisible ()) - { - octave::autolock guard (gh_mgr.graphics_lock ()); + frame->setGeometry (octave::math::round (bb(0)), + octave::math::round (bb(1)), + octave::math::round (bb(2)), + octave::math::round (bb(3))); + updateLayout (); + } + m_previous_bbox = bb; + } + break; - graphics_object go = object (); + case uipanel::properties::ID_BORDERWIDTH: + frame->setLineWidth (octave::math::round (pp.get_borderwidth ())); + updateLayout (); + break; - if (go.valid_object ()) - go.get_properties ().update_boundingbox (); - } - break; + case uipanel::properties::ID_BACKGROUNDCOLOR: + case uipanel::properties::ID_FOREGROUNDCOLOR: + case uipanel::properties::ID_HIGHLIGHTCOLOR: + case uipanel::properties::ID_SHADOWCOLOR: + { + QPalette pal = frame->palette (); - default: - break; - } + setupPalette (pp, pal); + frame->setPalette (pal); + if (m_title) + m_title->setPalette (pal); } - } + break; + + case uipanel::properties::ID_TITLE: + { + QString title = Utils::fromStdString (pp.get_title ()); - return false; -} - -void -Panel::update (int pId) -{ - uipanel::properties& pp = properties (); - QFrame *frame = qWidget (); + if (title.isEmpty ()) + { + if (m_title) + delete m_title; + m_title = nullptr; + } + else + { + if (! m_title) + { + QPalette pal = frame->palette (); - m_blockUpdates = true; + m_title = new QLabel (title, frame); + m_title->setAutoFillBackground (true); + m_title->setContentsMargins (4, 0, 4, 0); + m_title->setPalette (pal); + m_title->setFont (Utils::computeFont (pp)); + m_title->show (); + } + else + { + m_title->setText (title); + m_title->resize (m_title->sizeHint ()); + } + } + updateLayout (); + } + break; - switch (pId) - { - case uipanel::properties::ID_POSITION: - { - Matrix bb = pp.get_boundingbox (false); - if (m_previous_bbox(0) != bb(0) || m_previous_bbox(1) != bb(1) - || m_previous_bbox(2) != bb(2) || m_previous_bbox(3) != bb(3)) + case uipanel::properties::ID_TITLEPOSITION: + updateLayout (); + break; + + case uipanel::properties::ID_BORDERTYPE: + frame->setFrameStyle (frameStyleFromProperties (pp)); + updateLayout (); + break; + + case uipanel::properties::ID_FONTNAME: + case uipanel::properties::ID_FONTSIZE: + case uipanel::properties::ID_FONTWEIGHT: + case uipanel::properties::ID_FONTANGLE: + if (m_title) { - frame->setGeometry (octave::math::round (bb(0)), - octave::math::round (bb(1)), - octave::math::round (bb(2)), - octave::math::round (bb(3))); + m_title->setFont (Utils::computeFont (pp)); + m_title->resize (m_title->sizeHint ()); updateLayout (); } - m_previous_bbox = bb; - } - break; + break; - case uipanel::properties::ID_BORDERWIDTH: - frame->setLineWidth (octave::math::round (pp.get_borderwidth ())); - updateLayout (); - break; + case uipanel::properties::ID_VISIBLE: + frame->setVisible (pp.is_visible ()); + updateLayout (); + break; - case uipanel::properties::ID_BACKGROUNDCOLOR: - case uipanel::properties::ID_FOREGROUNDCOLOR: - case uipanel::properties::ID_HIGHLIGHTCOLOR: - case uipanel::properties::ID_SHADOWCOLOR: - { - QPalette pal = frame->palette (); + default: + break; + } - setupPalette (pp, pal); - frame->setPalette (pal); - if (m_title) - m_title->setPalette (pal); - } - break; - - case uipanel::properties::ID_TITLE: - { - QString title = Utils::fromStdString (pp.get_title ()); + m_blockUpdates = false; + } - if (title.isEmpty ()) - { - if (m_title) - delete m_title; - m_title = nullptr; - } - else - { - if (! m_title) - { - QPalette pal = frame->palette (); + void + Panel::redraw () + { + update (uipanel::properties::ID_POSITION); + + Canvas *canvas = m_container->canvas (m_handle); - m_title = new QLabel (title, frame); - m_title->setAutoFillBackground (true); - m_title->setContentsMargins (4, 0, 4, 0); - m_title->setPalette (pal); - m_title->setFont (Utils::computeFont (pp)); - m_title->show (); - } - else - { - m_title->setText (title); - m_title->resize (m_title->sizeHint ()); - } - } - updateLayout (); - } - break; + if (canvas) + canvas->redraw (); + } - case uipanel::properties::ID_TITLEPOSITION: - updateLayout (); - break; + void + Panel::updateLayout () + { + uipanel::properties& pp = properties (); + QFrame *frame = qWidget (); - case uipanel::properties::ID_BORDERTYPE: - frame->setFrameStyle (frameStyleFromProperties (pp)); - updateLayout (); - break; + Matrix bb = pp.get_boundingbox (true); + int bw = borderWidthFromProperties (pp); - case uipanel::properties::ID_FONTNAME: - case uipanel::properties::ID_FONTSIZE: - case uipanel::properties::ID_FONTWEIGHT: - case uipanel::properties::ID_FONTANGLE: - if (m_title) - { - m_title->setFont (Utils::computeFont (pp)); - m_title->resize (m_title->sizeHint ()); - updateLayout (); - } - break; - - case uipanel::properties::ID_VISIBLE: - frame->setVisible (pp.is_visible ()); - updateLayout (); - break; + frame->setFrameRect (QRect (octave::math::round (bb(0)) - bw, + octave::math::round (bb(1)) - bw, + octave::math::round (bb(2)) + 2*bw, octave::math::round (bb(3)) + 2*bw)); + m_container->setGeometry (octave::math::round (bb(0)), + octave::math::round (bb(1)), + octave::math::round (bb(2)), octave::math::round (bb(3))); - default: - break; - } - - m_blockUpdates = false; -} - -void -Panel::redraw (void) -{ - update (uipanel::properties::ID_POSITION); + if (m_blockUpdates) + pp.update_boundingbox (); - Canvas *canvas = m_container->canvas (m_handle); - - if (canvas) - canvas->redraw (); -} - -void -Panel::updateLayout (void) -{ - uipanel::properties& pp = properties (); - QFrame *frame = qWidget (); + if (m_title) + { + QSize sz = m_title->sizeHint (); + int offset = 5; - Matrix bb = pp.get_boundingbox (true); - int bw = borderWidthFromProperties (pp); - - frame->setFrameRect (QRect (octave::math::round (bb(0)) - bw, - octave::math::round (bb(1)) - bw, - octave::math::round (bb(2)) + 2*bw, octave::math::round (bb(3)) + 2*bw)); - m_container->setGeometry (octave::math::round (bb(0)), - octave::math::round (bb(1)), - octave::math::round (bb(2)), octave::math::round (bb(3))); - - if (m_blockUpdates) - pp.update_boundingbox (); - - if (m_title) - { - QSize sz = m_title->sizeHint (); - int offset = 5; + if (pp.titleposition_is ("lefttop")) + m_title->move (bw+offset, 0); + else if (pp.titleposition_is ("righttop")) + m_title->move (frame->width () - bw - offset - sz.width (), 0); + else if (pp.titleposition_is ("leftbottom")) + m_title->move (bw+offset, frame->height () - sz.height ()); + else if (pp.titleposition_is ("rightbottom")) + m_title->move (frame->width () - bw - offset - sz.width (), + frame->height () - sz.height ()); + else if (pp.titleposition_is ("centertop")) + m_title->move (frame->width () / 2 - sz.width () / 2, 0); + else if (pp.titleposition_is ("centerbottom")) + m_title->move (frame->width () / 2 - sz.width () / 2, + frame->height () - sz.height ()); + } + } - if (pp.titleposition_is ("lefttop")) - m_title->move (bw+offset, 0); - else if (pp.titleposition_is ("righttop")) - m_title->move (frame->width () - bw - offset - sz.width (), 0); - else if (pp.titleposition_is ("leftbottom")) - m_title->move (bw+offset, frame->height () - sz.height ()); - else if (pp.titleposition_is ("rightbottom")) - m_title->move (frame->width () - bw - offset - sz.width (), - frame->height () - sz.height ()); - else if (pp.titleposition_is ("centertop")) - m_title->move (frame->width () / 2 - sz.width () / 2, 0); - else if (pp.titleposition_is ("centerbottom")) - m_title->move (frame->width () / 2 - sz.width () / 2, - frame->height () - sz.height ()); - } -} - -void -Panel::do_connections (const QObject *receiver, const QObject * /* emitter */) -{ - Object::do_connections (receiver); - Object::do_connections (receiver, m_container->canvas (m_handle)); -} + void + Panel::do_connections (const QObject *receiver, const QObject * /* emitter */) + { + Object::do_connections (receiver); + Object::do_connections (receiver, m_container->canvas (m_handle)); + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Panel.h --- a/libgui/graphics/Panel.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Panel.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,42 +33,41 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class Container; + class Container; -class Panel : public Object -{ -public: - Panel (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QFrame *frame); - ~Panel (void); + class Panel : public Object + { + public: + Panel (octave::interpreter& interp, + const graphics_object& go, QFrame *frame); + ~Panel (); - Container * innerContainer (void) { return m_container; } + Container * innerContainer () { return m_container; } - bool eventFilter (QObject *watched, QEvent *event); + bool eventFilter (QObject *watched, QEvent *event); - static Panel * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static Panel * + create (octave::interpreter& interp, + const graphics_object& go); - void do_connections (const QObject *receiver, - const QObject *emitter = nullptr); + void do_connections (const QObject *receiver, + const QObject *emitter = nullptr); -protected: - void update (int pId); - void redraw (void); + protected: + void update (int pId); + void redraw (); -private: - void updateLayout (void); + private: + void updateLayout (); -private: - Container *m_container; - QLabel *m_title; - bool m_blockUpdates; - Matrix m_previous_bbox; -}; + private: + Container *m_container; + QLabel *m_title; + bool m_blockUpdates; + Matrix m_previous_bbox; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/PopupMenuControl.cc --- a/libgui/graphics/PopupMenuControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/PopupMenuControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,121 +33,116 @@ #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, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + PopupMenuControl * + PopupMenuControl::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - return new PopupMenuControl (oct_qobj, interp, go, - new QComboBox (container)); - } + if (container) + return new PopupMenuControl (interp, go, + new QComboBox (container)); + } - return nullptr; -} + return nullptr; + } -PopupMenuControl::PopupMenuControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, - QComboBox *box) - : BaseControl (oct_qobj, interp, go, box), m_blockUpdate (false) -{ - uicontrol::properties& up = properties (); + PopupMenuControl::PopupMenuControl (octave::interpreter& interp, + const graphics_object& go, + QComboBox *box) + : BaseControl (interp, go, box), m_blockUpdate (false) + { + uicontrol::properties& up = properties (); - box->addItems (Utils::fromStdString (up.get_string_string ()).split ('|')); + box->addItems (Utils::fromStdString (up.get_string_string ()).split ('|')); + + update (uicontrol::properties::ID_VALUE); - update (uicontrol::properties::ID_VALUE); + connect (box, QOverload::of (&QComboBox::activated), + this, &PopupMenuControl::currentIndexChanged); + } - connect (box, QOverload::of (&QComboBox::activated), - this, &PopupMenuControl::currentIndexChanged); -} - -PopupMenuControl::~PopupMenuControl (void) -{ } + PopupMenuControl::~PopupMenuControl () + { } -void PopupMenuControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QComboBox *box = qWidget (); + void PopupMenuControl::update (int pId) + { + uicontrol::properties& up = properties (); + QComboBox *box = qWidget (); - switch (pId) - { - case uicontrol::properties::ID_STRING: - m_blockUpdate = true; + switch (pId) { - int oldCurrent = box->currentIndex (); + case uicontrol::properties::ID_STRING: + m_blockUpdate = true; + { + int oldCurrent = box->currentIndex (); - box->clear (); - box->addItems (Utils::fromStdString - (up.get_string_string ()).split ('|')); - if (box->count () > 0 - && oldCurrent >= 0 - && oldCurrent < box->count ()) - { - box->setCurrentIndex (oldCurrent); - } - else - { - emit gh_set_event (m_handle, "value", - octave_value (box->count () > 0 ? 1.0 : 0.0), - false); - } - } - m_blockUpdate = false; - break; + box->clear (); + box->addItems (Utils::fromStdString + (up.get_string_string ()).split ('|')); + if (box->count () > 0 + && oldCurrent >= 0 + && oldCurrent < box->count ()) + { + box->setCurrentIndex (oldCurrent); + } + else + { + emit gh_set_event (m_handle, "value", + octave_value (box->count () > 0 ? 1.0 : 0.0), + false); + } + } + m_blockUpdate = false; + break; - case uicontrol::properties::ID_VALUE: - m_blockUpdate = true; - { - Matrix value = up.get_value ().matrix_value (); + case uicontrol::properties::ID_VALUE: + m_blockUpdate = true; + { + Matrix value = up.get_value ().matrix_value (); - if (value.numel () > 0) - { - if (value(0) != static_cast (value(0))) - warning ("popupmenu value should be integer"); - else - { - int newIndex = int (value(0)) - 1; + if (value.numel () > 0) + { + if (value(0) != static_cast (value(0))) + warning ("popupmenu value should be integer"); + else + { + int newIndex = int (value(0)) - 1; - if (newIndex >= 0 && newIndex < box->count ()) - { - if (newIndex != box->currentIndex ()) - box->setCurrentIndex (newIndex); - } - else - warning ("popupmenu value not within valid display range"); - } - } + if (newIndex >= 0 && newIndex < box->count ()) + { + if (newIndex != box->currentIndex ()) + box->setCurrentIndex (newIndex); + } + else + warning ("popupmenu value not within valid display range"); + } + } + } + m_blockUpdate = false; + break; + + default: + BaseControl::update (pId); + break; } - m_blockUpdate = false; - break; - - default: - BaseControl::update (pId); - break; - } -} + } -void -PopupMenuControl::currentIndexChanged (int index) -{ - if (! m_blockUpdate) - { - emit gh_set_event (m_handle, "value", octave_value (double (index + 1)), - false); - emit gh_callback_event (m_handle, "callback"); - } -} + void + PopupMenuControl::currentIndexChanged (int index) + { + if (! m_blockUpdate) + { + emit gh_set_event (m_handle, "value", octave_value (double (index + 1)), + false); + emit gh_callback_event (m_handle, "callback"); + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/PopupMenuControl.h --- a/libgui/graphics/PopupMenuControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/PopupMenuControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,32 +32,30 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class PopupMenuControl : public BaseControl -{ - Q_OBJECT + class PopupMenuControl : public BaseControl + { + Q_OBJECT -public: - PopupMenuControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, - QComboBox *box); - ~PopupMenuControl (void); + public: + PopupMenuControl (octave::interpreter& interp, const graphics_object& go, + QComboBox *box); + ~PopupMenuControl (); - static PopupMenuControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static PopupMenuControl * + create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); + protected: + void update (int pId); -private slots: - void currentIndexChanged (int index); + private slots: + void currentIndexChanged (int index); -private: - bool m_blockUpdate; -}; + private: + bool m_blockUpdate; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/PushButtonControl.cc --- a/libgui/graphics/PushButtonControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/PushButtonControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,71 +34,67 @@ #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, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + PushButtonControl * + PushButtonControl::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - return new PushButtonControl (oct_qobj, interp, go, - new QPushButton (container)); - } - - return nullptr; -} + if (container) + return new PushButtonControl (interp, go, + new QPushButton (container)); + } -PushButtonControl::PushButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, - QPushButton *btn) - : ButtonControl (oct_qobj, interp, go, btn) -{ - uicontrol::properties& up = properties (); + return nullptr; + } + + PushButtonControl::PushButtonControl (octave::interpreter& interp, + const graphics_object& go, + QPushButton *btn) + : ButtonControl (interp, go, btn) + { + uicontrol::properties& up = properties (); - btn->setAutoFillBackground (true); - octave_value cdat = up.get_cdata (); - QImage img = Utils::makeImageFromCData (cdat, - cdat.columns (), cdat.rows ()); - btn->setIcon (QIcon (QPixmap::fromImage (img))); - btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); -} + btn->setAutoFillBackground (true); + octave_value cdat = up.get_cdata (); + QImage img = Utils::makeImageFromCData (cdat, + cdat.columns (), cdat.rows ()); + btn->setIcon (QIcon (QPixmap::fromImage (img))); + btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); + } -PushButtonControl::~PushButtonControl (void) -{ } + PushButtonControl::~PushButtonControl () + { } -void -PushButtonControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QPushButton *btn = qWidget (); + void + PushButtonControl::update (int pId) + { + uicontrol::properties& up = properties (); + QPushButton *btn = qWidget (); - switch (pId) - { - case uicontrol::properties::ID_CDATA: + switch (pId) { - octave_value cdat = up.get_cdata (); - QImage img = Utils::makeImageFromCData (cdat, - cdat.rows (), - cdat.columns ()); - btn->setIcon (QIcon (QPixmap::fromImage (img))); - btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); + case uicontrol::properties::ID_CDATA: + { + octave_value cdat = up.get_cdata (); + QImage img = Utils::makeImageFromCData (cdat, + cdat.rows (), + cdat.columns ()); + btn->setIcon (QIcon (QPixmap::fromImage (img))); + btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); + } + break; + + default: + ButtonControl::update (pId); + break; } - break; - - default: - ButtonControl::update (pId); - break; - } -} + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/PushButtonControl.h --- a/libgui/graphics/PushButtonControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/PushButtonControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,24 +32,22 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class PushButtonControl : public ButtonControl -{ -public: - PushButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, - QPushButton *btn); - ~PushButtonControl (void); + class PushButtonControl : public ButtonControl + { + public: + PushButtonControl (octave::interpreter& interp, const graphics_object& go, + QPushButton *btn); + ~PushButtonControl (); - static PushButtonControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static PushButtonControl * + create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); -}; + protected: + void update (int pId); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/PushTool.cc --- a/libgui/graphics/PushTool.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/PushTool.cc Mon Jan 30 18:36:03 2023 +0100 @@ -31,54 +31,50 @@ #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) -{ - Object *parent = parentObject (interp, go); + PushTool * + PushTool::create (octave::interpreter& interp, const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - QWidget *parentWidget = parent->qWidget (); + if (parent) + { + QWidget *parentWidget = parent->qWidget (); - if (parentWidget) - return new PushTool (oct_qobj, interp, go, - new QAction (parentWidget)); - } + if (parentWidget) + return new PushTool (interp, go, + new QAction (parentWidget)); + } - return nullptr; -} + return nullptr; + } -PushTool::PushTool (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, QAction *action) - : ToolBarButton (oct_qobj, interp, go, action) -{ - connect (action, &QAction::triggered, this, &PushTool::clicked); -} + PushTool::PushTool (octave::interpreter& interp, + const graphics_object& go, QAction *action) + : ToolBarButton (interp, go, action) + { + connect (action, &QAction::triggered, this, &PushTool::clicked); + } -PushTool::~PushTool (void) -{ } + PushTool::~PushTool () + { } -void -PushTool::update (int pId) -{ - switch (pId) - { - default: - ToolBarButton::update (pId); - break; - } -} + void + PushTool::update (int pId) + { + switch (pId) + { + default: + ToolBarButton::update (pId); + break; + } + } -void -PushTool::clicked (void) -{ - emit gh_callback_event (m_handle, "clickedcallback"); -} + void + PushTool::clicked () + { + emit gh_callback_event (m_handle, "clickedcallback"); + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/PushTool.h --- a/libgui/graphics/PushTool.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/PushTool.h Mon Jan 30 18:36:03 2023 +0100 @@ -30,28 +30,27 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class PushTool : public ToolBarButton -{ - Q_OBJECT + class PushTool : public ToolBarButton + { + Q_OBJECT + + public: + PushTool (octave::interpreter& interp, + const graphics_object& go, QAction *action); + ~PushTool (); -public: - PushTool (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QAction *action); - ~PushTool (void); + static PushTool * + create (octave::interpreter& interp, + const graphics_object& go); - static PushTool * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + protected: + void update (int pId); -protected: - void update (int pId); - -private slots: - void clicked (void); -}; + private slots: + void clicked (); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/QtHandlesUtils.cc --- a/libgui/graphics/QtHandlesUtils.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/QtHandlesUtils.cc Mon Jan 30 18:36:03 2023 +0100 @@ -401,11 +401,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 17d568574e1c -r 7860fcc69082 libgui/graphics/RadioButtonControl.cc --- a/libgui/graphics/RadioButtonControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/RadioButtonControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,73 +34,69 @@ #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, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + RadioButtonControl * + RadioButtonControl::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - return new RadioButtonControl (oct_qobj, interp, go, - new QRadioButton (container)); - } + if (container) + return new RadioButtonControl (interp, go, + new QRadioButton (container)); + } - return nullptr; -} + return nullptr; + } -RadioButtonControl::RadioButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, - QRadioButton *radio) - : ButtonControl (oct_qobj, interp, go, radio) -{ - Object *parent = parentObject (interp, go); - ButtonGroup *btnGroup = dynamic_cast(parent); - if (btnGroup) - btnGroup->addButton (radio); + RadioButtonControl::RadioButtonControl (octave::interpreter& interp, + const graphics_object& go, + QRadioButton *radio) + : ButtonControl (interp, go, radio) + { + Object *parent = parentObject (interp, go); + ButtonGroup *btnGroup = dynamic_cast(parent); + if (btnGroup) + btnGroup->addButton (radio); - uicontrol::properties& up = properties (); + uicontrol::properties& up = properties (); - radio->setAutoFillBackground (true); - radio->setAutoExclusive (false); - if (up.enable_is ("inactive")) - radio->setCheckable (false); -} + radio->setAutoFillBackground (true); + radio->setAutoExclusive (false); + if (up.enable_is ("inactive")) + radio->setCheckable (false); + } -RadioButtonControl::~RadioButtonControl (void) -{ } + RadioButtonControl::~RadioButtonControl () + { } -void -RadioButtonControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QRadioButton *btn = qWidget (); + void + RadioButtonControl::update (int pId) + { + uicontrol::properties& up = properties (); + QRadioButton *btn = qWidget (); - switch (pId) - { - case uicontrol::properties::ID_ENABLE: + switch (pId) { - if (up.enable_is ("inactive")) - btn->setCheckable (false); - else - btn->setCheckable (true); + case uicontrol::properties::ID_ENABLE: + { + if (up.enable_is ("inactive")) + btn->setCheckable (false); + else + btn->setCheckable (true); + ButtonControl::update (pId); + } + break; + + default: ButtonControl::update (pId); + break; } - break; - - default: - ButtonControl::update (pId); - break; - } -} + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/RadioButtonControl.h --- a/libgui/graphics/RadioButtonControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/RadioButtonControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,24 +32,21 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class RadioButtonControl : public ButtonControl -{ -public: - RadioButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, - QRadioButton *box); - ~RadioButtonControl (void); + class RadioButtonControl : public ButtonControl + { + public: + RadioButtonControl (octave::interpreter& interp, const graphics_object& go, + QRadioButton *box); + ~RadioButtonControl (); - static RadioButtonControl * create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go); + static RadioButtonControl * create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); -}; + protected: + void update (int pId); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/SliderControl.cc --- a/libgui/graphics/SliderControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/SliderControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,8 +33,6 @@ #include "SliderControl.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - #include "graphics.h" #include "interpreter.h" @@ -42,132 +40,130 @@ OCTAVE_BEGIN_NAMESPACE(octave) -SliderControl * -SliderControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + SliderControl * + SliderControl::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); + + if (parent) + { + Container *container = parent->innerContainer (); - if (parent) - { - Container *container = parent->innerContainer (); + if (container) + return new SliderControl (interp, go, + new QScrollBar (container)); + } + + return nullptr; + } + + SliderControl::SliderControl (octave::interpreter& interp, + const graphics_object& go, + QAbstractSlider *slider) + : BaseControl (interp, go, slider), m_blockUpdates (false) + { + uicontrol::properties& up = properties (); - if (container) - return new SliderControl (oct_qobj, interp, go, - new QScrollBar (container)); - } - - return nullptr; -} + slider->setTracking (false); + Matrix bb = up.get_boundingbox (); + bool vertical_slider = ( bb(2) < bb(3) ); + slider->setOrientation (vertical_slider ? Qt::Vertical : Qt::Horizontal); + if (vertical_slider) + slider->setInvertedAppearance (true); // Matlab compatibility + Matrix steps = up.get_sliderstep ().matrix_value (); + slider->setMinimum (0); + slider->setMaximum (RANGE_INT_MAX); + slider->setSingleStep (octave::math::round (steps(0) * RANGE_INT_MAX)); + slider->setPageStep (octave::math::round (steps(1) * RANGE_INT_MAX)); + Matrix value = up.get_value ().matrix_value (); + if (value.numel () > 0) + { + double dmin = up.get_min (), dmax = up.get_max (); -SliderControl::SliderControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, - QAbstractSlider *slider) - : BaseControl (oct_qobj, interp, go, slider), m_blockUpdates (false) -{ - uicontrol::properties& up = properties (); + slider->setValue (octave::math::round (((value(0) - dmin) / (dmax - dmin)) + * RANGE_INT_MAX)); + } + + connect (slider, &QAbstractSlider::valueChanged, + this, &SliderControl::valueChanged); + } + + SliderControl::~SliderControl () + { } + + void + SliderControl::update (int pId) + { + uicontrol::properties& up = properties (); + QScrollBar *slider = qWidget (); - slider->setTracking (false); - Matrix bb = up.get_boundingbox (); - bool vertical_slider = ( bb(2) < bb(3) ); - slider->setOrientation (vertical_slider ? Qt::Vertical : Qt::Horizontal); - if (vertical_slider) - slider->setInvertedAppearance (true); // Matlab compatibility - Matrix steps = up.get_sliderstep ().matrix_value (); - slider->setMinimum (0); - slider->setMaximum (RANGE_INT_MAX); - slider->setSingleStep (octave::math::round (steps(0) * RANGE_INT_MAX)); - slider->setPageStep (octave::math::round (steps(1) * RANGE_INT_MAX)); - Matrix value = up.get_value ().matrix_value (); - if (value.numel () > 0) - { - double dmin = up.get_min (), dmax = up.get_max (); + switch (pId) + { + case uicontrol::properties::ID_SLIDERSTEP: + { + Matrix steps = up.get_sliderstep ().matrix_value (); + + slider->setSingleStep (octave::math::round (steps(0) * RANGE_INT_MAX)); + slider->setPageStep (octave::math::round (steps(1) * RANGE_INT_MAX)); + } + break; - slider->setValue (octave::math::round (((value(0) - dmin) / (dmax - dmin)) - * RANGE_INT_MAX)); - } + case uicontrol::properties::ID_VALUE: + { + Matrix value = up.get_value ().matrix_value (); + double dmax = up.get_max (), dmin = up.get_min (); - connect (slider, &QAbstractSlider::valueChanged, - this, &SliderControl::valueChanged); -} + if (value.numel () > 0) + { + int ival = octave::math::round (((value(0) - dmin) / (dmax - dmin)) + * RANGE_INT_MAX); -SliderControl::~SliderControl (void) -{ } + m_blockUpdates = true; + slider->setValue (ival); + m_blockUpdates = false; + } + } + break; -void -SliderControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QScrollBar *slider = qWidget (); - - switch (pId) - { - case uicontrol::properties::ID_SLIDERSTEP: - { - Matrix steps = up.get_sliderstep ().matrix_value (); - - slider->setSingleStep (octave::math::round (steps(0) * RANGE_INT_MAX)); - slider->setPageStep (octave::math::round (steps(1) * RANGE_INT_MAX)); + default: + BaseControl::update (pId); + break; } - break; + } - case uicontrol::properties::ID_VALUE: + void + SliderControl::valueChanged (int ival) + { + if (! m_blockUpdates) { - Matrix value = up.get_value ().matrix_value (); - double dmax = up.get_max (), dmin = up.get_min (); + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object go = object (); - if (value.numel () > 0) + if (go.valid_object ()) { - int ival = octave::math::round (((value(0) - dmin) / (dmax - dmin)) - * RANGE_INT_MAX); + uicontrol::properties& up = Utils::properties (go); + + Matrix value = up.get_value ().matrix_value (); + double dmin = up.get_min (), dmax = up.get_max (); - m_blockUpdates = true; - slider->setValue (ival); - m_blockUpdates = false; + int ival_tmp = (value.numel () > 0 ? + octave::math::round (((value(0) - dmin) / (dmax - dmin)) + * RANGE_INT_MAX) : + 0); + + if (ival != ival_tmp || value.numel () > 0) + { + double dval = dmin + (ival * (dmax - dmin) / RANGE_INT_MAX); + + emit gh_set_event (m_handle, "value", octave_value (dval)); + emit gh_callback_event (m_handle, "callback"); + } } } - break; - - default: - BaseControl::update (pId); - break; - } -} - -void -SliderControl::valueChanged (int ival) -{ - if (! m_blockUpdates) - { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - graphics_object go = object (); - - if (go.valid_object ()) - { - uicontrol::properties& up = Utils::properties (go); - - Matrix value = up.get_value ().matrix_value (); - double dmin = up.get_min (), dmax = up.get_max (); - - int ival_tmp = (value.numel () > 0 ? - octave::math::round (((value(0) - dmin) / (dmax - dmin)) - * RANGE_INT_MAX) : - 0); - - if (ival != ival_tmp || value.numel () > 0) - { - double dval = dmin + (ival * (dmax - dmin) / RANGE_INT_MAX); - - emit gh_set_event (m_handle, "value", octave_value (dval)); - emit gh_callback_event (m_handle, "callback"); - } - } - } -} + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/SliderControl.h --- a/libgui/graphics/SliderControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/SliderControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,31 +32,30 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class SliderControl : public BaseControl -{ - Q_OBJECT + class SliderControl : public BaseControl + { + Q_OBJECT -public: - SliderControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QAbstractSlider *slider); - ~SliderControl (void); + public: + SliderControl (octave::interpreter& interp, + const graphics_object& go, QAbstractSlider *slider); + ~SliderControl (); - static SliderControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static SliderControl * + create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); + protected: + void update (int pId); -private slots: - void valueChanged (int ival); + private slots: + void valueChanged (int ival); -private: - bool m_blockUpdates; -}; + private: + bool m_blockUpdates; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Table.cc --- a/libgui/graphics/Table.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Table.cc Mon Jan 30 18:36:03 2023 +0100 @@ -48,8 +48,6 @@ #include "Table.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - #include "graphics.h" #include "interpreter.h" #include "oct-map.h" @@ -59,99 +57,99 @@ OCTAVE_BEGIN_NAMESPACE(octave) -static const int AUTO_WIDTH = 75; + static const int AUTO_WIDTH = 75; #define AUTO_HEIGHT (tp.get_fontsize () * 2 - 1) -static QSize realQSizeForTable (QTableWidget *t) -{ - int w = t->verticalHeader ()->width () + 4; - for (int i = 0; i < t->columnCount (); i++) - w += t->columnWidth (i); - int h = t->horizontalHeader ()->height () + 4; - for (int i = 0; i < t->rowCount (); i++) - h += t->rowHeight (i); - 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); \ + static QSize realQSizeForTable (QTableWidget *t) + { + int w = t->verticalHeader ()->width () + 4; + for (int i = 0; i < t->columnCount (); i++) + w += t->columnWidth (i); + int h = t->horizontalHeader ()->height () + 4; + for (int i = 0; i < t->rowCount (); i++) + h += t->rowHeight (i); + return QSize (w, h); } -FORMATNUMBER(double) -FORMATNUMBER(float) +#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) #undef FORMATNUMBER -static QString formatComplex (Complex c, char format = 'f', int precision = 4) -{ - return formatNumber (c.real (), format, precision) + " + " - + formatNumber (c.imag (), format, precision) + "i"; -} + static QString formatComplex (Complex c, char format = 'f', int precision = 4) + { + return formatNumber (c.real (), format, precision) + " + " + + 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 \ +#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) \ @@ -164,217 +162,217 @@ 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 = "") -{ - Qt::AlignmentFlag flag = Qt::AlignRight; - QString text; - if (val.isempty ()) - { - text = ""; - flag = Qt::AlignLeft; - } - else if (val.is_string ()) - { - text = octave::Utils::fromStdString (val.string_value ()); - flag = Qt::AlignLeft; - } - else if (val.iscomplex ()) - { - // Matlab has multiple complex types, we only have double. - Complex c = val.complex_value (); - if (format == "short") - text = formatComplex (c, 'f', 4); - else if (format == "short e" || format == "shorte") - text = formatComplex (c, 'e', 4); - else if (format == "short eng" || format == "shorteng") - text = formatComplex (c, 'E', 4); - else if (format == "short g" || format == "shortg") - text = formatComplex (c, 'g', 5); - else if (format == "long") - text = formatComplex (c, 'f', 15); - else if (format == "long e" || format == "longe") - text = formatComplex (c, 'e', 15); - else if (format == "long eng" || format == "longeng") - text = formatComplex (c, 'E', 15); - else if (format == "long g" || format == "longg") - text = formatComplex (c, 'g', 16); - else if (format == "bank") - text = QString::number (c.real (), 'f', 2); - else if (format == "+") - { - if (c.real () > 0) - text = Utils::fromStdString ("+"); - else if (c.real () < 0) - text = Utils::fromStdString ("-"); - else - text = Utils::fromStdString (""); - } - else if (format == "rat") - text = Utils::fromStdString (rational_approx (c.real (), 0)) + " + " - + 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"; - else - { + static std::pair + qStringValueFor (octave_value val, std::string format = "") + { + Qt::AlignmentFlag flag = Qt::AlignRight; + QString text; + if (val.isempty ()) + { + text = ""; + flag = Qt::AlignLeft; + } + else if (val.is_string ()) + { + text = octave::Utils::fromStdString (val.string_value ()); + flag = Qt::AlignLeft; + } + else if (val.iscomplex ()) + { + // Matlab has multiple complex types, we only have double. + Complex c = val.complex_value (); + if (format == "short") + text = formatComplex (c, 'f', 4); + else if (format == "short e" || format == "shorte") + text = formatComplex (c, 'e', 4); + else if (format == "short eng" || format == "shorteng") + text = formatComplex (c, 'E', 4); + else if (format == "short g" || format == "shortg") + text = formatComplex (c, 'g', 5); + else if (format == "long") + text = formatComplex (c, 'f', 15); + else if (format == "long e" || format == "longe") + text = formatComplex (c, 'e', 15); + else if (format == "long eng" || format == "longeng") + text = formatComplex (c, 'E', 15); + else if (format == "long g" || format == "longg") + text = formatComplex (c, 'g', 16); + else if (format == "bank") + text = QString::number (c.real (), 'f', 2); + else if (format == "+") + { + if (c.real () > 0) + text = Utils::fromStdString ("+"); + else if (c.real () < 0) + text = Utils::fromStdString ("-"); + else + text = Utils::fromStdString (""); + } + else if (format == "rat") + text = Utils::fromStdString (rational_approx (c.real (), 0)) + " + " + + 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"; - flag = Qt::AlignLeft; - } - } - else if (val.is_double_type () ) - { - 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 (); - if (format == "char" || format == "popup" || format == "") - { - text = Utils::fromStdString (b ? "true" : "false"); - flag = Qt::AlignLeft; - } - else if (format == "+") - { - text = Utils::fromStdString (b ? "+" : ""); - flag = Qt::AlignLeft; - } - else - text = Utils::fromStdString (b ? "1" : "0"); - } - else - { - // FIXME: Should we warn about the unknown conversion? If so, - // how? We can't just call Octave's warning function here. + + QString::number (c.imag (), 'g', 5) + "i"; + else + { + text = QString::number (c.real (), 'g', 5) + " + " + + QString::number (c.imag (), 'g', 5) + "i"; + flag = Qt::AlignLeft; + } + } + else if (val.is_double_type () ) + { + 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 (); + if (format == "char" || format == "popup" || format == "") + { + text = Utils::fromStdString (b ? "true" : "false"); + flag = Qt::AlignLeft; + } + else if (format == "+") + { + text = Utils::fromStdString (b ? "+" : ""); + flag = Qt::AlignLeft; + } + else + text = Utils::fromStdString (b ? "1" : "0"); + } + else + { + // FIXME: Should we warn about the unknown conversion? If so, + // how? We can't just call Octave's warning function here. - text = Utils::fromStdString (val.string_value (true)); - } + text = Utils::fromStdString (val.string_value (true)); + } - return std::make_pair (flag, text); -} + return std::make_pair (flag, text); + } #undef FORMAT_VALUE #undef FORMAT_VALUE_EXCEPT_RAT #undef FORMAT_UINT_VALUE #undef FORMAT_INT_VALUE -static QTableWidgetItem * itemFor (octave_value val, std::string format = "", - bool enabled = false) -{ - QTableWidgetItem *retval = new QTableWidgetItem (); - std::pair flag_and_text = - qStringValueFor (val, format); - retval->setTextAlignment (flag_and_text.first); - retval->setText (flag_and_text.second); + static QTableWidgetItem * itemFor (octave_value val, std::string format = "", + bool enabled = false) + { + QTableWidgetItem *retval = new QTableWidgetItem (); + std::pair flag_and_text = + qStringValueFor (val, format); + retval->setTextAlignment (flag_and_text.first); + retval->setText (flag_and_text.second); - if (enabled) - retval->setFlags (retval->flags () | Qt::ItemIsEditable); - else - retval->setFlags (retval->flags () & ~Qt::ItemIsEditable); + if (enabled) + retval->setFlags (retval->flags () | Qt::ItemIsEditable); + else + retval->setFlags (retval->flags () & ~Qt::ItemIsEditable); - return retval; -} + return retval; + } -static octave_value -attempt_type_conversion (const octave_value& ov, - const octave_value& old_value) -{ - octave_value retval; + static octave_value + attempt_type_conversion (const octave_value& ov, + const octave_value& old_value) + { + octave_value retval; - // 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 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)); \ } - if (old_value.is_string ()) - retval = ov; - SCANF_AND_CONVERT(int8, int64_t, "%" PRId64 " %n") + 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") @@ -385,745 +383,709 @@ #undef SCANF_AND_CONVERT - else if (old_value.isnumeric () && ! old_value.isinteger ()) - { - // Basically need to do str2double - Complex complex = octave::string::str2double (ov.string_value ()); - if (old_value.is_single_type ()) - retval = octave_value (FloatComplex (complex)); - else - retval = octave_value (complex); - } - else if (old_value.islogical ()) - { - // Right: Matlab basically needs this to be true or false, we should - // accept 1 too. - if (ov.string_value () == "true" || ov.string_value () == "1") - retval = octave_value (true); - else - retval = octave_value (false); - } - else - retval = octave_value (octave::string::str2double (ov.string_value ())); - return retval; -} + else if (old_value.isnumeric () && ! old_value.isinteger ()) + { + // Basically need to do str2double + Complex complex = octave::string::str2double (ov.string_value ()); + if (old_value.is_single_type ()) + retval = octave_value (FloatComplex (complex)); + else + retval = octave_value (complex); + } + else if (old_value.islogical ()) + { + // Right: Matlab basically needs this to be true or false, we should + // accept 1 too. + if (ov.string_value () == "true" || ov.string_value () == "1") + retval = octave_value (true); + else + retval = octave_value (false); + } + else + retval = octave_value (octave::string::str2double (ov.string_value ())); + return retval; + } -QWidget * -Table::checkBoxForLogical (octave_value val, bool enabled = false) -{ - QWidget *retval = new QWidget (m_tableWidget); - QCheckBox *checkBox = new QCheckBox (); - QHBoxLayout *layout = new QHBoxLayout (retval); - layout->addWidget (checkBox); - layout->setAlignment (Qt::AlignCenter); - layout->setContentsMargins (0, 0, 0, 0); - retval->setLayout (layout); + QWidget * + Table::checkBoxForLogical (octave_value val, bool enabled = false) + { + QWidget *retval = new QWidget (m_tableWidget); + QCheckBox *checkBox = new QCheckBox (); + QHBoxLayout *layout = new QHBoxLayout (retval); + layout->addWidget (checkBox); + layout->setAlignment (Qt::AlignCenter); + layout->setContentsMargins (0, 0, 0, 0); + retval->setLayout (layout); - if ((val.islogical () || val.is_bool_scalar ()) && val.bool_value ()) - checkBox->setCheckState (Qt::Checked); - else - checkBox->setCheckState (Qt::Unchecked); + if ((val.islogical () || val.is_bool_scalar ()) && val.bool_value ()) + checkBox->setCheckState (Qt::Checked); + else + checkBox->setCheckState (Qt::Unchecked); - checkBox->setAttribute (Qt::WA_TransparentForMouseEvents, true); - checkBox->setFocusPolicy (Qt::NoFocus); - checkBox->setProperty ("Enabled", QVariant (enabled)); + checkBox->setAttribute (Qt::WA_TransparentForMouseEvents, true); + checkBox->setFocusPolicy (Qt::NoFocus); + checkBox->setProperty ("Enabled", QVariant (enabled)); - return retval; -} + return retval; + } -Table * -Table::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + Table * + Table::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - return new Table (oct_qobj, interp, go, new QTableWidget (container)); - } + if (container) + return new Table (interp, go, new QTableWidget (container)); + } - return 0; -} + return 0; + } -Table::Table (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QTableWidget *tableWidget) - : Object (oct_qobj, interp, go, tableWidget), m_tableWidget (tableWidget), - m_curData (), m_blockUpdates (false) -{ - qObject ()->setObjectName ("UItable"); - uitable::properties& tp = properties (); + Table::Table (octave::interpreter& interp, + const graphics_object& go, QTableWidget *tableWidget) + : Object (interp, go, tableWidget), m_tableWidget (tableWidget), + m_curData (), m_blockUpdates (false) + { + qObject ()->setObjectName ("UItable"); + uitable::properties& tp = properties (); - m_curData = octave_value (tp.get_data ()); - Matrix bb = tp.get_boundingbox (false); - m_tableWidget->setObjectName ("UITable"); - m_tableWidget->setAutoFillBackground (true); - m_tableWidget->setGeometry (octave::math::round (bb(0)), - octave::math::round (bb(1)), - octave::math::round (bb(2)), - octave::math::round (bb(3))); - m_tableWidget->setFont (Utils::computeFont (tp)) ; - m_tableWidget->setSelectionBehavior (QAbstractItemView::SelectItems); - updatePalette (); - m_keyPressHandlerDefined = ! tp.get_keypressfcn ().isempty (); - m_keyReleaseHandlerDefined = ! tp.get_keyreleasefcn ().isempty (); - updateData (); - updateRowname (); - updateColumnname (); - updateColumnwidth (); - updateEnable (); // Also does rearrangeableColumns - m_tableWidget->setToolTip (Utils::fromStdString (tp.get_tooltipstring ())); - m_tableWidget->setVisible (tp.is_visible ()); - updateExtent (); - m_tableWidget->installEventFilter (this); + m_curData = octave_value (tp.get_data ()); + Matrix bb = tp.get_boundingbox (false); + m_tableWidget->setObjectName ("UITable"); + m_tableWidget->setAutoFillBackground (true); + m_tableWidget->setGeometry (octave::math::round (bb(0)), + octave::math::round (bb(1)), + octave::math::round (bb(2)), + octave::math::round (bb(3))); + m_tableWidget->setFont (Utils::computeFont (tp)) ; + m_tableWidget->setSelectionBehavior (QAbstractItemView::SelectItems); + updatePalette (); + m_keyPressHandlerDefined = ! tp.get_keypressfcn ().isempty (); + m_keyReleaseHandlerDefined = ! tp.get_keyreleasefcn ().isempty (); + updateData (); + updateRowname (); + updateColumnname (); + updateColumnwidth (); + updateEnable (); // Also does rearrangeableColumns + m_tableWidget->setToolTip (Utils::fromStdString (tp.get_tooltipstring ())); + m_tableWidget->setVisible (tp.is_visible ()); + updateExtent (); + m_tableWidget->installEventFilter (this); - connect (m_tableWidget, &QTableWidget::itemChanged, - this, &Table::itemChanged); - connect (m_tableWidget, &QTableWidget::cellClicked, - this, &Table::cellClicked); - connect (m_tableWidget, &QTableWidget::itemSelectionChanged, - this, &Table::itemSelectionChanged); -} + connect (m_tableWidget, &QTableWidget::itemChanged, + this, &Table::itemChanged); + connect (m_tableWidget, &QTableWidget::cellClicked, + this, &Table::cellClicked); + connect (m_tableWidget, &QTableWidget::itemSelectionChanged, + this, &Table::itemSelectionChanged); + } -Table::~Table (void) { } + Table::~Table () { } -void -Table::itemSelectionChanged () -{ - if (! (properties ().get_cellselectioncallback ().isempty ())) - { - QModelIndexList modelIndexList = - m_tableWidget->selectionModel ()->selectedIndexes (); - int length = modelIndexList.size (); - Matrix indices = Matrix (length, 2); - for (int i = 0; i < length; i++) - { - indices(i, 0) = modelIndexList.value (i).row () + 1; - indices(i, 1) = modelIndexList.value (i).column () + 1; - } - octave_scalar_map eventData; - eventData.setfield ("Indices", indices); - octave_value cellSelectionCallbackEventObject (eventData); - emit gh_callback_event (m_handle, "cellselectioncallback", - cellSelectionCallbackEventObject); - } -} - -void -Table::cellClicked (int row, int col) -{ - QCheckBox *checkBox = nullptr; - QWidget *widget - = qobject_cast (m_tableWidget->cellWidget (row, col)); - if (widget && ! widget->children ().isEmpty ()) - { - QHBoxLayout *layout - = qobject_cast (widget->children ().first ()); + void + Table::itemSelectionChanged () + { + if (! (properties ().get_cellselectioncallback ().isempty ())) + { + QModelIndexList modelIndexList = + m_tableWidget->selectionModel ()->selectedIndexes (); + int length = modelIndexList.size (); + Matrix indices = Matrix (length, 2); + for (int i = 0; i < length; i++) + { + indices(i, 0) = modelIndexList.value (i).row () + 1; + indices(i, 1) = modelIndexList.value (i).column () + 1; + } + octave_scalar_map eventData; + eventData.setfield ("Indices", indices); + octave_value cellSelectionCallbackEventObject (eventData); + emit gh_callback_event (m_handle, "cellselectioncallback", + cellSelectionCallbackEventObject); + } + } - if (layout && layout->count () > 0) - checkBox = qobject_cast (layout->itemAt (0)-> widget ()); - } - - if (checkBox && checkBox->property ("Enabled").toBool ()) - checkBoxClicked (row, col, checkBox); -} + void + Table::cellClicked (int row, int col) + { + QCheckBox *checkBox = nullptr; + QWidget *widget + = qobject_cast (m_tableWidget->cellWidget (row, col)); + if (widget && ! widget->children ().isEmpty ()) + { + QHBoxLayout *layout + = qobject_cast (widget->children ().first ()); -void -Table::sendCellEditCallback (int row, - int col, - octave_value old_value, - octave_value new_value, - octave_value edit_data, - octave_value error) -{ + if (layout && layout->count () > 0) + checkBox = qobject_cast (layout->itemAt (0)-> widget ()); + } - if (!(properties ().get_celleditcallback ().isempty ())) - { - Matrix indices = Matrix (1, 2); - indices(0, 0) = row + 1; - indices(0, 1) = col + 1; + if (checkBox && checkBox->property ("Enabled").toBool ()) + checkBoxClicked (row, col, checkBox); + } - octave_scalar_map eventData; - eventData.setfield ("Indices", indices); - eventData.setfield ("PreviousData", old_value); - eventData.setfield ("NewData", new_value); - eventData.setfield ("EditData", edit_data); - eventData.setfield ("Error", error); - - octave_value cellEditCallbackEventObject (eventData); - - emit gh_callback_event (m_handle, "celleditcallback", - cellEditCallbackEventObject); - } -} + void + Table::sendCellEditCallback (int row, + int col, + octave_value old_value, + octave_value new_value, + octave_value edit_data, + octave_value error) + { + if (!(properties ().get_celleditcallback ().isempty ())) + { + Matrix indices = Matrix (1, 2); + indices(0, 0) = row + 1; + indices(0, 1) = col + 1; -void -Table::comboBoxCurrentIndexChanged (const QString& value) -{ - if (m_blockUpdates) - return; + octave_scalar_map eventData; + eventData.setfield ("Indices", indices); + eventData.setfield ("PreviousData", old_value); + eventData.setfield ("NewData", new_value); + eventData.setfield ("EditData", edit_data); + eventData.setfield ("Error", error); - m_blockUpdates = true; - - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + octave_value cellEditCallbackEventObject (eventData); - octave::autolock guard (gh_mgr.graphics_lock ()); - - octave_value data = octave_value (m_curData); - bool ok = false; + emit gh_callback_event (m_handle, "celleditcallback", + cellEditCallbackEventObject); + } + } - QComboBox *comboBox = qobject_cast (sender ()); - int row = comboBox->property ("row").toInt (); - int col = comboBox->property ("col").toInt (); + void + Table::comboBoxCurrentIndexChanged (const QString& value) + { + if (m_blockUpdates) + return; - octave_value edit_data = octave_value (Utils::toStdString (value)); + m_blockUpdates = true; + + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - if (row < data.rows () && col < data.columns ()) - { - if (data.iscell ()) - { - Cell cell = data.cell_value (); - octave_value old_data = cell(row, col); - if (cell(row, col).is_string ()) - { - cell(row, col) = edit_data; - if (edit_data.string_value () != old_data.string_value ()) - { - m_curData = octave_value (cell); - emit gh_set_event (m_handle, "data", octave_value (cell), - false); - } + octave::autolock guard (gh_mgr.graphics_lock ()); + + octave_value data = octave_value (m_curData); + bool ok = false; + + QComboBox *comboBox = qobject_cast (sender ()); + int row = comboBox->property ("row").toInt (); + int col = comboBox->property ("col").toInt (); + + octave_value edit_data = octave_value (Utils::toStdString (value)); - octave_value error = octave_value (""); - sendCellEditCallback (row, col, - old_data, - edit_data, - edit_data, - error); - ok = true; - } - else - { - cell(row, col) = attempt_type_conversion (edit_data, old_data); - - // Inform the QTableWidget of our change - updateData (row, col, cell(row, col), - columnformat (col), columneditable (col)); - - m_curData = octave_value (cell); - emit gh_set_event (m_handle, "data", octave_value (cell), - false); + if (row < data.rows () && col < data.columns ()) + { + if (data.iscell ()) + { + Cell cell = data.cell_value (); + octave_value old_data = cell(row, col); + if (cell(row, col).is_string ()) + { + cell(row, col) = edit_data; + if (edit_data.string_value () != old_data.string_value ()) + { + m_curData = octave_value (cell); + emit gh_set_event (m_handle, "data", octave_value (cell), + false); + } - octave_value error = octave_value (""); - sendCellEditCallback (row, - col, - old_data, - cell(row, col), - edit_data, - error); - ok = true; - } - } - else - { - octave_value old_data = data.is_matrix_type () - ? 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)); + octave_value error = octave_value (""); + sendCellEditCallback (row, col, + old_data, + edit_data, + edit_data, + error); + ok = true; + } + else + { + cell(row, col) = attempt_type_conversion (edit_data, old_data); - // Inform the QTableWidget of our change - updateData (row, - col, - data.fast_elem_extract (row + col * data.rows ()), - columnformat (col), - columneditable (col)); + // Inform the QTableWidget of our change + updateData (row, col, cell(row, col), + columnformat (col), columneditable (col)); - m_curData = octave_value (data); - emit gh_set_event (m_handle, "data", data, false); + m_curData = octave_value (cell); + emit gh_set_event (m_handle, "data", octave_value (cell), + false); - octave_value error = octave_value (""); - sendCellEditCallback (row, - col, - old_data, - data.fast_elem_extract (row + col * data.rows ()), - edit_data, - error); - ok = true; - } - } - else - { - // Reset the QTableWidgetItem - updateData (row, col, octave_value (""), columnformat (col), - columneditable (col)); + octave_value error = octave_value (""); + sendCellEditCallback (row, + col, + old_data, + cell(row, col), + edit_data, + error); + ok = true; + } + } + else + { + octave_value old_data = data.is_matrix_type () + ? 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)); - octave_value error = - octave_value ("Table data is not editable at this location."); - sendCellEditCallback (row, - col, - octave_value (), - octave_value (), - edit_data, - error); - } + // Inform the QTableWidget of our change + updateData (row, + col, + data.fast_elem_extract (row + col * data.rows ()), + columnformat (col), + columneditable (col)); + + m_curData = octave_value (data); + emit gh_set_event (m_handle, "data", data, false); - if (! ok) - { - comboBox->setCurrentIndex (-1); - comboBox->setEditable (true); - comboBox->setEditText (comboBox->property ("original_value").toString ()); - comboBox->lineEdit ()->setReadOnly (true); - } - m_blockUpdates = false; -} - -void -Table::checkBoxClicked (int row, int col, QCheckBox *checkBox) -{ - if (m_blockUpdates) - return; - m_blockUpdates = true; - - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - bool new_value = ! checkBox->isChecked (); + octave_value error = octave_value (""); + sendCellEditCallback (row, + col, + old_data, + data.fast_elem_extract (row + col * data.rows ()), + edit_data, + error); + ok = true; + } + } + else + { + // Reset the QTableWidgetItem + updateData (row, col, octave_value (""), columnformat (col), + columneditable (col)); - octave_value data = octave_value (m_curData); - if (data.islogical ()) - { - // EASY WE JUST CONVERT - boolMatrix matrix = data.bool_matrix_value (); - if (row < matrix.rows () && col < matrix.columns ()) - { - bool old_value = matrix(row, col); - matrix(row, col) = new_value; - checkBox->setChecked (new_value); - if (new_value != old_value) - { - m_curData = octave_value (matrix); - emit gh_set_event (m_handle, "data", octave_value (matrix), - false); - } + octave_value error = + octave_value ("Table data is not editable at this location."); + sendCellEditCallback (row, + col, + octave_value (), + octave_value (), + edit_data, + error); + } - sendCellEditCallback (row, col, - octave_value (old_value), - octave_value (new_value), - octave_value (new_value), - octave_value ("")); + if (! ok) + { + comboBox->setCurrentIndex (-1); + comboBox->setEditable (true); + comboBox->setEditText (comboBox->property ("original_value").toString ()); + comboBox->lineEdit ()->setReadOnly (true); + } + m_blockUpdates = false; + } + + void + Table::checkBoxClicked (int row, int col, QCheckBox *checkBox) + { + if (m_blockUpdates) + return; + m_blockUpdates = true; - } - else - { - sendCellEditCallback (row, - col, - octave_value (), - octave_value (), - octave_value (new_value), - octave_value ("Table data is not editable at this location.")); - } - } - else if (data.iscell ()) - { - Cell cell = data.cell_value (); - if (row < cell.rows () && col < cell.columns ()) - { - if (cell(row, col).islogical ()) - { - bool old_value = cell(row, col).bool_value (); - cell(row, col) = octave_value (new_value); - checkBox->setChecked (new_value); - if (new_value != old_value) - { - m_curData = octave_value (cell); - emit gh_set_event (m_handle, "data", octave_value (cell), - false); - } + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + bool new_value = ! checkBox->isChecked (); + + octave_value data = octave_value (m_curData); + if (data.islogical ()) + { + // EASY WE JUST CONVERT + boolMatrix matrix = data.bool_matrix_value (); + if (row < matrix.rows () && col < matrix.columns ()) + { + bool old_value = matrix(row, col); + matrix(row, col) = new_value; + checkBox->setChecked (new_value); + if (new_value != old_value) + { + m_curData = octave_value (matrix); + emit gh_set_event (m_handle, "data", octave_value (matrix), + false); + } + + sendCellEditCallback (row, col, + octave_value (old_value), + octave_value (new_value), + octave_value (new_value), + octave_value ("")); - sendCellEditCallback (row, - col, - octave_value (old_value), - octave_value (new_value), - octave_value (new_value), - octave_value ("")); - } - else - { - sendCellEditCallback (row, - col, - cell(row, col), - octave_value (), - octave_value (new_value), - octave_value ("Cannot convert logical edit to other type.")); - } - } - else - { - sendCellEditCallback (row, - col, - cell(row, col), - octave_value (), - octave_value (new_value), - octave_value ("Table data is not editable at this location.")); - } - } - else if (data.is_matrix_type ()) - { - if (row < data.rows () && col < data.columns ()) - { - sendCellEditCallback (row, - col, - data.fast_elem_extract (row + col * data.rows ()), - octave_value (), - octave_value (new_value), - octave_value ("Cannot convert logical edit to other type.")); - } - else - { - sendCellEditCallback (row, - col, - data.fast_elem_extract (row + col * data.rows ()), - octave_value (), - octave_value (new_value), - octave_value ("Table data is not editable at this location.")); - } - } - m_blockUpdates = false; -} + } + else + { + sendCellEditCallback (row, + col, + octave_value (), + octave_value (), + octave_value (new_value), + octave_value ("Table data is not editable at this location.")); + } + } + else if (data.iscell ()) + { + Cell cell = data.cell_value (); + if (row < cell.rows () && col < cell.columns ()) + { + if (cell(row, col).islogical ()) + { + bool old_value = cell(row, col).bool_value (); + cell(row, col) = octave_value (new_value); + checkBox->setChecked (new_value); + if (new_value != old_value) + { + m_curData = octave_value (cell); + emit gh_set_event (m_handle, "data", octave_value (cell), + false); + } -void -Table::itemChanged (QTableWidgetItem *item) -{ - if (m_blockUpdates) - return; - m_blockUpdates = true; - - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - octave_value data = octave_value (m_curData); - - int row = item->row (); - int col = item->column (); - octave_value edit_data = octave_value (Utils::toStdString (item->text ())); - octave_value new_value; - octave_value old_value; - octave_value new_data; + sendCellEditCallback (row, + col, + octave_value (old_value), + octave_value (new_value), + octave_value (new_value), + octave_value ("")); + } + else + { + sendCellEditCallback (row, + col, + cell(row, col), + octave_value (), + octave_value (new_value), + octave_value ("Cannot convert logical edit to other type.")); + } + } + else + { + sendCellEditCallback (row, + col, + cell(row, col), + octave_value (), + octave_value (new_value), + octave_value ("Table data is not editable at this location.")); + } + } + else if (data.is_matrix_type ()) + { + if (row < data.rows () && col < data.columns ()) + { + sendCellEditCallback (row, + col, + data.fast_elem_extract (row + col * data.rows ()), + octave_value (), + octave_value (new_value), + octave_value ("Cannot convert logical edit to other type.")); + } + else + { + sendCellEditCallback (row, + col, + data.fast_elem_extract (row + col * data.rows ()), + octave_value (), + octave_value (new_value), + octave_value ("Table data is not editable at this location.")); + } + } + m_blockUpdates = false; + } - if (row < data.rows () && col < data.columns ()) - { - if (data.iscell ()) - { - old_value = data.cell_value () (row, col); - } - else if (data.is_matrix_type ()) - { - old_value = data.fast_elem_extract (row + col * data.rows ()); - } + void + Table::itemChanged (QTableWidgetItem *item) + { + if (m_blockUpdates) + return; + m_blockUpdates = true; + + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + octave_value data = octave_value (m_curData); - // Now we need to coerce the new_value in to the type of the old_value - if (old_value.is_string ()) - new_value = edit_data; - else - { - new_value = attempt_type_conversion (edit_data, old_value); - std::pair flag_and_text = - qStringValueFor (new_value, columnformat (col)); - item->setTextAlignment (flag_and_text.first); - item->setText (flag_and_text.second); - } + int row = item->row (); + int col = item->column (); + octave_value edit_data = octave_value (Utils::toStdString (item->text ())); + octave_value new_value; + octave_value old_value; + octave_value new_data; + + if (row < data.rows () && col < data.columns ()) + { + if (data.iscell ()) + { + old_value = data.cell_value () (row, col); + } + else if (data.is_matrix_type ()) + { + old_value = data.fast_elem_extract (row + col * data.rows ()); + } - if (data.iscell ()) - { - Cell cell = data.cell_value (); - cell(row, col) = new_value; - new_data = octave_value (cell); - } - else - { - data.fast_elem_insert (row + col * data.rows (), new_value); - new_data = data; - } - m_curData = octave_value (new_data); - emit gh_set_event (m_handle, "data", new_data, false); + // Now we need to coerce the new_value in to the type of the old_value + if (old_value.is_string ()) + new_value = edit_data; + else + { + new_value = attempt_type_conversion (edit_data, old_value); + std::pair flag_and_text = + qStringValueFor (new_value, columnformat (col)); + item->setTextAlignment (flag_and_text.first); + item->setText (flag_and_text.second); + } + + if (data.iscell ()) + { + Cell cell = data.cell_value (); + cell(row, col) = new_value; + new_data = octave_value (cell); + } + else + { + data.fast_elem_insert (row + col * data.rows (), new_value); + new_data = data; + } + m_curData = octave_value (new_data); + emit gh_set_event (m_handle, "data", new_data, false); - sendCellEditCallback (row, - col, - octave_value (old_value), - octave_value (new_value), - octave_value (new_value), - octave_value ("")); - } - else - { - item->setText (""); + sendCellEditCallback (row, + col, + octave_value (old_value), + octave_value (new_value), + octave_value (new_value), + octave_value ("")); + } + else + { + item->setText (""); - octave_value error = - octave_value ("Table data is not editable at this location."); - sendCellEditCallback (row, - col, - octave_value (), - octave_value (), - edit_data, - error); - } + octave_value error = + octave_value ("Table data is not editable at this location."); + sendCellEditCallback (row, + col, + octave_value (), + octave_value (), + edit_data, + error); + } - m_blockUpdates = false; -} + m_blockUpdates = false; + } -void -Table::redraw (void) -{ - update (uitable::properties::ID_POSITION); -} + void + Table::redraw () + { + update (uitable::properties::ID_POSITION); + } -void -Table::update (int pId) -{ - uitable::properties& tp = properties (); + void + Table::update (int pId) + { + uitable::properties& tp = properties (); - switch (pId) - { - case uitable::properties::ID_BACKGROUNDCOLOR: - case uitable::properties::ID_FOREGROUNDCOLOR: - updatePalette (); - break; + switch (pId) + { + case uitable::properties::ID_BACKGROUNDCOLOR: + case uitable::properties::ID_FOREGROUNDCOLOR: + updatePalette (); + break; - case uitable::properties::ID_COLUMNNAME: - updateColumnname (); - updateColumnwidth (); - break; + case uitable::properties::ID_COLUMNNAME: + updateColumnname (); + updateColumnwidth (); + break; - case uitable::properties::ID_COLUMNWIDTH: - updateColumnwidth (); - break; + case uitable::properties::ID_COLUMNWIDTH: + updateColumnwidth (); + break; - case uitable::properties::ID_COLUMNEDITABLE: - case uitable::properties::ID_COLUMNFORMAT: - case uitable::properties::ID_DATA: - m_blockUpdates = true; - m_curData = octave_value (tp.get_data ()); - updateData (); - updateRowname (); - updateColumnname (); - updateColumnwidth (); - updateEnable (); - m_blockUpdates = false; - break; + case uitable::properties::ID_COLUMNEDITABLE: + case uitable::properties::ID_COLUMNFORMAT: + case uitable::properties::ID_DATA: + m_blockUpdates = true; + m_curData = octave_value (tp.get_data ()); + updateData (); + updateRowname (); + updateColumnname (); + updateColumnwidth (); + updateEnable (); + m_blockUpdates = false; + break; + + case uitable::properties::ID_ENABLE: + updateEnable (); + break; - case uitable::properties::ID_ENABLE: - updateEnable (); - break; + case uitable::properties::ID_KEYPRESSFCN: + m_keyPressHandlerDefined = ! tp.get_keypressfcn ().isempty (); + break; - case uitable::properties::ID_KEYPRESSFCN: - m_keyPressHandlerDefined = ! tp.get_keypressfcn ().isempty (); - break; + case uitable::properties::ID_KEYRELEASEFCN: + m_keyReleaseHandlerDefined = ! tp.get_keyreleasefcn ().isempty (); + break; - case uitable::properties::ID_KEYRELEASEFCN: - m_keyReleaseHandlerDefined = ! tp.get_keyreleasefcn ().isempty (); - break; + case uitable::properties::ID_FONTNAME: + case uitable::properties::ID_FONTSIZE: + case uitable::properties::ID_FONTWEIGHT: + case uitable::properties::ID_FONTANGLE: + if (m_tableWidget) + { + m_tableWidget->setFont (Utils::computeFont (tp)); + for (int row = 0; row < m_tableWidget->rowCount (); row++) + { + m_tableWidget->setRowHeight (row, AUTO_HEIGHT); + } + } + break; - case uitable::properties::ID_FONTNAME: - case uitable::properties::ID_FONTSIZE: - case uitable::properties::ID_FONTWEIGHT: - case uitable::properties::ID_FONTANGLE: - if (m_tableWidget) + case uitable::properties::ID_POSITION: { - m_tableWidget->setFont (Utils::computeFont (tp)); - for (int row = 0; row < m_tableWidget->rowCount (); row++) - { - m_tableWidget->setRowHeight (row, AUTO_HEIGHT); - } + Matrix bb = tp.get_boundingbox (false); + m_tableWidget->setGeometry (octave::math::round (bb(0)), + octave::math::round (bb(1)), + octave::math::round (bb(2)), + octave::math::round (bb(3))); + updateExtent (); } - break; + break; - case uitable::properties::ID_POSITION: - { - Matrix bb = tp.get_boundingbox (false); - m_tableWidget->setGeometry (octave::math::round (bb(0)), - octave::math::round (bb(1)), - octave::math::round (bb(2)), - octave::math::round (bb(3))); - updateExtent (); - } - break; + case uitable::properties::ID_REARRANGEABLECOLUMNS: + updateRearrangeableColumns (); + break; - case uitable::properties::ID_REARRANGEABLECOLUMNS: - updateRearrangeableColumns (); - break; + case uitable::properties::ID_ROWNAME: + updateRowname (); + break; - case uitable::properties::ID_ROWNAME: - updateRowname (); - break; + case uitable::properties::ID_ROWSTRIPING: + updatePalette (); + break; - case uitable::properties::ID_ROWSTRIPING: - updatePalette (); - break; + case uitable::properties::ID_TOOLTIPSTRING: + m_tableWidget->setToolTip (Utils::fromStdString (tp.get_tooltipstring ())); + break; - case uitable::properties::ID_TOOLTIPSTRING: - m_tableWidget->setToolTip (Utils::fromStdString (tp.get_tooltipstring ())); - break; + case base_properties::ID_VISIBLE: + m_tableWidget->setVisible (tp.is_visible ()); + break; - case base_properties::ID_VISIBLE: - m_tableWidget->setVisible (tp.is_visible ()); - break; - - default: - break; + default: + break; - } -} + } + } -void -Table::updateColumnname (void) -{ - uitable::properties& tp = properties (); + void + Table::updateColumnname () + { + uitable::properties& tp = properties (); - // Reset the Column Count - m_tableWidget->setColumnCount (tp.get_data ().columns ()); + // Reset the Column Count + m_tableWidget->setColumnCount (tp.get_data ().columns ()); - octave_value columnname = tp.get_columnname (); - QStringList l; - bool visible = true; + octave_value columnname = tp.get_columnname (); + QStringList l; + bool visible = true; - if (columnname.is_string () && columnname.string_value (false) == "numbered") - for (int i = 0; i < m_tableWidget->columnCount (); i++) - l << QString::number (i + 1); - else if (columnname.is_string ()) - { - if (m_tableWidget->columnCount () > 0) - l << Utils::fromStdString (columnname.string_value ()); - for (int i = 1; i < m_tableWidget->columnCount (); i++) - l << ""; - } - else if (columnname.isempty ()) - { + if (columnname.is_string () && columnname.string_value (false) == "numbered") for (int i = 0; i < m_tableWidget->columnCount (); i++) - l << ""; + l << QString::number (i + 1); + else if (columnname.is_string ()) + { + if (m_tableWidget->columnCount () > 0) + l << Utils::fromStdString (columnname.string_value ()); + for (int i = 1; i < m_tableWidget->columnCount (); i++) + l << ""; + } + else if (columnname.isempty ()) + { + for (int i = 0; i < m_tableWidget->columnCount (); i++) + l << ""; - visible = false; - } - else if (columnname.iscell ()) - { - octave_idx_type n = columnname.numel (); - Cell cell_value = columnname.cell_value (); - - for (octave_idx_type i = 0; i < n; i++) - { - octave_value v = cell_value (i); - if (v.is_string ()) - l << Utils::fromStdString (v.string_value (true)); - else if (v.is_matrix_type ()) - { - Matrix data = v.matrix_value (); + visible = false; + } + else if (columnname.iscell ()) + { + octave_idx_type n = columnname.numel (); + Cell cell_value = columnname.cell_value (); - /* Now Matlab does something very strange here: - * If data is a row or column matrix, - * then each datapoint is added. - * Otherwise, nothing is set. - */ - if (data.rows () > 1 && data.cols () > 1) - l << ""; - else - for (octave_idx_type j = 0; j < data.numel (); j++) - l << QString::number (data(j)); - } - else if (v.isnumeric ()) - l << QString::number (v.double_value ()); - else - l << QString::number (v.double_value ()); - } - } - else if (columnname.is_matrix_type ()) - { - octave_idx_type n = columnname.numel (); - Matrix matrix_value = columnname.matrix_value (); + for (octave_idx_type i = 0; i < n; i++) + { + octave_value v = cell_value (i); + if (v.is_string ()) + l << Utils::fromStdString (v.string_value (true)); + else if (v.is_matrix_type ()) + { + Matrix data = v.matrix_value (); - for (octave_idx_type i = 0; i < n; i++) - l << QString::number (matrix_value(i)); - } - else - { - for (int i = 0; i < m_tableWidget->columnCount (); i++) - l << ""; - visible = false; - } - - l.replaceInStrings ("|", "\n"); - - // Now add the columns as required - if (m_tableWidget->columnCount () < l.length ()) - { - int oldColumnCount = m_tableWidget->columnCount (); - m_tableWidget->setColumnCount (l.length ()); - for (int col = oldColumnCount; col < l.length (); col++) - { - std::string format = columnformat (col); - bool enabled = columneditable (col); - - for (int row = 0; row < m_tableWidget->rowCount (); row++) - updateData (row, col, octave_value (""), format, enabled); - } - } + /* Now Matlab does something very strange here: + * If data is a row or column matrix, + * then each datapoint is added. + * Otherwise, nothing is set. + */ + if (data.rows () > 1 && data.cols () > 1) + l << ""; + else + for (octave_idx_type j = 0; j < data.numel (); j++) + l << QString::number (data(j)); + } + else if (v.isnumeric ()) + l << QString::number (v.double_value ()); + else + l << QString::number (v.double_value ()); + } + } + else if (columnname.is_matrix_type ()) + { + octave_idx_type n = columnname.numel (); + Matrix matrix_value = columnname.matrix_value (); - m_tableWidget->setHorizontalHeaderLabels (l); - m_tableWidget->horizontalHeader ()->setVisible (visible); -} - -void -Table::updateColumnwidth (void) -{ - uitable::properties& tp = properties (); - - octave_value columnwidth = tp.get_columnwidth (); - if (columnwidth.isempty () - || (columnwidth.is_string () - && columnwidth.string_value (false) == "auto")) - for (int i = 0; i < m_tableWidget->columnCount (); i++) - m_tableWidget->setColumnWidth (i, AUTO_WIDTH); - else if (columnwidth.is_string () - && columnwidth.string_value (false) == "preferred") - for (int i = 0; i < m_tableWidget->columnCount (); i++) + for (octave_idx_type i = 0; i < n; i++) + l << QString::number (matrix_value(i)); + } + else { - int column_size = - (qobject_cast (m_tableWidget))->sizeHintForColumn (i); - int header_size = m_tableWidget->horizontalHeader ()->sectionSizeHint (i); - - if (column_size > header_size) - header_size = column_size; - m_tableWidget->setColumnWidth (i, header_size); + for (int i = 0; i < m_tableWidget->columnCount (); i++) + l << ""; + visible = false; } - else if (columnwidth.iscell ()) - { - Cell cell_value = columnwidth.cell_value (); - int i = 0; - for (; i < m_tableWidget->columnCount () && i < cell_value.numel (); i++) - { - octave_value v = cell_value (i); - if (v.is_string () && v.string_value (false) == "auto") - m_tableWidget->setColumnWidth (i, AUTO_WIDTH); - else if (v.is_string () && v.string_value (false) == "preferred") - { - int column_size = - (qobject_cast (m_tableWidget))->sizeHintForColumn (i); - int header_size = m_tableWidget->horizontalHeader ()->sectionSizeHint (i); + + l.replaceInStrings ("|", "\n"); + + // Now add the columns as required + if (m_tableWidget->columnCount () < l.length ()) + { + int oldColumnCount = m_tableWidget->columnCount (); + m_tableWidget->setColumnCount (l.length ()); + for (int col = oldColumnCount; col < l.length (); col++) + { + std::string format = columnformat (col); + bool enabled = columneditable (col); + + for (int row = 0; row < m_tableWidget->rowCount (); row++) + updateData (row, col, octave_value (""), format, enabled); + } + } - if (column_size > header_size) - header_size = column_size; - m_tableWidget->setColumnWidth (i, header_size); - } - else - { - int w = int (v.double_value ()); - m_tableWidget->setColumnWidth (i, w); - } - } - for (; i < m_tableWidget->columnCount (); i++) + m_tableWidget->setHorizontalHeaderLabels (l); + m_tableWidget->horizontalHeader ()->setVisible (visible); + } + + void + Table::updateColumnwidth () + { + uitable::properties& tp = properties (); + + octave_value columnwidth = tp.get_columnwidth (); + if (columnwidth.isempty () + || (columnwidth.is_string () + && columnwidth.string_value (false) == "auto")) + for (int i = 0; i < m_tableWidget->columnCount (); i++) + m_tableWidget->setColumnWidth (i, AUTO_WIDTH); + else if (columnwidth.is_string () + && columnwidth.string_value (false) == "preferred") + for (int i = 0; i < m_tableWidget->columnCount (); i++) { int column_size = (qobject_cast (m_tableWidget))->sizeHintForColumn (i); @@ -1133,594 +1095,629 @@ header_size = column_size; m_tableWidget->setColumnWidth (i, header_size); } - } - else if (columnwidth.is_matrix_type ()) - { - Matrix matrix_value = columnwidth.matrix_value (); - int i = 0; - for (; i < m_tableWidget->columnCount () && i < matrix_value.numel (); i++) - { - octave_value v = matrix_value(i); - int w = int (v.double_value ()); - m_tableWidget->setColumnWidth (i, w); - } - for (; i < m_tableWidget->columnCount (); i++) - m_tableWidget->setColumnWidth (i, AUTO_WIDTH); - } -} + else if (columnwidth.iscell ()) + { + Cell cell_value = columnwidth.cell_value (); + int i = 0; + for (; i < m_tableWidget->columnCount () && i < cell_value.numel (); i++) + { + octave_value v = cell_value (i); + if (v.is_string () && v.string_value (false) == "auto") + m_tableWidget->setColumnWidth (i, AUTO_WIDTH); + else if (v.is_string () && v.string_value (false) == "preferred") + { + int column_size = + (qobject_cast (m_tableWidget))->sizeHintForColumn (i); + int header_size = m_tableWidget->horizontalHeader ()->sectionSizeHint (i); -bool inline -Table::columneditable (int col) -{ - uitable::properties& tp = properties (); - boolNDArray columneditable = tp.get_columneditable ().bool_array_value (); - bool editable = false; + if (column_size > header_size) + header_size = column_size; + m_tableWidget->setColumnWidth (i, header_size); + } + else + { + int w = int (v.double_value ()); + m_tableWidget->setColumnWidth (i, w); + } + } + for (; i < m_tableWidget->columnCount (); i++) + { + int column_size = + (qobject_cast (m_tableWidget))->sizeHintForColumn (i); + int header_size = m_tableWidget->horizontalHeader ()->sectionSizeHint (i); - if (! columneditable.isempty () && col < columneditable.numel ()) - editable = columneditable.xelem (col); - else if (! columneditable.isempty () && columneditable.numel () == 1) - editable = columneditable.xelem (0); + if (column_size > header_size) + header_size = column_size; + m_tableWidget->setColumnWidth (i, header_size); + } + } + else if (columnwidth.is_matrix_type ()) + { + Matrix matrix_value = columnwidth.matrix_value (); + int i = 0; + for (; i < m_tableWidget->columnCount () && i < matrix_value.numel (); i++) + { + octave_value v = matrix_value(i); + int w = int (v.double_value ()); + m_tableWidget->setColumnWidth (i, w); + } + for (; i < m_tableWidget->columnCount (); i++) + m_tableWidget->setColumnWidth (i, AUTO_WIDTH); + } + } - return editable; -} + bool inline + Table::columneditable (int col) + { + uitable::properties& tp = properties (); + boolNDArray columneditable = tp.get_columneditable ().bool_array_value (); + bool editable = false; -std::string inline -Table::columnformat (int col) -{ - uitable::properties& tp = properties (); - std::string format = ""; - octave_value ov_columnformat = tp.get_columnformat (); + if (! columneditable.isempty () && col < columneditable.numel ()) + editable = columneditable.xelem (col); + else if (! columneditable.isempty () && columneditable.numel () == 1) + editable = columneditable.xelem (0); + + return editable; + } - if (ov_columnformat.iscell ()) - { - Cell columnformat = ov_columnformat.cell_value (); - if (! columnformat.isempty () && col < columnformat.numel ()) - { - octave_value format_value = columnformat.xelem (col); + std::string inline + Table::columnformat (int col) + { + uitable::properties& tp = properties (); + std::string format = ""; + octave_value ov_columnformat = tp.get_columnformat (); + + if (ov_columnformat.iscell ()) + { + Cell columnformat = ov_columnformat.cell_value (); + if (! columnformat.isempty () && col < columnformat.numel ()) + { + octave_value format_value = columnformat.xelem (col); - if (! format_value.isempty () && format_value.is_string ()) - format = format_value.string_value (); - else if (! format_value.isempty () && format_value.iscell ()) - format = "popup"; - } - } - else if (ov_columnformat.is_string ()) - { - format = ov_columnformat.string_value (); - } - return format; -} + if (! format_value.isempty () && format_value.is_string ()) + format = format_value.string_value (); + else if (! format_value.isempty () && format_value.iscell ()) + format = "popup"; + } + } + else if (ov_columnformat.is_string ()) + { + format = ov_columnformat.string_value (); + } + return format; + } + + void inline + Table::updateDataColumn (int col) + { + octave_value data = properties ().get_data (); -void inline -Table::updateDataColumn (int col) -{ - octave_value data = properties ().get_data (); + std::string format = columnformat (col); + bool is_editable = columneditable (col); - std::string format = columnformat (col); - bool is_editable = columneditable (col); + for (octave_idx_type row = 0; row < data.rows (); row++) + updateData (row, + col, + data.iscell () + ? data.cell_value () (row, col) + : data.fast_elem_extract (row + col * data.rows ()), + format, + is_editable); + } - for (octave_idx_type row = 0; row < data.rows (); row++) + void inline + Table::updateData (int row, int col) + { + octave_value data = properties ().get_data (); updateData (row, col, data.iscell () ? data.cell_value () (row, col) : data.fast_elem_extract (row + col * data.rows ()), - format, - is_editable); -} + columnformat (col), + columneditable (col)); + } + + void inline + Table::updateData (int row, int col, octave_value value, + std::string format = "", bool enabled = false) + { + if (format == "logical" || (format == "" && value.islogical ())) + { + if (m_tableWidget->item (row, col)) + delete m_tableWidget->item (row, col); + + m_tableWidget->setCellWidget (row, col, checkBoxForLogical (value, enabled)); + m_tableWidget->cellWidget (row, col)->setProperty ("row", QVariant (row)); + m_tableWidget->cellWidget (row, col)->setProperty ("col", QVariant (col)); + } + else if (format == "popup" && enabled) + { + if (m_tableWidget->item (row, col)) + delete m_tableWidget->item (row, col); + + QString string_value = qStringValueFor (value, format).second; + uitable::properties& tp = properties (); + octave_value format_value = tp.get_columnformat ().cell_value ().xelem (col); + + QComboBox *comboBox = new QComboBox (); + comboBox->setProperty ("row", QVariant (row)); + comboBox->setProperty ("col", QVariant (col)); -void inline -Table::updateData (int row, int col) -{ - octave_value data = properties ().get_data (); - updateData (row, - col, - data.iscell () - ? data.cell_value () (row, col) - : data.fast_elem_extract (row + col * data.rows ()), - columnformat (col), - columneditable (col)); -} + int index = -1; + for (int k = 0; k < format_value.numel (); k++) + { + QString popup_item + = Utils::fromStdString (format_value.fast_elem_extract (k).string_value ()); + + comboBox->addItem (popup_item); + + if (popup_item == string_value) + index = k; + } + comboBox->setCurrentIndex (index); -void inline -Table::updateData (int row, int col, octave_value value, - std::string format = "", bool enabled = false) -{ - if (format == "logical" || (format == "" && value.islogical ())) - { - if (m_tableWidget->item (row, col)) - delete m_tableWidget->item (row, col); + if (index < 0) + { + comboBox->setEditable (true); + comboBox->setEditText (string_value); + comboBox->lineEdit ()->setReadOnly (true); + } + + comboBox->setProperty ("original_value", QVariant (string_value)); + + comboBox->installEventFilter (this); + m_tableWidget->setCellWidget (row, col, comboBox); + connect (comboBox, SIGNAL(currentIndexChanged (const QString&)), + this, SLOT(comboBoxCurrentIndexChanged (const QString&))); + } + else + { + if (m_tableWidget->cellWidget (row, col)) + delete m_tableWidget->cellWidget (row, col); + m_tableWidget->setItem (row, col, itemFor (value, format, enabled)); + } + } - m_tableWidget->setCellWidget (row, col, checkBoxForLogical (value, enabled)); - m_tableWidget->cellWidget (row, col)->setProperty ("row", QVariant (row)); - m_tableWidget->cellWidget (row, col)->setProperty ("col", QVariant (col)); - } - else if (format == "popup" && enabled) - { - if (m_tableWidget->item (row, col)) - delete m_tableWidget->item (row, col); + void + Table::updateData () + { + uitable::properties& tp = properties (); + + octave_value data = tp.get_data (); + + if (data.iscell () || data.is_matrix_type ()) + { + m_tableWidget->setRowCount (data.rows ()); + m_tableWidget->setColumnCount (data.columns ()); - QString string_value = qStringValueFor (value, format).second; - uitable::properties& tp = properties (); - octave_value format_value = tp.get_columnformat ().cell_value ().xelem (col); + for (octave_idx_type col = 0; col < data.columns (); col++) + updateDataColumn (col); + } + + for (octave_idx_type row = 0; row < m_tableWidget->rowCount (); row++) + m_tableWidget->setRowHeight (row, AUTO_HEIGHT); + } - QComboBox *comboBox = new QComboBox (); - comboBox->setProperty ("row", QVariant (row)); - comboBox->setProperty ("col", QVariant (col)); + void + Table::updateEnable () + { + uitable::properties& tp = properties (); + bool enabled = tp.is_enable (); + m_tableWidget->setEnabled (enabled); + + bool rearrangeableColumns = tp.is_rearrangeablecolumns (); - int index = -1; - for (int k = 0; k < format_value.numel (); k++) - { - QString popup_item - = Utils::fromStdString (format_value.fast_elem_extract (k).string_value ()); + // Set selection mode + m_tableWidget->setSelectionMode (enabled + ? QAbstractItemView::ExtendedSelection + : QAbstractItemView::NoSelection); - comboBox->addItem (popup_item); + // Set rearrangeablecolumns + m_tableWidget->horizontalHeader ()->setSectionsMovable (enabled && rearrangeableColumns); + m_tableWidget->horizontalHeader ()->setDragEnabled (enabled && rearrangeableColumns); + m_tableWidget->horizontalHeader ()->setDragDropMode (QAbstractItemView::InternalMove); + + // Turn off column editable + for (int col = 0; col < m_tableWidget->columnCount (); col++) + { + bool editable = columneditable (col); - if (popup_item == string_value) - index = k; - } - comboBox->setCurrentIndex (index); + for (int row = 0; row < m_tableWidget->rowCount (); row++) + if (QTableWidgetItem *item = m_tableWidget->item (row, col)) + { + Qt::ItemFlags flags = item->flags (); + if (enabled && editable) + item->setFlags (flags | Qt::ItemIsEditable); + else + item->setFlags (flags & ~Qt::ItemIsEditable); + } + else if (QWidget *widget = m_tableWidget->cellWidget (row, col)) + { + QCheckBox *checkBox = nullptr; + if (widget && ! widget->children ().isEmpty ()) + { + QHBoxLayout *layout + = qobject_cast (widget->children ().first ()); - if (index < 0) - { - comboBox->setEditable (true); - comboBox->setEditText (string_value); - comboBox->lineEdit ()->setReadOnly (true); - } - - comboBox->setProperty ("original_value", QVariant (string_value)); + if (layout && layout->count () > 0) + checkBox = qobject_cast (layout->itemAt (0)-> widget ()); + } - comboBox->installEventFilter (this); - m_tableWidget->setCellWidget (row, col, comboBox); - connect (comboBox, SIGNAL(currentIndexChanged (const QString&)), - this, SLOT(comboBoxCurrentIndexChanged (const QString&))); - } - else - { - if (m_tableWidget->cellWidget (row, col)) - delete m_tableWidget->cellWidget (row, col); - m_tableWidget->setItem (row, col, itemFor (value, format, enabled)); - } -} + if (checkBox) + widget->setProperty ("Enabled", QVariant (enabled & editable)); + else + { + widget->setAttribute (Qt::WA_TransparentForMouseEvents, + !(editable & enabled)); + + widget->setFocusPolicy (Qt::NoFocus); + } + } + } + } -void -Table::updateData () -{ - uitable::properties& tp = properties (); - - octave_value data = tp.get_data (); + void + Table::updateExtent () + { + QSize s = realQSizeForTable (m_tableWidget); + Matrix extent = Matrix (1, 4); + extent(0, 0) = 0; + extent(0, 1) = 0; + extent(0, 2) = s.width (); + extent(0, 3) = s.height () ; + graphics_object go = object (); + emit gh_set_event (go.get_handle (), "extent", extent, false); + } - if (data.iscell () || data.is_matrix_type ()) - { - m_tableWidget->setRowCount (data.rows ()); - m_tableWidget->setColumnCount (data.columns ()); - - for (octave_idx_type col = 0; col < data.columns (); col++) - updateDataColumn (col); - } + void + Table::updatePalette () + { + uitable::properties& tp = properties (); - for (octave_idx_type row = 0; row < m_tableWidget->rowCount (); row++) - m_tableWidget->setRowHeight (row, AUTO_HEIGHT); -} + QPalette p = m_tableWidget->palette (); + p.setColor (QPalette::Text, + Utils::fromRgb (tp.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Base, + Utils::fromRgb (tp.get_backgroundcolor_rgb ())); + p.setColor (QPalette::AlternateBase, + Utils::fromRgb (tp.get_alternatebackgroundcolor_rgb ())); + m_tableWidget->setPalette (p); + m_tableWidget->setAlternatingRowColors (tp.is_rowstriping ()); + // FIXME: Handle multiple alternating background colors + } -void -Table::updateEnable (void) -{ - uitable::properties& tp = properties (); - bool enabled = tp.is_enable (); - m_tableWidget->setEnabled (enabled); + void + Table::updateRowname () + { + uitable::properties& tp = properties (); - bool rearrangeableColumns = tp.is_rearrangeablecolumns (); + // Reset the row count + m_tableWidget->setRowCount (tp.get_data ().rows ()); + + octave_value rowname = tp.get_rowname (); + QStringList l; + bool visible = true; - // Set selection mode - m_tableWidget->setSelectionMode (enabled - ? QAbstractItemView::ExtendedSelection - : QAbstractItemView::NoSelection); - - // Set rearrangeablecolumns - m_tableWidget->horizontalHeader ()->setSectionsMovable (enabled && rearrangeableColumns); - m_tableWidget->horizontalHeader ()->setDragEnabled (enabled && rearrangeableColumns); - m_tableWidget->horizontalHeader ()->setDragDropMode (QAbstractItemView::InternalMove); + if (rowname.is_string () && rowname.string_value (false) == "numbered") + for (int i = 0; i < m_tableWidget->rowCount (); i++) + l << QString::number (i + 1); + else if (rowname.is_string ()) + { + if (m_tableWidget->rowCount () > 0) + l << Utils::fromStdString (rowname.string_value ()); + for (int i = 1; i < m_tableWidget->rowCount (); i++) + l << ""; + } + else if (rowname.isempty ()) + { + for (int i = 0; i < m_tableWidget->rowCount (); i++) + l << ""; + visible = false; + } + else if (rowname.iscell ()) + { + octave_idx_type n = rowname.numel (); + Cell cell_value = rowname.cell_value (); - // Turn off column editable - for (int col = 0; col < m_tableWidget->columnCount (); col++) - { - bool editable = columneditable (col); + for (octave_idx_type i = 0; i < n; i++) + { + octave_value v = cell_value (i); + if (v.is_string ()) + l << Utils::fromStdString (v.string_value (true)); + else if (v.is_matrix_type ()) + { + Matrix data = v.matrix_value (); - for (int row = 0; row < m_tableWidget->rowCount (); row++) - if (QTableWidgetItem *item = m_tableWidget->item (row, col)) - { - Qt::ItemFlags flags = item->flags (); - if (enabled && editable) - item->setFlags (flags | Qt::ItemIsEditable); + /* Now Matlab does something very strange here: + * If data is a row or column matrix, + * then each datapoint is added. + * Otherwise, nothing is set. + */ + if (data.rows () > 1 && data.cols () > 1) + l << ""; + else + for (octave_idx_type j = 0; j < data.numel (); j++) + l << QString::number (data(j)); + } + else if (v.isnumeric ()) + l << QString::number (v.double_value (true)); else - item->setFlags (flags & ~Qt::ItemIsEditable); + l << QString::number (v.double_value (true)); } - else if (QWidget *widget = m_tableWidget->cellWidget (row, col)) - { - QCheckBox *checkBox = nullptr; - if (widget && ! widget->children ().isEmpty ()) - { - QHBoxLayout *layout - = qobject_cast (widget->children ().first ()); + } + else if (rowname.is_matrix_type ()) + { + octave_idx_type n = rowname.numel (); + Matrix matrix_value = rowname.matrix_value (); - if (layout && layout->count () > 0) - checkBox = qobject_cast (layout->itemAt (0)-> widget ()); - } + for (octave_idx_type i = 0; i < n; i++) + l << QString::number (matrix_value(i)); + } + else + { + for (int i = 0; i < m_tableWidget->columnCount (); i++) + l << ""; + visible = false; + } - if (checkBox) - widget->setProperty ("Enabled", QVariant (enabled & editable)); - else + // Add dummy rows as required + if (m_tableWidget->rowCount () < l.length ()) + { + int oldRowCount = m_tableWidget->rowCount (); + m_tableWidget->setRowCount (l.length ()); + + for (int col = 0; col < m_tableWidget->columnCount (); col++) + { + std::string format = columnformat (col); + bool enabled = columneditable (col); + + for (int row = oldRowCount; row < l.length (); row++) { - widget->setAttribute (Qt::WA_TransparentForMouseEvents, - !(editable & enabled)); + m_tableWidget->setRowHeight (row, AUTO_HEIGHT); - widget->setFocusPolicy (Qt::NoFocus); + updateData (row, col, octave_value (""), format, enabled); } } - } -} + } -void -Table::updateExtent (void) -{ - QSize s = realQSizeForTable (m_tableWidget); - Matrix extent = Matrix (1, 4); - extent(0, 0) = 0; - extent(0, 1) = 0; - extent(0, 2) = s.width (); - extent(0, 3) = s.height () ; - graphics_object go = object (); - emit gh_set_event (go.get_handle (), "extent", extent, false); -} + m_tableWidget->setVerticalHeaderLabels (l); + m_tableWidget->verticalHeader ()->setVisible (visible); + } -void -Table::updatePalette (void) -{ - uitable::properties& tp = properties (); + void + Table::updateRearrangeableColumns () + { + uitable::properties& tp = properties (); - QPalette p = m_tableWidget->palette (); - p.setColor (QPalette::Text, - Utils::fromRgb (tp.get_foregroundcolor_rgb ())); - p.setColor (QPalette::Base, - Utils::fromRgb (tp.get_backgroundcolor_rgb ())); - p.setColor (QPalette::AlternateBase, - Utils::fromRgb (tp.get_alternatebackgroundcolor_rgb ())); - m_tableWidget->setPalette (p); - m_tableWidget->setAlternatingRowColors (tp.is_rowstriping ()); - // FIXME: Handle multiple alternating background colors -} + bool rearrangeableColumns = tp.is_rearrangeablecolumns (); + bool enabled = tp.is_enable (); -void -Table::updateRowname (void) -{ - uitable::properties& tp = properties (); + m_tableWidget->horizontalHeader ()->setSectionsMovable (enabled && rearrangeableColumns); + m_tableWidget->horizontalHeader ()->setDragEnabled (enabled && rearrangeableColumns); + m_tableWidget->horizontalHeader ()->setDragDropMode (QAbstractItemView::InternalMove); + } - // Reset the row count - m_tableWidget->setRowCount (tp.get_data ().rows ()); - - octave_value rowname = tp.get_rowname (); - QStringList l; - bool visible = true; + bool + Table::eventFilter (QObject *watched, QEvent *xevent) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - if (rowname.is_string () && rowname.string_value (false) == "numbered") - for (int i = 0; i < m_tableWidget->rowCount (); i++) - l << QString::number (i + 1); - else if (rowname.is_string ()) - { - if (m_tableWidget->rowCount () > 0) - l << Utils::fromStdString (rowname.string_value ()); - for (int i = 1; i < m_tableWidget->rowCount (); i++) - l << ""; - } - else if (rowname.isempty ()) - { - for (int i = 0; i < m_tableWidget->rowCount (); i++) - l << ""; - visible = false; - } - else if (rowname.iscell ()) - { - octave_idx_type n = rowname.numel (); - Cell cell_value = rowname.cell_value (); + //uitable::properties& tp = properties (); + if (qobject_cast (watched)) + { + switch (xevent->type ()) + { + case QEvent::Resize: + { + octave::autolock guard (gh_mgr.graphics_lock ()); - for (octave_idx_type i = 0; i < n; i++) - { - octave_value v = cell_value (i); - if (v.is_string ()) - l << Utils::fromStdString (v.string_value (true)); - else if (v.is_matrix_type ()) - { - Matrix data = v.matrix_value (); - - /* Now Matlab does something very strange here: - * If data is a row or column matrix, - * then each datapoint is added. - * Otherwise, nothing is set. - */ - if (data.rows () > 1 && data.cols () > 1) - l << ""; - else - for (octave_idx_type j = 0; j < data.numel (); j++) - l << QString::number (data(j)); + graphics_object go = object (); + if (go.valid_object ()) + { + const uitable::properties& tp = + Utils::properties (go); + if (tp.fontunits_is ("normalized")) + m_tableWidget->setFont (Utils::computeFont (tp)); + } } - else if (v.isnumeric ()) - l << QString::number (v.double_value (true)); - else - l << QString::number (v.double_value (true)); - } - } - else if (rowname.is_matrix_type ()) - { - octave_idx_type n = rowname.numel (); - Matrix matrix_value = rowname.matrix_value (); + break; - for (octave_idx_type i = 0; i < n; i++) - l << QString::number (matrix_value(i)); - } - else - { - for (int i = 0; i < m_tableWidget->columnCount (); i++) - l << ""; - visible = false; - } + case QEvent::MouseButtonPress: + { + octave::autolock guard (gh_mgr.graphics_lock ()); - // Add dummy rows as required - if (m_tableWidget->rowCount () < l.length ()) - { - int oldRowCount = m_tableWidget->rowCount (); - m_tableWidget->setRowCount (l.length ()); - - for (int col = 0; col < m_tableWidget->columnCount (); col++) - { - std::string format = columnformat (col); - bool enabled = columneditable (col); + QMouseEvent *m = dynamic_cast (xevent); + graphics_object go = object (); + const uitable::properties& tp = + Utils::properties (go); + graphics_object fig = go.get_ancestor ("figure"); - for (int row = oldRowCount; row < l.length (); row++) - { - m_tableWidget->setRowHeight (row, AUTO_HEIGHT); - - updateData (row, col, octave_value (""), format, enabled); - } - } - } - - m_tableWidget->setVerticalHeaderLabels (l); - m_tableWidget->verticalHeader ()->setVisible (visible); -} + if (m->button () != Qt::LeftButton || ! tp.is_enable ()) + { + emit gh_set_event (fig.get_handle (), "selectiontype", + Utils::figureSelectionType (m), false); + emit gh_set_event (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig, m), + false); + emit gh_callback_event (fig.get_handle (), + "windowbuttondownfcn"); + emit gh_callback_event (m_handle, "buttondownfcn"); -void -Table::updateRearrangeableColumns (void) -{ - uitable::properties& tp = properties (); - - bool rearrangeableColumns = tp.is_rearrangeablecolumns (); - bool enabled = tp.is_enable (); - - m_tableWidget->horizontalHeader ()->setSectionsMovable (enabled && rearrangeableColumns); - m_tableWidget->horizontalHeader ()->setDragEnabled (enabled && rearrangeableColumns); - m_tableWidget->horizontalHeader ()->setDragDropMode (QAbstractItemView::InternalMove); -} - -bool -Table::eventFilter (QObject *watched, QEvent *xevent) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - //uitable::properties& tp = properties (); - if (qobject_cast (watched)) - { - switch (xevent->type ()) - { - case QEvent::Resize: - { - octave::autolock guard (gh_mgr.graphics_lock ()); + if (m->button () == Qt::RightButton) + ContextMenu::executeAt (m_interpreter, properties (), + m->globalPos ()); + } + else + { + emit gh_set_event (fig.get_handle (), "selectiontype", + octave_value ("normal"), false); + } + } + break; - graphics_object go = object (); - if (go.valid_object ()) - { - const uitable::properties& tp = - Utils::properties (go); - if (tp.fontunits_is ("normalized")) - m_tableWidget->setFont (Utils::computeFont (tp)); - } - } - break; + case QEvent::KeyPress: + { + QKeyEvent *k = dynamic_cast (xevent); + if (m_keyPressHandlerDefined) + { + octave::autolock guard (gh_mgr.graphics_lock ()); - case QEvent::MouseButtonPress: - { - octave::autolock guard (gh_mgr.graphics_lock ()); + octave_scalar_map keyData = Utils::makeKeyEventStruct (k); + graphics_object fig = object ().get_ancestor ("figure"); - QMouseEvent *m = dynamic_cast (xevent); - graphics_object go = object (); - const uitable::properties& tp = - Utils::properties (go); - graphics_object fig = go.get_ancestor ("figure"); + emit gh_set_event (fig.get_handle (), "currentcharacter", + keyData.getfield ("Character"), false); + emit gh_callback_event (m_handle, "keypressfcn", keyData); + } + int row = m_tableWidget->currentRow (); + int col = m_tableWidget->currentColumn (); + switch (k->key ()) + { + case Qt::Key_Space: + { + QCheckBox *checkBox = nullptr; - if (m->button () != Qt::LeftButton || ! tp.is_enable ()) - { - emit gh_set_event (fig.get_handle (), "selectiontype", - Utils::figureSelectionType (m), false); - emit gh_set_event (fig.get_handle (), "currentpoint", - Utils::figureCurrentPoint (fig, m), - false); - emit gh_callback_event (fig.get_handle (), - "windowbuttondownfcn"); - emit gh_callback_event (m_handle, "buttondownfcn"); + QWidget *widget + = qobject_cast (m_tableWidget->cellWidget (row, col)); - if (m->button () == Qt::RightButton) - ContextMenu::executeAt (m_interpreter, properties (), - m->globalPos ()); - } - else - { - emit gh_set_event (fig.get_handle (), "selectiontype", - octave_value ("normal"), false); - } - } - break; + if (widget && ! widget->children ().isEmpty ()) + { + QHBoxLayout *layout + = qobject_cast (widget->children ().first ()); + + if (layout && layout->count () > 0) + checkBox = qobject_cast (layout->itemAt (0)-> widget ()); + } - case QEvent::KeyPress: - { - QKeyEvent *k = dynamic_cast (xevent); - if (m_keyPressHandlerDefined) - { - octave::autolock guard (gh_mgr.graphics_lock ()); - - octave_scalar_map keyData = Utils::makeKeyEventStruct (k); - graphics_object fig = object ().get_ancestor ("figure"); + if (checkBox && checkBox->property ("Enabled").toBool ()) + checkBoxClicked (row, col, checkBox); - emit gh_set_event (fig.get_handle (), "currentcharacter", - keyData.getfield ("Character"), false); - emit gh_callback_event (m_handle, "keypressfcn", keyData); - } - int row = m_tableWidget->currentRow (); - int col = m_tableWidget->currentColumn (); - switch (k->key ()) - { - case Qt::Key_Space: - { - QCheckBox *checkBox = nullptr; + QComboBox *comboBox + = qobject_cast (m_tableWidget->cellWidget (row, col)); - QWidget *widget - = qobject_cast (m_tableWidget->cellWidget (row, col)); + if (comboBox) + comboBox->showPopup (); + } + break; - if (widget && ! widget->children ().isEmpty ()) - { - QHBoxLayout *layout - = qobject_cast (widget->children ().first ()); - - if (layout && layout->count () > 0) - checkBox = qobject_cast (layout->itemAt (0)-> widget ()); - } - - if (checkBox && checkBox->property ("Enabled").toBool ()) - checkBoxClicked (row, col, checkBox); - - QComboBox *comboBox - = qobject_cast (m_tableWidget->cellWidget (row, col)); - - if (comboBox) - comboBox->showPopup (); - } - break; - - case Qt::Key_Return: - case Qt::Key_Enter: - { - if (k->modifiers () == Qt::NoModifier) - { - if (row + 1 < m_tableWidget->rowCount ()) - m_tableWidget->setCurrentCell (row + 1, col); - else - { - if (col + 1 < m_tableWidget->columnCount ()) - m_tableWidget->setCurrentCell (0, col + 1); - else - m_tableWidget->setCurrentCell (0, 0); - } - } - else if (k->modifiers () == Qt::ShiftModifier) - { - if (row - 1 >= 0) - m_tableWidget->setCurrentCell (row - 1, col); - else - { - if (col - 1 >= 0) - m_tableWidget->setCurrentCell + case Qt::Key_Return: + case Qt::Key_Enter: + { + if (k->modifiers () == Qt::NoModifier) + { + if (row + 1 < m_tableWidget->rowCount ()) + m_tableWidget->setCurrentCell (row + 1, col); + else + { + if (col + 1 < m_tableWidget->columnCount ()) + m_tableWidget->setCurrentCell (0, col + 1); + else + m_tableWidget->setCurrentCell (0, 0); + } + } + else if (k->modifiers () == Qt::ShiftModifier) + { + if (row - 1 >= 0) + m_tableWidget->setCurrentCell (row - 1, col); + else + { + if (col - 1 >= 0) + m_tableWidget->setCurrentCell (m_tableWidget->rowCount () - 1, col - 1); - else - m_tableWidget->setCurrentCell + else + m_tableWidget->setCurrentCell (m_tableWidget->rowCount () - 1, m_tableWidget->columnCount () - 1); + } + } + } + break; + + default: + break; + } + } + break; + + case QEvent::KeyRelease: + { + if (m_keyReleaseHandlerDefined) + { + octave::autolock guard (gh_mgr.graphics_lock ()); + + QKeyEvent *k = dynamic_cast (xevent); + + octave_scalar_map keyData = Utils::makeKeyEventStruct (k); + graphics_object fig = object ().get_ancestor ("figure"); + + emit gh_set_event (fig.get_handle (), "currentcharacter", + keyData.getfield ("Character"), false); + emit gh_callback_event (m_handle, "keyreleasefcn", keyData); + } + } + break; + + default: + break; + } + } + else if (qobject_cast (watched)) + { + switch (xevent->type ()) + { + case QEvent::MouseButtonPress: + { + octave::autolock guard (gh_mgr.graphics_lock ()); + + QMouseEvent *m = dynamic_cast (xevent); + graphics_object go = object (); + const uitable::properties& tp = Utils::properties (go); + graphics_object fig = go.get_ancestor ("figure"); + + if (m->button () != Qt::LeftButton || ! tp.is_enable ()) + { + emit gh_set_event (fig.get_handle (), "selectiontype", + Utils::figureSelectionType (m), false); + emit gh_set_event (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig, m), + false); + emit gh_callback_event (fig.get_handle (), + "windowbuttondownfcn"); + emit gh_callback_event (m_handle, "buttondownfcn"); + + if (m->button () == Qt::RightButton) + ContextMenu::executeAt (m_interpreter, tp, m->globalPos ()); + } + else + { + emit gh_set_event (fig.get_handle (), "selectiontype", + Utils::figureSelectionType (m), false); + + QComboBox *comboBox_0 = qobject_cast (watched); + for (int row = 0; row < m_tableWidget->rowCount (); row++) + { + for (int col = 0; col < m_tableWidget->columnCount (); col++) + { + QComboBox *comboBox_1 + = qobject_cast (m_tableWidget->cellWidget (row, col)); + + if (comboBox_0 == comboBox_1) + m_tableWidget->setCurrentCell (row, col); } } } - break; - - default: - break; - } - } - break; - - case QEvent::KeyRelease: - { - if (m_keyReleaseHandlerDefined) - { - octave::autolock guard (gh_mgr.graphics_lock ()); - - QKeyEvent *k = dynamic_cast (xevent); - - octave_scalar_map keyData = Utils::makeKeyEventStruct (k); - graphics_object fig = object ().get_ancestor ("figure"); - - emit gh_set_event (fig.get_handle (), "currentcharacter", - keyData.getfield ("Character"), false); - emit gh_callback_event (m_handle, "keyreleasefcn", keyData); - } - } - break; - - default: - break; - } - } - else if (qobject_cast (watched)) - { - switch (xevent->type ()) - { - case QEvent::MouseButtonPress: - { - octave::autolock guard (gh_mgr.graphics_lock ()); + } + break; - QMouseEvent *m = dynamic_cast (xevent); - graphics_object go = object (); - const uitable::properties& tp = Utils::properties (go); - graphics_object fig = go.get_ancestor ("figure"); - - if (m->button () != Qt::LeftButton || ! tp.is_enable ()) - { - emit gh_set_event (fig.get_handle (), "selectiontype", - Utils::figureSelectionType (m), false); - emit gh_set_event (fig.get_handle (), "currentpoint", - Utils::figureCurrentPoint (fig, m), - false); - emit gh_callback_event (fig.get_handle (), - "windowbuttondownfcn"); - emit gh_callback_event (m_handle, "buttondownfcn"); - - if (m->button () == Qt::RightButton) - ContextMenu::executeAt (m_interpreter, tp, m->globalPos ()); - } - else - { - emit gh_set_event (fig.get_handle (), "selectiontype", - Utils::figureSelectionType (m), false); - - QComboBox *comboBox_0 = qobject_cast (watched); - for (int row = 0; row < m_tableWidget->rowCount (); row++) - { - for (int col = 0; col < m_tableWidget->columnCount (); col++) - { - QComboBox *comboBox_1 - = qobject_cast (m_tableWidget->cellWidget (row, col)); - - if (comboBox_0 == comboBox_1) - m_tableWidget->setCurrentCell (row, col); - } - } - } + default: + break; } - break; - - default: - break; - } - } - return false; -} + } + return false; + } #undef AUTO_HEIGHT diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/Table.h --- a/libgui/graphics/Table.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/Table.h Mon Jan 30 18:36:03 2023 +0100 @@ -34,65 +34,64 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; + + class Container; -class Container; - -class Table : public Object -{ - Q_OBJECT + class Table : public Object + { + Q_OBJECT -public: - Table (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QTableWidget *tableWidget); - ~Table (void); + public: + Table (octave::interpreter& interp, + const graphics_object& go, QTableWidget *tableWidget); + ~Table (); - Container * innerContainer (void) { return m_container; } + Container * innerContainer () { return m_container; } - bool eventFilter (QObject *watched, QEvent *event); + bool eventFilter (QObject *watched, QEvent *event); - static Table * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static Table * + 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); + protected: + void update (int pId); + 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); + private slots: + void itemChanged (QTableWidgetItem *item); + void comboBoxCurrentIndexChanged (const QString& value); + void cellClicked (int row, int col); + void itemSelectionChanged (); -private: - Container *m_container; - QTableWidget *m_tableWidget; - octave_value m_curData; - bool m_blockUpdates; - bool m_keyPressHandlerDefined; - bool m_keyReleaseHandlerDefined; - QWidget * checkBoxForLogical(octave_value cal, bool enabled); - void updateData (int row, int col, octave_value value, std::string format, - bool enabled); - void updateData (int row, int col); - void updateDataColumn (int col); - std::string columnformat (int column); - bool columneditable (int column); - void sendCellEditCallback (int row, int col, octave_value old_value, - octave_value new_value, octave_value edit_data, octave_value error); - void checkBoxClicked (int row, int col, QCheckBox* checkBox); + private: + Container *m_container; + QTableWidget *m_tableWidget; + octave_value m_curData; + bool m_blockUpdates; + bool m_keyPressHandlerDefined; + bool m_keyReleaseHandlerDefined; + QWidget * checkBoxForLogical(octave_value cal, bool enabled); + void updateData (int row, int col, octave_value value, std::string format, + bool enabled); + void updateData (int row, int col); + void updateDataColumn (int col); + std::string columnformat (int column); + bool columneditable (int column); + void sendCellEditCallback (int row, int col, octave_value old_value, + octave_value new_value, octave_value edit_data, octave_value error); + void checkBoxClicked (int row, int col, QCheckBox* checkBox); -}; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/TextControl.cc --- a/libgui/graphics/TextControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/TextControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,67 +33,63 @@ #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) -{ - Object *parent = parentObject (interp, go); + TextControl * + TextControl::create (octave::interpreter& interp, const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - return new TextControl (oct_qobj, interp, go, new QLabel (container)); - } - - return nullptr; -} + if (container) + return new TextControl (interp, go, new QLabel (container)); + } -TextControl::TextControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, QLabel *label) - : BaseControl (oct_qobj, interp, go, label) -{ - uicontrol::properties& up = properties (); + return nullptr; + } + + TextControl::TextControl (octave::interpreter& interp, + const graphics_object& go, QLabel *label) + : BaseControl (interp, go, label) + { + uicontrol::properties& up = properties (); - label->setAutoFillBackground (true); - label->setTextFormat (Qt::PlainText); - label->setWordWrap (false); - label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), - up.get_verticalalignment ())); - label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n")); -} + label->setAutoFillBackground (true); + label->setTextFormat (Qt::PlainText); + label->setWordWrap (false); + label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), + up.get_verticalalignment ())); + label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n")); + } -TextControl::~TextControl (void) -{ } + TextControl::~TextControl () + { } -void -TextControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QLabel *label = qWidget (); + void + TextControl::update (int pId) + { + uicontrol::properties& up = properties (); + QLabel *label = qWidget (); - switch (pId) - { - case uicontrol::properties::ID_STRING: - label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n")); - break; + switch (pId) + { + case uicontrol::properties::ID_STRING: + label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n")); + break; - case uicontrol::properties::ID_HORIZONTALALIGNMENT: - case uicontrol::properties::ID_VERTICALALIGNMENT: - label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), - up.get_verticalalignment ())); - break; + case uicontrol::properties::ID_HORIZONTALALIGNMENT: + case uicontrol::properties::ID_VERTICALALIGNMENT: + label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), + up.get_verticalalignment ())); + break; - default: - BaseControl::update (pId); - break; - } -} + default: + BaseControl::update (pId); + break; + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/TextControl.h --- a/libgui/graphics/TextControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/TextControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,23 +32,22 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class TextControl : public BaseControl -{ -public: - TextControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QLabel *label); - ~TextControl (void); + class TextControl : public BaseControl + { + public: + TextControl (octave::interpreter& interp, + const graphics_object& go, QLabel *label); + ~TextControl (); - static TextControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static TextControl * + create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); -}; + protected: + void update (int pId); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/TextEdit.h --- a/libgui/graphics/TextEdit.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/TextEdit.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/ToggleButtonControl.cc --- a/libgui/graphics/ToggleButtonControl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ToggleButtonControl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,77 +34,73 @@ #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, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + ToggleButtonControl * + ToggleButtonControl::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - Container *container = parent->innerContainer (); + if (parent) + { + Container *container = parent->innerContainer (); - if (container) - return new ToggleButtonControl (oct_qobj, interp, go, - new QPushButton (container)); - } + if (container) + return new ToggleButtonControl (interp, go, + new QPushButton (container)); + } - return nullptr; -} + return nullptr; + } -ToggleButtonControl::ToggleButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, - QPushButton *btn) - : ButtonControl (oct_qobj, interp, go, btn) -{ - Object *parent = parentObject (interp, go); - ButtonGroup *btnGroup = dynamic_cast(parent); - if (btnGroup) - btnGroup->addButton (btn); + ToggleButtonControl::ToggleButtonControl (octave::interpreter& interp, + const graphics_object& go, + QPushButton *btn) + : ButtonControl (interp, go, btn) + { + Object *parent = parentObject (interp, go); + ButtonGroup *btnGroup = dynamic_cast(parent); + if (btnGroup) + btnGroup->addButton (btn); - uicontrol::properties& up = properties (); + uicontrol::properties& up = properties (); - btn->setCheckable (true); - btn->setAutoFillBackground (true); - octave_value cdat = up.get_cdata (); - QImage img = Utils::makeImageFromCData (cdat, - cdat.columns (), cdat.rows ()); - btn->setIcon (QIcon (QPixmap::fromImage (img))); - btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); -} + btn->setCheckable (true); + btn->setAutoFillBackground (true); + octave_value cdat = up.get_cdata (); + QImage img = Utils::makeImageFromCData (cdat, + cdat.columns (), cdat.rows ()); + btn->setIcon (QIcon (QPixmap::fromImage (img))); + btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); + } -ToggleButtonControl::~ToggleButtonControl (void) -{ } + ToggleButtonControl::~ToggleButtonControl () + { } -void -ToggleButtonControl::update (int pId) -{ - uicontrol::properties& up = properties (); - QPushButton *btn = qWidget (); + void + ToggleButtonControl::update (int pId) + { + uicontrol::properties& up = properties (); + QPushButton *btn = qWidget (); - switch (pId) - { - case uicontrol::properties::ID_CDATA: + switch (pId) { - octave_value cdat = up.get_cdata (); - QImage img = Utils::makeImageFromCData (cdat, - cdat.rows (), - cdat.columns ()); - btn->setIcon (QIcon (QPixmap::fromImage (img))); - btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); + case uicontrol::properties::ID_CDATA: + { + octave_value cdat = up.get_cdata (); + QImage img = Utils::makeImageFromCData (cdat, + cdat.rows (), + cdat.columns ()); + btn->setIcon (QIcon (QPixmap::fromImage (img))); + btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); + } + break; + + default: + ButtonControl::update (pId); + break; } - break; - - default: - ButtonControl::update (pId); - break; - } -} + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ToggleButtonControl.h --- a/libgui/graphics/ToggleButtonControl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ToggleButtonControl.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,24 +32,22 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class ToggleButtonControl : public ButtonControl -{ -public: - ToggleButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, QPushButton *box); - ~ToggleButtonControl (void); + class ToggleButtonControl : public ButtonControl + { + public: + ToggleButtonControl (octave::interpreter& interp, + const graphics_object& go, QPushButton *box); + ~ToggleButtonControl (); - static ToggleButtonControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static ToggleButtonControl * + create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); -}; + protected: + void update (int pId); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ToggleTool.cc --- a/libgui/graphics/ToggleTool.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ToggleTool.cc Mon Jan 30 18:36:03 2023 +0100 @@ -31,68 +31,64 @@ #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) -{ - Object *parent = parentObject (interp, go); + ToggleTool * + ToggleTool::create (octave::interpreter& interp, const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - QWidget *parentWidget = parent->qWidget (); + if (parent) + { + QWidget *parentWidget = parent->qWidget (); + + if (parentWidget) + return new ToggleTool (interp, go, + new QAction (parentWidget)); + } - if (parentWidget) - return new ToggleTool (oct_qobj, interp, go, - new QAction (parentWidget)); - } - - return nullptr; -} + return nullptr; + } -ToggleTool::ToggleTool (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_object& go, QAction *action) - : ToolBarButton (oct_qobj, interp, go, action) -{ - uitoggletool::properties& tp = properties (); + ToggleTool::ToggleTool (octave::interpreter& interp, + const graphics_object& go, QAction *action) + : ToolBarButton (interp, go, action) + { + uitoggletool::properties& tp = properties (); - action->setCheckable (true); - action->setChecked (tp.is_state ()); + action->setCheckable (true); + action->setChecked (tp.is_state ()); + + connect (action, &QAction::toggled, this, &ToggleTool::triggered); + } - connect (action, &QAction::toggled, this, &ToggleTool::triggered); -} - -ToggleTool::~ToggleTool (void) -{ } + ToggleTool::~ToggleTool () + { } -void -ToggleTool::update (int pId) -{ - uitoggletool::properties& tp = properties (); - QAction *action = qWidget (); + void + ToggleTool::update (int pId) + { + uitoggletool::properties& tp = properties (); + QAction *action = qWidget (); - switch (pId) - { - case uitoggletool::properties::ID_STATE: - action->setChecked (tp.is_state ()); - break; + switch (pId) + { + case uitoggletool::properties::ID_STATE: + action->setChecked (tp.is_state ()); + break; - default: - ToolBarButton::update (pId); - break; - } -} + default: + ToolBarButton::update (pId); + break; + } + } -void -ToggleTool::triggered (bool checked) -{ - emit gh_set_event (m_handle, "state", checked, false); - emit gh_callback_event (m_handle, checked ? "oncallback" : "offcallback"); - emit gh_callback_event (m_handle, "clickedcallback"); -} + void + ToggleTool::triggered (bool checked) + { + emit gh_set_event (m_handle, "state", checked, false); + emit gh_callback_event (m_handle, checked ? "oncallback" : "offcallback"); + emit gh_callback_event (m_handle, "clickedcallback"); + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ToggleTool.h --- a/libgui/graphics/ToggleTool.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ToggleTool.h Mon Jan 30 18:36:03 2023 +0100 @@ -30,29 +30,28 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class ToggleTool : public ToolBarButton -{ - Q_OBJECT + class ToggleTool : public ToolBarButton + { + Q_OBJECT -public: - ToggleTool (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, - QAction *action); - ~ToggleTool (void); + public: + ToggleTool (octave::interpreter& interp, + const graphics_object& go, + QAction *action); + ~ToggleTool (); - static ToggleTool * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static ToggleTool * + create (octave::interpreter& interp, + const graphics_object& go); -protected: - void update (int pId); + protected: + void update (int pId); -private slots: - void triggered (bool checked); -}; + private slots: + void triggered (bool checked); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ToolBar.cc --- a/libgui/graphics/ToolBar.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ToolBar.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,148 +42,147 @@ #include "QtHandlesUtils.h" #include "gui-preferences-global.h" -#include "octave-qobject.h" OCTAVE_BEGIN_NAMESPACE(octave) -static QIcon makeEmptyIcon (void) -{ - QPixmap pix (16, 16); + static QIcon makeEmptyIcon () + { + QPixmap pix (16, 16); - pix.fill (Qt::transparent); + pix.fill (Qt::transparent); - return QIcon (pix); -} + return QIcon (pix); + } -static QAction * -addEmptyAction (QToolBar *bar) -{ - static const QIcon empty_icon = makeEmptyIcon (); + static QAction * + addEmptyAction (QToolBar *bar) + { + static const QIcon empty_icon = makeEmptyIcon (); - QAction *a = bar->addAction (empty_icon, "Empty Toolbar"); + QAction *a = bar->addAction (empty_icon, "Empty Toolbar"); - a->setEnabled (false); - a->setToolTip (""); + a->setEnabled (false); + a->setToolTip (""); - return a; -} + return a; + } -ToolBar * -ToolBar::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go) -{ - Object *parent = parentObject (interp, go); + ToolBar * + ToolBar::create (octave::interpreter& interp, + const graphics_object& go) + { + Object *parent = parentObject (interp, go); - if (parent) - { - QWidget *parentWidget = parent->qWidget (); + if (parent) + { + QWidget *parentWidget = parent->qWidget (); - if (parentWidget) - return new ToolBar (oct_qobj, interp, go, - new QToolBar (parentWidget)); - } + if (parentWidget) + return new ToolBar (interp, go, + new QToolBar (parentWidget)); + } - return nullptr; -} + return nullptr; + } -ToolBar::ToolBar (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QToolBar *bar) - : Object (oct_qobj, interp, go, bar), m_empty (nullptr), m_figure (nullptr) -{ - uitoolbar::properties& tp = properties (); + ToolBar::ToolBar (octave::interpreter& interp, + const graphics_object& go, QToolBar *bar) + : Object (interp, go, bar), m_empty (nullptr), m_figure (nullptr) + { + uitoolbar::properties& tp = properties (); - bar->setFloatable (false); - bar->setMovable (false); - bar->setVisible (tp.is_visible ()); - bar->setStyleSheet (bar->styleSheet () + global_toolbar_style); + bar->setFloatable (false); + bar->setMovable (false); + bar->setVisible (tp.is_visible ()); + bar->setStyleSheet (bar->styleSheet () + global_toolbar_style); - m_empty = addEmptyAction (bar); + m_empty = addEmptyAction (bar); - m_figure = - dynamic_cast
(Object::fromQObject (bar->parentWidget ())); + m_figure = + dynamic_cast
(Object::fromQObject (bar->parentWidget ())); - if (m_figure) - m_figure->addCustomToolBar (bar, tp.is_visible (), - tp.get_tag () == "__default_toolbar__"); + if (m_figure) + m_figure->addCustomToolBar (bar, tp.is_visible (), + tp.get_tag () == "__default_toolbar__"); - bar->installEventFilter (this); -} + bar->installEventFilter (this); + } -ToolBar::~ToolBar (void) -{ } + ToolBar::~ToolBar () + { } -void -ToolBar::update (int pId) -{ - uitoolbar::properties& tp = properties (); - QToolBar *bar = qWidget (); + void + ToolBar::update (int pId) + { + uitoolbar::properties& tp = properties (); + QToolBar *bar = qWidget (); - switch (pId) - { - case base_properties::ID_VISIBLE: - if (m_figure) - m_figure->showCustomToolBar (bar, tp.is_visible ()); - break; + switch (pId) + { + case base_properties::ID_VISIBLE: + if (m_figure) + m_figure->showCustomToolBar (bar, tp.is_visible ()); + break; - default: - Object::update (pId); - break; - } -} + default: + Object::update (pId); + break; + } + } -bool -ToolBar::eventFilter (QObject *watched, QEvent *xevent) -{ - if (watched == qObject ()) - { - switch (xevent->type ()) - { - case QEvent::ActionAdded: - case QEvent::ActionRemoved: + bool + ToolBar::eventFilter (QObject *watched, QEvent *xevent) + { + if (watched == qObject ()) + { + switch (xevent->type ()) { - QActionEvent *ae = dynamic_cast (xevent); - QToolBar *bar = qWidget (); + case QEvent::ActionAdded: + case QEvent::ActionRemoved: + { + QActionEvent *ae = dynamic_cast (xevent); + QToolBar *bar = qWidget (); - if (ae->action () != m_empty) - { - if (xevent->type () == QEvent::ActionAdded) - { - if (bar->actions ().size () == 2) - QTimer::singleShot (0, this, &ToolBar::hideEmpty); - } - else - { - if (bar->actions ().size () == 1) - m_empty->setVisible (true); - } - } + if (ae->action () != m_empty) + { + if (xevent->type () == QEvent::ActionAdded) + { + if (bar->actions ().size () == 2) + QTimer::singleShot (0, this, &ToolBar::hideEmpty); + } + else + { + if (bar->actions ().size () == 1) + m_empty->setVisible (true); + } + } + } + break; + + default: + break; } - break; - - default: - break; - } - } + } - return false; -} + return false; + } -void -ToolBar::hideEmpty (void) -{ - m_empty->setVisible (false); -} + void + ToolBar::hideEmpty () + { + m_empty->setVisible (false); + } -void -ToolBar::beingDeleted (void) -{ - if (m_figure) - { - QToolBar *bar = qWidget (); + void + ToolBar::beingDeleted () + { + if (m_figure) + { + QToolBar *bar = qWidget (); - if (bar) - m_figure->showCustomToolBar (bar, false); - } -} + if (bar) + m_figure->showCustomToolBar (bar, false); + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ToolBar.h --- a/libgui/graphics/ToolBar.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ToolBar.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,39 +33,38 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class Figure; + class Figure; -class ToolBar : public Object -{ - Q_OBJECT + class ToolBar : public Object + { + Q_OBJECT -public: - ToolBar (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QToolBar *bar); - ~ToolBar (void); + public: + ToolBar (octave::interpreter& interp, + const graphics_object& go, QToolBar *bar); + ~ToolBar (); - static ToolBar * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go); + static ToolBar * + create (octave::interpreter& interp, + const graphics_object& go); - Container * innerContainer (void) { return nullptr; } + Container * innerContainer () { return nullptr; } - bool eventFilter (QObject *watched, QEvent *event); + bool eventFilter (QObject *watched, QEvent *event); -protected: - void update (int pId); - void beingDeleted (void); + protected: + void update (int pId); + void beingDeleted (); -private slots: - void hideEmpty (void); + private slots: + void hideEmpty (); -private: - QAction *m_empty; - Figure *m_figure; -}; + private: + QAction *m_empty; + Figure *m_figure; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ToolBarButton.cc --- a/libgui/graphics/ToolBarButton.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ToolBarButton.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,130 +34,128 @@ #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, - const graphics_object& go, QAction *action) -: Object (oct_qobj, interp, go, action), m_separator (nullptr) -{ - typename T::properties& tp = properties (); + template + ToolBarButton::ToolBarButton (octave::interpreter& interp, + const graphics_object& go, QAction *action) + : Object (interp, go, action), m_separator (nullptr) + { + typename T::properties& tp = properties (); + + action->setToolTip (Utils::fromStdString (tp.get_tooltipstring ())); + action->setVisible (tp.is_visible ()); - action->setToolTip (Utils::fromStdString (tp.get_tooltipstring ())); - action->setVisible (tp.is_visible ()); + // Get the icon data from cdata or as a named icon + QImage img = Utils::makeImageFromCData (tp.get_cdata (), 24, 24); - // Get the icon data from cdata or as a named icon - QImage img = Utils::makeImageFromCData (tp.get_cdata (), 24, 24); + if (img.width () == 0) + { + QIcon ico; + std::string name = tp.get___named_icon__ (); + if (! name.empty ()) + ico = get_icon (name); - if (img.width () == 0) - { - QIcon ico; - std::string name = tp.get___named_icon__ (); - if (! name.empty ()) - ico = get_icon (name); + action->setIcon (ico); + } + else + action->setIcon (QIcon (QPixmap::fromImage (img))); - action->setIcon (ico); - } - else - action->setIcon (QIcon (QPixmap::fromImage (img))); + if (tp.is_separator ()) + { + m_separator = new QAction (action); + m_separator->setSeparator (true); + m_separator->setVisible (tp.is_visible ()); + } + action->setEnabled (tp.is_enable ()); - if (tp.is_separator ()) - { - m_separator = new QAction (action); - m_separator->setSeparator (true); - m_separator->setVisible (tp.is_visible ()); - } - action->setEnabled (tp.is_enable ()); + QWidget *w = qobject_cast (action->parent ()); - QWidget *w = qobject_cast (action->parent ()); + w->insertAction (w->actions ().back (), action); + if (m_separator) + w->insertAction (action, m_separator); + } + + template + ToolBarButton::~ToolBarButton () + { } - w->insertAction (w->actions ().back (), action); - if (m_separator) - w->insertAction (action, m_separator); -} + template + void + ToolBarButton::update (int pId) + { + typename T::properties& tp = properties (); + QAction *action = qWidget (); -template -ToolBarButton::~ToolBarButton (void) -{ } + switch (pId) + { + case base_properties::ID_VISIBLE: + action->setVisible (tp.is_visible ()); + if (m_separator) + m_separator->setVisible (tp.is_visible ()); + break; -template -void -ToolBarButton::update (int pId) -{ - typename T::properties& tp = properties (); - QAction *action = qWidget (); + case T::properties::ID_TOOLTIPSTRING: + action->setToolTip (Utils::fromStdString (tp.get_tooltipstring ())); + break; + + case T::properties::ID_CDATA: + { + // Get the icon data from cdata or as a named icon + QImage img = Utils::makeImageFromCData (tp.get_cdata (), 24, 24); - switch (pId) - { - case base_properties::ID_VISIBLE: - action->setVisible (tp.is_visible ()); - if (m_separator) - m_separator->setVisible (tp.is_visible ()); - break; + if (img.width () == 0) + { + QIcon ico; + std::string name = tp.get___named_icon__ (); + if (! name.empty ()) + ico = get_icon (name); - case T::properties::ID_TOOLTIPSTRING: - action->setToolTip (Utils::fromStdString (tp.get_tooltipstring ())); - break; + action->setIcon (ico); + } + else + action->setIcon (QIcon (QPixmap::fromImage (img))); + } + break; - case T::properties::ID_CDATA: - { - // Get the icon data from cdata or as a named icon - QImage img = Utils::makeImageFromCData (tp.get_cdata (), 24, 24); - - if (img.width () == 0) + case T::properties::ID_SEPARATOR: + if (tp.is_separator ()) { - QIcon ico; - std::string name = tp.get___named_icon__ (); - if (! name.empty ()) - ico = get_icon (name); + if (! m_separator) + { + m_separator = new QAction (action); + m_separator->setSeparator (true); + m_separator->setVisible (tp.is_visible ()); - action->setIcon (ico); + QWidget *w = qobject_cast (action->parent ()); + + w->insertAction (action, m_separator); + } } else - action->setIcon (QIcon (QPixmap::fromImage (img))); - } - break; + { + if (m_separator) + delete m_separator; + m_separator = nullptr; + } + break; - case T::properties::ID_SEPARATOR: - if (tp.is_separator ()) - { - if (! m_separator) - { - m_separator = new QAction (action); - m_separator->setSeparator (true); - m_separator->setVisible (tp.is_visible ()); - - QWidget *w = qobject_cast (action->parent ()); + case T::properties::ID_ENABLE: + action->setEnabled (tp.is_enable ()); + break; - w->insertAction (action, m_separator); - } - } - else - { - if (m_separator) - delete m_separator; - m_separator = nullptr; - } - break; + default: + Object::update (pId); + break; + } + } - case T::properties::ID_ENABLE: - action->setEnabled (tp.is_enable ()); - break; - - default: - Object::update (pId); - break; - } -} - -template -QIcon ToolBarButton::get_icon (const std::string& name) -{ - return QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) + QString::fromStdString (name) + ".png"); -} + template + QIcon ToolBarButton::get_icon (const std::string& name) + { + return QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) + QString::fromStdString (name) + ".png"); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/ToolBarButton.h --- a/libgui/graphics/ToolBarButton.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/ToolBarButton.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,29 +33,28 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class interpreter; + class interpreter; -class Container; + class Container; -template -class ToolBarButton : public Object -{ -public: - ToolBarButton (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_object& go, QAction *action); - ~ToolBarButton (void); + template + class ToolBarButton : public Object + { + public: + ToolBarButton (octave::interpreter& interp, + const graphics_object& go, QAction *action); + ~ToolBarButton (); - Container * innerContainer (void) { return nullptr; } + Container * innerContainer () { return nullptr; } -protected: - void update (int pId); + protected: + void update (int pId); -private: - QAction *m_separator; + private: + QAction *m_separator; - QIcon get_icon (const std::string& name); -}; + QIcon get_icon (const std::string& name); + }; OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/annotation-dialog.cc --- a/libgui/graphics/annotation-dialog.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/annotation-dialog.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,17 +33,14 @@ #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), ui (new Ui::annotation_dialog) { props = pr; @@ -55,13 +52,11 @@ { 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, @@ -101,13 +96,10 @@ QDialogButtonBox::ButtonRole button_role = 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) @@ -164,7 +156,7 @@ 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 (). + props.append (ovl ("color", octave::Utils::toRgb (ui->btn_color->palette (). color (QPalette::Button)))); // FIXME: only "none" linestyle is selectable, change the code bellow @@ -249,7 +241,7 @@ { QColor color; if (props(1*i +1).is_matrix_type ()) - color = Utils::fromRgb (props(2*i +1).matrix_value ()); + color = octave::Utils::fromRgb (props(2*i +1).matrix_value ()); else color.setNamedColor (props(2*i +1).string_value ().c_str ()); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/annotation-dialog.h --- a/libgui/graphics/annotation-dialog.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/annotation-dialog.h Mon Jan 30 18:36:03 2023 +0100 @@ -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,7 +58,6 @@ void get_gui_props (); void set_gui_props (); - octave::base_qobject& m_octave_qobj; Ui::annotation_dialog *ui; octave_value_list props; }; diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/gl-select.cc --- a/libgui/graphics/gl-select.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/gl-select.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) void -opengl_selector::apply_pick_matrix (void) +opengl_selector::apply_pick_matrix () { GLdouble p_matrix[16]; diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/gl-select.h --- a/libgui/graphics/gl-select.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/gl-select.h Mon Jan 30 18:36:03 2023 +0100 @@ -47,7 +47,7 @@ : opengl_renderer (glfcns), 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); @@ -68,7 +68,7 @@ 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); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/module.mk --- a/libgui/graphics/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/qopengl-functions.h --- a/libgui/graphics/qopengl-functions.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/qopengl-functions.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/graphics/qt-graphics-toolkit.cc --- a/libgui/graphics/qt-graphics-toolkit.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/qt-graphics-toolkit.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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" @@ -75,439 +73,437 @@ OCTAVE_BEGIN_NAMESPACE(octave) -static std::string -toolkitObjectProperty (const graphics_object& go) -{ - if (go.isa ("figure")) - return "__plot_stream__"; - else if (go.isa ("uicontrol") - || go.isa ("uipanel") - || go.isa ("uibuttongroup") - || go.isa ("uimenu") - || go.isa ("uicontextmenu") - || go.isa ("uitable") - || go.isa ("uitoolbar") - || go.isa ("uipushtool") - || go.isa ("uitoggletool")) - return "__object__"; - else - qCritical ("octave::qt_graphics_toolkit: no __object__ property known for object " - "of type %s", go.type ().c_str ()); + static std::string + toolkitObjectProperty (const graphics_object& go) + { + if (go.isa ("figure")) + return "__plot_stream__"; + else if (go.isa ("uicontrol") + || go.isa ("uipanel") + || go.isa ("uibuttongroup") + || go.isa ("uimenu") + || go.isa ("uicontextmenu") + || go.isa ("uitable") + || go.isa ("uitoolbar") + || go.isa ("uipushtool") + || go.isa ("uitoggletool")) + return "__object__"; + else + qCritical ("octave::qt_graphics_toolkit: no __object__ property known for object " + "of type %s", go.type ().c_str ()); - return ""; -} + 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) -{ - // Implemented with a signal/slot connection in order to properly - // cross from the interpreter thread (where requests to create - // graphics object are initiated) to the GUI application thread - // (where they are actually created and displayed). - // We need to make sure the GUI Object and its proxy are properly - // created before the initialize method returns, so we use a - // BlockingQueuedConnection. After the signal is emitted, the interpreter - // thread is locked until the slot has returned. + 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 + // graphics object are initiated) to the GUI application thread + // (where they are actually created and displayed). + // We need to make sure the GUI Object and its proxy are properly + // created before the initialize method returns, so we use a + // BlockingQueuedConnection. After the signal is emitted, the interpreter + // thread is locked until the slot has returned. - connect (this, &qt_graphics_toolkit::create_object_signal, - this, &qt_graphics_toolkit::create_object, - Qt::BlockingQueuedConnection); -} + connect (this, &qt_graphics_toolkit::create_object_signal, + this, &qt_graphics_toolkit::create_object, + Qt::BlockingQueuedConnection); + } -bool -qt_graphics_toolkit::initialize (const graphics_object& go) -{ - if (go.isa ("figure") - || (go.isa ("uicontrol") && go.get ("style").string_value () != "frame") - || go.isa ("uipanel") - || go.isa ("uibuttongroup") - || go.isa ("uimenu") - || go.isa ("uicontextmenu") - || go.isa ("uitable") - || go.isa ("uitoolbar") - || go.isa ("uipushtool") - || go.isa ("uitoggletool")) - { - // FIXME: We need to unlock the mutex here but we have no way to know - // if it was previously locked by this thread, and thus if we should - // re-lock it. + bool + qt_graphics_toolkit::initialize (const graphics_object& go) + { + if (go.isa ("figure") + || (go.isa ("uicontrol") && go.get ("style").string_value () != "frame") + || go.isa ("uipanel") + || go.isa ("uibuttongroup") + || go.isa ("uimenu") + || go.isa ("uicontextmenu") + || go.isa ("uitable") + || go.isa ("uitoolbar") + || go.isa ("uipushtool") + || go.isa ("uitoggletool")) + { + // FIXME: We need to unlock the mutex here but we have no way to know + // if it was previously locked by this thread, and thus if we should + // re-lock it. - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - gh_mgr.unlock (); + gh_mgr.unlock (); - Logger::debug ("qt_graphics_toolkit::initialize %s from thread %p", - go.type ().c_str (), QThread::currentThreadId ()); + Logger::debug ("qt_graphics_toolkit::initialize %s from thread %p", + go.type ().c_str (), QThread::currentThreadId ()); - ObjectProxy *proxy = new ObjectProxy (); - graphics_object gObj (go); + ObjectProxy *proxy = new ObjectProxy (); + graphics_object gObj (go); - OCTAVE_PTR_TYPE tmp (reinterpret_cast (proxy)); - gObj.get_properties ().set (toolkitObjectProperty (go), tmp); + OCTAVE_PTR_TYPE tmp (reinterpret_cast (proxy)); + gObj.get_properties ().set (toolkitObjectProperty (go), tmp); - emit create_object_signal (go.get_handle ().value ()); + emit create_object_signal (go.get_handle ().value ()); - return true; - } + return true; + } - return false; -} + return false; + } -void -qt_graphics_toolkit::update (const graphics_object& go, int pId) -{ - // Rule out obvious properties we want to ignore. - if (pId == figure::properties::ID___PLOT_STREAM__ - || pId == uicontrol::properties::ID___OBJECT__ - || pId == uipanel::properties::ID___OBJECT__ - || pId == uibuttongroup::properties::ID___OBJECT__ - || pId == uimenu::properties::ID___OBJECT__ - || pId == uicontextmenu::properties::ID___OBJECT__ - || pId == uitable::properties::ID___OBJECT__ - || pId == uitoolbar::properties::ID___OBJECT__ - || pId == uipushtool::properties::ID___OBJECT__ - || pId == uitoggletool::properties::ID___OBJECT__ - || pId == base_properties::ID___MODIFIED__) - return; + void + qt_graphics_toolkit::update (const graphics_object& go, int pId) + { + // Rule out obvious properties we want to ignore. + if (pId == figure::properties::ID___PLOT_STREAM__ + || pId == uicontrol::properties::ID___OBJECT__ + || pId == uipanel::properties::ID___OBJECT__ + || pId == uibuttongroup::properties::ID___OBJECT__ + || pId == uimenu::properties::ID___OBJECT__ + || pId == uicontextmenu::properties::ID___OBJECT__ + || pId == uitable::properties::ID___OBJECT__ + || pId == uitoolbar::properties::ID___OBJECT__ + || pId == uipushtool::properties::ID___OBJECT__ + || pId == uitoggletool::properties::ID___OBJECT__ + || pId == base_properties::ID___MODIFIED__) + return; - Logger::debug ("qt_graphics_toolkit::update %s(%d) from thread %p", - go.type ().c_str (), pId, QThread::currentThreadId ()); + Logger::debug ("qt_graphics_toolkit::update %s(%d) from thread %p", + go.type ().c_str (), pId, QThread::currentThreadId ()); - ObjectProxy *proxy = toolkitObjectProxy (go); + ObjectProxy *proxy = toolkitObjectProxy (go); - if (proxy) - { - if ((go.isa ("uicontrol") - && pId == uicontrol::properties::ID_STYLE) - || (go.isa ("uitable") - && pId == uitable::properties::ID_DATA)) - { - // Special case: we need to recreate the control widget - // associated with the octave graphics_object - // FIXME: For uitable, it would only be necessary to recreate - // the table widget if the type of the displayed values changes - // between Boolean and non-Boolean (bug #63388). + if (proxy) + { + if ((go.isa ("uicontrol") + && pId == uicontrol::properties::ID_STYLE) + || (go.isa ("uitable") + && pId == uitable::properties::ID_DATA)) + { + // Special case: we need to recreate the control widget + // associated with the octave graphics_object + // FIXME: For uitable, it would only be necessary to recreate + // the table widget if the type of the displayed values changes + // between Boolean and non-Boolean (bug #63388). - finalize (go); - initialize (go); - } - else - proxy->update (pId); - } -} + finalize (go); + initialize (go); + } + else + proxy->update (pId); + } + } -void -qt_graphics_toolkit::finalize (const graphics_object& go) -{ - // FIXME: We need to unlock the mutex here but we have no way to know if - // if it was previously locked by this thread, and thus if we should - // re-lock it. + void + qt_graphics_toolkit::finalize (const graphics_object& go) + { + // FIXME: We need to unlock the mutex here but we have no way to know if + // if it was previously locked by this thread, and thus if we should + // re-lock it. - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - gh_mgr.unlock (); + gh_mgr.unlock (); - Logger::debug ("qt_graphics_toolkit::finalize %s from thread %p", - go.type ().c_str (), QThread::currentThreadId ()); + Logger::debug ("qt_graphics_toolkit::finalize %s from thread %p", + go.type ().c_str (), QThread::currentThreadId ()); - ObjectProxy *proxy = toolkitObjectProxy (go); + ObjectProxy *proxy = toolkitObjectProxy (go); - if (proxy) - { - proxy->finalize (); - delete proxy; + if (proxy) + { + proxy->finalize (); + delete proxy; - graphics_object gObj (go); + graphics_object gObj (go); - gObj.get_properties ().set (toolkitObjectProperty (go), Matrix ()); - } -} + gObj.get_properties ().set (toolkitObjectProperty (go), Matrix ()); + } + } -void -qt_graphics_toolkit::redraw_figure (const graphics_object& go) const -{ - if (go.get_properties ().is_visible ()) - { - ObjectProxy *proxy = toolkitObjectProxy (go); + void + qt_graphics_toolkit::redraw_figure (const graphics_object& go) const + { + if (go.get_properties ().is_visible ()) + { + ObjectProxy *proxy = toolkitObjectProxy (go); - if (proxy) - proxy->redraw (); - } -} + if (proxy) + proxy->redraw (); + } + } -void -qt_graphics_toolkit::show_figure (const graphics_object& go) const -{ - if (go.get_properties ().is_visible ()) - { - ObjectProxy *proxy = toolkitObjectProxy (go); + void + qt_graphics_toolkit::show_figure (const graphics_object& go) const + { + if (go.get_properties ().is_visible ()) + { + ObjectProxy *proxy = toolkitObjectProxy (go); - if (proxy) - proxy->show (); - } -} + if (proxy) + proxy->show (); + } + } -void -qt_graphics_toolkit::print_figure (const graphics_object& go, - const std::string& term, - const std::string& file_cmd, - const std::string& /*debug_file*/) const -{ - ObjectProxy *proxy = toolkitObjectProxy (go); + void + qt_graphics_toolkit::print_figure (const graphics_object& go, + const std::string& term, + const std::string& file_cmd, + const std::string& /*debug_file*/) const + { + ObjectProxy *proxy = toolkitObjectProxy (go); - if (proxy) - proxy->print (QString::fromStdString (file_cmd), - QString::fromStdString (term)); -} + if (proxy) + proxy->print (QString::fromStdString (file_cmd), + QString::fromStdString (term)); + } -uint8NDArray -qt_graphics_toolkit::get_pixels (const graphics_object& go) const -{ - uint8NDArray retval; + uint8NDArray + qt_graphics_toolkit::get_pixels (const graphics_object& go) const + { + uint8NDArray retval; - if (go.isa ("figure")) - { - ObjectProxy *proxy = toolkitObjectProxy (go); + if (go.isa ("figure")) + { + ObjectProxy *proxy = toolkitObjectProxy (go); - if (proxy) - retval = proxy->get_pixels (); - } + if (proxy) + retval = proxy->get_pixels (); + } - return retval; -} + return retval; + } -Matrix -qt_graphics_toolkit::get_text_extent (const graphics_object& go) const -{ - Matrix ext (1, 4, 0.0); + Matrix + qt_graphics_toolkit::get_text_extent (const graphics_object& go) const + { + Matrix ext (1, 4, 0.0); - if (go.isa ("uicontrol")) - { - octave_value str = go.get ("string"); - if (! str.isempty ()) - { - const uicontrol::properties& up = - dynamic_cast (go.get_properties ()); - Matrix bb = up.get_boundingbox (false); - QFont font = Utils::computeFont (up, bb(3)); - QFontMetrics fm (font); + if (go.isa ("uicontrol")) + { + octave_value str = go.get ("string"); + if (! str.isempty ()) + { + const uicontrol::properties& up = + dynamic_cast (go.get_properties ()); + Matrix bb = up.get_boundingbox (false); + QFont font = Utils::computeFont (up, bb(3)); + QFontMetrics fm (font); - QString s; - QSize sz; + QString s; + QSize sz; - if (str.is_string ()) - { - s = QString::fromStdString (str.string_value ()); - sz = fm.size (Qt::TextSingleLine, s); - ext(2) = sz.width (); - ext(3) = sz.height (); - } - else if (str.iscellstr ()) - { - string_vector sv = str.string_vector_value (); - double wd = 0.0; - double hg = 0.0; - for (octave_idx_type ii = 0; ii < sv.numel (); ii++) - { - s = QString::fromStdString (sv(ii)); - sz = fm.size (Qt::TextSingleLine, s); - wd = std::max (wd, static_cast (sz.width ())); - hg = std::max (hg, static_cast (sz.height ())); - } + if (str.is_string ()) + { + s = QString::fromStdString (str.string_value ()); + sz = fm.size (Qt::TextSingleLine, s); + ext(2) = sz.width (); + ext(3) = sz.height (); + } + else if (str.iscellstr ()) + { + string_vector sv = str.string_vector_value (); + double wd = 0.0; + double hg = 0.0; + for (octave_idx_type ii = 0; ii < sv.numel (); ii++) + { + s = QString::fromStdString (sv(ii)); + sz = fm.size (Qt::TextSingleLine, s); + wd = std::max (wd, static_cast (sz.width ())); + hg = std::max (hg, static_cast (sz.height ())); + } - ext(2) = wd; - // FIXME: Find a better way to determine the height of e.g. - // listbox uicontrol objects - ext(3) = hg * sv.numel (); - } - } - } + ext(2) = wd; + // FIXME: Find a better way to determine the height of e.g. + // listbox uicontrol objects + ext(3) = hg * sv.numel (); + } + } + } - return ext; -} + return ext; + } -Object * -qt_graphics_toolkit::toolkitObject (const graphics_object& go) -{ - ObjectProxy *proxy = toolkitObjectProxy (go); + Object * + qt_graphics_toolkit::toolkitObject (const graphics_object& go) + { + ObjectProxy *proxy = toolkitObjectProxy (go); - if (proxy) - return proxy->object (); + if (proxy) + return proxy->object (); - return nullptr; -} + return nullptr; + } -ObjectProxy * -qt_graphics_toolkit::toolkitObjectProxy (const graphics_object& go) -{ - if (go) - { - octave_value ov = go.get (toolkitObjectProperty (go)); + ObjectProxy * + qt_graphics_toolkit::toolkitObjectProxy (const graphics_object& go) + { + if (go) + { + octave_value ov = go.get (toolkitObjectProperty (go)); - if (ov.is_defined () && ! ov.isempty ()) - { - OCTAVE_INTPTR_TYPE ptr = ov.OCTAVE_PTR_SCALAR ().value (); + if (ov.is_defined () && ! ov.isempty ()) + { + OCTAVE_INTPTR_TYPE ptr = ov.OCTAVE_PTR_SCALAR ().value (); - return reinterpret_cast (ptr); - } - } + return reinterpret_cast (ptr); + } + } - return nullptr; -} + return nullptr; + } -void -qt_graphics_toolkit::interpreter_event (const octave::fcn_callback& fcn) -{ - octave::event_manager& evmgr = m_interpreter.get_event_manager (); + void + qt_graphics_toolkit::interpreter_event (const octave::fcn_callback& fcn) + { + octave::event_manager& evmgr = m_interpreter.get_event_manager (); - evmgr.post_event (fcn); -} + evmgr.post_event (fcn); + } -void -qt_graphics_toolkit::interpreter_event (const octave::meth_callback& meth) -{ - octave::event_manager& evmgr = m_interpreter.get_event_manager (); + void + qt_graphics_toolkit::interpreter_event (const octave::meth_callback& meth) + { + octave::event_manager& evmgr = m_interpreter.get_event_manager (); - evmgr.post_event (meth); -} + evmgr.post_event (meth); + } -void -qt_graphics_toolkit::create_object (double handle) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void + qt_graphics_toolkit::create_object (double handle) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - octave::autolock guard (gh_mgr.graphics_lock ()); + octave::autolock guard (gh_mgr.graphics_lock ()); - graphics_object go (gh_mgr.get_object (graphics_handle (handle))); + graphics_object go (gh_mgr.get_object (graphics_handle (handle))); - if (! go.valid_object ()) - { - qWarning ("qt_graphics_toolkit::create_object: invalid object for handle %g", - handle); - return; - } + if (! go.valid_object ()) + { + qWarning ("qt_graphics_toolkit::create_object: invalid object for handle %g", + handle); + return; + } - if (go.get_properties ().is_beingdeleted ()) - { - qWarning ("qt_graphics_toolkit::create_object: object is being deleted"); - return; - } + if (go.get_properties ().is_beingdeleted ()) + { + qWarning ("qt_graphics_toolkit::create_object: object is being deleted"); + return; + } - ObjectProxy *proxy = qt_graphics_toolkit::toolkitObjectProxy (go); + ObjectProxy *proxy = qt_graphics_toolkit::toolkitObjectProxy (go); - if (! proxy) - { - qWarning ("qt_graphics_toolkit::create_object: no proxy for handle %g", - handle); - return; - } + if (! proxy) + { + qWarning ("qt_graphics_toolkit::create_object: no proxy for handle %g", + handle); + return; + } - Logger::debug ("qt_graphics_toolkit::create_object: " - "create %s from thread %p", - go.type ().c_str (), QThread::currentThreadId ()); + Logger::debug ("qt_graphics_toolkit::create_object: " + "create %s from thread %p", + go.type ().c_str (), QThread::currentThreadId ()); - Object *obj = nullptr; + Object *obj = nullptr; - if (go.isa ("figure")) - obj = Figure::create (m_octave_qobj, m_interpreter, go); - else if (go.isa ("uicontrol")) - { - uicontrol::properties& up = - Utils::properties (go); + if (go.isa ("figure")) + 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); - else if (up.style_is ("edit")) - obj = EditControl::create (m_octave_qobj, m_interpreter, go); - else if (up.style_is ("checkbox")) - obj = CheckBoxControl::create (m_octave_qobj, m_interpreter, go); - else if (up.style_is ("radiobutton")) - obj = RadioButtonControl::create (m_octave_qobj, m_interpreter, go); - else if (up.style_is ("togglebutton")) - obj = ToggleButtonControl::create (m_octave_qobj, m_interpreter, go); - else if (up.style_is ("text")) - obj = TextControl::create (m_octave_qobj, m_interpreter, go); - else if (up.style_is ("popupmenu")) - obj = PopupMenuControl::create (m_octave_qobj, m_interpreter, go); - else if (up.style_is ("slider")) - obj = SliderControl::create (m_octave_qobj, m_interpreter, go); - else if (up.style_is ("listbox")) - obj = ListBoxControl::create (m_octave_qobj, m_interpreter, go); - } - else if (go.isa ("uibuttongroup")) - obj = ButtonGroup::create (m_octave_qobj, m_interpreter, go); - else if (go.isa ("uipanel")) - obj = Panel::create (m_octave_qobj, m_interpreter, go); - else if (go.isa ("uimenu")) - obj = Menu::create (m_octave_qobj, m_interpreter, go); - else if (go.isa ("uicontextmenu")) - obj = ContextMenu::create (m_octave_qobj, m_interpreter, go); - else if (go.isa ("uitable")) - obj = Table::create (m_octave_qobj, m_interpreter, go); - else if (go.isa ("uitoolbar")) - obj = ToolBar::create (m_octave_qobj, m_interpreter, go); - else if (go.isa ("uipushtool")) - obj = PushTool::create (m_octave_qobj, m_interpreter, go); - else if (go.isa ("uitoggletool")) - obj = ToggleTool::create (m_octave_qobj, m_interpreter, go); - else - qWarning ("qt_graphics_toolkit::create_object: unsupported type '%s'", - go.type ().c_str ()); + if (up.style_is ("pushbutton")) + obj = PushButtonControl::create (m_interpreter, go); + else if (up.style_is ("edit")) + obj = EditControl::create (m_interpreter, go); + else if (up.style_is ("checkbox")) + obj = CheckBoxControl::create (m_interpreter, go); + else if (up.style_is ("radiobutton")) + obj = RadioButtonControl::create (m_interpreter, go); + else if (up.style_is ("togglebutton")) + obj = ToggleButtonControl::create (m_interpreter, go); + else if (up.style_is ("text")) + obj = TextControl::create (m_interpreter, go); + else if (up.style_is ("popupmenu")) + obj = PopupMenuControl::create (m_interpreter, go); + else if (up.style_is ("slider")) + obj = SliderControl::create (m_interpreter, go); + else if (up.style_is ("listbox")) + obj = ListBoxControl::create (m_interpreter, go); + } + else if (go.isa ("uibuttongroup")) + obj = ButtonGroup::create (m_interpreter, go); + else if (go.isa ("uipanel")) + obj = Panel::create (m_interpreter, go); + else if (go.isa ("uimenu")) + obj = Menu::create (m_interpreter, go); + else if (go.isa ("uicontextmenu")) + obj = ContextMenu::create (m_interpreter, go); + else if (go.isa ("uitable")) + obj = Table::create (m_interpreter, go); + else if (go.isa ("uitoolbar")) + obj = ToolBar::create (m_interpreter, go); + else if (go.isa ("uipushtool")) + obj = PushTool::create (m_interpreter, go); + else if (go.isa ("uitoggletool")) + obj = ToggleTool::create (m_interpreter, go); + else + qWarning ("qt_graphics_toolkit::create_object: unsupported type '%s'", + go.type ().c_str ()); - if (obj) - { - proxy->setObject (obj); - obj->do_connections (this); - } -} + if (obj) + { + proxy->setObject (obj); + obj->do_connections (this); + } + } -void qt_graphics_toolkit::gh_callback_event (const graphics_handle& h, - const std::string& nm) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void qt_graphics_toolkit::gh_callback_event (const graphics_handle& h, + const std::string& nm) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - gh_mgr.post_callback (h, nm); -} + gh_mgr.post_callback (h, nm); + } -void qt_graphics_toolkit::gh_callback_event (const graphics_handle& h, - const std::string& nm, - const octave_value& data) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void qt_graphics_toolkit::gh_callback_event (const graphics_handle& h, + const std::string& nm, + const octave_value& data) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - gh_mgr.post_callback (h, nm, data); -} + gh_mgr.post_callback (h, nm, data); + } -void qt_graphics_toolkit::gh_set_event (const graphics_handle& h, - const std::string& nm, - const octave_value& value) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void qt_graphics_toolkit::gh_set_event (const graphics_handle& h, + const std::string& nm, + const octave_value& value) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - gh_mgr.post_set (h, nm, value); -} + gh_mgr.post_set (h, nm, value); + } -void qt_graphics_toolkit::gh_set_event (const graphics_handle& h, - const std::string& nm, - const octave_value& value, - bool notify_toolkit) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void qt_graphics_toolkit::gh_set_event (const graphics_handle& h, + const std::string& nm, + const octave_value& value, + bool notify_toolkit) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - gh_mgr.post_set (h, nm, value, notify_toolkit); -} + gh_mgr.post_set (h, nm, value, notify_toolkit); + } -void qt_graphics_toolkit::gh_set_event (const graphics_handle& h, - const std::string& nm, - const octave_value& value, - bool notify_toolkit, - bool redraw_figure) -{ - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + void qt_graphics_toolkit::gh_set_event (const graphics_handle& h, + const std::string& nm, + const octave_value& value, + bool notify_toolkit, + bool redraw_figure) + { + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - gh_mgr.post_set (h, nm, value, notify_toolkit, redraw_figure); -} + gh_mgr.post_set (h, nm, value, notify_toolkit, redraw_figure); + } OCTAVE_END_NAMESPACE(octave); diff -r 17d568574e1c -r 7860fcc69082 libgui/graphics/qt-graphics-toolkit.h --- a/libgui/graphics/qt-graphics-toolkit.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/graphics/qt-graphics-toolkit.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,95 +33,91 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class interpreter; -class base_qobject; + class interpreter; -class Object; -class ObjectProxy; + class Object; + class ObjectProxy; -class qt_graphics_toolkit - : public QObject, public octave::base_graphics_toolkit -{ - Q_OBJECT + class qt_graphics_toolkit + : public QObject, public octave::base_graphics_toolkit + { + Q_OBJECT -public: + 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 - // separate thread. So in order to correctly cross from the - // interpreter thread to the GUI thread, these functions should emit - // signals (in the interpreter thread) that are handled by slots - // that will run in the GUI thread. This design is similar to the - // event_manager, interpreter_events, and qt_interpreter_events - // classes work to pass messages from the interpreter to the GUI. - // - // FIXME: currently most of these functions do not emit signals. - // They may work because they use locking and the gh_manager class, - // but it might be better to use Qt signals and slots. In any case, - // we should ensure that they are correctly handling the connection - // between the interpreter and GUI threads. + // The interpreter may call graphics toolkit functions that we + // implement here. The Qt GUI that manages these actions runs in a + // separate thread. So in order to correctly cross from the + // interpreter thread to the GUI thread, these functions should emit + // signals (in the interpreter thread) that are handled by slots + // that will run in the GUI thread. This design is similar to the + // event_manager, interpreter_events, and qt_interpreter_events + // classes work to pass messages from the interpreter to the GUI. + // + // FIXME: currently most of these functions do not emit signals. + // They may work because they use locking and the gh_manager class, + // but it might be better to use Qt signals and slots. In any case, + // 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; + void redraw_figure (const graphics_object& h) const; - void show_figure (const graphics_object& h) const; + void show_figure (const graphics_object& h) const; - void update (const graphics_object& obj, int pId); + void update (const graphics_object& obj, int pId); - bool initialize (const graphics_object& obj); + bool initialize (const graphics_object& obj); - void finalize (const graphics_object& obj); + void finalize (const graphics_object& obj); - void print_figure (const graphics_object& go, - const std::string& term, - const std::string& file_cmd, - const std::string& /*debug_file*/) const; + void print_figure (const graphics_object& go, + const std::string& term, + const std::string& file_cmd, + const std::string& /*debug_file*/) const; - uint8NDArray get_pixels (const graphics_object& go) const; + uint8NDArray get_pixels (const graphics_object& go) const; - Matrix get_text_extent (const graphics_object& go) const; - - static Object * toolkitObject (const graphics_object& go); + Matrix get_text_extent (const graphics_object& go) const; - static ObjectProxy * toolkitObjectProxy (const graphics_object& go); + static Object * toolkitObject (const graphics_object& go); -signals: + static ObjectProxy * toolkitObjectProxy (const graphics_object& go); - void create_object_signal (double handle); + signals: -public slots: + void create_object_signal (double handle); - void interpreter_event (const octave::fcn_callback& fcn); - void interpreter_event (const octave::meth_callback& meth); + public slots: - void create_object (double handle); + void interpreter_event (const octave::fcn_callback& fcn); + void interpreter_event (const octave::meth_callback& meth); - void gh_callback_event (const graphics_handle& h, const std::string& name); + void create_object (double handle); - void gh_callback_event (const graphics_handle& h, const std::string& name, - const octave_value& data); + void gh_callback_event (const graphics_handle& h, const std::string& name); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value); + void gh_callback_event (const graphics_handle& h, const std::string& name, + const octave_value& data); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit); + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value); + + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit); - void gh_set_event (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit, - bool redraw_figure); -private: + void gh_set_event (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit, + bool redraw_figure); + private: - octave::interpreter& m_interpreter; - - octave::base_qobject& m_octave_qobj; -}; + octave::interpreter& m_interpreter; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/languages/build_ts/octave-qt/qdialog.cpp --- a/libgui/languages/build_ts/octave-qt/qdialog.cpp Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/languages/build_ts/octave-qt/qdialog.cpp Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/languages/build_ts/octave-qt/qfontdialog.cpp --- a/libgui/languages/build_ts/octave-qt/qfontdialog.cpp Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/languages/build_ts/octave-qt/qfontdialog.cpp Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/languages/build_ts/octave-qt/qprintdialog_win.cpp --- a/libgui/languages/build_ts/octave-qt/qprintdialog_win.cpp Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/languages/build_ts/octave-qt/qprintdialog_win.cpp Mon Jan 30 18:36:03 2023 +0100 @@ -307,7 +307,7 @@ if (!warnIfNotNative(d->printer)) return; - (void)d->openWindowsPrintDialogModally(); + ()d->openWindowsPrintDialogModally(); return; } diff -r 17d568574e1c -r 7860fcc69082 libgui/liboctgui-build-info.h --- a/libgui/liboctgui-build-info.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/liboctgui-build-info.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/liboctgui-build-info.in.cc --- a/libgui/liboctgui-build-info.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/liboctgui-build-info.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,7 @@ #include "liboctgui-build-info.h" std::string -liboctgui_hg_id (void) +liboctgui_hg_id () { return "%OCTAVE_HG_ID%"; } diff -r 17d568574e1c -r 7860fcc69082 libgui/qterminal/libqterminal/QTerminal.cc --- a/libgui/qterminal/libqterminal/QTerminal.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/qterminal/libqterminal/QTerminal.cc Mon Jan 30 18:36:03 2023 +0100 @@ -38,8 +38,10 @@ #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 +51,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; } @@ -194,37 +193,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 +241,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 +289,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 (); diff -r 17d568574e1c -r 7860fcc69082 libgui/qterminal/libqterminal/QTerminal.h --- a/libgui/qterminal/libqterminal/QTerminal.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/qterminal/libqterminal/QTerminal.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp --- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h --- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/qterminal/libqterminal/unix/TerminalView.cpp --- a/libgui/qterminal/libqterminal/unix/TerminalView.cpp Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/qterminal/libqterminal/unix/TerminalView.cpp Mon Jan 30 18:36:03 2023 +0100 @@ -2043,13 +2043,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 +2059,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 17d568574e1c -r 7860fcc69082 libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp --- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h --- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/color-picker.cc --- a/libgui/src/color-picker.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/color-picker.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/color-picker.h --- a/libgui/src/color-picker.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/color-picker.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/command-widget.cc --- a/libgui/src/command-widget.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/command-widget.cc Mon Jan 30 18:36:03 2023 +0100 @@ -44,286 +44,299 @@ #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)) -{ - QPushButton *pause_button = new QPushButton (tr("Pause"), this); - QPushButton *stop_button = new QPushButton (tr("Stop"), this); - QPushButton *resume_button = new QPushButton (tr("Continue"), this); + 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); + QPushButton *resume_button = new QPushButton (tr("Continue"), this); - QGroupBox *input_group_box = new QGroupBox (); - QHBoxLayout *input_layout = new QHBoxLayout; - input_layout->addWidget (pause_button); - input_layout->addWidget (stop_button); - input_layout->addWidget (resume_button); - input_group_box->setLayout (input_layout); + QGroupBox *input_group_box = new QGroupBox (); + QHBoxLayout *input_layout = new QHBoxLayout; + input_layout->addWidget (pause_button); + input_layout->addWidget (stop_button); + input_layout->addWidget (resume_button); + input_group_box->setLayout (input_layout); - QVBoxLayout *main_layout = new QVBoxLayout (); - main_layout->addWidget (m_console); - main_layout->addWidget (input_group_box); + QVBoxLayout *main_layout = new QVBoxLayout (); + main_layout->addWidget (m_console); + main_layout->addWidget (input_group_box); - setLayout (main_layout); + setLayout (main_layout); - setFocusProxy (m_console); + setFocusProxy (m_console); - connect (pause_button, &QPushButton::clicked, - this, &command_widget::interpreter_pause); + connect (pause_button, &QPushButton::clicked, + this, &command_widget::interpreter_pause); - connect (resume_button, &QPushButton::clicked, - this, &command_widget::interpreter_resume); + connect (resume_button, &QPushButton::clicked, + this, &command_widget::interpreter_resume); - connect (stop_button, &QPushButton::clicked, - this, &command_widget::interpreter_stop); + connect (stop_button, &QPushButton::clicked, + this, &command_widget::interpreter_stop); - connect (this, &command_widget::new_command_line_signal, - m_console, &console::new_command_line); + connect (this, &command_widget::update_prompt_signal, + this, &command_widget::update_prompt); - insert_interpreter_output ("\n\n Welcome to Octave\n\n"); - -} + connect (this, &command_widget::new_command_line_signal, + m_console, &console::new_command_line); -void command_widget::init_command_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. + connect (m_console, QOverload::of (&console::interpreter_event), + this, QOverload::of (&command_widget::interpreter_event)); - QPointer this_cw (this); + 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"); + + } - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD + void command_widget::init_command_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. - // We can skip the entire callback function because it does not - // make any changes to the interpreter state. + QPointer this_cw (this); - if (this_cw.isNull ()) - return; + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD - 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)); + // We can skip the entire callback function because it does not + // make any changes to the interpreter state. - emit new_command_line_signal (); - }); -} + if (this_cw.isNull ()) + return; -void command_widget::update_prompt (const QString& prompt) -{ - m_prompt = prompt; -} + std::string prompt = interp.PS1 (); + std::string decoded_prompt + = command_editor::decode_prompt_string (prompt); + + emit update_prompt_signal (QString::fromStdString (decoded_prompt)); -QString command_widget::prompt () -{ - return m_prompt; -} + emit new_command_line_signal (); + }); + } -void command_widget::insert_interpreter_output (const QString& msg) -{ - m_console->append (msg); -} + void command_widget::update_prompt (const QString& prompt) + { + m_prompt = prompt; + } -void command_widget::process_input_line (const QString& input_line) -{ - // 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_cw (this); + QString command_widget::prompt () + { + return m_prompt; + } - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD + void command_widget::insert_interpreter_output (const QString& msg) + { + m_console->append (msg); + } - // 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. + void command_widget::process_input_line (const QString& input_line) + { + // 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_cw (this); - interp.parse_and_execute (input_line.toStdString (), - m_incomplete_parse); + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD - if (this_cw.isNull ()) - return; + // 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. - event_manager& evmgr = interp.get_event_manager (); - input_system& input_sys = interp.get_input_system (); + interp.parse_and_execute (input_line.toStdString (), + m_incomplete_parse); - std::string prompt - = m_incomplete_parse ? input_sys.PS2 () : input_sys.PS1 (); + if (this_cw.isNull ()) + return; - evmgr.update_prompt (command_editor::decode_prompt_string (prompt)); - - emit new_command_line_signal (); - }); + std::string prompt + = m_incomplete_parse ? interp.PS2 () : interp.PS1 (); -} + std::string decoded_prompt + = command_editor::decode_prompt_string (prompt); + + emit update_prompt_signal (QString::fromStdString (decoded_prompt)); + + emit new_command_line_signal (); + }); + + } -void command_widget::notice_settings (const gui_settings *settings) -{ - // Set terminal font: - QFont term_font = QFont (); - term_font.setStyleHint (QFont::TypeWriter); - QString default_font = settings->value (global_mono_font).toString (); - term_font.setFamily - (settings->value (cs_font.key, default_font).toString ()); - term_font.setPointSize - (settings->value (cs_font_size).toInt ()); + void command_widget::notice_settings () + { + gui_settings settings; - 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); + // Set terminal font: + QFont term_font = QFont (); + term_font.setStyleHint (QFont::TypeWriter); + QString default_font = settings.string_value (global_mono_font); + term_font.setFamily + (settings.value (cs_font.settings_key (), default_font).toString ()); + term_font.setPointSize + (settings.int_value (cs_font_size)); - m_console->setStyleSheet (QString ("color: %1; background-color:%2;") - .arg (fgc.name ()).arg (bgc.name ())); -} + m_console->setFont (term_font); + + // Colors + 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); -// The console itself using QScintilla. -// This implementation is partly based on the basic concept of -// "qpconsole" as proposed by user "DerManu" in the Qt-forum thread -// https://forum.qt.io/topic/28765/command-terminal-using-qtextedit + m_console->setStyleSheet (QString ("color: %1; background-color:%2;") + .arg (fgc.name ()).arg (bgc.name ())); + } + + // The console itself using QScintilla. + // This implementation is partly based on the basic concept of + // "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&) - : QsciScintilla (p), - m_command_position (-1), - m_cursor_position (0), - m_text_changed (false), - m_command_widget (p), - m_last_key_string (QString ()) -{ - setMargins (0); - setWrapMode (QsciScintilla::WrapWord); + console::console (command_widget *p) + : QsciScintilla (p), + m_command_position (-1), + m_cursor_position (0), + m_text_changed (false), + m_command_widget (p), + m_last_key_string (QString ()) + { + setMargins (0); + setWrapMode (QsciScintilla::WrapWord); - connect (this, SIGNAL (cursorPositionChanged (int, int)), - this, SLOT (cursor_position_changed (int, int))); + 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 (modificationAttempted (void)), - this, SLOT (move_cursor_to_end (void))); -} + connect (this, SIGNAL (textChanged ()), + this, SLOT (text_changed ())); -// Prepare a new command line with the current prompt -void console::new_command_line (const QString& command) -{ - if (! text (lines () -1).isEmpty ()) - append ("\n"); + connect (this, SIGNAL (modificationAttempted ()), + this, SLOT (move_cursor_to_end ())); + } - append_string (m_command_widget->prompt ()); + // Prepare a new command line with the current prompt + void console::new_command_line (const QString& command) + { + if (! text (lines () -1).isEmpty ()) + append ("\n"); - int line, index; - getCursorPosition (&line,&index); - m_command_position = positionFromLineIndex (line, index); + append_string (m_command_widget->prompt ()); - append_string (command); -} + int line, index; + getCursorPosition (&line,&index); + m_command_position = positionFromLineIndex (line, index); -// Accept the current command line (or block) -void console::accept_command_line () -{ - QString input_line = text (lines () - 1); + append_string (command); + } - if (input_line.startsWith (m_command_widget->prompt ())) - input_line.remove(0, m_command_widget->prompt ().length ()); - - input_line = input_line.trimmed (); - - append_string ("\n"); + // Accept the current command line (or block) + void console::accept_command_line () + { + QString input_line = text (lines () - 1); - if (input_line.isEmpty ()) - new_command_line (); - else - m_command_widget->process_input_line (input_line); -} + if (input_line.startsWith (m_command_widget->prompt ())) + input_line.remove(0, m_command_widget->prompt ().length ()); + + input_line = input_line.trimmed (); -// Execute a command -void console::execute_command (const QString& command) -{ - if (command.trimmed ().isEmpty ()) - return; + append_string ("\n"); + + if (input_line.isEmpty ()) + new_command_line (); + else + m_command_widget->process_input_line (input_line); + } - new_command_line (command); - accept_command_line (); -} + // Execute a command + void console::execute_command (const QString& command) + { + if (command.trimmed ().isEmpty ()) + return; -// Append a string and update the curdor püosition -void console::append_string (const QString& string) -{ - setReadOnly (false); - append (string); - - int line, index; - lineIndexFromPosition (text ().length (), &line, &index); - - setCursorPosition (line, index); -} + new_command_line (command); + accept_command_line (); + } -// Cursor position changed: Are we in the command line or not? -void console::cursor_position_changed (int line, int col) -{ - m_cursor_position = positionFromLineIndex (line, col); - if (m_cursor_position < m_command_position) - { - // We are in the read only area - if (m_text_changed && (m_cursor_position == m_command_position - 1)) - { - setReadOnly (false); - insert (m_command_widget->prompt ().right (1)); // And here we have tried to remove the prompt by Backspace - setCursorPosition (line+1, col); - } - setReadOnly (true); - } - else - setReadOnly (false); // Writable area + // Append a string and update the curdor püosition + void console::append_string (const QString& string) + { + setReadOnly (false); + append (string); + + int line, index; + lineIndexFromPosition (text ().length (), &line, &index); + + setCursorPosition (line, index); + } - m_text_changed = false; -} + // Cursor position changed: Are we in the command line or not? + void console::cursor_position_changed (int line, int col) + { + m_cursor_position = positionFromLineIndex (line, col); + if (m_cursor_position < m_command_position) + { + // We are in the read only area + if (m_text_changed && (m_cursor_position == m_command_position - 1)) + { + setReadOnly (false); + insert (m_command_widget->prompt ().right (1)); // And here we have tried to remove the prompt by Backspace + setCursorPosition (line+1, col); + } + setReadOnly (true); + } + else + setReadOnly (false); // Writable area -// User attempted to type on read only mode: move cursor at end and allow -// editing -void console::move_cursor_to_end (void) -{ - if ((! m_last_key_string.isEmpty ()) && (m_last_key_string.at (0).isPrint ())) - { - append_string (m_last_key_string); - setReadOnly (true); // Avoid that changing read only text is done afterwards - } -} + m_text_changed = false; + } -// Text has changed: is cursor still in "writable" area? -// This signal seems to be emitted before cursor position changed. -void console::text_changed (void) -{ - m_text_changed = true; -} + // User attempted to type on read only mode: move cursor at end and allow + // editing + void console::move_cursor_to_end () + { + if ((! m_last_key_string.isEmpty ()) && (m_last_key_string.at (0).isPrint ())) + { + append_string (m_last_key_string); + setReadOnly (true); // Avoid that changing read only text is done afterwards + } + } -// Re-implement key event -void console::keyPressEvent (QKeyEvent *e) -{ - if (e->key () == Qt::Key_Return) - // On "return", accept the current command line - accept_command_line (); - else - { - // Otherwise, store text process the expected event - m_last_key_string = e->text (); - QsciScintilla::keyPressEvent(e); - } -} + // Text has changed: is cursor still in "writable" area? + // This signal seems to be emitted before cursor position changed. + void console::text_changed () + { + m_text_changed = true; + } + + // Re-implement key event + void console::keyPressEvent (QKeyEvent *e) + { + if (e->key () == Qt::Key_Return) + // On "return", accept the current command line + accept_command_line (); + else + { + // Otherwise, store text process the expected event + m_last_key_string = e->text (); + QsciScintilla::keyPressEvent(e); + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/command-widget.h --- a/libgui/src/command-widget.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/command-widget.h Mon Jan 30 18:36:03 2023 +0100 @@ -30,97 +30,105 @@ #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 command_widget; -class console : public QsciScintilla -{ - Q_OBJECT + class console : public QsciScintilla + { + Q_OBJECT -public: + public: + + console (command_widget *p); - console (command_widget *p, base_qobject& oct_qobj); + signals: -public slots: + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); - void cursor_position_changed (int line, int col); + public slots: - void text_changed (void); + void cursor_position_changed (int line, int col); - void move_cursor_to_end (void); + void text_changed (); - void new_command_line (const QString& command = QString ()); + void move_cursor_to_end (); - void execute_command (const QString& command); + void new_command_line (const QString& command = QString ()); + + void execute_command (const QString& command); -protected: + protected: - void keyPressEvent (QKeyEvent *e); + void keyPressEvent (QKeyEvent *e); -private: + private: - void append_string (const QString& string); + void append_string (const QString& string); - void accept_command_line (void); + void accept_command_line (); - int m_command_position; - int m_cursor_position; - bool m_text_changed; - command_widget *m_command_widget; - QString m_last_key_string; + int m_command_position; + int m_cursor_position; + bool m_text_changed; + command_widget *m_command_widget; + QString m_last_key_string; -}; + }; -class command_widget : public QWidget -{ - Q_OBJECT + class command_widget : public QWidget + { + Q_OBJECT -public: + public: - command_widget (base_qobject& oct_qobj, QWidget *p); + command_widget (QWidget *p); - console * get_console ( ) { return m_console; }; + console * get_console ( ) { return m_console; }; - void init_command_prompt (); + void init_command_prompt (); - QString prompt (void); + QString prompt (); -signals: + 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 interpreter_event (const fcn_callback& fcn); - void interpreter_event (const meth_callback& meth); - - void new_command_line_signal (const QString& command = QString ()); + void update_prompt_signal (const QString& prompt); + void new_command_line_signal (const QString& command = QString ()); -public slots: + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); - void process_input_line (const QString& input_line); + public slots: - void update_prompt (const QString& prompt); + void process_input_line (const QString& input_line); - void insert_interpreter_output (const QString& msg); + void update_prompt (const QString& prompt); - void notice_settings (const gui_settings *settings); + void insert_interpreter_output (const QString& msg); + + void notice_settings (); -private: + private: - bool m_incomplete_parse; - QString m_prompt; - console *m_console; -}; + bool m_incomplete_parse; + QString m_prompt; + console *m_console; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/community-news.cc --- a/libgui/src/community-news.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/community-news.cc Mon Jan 30 18:36:03 2023 +0100 @@ -35,105 +35,99 @@ #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) -{ - construct (oct_qobj, "https://octave.org", "community-news.html", serial); -} + community_news::community_news (int serial) + : QWidget (nullptr), m_browser (nullptr) + { + 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) - : QWidget (parent), m_browser (nullptr) -{ - construct (oct_qobj, base_url, page, serial); -} + community_news::community_news (QWidget *parent, const QString& base_url, + const QString& page, int serial) + : QWidget (parent), m_browser (nullptr) + { + construct (base_url, page, serial); + } -void community_news::construct (base_qobject& oct_qobj, - const QString& base_url, const QString& page, - int serial) -{ - m_browser = new QTextBrowser (this); + void community_news::construct (const QString& base_url, const QString& page, + int serial) + { + m_browser = new QTextBrowser (this); - m_browser->setObjectName ("OctaveNews"); - m_browser->setOpenExternalLinks (true); + m_browser->setObjectName ("OctaveNews"); + m_browser->setOpenExternalLinks (true); - QVBoxLayout *vlayout = new QVBoxLayout; + QVBoxLayout *vlayout = new QVBoxLayout; - vlayout->addWidget (m_browser); + vlayout->addWidget (m_browser); - setLayout (vlayout); - setWindowTitle (tr ("Octave Community News")); + setLayout (vlayout); + setWindowTitle (tr ("Octave Community News")); - int win_x, win_y; - get_screen_geometry (win_x, win_y); + int win_x, win_y; + get_screen_geometry (win_x, win_y); - resize (win_x/2, win_y/2); - move ((win_x - width ())/2, (win_y - height ())/2); + 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 (); - 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"; - else - icon = dw_icon_set_names[icon_set]; + QString icon; + 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"; + else + icon = dw_icon_set_names[icon_set]; - setWindowIcon (QIcon (icon)); - - // FIXME: This is a news reader preference, so shouldn't it be used - // in the news_reader object? + setWindowIcon (QIcon (icon)); - bool connect_to_web - = (settings - ? settings->value (nr_allow_connection).toBool () - : true); + // FIXME: This is a news reader preference, so shouldn't it be used + // in the news_reader object? + + bool connect_to_web = settings.bool_value (nr_allow_connection); + + QThread *worker_thread = new QThread; - QThread *worker_thread = new QThread; + news_reader *reader + = new news_reader (base_url, page, serial, connect_to_web); - news_reader *reader = new news_reader (oct_qobj, base_url, page, - serial, connect_to_web); + reader->moveToThread (worker_thread); - reader->moveToThread (worker_thread); + connect (reader, &news_reader::display_news_signal, + this, &community_news::set_news); - connect (reader, &news_reader::display_news_signal, - this, &community_news::set_news); + connect (worker_thread, &QThread::started, + reader, &news_reader::process); - connect (worker_thread, &QThread::started, - reader, &news_reader::process); + connect (reader, &news_reader::finished, worker_thread, &QThread::quit); - connect (reader, &news_reader::finished, worker_thread, &QThread::quit); - - connect (reader, &news_reader::finished, reader, &news_reader::deleteLater); + connect (reader, &news_reader::finished, reader, &news_reader::deleteLater); - connect (worker_thread, &QThread::finished, - worker_thread, &QThread::deleteLater); + connect (worker_thread, &QThread::finished, + worker_thread, &QThread::deleteLater); - worker_thread->start (); -} + worker_thread->start (); + } -void community_news::set_news (const QString& news) -{ - m_browser->setHtml (news); -} + void community_news::set_news (const QString& news) + { + m_browser->setHtml (news); + } -void community_news::display (void) -{ - if (! isVisible ()) - show (); - else if (isMinimized ()) - showNormal (); + void community_news::display () + { + if (! isVisible ()) + show (); + else if (isMinimized ()) + showNormal (); - raise (); - activateWindow (); -} + raise (); + activateWindow (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/community-news.h --- a/libgui/src/community-news.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/community-news.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,36 +33,33 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class community_news : public QWidget + { + Q_OBJECT -class community_news : public QWidget -{ - Q_OBJECT + public: -public: - - community_news (base_qobject& oct_qobj, int serial); + community_news (int serial); - community_news (base_qobject& oct_qobj, QWidget *parent = nullptr, - const QString& base_url = "https://octave.org", - const QString& page = "community-news.html", - int serial = -1); + 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; - -public slots: + ~community_news () = default; - void set_news (const QString& news); + public slots: - void display (void); + void set_news (const QString& news); -private: + 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; -}; + QTextBrowser *m_browser; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/dialog.cc --- a/libgui/src/dialog.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/dialog.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,670 +42,668 @@ #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 () -{ - connect (this, &QUIWidgetCreator::create_dialog, - this, &QUIWidgetCreator::handle_create_dialog); + 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); - connect (this, &QUIWidgetCreator::create_listview, - this, &QUIWidgetCreator::handle_create_listview); + connect (this, &QUIWidgetCreator::create_listview, + this, &QUIWidgetCreator::handle_create_listview); - connect (this, &QUIWidgetCreator::create_inputlayout, - this, &QUIWidgetCreator::handle_create_inputlayout); + connect (this, &QUIWidgetCreator::create_inputlayout, + this, &QUIWidgetCreator::handle_create_inputlayout); - connect (this, &QUIWidgetCreator::create_filedialog, - this, &QUIWidgetCreator::handle_create_filedialog); -} + connect (this, &QUIWidgetCreator::create_filedialog, + this, &QUIWidgetCreator::handle_create_filedialog); + } -QString QUIWidgetCreator::rm_amp (const QString& text) -{ - QString text_wo_amp = text; - text_wo_amp.replace (QRegExp ("&(\\w)"), "\\1"); - return text_wo_amp; -} + QString QUIWidgetCreator::rm_amp (const QString& text) + { + QString text_wo_amp = text; + text_wo_amp.replace (QRegExp ("&(\\w)"), "\\1"); + return text_wo_amp; + } -QString QUIWidgetCreator::message_dialog (const QString& message, - const QString& title, - const QString& icon, - const QStringList& buttons, - const QString& defbutton, - const QStringList& role) -{ - QMutexLocker autolock (&m_mutex); + QString QUIWidgetCreator::message_dialog (const QString& message, + const QString& title, + const QString& icon, + const QStringList& buttons, + const QString& defbutton, + const QStringList& role) + { + QMutexLocker autolock (&m_mutex); - // Store button text before a window-manager adds accelerators. + // Store button text before a window-manager adds accelerators. - m_button_list = buttons; + m_button_list = buttons; - // Use the last button in the list as the reject result, i.e., when - // no button is pressed such as in the case of the upper right close - // tab. - if (! buttons.isEmpty ()) - m_dialog_button = buttons.last (); + // Use the last button in the list as the reject result, i.e., when + // no button is pressed such as in the case of the upper right close + // tab. + if (! buttons.isEmpty ()) + m_dialog_button = buttons.last (); - QString xicon = icon; - if (xicon.isEmpty ()) - xicon = "none"; + QString xicon = icon; + if (xicon.isEmpty ()) + xicon = "none"; - emit create_dialog (message, title, xicon, buttons, defbutton, role); + emit create_dialog (message, title, xicon, buttons, defbutton, role); - // Wait while the user is responding to message box. - wait (); + // Wait while the user is responding to message box. + wait (); - // The GUI has sent a signal and the thread has been awakened. - return m_dialog_button; -}; + // The GUI has sent a signal and the thread has been awakened. + return m_dialog_button; + }; -QPair -QUIWidgetCreator::list_dialog (const QStringList& list, const QString& mode, - int wd, int ht, const QList& initial, - const QString& name, - const QStringList& prompt, - const QString& ok_string, - const QString& cancel_string) -{ - if (list.isEmpty ()) - return QPair (); + QPair + QUIWidgetCreator::list_dialog (const QStringList& list, const QString& mode, + int wd, int ht, const QList& initial, + const QString& name, + const QStringList& prompt, + const QString& ok_string, + const QString& cancel_string) + { + if (list.isEmpty ()) + return QPair (); - QMutexLocker autolock (&m_mutex); + QMutexLocker autolock (&m_mutex); - emit create_listview (list, mode, wd, ht, initial, name, - prompt, ok_string, cancel_string); + emit create_listview (list, mode, wd, ht, initial, name, + prompt, ok_string, cancel_string); - // Wait while the user is responding to message box. - wait (); + // Wait while the user is responding to message box. + wait (); - // The GUI has sent a signal and the thread has been awakened. - return QPair (m_list_index, m_dialog_result); -}; + // The GUI has sent a signal and the thread has been awakened. + return QPair (m_list_index, m_dialog_result); + }; -// Create a message dialog with specified string, buttons and -// decorative text. + // Create a message dialog with specified string, buttons and + // decorative text. -QStringList QUIWidgetCreator::input_dialog (const QStringList& prompt, - const QString& title, - const QFloatList& nr, - const QFloatList& nc, - const QStringList& defaults) -{ - if (prompt.isEmpty ()) - return QStringList (); + QStringList QUIWidgetCreator::input_dialog (const QStringList& prompt, + const QString& title, + const QFloatList& nr, + const QFloatList& nc, + const QStringList& defaults) + { + if (prompt.isEmpty ()) + return QStringList (); - QMutexLocker autolock (&m_mutex); + QMutexLocker autolock (&m_mutex); - emit create_inputlayout (prompt, title, nr, nc, defaults); + emit create_inputlayout (prompt, title, nr, nc, defaults); - // Wait while the user is responding to message box. - wait (); + // Wait while the user is responding to message box. + wait (); - // The GUI has sent a signal and the thread has been awakened. - return m_string_list; -}; + // The GUI has sent a signal and the thread has been awakened. + return m_string_list; + }; -QStringList QUIWidgetCreator::file_dialog (const QStringList& filters, - const QString& title, - const QString& filename, - const QString& dirname, - const QString& multimode) -{ - QMutexLocker autolock (&m_mutex); + QStringList QUIWidgetCreator::file_dialog (const QStringList& filters, + const QString& title, + const QString& filename, + const QString& dirname, + const QString& multimode) + { + QMutexLocker autolock (&m_mutex); - emit create_filedialog (filters, title, filename, dirname, multimode); + emit create_filedialog (filters, title, filename, dirname, multimode); - // Wait while the user is responding to dialog. - wait (); + // Wait while the user is responding to dialog. + wait (); - // The GUI has sent a signal and the thread has been awakened. - // Add all the file dialog results to a string list. - QStringList retval; - retval << m_string_list - << m_path_name - << QString::number (m_dialog_result); + // The GUI has sent a signal and the thread has been awakened. + // Add all the file dialog results to a string list. + QStringList retval; + retval << m_string_list + << m_path_name + << QString::number (m_dialog_result); - return retval; -} + return retval; + } -void QUIWidgetCreator::handle_create_dialog (const QString& message, - const QString& title, - const QString& icon, - const QStringList& button, - const QString& defbutton, - const QStringList& role) -{ - MessageDialog *message_dialog - = new MessageDialog (m_octave_qobj, message, title, icon, - button, defbutton, role); + void QUIWidgetCreator::handle_create_dialog (const QString& message, + const QString& title, + const QString& icon, + const QStringList& button, + const QString& defbutton, + const QStringList& role) + { + MessageDialog *message_dialog + = new MessageDialog (message, title, icon, button, defbutton, role); - connect (message_dialog, &MessageDialog::buttonClicked, - this, &QUIWidgetCreator::dialog_button_clicked); + connect (message_dialog, &MessageDialog::buttonClicked, + this, &QUIWidgetCreator::dialog_button_clicked); - message_dialog->setAttribute (Qt::WA_DeleteOnClose); - message_dialog->show (); -} + message_dialog->setAttribute (Qt::WA_DeleteOnClose); + message_dialog->show (); + } -void QUIWidgetCreator::dialog_button_clicked (QAbstractButton *button) -{ - // button is NULL when dialog is closed. - if (button) - { - // Check for a matching button text while ignoring accelerators - // because the window manager may have added one in the passed - // button. + void QUIWidgetCreator::dialog_button_clicked (QAbstractButton *button) + { + // button is NULL when dialog is closed. + if (button) + { + // Check for a matching button text while ignoring accelerators + // because the window manager may have added one in the passed + // button. - QString text_clean = rm_amp (button->text ()); + QString text_clean = rm_amp (button->text ()); - for (int i = 0; i < m_button_list.count (); i++) - { - if (rm_amp (m_button_list.at (i)) == text_clean) - { - // Text w/o extra accelerator. - m_dialog_button = m_button_list.at (i); - break; - } - } - } + for (int i = 0; i < m_button_list.count (); i++) + { + if (rm_amp (m_button_list.at (i)) == text_clean) + { + // Text w/o extra accelerator. + m_dialog_button = m_button_list.at (i); + break; + } + } + } - // The value should always be 1 for the Octave functions. - m_dialog_result = 1; + // The value should always be 1 for the Octave functions. + m_dialog_result = 1; - // Wake up Octave process so that it continues. - wake_all (); -} + // Wake up Octave process so that it continues. + wake_all (); + } -// Create a list dialog with specified list, initially selected, mode, -// view size and decorative text. + // Create a list dialog with specified list, initially selected, mode, + // view size and decorative text. -void QUIWidgetCreator::handle_create_listview (const QStringList& list, - const QString& mode, - int wd, int ht, - const QIntList& initial, - const QString& name, - const QStringList& prompt, - const QString& ok_string, - const QString& cancel_string) -{ - ListDialog *list_dialog - = new ListDialog (m_octave_qobj, list, mode, wd, ht, initial, - name, prompt, ok_string, cancel_string); + void QUIWidgetCreator::handle_create_listview (const QStringList& list, + const QString& mode, + int wd, int ht, + const QIntList& initial, + const QString& name, + const QStringList& prompt, + const QString& ok_string, + const QString& cancel_string) + { + ListDialog *list_dialog + = new ListDialog (list, mode, wd, ht, initial, + name, prompt, ok_string, cancel_string); - connect (list_dialog, &ListDialog::finish_selection, - this, &QUIWidgetCreator::list_select_finished); + connect (list_dialog, &ListDialog::finish_selection, + this, &QUIWidgetCreator::list_select_finished); + + list_dialog->setAttribute (Qt::WA_DeleteOnClose); + list_dialog->show (); + } - list_dialog->setAttribute (Qt::WA_DeleteOnClose); - list_dialog->show (); -} + void QUIWidgetCreator::list_select_finished (const QIntList& selected, + int button_pressed) + { + // Store the value so that builtin functions can retrieve. -void QUIWidgetCreator::list_select_finished (const QIntList& selected, - int button_pressed) -{ - // Store the value so that builtin functions can retrieve. + m_list_index = selected; + m_dialog_result = button_pressed; - m_list_index = selected; - m_dialog_result = button_pressed; + // Wake up Octave process so that it continues. + wake_all (); + } - // Wake up Octave process so that it continues. - wake_all (); -} + // Create an input dialog with specified prompts and defaults, title + // and row/column size specifications. -// Create an input dialog with specified prompts and defaults, title -// and row/column size specifications. + void QUIWidgetCreator::handle_create_inputlayout (const QStringList& prompt, + const QString& title, + const QFloatList& nr, + const QFloatList& nc, + const QStringList& defaults) + { + InputDialog *input_dialog + = new InputDialog (prompt, title, nr, nc, defaults); -void QUIWidgetCreator::handle_create_inputlayout (const QStringList& prompt, - const QString& title, - const QFloatList& nr, - const QFloatList& nc, - const QStringList& defaults) -{ - InputDialog *input_dialog - = new InputDialog (m_octave_qobj, prompt, title, nr, nc, defaults); + connect (input_dialog, &InputDialog::finish_input, + this, &QUIWidgetCreator::input_finished); - connect (input_dialog, &InputDialog::finish_input, - this, &QUIWidgetCreator::input_finished); + input_dialog->setAttribute (Qt::WA_DeleteOnClose); + input_dialog->show (); + } - input_dialog->setAttribute (Qt::WA_DeleteOnClose); - input_dialog->show (); -} + void QUIWidgetCreator::input_finished (const QStringList& input, + int button_pressed) + { + // Store the value so that builtin functions can retrieve. + + m_string_list = input; + m_dialog_result = button_pressed; -void QUIWidgetCreator::input_finished (const QStringList& input, - int button_pressed) -{ - // Store the value so that builtin functions can retrieve. + // Wake up Octave process so that it continues. + wake_all (); + } - m_string_list = input; - m_dialog_result = button_pressed; - - // Wake up Octave process so that it continues. - wake_all (); -} + void QUIWidgetCreator::handle_create_filedialog (const QStringList& filters, + const QString& title, + const QString& filename, + const QString& dirname, + const QString& multimode) + { + FileDialog *file_dialog + = new FileDialog (filters, title, filename, dirname, multimode); -void QUIWidgetCreator::handle_create_filedialog (const QStringList& filters, - const QString& title, - const QString& filename, - const QString& dirname, - const QString& multimode) -{ - FileDialog *file_dialog - = new FileDialog (m_octave_qobj, filters, title, filename, - dirname, multimode); + connect (file_dialog, &FileDialog::finish_input, + this, &QUIWidgetCreator::filedialog_finished); + + file_dialog->setAttribute (Qt::WA_DeleteOnClose); + file_dialog->show (); + } - connect (file_dialog, &FileDialog::finish_input, - this, &QUIWidgetCreator::filedialog_finished); + void QUIWidgetCreator::filedialog_finished (const QStringList& files, + const QString& path, + int filterindex) + { + // Store the value so that builtin functions can retrieve. - file_dialog->setAttribute (Qt::WA_DeleteOnClose); - file_dialog->show (); -} + m_string_list = files; + m_dialog_result = filterindex; + m_path_name = path; -void QUIWidgetCreator::filedialog_finished (const QStringList& files, - const QString& path, - int filterindex) -{ - // Store the value so that builtin functions can retrieve. - - m_string_list = files; - m_dialog_result = filterindex; - m_path_name = path; - - // Wake up Octave process so that it continues. - wake_all (); -} + // Wake up Octave process so that it continues. + wake_all (); + } -MessageDialog::MessageDialog (base_qobject&, const QString& message, - const QString& title, const QString& qsicon, - const QStringList& qsbutton, - const QString& defbutton, - const QStringList& role) - : QMessageBox (QMessageBox::NoIcon, title.isEmpty () ? " " : title, - message) -{ - // Create a NonModal message. - setWindowModality (Qt::NonModal); + MessageDialog::MessageDialog (const QString& message, + const QString& title, const QString& qsicon, + const QStringList& qsbutton, + const QString& defbutton, + const QStringList& role) + : QMessageBox (QMessageBox::NoIcon, title.isEmpty () ? " " : title, + message) + { + // Create a NonModal message. + setWindowModality (Qt::NonModal); - // Interpret the icon string, because enumeration QMessageBox::Icon can't - // easily be made to pass through a signal. + // Interpret the icon string, because enumeration QMessageBox::Icon can't + // easily be made to pass through a signal. + + QMessageBox::Icon eicon = QMessageBox::NoIcon; - QMessageBox::Icon eicon = QMessageBox::NoIcon; + if (qsicon == "error") + eicon = QMessageBox::Critical; + else if (qsicon == "warn") + eicon = QMessageBox::Warning; + else if (qsicon == "help") + eicon = QMessageBox::Information; + else if (qsicon == "quest") + eicon = QMessageBox::Question; - if (qsicon == "error") - eicon = QMessageBox::Critical; - else if (qsicon == "warn") - eicon = QMessageBox::Warning; - else if (qsicon == "help") - eicon = QMessageBox::Information; - else if (qsicon == "quest") - eicon = QMessageBox::Question; + setIcon (eicon); - setIcon (eicon); - - int N = (qsbutton.size () < role.size () ? qsbutton.size () : role.size ()); + int N = (qsbutton.size () < role.size () ? qsbutton.size () : role.size ()); - if (N == 0) - addButton (QMessageBox::Ok); - else - { - for (int i = 0; i < N; i++) - { - // Interpret the button role string, because enumeration - // QMessageBox::ButtonRole can't be made to pass through a - // signal. + if (N == 0) + addButton (QMessageBox::Ok); + else + { + for (int i = 0; i < N; i++) + { + // Interpret the button role string, because enumeration + // QMessageBox::ButtonRole can't be made to pass through a + // signal. - QString srole = role.at (i); - QMessageBox::ButtonRole erole = QMessageBox::InvalidRole; - if (srole == "ResetRole") - erole = QMessageBox::ResetRole; - else if (srole == "YesRole") - erole = QMessageBox::YesRole; - else if (srole == "NoRole") - erole = QMessageBox::NoRole; - else if (srole == "RejectRole") - erole = QMessageBox::RejectRole; - else if (srole == "AcceptRole") - erole = QMessageBox::AcceptRole; + QString srole = role.at (i); + QMessageBox::ButtonRole erole = QMessageBox::InvalidRole; + if (srole == "ResetRole") + erole = QMessageBox::ResetRole; + else if (srole == "YesRole") + erole = QMessageBox::YesRole; + else if (srole == "NoRole") + erole = QMessageBox::NoRole; + else if (srole == "RejectRole") + erole = QMessageBox::RejectRole; + else if (srole == "AcceptRole") + erole = QMessageBox::AcceptRole; - QPushButton *pbutton = addButton (qsbutton.at (i), erole); - if (qsbutton.at (i) == defbutton) - setDefaultButton (pbutton); + QPushButton *pbutton = addButton (qsbutton.at (i), erole); + if (qsbutton.at (i) == defbutton) + setDefaultButton (pbutton); - // Make the last button the button pressed when key activated. - if (i == N-1) - { - // FIXME: Why define and then immediately test value? + // Make the last button the button pressed when key activated. + if (i == N-1) + { + // FIXME: Why define and then immediately test value? #define ACTIVE_ESCAPE 1 #if ACTIVE_ESCAPE - setEscapeButton (pbutton); + setEscapeButton (pbutton); #else - setEscapeButton (0); + setEscapeButton (0); #endif #undef ACTIVE_ESCAPE - } - } - } -} + } + } + } + } -ListDialog::ListDialog (base_qobject&, const QStringList& list, - const QString& mode, int wd, int ht, - const QList& initial, const QString& title, - const QStringList& prompt, - const QString& ok_string, - const QString& cancel_string) - : QDialog (), m_model (new QStringListModel (list, this)) -{ - QListView *view = new QListView; - view->setModel (m_model); + ListDialog::ListDialog (const QStringList& list, + const QString& mode, int wd, int ht, + const QList& initial, const QString& title, + const QStringList& prompt, + const QString& ok_string, + const QString& cancel_string) + : QDialog (), m_model (new QStringListModel (list, this)) + { + QListView *view = new QListView; + view->setModel (m_model); - if (mode == "single") - view->setSelectionMode (QAbstractItemView::SingleSelection); - else if (mode == "multiple") - view->setSelectionMode (QAbstractItemView::ExtendedSelection); - else - view->setSelectionMode (QAbstractItemView::NoSelection); + if (mode == "single") + view->setSelectionMode (QAbstractItemView::SingleSelection); + else if (mode == "multiple") + view->setSelectionMode (QAbstractItemView::ExtendedSelection); + else + view->setSelectionMode (QAbstractItemView::NoSelection); - selector = view->selectionModel (); - int i = 0; - for (auto it = initial.begin (); it != initial.end (); it++) - { - QModelIndex idx = m_model->index (initial.value (i++) - 1, 0, - QModelIndex ()); - selector->select (idx, QItemSelectionModel::Select); - } + selector = view->selectionModel (); + int i = 0; + for (auto it = initial.begin (); it != initial.end (); it++) + { + QModelIndex idx = m_model->index (initial.value (i++) - 1, 0, + QModelIndex ()); + selector->select (idx, QItemSelectionModel::Select); + } - bool fixed_layout = false; - if (wd > 0 && ht > 0) - { - view->setFixedSize (wd, ht); - fixed_layout = true; - } + bool fixed_layout = false; + if (wd > 0 && ht > 0) + { + view->setFixedSize (wd, ht); + fixed_layout = true; + } - view->setEditTriggers (QAbstractItemView::NoEditTriggers); + view->setEditTriggers (QAbstractItemView::NoEditTriggers); - 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. - QString prompt_string; - for (int j = 0; j < prompt.length (); j++) - { - if (j > 0) - // FIXME: Why define and then immediately test value? + 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. + QString prompt_string; + for (int j = 0; 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 ("
"); + prompt_string.append ("
"); #else - prompt_string.append ("\n"); + prompt_string.append ("\n"); #endif - prompt_string.append (prompt.at (j)); - } - QLabel *plabel = new QLabel (prompt_string); + prompt_string.append (prompt.at (j)); + } + QLabel *plabel = new QLabel (prompt_string); #if RICH_TEXT - plabel->setTextFormat (Qt::RichText); + plabel->setTextFormat (Qt::RichText); #endif #undef RICH_TEXT - listLayout->addWidget (plabel); - } - listLayout->addWidget (view); - QPushButton *select_all = new QPushButton (tr ("Select All")); - select_all->setVisible (mode == "multiple"); - listLayout->addWidget (select_all); + listLayout->addWidget (plabel); + } + listLayout->addWidget (view); + QPushButton *select_all = new QPushButton (tr ("Select All")); + select_all->setVisible (mode == "multiple"); + listLayout->addWidget (select_all); - QPushButton *buttonOk = new QPushButton (ok_string); - QPushButton *buttonCancel = new QPushButton (cancel_string); - QHBoxLayout *buttonsLayout = new QHBoxLayout; - buttonsLayout->addStretch (1); - buttonsLayout->addWidget (buttonOk); - buttonsLayout->addWidget (buttonCancel); - buttonOk->setDefault (true); + QPushButton *buttonOk = new QPushButton (ok_string); + QPushButton *buttonCancel = new QPushButton (cancel_string); + QHBoxLayout *buttonsLayout = new QHBoxLayout; + buttonsLayout->addStretch (1); + buttonsLayout->addWidget (buttonOk); + buttonsLayout->addWidget (buttonCancel); + buttonOk->setDefault (true); - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout (listLayout); - mainLayout->addSpacing (12); - mainLayout->addLayout (buttonsLayout); - setLayout (mainLayout); - if (fixed_layout) - layout ()->setSizeConstraint (QLayout::SetFixedSize); + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout (listLayout); + mainLayout->addSpacing (12); + mainLayout->addLayout (buttonsLayout); + setLayout (mainLayout); + if (fixed_layout) + layout ()->setSizeConstraint (QLayout::SetFixedSize); - // If empty, make blank rather than use default OS behavior. - setWindowTitle (title.isEmpty () ? " " : title); + // If empty, make blank rather than use default OS behavior. + setWindowTitle (title.isEmpty () ? " " : title); - connect (select_all, &QPushButton::clicked, - view, &QListView::selectAll); + connect (select_all, &QPushButton::clicked, + view, &QListView::selectAll); - connect (buttonOk, &QPushButton::clicked, - this, &ListDialog::buttonOk_clicked); + connect (buttonOk, &QPushButton::clicked, + this, &ListDialog::buttonOk_clicked); - connect (buttonCancel, &QPushButton::clicked, - this, &ListDialog::buttonCancel_clicked); + connect (buttonCancel, &QPushButton::clicked, + this, &ListDialog::buttonCancel_clicked); - connect (view, &QListView::doubleClicked, - this, &ListDialog::item_double_clicked); -} + connect (view, &QListView::doubleClicked, + this, &ListDialog::item_double_clicked); + } -void ListDialog::buttonOk_clicked (void) -{ - // Store information about what button was pressed so that builtin - // functions can retrieve. + void ListDialog::buttonOk_clicked () + { + // Store information about what button was pressed so that builtin + // functions can retrieve. - QModelIndexList selected_index = selector->selectedIndexes (); - QIntList selected_int; + QModelIndexList selected_index = selector->selectedIndexes (); + QIntList selected_int; - for (int i = 0; i < selected_index.size (); i++) - selected_int << selected_index.at (i).row () + 1; + for (int i = 0; i < selected_index.size (); i++) + selected_int << selected_index.at (i).row () + 1; - emit finish_selection (selected_int, 1); + emit finish_selection (selected_int, 1); - done (QDialog::Accepted); -} + done (QDialog::Accepted); + } -void ListDialog::buttonCancel_clicked (void) -{ - // Store information about what button was pressed so that builtin - // functions can retrieve. + void ListDialog::buttonCancel_clicked () + { + // Store information about what button was pressed so that builtin + // functions can retrieve. - QIntList empty; + QIntList empty; - emit finish_selection (empty, 0); + emit finish_selection (empty, 0); - done (QDialog::Rejected); -} + done (QDialog::Rejected); + } -void ListDialog::reject (void) -{ - buttonCancel_clicked (); -} + void ListDialog::reject () + { + buttonCancel_clicked (); + } -void ListDialog::item_double_clicked (const QModelIndex&) -{ - buttonOk_clicked (); -} + void ListDialog::item_double_clicked (const QModelIndex&) + { + buttonOk_clicked (); + } -InputDialog::InputDialog (base_qobject&, const QStringList& prompt, - const QString& title, const QFloatList& nr, - const QFloatList& nc, const QStringList& defaults) - : QDialog () -{ + InputDialog::InputDialog (const QStringList& prompt, + const QString& title, const QFloatList& nr, + const QFloatList& nc, const QStringList& defaults) + : QDialog () + { #define LINE_EDIT_FOLLOWS_PROMPT 0 #if LINE_EDIT_FOLLOWS_PROMPT - // Prompt on left followed by input on right. - QGridLayout *promptInputLayout = new QGridLayout; + // Prompt on left followed by input on right. + QGridLayout *promptInputLayout = new QGridLayout; #else - // Prompt aligned above input. - QVBoxLayout *promptInputLayout = new QVBoxLayout; + // Prompt aligned above input. + QVBoxLayout *promptInputLayout = new QVBoxLayout; #endif - int N_gridrows = prompt.size (); - for (int i = 0; i < N_gridrows; i++) - { - QLabel *label = new QLabel (prompt.at (i)); - QLineEdit *line_edit = new QLineEdit (); - if (i < defaults.size ()) - line_edit->setText (defaults.at (i)); - if (i < nr.size () && nr.at (i) > 0) - { - QSize qsize = line_edit->sizeHint (); - int intval = qsize.height () * nr.at (i); - line_edit->setFixedHeight (intval); - if (i < nc.size () && nc.at (i) > 0) - { - intval = qsize.height () * nc.at (i) / 2; - line_edit->setFixedWidth (intval); - } - } - input_line << line_edit; + int N_gridrows = prompt.size (); + for (int i = 0; i < N_gridrows; i++) + { + QLabel *label = new QLabel (prompt.at (i)); + QLineEdit *line_edit = new QLineEdit (); + if (i < defaults.size ()) + line_edit->setText (defaults.at (i)); + if (i < nr.size () && nr.at (i) > 0) + { + QSize qsize = line_edit->sizeHint (); + int intval = qsize.height () * nr.at (i); + line_edit->setFixedHeight (intval); + if (i < nc.size () && nc.at (i) > 0) + { + intval = qsize.height () * nc.at (i) / 2; + line_edit->setFixedWidth (intval); + } + } + input_line << line_edit; #if LINE_EDIT_FOLLOWS_PROMPT - promptInputLayout->addWidget (label, i + 1, 0); - promptInputLayout->addWidget (line_edit, i + 1, 1); + promptInputLayout->addWidget (label, i + 1, 0); + promptInputLayout->addWidget (line_edit, i + 1, 1); #else - promptInputLayout->addWidget (label); - promptInputLayout->addWidget (line_edit); + promptInputLayout->addWidget (label); + promptInputLayout->addWidget (line_edit); #endif - } + } #undef LINE_EDIT_FOLLOWS_PROMPT - QPushButton *buttonOk = new QPushButton ("OK"); - QPushButton *buttonCancel = new QPushButton ("Cancel"); - QHBoxLayout *buttonsLayout = new QHBoxLayout; - buttonsLayout->addStretch (1); - buttonsLayout->addWidget (buttonOk); - buttonsLayout->addWidget (buttonCancel); + QPushButton *buttonOk = new QPushButton ("OK"); + QPushButton *buttonCancel = new QPushButton ("Cancel"); + QHBoxLayout *buttonsLayout = new QHBoxLayout; + buttonsLayout->addStretch (1); + buttonsLayout->addWidget (buttonOk); + buttonsLayout->addWidget (buttonCancel); - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout (promptInputLayout); - mainLayout->addSpacing (12); - mainLayout->addLayout (buttonsLayout); - setLayout (mainLayout); + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout (promptInputLayout); + mainLayout->addSpacing (12); + mainLayout->addLayout (buttonsLayout); + setLayout (mainLayout); - // If empty, make blank rather than use default OS behavior. - setWindowTitle (title.isEmpty () ? " " : title); + // If empty, make blank rather than use default OS behavior. + setWindowTitle (title.isEmpty () ? " " : title); - connect (buttonOk, &QPushButton::clicked, - this, &InputDialog::buttonOk_clicked); + connect (buttonOk, &QPushButton::clicked, + this, &InputDialog::buttonOk_clicked); - connect (buttonCancel, &QPushButton::clicked, - this, &InputDialog::buttonCancel_clicked); -} + connect (buttonCancel, &QPushButton::clicked, + this, &InputDialog::buttonCancel_clicked); + } -void InputDialog::buttonOk_clicked (void) -{ - // Store information about what button was pressed so that builtin - // functions can retrieve. + 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 (); - emit finish_input (string_result, 1); - done (QDialog::Accepted); -} + QStringList string_result; + for (int i = 0; i < input_line.size (); i++) + string_result << input_line.at (i)->text (); + emit finish_input (string_result, 1); + done (QDialog::Accepted); + } -void InputDialog::buttonCancel_clicked (void) -{ - // Store information about what button was pressed so that builtin - // functions can retrieve. + void InputDialog::buttonCancel_clicked () + { + // Store information about what button was pressed so that builtin + // functions can retrieve. - QStringList empty; - emit finish_input (empty, 0); - done (QDialog::Rejected); -} + QStringList empty; + emit finish_input (empty, 0); + done (QDialog::Rejected); + } -void InputDialog::reject (void) -{ - buttonCancel_clicked (); -} + void InputDialog::reject () + { + buttonCancel_clicked (); + } -FileDialog::FileDialog (base_qobject& oct_qobj, - const QStringList& name_filters, - const QString& title, const QString& filename, - const QString& dirname, const QString& multimode) - : QFileDialog () -{ - // Create a NonModal message. - setWindowModality (Qt::NonModal); + FileDialog::FileDialog (const QStringList& name_filters, + const QString& title, const QString& filename, + const QString& dirname, const QString& multimode) + : QFileDialog () + { + // Create a NonModal message. + setWindowModality (Qt::NonModal); - setWindowTitle (title.isEmpty () ? " " : title); - setDirectory (dirname); + setWindowTitle (title.isEmpty () ? " " : title); + setDirectory (dirname); + + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. - // 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 ()) - setOption(QFileDialog::DontUseNativeDialog); + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) + setOption(QFileDialog::DontUseNativeDialog); - if (multimode == "on") // uigetfile multiselect=on - { - setFileMode (QFileDialog::ExistingFiles); - setAcceptMode (QFileDialog::AcceptOpen); - } - else if (multimode == "create") // uiputfile - { - setFileMode (QFileDialog::AnyFile); - setAcceptMode (QFileDialog::AcceptSave); - setOption (QFileDialog::DontConfirmOverwrite, false); - } - else if (multimode == "dir") // uigetdir - { - setFileMode (QFileDialog::Directory); - setOption (QFileDialog::ShowDirsOnly, true); - setOption (QFileDialog::HideNameFilterDetails, true); - setAcceptMode (QFileDialog::AcceptOpen); - } - else // uigetfile multiselect=off - { - setFileMode (QFileDialog::ExistingFile); - setAcceptMode (QFileDialog::AcceptOpen); - } + if (multimode == "on") // uigetfile multiselect=on + { + setFileMode (QFileDialog::ExistingFiles); + setAcceptMode (QFileDialog::AcceptOpen); + } + else if (multimode == "create") // uiputfile + { + setFileMode (QFileDialog::AnyFile); + setAcceptMode (QFileDialog::AcceptSave); + setOption (QFileDialog::DontConfirmOverwrite, false); + } + else if (multimode == "dir") // uigetdir + { + setFileMode (QFileDialog::Directory); + setOption (QFileDialog::ShowDirsOnly, true); + setOption (QFileDialog::HideNameFilterDetails, true); + setAcceptMode (QFileDialog::AcceptOpen); + } + else // uigetfile multiselect=off + { + setFileMode (QFileDialog::ExistingFile); + setAcceptMode (QFileDialog::AcceptOpen); + } - setNameFilters (name_filters); + setNameFilters (name_filters); - selectFile (filename); + selectFile (filename); - connect (this, &FileDialog::accepted, this, &FileDialog::acceptSelection); + connect (this, &FileDialog::accepted, this, &FileDialog::acceptSelection); - connect (this, &FileDialog::rejected, this, &FileDialog::rejectSelection); -} + connect (this, &FileDialog::rejected, this, &FileDialog::rejectSelection); + } -void FileDialog::rejectSelection (void) -{ - QStringList empty; - emit finish_input (empty, "", 0); -} + void FileDialog::rejectSelection () + { + QStringList empty; + emit finish_input (empty, "", 0); + } -void FileDialog::acceptSelection (void) -{ - QStringList string_result; - QString path; - int idx = 1; + void FileDialog::acceptSelection () + { + QStringList string_result; + QString path; + int idx = 1; - string_result = selectedFiles (); + string_result = selectedFiles (); - if (testOption (QFileDialog::ShowDirsOnly) && string_result.size () > 0) - path = string_result[0]; - else - path = directory ().absolutePath (); + if (testOption (QFileDialog::ShowDirsOnly) && string_result.size () > 0) + path = string_result[0]; + else + path = directory ().absolutePath (); - // Matlab expects just the filename, whereas the file dialog gave us - // full path names, so fix it. + // Matlab expects just the filename, whereas the file dialog gave us + // full path names, so fix it. - for (int i = 0; i < string_result.size (); i++) - string_result[i] = QFileInfo (string_result[i]).fileName (); + for (int i = 0; i < string_result.size (); i++) + string_result[i] = QFileInfo (string_result[i]).fileName (); - // If not showing only dirs, add end slash for the path component. - if (testOption (QFileDialog::ShowDirsOnly) == false) - path += '/'; + // If not showing only dirs, add end slash for the path component. + if (testOption (QFileDialog::ShowDirsOnly) == false) + path += '/'; - // Convert to native slashes. - path = QDir::toNativeSeparators (path); + // Convert to native slashes. + path = QDir::toNativeSeparators (path); - QStringList name_filters = nameFilters (); - idx = name_filters.indexOf (selectedNameFilter ()) + 1; + QStringList name_filters = nameFilters (); + idx = name_filters.indexOf (selectedNameFilter ()) + 1; - // Send the selected info. - emit finish_input (string_result, path, idx); -} + // Send the selected info. + emit finish_input (string_result, path, idx); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/dialog.h --- a/libgui/src/dialog.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/dialog.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,239 +44,235 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - -class QUIWidgetCreator : public QObject -{ - Q_OBJECT + class QUIWidgetCreator : public QObject + { + Q_OBJECT -public: + public: - QUIWidgetCreator (base_qobject& oct_qobj); + QUIWidgetCreator (); - ~QUIWidgetCreator (void) = default; + ~QUIWidgetCreator () = default; -public: + public: - QString rm_amp (const QString& text); + QString rm_amp (const QString& text); - QString message_dialog (const QString& message, const QString& title, - const QString& icon, const QStringList& button, - const QString& defbutton, const QStringList& role); + QString message_dialog (const QString& message, const QString& title, + 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, - int wd, int ht, - const QList& initial, - const QString& name, - const QStringList& prompt, - const QString& ok_string, - const QString& cancel_string); + QPair list_dialog (const QStringList& list, + const QString& mode, + int wd, int ht, + const QList& initial, + const QString& name, + const QStringList& prompt, + 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 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); + 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: + signals: - void create_dialog (const QString&, const QString&, const QString&, - const QStringList&, const QString&, const QStringList&); + void create_dialog (const QString&, const QString&, const QString&, + const QStringList&, const QString&, const QStringList&); - void create_listview (const QStringList&, const QString&, int, int, - const QIntList&, const QString&, const QStringList&, - const QString&, const QString&); + void create_listview (const QStringList&, const QString&, int, int, + const QIntList&, const QString&, const QStringList&, + const QString&, const QString&); - void create_inputlayout (const QStringList&, const QString&, - const QFloatList&, const QFloatList&, - const QStringList&); + void create_inputlayout (const QStringList&, const QString&, + const QFloatList&, const QFloatList&, + const QStringList&); - void create_filedialog (const QStringList& filters, const QString& title, - const QString& filename, const QString& dirname, - const QString& multimode); -public slots: + void create_filedialog (const QStringList& filters, const QString& title, + const QString& filename, const QString& dirname, + const QString& multimode); + public slots: - void handle_create_dialog (const QString& message, const QString& title, - const QString& icon, const QStringList& button, - const QString& defbutton, - const QStringList& role); + void handle_create_dialog (const QString& message, const QString& title, + const QString& icon, const QStringList& button, + const QString& defbutton, + const QStringList& role); - void dialog_button_clicked (QAbstractButton *button); + void dialog_button_clicked (QAbstractButton *button); - void handle_create_listview (const QStringList& list, const QString& mode, - int width, int height, - const QIntList& initial, - const QString& name, - const QStringList& prompt, - const QString& ok_string, - const QString& cancel_string); + void handle_create_listview (const QStringList& list, const QString& mode, + int width, int height, + const QIntList& initial, + const QString& name, + const QStringList& prompt, + const QString& ok_string, + const QString& cancel_string); - void list_select_finished (const QIntList& selected, int button_pressed); + void list_select_finished (const QIntList& selected, int button_pressed); - void handle_create_inputlayout (const QStringList&, const QString&, - const QFloatList&, const QFloatList&, - const QStringList&); + void handle_create_inputlayout (const QStringList&, const QString&, + const QFloatList&, const QFloatList&, + const QStringList&); - void input_finished (const QStringList& input, int button_pressed); + void input_finished (const QStringList& input, int button_pressed); - void handle_create_filedialog (const QStringList& filters, - const QString& title, - const QString& filename, - const QString& dirname, - const QString& multimode); + void handle_create_filedialog (const QStringList& filters, + const QString& title, + const QString& filename, + const QString& dirname, + const QString& multimode); - void filedialog_finished (const QStringList& files, const QString& path, - int filterindex); + void filedialog_finished (const QStringList& files, const QString& path, + int filterindex); -private: + private: - base_qobject& m_octave_qobj; - - int m_dialog_result; - QString m_dialog_button; + int m_dialog_result; + QString m_dialog_button; - // A copy of the dialogs button texts - QStringList m_button_list; + // A copy of the dialogs button texts + QStringList m_button_list; - // The list could conceivably be big. Not sure how things are - // stored internally, so keep off of the stack. - QStringList m_string_list; - QIntList m_list_index; + // The list could conceivably be big. Not sure how things are + // stored internally, so keep off of the stack. + QStringList m_string_list; + QIntList m_list_index; + + QString m_path_name; - QString m_path_name; - - // GUI objects cannot be accessed in the non-GUI thread. However, - // signals can be sent to slots across threads with proper - // synchronization. Hence, the use of QWaitCondition. - QMutex m_mutex; - QWaitCondition m_waitcondition; -}; - -class MessageDialog : public QMessageBox -{ - Q_OBJECT + // GUI objects cannot be accessed in the non-GUI thread. However, + // signals can be sent to slots across threads with proper + // synchronization. Hence, the use of QWaitCondition. + QMutex m_mutex; + QWaitCondition m_waitcondition; + }; -public: - - MessageDialog (base_qobject& oct_qobj, const QString& message, - const QString& title, const QString& icon, - const QStringList& button, const QString& defbutton, - const QStringList& role); - - ~MessageDialog (void) = default; - -private: - - void closeEvent (QCloseEvent *) + class MessageDialog : public QMessageBox { - // Reroute the close tab to a button click so there is only a single - // route to waking the wait condition. - emit buttonClicked (nullptr); - } -}; + Q_OBJECT + + public: + + MessageDialog (const QString& message, + const QString& title, const QString& icon, + const QStringList& button, const QString& defbutton, + const QStringList& role); -class ListDialog : public QDialog -{ - Q_OBJECT + ~MessageDialog () = default; + + private: - QItemSelectionModel *selector; - -public: + void closeEvent (QCloseEvent *) + { + // Reroute the close tab to a button click so there is only a single + // route to waking the wait condition. + emit buttonClicked (nullptr); + } + }; - ListDialog (base_qobject& oct_qobj, 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); + class ListDialog : public QDialog + { + Q_OBJECT - ~ListDialog (void) = default; + QItemSelectionModel *selector; + + public: -signals: + 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); - void finish_selection (const QIntList&, int); + ~ListDialog () = default; -public slots: + signals: + + void finish_selection (const QIntList&, int); - void buttonOk_clicked (void); + public slots: - void buttonCancel_clicked (void); + void buttonOk_clicked (); + + void buttonCancel_clicked (); - void reject (void); + void reject (); - void item_double_clicked (const QModelIndex&); + void item_double_clicked (const QModelIndex&); -private: + private: - QAbstractItemModel *m_model; -}; + QAbstractItemModel *m_model; + }; -class InputDialog : public QDialog -{ - Q_OBJECT + class InputDialog : public QDialog + { + Q_OBJECT - QList input_line; + QList input_line; -public: + public: - InputDialog (base_qobject& oct_qobj, const QStringList& prompt, - const QString& title, const QFloatList& nr, - const QFloatList& nc, const QStringList& defaults); + InputDialog (const QStringList& prompt, + const QString& title, const QFloatList& nr, + const QFloatList& nc, const QStringList& defaults); - ~InputDialog (void) = default; + ~InputDialog () = default; -signals: + signals: - void finish_input (const QStringList&, int); + void finish_input (const QStringList&, int); -public slots: + public slots: - void buttonOk_clicked (void); + void buttonOk_clicked (); - void buttonCancel_clicked (void); + void buttonCancel_clicked (); - void reject (void); -}; + void reject (); + }; -class FileDialog : public QFileDialog -{ - Q_OBJECT + class FileDialog : public QFileDialog + { + Q_OBJECT -public: + public: - FileDialog (base_qobject& oct_qobj, const QStringList& filters, - const QString& title, const QString& filename, - const QString& dirname, const QString& multimode); + FileDialog (const QStringList& filters, + const QString& title, const QString& filename, + const QString& dirname, const QString& multimode); - ~FileDialog (void) = default; + ~FileDialog () = default; -signals: + signals: - void finish_input (const QStringList&, const QString&, int); + void finish_input (const QStringList&, const QString&, int); -private slots: + private slots: - void acceptSelection (void); + void acceptSelection (); - void rejectSelection (void); -}; + void rejectSelection (); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/documentation-bookmarks.cc --- a/libgui/src/documentation-bookmarks.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/documentation-bookmarks.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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,497 +51,495 @@ 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) -{ - setObjectName ("documentation_tab_bookmarks"); + 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"); + + gui_settings settings; + + // Setup the tree view with the bookmarks + m_tree = new QTreeWidget (p); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + m_tree->setContextMenuPolicy (Qt::CustomContextMenu); + m_tree->setSelectionMode (QAbstractItemView::ExtendedSelection); + m_tree->setSortingEnabled (false); + m_tree->setDragEnabled(true); + m_tree->viewport()->setAcceptDrops(true); + m_tree->setDropIndicatorShown(true); + m_tree->setDragDropMode(QAbstractItemView::InternalMove); + m_tree->setColumnCount (1); + m_tree->setHeaderHidden (true); + m_tree->setEditTriggers (QAbstractItemView::EditKeyPressed + | QAbstractItemView::SelectedClicked); - // Setup the tree view with the bookmarks - m_tree = new QTreeWidget (p); + connect (m_tree, &QTreeWidget::customContextMenuRequested, + this, &documentation_bookmarks::ctx_menu); + connect (m_tree, &QTreeWidget::itemDoubleClicked, + this, &documentation_bookmarks::handle_double_click); - m_tree->setContextMenuPolicy (Qt::CustomContextMenu); - m_tree->setSelectionMode (QAbstractItemView::ExtendedSelection); - m_tree->setSortingEnabled (false); - m_tree->setDragEnabled(true); - m_tree->viewport()->setAcceptDrops(true); - m_tree->setDropIndicatorShown(true); - m_tree->setDragDropMode(QAbstractItemView::InternalMove); - m_tree->setColumnCount (1); - m_tree->setHeaderHidden (true); - m_tree->setEditTriggers (QAbstractItemView::EditKeyPressed - | QAbstractItemView::SelectedClicked); + // Define the icons for the tree view + icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirClosedIcon), + QIcon::Normal, QIcon::Off); + icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirOpenIcon), + QIcon::Normal, QIcon::On); + icon_bookmark.addPixmap (style ()->standardPixmap(QStyle::SP_FileIcon)); + + // Setup and read the bookmarkfile + QFileInfo f (settings.fileName ()); + QString f_path = f.absolutePath (); + f.setFile (QDir (f_path), dc_bookmark_file); + m_xbel_file.setFileName (f.absoluteFilePath ()); - connect (m_tree, &QTreeWidget::customContextMenuRequested, - this, &documentation_bookmarks::ctx_menu); - connect (m_tree, &QTreeWidget::itemDoubleClicked, - this, &documentation_bookmarks::handle_double_click); + if (m_xbel_file.exists ()) + { + QString err = read_bookmarks (); + if ( !err.isEmpty ()) + { + err.append (tr ("\nNo documentation bookmarks loaded!")); + QMessageBox::warning (this, + tr ("Octave: Loading Documentation Bookmarks"), + err); + m_xbel_file.close (); + } + } - // Define the icons for the tree view - icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirClosedIcon), - QIcon::Normal, QIcon::Off); - icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirOpenIcon), - QIcon::Normal, QIcon::On); - icon_bookmark.addPixmap (style ()->standardPixmap(QStyle::SP_FileIcon)); - - // Setup and read the bookmarkfile - QFileInfo f (settings->fileName ()); - QString f_path = f.absolutePath (); - f.setFile (QDir (f_path), dc_bookmark_file); - m_xbel_file.setFileName (f.absoluteFilePath ()); + // Setup the filter widget + m_filter_widget = new QWidget (p); + m_filter = new QComboBox (m_filter_widget); - if (m_xbel_file.exists ()) - { - QString err = read_bookmarks (); - if ( !err.isEmpty ()) - { - err.append (tr ("\nNo documentation bookmarks loaded!")); - QMessageBox::warning (this, - tr ("Octave: Loading Documentation Bookmarks"), - err); - m_xbel_file.close (); - } - } + m_filter->setToolTip (tr ("Enter text to search the bookmarks")); + m_filter->setEditable (true); + m_filter->setInsertPolicy (QComboBox::NoInsert); + m_filter->setMaxCount (10); + m_filter->setMaxVisibleItems (10); + m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); + QSizePolicy size_pol (QSizePolicy::Expanding, QSizePolicy::Preferred); + m_filter->setSizePolicy (size_pol); + m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); + + m_filter->addItems (settings.string_list_value (dc_bookmark_filter_mru)); - // Setup the filter widget - m_filter_widget = new QWidget (p); - m_filter = new QComboBox (m_filter_widget); + connect (m_filter, &QComboBox::editTextChanged, + this, &documentation_bookmarks::filter_bookmarks); + connect (m_filter->lineEdit (), &QLineEdit::editingFinished, + this, &documentation_bookmarks::update_filter_history); - m_filter->setToolTip (tr ("Enter text to search the bookmarks")); - m_filter->setEditable (true); - m_filter->setInsertPolicy (QComboBox::NoInsert); - m_filter->setMaxCount (10); - m_filter->setMaxVisibleItems (10); - m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); - QSizePolicy size_pol (QSizePolicy::Expanding, QSizePolicy::Preferred); - m_filter->setSizePolicy (size_pol); - m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); + m_filter_checkbox = new QCheckBox (m_filter_widget); + bool filter_state = settings.bool_value (dc_bookmark_filter_active); + m_filter_checkbox->setChecked (filter_state); + filter_activate (filter_state); - m_filter->addItems (settings->value (dc_bookmark_filter_mru).toStringList ()); + connect (m_filter_checkbox, &QCheckBox::toggled, + this, &documentation_bookmarks::filter_activate); - connect (m_filter, &QComboBox::editTextChanged, - this, &documentation_bookmarks::filter_bookmarks); - connect (m_filter->lineEdit (), &QLineEdit::editingFinished, - this, &documentation_bookmarks::update_filter_history); + QLabel *filter_label = new QLabel (tr ("Filter"), m_filter_widget); + QHBoxLayout *h_box_bm = new QHBoxLayout (m_filter_widget); + h_box_bm->addWidget (filter_label); + h_box_bm->addWidget (m_filter_checkbox); + h_box_bm->addWidget (m_filter); + h_box_bm->setMargin (2); + m_filter_widget->setLayout (h_box_bm); - m_filter_checkbox = new QCheckBox (m_filter_widget); - bool filter_state = settings->value (dc_bookmark_filter_active).toBool (); - m_filter_checkbox->setChecked (filter_state); - filter_activate (filter_state); + m_filter_shown = settings.bool_value (dc_bookmark_filter_shown); + m_filter_widget->setVisible (m_filter_shown); - connect (m_filter_checkbox, &QCheckBox::toggled, - this, &documentation_bookmarks::filter_activate); + // Resulting Layout of this widget + QVBoxLayout *v_box_bm = new QVBoxLayout (this); + v_box_bm->addWidget (m_filter_widget); + v_box_bm->addWidget (m_tree); + setLayout (v_box_bm); + } - QLabel *filter_label = new QLabel (tr ("Filter"), m_filter_widget); - QHBoxLayout *h_box_bm = new QHBoxLayout (m_filter_widget); - h_box_bm->addWidget (filter_label); - h_box_bm->addWidget (m_filter_checkbox); - h_box_bm->addWidget (m_filter); - h_box_bm->setMargin (2); - m_filter_widget->setLayout (h_box_bm); - - m_filter_shown = settings->value (dc_bookmark_filter_shown).toBool (); - m_filter_widget->setVisible (m_filter_shown); + // Slot for adding the current page as a bookmark + void documentation_bookmarks::add_bookmark () + { + QUrl url = m_browser->historyUrl (0); - // Resulting Layout of this widget - QVBoxLayout *v_box_bm = new QVBoxLayout (this); - v_box_bm->addWidget (m_filter_widget); - v_box_bm->addWidget (m_tree); - setLayout (v_box_bm); -} - -// Slot for adding the current page as a bookmark -void documentation_bookmarks::add_bookmark (void) -{ - QUrl url = m_browser->historyUrl (0); + // Check if bookmark already exists and select if yes + QTreeWidgetItemIterator it (m_tree); + while (*it) + { + QUrl url_i = (*it)->data (0, url_role).toUrl (); + if (url == url_i) + { + m_tree->setCurrentItem (*it); + (*it)->setExpanded (true); + return; + } + it++; + } - // Check if bookmark already exists and select if yes - QTreeWidgetItemIterator it (m_tree); - while (*it) - { - QUrl url_i = (*it)->data (0, url_role).toUrl (); - if (url == url_i) - { - m_tree->setCurrentItem (*it); - (*it)->setExpanded (true); - return; - } - it++; - } + // Add the anchor name to the title of the page and add the bookmark + // as top-level-item + QString title = m_doc->title_and_anchor (m_browser->historyTitle (0), url); + add_bookmark (title, url.toString ()); + } - // Add the anchor name to the title of the page and add the bookmark - // as top-level-item - QString title = m_doc->title_and_anchor (m_browser->historyTitle (0), url); - add_bookmark (title, url.toString ()); -} + // Function for actually adding a bookmark to the tree + void documentation_bookmarks::add_bookmark (const QString& title, + const QString& url, + QTreeWidgetItem* item) + { + // Create new bookmark + QTreeWidgetItem *new_item = new QTreeWidgetItem (QStringList (title)); + 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); -// Function for actually adding a bookmark to the tree -void documentation_bookmarks::add_bookmark (const QString& title, - const QString& url, - QTreeWidgetItem* item) -{ - // Create new bookmark - QTreeWidgetItem *new_item = new QTreeWidgetItem (QStringList (title)); - 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); + // Insert as top level or child item + // TODO: Open dialog allowing to select a target folder if this + // bookmark is added manually and not by reading a bookmark file + if (item) + item->addChild (new_item); + else + m_tree->addTopLevelItem (new_item); + } - // Insert as top level or child item - // TODO: Open dialog allowing to select a target folder if this - // bookmark is added manually and not by reading a bookmark file - if (item) - item->addChild (new_item); - else - m_tree->addTopLevelItem (new_item); -} + // Slot for adding a folder from the context menu + void documentation_bookmarks::add_folder (bool) + { + QTreeWidgetItem *parent_item = nullptr; -// Slot for adding a folder from the context menu -void documentation_bookmarks::add_folder (bool) -{ - QTreeWidgetItem *parent_item = nullptr; + if (m_ctx_menu_item) + { + if (m_ctx_menu_item->data (0, tag_role).toInt () == folder_tag) + parent_item = m_ctx_menu_item; + else + { + QTreeWidgetItem *p = m_ctx_menu_item->parent (); + if (p) + parent_item = p; + } + } - if (m_ctx_menu_item) - { - if (m_ctx_menu_item->data (0, tag_role).toInt () == folder_tag) - parent_item = m_ctx_menu_item; - else - { - QTreeWidgetItem *p = m_ctx_menu_item->parent (); - if (p) - parent_item = p; - } - } + QTreeWidgetItem *new_folder = add_folder (tr ("New Folder"), parent_item); - QTreeWidgetItem *new_folder = add_folder (tr ("New Folder"), parent_item); - - m_tree->setCurrentItem (new_folder); - m_tree->editItem (new_folder); -} + m_tree->setCurrentItem (new_folder); + m_tree->editItem (new_folder); + } -// Function for actually adding a folder to the tree -QTreeWidgetItem* documentation_bookmarks::add_folder (const QString& folder, - 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); - new_folder->setChildIndicatorPolicy (QTreeWidgetItem::DontShowIndicatorWhenChildless); - new_folder->setIcon (0, icon_folder); - new_folder->setExpanded (expanded); + // Function for actually adding a folder to the tree + QTreeWidgetItem* documentation_bookmarks::add_folder (const QString& folder, + 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); + new_folder->setChildIndicatorPolicy (QTreeWidgetItem::DontShowIndicatorWhenChildless); + new_folder->setIcon (0, icon_folder); + new_folder->setExpanded (expanded); - // Insert as top level or child item - if (item) - item->addChild (new_folder); - else - m_tree->addTopLevelItem (new_folder); + // Insert as top level or child item + if (item) + item->addChild (new_folder); + else + m_tree->addTopLevelItem (new_folder); - return new_folder; -} + return new_folder; + } -void documentation_bookmarks::filter_bookmarks (const QString& pattern) -{ - QTreeWidgetItemIterator it (m_tree); + void documentation_bookmarks::filter_bookmarks (const QString& pattern) + { + QTreeWidgetItemIterator it (m_tree); - while (*it) - { - if ((*it)->text (0).contains (pattern, Qt::CaseInsensitive)) - { - (*it)->setHidden (false); - (*it)->setExpanded (true); - QTreeWidgetItem *p = (*it)->parent (); - while (p) - { - p->setHidden (false); - p->setExpanded (true); - p = p->parent (); - } - } - else - (*it)->setHidden (true); + while (*it) + { + if ((*it)->text (0).contains (pattern, Qt::CaseInsensitive)) + { + (*it)->setHidden (false); + (*it)->setExpanded (true); + QTreeWidgetItem *p = (*it)->parent (); + while (p) + { + p->setHidden (false); + p->setExpanded (true); + p = p->parent (); + } + } + else + (*it)->setHidden (true); - it++; - } -} + it++; + } + } -void documentation_bookmarks::filter_activate (bool state) -{ - m_filter->setEnabled (state); + void documentation_bookmarks::filter_activate (bool state) + { + m_filter->setEnabled (state); - QString pattern; - if (state) - pattern = m_filter->currentText (); + QString pattern; + if (state) + pattern = m_filter->currentText (); - filter_bookmarks (pattern); -} + filter_bookmarks (pattern); + } -void documentation_bookmarks::update_filter_history (void) -{ - QString text = m_filter->currentText (); // get current text - int index = m_filter->findText (text); // and its actual index + void documentation_bookmarks::update_filter_history () + { + QString text = m_filter->currentText (); // get current text + int index = m_filter->findText (text); // and its actual index - if (index > -1) - m_filter->removeItem (index); // remove if already existing + if (index > -1) + m_filter->removeItem (index); // remove if already existing - m_filter->insertItem (0, text); // (re)insert at beginning - m_filter->setCurrentIndex (0); -} + m_filter->insertItem (0, text); // (re)insert at beginning + m_filter->setCurrentIndex (0); + } -void documentation_bookmarks::handle_double_click (QTreeWidgetItem *item, int) -{ - int tag = item->data (0, tag_role).toInt (); + void documentation_bookmarks::handle_double_click (QTreeWidgetItem *item, int) + { + int tag = item->data (0, tag_role).toInt (); - if (tag == folder_tag) - { - item->setExpanded (! item->isExpanded ()); - return; - } + if (tag == folder_tag) + { + item->setExpanded (! item->isExpanded ()); + return; + } - if (tag == bookmark_tag) - { - QUrl url = item->data (0, url_role).toUrl (); - if (! url.isEmpty ()) - m_browser->setSource (url); - return; - } -} + if (tag == bookmark_tag) + { + QUrl url = item->data (0, url_role).toUrl (); + if (! url.isEmpty ()) + m_browser->setSource (url); + return; + } + } -void documentation_bookmarks::ctx_menu (const QPoint& xpos) -{ - QMenu menu (this); + void documentation_bookmarks::ctx_menu (const QPoint& xpos) + { + QMenu menu (this); - m_ctx_menu_item = m_tree->itemAt (xpos); + m_ctx_menu_item = m_tree->itemAt (xpos); - if (m_ctx_menu_item) - { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + if (m_ctx_menu_item) + { + 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"), - this, &documentation_bookmarks::remove); - menu.addSeparator (); - } + menu.addAction (tr ("&Open"), this, &documentation_bookmarks::open); + menu.addAction (tr ("&Rename"), this, &documentation_bookmarks::edit); + menu.addAction (settings.icon ("window-close"), tr ("Remo&ve"), + this, &documentation_bookmarks::remove); + menu.addSeparator (); + } - menu.addAction (tr ("&Add Folder"), this, - QOverload::of (&documentation_bookmarks::add_folder)); + menu.addAction (tr ("&Add Folder"), this, + QOverload::of (&documentation_bookmarks::add_folder)); - menu.addSeparator (); + menu.addSeparator (); - if (m_filter_shown) - menu.addAction (tr ("Hide &Filter"), - this, &documentation_bookmarks::show_filter); - else - menu.addAction (tr ("Show &Filter"), - this, &documentation_bookmarks::show_filter); + if (m_filter_shown) + menu.addAction (tr ("Hide &Filter"), + this, &documentation_bookmarks::show_filter); + else + menu.addAction (tr ("Show &Filter"), + this, &documentation_bookmarks::show_filter); - menu.exec (m_tree->mapToGlobal (xpos)); -} + menu.exec (m_tree->mapToGlobal (xpos)); + } -void documentation_bookmarks::open (bool) -{ - QList items = m_tree->selectedItems (); + void documentation_bookmarks::open (bool) + { + QList items = m_tree->selectedItems (); - if (items.size () > 0) - handle_double_click (items.at (0)); -} + if (items.size () > 0) + handle_double_click (items.at (0)); + } -void documentation_bookmarks::edit (bool) -{ - QList items = m_tree->selectedItems (); + void documentation_bookmarks::edit (bool) + { + QList items = m_tree->selectedItems (); - if (items.size () > 0) - m_tree->editItem (items.at (0)); -} + if (items.size () > 0) + m_tree->editItem (items.at (0)); + } -void documentation_bookmarks::remove (bool) -{ - QList items = m_tree->selectedItems (); + void documentation_bookmarks::remove (bool) + { + QList items = m_tree->selectedItems (); - for (auto it = items.begin () ; it != items.end (); it++) - { - if (*it) - m_tree->takeTopLevelItem ( - m_tree->indexOfTopLevelItem (*it)); - } -} + for (auto it = items.begin () ; it != items.end (); it++) + { + if (*it) + m_tree->takeTopLevelItem (m_tree->indexOfTopLevelItem (*it)); + } + } -void documentation_bookmarks::show_filter (bool) -{ - m_filter_shown = ! m_filter_shown; - m_filter_widget->setVisible (m_filter_shown); -} + void documentation_bookmarks::show_filter (bool) + { + m_filter_shown = ! m_filter_shown; + m_filter_widget->setVisible (m_filter_shown); + } -void documentation_bookmarks::save_settings (gui_settings *settings) -{ - // Write the bookmarks to the xbel-file - write_bookmarks (); + 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); + // Store settings + 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); + QStringList mru; + for (int i = 0; i < m_filter->count (); i++) + mru.append (m_filter->itemText (i)); + settings.setValue (dc_bookmark_filter_mru.settings_key (), mru); - settings->sync (); -} + settings.sync (); + } -void documentation_bookmarks::write_bookmarks (void) -{ - 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())); - return; - } + 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())); + return; + } - QXmlStreamWriter xml_writer (&m_xbel_file); - xml_writer.setAutoFormatting (true); + QXmlStreamWriter xml_writer (&m_xbel_file); + xml_writer.setAutoFormatting (true); - xml_writer.writeStartDocument (); - xml_writer.writeDTD (dc_xbel_doctype); - xml_writer.writeStartElement (dc_xbel_name_format); - xml_writer.writeAttribute (dc_xbel_attr_version, dc_xbel_value_version); + xml_writer.writeStartDocument (); + xml_writer.writeDTD (dc_xbel_doctype); + xml_writer.writeStartElement (dc_xbel_name_format); + xml_writer.writeAttribute (dc_xbel_attr_version, dc_xbel_value_version); - for (int i = 0; i < m_tree->topLevelItemCount(); i++) - write_tree_item (&xml_writer, m_tree->topLevelItem (i)); + for (int i = 0; i < m_tree->topLevelItemCount(); i++) + write_tree_item (&xml_writer, m_tree->topLevelItem (i)); - xml_writer.writeEndDocument(); + xml_writer.writeEndDocument(); - m_xbel_file.flush (); - m_xbel_file.close (); -} + m_xbel_file.flush (); + m_xbel_file.close (); + } -void documentation_bookmarks::write_tree_item (QXmlStreamWriter* xml_writer, - const QTreeWidgetItem *item) -{ - switch (item->data (0, tag_role).toInt ()) - { - case folder_tag: - xml_writer->writeStartElement (dc_xbel_name_folder); - xml_writer->writeAttribute (dc_xbel_attr_folded, - item->isExpanded () ? dc_xbel_value_no : dc_xbel_value_yes); - xml_writer->writeTextElement (dc_xbel_name_title, item->text(0)); - for (int i = 0; i < item->childCount (); i++) - write_tree_item (xml_writer, item->child (i)); - xml_writer->writeEndElement (); - break; + void documentation_bookmarks::write_tree_item (QXmlStreamWriter* xml_writer, + const QTreeWidgetItem *item) + { + switch (item->data (0, tag_role).toInt ()) + { + case folder_tag: + xml_writer->writeStartElement (dc_xbel_name_folder); + xml_writer->writeAttribute (dc_xbel_attr_folded, + item->isExpanded () ? dc_xbel_value_no : dc_xbel_value_yes); + xml_writer->writeTextElement (dc_xbel_name_title, item->text(0)); + for (int i = 0; i < item->childCount (); i++) + write_tree_item (xml_writer, item->child (i)); + xml_writer->writeEndElement (); + break; - case bookmark_tag: - xml_writer->writeStartElement (dc_xbel_name_bookmark); - xml_writer->writeAttribute (dc_xbel_attr_href, item->data (0, url_role).toString ()); - xml_writer->writeTextElement (dc_xbel_name_title, item->text (0)); - xml_writer->writeEndElement (); - break; - } -} + case bookmark_tag: + xml_writer->writeStartElement (dc_xbel_name_bookmark); + xml_writer->writeAttribute (dc_xbel_attr_href, item->data (0, url_role).toString ()); + xml_writer->writeTextElement (dc_xbel_name_title, item->text (0)); + xml_writer->writeEndElement (); + break; + } + } -QString documentation_bookmarks::read_bookmarks (void) -{ - QString error_message; + QString documentation_bookmarks::read_bookmarks () + { + QString error_message; - // Check the file - 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()); - return error_message; - } + // Check the file + 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()); + return error_message; + } - QXmlStreamReader xml_reader (&m_xbel_file); + QXmlStreamReader xml_reader (&m_xbel_file); - if (! xml_reader.readNextStartElement ()) - { - error_message = tr ("No start element found in %1.\n" - "Invalid bookmark file?") - .arg (m_xbel_file.fileName ()); - return error_message; - } + if (! xml_reader.readNextStartElement ()) + { + error_message = tr ("No start element found in %1.\n" + "Invalid bookmark file?") + .arg (m_xbel_file.fileName ()); + return error_message; + } - if (xml_reader.name() != dc_xbel_name_format - || xml_reader.attributes ().value (dc_xbel_attr_version) != dc_xbel_value_version) - { - error_message = tr ("The file\n" - "%1\n" - "is not a valid XBEL file version 1.0.") - .arg (m_xbel_file.fileName ()); - return error_message; - } + if (xml_reader.name() != dc_xbel_name_format + || xml_reader.attributes ().value (dc_xbel_attr_version) != dc_xbel_value_version) + { + error_message = tr ("The file\n" + "%1\n" + "is not a valid XBEL file version 1.0.") + .arg (m_xbel_file.fileName ()); + return error_message; + } - // Read the elements from the file - while (xml_reader.readNextStartElement ()) - { - if (xml_reader.name () == dc_xbel_name_folder) - read_next_item (&xml_reader, folder_tag); - else if (xml_reader.name () == dc_xbel_name_bookmark) - read_next_item (&xml_reader, bookmark_tag); - else - xml_reader.skipCurrentElement (); - } + // Read the elements from the file + while (xml_reader.readNextStartElement ()) + { + if (xml_reader.name () == dc_xbel_name_folder) + read_next_item (&xml_reader, folder_tag); + else if (xml_reader.name () == dc_xbel_name_bookmark) + read_next_item (&xml_reader, bookmark_tag); + else + xml_reader.skipCurrentElement (); + } - m_xbel_file.close (); + m_xbel_file.close (); - return error_message; -} + return error_message; + } -void documentation_bookmarks::read_next_item (QXmlStreamReader *xml_reader, - item_tag tag, QTreeWidgetItem *item) -{ - QString title (tr ("Unknown title")); - if (tag == folder_tag) - { - // Next item is a folder, which might also have children - bool expanded = (xml_reader->attributes().value (dc_xbel_attr_folded) == dc_xbel_value_no); + void documentation_bookmarks::read_next_item (QXmlStreamReader *xml_reader, + item_tag tag, QTreeWidgetItem *item) + { + QString title (tr ("Unknown title")); + if (tag == folder_tag) + { + // Next item is a folder, which might also have children + bool expanded = (xml_reader->attributes().value (dc_xbel_attr_folded) == dc_xbel_value_no); + + QTreeWidgetItem *new_folder = add_folder (title, item, expanded); - QTreeWidgetItem *new_folder = add_folder (title, item, expanded); - - // Check elements of this folder for title and for recursively - // adding sub-items - while (xml_reader->readNextStartElement ()) - { - if (xml_reader->name () == dc_xbel_name_title) - { + // Check elements of this folder for title and for recursively + // adding sub-items + while (xml_reader->readNextStartElement ()) + { + if (xml_reader->name () == dc_xbel_name_title) + { + title = xml_reader->readElementText(); + new_folder->setText (0, title); + } + else if (xml_reader->name () == dc_xbel_name_folder) + read_next_item (xml_reader, folder_tag, new_folder); + else if (xml_reader->name () == dc_xbel_name_bookmark) + read_next_item (xml_reader, bookmark_tag, new_folder); + else + xml_reader->skipCurrentElement (); + } + } + else if (tag == bookmark_tag) + { + // Next item is a bookmark, without children + QString url = xml_reader->attributes().value (dc_xbel_attr_href).toString (); + while (xml_reader->readNextStartElement ()) + { + if (xml_reader->name() == dc_xbel_name_title) title = xml_reader->readElementText(); - new_folder->setText (0, title); - } - else if (xml_reader->name () == dc_xbel_name_folder) - read_next_item (xml_reader, folder_tag, new_folder); - else if (xml_reader->name () == dc_xbel_name_bookmark) - read_next_item (xml_reader, bookmark_tag, new_folder); - else - xml_reader->skipCurrentElement (); - } - } - else if (tag == bookmark_tag) - { - // Next item is a bookmark, without children - QString url = xml_reader->attributes().value (dc_xbel_attr_href).toString (); - while (xml_reader->readNextStartElement ()) - { - if (xml_reader->name() == dc_xbel_name_title) - title = xml_reader->readElementText(); - else - xml_reader->skipCurrentElement (); - } - add_bookmark (title, url, item); - } -} + else + xml_reader->skipCurrentElement (); + } + add_bookmark (title, url, item); + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/documentation-bookmarks.h --- a/libgui/src/documentation-bookmarks.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/documentation-bookmarks.h Mon Jan 30 18:36:03 2023 +0100 @@ -28,96 +28,94 @@ #include #include +#include #include #include #include "documentation.h" -#include "octave-qobject.h" OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class documentation; + class documentation; -class documentation_bookmarks : public QWidget -{ - Q_OBJECT + class documentation_bookmarks : public QWidget + { + Q_OBJECT + + public: -public: + documentation_bookmarks (documentation *doc, + documentation_browser *browser, + QWidget *p = nullptr); - documentation_bookmarks ( - documentation *doc, documentation_browser *browser, - base_qobject& oct_qobj, QWidget *p = nullptr); + ~documentation_bookmarks () = default; - ~documentation_bookmarks (void) = default; - -public slots: + public slots: - void add_bookmark (void); - void add_folder (bool); - void save_settings (gui_settings *settings); + void add_bookmark (); + void add_folder (bool); + void save_settings (); -private slots: + private slots: - void filter_bookmarks (const QString& pattern); - void filter_activate (bool state); - void update_filter_history (void); - void handle_double_click (QTreeWidgetItem *item, int col = 0); - void ctx_menu (const QPoint& xpos); - void open (bool); - void edit (bool); - void remove (bool); - void show_filter (bool); + void filter_bookmarks (const QString& pattern); + void filter_activate (bool state); + void update_filter_history (); + void handle_double_click (QTreeWidgetItem *item, int col = 0); + void ctx_menu (const QPoint& xpos); + void open (bool); + void edit (bool); + void remove (bool); + void show_filter (bool); -private: + private: - enum item_role + enum item_role { url_role = Qt::UserRole, tag_role = Qt::UserRole + 1 }; - enum item_tag + enum item_tag { bookmark_tag, folder_tag }; - void add_bookmark (const QString& title, const QString& url, - QTreeWidgetItem *item = nullptr); - QTreeWidgetItem* add_folder (const QString& folder, - QTreeWidgetItem *item = nullptr, - bool expanded = true); + void add_bookmark (const QString& title, const QString& url, + QTreeWidgetItem *item = nullptr); + QTreeWidgetItem* add_folder (const QString& folder, + QTreeWidgetItem *item = nullptr, + 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) - */ - void write_bookmarks (void); - void write_tree_item (QXmlStreamWriter *xml_writer, - const QTreeWidgetItem *item); - QString read_bookmarks (void); - void read_next_item (QXmlStreamReader *xml_writer, item_tag tag, - QTreeWidgetItem *item = nullptr); + /*! + 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 write_tree_item (QXmlStreamWriter *xml_writer, + const QTreeWidgetItem *item); + 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; + documentation *m_doc; + documentation_browser *m_browser; - QComboBox *m_filter; - QTreeWidget *m_tree; + QComboBox *m_filter; + QTreeWidget *m_tree; - QTreeWidgetItem *m_ctx_menu_item; + QTreeWidgetItem *m_ctx_menu_item; - QIcon icon_folder; - QIcon icon_bookmark; + QIcon icon_folder; + QIcon icon_bookmark; - QWidget *m_filter_widget; - QCheckBox *m_filter_checkbox; - bool m_filter_shown; + QWidget *m_filter_widget; + QCheckBox *m_filter_checkbox; + bool m_filter_shown; - QFile m_xbel_file; -}; + QFile m_xbel_file; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/documentation-dock-widget.cc --- a/libgui/src/documentation-dock-widget.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/documentation-dock-widget.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,65 +33,64 @@ 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)) -{ - set_title (tr ("Documentation")); - setStatusTip (tr ("See the documentation for help.")); + 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.")); - setWidget (m_docs); + setWidget (m_docs); - if (! p) - make_window (); -} + if (! p) + make_window (); + } -void documentation_dock_widget::notice_settings (const gui_settings *settings) -{ - m_docs->notice_settings (settings); -} + void documentation_dock_widget::notice_settings () + { + m_docs->notice_settings (); + } -void documentation_dock_widget::save_settings (void) -{ - m_docs->save_settings (); - octave_dock_widget::save_settings (); -} + void documentation_dock_widget::save_settings () + { + m_docs->save_settings (); + octave_dock_widget::save_settings (); + } -void documentation_dock_widget::copyClipboard (void) -{ - m_docs->copyClipboard (); -} + void documentation_dock_widget::copyClipboard () + { + m_docs->copyClipboard (); + } -void documentation_dock_widget::pasteClipboard (void) -{ - m_docs->pasteClipboard (); -} + void documentation_dock_widget::pasteClipboard () + { + m_docs->pasteClipboard (); + } -void documentation_dock_widget::selectAll (void) -{ - m_docs->selectAll (); -} + void documentation_dock_widget::selectAll () + { + m_docs->selectAll (); + } -void documentation_dock_widget::showDoc (const QString& name) -{ - // show the doc pane without focus for carrying on typing in the console - if (! isVisible ()) - setVisible (true); + void documentation_dock_widget::showDoc (const QString& name) + { + // show the doc pane without focus for carrying on typing in the console + if (! isVisible ()) + setVisible (true); - raise (); + raise (); - m_docs->load_ref (name); -} + m_docs->load_ref (name); + } -void documentation_dock_widget::registerDoc (const QString& name) -{ - m_docs->registerDoc (name); -} + void documentation_dock_widget::registerDoc (const QString& name) + { + m_docs->registerDoc (name); + } -void documentation_dock_widget::unregisterDoc (const QString& name) -{ - m_docs->unregisterDoc (name); -} + void documentation_dock_widget::unregisterDoc (const QString& name) + { + m_docs->unregisterDoc (name); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/documentation-dock-widget.h --- a/libgui/src/documentation-dock-widget.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/documentation-dock-widget.h Mon Jan 30 18:36:03 2023 +0100 @@ -31,35 +31,33 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class documentation_dock_widget : public octave_dock_widget + { + Q_OBJECT -class documentation_dock_widget : public octave_dock_widget -{ - Q_OBJECT + public: -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: + 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); - void unregisterDoc (const QString& name); + void showDoc (const QString& name); + void registerDoc (const QString& name); + void unregisterDoc (const QString& name); -private: + private: - documentation *m_docs; -}; + documentation *m_docs; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/documentation.cc --- a/libgui/src/documentation.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/documentation.cc Mon Jan 30 18:36:03 2023 +0100 @@ -49,15 +49,16 @@ #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" @@ -65,1046 +66,1047 @@ OCTAVE_BEGIN_NAMESPACE(octave) -// 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)) -{ - // Get original collection - QString collection = getenv ("OCTAVE_QTHELP_COLLECTION"); - if (collection.isEmpty ()) - collection = QString::fromStdString (config::oct_doc_dir () - + sys::file_ops::dir_sep_str () - + "octave_interpreter.qhc"); + // The documentation splitter, which is the main widget + // of the doc dock widget + 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"); + if (collection.isEmpty ()) + collection = QString::fromStdString (config::oct_doc_dir () + + sys::file_ops::dir_sep_str () + + "octave_interpreter.qhc"); - // Setup the help engine with the original collection, use a writable copy - // of the original collection and load the help data - m_help_engine = new QHelpEngine (collection, this); + // Setup the help engine with the original collection, use a writable copy + // of the original collection and load the help data + m_help_engine = new QHelpEngine (collection, this); - // Mark help as readonly to avoid error if collection file is stored in a - // readonly location - m_help_engine->setProperty ("_q_readonly", - QVariant::fromValue (true)); + // Mark help as readonly to avoid error if collection file is stored in a + // readonly location + m_help_engine->setProperty ("_q_readonly", + QVariant::fromValue (true)); - QString tmpdir = QString::fromStdString (sys::env::get_temp_directory ()); - m_collection - = QString::fromStdString (sys::tempnam (tmpdir.toStdString (), - "oct-qhelp-")); + QString tmpdir = QString::fromStdString (sys::env::get_temp_directory ()); + m_collection + = QString::fromStdString (sys::tempnam (tmpdir.toStdString (), + "oct-qhelp-")); - if (m_help_engine->copyCollectionFile (m_collection)) - m_help_engine->setCollectionFile (m_collection); - else + if (m_help_engine->copyCollectionFile (m_collection)) + m_help_engine->setCollectionFile (m_collection); + else #ifdef ENABLE_DOCS - // FIXME: Perhaps a better way to do this would be to keep a count - // in the GUI preferences file. After issuing this warning 3 times - // it would be disabled. The count would need to be reset when a new - // version of Octave is installed. - QMessageBox::warning (this, tr ("Octave Documentation"), - tr ("Could not copy help collection to temporary\n" - "file. Search capabilities may be affected.\n" - "%1").arg (m_help_engine->error ())); + // FIXME: Perhaps a better way to do this would be to keep a count + // in the GUI preferences file. After issuing this warning 3 times + // it would be disabled. The count would need to be reset when a new + // version of Octave is installed. + QMessageBox::warning (this, tr ("Octave Documentation"), + tr ("Could not copy help collection to temporary\n" + "file. Search capabilities may be affected.\n" + "%1").arg (m_help_engine->error ())); #endif - connect(m_help_engine->searchEngine (), SIGNAL(indexingFinished ()), - this, SLOT(load_index ())); - connect(m_help_engine, SIGNAL(setupFinished ()), - m_help_engine->searchEngine (), SLOT(reindexDocumentation ())); + connect(m_help_engine->searchEngine (), SIGNAL(indexingFinished ()), + this, SLOT(load_index ())); + connect(m_help_engine, SIGNAL(setupFinished ()), + m_help_engine->searchEngine (), SLOT(reindexDocumentation ())); - if (! m_help_engine->setupData()) - { + if (! m_help_engine->setupData()) + { #ifdef ENABLE_DOCS - QMessageBox::warning (this, tr ("Octave Documentation"), - tr ("Could not setup the data required for the\n" - "documentation viewer. Only help texts in\n" - "the Command Window will be available.")); + QMessageBox::warning (this, tr ("Octave Documentation"), + tr ("Could not setup the data required for the\n" + "documentation viewer. Only help texts in\n" + "the Command Window will be available.")); #endif - disconnect (m_help_engine, 0, 0, 0); + disconnect (m_help_engine, 0, 0, 0); + + delete m_help_engine; + m_help_engine = nullptr; + } - delete m_help_engine; - m_help_engine = nullptr; - } + // The browser + QWidget *browser_find = new QWidget (this); + m_doc_browser = new documentation_browser (m_help_engine, browser_find); + connect (m_doc_browser, &documentation_browser::cursorPositionChanged, + this, &documentation::handle_cursor_position_change); - // The browser - QWidget *browser_find = new QWidget (this); - m_doc_browser = new documentation_browser (m_help_engine, browser_find); - connect (m_doc_browser, &documentation_browser::cursorPositionChanged, - this, &documentation::handle_cursor_position_change); + // Tool bar + construct_tool_bar (); - // Tool bar - construct_tool_bar (); + // Find bar + QWidget *find_footer = new QWidget (browser_find); + QLabel *find_label = new QLabel (tr ("Find:"), find_footer); + m_find_line_edit = new QLineEdit (find_footer); + connect (m_find_line_edit, &QLineEdit::returnPressed, + this, [=] () { find (); }); + connect (m_find_line_edit, &QLineEdit::textEdited, + this, &documentation::find_forward_from_anchor); + QToolButton *forward_button = new QToolButton (find_footer); + forward_button->setText (tr ("Search forward")); + forward_button->setToolTip (tr ("Search forward")); - // Find bar - QWidget *find_footer = new QWidget (browser_find); - QLabel *find_label = new QLabel (tr ("Find:"), find_footer); - m_find_line_edit = new QLineEdit (find_footer); - connect (m_find_line_edit, &QLineEdit::returnPressed, - this, [=] () { find (); }); - connect (m_find_line_edit, &QLineEdit::textEdited, - this, &documentation::find_forward_from_anchor); - 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")); - 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")); - connect (backward_button, &QToolButton::pressed, - this, &documentation::find_backward); - QHBoxLayout *h_box_find_footer = new QHBoxLayout (find_footer); - h_box_find_footer->addWidget (find_label); - 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); - find_footer->setLayout (h_box_find_footer); + gui_settings settings; - QVBoxLayout *v_box_browser_find = new QVBoxLayout (browser_find); - v_box_browser_find->addWidget (m_tool_bar); - v_box_browser_find->addWidget (m_doc_browser); - v_box_browser_find->addWidget (find_footer); - browser_find->setLayout (v_box_browser_find); + 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 (settings.icon ("go-up")); + connect (backward_button, &QToolButton::pressed, + this, &documentation::find_backward); + QHBoxLayout *h_box_find_footer = new QHBoxLayout (find_footer); + h_box_find_footer->addWidget (find_label); + 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); + find_footer->setLayout (h_box_find_footer); - notice_settings (rmgr.get_settings ()); + QVBoxLayout *v_box_browser_find = new QVBoxLayout (browser_find); + v_box_browser_find->addWidget (m_tool_bar); + v_box_browser_find->addWidget (m_doc_browser); + v_box_browser_find->addWidget (find_footer); + browser_find->setLayout (v_box_browser_find); + + notice_settings (); - m_findnext_shortcut->setContext (Qt::WidgetWithChildrenShortcut); - connect (m_findnext_shortcut, &QShortcut::activated, - this, [=] () { find (); }); - m_findprev_shortcut->setContext (Qt::WidgetWithChildrenShortcut); - connect (m_findprev_shortcut, &QShortcut::activated, - this, &documentation::find_backward); + m_findnext_shortcut->setContext (Qt::WidgetWithChildrenShortcut); + connect (m_findnext_shortcut, &QShortcut::activated, + this, [=] () { find (); }); + m_findprev_shortcut->setContext (Qt::WidgetWithChildrenShortcut); + connect (m_findprev_shortcut, &QShortcut::activated, + this, &documentation::find_backward); - find_footer->hide (); - m_search_anchor_position = 0; + find_footer->hide (); + m_search_anchor_position = 0; - if (m_help_engine) - { + if (m_help_engine) + { #if defined (HAVE_NEW_QHELPINDEXWIDGET_API) - // Starting in Qt 5.15, help engine uses filters instead of old API - m_help_engine->setUsesFilterEngine (true); + // Starting in Qt 5.15, help engine uses filters instead of old API + m_help_engine->setUsesFilterEngine (true); #endif - // Layout contents, index and search - QTabWidget *navi = new QTabWidget (this); - navi->setTabsClosable (false); - navi->setMovable (true); + // Layout contents, index and search + QTabWidget *navi = new QTabWidget (this); + navi->setTabsClosable (false); + navi->setMovable (true); - // Contents - QHelpContentWidget *content = m_help_engine->contentWidget (); - content->setObjectName ("documentation_tab_contents"); - navi->addTab (content, tr ("Contents")); + // Contents + QHelpContentWidget *content = m_help_engine->contentWidget (); + content->setObjectName ("documentation_tab_contents"); + navi->addTab (content, tr ("Contents")); - connect (m_help_engine->contentWidget (), - &QHelpContentWidget::linkActivated, - m_doc_browser, [=] (const QUrl& url) { - m_doc_browser->handle_index_clicked (url); }); + connect (m_help_engine->contentWidget (), + &QHelpContentWidget::linkActivated, + m_doc_browser, [=] (const QUrl& url) { + m_doc_browser->handle_index_clicked (url); }); - // Index - QHelpIndexWidget *index = m_help_engine->indexWidget (); + // Index + QHelpIndexWidget *index = m_help_engine->indexWidget (); - m_filter = new QComboBox (this); - m_filter->setToolTip (tr ("Enter text to search the indices")); - m_filter->setEditable (true); - m_filter->setInsertPolicy (QComboBox::NoInsert); - m_filter->setMaxCount (10); - m_filter->setMaxVisibleItems (10); - m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); - QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); - m_filter->setSizePolicy (sizePol); - m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); - QLabel *filter_label = new QLabel (tr ("Search")); + m_filter = new QComboBox (this); + m_filter->setToolTip (tr ("Enter text to search the indices")); + m_filter->setEditable (true); + m_filter->setInsertPolicy (QComboBox::NoInsert); + m_filter->setMaxCount (10); + m_filter->setMaxVisibleItems (10); + m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); + QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); + m_filter->setSizePolicy (sizePol); + m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); + QLabel *filter_label = new QLabel (tr ("Search")); - QWidget *filter_all = new QWidget (navi); - 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); - filter_all->setLayout (h_box_index); + QWidget *filter_all = new QWidget (navi); + 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); + filter_all->setLayout (h_box_index); - QWidget *index_all = new QWidget (navi); - index_all->setObjectName ("documentation_tab_index"); - QVBoxLayout *v_box_index = new QVBoxLayout (index_all); - v_box_index->addWidget (filter_all); - v_box_index->addWidget (index); - index_all->setLayout (v_box_index); + QWidget *index_all = new QWidget (navi); + index_all->setObjectName ("documentation_tab_index"); + QVBoxLayout *v_box_index = new QVBoxLayout (index_all); + v_box_index->addWidget (filter_all); + v_box_index->addWidget (index); + index_all->setLayout (v_box_index); - navi->addTab (index_all, tr ("Function Index")); + navi->addTab (index_all, tr ("Function Index")); #if defined (HAVE_NEW_QHELPINDEXWIDGET_API) - connect (m_help_engine->indexWidget (), - &QHelpIndexWidget::documentActivated, - this, [=] (const QHelpLink &link) { - m_doc_browser->handle_index_clicked (link.url); }); + connect (m_help_engine->indexWidget (), + &QHelpIndexWidget::documentActivated, + this, [=] (const QHelpLink &link) { + m_doc_browser->handle_index_clicked (link.url); }); #else - connect (m_help_engine->indexWidget (), - &QHelpIndexWidget::linkActivated, - m_doc_browser, &documentation_browser::handle_index_clicked); + connect (m_help_engine->indexWidget (), + &QHelpIndexWidget::linkActivated, + m_doc_browser, &documentation_browser::handle_index_clicked); #endif - connect (m_filter, &QComboBox::editTextChanged, - this, &documentation::filter_update); + connect (m_filter, &QComboBox::editTextChanged, + this, &documentation::filter_update); - connect (m_filter->lineEdit (), &QLineEdit::editingFinished, - this, &documentation::filter_update_history); + connect (m_filter->lineEdit (), &QLineEdit::editingFinished, + this, &documentation::filter_update_history); - // Bookmarks (own class) - m_bookmarks - = new documentation_bookmarks (this, m_doc_browser, m_octave_qobj, navi); - navi->addTab (m_bookmarks, tr ("Bookmarks")); + // Bookmarks (own class) + m_bookmarks = new documentation_bookmarks (this, m_doc_browser, navi); + navi->addTab (m_bookmarks, tr ("Bookmarks")); - connect (m_action_bookmark, &QAction::triggered, - m_bookmarks, [=] () { m_bookmarks->add_bookmark (); }); + connect (m_action_bookmark, &QAction::triggered, + m_bookmarks, [=] () { m_bookmarks->add_bookmark (); }); - // Search - QHelpSearchEngine *search_engine = m_help_engine->searchEngine (); - QHelpSearchQueryWidget *search = search_engine->queryWidget (); - QHelpSearchResultWidget *result = search_engine->resultWidget (); - QWidget *search_all = new QWidget (navi); - QVBoxLayout *v_box_search = new QVBoxLayout (search_all); - v_box_search->addWidget (search); - v_box_search->addWidget (result); - search_all->setLayout (v_box_search); - search_all->setObjectName ("documentation_tab_search"); - navi->addTab (search_all, tr ("Search")); + // Search + QHelpSearchEngine *search_engine = m_help_engine->searchEngine (); + QHelpSearchQueryWidget *search = search_engine->queryWidget (); + QHelpSearchResultWidget *result = search_engine->resultWidget (); + QWidget *search_all = new QWidget (navi); + QVBoxLayout *v_box_search = new QVBoxLayout (search_all); + v_box_search->addWidget (search); + v_box_search->addWidget (result); + search_all->setLayout (v_box_search); + search_all->setObjectName ("documentation_tab_search"); + navi->addTab (search_all, tr ("Search")); - connect (search, &QHelpSearchQueryWidget::search, - this, &documentation::global_search); + connect (search, &QHelpSearchQueryWidget::search, + this, &documentation::global_search); - connect (search_engine, &QHelpSearchEngine::searchingStarted, - this, &documentation::global_search_started); - connect (search_engine, &QHelpSearchEngine::searchingFinished, - this, &documentation::global_search_finished); + connect (search_engine, &QHelpSearchEngine::searchingStarted, + this, &documentation::global_search_started); + connect (search_engine, &QHelpSearchEngine::searchingFinished, + this, &documentation::global_search_finished); - connect (search_engine->resultWidget (), - &QHelpSearchResultWidget::requestShowLink, - this, &documentation::handle_search_result_clicked); + connect (search_engine->resultWidget (), + &QHelpSearchResultWidget::requestShowLink, + this, &documentation::handle_search_result_clicked); - // Fill the splitter - insertWidget (0, navi); - insertWidget (1, browser_find); - setStretchFactor (1, 1); - } -} + // Fill the splitter + insertWidget (0, navi); + insertWidget (1, browser_find); + setStretchFactor (1, 1); + } + } -documentation::~documentation (void) -{ - // Cleanup temporary file and directory - QFile file (m_collection); - if (file.exists ()) - { - QFileInfo finfo (file); - QString bname = finfo.fileName (); - QDir dir = finfo.absoluteDir (); - dir.setFilter (QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden); - QStringList namefilter; - namefilter.append ("*" + bname + "*"); - for (const auto& fi : dir.entryInfoList (namefilter)) - { - std::string file_name = fi.absoluteFilePath ().toStdString (); - sys::recursive_rmdir (file_name); - } + documentation::~documentation () + { + // Cleanup temporary file and directory + QFile file (m_collection); + if (file.exists ()) + { + QFileInfo finfo (file); + QString bname = finfo.fileName (); + QDir dir = finfo.absoluteDir (); + dir.setFilter (QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden); + QStringList namefilter; + namefilter.append ("*" + bname + "*"); + for (const auto& fi : dir.entryInfoList (namefilter)) + { + std::string file_name = fi.absoluteFilePath ().toStdString (); + sys::recursive_rmdir (file_name); + } - file.remove(); - } -} + file.remove(); + } + } -QAction * documentation::add_action (const QIcon& icon, const QString& text, - const char *member, QWidget *receiver, - QToolBar *tool_bar) -{ - QAction *a; - QWidget *r = this; - if (receiver != nullptr) - r = receiver; + QAction * documentation::add_action (const QIcon& icon, const QString& text, + const char *member, QWidget *receiver, + QToolBar *tool_bar) + { + QAction *a; + QWidget *r = this; + if (receiver != nullptr) + r = receiver; - a = new QAction (icon, text, this); + a = new QAction (icon, text, this); - if (member) - connect (a, SIGNAL (triggered ()), r, member); + if (member) + connect (a, SIGNAL (triggered ()), r, member); - if (tool_bar) - tool_bar->addAction (a); + if (tool_bar) + tool_bar->addAction (a); - m_doc_widget->addAction (a); // important for shortcut context - a->setShortcutContext (Qt::WidgetWithChildrenShortcut); + m_doc_widget->addAction (a); // important for shortcut context + a->setShortcutContext (Qt::WidgetWithChildrenShortcut); + + return a; + } - return a; -} + void documentation::construct_tool_bar () + { + // Home, Previous, Next + gui_settings settings; -void documentation::construct_tool_bar (void) -{ - // Home, Previous, Next - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - m_action_go_home - = add_action (rmgr.icon ("go-home"), tr ("Go home"), SLOT (home (void)), - m_doc_browser, m_tool_bar); + m_action_go_home + = 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); - m_action_go_prev->setEnabled (false); + m_action_go_prev + = 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 - QToolButton *popdown_button_prev_pages = new QToolButton (); - popdown_button_prev_pages->setToolTip (tr ("Previous pages")); - popdown_button_prev_pages->setMenu (m_prev_pages_menu); - popdown_button_prev_pages->setPopupMode (QToolButton::InstantPopup); - popdown_button_prev_pages->setToolButtonStyle (Qt::ToolButtonTextOnly); - popdown_button_prev_pages->setCheckable (false); - popdown_button_prev_pages->setArrowType(Qt::DownArrow); - m_tool_bar->addWidget (popdown_button_prev_pages); + // popdown menu with prev pages files + QToolButton *popdown_button_prev_pages = new QToolButton (); + popdown_button_prev_pages->setToolTip (tr ("Previous pages")); + popdown_button_prev_pages->setMenu (m_prev_pages_menu); + popdown_button_prev_pages->setPopupMode (QToolButton::InstantPopup); + popdown_button_prev_pages->setToolButtonStyle (Qt::ToolButtonTextOnly); + popdown_button_prev_pages->setCheckable (false); + popdown_button_prev_pages->setArrowType(Qt::DownArrow); + 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); - m_action_go_next->setEnabled (false); + m_action_go_next + = 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 - QToolButton *popdown_button_next_pages = new QToolButton (); - popdown_button_next_pages->setToolTip (tr ("Next pages")); - popdown_button_next_pages->setMenu (m_next_pages_menu); - popdown_button_next_pages->setPopupMode (QToolButton::InstantPopup); - popdown_button_next_pages->setToolButtonStyle (Qt::ToolButtonTextOnly); - popdown_button_next_pages->setArrowType(Qt::DownArrow); - m_tool_bar->addWidget (popdown_button_next_pages); + // popdown menu with prev pages files + QToolButton *popdown_button_next_pages = new QToolButton (); + popdown_button_next_pages->setToolTip (tr ("Next pages")); + popdown_button_next_pages->setMenu (m_next_pages_menu); + popdown_button_next_pages->setPopupMode (QToolButton::InstantPopup); + popdown_button_next_pages->setToolButtonStyle (Qt::ToolButtonTextOnly); + popdown_button_next_pages->setArrowType(Qt::DownArrow); + m_tool_bar->addWidget (popdown_button_next_pages); - connect (m_doc_browser, &documentation_browser::backwardAvailable, - m_action_go_prev, &QAction::setEnabled); - connect (m_doc_browser, &documentation_browser::backwardAvailable, - popdown_button_prev_pages, &QToolButton::setEnabled); - connect (m_doc_browser, &documentation_browser::forwardAvailable, - m_action_go_next, &QAction::setEnabled); - connect (m_doc_browser, &documentation_browser::forwardAvailable, - popdown_button_next_pages, &QToolButton::setEnabled); - connect (m_doc_browser, &documentation_browser::historyChanged, - this, &documentation::update_history_menus); + connect (m_doc_browser, &documentation_browser::backwardAvailable, + m_action_go_prev, &QAction::setEnabled); + connect (m_doc_browser, &documentation_browser::backwardAvailable, + popdown_button_prev_pages, &QToolButton::setEnabled); + connect (m_doc_browser, &documentation_browser::forwardAvailable, + m_action_go_next, &QAction::setEnabled); + connect (m_doc_browser, &documentation_browser::forwardAvailable, + popdown_button_next_pages, &QToolButton::setEnabled); + connect (m_doc_browser, &documentation_browser::historyChanged, + this, &documentation::update_history_menus); - // Init prev/next menus - for (int i = 0; i < max_history_entries; ++i) - { - m_prev_pages_actions[i] = new QAction (this); - m_prev_pages_actions[i]->setVisible (false); - m_next_pages_actions[i] = new QAction (this); - m_next_pages_actions[i]->setVisible (false); - m_prev_pages_menu->addAction (m_prev_pages_actions[i]); - m_next_pages_menu->addAction (m_next_pages_actions[i]); - } + // Init prev/next menus + for (int i = 0; i < max_history_entries; ++i) + { + m_prev_pages_actions[i] = new QAction (this); + m_prev_pages_actions[i]->setVisible (false); + m_next_pages_actions[i] = new QAction (this); + m_next_pages_actions[i]->setVisible (false); + m_prev_pages_menu->addAction (m_prev_pages_actions[i]); + m_next_pages_menu->addAction (m_next_pages_actions[i]); + } - connect (m_prev_pages_menu, &QMenu::triggered, - this, &documentation::open_hist_url); - connect (m_next_pages_menu, &QMenu::triggered, - this, &documentation::open_hist_url); + connect (m_prev_pages_menu, &QMenu::triggered, + this, &documentation::open_hist_url); + connect (m_next_pages_menu, &QMenu::triggered, + this, &documentation::open_hist_url); - // Find - m_tool_bar->addSeparator (); - m_action_find - = add_action (rmgr.icon ("edit-find"), tr ("Find"), - SLOT (activate_find (void)), this, m_tool_bar); + // Find + m_tool_bar->addSeparator (); + m_action_find + = 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); - m_action_zoom_out - = add_action (rmgr.icon ("view-zoom-out"), tr ("Zoom out"), - SLOT (zoom_out (void)), 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); + // Zoom + m_tool_bar->addSeparator (); + m_action_zoom_in + = 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 (settings.icon ("view-zoom-out"), tr ("Zoom out"), + SLOT (zoom_out ()), m_doc_browser, m_tool_bar); + m_action_zoom_original + = 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); -} + // Bookmarks (connect slots later) + m_tool_bar->addSeparator (); + m_action_bookmark + = add_action (settings.icon ("bookmark-new"), + tr ("Bookmark current page"), nullptr, nullptr, m_tool_bar); + } -void documentation::global_search (void) -{ - if (! m_help_engine) - return; + void documentation::global_search () + { + if (! m_help_engine) + return; - QString query_string; + QString query_string; #if defined (HAVE_QHELPSEARCHQUERYWIDGET_SEARCHINPUT) - QString queries - = m_help_engine->searchEngine ()->queryWidget ()->searchInput (); - query_string = queries; + QString queries + = m_help_engine->searchEngine ()->queryWidget ()->searchInput (); + query_string = queries; #else - // FIXME: drop this part when support for Qt4 is dropped - QList queries - = m_help_engine->searchEngine ()->queryWidget ()->query (); - if (queries.count ()) - query_string = queries.first ().wordList.join (" "); - else - query_string = ""; + // FIXME: drop this part when support for Qt4 is dropped + QList queries + = m_help_engine->searchEngine ()->queryWidget ()->query (); + if (queries.count ()) + query_string = queries.first ().wordList.join (" "); + else + query_string = ""; #endif - if (query_string.isEmpty ()) - return; + if (query_string.isEmpty ()) + 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); - else + // 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); + else #if defined (HAVE_QT_SPLITBEHAVIOR_ENUM) - m_internal_search = query_string.split (" ", Qt::SkipEmptyParts).first (); + 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); -} + m_help_engine->searchEngine ()->search (queries); + } -void documentation::global_search_started (void) -{ - qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); -} + void documentation::global_search_started () + { + qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); + } -void documentation::global_search_finished (int) -{ - if (! m_help_engine) - return; + void documentation::global_search_finished (int) + { + if (! m_help_engine) + return; - if (! m_internal_search.isEmpty ()) - { - m_query_string = m_internal_search; + if (! m_internal_search.isEmpty ()) + { + m_query_string = m_internal_search; - QHelpSearchEngine *search_engine = m_help_engine->searchEngine (); - if (search_engine) - { + QHelpSearchEngine *search_engine = m_help_engine->searchEngine (); + if (search_engine) + { #if defined (HAVE_QHELPSEARCHQUERYWIDGET_SEARCHINPUT) - QVector res - = search_engine->searchResults (0, search_engine->searchResultCount ()); + QVector res + = search_engine->searchResults (0, search_engine->searchResultCount ()); #else - QList< QPair > res - = search_engine->hits (0, search_engine->hitCount ()); + QList< QPair > res + = search_engine->hits (0, search_engine->hitCount ()); #endif - if (res.count ()) - { - QUrl url; + if (res.count ()) + { + QUrl url; - if (res.count () == 1) + if (res.count () == 1) #if defined (HAVE_QHELPSEARCHQUERYWIDGET_SEARCHINPUT) - url = res.front ().url (); + 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; + else + { + // Remove the quotes we added + QString search_string = m_internal_search; - for (auto r = res.begin (); r != res.end (); r++) - { + for (auto r = res.begin (); r != res.end (); r++) + { #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 ())) - { - if (title.indexOf (search_string.toLower ()) == 0) - { + if (title.contains (search_string.toLower ())) + { + if (title.indexOf (search_string.toLower ()) == 0) + { + url = tmpurl; + break; + } + else if (url.isEmpty ()) url = tmpurl; - break; - } - else if (url.isEmpty ()) - url = tmpurl; - } - } - } + } + } + } - if (! url.isEmpty ()) - { - connect (this, &documentation::show_single_result, - this, &documentation::handle_search_result_clicked); + if (! url.isEmpty ()) + { + connect (this, &documentation::show_single_result, + this, &documentation::handle_search_result_clicked); - emit show_single_result (url); - } - } - } + emit show_single_result (url); + } + } + } - m_internal_search = QString (); - } + m_internal_search = QString (); + } - qApp->restoreOverrideCursor(); -} + qApp->restoreOverrideCursor(); + } -void documentation::handle_search_result_clicked (const QUrl& url) -{ - // Open url with matching text - m_doc_browser->handle_index_clicked (url); + void documentation::handle_search_result_clicked (const QUrl& url) + { + // Open url with matching text + m_doc_browser->handle_index_clicked (url); - // Select all occurrences of matching text - select_all_occurrences (m_query_string); + // Select all occurrences of matching text + select_all_occurrences (m_query_string); - // Open search widget with matching text as search string - m_find_line_edit->setText (m_query_string); - m_find_line_edit->parentWidget ()->show (); + // Open search widget with matching text as search string + m_find_line_edit->setText (m_query_string); + m_find_line_edit->parentWidget ()->show (); - // If no occurrence can be found go to the top of the page - if (! m_doc_browser->find (m_find_line_edit->text ())) - m_doc_browser->moveCursor (QTextCursor::Start); - else - { - // Go to to first occurrence of search text. Going to the end and then - // search backwards until the last occurrence ensures the search text - // is visible in the first line of the visible part of the text. - m_doc_browser->moveCursor (QTextCursor::End); - while (m_doc_browser->find (m_find_line_edit->text (), - QTextDocument::FindBackward)); - } -} + // If no occurrence can be found go to the top of the page + if (! m_doc_browser->find (m_find_line_edit->text ())) + m_doc_browser->moveCursor (QTextCursor::Start); + else + { + // Go to to first occurrence of search text. Going to the end and then + // search backwards until the last occurrence ensures the search text + // is visible in the first line of the visible part of the text. + m_doc_browser->moveCursor (QTextCursor::End); + while (m_doc_browser->find (m_find_line_edit->text (), + QTextDocument::FindBackward)); + } + } -void documentation::select_all_occurrences (const QString& text) -{ - // Get highlight background and text color - QPalette pal = QApplication::palette (); - QTextCharFormat format; - QColor col = pal.color (QPalette::Highlight); - col.setAlphaF (0.25); - format.setBackground (QBrush (col)); - format.setForeground (QBrush (pal.color (QPalette::Text))); + void documentation::select_all_occurrences (const QString& text) + { + // Get highlight background and text color + QPalette pal = QApplication::palette (); + QTextCharFormat format; + QColor col = pal.color (QPalette::Highlight); + col.setAlphaF (0.25); + format.setBackground (QBrush (col)); + format.setForeground (QBrush (pal.color (QPalette::Text))); - // Create list for extra selected items - QList selected; - m_doc_browser->moveCursor (QTextCursor::Start); + // Create list for extra selected items + QList selected; + m_doc_browser->moveCursor (QTextCursor::Start); - // Find all occurrences and add them to the selection - while ( m_doc_browser->find (text) ) - { - QTextEdit::ExtraSelection selected_item; - selected_item.cursor = m_doc_browser->textCursor (); - selected_item.format = format; - selected.append (selected_item); - } + // Find all occurrences and add them to the selection + while ( m_doc_browser->find (text) ) + { + QTextEdit::ExtraSelection selected_item; + selected_item.cursor = m_doc_browser->textCursor (); + selected_item.format = format; + selected.append (selected_item); + } - // Apply selection and move back to the beginning - m_doc_browser->setExtraSelections (selected); - m_doc_browser->moveCursor (QTextCursor::Start); -} + // Apply selection and move back to the beginning + m_doc_browser->setExtraSelections (selected); + m_doc_browser->moveCursor (QTextCursor::Start); + } + + void documentation::notice_settings () + { + gui_settings settings; -void documentation::notice_settings (const 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; + // 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 (); - size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 + // Icon size in the toolbar. + 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_tool_bar->setIconSize (QSize (icon_size, icon_size)); - - // Shortcuts - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + QStyle *st = style (); + int icon_size = st->pixelMetric (global_icon_sizes[size_idx]); + m_tool_bar->setIconSize (QSize (icon_size, icon_size)); - 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); + // Shortcuts + 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); -} + // Settings for the browser + m_doc_browser->notice_settings (); + } -void documentation::save_settings (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + void documentation::save_settings () + { + gui_settings settings; + + m_doc_browser->save_settings (); + m_bookmarks->save_settings (); + } - m_doc_browser->save_settings (settings); - m_bookmarks->save_settings (settings); -} + void documentation::copyClipboard () + { + if (m_doc_browser->hasFocus ()) + { + m_doc_browser->copy(); + } + } -void documentation::copyClipboard (void) -{ - if (m_doc_browser->hasFocus ()) - { - m_doc_browser->copy(); - } -} + void documentation::pasteClipboard () { } -void documentation::pasteClipboard (void) { } + void documentation::selectAll () { } -void documentation::selectAll (void) { } - -void documentation::load_index (void) -{ - m_indexed = true; + void documentation::load_index () + { + m_indexed = true; - // Show index if no other page is required. - if (m_current_ref_name.isEmpty ()) - m_doc_browser->setSource - (QUrl ("qthelp://org.octave.interpreter-1.0/doc/octave.html/index.html")); - else - load_ref (m_current_ref_name); + // Show index if no other page is required. + if (m_current_ref_name.isEmpty ()) + m_doc_browser->setSource + (QUrl ("qthelp://org.octave.interpreter-1.0/doc/octave.html/index.html")); + else + load_ref (m_current_ref_name); - m_help_engine->contentWidget ()->expandToDepth (0); -} + m_help_engine->contentWidget ()->expandToDepth (0); + } -void documentation::load_ref (const QString& ref_name) -{ - if (! m_help_engine || ref_name.isEmpty ()) - return; + void documentation::load_ref (const QString& ref_name) + { + if (! m_help_engine || ref_name.isEmpty ()) + return; - m_current_ref_name = ref_name; + m_current_ref_name = ref_name; - if (! m_indexed) - return; + if (! m_indexed) + return; #if defined (HAVE_QHELPENGINE_DOCUMENTSFORIDENTIFIER) - QList found_links - = m_help_engine->documentsForIdentifier (ref_name); + QList found_links + = m_help_engine->documentsForIdentifier (ref_name); #else - QMap found_links - = m_help_engine->linksForIdentifier (ref_name); + QMap found_links + = m_help_engine->linksForIdentifier (ref_name); #endif - QTabWidget *navi = static_cast (widget (0)); + QTabWidget *navi = static_cast (widget (0)); - if (found_links.count() > 0) - { - // First search in the function index + if (found_links.count() > 0) + { + // First search in the function index #if defined (HAVE_QHELPENGINE_DOCUMENTSFORIDENTIFIER) - QUrl first_url = found_links.constFirst().url; + QUrl first_url = found_links.constFirst().url; #else - QUrl first_url = found_links.constBegin().value (); + QUrl first_url = found_links.constBegin().value (); #endif - m_doc_browser->setSource (first_url); + m_doc_browser->setSource (first_url); - // Switch to function index tab - m_help_engine->indexWidget()->filterIndices (ref_name); - QWidget *index_tab - = navi->findChild ("documentation_tab_index"); - navi->setCurrentWidget (index_tab); - } - else - { - // Use full text search to provide the best match - QHelpSearchEngine *search_engine = m_help_engine->searchEngine (); - QHelpSearchQueryWidget *search_query = search_engine->queryWidget (); + // Switch to function index tab + m_help_engine->indexWidget()->filterIndices (ref_name); + QWidget *index_tab + = navi->findChild ("documentation_tab_index"); + navi->setCurrentWidget (index_tab); + } + else + { + // Use full text search to provide the best match + QHelpSearchEngine *search_engine = m_help_engine->searchEngine (); + QHelpSearchQueryWidget *search_query = search_engine->queryWidget (); #if defined (HAVE_QHELPSEARCHQUERYWIDGET_SEARCHINPUT) - QString query = ref_name; - query.prepend ("\"").append ("\""); + QString query = ref_name; + query.prepend ("\"").append ("\""); #else - QList query; - query << QHelpSearchQuery (QHelpSearchQuery::DEFAULT, - QStringList (QString("\"") + ref_name + QString("\""))); + QList query; + query << QHelpSearchQuery (QHelpSearchQuery::DEFAULT, + QStringList (QString("\"") + ref_name + QString("\""))); #endif - m_internal_search = ref_name; - search_engine->search (query); + m_internal_search = ref_name; + search_engine->search (query); - // Switch to search tab + // Switch to search tab #if defined (HAVE_QHELPSEARCHQUERYWIDGET_SEARCHINPUT) - search_query->setSearchInput (query); + search_query->setSearchInput (query); #else - search_query->setQuery (query); + search_query->setQuery (query); #endif - QWidget *search_tab - = navi->findChild ("documentation_tab_search"); - navi->setCurrentWidget (search_tab); - } -} + QWidget *search_tab + = navi->findChild ("documentation_tab_search"); + navi->setCurrentWidget (search_tab); + } + } -void documentation::activate_find (void) -{ - if (m_find_line_edit->parentWidget ()->isVisible ()) - { - m_find_line_edit->parentWidget ()->hide (); - m_doc_browser->setFocus (); - } - else - { - m_find_line_edit->parentWidget ()->show (); - m_find_line_edit->selectAll (); - m_find_line_edit->setFocus (); - } -} + void documentation::activate_find () + { + if (m_find_line_edit->parentWidget ()->isVisible ()) + { + m_find_line_edit->parentWidget ()->hide (); + m_doc_browser->setFocus (); + } + else + { + m_find_line_edit->parentWidget ()->show (); + m_find_line_edit->selectAll (); + m_find_line_edit->setFocus (); + } + } -void documentation::filter_update (const QString& expression) -{ - if (! m_help_engine) - return; + void documentation::filter_update (const QString& expression) + { + if (! m_help_engine) + return; - QString wildcard; - if (expression.contains (QLatin1Char('*'))) - wildcard = expression; + QString wildcard; + if (expression.contains (QLatin1Char('*'))) + wildcard = expression; - m_help_engine->indexWidget ()->filterIndices(expression, wildcard); -} + m_help_engine->indexWidget ()->filterIndices(expression, wildcard); + } -void documentation::filter_update_history (void) -{ - QString text = m_filter->currentText (); // get current text - int index = m_filter->findText (text); // and its actual index + void documentation::filter_update_history () + { + QString text = m_filter->currentText (); // get current text + int index = m_filter->findText (text); // and its actual index - if (index > -1) - m_filter->removeItem (index); // remove if already existing + if (index > -1) + m_filter->removeItem (index); // remove if already existing - m_filter->insertItem (0, text); // (re)insert at beginning - m_filter->setCurrentIndex (0); -} + m_filter->insertItem (0, text); // (re)insert at beginning + m_filter->setCurrentIndex (0); + } -void documentation::find_backward (void) -{ - find (true); -} + void documentation::find_backward () + { + find (true); + } -void documentation::find (bool backward) -{ - if (! m_help_engine) - return; + void documentation::find (bool backward) + { + if (! m_help_engine) + return; - QTextDocument::FindFlags find_flags; - if (backward) - find_flags = QTextDocument::FindBackward; + QTextDocument::FindFlags find_flags; + if (backward) + find_flags = QTextDocument::FindBackward; - if (! m_doc_browser->find (m_find_line_edit->text (), find_flags)) - { - // Nothing was found, restart search from the begin or end of text - QTextCursor textcur = m_doc_browser->textCursor (); - if (backward) - textcur.movePosition (QTextCursor::End); - else - textcur.movePosition (QTextCursor::Start); - m_doc_browser->setTextCursor (textcur); - m_doc_browser->find (m_find_line_edit->text (), find_flags); - } + if (! m_doc_browser->find (m_find_line_edit->text (), find_flags)) + { + // Nothing was found, restart search from the begin or end of text + QTextCursor textcur = m_doc_browser->textCursor (); + if (backward) + textcur.movePosition (QTextCursor::End); + else + textcur.movePosition (QTextCursor::Start); + m_doc_browser->setTextCursor (textcur); + m_doc_browser->find (m_find_line_edit->text (), find_flags); + } - record_anchor_position (); -} + record_anchor_position (); + } -void documentation::find_forward_from_anchor (const QString& text) -{ - if (! m_help_engine) - return; + void documentation::find_forward_from_anchor (const QString& text) + { + if (! m_help_engine) + return; - // Search from the current position - QTextCursor textcur = m_doc_browser->textCursor (); - textcur.setPosition (m_search_anchor_position); - m_doc_browser->setTextCursor (textcur); + // Search from the current position + QTextCursor textcur = m_doc_browser->textCursor (); + textcur.setPosition (m_search_anchor_position); + m_doc_browser->setTextCursor (textcur); - if (! m_doc_browser->find (text)) - { - // Nothing was found, restart search from the beginning - textcur.movePosition (QTextCursor::Start); - m_doc_browser->setTextCursor (textcur); - m_doc_browser->find (text); - } -} + if (! m_doc_browser->find (text)) + { + // Nothing was found, restart search from the beginning + textcur.movePosition (QTextCursor::Start); + m_doc_browser->setTextCursor (textcur); + m_doc_browser->find (text); + } + } -void documentation::record_anchor_position (void) -{ - if (! m_help_engine) - return; + void documentation::record_anchor_position () + { + if (! m_help_engine) + return; - m_search_anchor_position = m_doc_browser->textCursor ().position (); -} + m_search_anchor_position = m_doc_browser->textCursor ().position (); + } -void documentation::handle_cursor_position_change (void) -{ - if (! m_help_engine) - return; + void documentation::handle_cursor_position_change () + { + if (! m_help_engine) + return; - if (m_doc_browser->hasFocus ()) - record_anchor_position (); -} + if (m_doc_browser->hasFocus ()) + record_anchor_position (); + } -void documentation::registerDoc (const QString& qch) -{ - if (m_help_engine) - { - QString ns = m_help_engine->namespaceName (qch); - bool do_setup = true; - if (m_help_engine->registeredDocumentations ().contains (ns)) - { - if (m_help_engine->documentationFileName (ns) == qch) - do_setup = false; - else - { - m_help_engine->unregisterDocumentation (ns); - m_help_engine->registerDocumentation (qch); - } - } - else if (! m_help_engine->registerDocumentation (qch)) - { - QMessageBox::warning (this, tr ("Octave Documentation"), - tr ("Unable to register help file %1."). - arg (qch)); - return; - } + void documentation::registerDoc (const QString& qch) + { + if (m_help_engine) + { + QString ns = m_help_engine->namespaceName (qch); + bool do_setup = true; + if (m_help_engine->registeredDocumentations ().contains (ns)) + { + if (m_help_engine->documentationFileName (ns) == qch) + do_setup = false; + else + { + m_help_engine->unregisterDocumentation (ns); + m_help_engine->registerDocumentation (qch); + } + } + else if (! m_help_engine->registerDocumentation (qch)) + { + QMessageBox::warning (this, tr ("Octave Documentation"), + tr ("Unable to register help file %1."). + arg (qch)); + return; + } - if (do_setup) - m_help_engine->setupData(); - } -} + if (do_setup) + m_help_engine->setupData(); + } + } -void documentation::unregisterDoc (const QString& qch) -{ - if (! m_help_engine) - return; + void documentation::unregisterDoc (const QString& qch) + { + if (! m_help_engine) + return; - QString ns = m_help_engine->namespaceName (qch); - if (m_help_engine - && m_help_engine->registeredDocumentations ().contains (ns) - && m_help_engine->documentationFileName (ns) == qch) - { - m_help_engine->unregisterDocumentation (ns); - m_help_engine->setupData (); - } -} + QString ns = m_help_engine->namespaceName (qch); + if (m_help_engine + && m_help_engine->registeredDocumentations ().contains (ns) + && m_help_engine->documentationFileName (ns) == qch) + { + m_help_engine->unregisterDocumentation (ns); + m_help_engine->setupData (); + } + } -void documentation::update_history_menus (void) -{ - if (m_prev_pages_count != m_doc_browser->backwardHistoryCount ()) - { - update_history (m_doc_browser->backwardHistoryCount (), - m_prev_pages_actions); - m_prev_pages_count = m_doc_browser->backwardHistoryCount (); - } + void documentation::update_history_menus () + { + if (m_prev_pages_count != m_doc_browser->backwardHistoryCount ()) + { + update_history (m_doc_browser->backwardHistoryCount (), + m_prev_pages_actions); + m_prev_pages_count = m_doc_browser->backwardHistoryCount (); + } - if (m_next_pages_count != m_doc_browser->forwardHistoryCount ()) - { - update_history (m_doc_browser->forwardHistoryCount (), - m_next_pages_actions); - m_next_pages_count = m_doc_browser->forwardHistoryCount (); - } -} + if (m_next_pages_count != m_doc_browser->forwardHistoryCount ()) + { + update_history (m_doc_browser->forwardHistoryCount (), + m_next_pages_actions); + m_next_pages_count = m_doc_browser->forwardHistoryCount (); + } + } -void documentation::update_history (int new_count, QAction **actions) -{ - // Which menu has to be updated? - int prev_next = -1; - QAction *a = m_action_go_prev; - if (actions == m_next_pages_actions) - { - prev_next = 1; - a = m_action_go_next; - } + void documentation::update_history (int new_count, QAction **actions) + { + // Which menu has to be updated? + int prev_next = -1; + QAction *a = m_action_go_prev; + if (actions == m_next_pages_actions) + { + prev_next = 1; + a = m_action_go_next; + } - // Get maximal count limited by array size - int count = qMin (new_count, int (max_history_entries)); + // Get maximal count limited by array size + int count = qMin (new_count, int (max_history_entries)); - // Fill used menu entries - for (int i = 0; i < count; i++) - { - QString title - = title_and_anchor (m_doc_browser->historyTitle (prev_next*(i+1)), - m_doc_browser->historyUrl (prev_next*(i+1))); + // Fill used menu entries + for (int i = 0; i < count; i++) + { + QString title + = title_and_anchor (m_doc_browser->historyTitle (prev_next*(i+1)), + m_doc_browser->historyUrl (prev_next*(i+1))); - if (i == 0) - a->setText (title); // set tool tip for prev/next buttons + if (i == 0) + a->setText (title); // set tool tip for prev/next buttons - actions[i]->setText (title); - actions[i]->setData (m_doc_browser->historyUrl (prev_next*(i+1))); - actions[i]->setEnabled (true); - actions[i]->setVisible (true); - } + actions[i]->setText (title); + actions[i]->setData (m_doc_browser->historyUrl (prev_next*(i+1))); + actions[i]->setEnabled (true); + actions[i]->setVisible (true); + } - // Hide unused menu entries - for (int j = count; j < max_history_entries; j++) - { - actions[j]->setEnabled (false); - actions[j]->setVisible (false); - } -} + // Hide unused menu entries + for (int j = count; j < max_history_entries; j++) + { + actions[j]->setEnabled (false); + actions[j]->setVisible (false); + } + } -void documentation::open_hist_url (QAction *a) -{ - m_doc_browser->setSource (a->data ().toUrl ()); -} + void documentation::open_hist_url (QAction *a) + { + m_doc_browser->setSource (a->data ().toUrl ()); + } -// Utility functions + // Utility functions -QString documentation::title_and_anchor (const QString& title, const QUrl& url) -{ - QString retval = title; - QString u = url.toString (); + QString documentation::title_and_anchor (const QString& title, const QUrl& url) + { + QString retval = title; + QString u = url.toString (); - retval.remove (QRegExp ("\\s*\\(*GNU Octave \\(version [^\\)]*\\)[: \\)]*")); + retval.remove (QRegExp ("\\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 - // it to the title - if (u.contains ('#')) - { - // 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 ("Concept-Index_cp_letter-"); - anchor.replace ("-", " "); + // Since the title only contains the section name and not the + // specific anchor, extract the latter from the url and append + // it to the title + if (u.contains ('#')) + { + // 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 ("Concept-Index_cp_letter-"); + anchor.replace ("-", " "); - // replace encoded special chars by their unencoded versions - QRegExp rx = QRegExp ("_00([0-7][0-9a-f])"); - int pos = 0; - while ((pos = rx.indexIn(anchor, pos)) != -1) - { - anchor.replace ("_00"+rx.cap (1), QChar (rx.cap (1).toInt (nullptr, 16))); - pos += rx.matchedLength(); - } + // replace encoded special chars by their unencoded versions + QRegExp rx = QRegExp ("_00([0-7][0-9a-f])"); + int pos = 0; + while ((pos = rx.indexIn(anchor, pos)) != -1) + { + anchor.replace ("_00"+rx.cap (1), QChar (rx.cap (1).toInt (nullptr, 16))); + pos += rx.matchedLength(); + } - if (retval != anchor) - retval = retval + ": " + anchor; - } + if (retval != anchor) + retval = retval + ": " + anchor; + } - return retval; -} + return retval; + } -// -// The documentation browser -// + // + // The documentation browser + // -documentation_browser::documentation_browser (QHelpEngine *he, QWidget *p) - : QTextBrowser (p), m_help_engine (he), m_zoom_level (max_zoom_level+1) -{ - setOpenLinks (false); - connect (this, &documentation_browser::anchorClicked, - this, [=] (const QUrl& url) { handle_index_clicked (url); }); + documentation_browser::documentation_browser (QHelpEngine *he, QWidget *p) + : QTextBrowser (p), m_help_engine (he), m_zoom_level (max_zoom_level+1) + { + setOpenLinks (false); + connect (this, &documentation_browser::anchorClicked, + this, [=] (const QUrl& url) { handle_index_clicked (url); }); - // 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"}; + // 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"}; - bool load_default_font = true; + bool load_default_font = true; - for (int i = 0; i < fonts.size (); ++i) - { - QFont font (fonts.at (i)); - if (font.exactMatch ()) - { - load_default_font = false; - break; - } - } + for (int i = 0; i < fonts.size (); ++i) + { + QFont font (fonts.at (i)); + if (font.exactMatch ()) + { + load_default_font = false; + break; + } + } - if (load_default_font) - { - QString fonts_dir = - QString::fromStdString (sys::env::getenv ("OCTAVE_FONTS_DIR") - + sys::file_ops::dir_sep_str ()); + if (load_default_font) + { + QString fonts_dir = + QString::fromStdString (sys::env::getenv ("OCTAVE_FONTS_DIR") + + sys::file_ops::dir_sep_str ()); - QStringList default_fonts = {"FreeMono", "FreeMonoBold", - "FreeMonoBoldOblique", "FreeMonoOblique"}; + QStringList default_fonts = {"FreeMono", "FreeMonoBold", + "FreeMonoBoldOblique", "FreeMonoOblique"}; - for (int i = 0; i < default_fonts.size (); ++i) - { - QString fontpath = - fonts_dir + default_fonts.at(i) + QString (".otf"); - QFontDatabase::addApplicationFont (fontpath); - } - } -} + for (int i = 0; i < default_fonts.size (); ++i) + { + QString fontpath = + fonts_dir + default_fonts.at(i) + QString (".otf"); + QFontDatabase::addApplicationFont (fontpath); + } + } + } -void documentation_browser::handle_index_clicked (const QUrl& url, - const QString&) -{ - if (url.scheme () == "qthelp") - setSource (url); - else - QDesktopServices::openUrl (url); -} + void documentation_browser::handle_index_clicked (const QUrl& url, + const QString&) + { + if (url.scheme () == "qthelp") + setSource (url); + else + QDesktopServices::openUrl (url); + } -void documentation_browser::notice_settings (const 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 (); - zoomIn (m_zoom_level); - } -} + void documentation_browser::notice_settings () + { + gui_settings settings; -QVariant documentation_browser::loadResource (int type, const QUrl& url) -{ - if (m_help_engine && url.scheme () == "qthelp") - return QVariant (m_help_engine->fileData(url)); - else - return QTextBrowser::loadResource(type, url); -} - -void documentation_browser::save_settings (gui_settings *settings) -{ - settings->setValue (dc_browser_zoom_level.key, m_zoom_level); + // Zoom level only at startup, not when other settings have changed + if (m_zoom_level > max_zoom_level) + { + m_zoom_level = settings.int_value (dc_browser_zoom_level); + zoomIn (m_zoom_level); + } + } - settings->sync (); -} + QVariant documentation_browser::loadResource (int type, const QUrl& url) + { + if (m_help_engine && url.scheme () == "qthelp") + return QVariant (m_help_engine->fileData(url)); + else + return QTextBrowser::loadResource(type, url); + } -void documentation_browser::zoom_in (void) -{ - if (m_zoom_level < max_zoom_level) - { - zoomIn (); - m_zoom_level++; - } -} + void documentation_browser::save_settings () + { + gui_settings settings; + + settings.setValue (dc_browser_zoom_level.settings_key (), m_zoom_level); + + settings.sync (); + } -void documentation_browser::zoom_out (void) -{ - if (m_zoom_level > min_zoom_level) - { - zoomOut (); - m_zoom_level--; - } -} + void documentation_browser::zoom_in () + { + if (m_zoom_level < max_zoom_level) + { + zoomIn (); + m_zoom_level++; + } + } -void documentation_browser::zoom_original (void) -{ - zoomIn (- m_zoom_level); - m_zoom_level = 0; -} + void documentation_browser::zoom_out () + { + if (m_zoom_level > min_zoom_level) + { + zoomOut (); + m_zoom_level--; + } + } -void documentation_browser::wheelEvent (QWheelEvent *we) -{ - if (we->modifiers () == Qt::ControlModifier) - { -#if defined (HAVE_QWHEELEVENT_ANGLEDELTA) - if (we->angleDelta().y () > 0) -#else - if (we->delta() > 0) -#endif + void documentation_browser::zoom_original () + { + zoomIn (- m_zoom_level); + m_zoom_level = 0; + } + + void documentation_browser::wheelEvent (QWheelEvent *we) + { + if (we->modifiers () == Qt::ControlModifier) + { + if (we->angleDelta().y () > 0) zoom_in (); else zoom_out (); - we->accept (); - } - else - QTextEdit::wheelEvent (we); -} + we->accept (); + } + else + QTextEdit::wheelEvent (we); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/documentation.h --- a/libgui/src/documentation.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/documentation.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,171 +37,166 @@ #include #include -#include "gui-settings.h" - OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class documentation; -class documentation_bookmarks; + class documentation; + class documentation_bookmarks; + + //! Documentation browser derived from Textbrowser -//! Documentation browser derived from Textbrowser + class documentation_browser : public QTextBrowser + { + Q_OBJECT + + public: -class documentation_browser : public QTextBrowser -{ - Q_OBJECT + documentation_browser (QHelpEngine *help_engine, QWidget *parent = nullptr); + ~documentation_browser () = default; -public: + virtual QVariant loadResource (int type, const QUrl& url); - documentation_browser (QHelpEngine *help_engine, QWidget *parent = nullptr); - ~documentation_browser (void) = default; + public slots: - virtual QVariant loadResource (int type, const QUrl& url); - -public slots: + void handle_index_clicked (const QUrl& url, + const QString& keyword = QString ()); + void notice_settings (); + void save_settings (); - void handle_index_clicked (const QUrl& url, - const QString& keyword = QString ()); - void notice_settings (const gui_settings *settings); - void save_settings (gui_settings *settings); + //! Zooming in and out while taking care of the zoom level + //!@{ + void zoom_in (); + void zoom_out (); + void zoom_original (); + //!@} - //! Zooming in and out while taking care of the zoom level - //!@{ - void zoom_in (void); - void zoom_out (void); - void zoom_original (void); - //!@} + protected: -protected: + void wheelEvent (QWheelEvent *we); - void wheelEvent (QWheelEvent *we); + private: -private: - - QHelpEngine *m_help_engine; + QHelpEngine *m_help_engine; - //! Store the current zoom level - int m_zoom_level; + //! Store the current zoom level + int m_zoom_level; - //! Minimal and maximal zoom level avoiding calling - //! zoom_in and zoom_out without actually zooming but - //! with changing the stored zoom level - enum + //! Minimal and maximal zoom level avoiding calling + //! zoom_in and zoom_out without actually zooming but + //! with changing the stored zoom level + enum { min_zoom_level = -5, max_zoom_level = 10 }; -}; + }; -//! The documentation main class derived from QSplitter + //! The documentation main class derived from QSplitter -class documentation : public QSplitter -{ - Q_OBJECT + class documentation : public QSplitter + { + Q_OBJECT -public: + 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" - */ - QString title_and_anchor (const QString& title, const QUrl& url); + @return QString "title: anchor" + */ + QString title_and_anchor (const QString& title, const QUrl& url); -signals: + signals: - void show_single_result (const QUrl&); + void show_single_result (const QUrl&); -public slots: + 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_ref (const QString& name = QString ()); - void registerDoc (const QString& name); - void unregisterDoc (const QString& name); + void load_index (); + void load_ref (const QString& name = QString ()); + void registerDoc (const QString& name); + void unregisterDoc (const QString& name); -private slots: + private slots: - void activate_find (void); - void global_search (void); - void global_search_started (void); - void global_search_finished (int hits); - void filter_update (const QString& expression); - void filter_update_history (void); - void find (bool backward = false); - void find_backward (void); - void find_forward_from_anchor (const QString& text); - void record_anchor_position (void); - void handle_cursor_position_change (void); - void handle_search_result_clicked (const QUrl& url); + 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 find (bool backward = false); + void find_backward (); + void find_forward_from_anchor (const QString& text); + void record_anchor_position (); + void handle_cursor_position_change (); + void handle_search_result_clicked (const QUrl& url); - void update_history_menus (void); - void open_hist_url (QAction *a); + void update_history_menus (); + void open_hist_url (QAction *a); -private: + private: - void construct_tool_bar (void); - QAction * add_action (const QIcon& icon, const QString& text, - const char *member, QWidget *receiver = nullptr, - QToolBar *tool_bar = nullptr); - void update_history (int new_count, QAction **actions); + void construct_tool_bar (); + QAction * add_action (const QIcon& icon, const QString& text, + const char *member, QWidget *receiver = nullptr, + QToolBar *tool_bar = nullptr); + void update_history (int new_count, QAction **actions); - //! Select all occurrences of a string in the doc browser - void select_all_occurrences (const QString& text); - - base_qobject& m_octave_qobj; + //! Select all occurrences of a string in the doc browser + void select_all_occurrences (const QString& text); - QHelpEngine *m_help_engine; - QString m_internal_search; - documentation_browser *m_doc_browser; - documentation_bookmarks *m_bookmarks; - QLineEdit *m_find_line_edit; - int m_search_anchor_position; - QComboBox *m_filter; - QString m_collection; + QHelpEngine *m_help_engine; + QString m_internal_search; + documentation_browser *m_doc_browser; + documentation_bookmarks *m_bookmarks; + QLineEdit *m_find_line_edit; + int m_search_anchor_position; + QComboBox *m_filter; + QString m_collection; - QWidget *m_doc_widget; - QToolBar *m_tool_bar; - QString m_query_string; + QWidget *m_doc_widget; + QToolBar *m_tool_bar; + QString m_query_string; - bool m_indexed; - QString m_current_ref_name; + bool m_indexed; + QString m_current_ref_name; - QAction *m_action_go_home; - QAction *m_action_go_prev; - QAction *m_action_go_next; - QMenu *m_prev_pages_menu; - QMenu *m_next_pages_menu; - int m_prev_pages_count; - int m_next_pages_count; + QAction *m_action_go_home; + QAction *m_action_go_prev; + QAction *m_action_go_next; + QMenu *m_prev_pages_menu; + QMenu *m_next_pages_menu; + int m_prev_pages_count; + int m_next_pages_count; - enum { max_history_entries = 10 }; - QAction *m_prev_pages_actions[max_history_entries]; - QAction *m_next_pages_actions[max_history_entries]; + enum { max_history_entries = 10 }; + QAction *m_prev_pages_actions[max_history_entries]; + QAction *m_next_pages_actions[max_history_entries]; - QAction *m_action_bookmark; + QAction *m_action_bookmark; - QAction *m_action_find; - QShortcut *m_findnext_shortcut; - QShortcut *m_findprev_shortcut; + QAction *m_action_find; + QShortcut *m_findnext_shortcut; + QShortcut *m_findprev_shortcut; - QAction *m_action_zoom_in; - QAction *m_action_zoom_out; - QAction *m_action_zoom_original; -}; + QAction *m_action_zoom_in; + QAction *m_action_zoom_out; + QAction *m_action_zoom_original; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/dw-main-window.cc --- a/libgui/src/dw-main-window.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/dw-main-window.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,217 +33,217 @@ #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) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + dw_main_window::dw_main_window (QWidget *p) + : QMainWindow (p) + { + gui_settings settings; - // Adding the actions for closing the dock widgets - m_close_action - = add_action (nullptr, rmgr.icon ("window-close", false), - tr ("&Close"), SLOT (request_close ()), this); + // Adding the actions for closing the dock widgets + m_close_action + = 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), - tr ("Close &All"), SLOT (request_close_all ()), this); + m_close_all_action + = 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), - tr ("Close &Other"), SLOT (request_close_other ()), this); + m_close_others_action + = add_action (nullptr, settings.icon ("window-close", false), + tr ("Close &Other"), SLOT (request_close_other ()), this); - m_switch_left_action - = add_action (nullptr, QIcon (), tr ("Switch to &Left Widget"), - SLOT (request_switch_left ()), this); + m_switch_left_action + = add_action (nullptr, QIcon (), tr ("Switch to &Left Widget"), + SLOT (request_switch_left ()), this); - m_switch_right_action - = add_action (nullptr, QIcon (), tr ("Switch to &Right Widget"), - SLOT (request_switch_right ()), this); + m_switch_right_action + = add_action (nullptr, QIcon (), tr ("Switch to &Right Widget"), + SLOT (request_switch_right ()), this); - // The list of actions for floating widgets - m_actions_list << m_close_action; - m_actions_list << m_close_others_action; - m_actions_list << m_close_all_action; - m_actions_list << m_switch_left_action; - m_actions_list << m_switch_right_action; + // The list of actions for floating widgets + m_actions_list << m_close_action; + m_actions_list << m_close_others_action; + m_actions_list << m_close_all_action; + 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 -QMenu *dw_main_window::createPopupMenu () -{ - QList new_actions = QList (); - new_actions.append (m_close_action); - new_actions.append (m_close_others_action); - new_actions.append (m_close_all_action); + // Re-implementing the popup menu of the main window + QMenu *dw_main_window::createPopupMenu () + { + QList new_actions = QList (); + new_actions.append (m_close_action); + new_actions.append (m_close_others_action); + new_actions.append (m_close_all_action); - QMenu *menu = QMainWindow::createPopupMenu (); - QList actions = menu->actions(); + QMenu *menu = QMainWindow::createPopupMenu (); + QList actions = menu->actions(); - if (actions.length () > 0) - { - QAction *sep = menu->insertSeparator (actions.at (0)); - menu->insertActions (sep, new_actions); - } - else - menu->addActions (new_actions); + if (actions.length () > 0) + { + QAction *sep = menu->insertSeparator (actions.at (0)); + menu->insertActions (sep, new_actions); + } + else + menu->addActions (new_actions); - return menu; -} + return menu; + } -// Adding an action to the main window -QAction * dw_main_window::add_action (QMenu *menu, const QIcon& icon, - const QString& text, const char *member, - QWidget *receiver) -{ - QAction *a; - QWidget *r = this; + // Adding an action to the main window + QAction * dw_main_window::add_action (QMenu *menu, const QIcon& icon, + const QString& text, const char *member, + QWidget *receiver) + { + QAction *a; + QWidget *r = this; - if (receiver != nullptr) - r = receiver; + if (receiver != nullptr) + r = receiver; - if (menu) - a = menu->addAction (icon, text, r, member); - else - { - a = new QAction (icon, text, this); - a->setEnabled (true); - connect (a, SIGNAL (triggered ()), r, member); - } + if (menu) + a = menu->addAction (icon, text, r, member); + else + { + a = new QAction (icon, text, this); + a->setEnabled (true); + connect (a, SIGNAL (triggered ()), r, member); + } - addAction (a); // important for shortcut context - a->setShortcutContext (Qt::WidgetWithChildrenShortcut); + addAction (a); // important for shortcut context + a->setShortcutContext (Qt::WidgetWithChildrenShortcut); - return a; -} + return a; + } -// Update the settings -void dw_main_window::notice_settings (const gui_settings *) -{ - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + // Update the settings + void dw_main_window::notice_settings () + { + 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 + // Slots for handling actions -// Close current widget -void dw_main_window::request_close () -{ - for (int i = 0; i < m_dw_list.length (); i++) - { - if (m_dw_list.at (i)->hasFocus ()) - { - m_dw_list.at (i)->close (); - if (i > 0) - m_dw_list.at (i-1)->setFocus (); - break; - } - } -} + // Close current widget + void dw_main_window::request_close () + { + for (int i = 0; i < m_dw_list.length (); i++) + { + if (m_dw_list.at (i)->hasFocus ()) + { + m_dw_list.at (i)->close (); + if (i > 0) + m_dw_list.at (i-1)->setFocus (); + break; + } + } + } -// Close other widgets -void dw_main_window::request_close_other () -{ - for (int i = m_dw_list.length () - 1; i >= 0; i--) - { - if (! m_dw_list.at (i)->hasFocus ()) - m_dw_list.at (i)->close (); - } -} + // Close other widgets + void dw_main_window::request_close_other () + { + for (int i = m_dw_list.length () - 1; i >= 0; i--) + { + if (! m_dw_list.at (i)->hasFocus ()) + m_dw_list.at (i)->close (); + } + } -// Close all widgets -void dw_main_window::request_close_all () -{ - for (int i = m_dw_list.length () - 1; i >= 0; i--) - m_dw_list.at (i)->close (); -} + // Close all widgets + void dw_main_window::request_close_all () + { + for (int i = m_dw_list.length () - 1; i >= 0; i--) + m_dw_list.at (i)->close (); + } -// Switch to left widget -void dw_main_window::request_switch_left () -{ - request_switch (-1); -} + // Switch to left widget + void dw_main_window::request_switch_left () + { + request_switch (-1); + } -// Switch to right widget -void dw_main_window::request_switch_right () -{ - request_switch (1); -} + // Switch to right widget + void dw_main_window::request_switch_right () + { + request_switch (1); + } -// Switch to left/right widget -void dw_main_window::request_switch (int direction) -{ - int active = -1, next; + // Switch to left/right widget + void dw_main_window::request_switch (int direction) + { + int active = -1, next; - for (int i = m_dw_list.length () - 1; i >= 0; i--) - { - if (m_dw_list.at (i)->hasFocus ()) - { - active = i; - break; - } - } + for (int i = m_dw_list.length () - 1; i >= 0; i--) + { + if (m_dw_list.at (i)->hasFocus ()) + { + active = i; + break; + } + } - if (active == -1) - return; + if (active == -1) + return; - if (direction == -1 && active == 0) - next = m_dw_list.length () - 1; - else if (direction == 1 && active == m_dw_list.length () - 1) - next = 0; - else - next = active + direction; + if (direction == -1 && active == 0) + next = m_dw_list.length () - 1; + else if (direction == 1 && active == m_dw_list.length () - 1) + next = 0; + else + next = active + direction; - m_dw_list.at (next)->raise (); - m_dw_list.at (next)->activateWindow (); - m_dw_list.at (next)->setFocus (); -} + m_dw_list.at (next)->raise (); + m_dw_list.at (next)->activateWindow (); + m_dw_list.at (next)->setFocus (); + } -// Reimplemented Event -bool dw_main_window::event (QEvent *ev) -{ - if (ev->type () == QEvent::ChildAdded - || ev->type () == QEvent::ChildRemoved) - { - // Adding or Removing a child indicates that a dock widget was - // created or removed. - // In all cases, the list of dock widgets has to be updated. - m_dw_list = findChildren(); - } + // Reimplemented Event + bool dw_main_window::event (QEvent *ev) + { + if (ev->type () == QEvent::ChildAdded + || ev->type () == QEvent::ChildRemoved) + { + // Adding or Removing a child indicates that a dock widget was + // created or removed. + // In all cases, the list of dock widgets has to be updated. + m_dw_list = findChildren(); + } - if (ev->type () == QEvent::StyleChange) - { - // This might indicate un- or re-docking a widget: Make sure - // floating widgets get a copy of our actions - for (int i = m_dw_list.length () - 1; i >= 0; i--) - { - // First remove possibly existing actions - for (int j = m_actions_list.length () - 1; j >0; j--) - m_dw_list.at (i)->removeAction (m_actions_list.at (j)); + if (ev->type () == QEvent::StyleChange) + { + // This might indicate un- or re-docking a widget: Make sure + // floating widgets get a copy of our actions + for (int i = m_dw_list.length () - 1; i >= 0; i--) + { + // First remove possibly existing actions + for (int j = m_actions_list.length () - 1; j >0; j--) + m_dw_list.at (i)->removeAction (m_actions_list.at (j)); - // Then add our actions for floating widgets - if (m_dw_list.at (i)->isFloating ()) - m_dw_list.at (i)->addActions (m_actions_list); - } - } + // Then add our actions for floating widgets + if (m_dw_list.at (i)->isFloating ()) + m_dw_list.at (i)->addActions (m_actions_list); + } + } - return QMainWindow::event (ev); -} + return QMainWindow::event (ev); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/dw-main-window.h --- a/libgui/src/dw-main-window.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/dw-main-window.h Mon Jan 30 18:36:03 2023 +0100 @@ -28,67 +28,61 @@ #include -#include "gui-settings.h" - OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class dw_main_window : public QMainWindow + { + Q_OBJECT -class dw_main_window : public QMainWindow -{ - Q_OBJECT + public: -public: - - dw_main_window (base_qobject& oct_qboj, QWidget *parent = nullptr); + dw_main_window (QWidget *parent = nullptr); - ~dw_main_window (void) = default; + ~dw_main_window () = default; - // No copying! + // No copying! - dw_main_window (const dw_main_window&) = delete; + dw_main_window (const dw_main_window&) = delete; - dw_main_window& operator = (const dw_main_window&) = delete; + dw_main_window& operator = (const dw_main_window&) = delete; -public slots: + public slots: - void notice_settings (const gui_settings *); + void notice_settings (); -protected slots: + protected slots: - virtual QMenu * createPopupMenu (); + virtual QMenu * createPopupMenu (); - virtual bool event (QEvent *ev); + virtual bool event (QEvent *ev); -private slots: + private slots: - void request_close (); - void request_close_all (); - void request_close_other (); + void request_close (); + void request_close_all (); + void request_close_other (); - void request_switch_left (); - void request_switch_right (); + void request_switch_left (); + void request_switch_right (); -private: + private: - void request_switch (int direction); + void request_switch (int direction); - QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text, - const char *member, QWidget *receiver); + 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; + QList m_dw_list; - QAction *m_close_action; - QAction *m_close_all_action; - QAction *m_close_others_action; + QAction *m_close_action; + QAction *m_close_all_action; + QAction *m_close_others_action; - QAction *m_switch_left_action; - QAction *m_switch_right_action; + QAction *m_switch_left_action; + QAction *m_switch_right_action; - QList m_actions_list; -}; + QList m_actions_list; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/external-editor-interface.cc --- a/libgui/src/external-editor-interface.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/external-editor-interface.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,99 +33,97 @@ #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 -bool -external_editor_interface::call_custom_editor (const QString& file, int line) -{ - QString editor = external_editor (); - if (editor.isEmpty ()) - return true; + // Calling the external editor + bool + external_editor_interface::call_custom_editor (const QString& file, int line) + { + QString editor = external_editor (); + if (editor.isEmpty ()) + return true; - if (line < 0) - line = 0; + if (line < 0) + line = 0; - // replace macros - editor.replace ("%f", file); - editor.replace ("%l", QString::number (line)); + // replace macros + editor.replace ("%f", file); + editor.replace ("%l", QString::number (line)); - QStringList arguments = editor.split (QRegExp("\\s+")); - editor = arguments.takeFirst (); + QStringList arguments = editor.split (QRegExp("\\s+")); + editor = arguments.takeFirst (); - // start the process and check for success - bool started_ok = QProcess::startDetached (editor, arguments); + // start the process and check for success + bool started_ok = QProcess::startDetached (editor, arguments); - if (started_ok != true) - { - QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical, - tr ("Octave Editor"), - tr ("Could not start custom file editor\n%1"). - arg (editor), - QMessageBox::Ok); + if (started_ok != true) + { + QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical, + tr ("Octave Editor"), + tr ("Could not start custom file editor\n%1"). + arg (editor), + QMessageBox::Ok); - msgBox->setWindowModality (Qt::NonModal); - msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); - } + msgBox->setWindowModality (Qt::NonModal); + msgBox->setAttribute (Qt::WA_DeleteOnClose); + msgBox->show (); + } - return started_ok; -} + return started_ok; + } -// Slots for the several signals for invoking the editor + // Slots for the several signals for invoking the editor -void external_editor_interface::request_new_file (const QString&) -{ - call_custom_editor (); -} + void external_editor_interface::request_new_file (const QString&) + { + call_custom_editor (); + } -void external_editor_interface::request_open_file (const QString& file_name, - const QString&, int line, - bool, bool, bool, - const QString&) -{ - call_custom_editor (file_name, line); -} + void external_editor_interface::request_open_file (const QString& file_name, + const QString&, int line, + bool, bool, bool, + const QString&) + { + call_custom_editor (file_name, line); + } -void external_editor_interface::handle_edit_file_request (const QString& file) -{ - call_custom_editor (file); -} + void external_editor_interface::handle_edit_file_request (const QString& file) + { + call_custom_editor (file); + } + + // Get and verify the settings of the external editor program + QString external_editor_interface::external_editor () + { + gui_settings settings; -// Get and verify the settings of the external editor program -QString external_editor_interface::external_editor (void) -{ - 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 (); + 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 ()) - { - QMessageBox *msgBox - = new QMessageBox (QMessageBox::Warning, - tr ("Octave Editor"), - tr ("There is no custom editor configured yet.\n" - "Do you want to open the preferences?"), - QMessageBox::No | QMessageBox::Yes); - msgBox->setDefaultButton (QMessageBox::Yes); - msgBox->setAttribute (Qt::WA_DeleteOnClose); + // check the settings (avoid an empty string) + if (editor.trimmed ().isEmpty ()) + { + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Warning, + tr ("Octave Editor"), + tr ("There is no custom editor configured yet.\n" + "Do you want to open the preferences?"), + QMessageBox::No | QMessageBox::Yes); + msgBox->setDefaultButton (QMessageBox::Yes); + msgBox->setAttribute (Qt::WA_DeleteOnClose); - int button = msgBox->exec (); + int button = msgBox->exec (); - if (button == QMessageBox::Yes) - emit request_settings_dialog ("editor"); - } + if (button == QMessageBox::Yes) + emit request_settings_dialog ("editor"); + } - return editor; -} + return editor; + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/external-editor-interface.h --- a/libgui/src/external-editor-interface.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/external-editor-interface.h Mon Jan 30 18:36:03 2023 +0100 @@ -31,42 +31,38 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class external_editor_interface : public QWidget + { + Q_OBJECT -class external_editor_interface : public QWidget -{ - Q_OBJECT + public: -public: + external_editor_interface (QWidget *main_win); - external_editor_interface (QWidget *main_win, base_qobject& oct_qobj); + ~external_editor_interface () = default; - ~external_editor_interface (void) = default; + signals: -signals: + void request_settings_dialog (const QString&); - void request_settings_dialog (const QString&); - -public slots: + public slots: - bool call_custom_editor (const QString& file = QString (), int line = -1); + bool call_custom_editor (const QString& file = QString (), int line = -1); - void request_open_file (const QString& fileName, - const QString& encoding = QString (), - int line = -1, bool debug_pointer = false, - bool breakpoint_marker = false, bool insert = true, - const QString& cond = ""); + void request_open_file (const QString& fileName, + const QString& encoding = QString (), + int line = -1, bool debug_pointer = false, + bool breakpoint_marker = false, bool insert = true, + const QString& cond = ""); - void request_new_file (const QString&); + void request_new_file (const QString&); - void handle_edit_file_request (const QString& file); + void handle_edit_file_request (const QString& file); -private: + private: - QString external_editor (void); - - base_qobject& m_octave_qobj; -}; + QString external_editor (); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/files-dock-widget.cc --- a/libgui/src/files-dock-widget.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/files-dock-widget.cc Mon Jan 30 18:36:03 2023 +0100 @@ -49,1131 +49,1127 @@ #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" OCTAVE_BEGIN_NAMESPACE(octave) -class FileTreeViewer : public QTreeView -{ -public: - - FileTreeViewer (QWidget *p) : QTreeView (p) { } - - ~FileTreeViewer (void) = default; - - void mousePressEvent (QMouseEvent *e) - { - if (e->button () != Qt::RightButton) - QTreeView::mousePressEvent (e); - } -}; - -// to have file renamed in the file tree, it has to be renamed in -// QFileSystemModel::setData. -// For the editor to behave correctly, some signals must be sent before -// and after the rename -class file_system_model : public QFileSystemModel -{ -public: - file_system_model (files_dock_widget *p) : QFileSystemModel (p) {} - - ~file_system_model () = default; - - bool setData (const QModelIndex &idx, const QVariant &value, - int role) override + class FileTreeViewer : public QTreeView { - if (!idx.isValid () || idx.column () != 0 || role != Qt::EditRole - || (flags (idx) & Qt::ItemIsEditable) == 0) - { - return false; - } + public: - QString new_name = value.toString (); - QString old_name = idx.data ().toString (); - if (new_name == old_name) - return true; - if (new_name.isEmpty () - || QDir::toNativeSeparators (new_name).contains (QDir::separator ())) - { - display_rename_failed_message (old_name, new_name); - return false; - } + FileTreeViewer (QWidget *p) : QTreeView (p) { } - auto parent_dir = QDir(filePath (parent (idx))); - - files_dock_widget *fdw = static_cast(parent()); - - fdw->file_remove_signal(parent_dir.filePath(old_name), parent_dir.filePath(new_name)); - - if (!parent_dir.rename (old_name, new_name)) - { - display_rename_failed_message (old_name, new_name); - fdw->file_renamed_signal(false); - return false; - } + ~FileTreeViewer () = default; - fdw->file_renamed_signal(true); - - emit fileRenamed(parent_dir.absolutePath(), old_name, new_name); - revert(); - - return true; - } - -private: - void display_rename_failed_message (const QString &old_name, - const QString &new_name) - { - const QString message = + void mousePressEvent (QMouseEvent *e) + { + if (e->button () != Qt::RightButton) + QTreeView::mousePressEvent (e); + } + }; - 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); - } -}; - -// Delegate to improve ergonomy of file renaming by pre-selecting the text -// before the extension. -class RenameItemDelegate : public QStyledItemDelegate -{ -public: - RenameItemDelegate (QObject *parent = nullptr) - : QStyledItemDelegate{ parent } + // to have file renamed in the file tree, it has to be renamed in + // QFileSystemModel::setData. + // For the editor to behave correctly, some signals must be sent before + // and after the rename + class file_system_model : public QFileSystemModel { - } - - void setEditorData (QWidget *editor, - const QModelIndex &index) const override - { - QLineEdit *line_edit = qobject_cast (editor); - - if (!line_edit) - { - QStyledItemDelegate::setEditorData (editor, index); - return; - } - - QString filename = index.data (Qt::EditRole).toString (); + public: + file_system_model (files_dock_widget *p) : QFileSystemModel (p) {} - int select_len = filename.indexOf (QChar ('.')); - if (select_len == -1) - select_len = filename.size (); - - line_edit->setText (filename); - - // Qt calls QLineEdit::selectAll after this function is called, so to - // actually restrict the selection, we have to post the modification at - // the end of the event loop. - // QTimer allows this easily with 0 as timeout. - QTimer::singleShot (0, [=] () { - line_edit->setSelection (0, select_len); - }); - } -}; + ~file_system_model () = default; -files_dock_widget::files_dock_widget (QWidget *p, base_qobject& oct_qobj) - : octave_dock_widget ("FilesDockWidget", p, oct_qobj) -{ - set_title (tr ("File Browser")); - setToolTip (tr ("Browse your files")); - - m_sig_mapper = nullptr; - - m_columns_shown = QStringList (); - m_columns_shown.append (tr ("File size")); - m_columns_shown.append (tr ("File type")); - m_columns_shown.append (tr ("Date modified")); - m_columns_shown.append (tr ("Show hidden")); - 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_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); - - QWidget *container = new QWidget (this); + bool setData (const QModelIndex &idx, const QVariant &value, + int role) override + { + if (!idx.isValid () || idx.column () != 0 || role != Qt::EditRole + || (flags (idx) & Qt::ItemIsEditable) == 0) + { + return false; + } - setWidget (container); - - // Create a toolbar - m_navigation_tool_bar = new QToolBar ("", container); - m_navigation_tool_bar->setAllowedAreas (Qt::TopToolBarArea); - m_navigation_tool_bar->setMovable (false); - - m_current_directory = new QComboBox (m_navigation_tool_bar); - m_current_directory->setToolTip (tr ("Enter the path or filename")); - m_current_directory->setEditable (true); - m_current_directory->setMaxCount (MaxMRUDirs); - m_current_directory->setInsertPolicy (QComboBox::NoInsert); - m_current_directory->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); - QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); - m_current_directory->setSizePolicy (sizePol); - - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - QAction *directory_up_action - = new QAction (rmgr.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"), - 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"), - 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); + QString new_name = value.toString (); + QString old_name = idx.data ().toString (); + if (new_name == old_name) + return true; + if (new_name.isEmpty () + || QDir::toNativeSeparators (new_name).contains (QDir::separator ())) + { + display_rename_failed_message (old_name, new_name); + return false; + } - 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"), - 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)); + auto parent_dir = QDir(filePath (parent (idx))); - popdown_menu->addSeparator (); - popdown_menu->addAction (rmgr.icon ("folder"), - tr ("Set Browser Directory..."), - this, &files_dock_widget::popdownmenu_search_dir); - popdown_menu->addSeparator (); - popdown_menu->addAction (rmgr.icon ("edit-find"), - tr ("Find Files..."), - this, &files_dock_widget::popdownmenu_findfiles); - popdown_menu->addSeparator (); - popdown_menu->addAction (rmgr.icon ("document-new"), - tr ("New File..."), - this, &files_dock_widget::popdownmenu_newfile); - popdown_menu->addAction (rmgr.icon ("folder-new"), - tr ("New Directory..."), - this, &files_dock_widget::popdownmenu_newdir); + files_dock_widget *fdw = static_cast(parent()); + + fdw->file_remove_signal(parent_dir.filePath(old_name), parent_dir.filePath(new_name)); - m_navigation_tool_bar->addWidget (m_current_directory); - m_navigation_tool_bar->addAction (directory_up_action); - m_navigation_tool_bar->addWidget (popdown_button); - - connect (directory_up_action, &QAction::triggered, - this, &files_dock_widget::change_directory_up); - connect (m_sync_octave_directory_action, &QAction::triggered, - this, &files_dock_widget::do_sync_octave_directory); - 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 (!parent_dir.rename (old_name, new_name)) + { + display_rename_failed_message (old_name, new_name); + fdw->file_renamed_signal(false); + return false; + } - if (settings->value (fb_restore_last_dir).toBool ()) - { - // restore last dir from previous session - QStringList last_dirs - = settings->value (fb_mru_list.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 ()) - { - // do not restore but there is a startup dir configured - startup_dir = QDir (settings->value (fb_startup_dir.key).toString ()); - } + fdw->file_renamed_signal(true); - if (! startup_dir.exists ()) - { - // the configured startup dir does not exist, take actual one - startup_dir = QDir (); + emit fileRenamed(parent_dir.absolutePath(), old_name, new_name); + revert(); + + return true; } - 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); - QModelIndex rootPathIndex - = m_file_system_model->setRootPath (startup_dir.absolutePath ()); - - // Attach the model to the QTreeView and set the root index - m_file_tree_view = new FileTreeViewer (container); - m_file_tree_view->setSelectionMode (QAbstractItemView::ExtendedSelection); - m_file_tree_view->setModel (m_file_system_model); - m_file_tree_view->setRootIndex (rootPathIndex); - m_file_tree_view->setSortingEnabled (true); - m_file_tree_view->setAlternatingRowColors (true); - m_file_tree_view->setAnimated (true); - m_file_tree_view->setToolTip (tr ("Double-click to open file/folder, right click for alternatives")); - - // allow renaming directly in the tree view with - // m_file_tree_view->edit(index) - m_file_system_model->setReadOnly (false); - // delegate to improve rename ergonomy by pre-selecting text up to the - // extension - auto *rename_delegate = new RenameItemDelegate (this); - m_file_tree_view->setItemDelegateForColumn (0, rename_delegate); - // prevent the tree view to override Octave's double-click behavior - m_file_tree_view->setEditTriggers (QAbstractItemView::NoEditTriggers); - // create the rename action (that will be added to context menu) - // and associate to F2 key shortcut - m_rename_action = new QAction (tr ("Rename..."), this); - m_rename_action->setShortcut (Qt::Key_F2); - m_rename_action->setShortcutContext(Qt::WidgetWithChildrenShortcut); - connect (m_rename_action, &QAction::triggered, this, - &files_dock_widget::contextmenu_rename); - addAction(m_rename_action); - - // 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 - - if (settings->contains (fb_column_state.key)) - m_file_tree_view->header ()->restoreState - (settings->value (fb_column_state.key).toByteArray ()); - - // Set header properties for sorting - m_file_tree_view->header ()->setSectionsClickable (true); - m_file_tree_view->header ()->setSectionsMovable (true); - m_file_tree_view->header ()->setSortIndicatorShown (true); - - QStringList mru_dirs = - settings->value (fb_mru_list.key).toStringList (); - m_current_directory->addItems (mru_dirs); - - m_current_directory->setEditText - (m_file_system_model->fileInfo (rootPathIndex). absoluteFilePath ()); - - connect (m_file_tree_view, &FileTreeViewer::activated, - this, &files_dock_widget::item_double_clicked); - - // add context menu to tree_view - m_file_tree_view->setContextMenuPolicy (Qt::CustomContextMenu); - connect (m_file_tree_view, &FileTreeViewer::customContextMenuRequested, - this, &files_dock_widget::contextmenu_requested); - - m_file_tree_view->header ()->setContextMenuPolicy (Qt::CustomContextMenu); - connect (m_file_tree_view->header (), - &QHeaderView::customContextMenuRequested, - this, &files_dock_widget::headercontextmenu_requested); - - // Layout the widgets vertically with the toolbar on top - QVBoxLayout *vbox_layout = new QVBoxLayout (); - vbox_layout->setSpacing (0); - vbox_layout->addWidget (m_navigation_tool_bar); - vbox_layout->addWidget (m_file_tree_view); - vbox_layout->setMargin (1); - - container->setLayout (vbox_layout); - - // FIXME: Add right-click contextual menus for copying, pasting, - // deleting files (and others). - - connect (m_current_directory->lineEdit (), &QLineEdit::returnPressed, - this, &files_dock_widget::accept_directory_line_edit); - - // FIXME: We could use - // - // connect (m_current_directory, - // QOverload::of (&QComboBox::activated), - // this, &files_dock_widget::set_current_directory); - // - // but referring to QComboBox::activated will generate deprecated - // function warnings from GCC. We could also use - // - // connect (m_current_directory, &QComboBox::textActivated, - // this, &files_dock_widget::set_current_directory); - // - // but the function textActivated was not introduced until Qt 5.14 - // so we'll need a feature test. - - connect (m_current_directory, SIGNAL (activated (const QString&)), - this, SLOT (set_current_directory (const QString&))); - - QCompleter *completer = new QCompleter (m_file_system_model, this); - m_current_directory->setCompleter (completer); - - setFocusProxy (m_current_directory); - - m_sync_octave_dir = true; // default, overwritten with notice_settings () - m_octave_dir = ""; - - if (! p) - make_window (); -} - -void files_dock_widget::save_settings (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (! settings) - return; - - 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 ()); - - QStringList dirs; - for (int i=0; i< m_current_directory->count (); i++) + private: + void display_rename_failed_message (const QString &old_name, + const QString &new_name) { - dirs.append (m_current_directory->itemText (i)); - } - settings->setValue (fb_mru_list.key, dirs); - - settings->sync (); - - octave_dock_widget::save_settings (); - - if (m_sig_mapper) - delete m_sig_mapper; -} + const QString message = -void files_dock_widget::item_double_clicked (const QModelIndex& index) -{ - // Retrieve the file info associated with the model index. - QFileInfo fileInfo = m_file_system_model->fileInfo (index); - set_current_directory (fileInfo.absoluteFilePath ()); -} - -void files_dock_widget::set_current_directory (const QString& dir) -{ - display_directory (dir); -} - -void files_dock_widget::accept_directory_line_edit (void) -{ - display_directory (m_current_directory->currentText ()); -} - -void files_dock_widget::change_directory_up (void) -{ - QDir dir - = QDir (m_file_system_model->filePath (m_file_tree_view->rootIndex ())); - - dir.cdUp (); - display_directory (dir.absolutePath ()); -} - -void files_dock_widget::do_sync_octave_directory (void) -{ - QDir dir - = QDir (m_file_system_model->filePath (m_file_tree_view->rootIndex ())); - - emit displayed_directory_changed (dir.absolutePath ()); -} - -void files_dock_widget::do_sync_browser_directory (void) -{ - display_directory (m_octave_dir, false); // false: no sync of octave dir -} - -void files_dock_widget::update_octave_directory (const QString& dir) -{ - m_octave_dir = dir; - if (m_sync_octave_dir) - display_directory (m_octave_dir, false); // false: no sync of octave dir -} - -void files_dock_widget::display_directory (const QString& dir, - bool set_octave_dir) -{ - QFileInfo fileInfo (dir); - if (fileInfo.exists ()) - { - if (fileInfo.isDir ()) - { - m_file_tree_view->setRootIndex (m_file_system_model-> - index (fileInfo.absoluteFilePath ())); - m_file_system_model->setRootPath (fileInfo.absoluteFilePath ()); - if (m_sync_octave_dir && set_octave_dir) - process_set_current_dir (fileInfo.absoluteFilePath ()); - - // see if it's in the list, and if it is, - // remove it and then put at top of the list - int index - = m_current_directory->findText (fileInfo.absoluteFilePath ()); - if (index != -1) - { - m_current_directory->removeItem (index); - } - m_current_directory->insertItem (0, fileInfo.absoluteFilePath ()); - m_current_directory->setCurrentIndex (0); - } - else - { - QString abs_fname = fileInfo.absoluteFilePath (); + 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); + } + }; - 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 (); -#if defined (HAVE_QT_SPLITBEHAVIOR_ENUM) - QStringList extensions = ext.split (";", Qt::SkipEmptyParts); -#else - QStringList extensions = ext.split (";", QString::SkipEmptyParts); -#endif - if (QFile::exists (abs_fname)) - { - if (extensions.contains (suffix)) - emit open_file (fileInfo.absoluteFilePath ()); - else - emit open_any_signal (abs_fname); - } - } - } -} - -void files_dock_widget::open_item_in_app (const QModelIndex& index) -{ - // Retrieve the file info associated with the model index. - QFileInfo fileInfo = m_file_system_model->fileInfo (index); - - QString file = fileInfo.absoluteFilePath (); - - QDesktopServices::openUrl (QUrl::fromLocalFile (file)); -} - -void files_dock_widget::toggle_header (int col) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - QString key = m_columns_shown_keys.at (col); - bool shown = settings->value (key, false).toBool (); - settings->setValue (key, ! shown); - settings->sync (); - - switch (col) + // Delegate to improve ergonomy of file renaming by pre-selecting the text + // before the extension. + class RenameItemDelegate : public QStyledItemDelegate + { + public: + RenameItemDelegate (QObject *parent = nullptr) + : QStyledItemDelegate{ parent } { - case 0: - case 1: - case 2: - // toggle column visibility - m_file_tree_view->setColumnHidden (col + 1, shown); - break; - case 3: - case 4: - // other actions depending on new settings - notice_settings (settings); - break; - } -} - -void files_dock_widget::headercontextmenu_requested (const QPoint& mpos) -{ - QMenu menu (this); - - if (m_sig_mapper) - 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 (); - - for (int i = 0; i < m_columns_shown.size (); i++) - { - QAction *action = menu.addAction (m_columns_shown.at (i), - m_sig_mapper, SLOT (map ())); - 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 ()); } - // FIXME: We could use - // - // connect (&m_sig_mapper, QOverload::of (&QSignalMapper::mapped), - // this, &workspace_view::toggle_header); - // - // but referring to QSignalMapper::mapped will generate deprecated - // function warnings from GCC. We could also use - // - // connect (&m_sig_mapper, &QSignalMapper::mappedInt, - // this, &workspace_view::toggle_header); - // - // but the function mappedInt was not introduced until Qt 5.15 so - // we'll need a feature test. - - connect (m_sig_mapper, SIGNAL (mapped (int)), - this, SLOT (toggle_header (int))); - - menu.exec (m_file_tree_view->mapToGlobal (mpos)); -} - -void files_dock_widget::contextmenu_requested (const QPoint& mpos) -{ - - QMenu menu (this); + void setEditorData (QWidget *editor, + const QModelIndex &index) const override + { + QLineEdit *line_edit = qobject_cast (editor); - QModelIndex index = m_file_tree_view->indexAt (mpos); - - if (index.isValid ()) - { - QFileInfo info = m_file_system_model->fileInfo (index); - - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList sel = m->selectedRows (); - - // check if item at mouse position is seleccted - if (! sel.contains (index)) - { - // is not selected -> clear actual selection and select this item - m->setCurrentIndex (index, - QItemSelectionModel::Clear - | QItemSelectionModel::Select - | QItemSelectionModel::Rows); - } - - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - // construct the context menu depending on item - menu.addAction (rmgr.icon ("document-open"), tr ("Open"), - this, &files_dock_widget::contextmenu_open); - - if (info.isDir ()) + if (!line_edit) { - menu.addAction (tr ("Open in System File Explorer"), - this, &files_dock_widget::contextmenu_open_in_app); - } - - if (info.isFile ()) - menu.addAction (tr ("Open in Text Editor"), - this, &files_dock_widget::contextmenu_open_in_editor); - - menu.addAction (tr ("Copy Selection to Clipboard"), - this, &files_dock_widget::contextmenu_copy_selection); - - if (info.isFile () && info.suffix () == "m") - menu.addAction (rmgr.icon ("media-playback-start"), tr ("Run"), - this, &files_dock_widget::contextmenu_run); - - if (info.isFile ()) - menu.addAction (tr ("Load Data"), - this, &files_dock_widget::contextmenu_load); - - if (info.isDir ()) - { - menu.addSeparator (); - menu.addAction (rmgr.icon ("go-first"), tr ("Set Current Directory"), - this, &files_dock_widget::contextmenu_setcurrentdir); - - QMenu *add_path_menu = menu.addMenu (tr ("Add to Path")); - - add_path_menu->addAction (tr ("Selected Directories"), - this, [=] (bool checked) { contextmenu_add_to_path (checked); }); - add_path_menu->addAction (tr ("Selected Directories and Subdirectories"), - this, &files_dock_widget::contextmenu_add_to_path_subdirs); - - QMenu *rm_path_menu = menu.addMenu (tr ("Remove from Path")); - - rm_path_menu->addAction (tr ("Selected Directories"), - this, &files_dock_widget::contextmenu_rm_from_path); - rm_path_menu->addAction (tr ("Selected Directories and Subdirectories"), - this, &files_dock_widget::contextmenu_rm_from_path_subdirs); - - menu.addSeparator (); - - menu.addAction (rmgr.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..."), - this, &files_dock_widget::contextmenu_delete); - - if (info.isDir ()) - { - menu.addSeparator (); - menu.addAction (rmgr.icon ("document-new"), tr ("New File..."), - this, &files_dock_widget::contextmenu_newfile); - menu.addAction (rmgr.icon ("folder-new"), tr ("New Directory..."), - this, &files_dock_widget::contextmenu_newdir); + QStyledItemDelegate::setEditorData (editor, index); + return; } - // show the menu - menu.exec (m_file_tree_view->mapToGlobal (mpos)); + QString filename = index.data (Qt::EditRole).toString (); - } -} + int select_len = filename.indexOf (QChar ('.')); + if (select_len == -1) + select_len = filename.size (); + + line_edit->setText (filename); -void files_dock_widget::contextmenu_open (bool) -{ + // Qt calls QLineEdit::selectAll after this function is called, so to + // actually restrict the selection, we have to post the modification at + // the end of the event loop. + // QTimer allows this easily with 0 as timeout. + QTimer::singleShot (0, [=] () { + line_edit->setSelection (0, select_len); + }); + } + }; - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + files_dock_widget::files_dock_widget (QWidget *p) + : octave_dock_widget ("FilesDockWidget", p) + { + set_title (tr ("File Browser")); + setToolTip (tr ("Browse your files")); + + m_sig_mapper = nullptr; + + m_columns_shown = QStringList (); + m_columns_shown.append (tr ("File size")); + m_columns_shown.append (tr ("File type")); + m_columns_shown.append (tr ("Date modified")); + m_columns_shown.append (tr ("Show hidden")); + m_columns_shown.append (tr ("Alternating row colors")); - for (auto it = rows.begin (); it != rows.end (); it++) - { - QFileInfo file = m_file_system_model->fileInfo (*it); - if (file.exists ()) - display_directory (file.absoluteFilePath ()); - } -} + m_columns_shown_keys = QStringList (); + 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 ()); + + QWidget *container = new QWidget (this); + + setWidget (container); -void files_dock_widget::contextmenu_open_in_editor (bool) -{ + // Create a toolbar + m_navigation_tool_bar = new QToolBar ("", container); + m_navigation_tool_bar->setAllowedAreas (Qt::TopToolBarArea); + m_navigation_tool_bar->setMovable (false); - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + m_current_directory = new QComboBox (m_navigation_tool_bar); + m_current_directory->setToolTip (tr ("Enter the path or filename")); + m_current_directory->setEditable (true); + m_current_directory->setMaxCount (MaxMRUDirs); + m_current_directory->setInsertPolicy (QComboBox::NoInsert); + m_current_directory->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); + QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); + m_current_directory->setSizePolicy (sizePol); + + gui_settings settings; + + QAction *directory_up_action + = 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 (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); - for (auto it = rows.begin (); it != rows.end (); it++) - { - QFileInfo file = m_file_system_model->fileInfo (*it); - if (file.exists ()) - emit open_file (file.absoluteFilePath ()); - } -} + m_sync_octave_directory_action + = 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); -void files_dock_widget::contextmenu_open_in_app (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + QToolButton *popdown_button = new QToolButton (); + popdown_button->setToolTip (tr ("Actions on current directory")); + QMenu *popdown_menu = new QMenu (); + 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 (settings.icon ("folder-settings", false, + "applications-system"), + "", m_navigation_tool_bar)); - for (auto it = rows.begin (); it != rows.end (); it++) - open_item_in_app (*it); -} + popdown_menu->addSeparator (); + popdown_menu->addAction (settings.icon ("folder"), + tr ("Set Browser Directory..."), + this, &files_dock_widget::popdownmenu_search_dir); + popdown_menu->addSeparator (); + popdown_menu->addAction (settings.icon ("edit-find"), + tr ("Find Files..."), + this, &files_dock_widget::popdownmenu_findfiles); + popdown_menu->addSeparator (); + popdown_menu->addAction (settings.icon ("document-new"), + tr ("New File..."), + this, &files_dock_widget::popdownmenu_newfile); + popdown_menu->addAction (settings.icon ("folder-new"), + tr ("New Directory..."), + this, &files_dock_widget::popdownmenu_newdir); + + m_navigation_tool_bar->addWidget (m_current_directory); + m_navigation_tool_bar->addAction (directory_up_action); + m_navigation_tool_bar->addWidget (popdown_button); -void files_dock_widget::contextmenu_copy_selection (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + connect (directory_up_action, &QAction::triggered, + this, &files_dock_widget::change_directory_up); + connect (m_sync_octave_directory_action, &QAction::triggered, + this, &files_dock_widget::do_sync_octave_directory); + connect (m_sync_browser_directory_action, &QAction::triggered, + this, &files_dock_widget::do_sync_browser_directory); - QStringList selection; + // Create the QFileSystemModel starting in the desired directory + QDir startup_dir; // take current dir - for (auto it = rows.begin (); it != rows.end (); it++) - { - QFileInfo info = m_file_system_model->fileInfo (*it); + if (settings.bool_value (fb_restore_last_dir)) + { + // restore last dir from previous session + QStringList last_dirs + = 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.string_value (fb_startup_dir).isEmpty ()) + { + // do not restore but there is a startup dir configured + startup_dir = QDir (settings.value (fb_startup_dir.settings_key ()).toString ()); + } - selection << info.fileName (); - } + if (! startup_dir.exists ()) + { + // the configured startup dir does not exist, take actual one + startup_dir = QDir (); + } - QClipboard *clipboard = QApplication::clipboard (); + 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); + QModelIndex rootPathIndex + = m_file_system_model->setRootPath (startup_dir.absolutePath ()); - clipboard->setText (selection.join ("\n")); -} + // Attach the model to the QTreeView and set the root index + m_file_tree_view = new FileTreeViewer (container); + m_file_tree_view->setSelectionMode (QAbstractItemView::ExtendedSelection); + m_file_tree_view->setModel (m_file_system_model); + m_file_tree_view->setRootIndex (rootPathIndex); + m_file_tree_view->setSortingEnabled (true); + m_file_tree_view->setAlternatingRowColors (true); + m_file_tree_view->setAnimated (true); + m_file_tree_view->setToolTip (tr ("Double-click to open file/folder, right click for alternatives")); -void files_dock_widget::contextmenu_load (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + // allow renaming directly in the tree view with + // m_file_tree_view->edit(index) + m_file_system_model->setReadOnly (false); + // delegate to improve rename ergonomy by pre-selecting text up to the + // extension + auto *rename_delegate = new RenameItemDelegate (this); + m_file_tree_view->setItemDelegateForColumn (0, rename_delegate); + // prevent the tree view to override Octave's double-click behavior + m_file_tree_view->setEditTriggers (QAbstractItemView::NoEditTriggers); + // create the rename action (that will be added to context menu) + // and associate to F2 key shortcut + m_rename_action = new QAction (tr ("Rename..."), this); + m_rename_action->setShortcut (Qt::Key_F2); + m_rename_action->setShortcutContext(Qt::WidgetWithChildrenShortcut); + connect (m_rename_action, &QAction::triggered, this, + &files_dock_widget::contextmenu_rename); + addAction(m_rename_action); + + // get sort column and order as well as column state (order and width) - if (rows.size () > 0) - { - QModelIndex index = rows[0]; + m_file_tree_view->sortByColumn + (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.settings_key ())) + m_file_tree_view->header ()->restoreState + (settings.value (fb_column_state.settings_key ()).toByteArray ()); - QFileInfo info = m_file_system_model->fileInfo (index); + // Set header properties for sorting + m_file_tree_view->header ()->setSectionsClickable (true); + m_file_tree_view->header ()->setSectionsMovable (true); + m_file_tree_view->header ()->setSortIndicatorShown (true); + + QStringList mru_dirs = + settings.value (fb_mru_list.settings_key ()).toStringList (); + m_current_directory->addItems (mru_dirs); + + m_current_directory->setEditText + (m_file_system_model->fileInfo (rootPathIndex). absoluteFilePath ()); + + connect (m_file_tree_view, &FileTreeViewer::activated, + this, &files_dock_widget::item_double_clicked); - emit load_file_signal (info.fileName ()); - } -} + // add context menu to tree_view + m_file_tree_view->setContextMenuPolicy (Qt::CustomContextMenu); + connect (m_file_tree_view, &FileTreeViewer::customContextMenuRequested, + this, &files_dock_widget::contextmenu_requested); + + m_file_tree_view->header ()->setContextMenuPolicy (Qt::CustomContextMenu); + connect (m_file_tree_view->header (), + &QHeaderView::customContextMenuRequested, + this, &files_dock_widget::headercontextmenu_requested); -void files_dock_widget::contextmenu_run (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + // Layout the widgets vertically with the toolbar on top + QVBoxLayout *vbox_layout = new QVBoxLayout (); + vbox_layout->setSpacing (0); + vbox_layout->addWidget (m_navigation_tool_bar); + vbox_layout->addWidget (m_file_tree_view); + vbox_layout->setMargin (1); + + container->setLayout (vbox_layout); + + // FIXME: Add right-click contextual menus for copying, pasting, + // deleting files (and others). + + connect (m_current_directory->lineEdit (), &QLineEdit::returnPressed, + this, &files_dock_widget::accept_directory_line_edit); - if (rows.size () > 0) - { - QModelIndex index = rows[0]; + // FIXME: We could use + // + // connect (m_current_directory, + // QOverload::of (&QComboBox::activated), + // this, &files_dock_widget::set_current_directory); + // + // but referring to QComboBox::activated will generate deprecated + // function warnings from GCC. We could also use + // + // connect (m_current_directory, &QComboBox::textActivated, + // this, &files_dock_widget::set_current_directory); + // + // but the function textActivated was not introduced until Qt 5.14 + // so we'll need a feature test. - QFileInfo info = m_file_system_model->fileInfo (index); - emit run_file_signal (info); - } -} + connect (m_current_directory, SIGNAL (activated (const QString&)), + this, SLOT (set_current_directory (const QString&))); + + QCompleter *completer = new QCompleter (m_file_system_model, this); + m_current_directory->setCompleter (completer); + + setFocusProxy (m_current_directory); + + m_sync_octave_dir = true; // default, overwritten with notice_settings () + m_octave_dir = ""; -void files_dock_widget::contextmenu_rename (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); - if (rows.size () > 0) - { - QModelIndex index = rows[0]; - m_file_tree_view->edit(index); - } -} + if (! p) + make_window (); + } + + void files_dock_widget::save_settings () + { + 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.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.settings_key (), dirs); -void files_dock_widget::contextmenu_delete (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + settings.sync (); + + octave_dock_widget::save_settings (); + + if (m_sig_mapper) + delete m_sig_mapper; + } + + void files_dock_widget::item_double_clicked (const QModelIndex& index) + { + // Retrieve the file info associated with the model index. + QFileInfo fileInfo = m_file_system_model->fileInfo (index); + set_current_directory (fileInfo.absoluteFilePath ()); + } + + void files_dock_widget::set_current_directory (const QString& dir) + { + display_directory (dir); + } + + void files_dock_widget::accept_directory_line_edit () + { + display_directory (m_current_directory->currentText ()); + } - int file_cnt = rows.size (); - bool multiple_files = (file_cnt > 1); + void files_dock_widget::change_directory_up () + { + QDir dir + = QDir (m_file_system_model->filePath (m_file_tree_view->rootIndex ())); + + dir.cdUp (); + display_directory (dir.absolutePath ()); + } - for (auto it = rows.begin (); it != rows.end (); it++) - { - QModelIndex index = *it; + void files_dock_widget::do_sync_octave_directory () + { + QDir dir + = QDir (m_file_system_model->filePath (m_file_tree_view->rootIndex ())); - QFileInfo info = m_file_system_model->fileInfo (index); + emit displayed_directory_changed (dir.absolutePath ()); + } + + void files_dock_widget::do_sync_browser_directory () + { + display_directory (m_octave_dir, false); // false: no sync of octave dir + } - QMessageBox::StandardButton dlg_answer; - if (multiple_files) - if (it == rows.begin ()) + void files_dock_widget::update_octave_directory (const QString& dir) + { + m_octave_dir = dir; + if (m_sync_octave_dir) + display_directory (m_octave_dir, false); // false: no sync of octave dir + } + + void files_dock_widget::display_directory (const QString& dir, + bool set_octave_dir) + { + QFileInfo fileInfo (dir); + if (fileInfo.exists ()) + { + if (fileInfo.isDir ()) { - dlg_answer = QMessageBox::question (this, - tr ("Delete file/directory"), - tr ("Are you sure you want to delete all %1 selected files?\n").arg (file_cnt), - QMessageBox::Yes | QMessageBox::No); - if (dlg_answer != QMessageBox::Yes) - return; + m_file_tree_view->setRootIndex (m_file_system_model-> + index (fileInfo.absoluteFilePath ())); + m_file_system_model->setRootPath (fileInfo.absoluteFilePath ()); + if (m_sync_octave_dir && set_octave_dir) + process_set_current_dir (fileInfo.absoluteFilePath ()); + + // see if it's in the list, and if it is, + // remove it and then put at top of the list + int index + = m_current_directory->findText (fileInfo.absoluteFilePath ()); + if (index != -1) + { + m_current_directory->removeItem (index); + } + m_current_directory->insertItem (0, fileInfo.absoluteFilePath ()); + m_current_directory->setCurrentIndex (0); } else - dlg_answer = QMessageBox::Yes; - 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); - } + { + QString abs_fname = fileInfo.absoluteFilePath (); + + QString suffix = fileInfo.suffix ().toLower (); + + 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 + QStringList extensions = ext.split (";", QString::SkipEmptyParts); +#endif + if (QFile::exists (abs_fname)) + { + if (extensions.contains (suffix)) + emit open_file (fileInfo.absoluteFilePath ()); + else + emit open_any_signal (abs_fname); + } + } + } + } + + void files_dock_widget::open_item_in_app (const QModelIndex& index) + { + // Retrieve the file info associated with the model index. + QFileInfo fileInfo = m_file_system_model->fileInfo (index); + + QString file = fileInfo.absoluteFilePath (); + + QDesktopServices::openUrl (QUrl::fromLocalFile (file)); + } + + void files_dock_widget::toggle_header (int col) + { + gui_settings settings; + + QString key = m_columns_shown_keys.at (col); + bool shown = settings.value (key, false).toBool (); + settings.setValue (key, ! shown); + settings.sync (); + + switch (col) + { + case 0: + case 1: + case 2: + // toggle column visibility + m_file_tree_view->setColumnHidden (col + 1, shown); + break; + case 3: + case 4: + // other actions depending on new settings + notice_settings (); + break; + } + } + + void files_dock_widget::headercontextmenu_requested (const QPoint& mpos) + { + QMenu menu (this); + + if (m_sig_mapper) + delete m_sig_mapper; + m_sig_mapper = new QSignalMapper (this); + + gui_settings settings; + + for (int i = 0; i < m_columns_shown.size (); i++) + { + QAction *action = menu.addAction (m_columns_shown.at (i), + m_sig_mapper, SLOT (map ())); + 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 ()); + } + + // FIXME: We could use + // + // connect (&m_sig_mapper, QOverload::of (&QSignalMapper::mapped), + // this, &workspace_view::toggle_header); + // + // but referring to QSignalMapper::mapped will generate deprecated + // function warnings from GCC. We could also use + // + // connect (&m_sig_mapper, &QSignalMapper::mappedInt, + // this, &workspace_view::toggle_header); + // + // but the function mappedInt was not introduced until Qt 5.15 so + // we'll need a feature test. + + connect (m_sig_mapper, SIGNAL (mapped (int)), + this, SLOT (toggle_header (int))); + + menu.exec (m_file_tree_view->mapToGlobal (mpos)); + } + + void files_dock_widget::contextmenu_requested (const QPoint& mpos) + { + + QMenu menu (this); + + QModelIndex index = m_file_tree_view->indexAt (mpos); + + if (index.isValid ()) + { + QFileInfo info = m_file_system_model->fileInfo (index); + + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList sel = m->selectedRows (); + + // check if item at mouse position is seleccted + if (! sel.contains (index)) + { + // is not selected -> clear actual selection and select this item + m->setCurrentIndex (index, + QItemSelectionModel::Clear + | QItemSelectionModel::Select + | QItemSelectionModel::Rows); + } + + gui_settings settings; + + // construct the context menu depending on item + menu.addAction (settings.icon ("document-open"), tr ("Open"), + this, &files_dock_widget::contextmenu_open); + + if (info.isDir ()) + { + menu.addAction (tr ("Open in System File Explorer"), + this, &files_dock_widget::contextmenu_open_in_app); + } + + if (info.isFile ()) + menu.addAction (tr ("Open in Text Editor"), + this, &files_dock_widget::contextmenu_open_in_editor); + + menu.addAction (tr ("Copy Selection to Clipboard"), + this, &files_dock_widget::contextmenu_copy_selection); + + if (info.isFile () && info.suffix () == "m") + menu.addAction (settings.icon ("media-playback-start"), tr ("Run"), + this, &files_dock_widget::contextmenu_run); + + if (info.isFile ()) + menu.addAction (tr ("Load Data"), + this, &files_dock_widget::contextmenu_load); + + if (info.isDir ()) + { + menu.addSeparator (); + 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")); - if (dlg_answer == QMessageBox::Yes) - { - if (info.isDir ()) + add_path_menu->addAction (tr ("Selected Directories"), + this, [=] (bool checked) { contextmenu_add_to_path (checked); }); + add_path_menu->addAction (tr ("Selected Directories and Subdirectories"), + this, &files_dock_widget::contextmenu_add_to_path_subdirs); + + QMenu *rm_path_menu = menu.addMenu (tr ("Remove from Path")); + + rm_path_menu->addAction (tr ("Selected Directories"), + this, &files_dock_widget::contextmenu_rm_from_path); + rm_path_menu->addAction (tr ("Selected Directories and Subdirectories"), + this, &files_dock_widget::contextmenu_rm_from_path_subdirs); + + menu.addSeparator (); + + menu.addAction (settings.icon ("edit-find"), tr ("Find Files..."), + this, &files_dock_widget::contextmenu_findfiles); + } + + menu.addSeparator (); + menu.addAction (m_rename_action); + menu.addAction (settings.icon ("edit-delete"), tr ("Delete..."), + this, &files_dock_widget::contextmenu_delete); + + if (info.isDir ()) + { + menu.addSeparator (); + menu.addAction (settings.icon ("document-new"), tr ("New File..."), + this, &files_dock_widget::contextmenu_newfile); + menu.addAction (settings.icon ("folder-new"), tr ("New Directory..."), + this, &files_dock_widget::contextmenu_newdir); + } + + // show the menu + menu.exec (m_file_tree_view->mapToGlobal (mpos)); + + } + } + + void files_dock_widget::contextmenu_open (bool) + { + + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); + + for (auto it = rows.begin (); it != rows.end (); it++) + { + QFileInfo file = m_file_system_model->fileInfo (*it); + if (file.exists ()) + display_directory (file.absoluteFilePath ()); + } + } + + void files_dock_widget::contextmenu_open_in_editor (bool) + { + + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); + + for (auto it = rows.begin (); it != rows.end (); it++) + { + QFileInfo file = m_file_system_model->fileInfo (*it); + if (file.exists ()) + emit open_file (file.absoluteFilePath ()); + } + } + + void files_dock_widget::contextmenu_open_in_app (bool) + { + 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); + } + + void files_dock_widget::contextmenu_copy_selection (bool) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); + + QStringList selection; + + for (auto it = rows.begin (); it != rows.end (); it++) + { + QFileInfo info = m_file_system_model->fileInfo (*it); + + selection << info.fileName (); + } + + QClipboard *clipboard = QApplication::clipboard (); + + clipboard->setText (selection.join ("\n")); + } + + void files_dock_widget::contextmenu_load (bool) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); + + if (rows.size () > 0) + { + QModelIndex index = rows[0]; + + QFileInfo info = m_file_system_model->fileInfo (index); + + emit load_file_signal (info.fileName ()); + } + } + + void files_dock_widget::contextmenu_run (bool) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); + + if (rows.size () > 0) + { + QModelIndex index = rows[0]; + + QFileInfo info = m_file_system_model->fileInfo (index); + emit run_file_signal (info); + } + } + + void files_dock_widget::contextmenu_rename (bool) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); + if (rows.size () > 0) + { + QModelIndex index = rows[0]; + m_file_tree_view->edit(index); + } + } + + void files_dock_widget::contextmenu_delete (bool) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); + + int file_cnt = rows.size (); + bool multiple_files = (file_cnt > 1); + + for (auto it = rows.begin (); it != rows.end (); it++) + { + QModelIndex index = *it; + + QFileInfo info = m_file_system_model->fileInfo (index); + + QMessageBox::StandardButton dlg_answer; + if (multiple_files) + if (it == rows.begin ()) { - // see if directory is empty - QDir path (info.absoluteFilePath ()); - QList fileLst = path.entryInfoList ( - QDir::Hidden | QDir::AllEntries | - QDir::NoDotAndDotDot | QDir::System); - - if (fileLst.count () != 0) - QMessageBox::warning (this, tr ("Delete file/directory"), - tr ("Can not delete a directory that is not empty")); - else - m_file_system_model->rmdir (index); + dlg_answer = QMessageBox::question (this, + tr ("Delete file/directory"), + tr ("Are you sure you want to delete all %1 selected files?\n").arg (file_cnt), + QMessageBox::Yes | QMessageBox::No); + if (dlg_answer != QMessageBox::Yes) + return; } else - { - // Close the file in the editor if open - emit file_remove_signal (info.filePath (), QString ()); - // Remove the file. - bool st = m_file_system_model->remove (index); - if (! st) - { - QMessageBox::warning (this, tr ("Deletion error"), - tr ("Could not delete file \"%1\"."). - arg (info.filePath ())); - // Reload the old file - } - emit file_renamed_signal (st); - } - - m_file_system_model->revert (); + dlg_answer = QMessageBox::Yes; + 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); + } - } - } -} - -// Get the currently selected files/dirs and return their file info -// in a list. -QList files_dock_widget::get_selected_items_info (bool dir) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); - - QList infos; - - for (auto it = rows.begin (); it != rows.end (); it++) - { - QModelIndex index = *it; - - QFileInfo info = m_file_system_model->fileInfo (index); + if (dlg_answer == QMessageBox::Yes) + { + if (info.isDir ()) + { + // see if directory is empty + QDir path (info.absoluteFilePath ()); + QList fileLst + = path.entryInfoList (QDir::Hidden | QDir::AllEntries + | QDir::NoDotAndDotDot | QDir::System); - if (info.exists () && - ((dir & info.isDir ()) || (! dir && info.isFile ()))) - infos.append (info); - } - - return infos; -} + if (fileLst.count () != 0) + QMessageBox::warning (this, tr ("Delete file/directory"), + tr ("Can not delete a directory that is not empty")); + else + m_file_system_model->rmdir (index); + } + else + { + // Close the file in the editor if open + emit file_remove_signal (info.filePath (), QString ()); + // Remove the file. + bool st = m_file_system_model->remove (index); + if (! st) + { + QMessageBox::warning (this, tr ("Deletion error"), + tr ("Could not delete file \"%1\"."). + arg (info.filePath ())); + // Reload the old file + } + emit file_renamed_signal (st); + } -void files_dock_widget::contextmenu_newfile (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + m_file_system_model->revert (); - if (rows.size () > 0) - { - QModelIndex index = rows[0]; + } + } + } - QFileInfo info = m_file_system_model->fileInfo (index); - QString parent_dir = info.filePath (); + // Get the currently selected files/dirs and return their file info + // in a list. + QList files_dock_widget::get_selected_items_info (bool dir) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); - process_new_file (parent_dir); - } -} + QList infos; + + for (auto it = rows.begin (); it != rows.end (); it++) + { + QModelIndex index = *it; + + QFileInfo info = m_file_system_model->fileInfo (index); -void files_dock_widget::contextmenu_newdir (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + if (info.exists () && + ((dir & info.isDir ()) || (! dir && info.isFile ()))) + infos.append (info); + } + + return infos; + } - if (rows.size () > 0) - { - QModelIndex index = rows[0]; + void files_dock_widget::contextmenu_newfile (bool) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); - QFileInfo info = m_file_system_model->fileInfo (index); - QString parent_dir = info.filePath (); + if (rows.size () > 0) + { + QModelIndex index = rows[0]; - process_new_dir (parent_dir); - } -} + QFileInfo info = m_file_system_model->fileInfo (index); + QString parent_dir = info.filePath (); -void files_dock_widget::contextmenu_setcurrentdir (bool) -{ - QList infos = get_selected_items_info (true); + process_new_file (parent_dir); + } + } - if (infos.length () > 0 && infos.first ().isDir ()) - process_set_current_dir (infos.first ().absoluteFilePath ()); -} + void files_dock_widget::contextmenu_newdir (bool) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); -void files_dock_widget::contextmenu_add_to_path (bool, bool rm, bool subdirs) -{ - QList infos = get_selected_items_info (true); + if (rows.size () > 0) + { + QModelIndex index = rows[0]; + + QFileInfo info = m_file_system_model->fileInfo (index); + QString parent_dir = info.filePath (); - QStringList dir_list; + process_new_dir (parent_dir); + } + } - for (int i = 0; i < infos.length (); i++) - dir_list.append (infos.at (i).absoluteFilePath ()); - - if (infos.length () > 0) - emit modify_path_signal (dir_list, rm, subdirs); -} + void files_dock_widget::contextmenu_setcurrentdir (bool) + { + QList infos = get_selected_items_info (true); -void files_dock_widget::contextmenu_add_to_path_subdirs (bool) -{ - contextmenu_add_to_path (true, false, true); -} + if (infos.length () > 0 && infos.first ().isDir ()) + process_set_current_dir (infos.first ().absoluteFilePath ()); + } -void files_dock_widget::contextmenu_rm_from_path (bool) -{ - contextmenu_add_to_path (true, true, false); -} + void files_dock_widget::contextmenu_add_to_path (bool, bool rm, bool subdirs) + { + QList infos = get_selected_items_info (true); + + QStringList dir_list; + + for (int i = 0; i < infos.length (); i++) + dir_list.append (infos.at (i).absoluteFilePath ()); -void files_dock_widget::contextmenu_rm_from_path_subdirs (bool) -{ - contextmenu_add_to_path (true, true, true); -} + if (infos.length () > 0) + emit modify_path_signal (dir_list, rm, subdirs); + } + + void files_dock_widget::contextmenu_add_to_path_subdirs (bool) + { + contextmenu_add_to_path (true, false, true); + } -void files_dock_widget::contextmenu_findfiles (bool) -{ - QItemSelectionModel *m = m_file_tree_view->selectionModel (); - QModelIndexList rows = m->selectedRows (); + void files_dock_widget::contextmenu_rm_from_path (bool) + { + contextmenu_add_to_path (true, true, false); + } - if (rows.size () > 0) - { - QModelIndex index = rows[0]; - - QFileInfo info = m_file_system_model->fileInfo (index); + void files_dock_widget::contextmenu_rm_from_path_subdirs (bool) + { + contextmenu_add_to_path (true, true, true); + } - if (info.isDir ()) - { - process_find_files (info.absoluteFilePath ()); - } - } -} + void files_dock_widget::contextmenu_findfiles (bool) + { + QItemSelectionModel *m = m_file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); -void files_dock_widget::notice_settings (const gui_settings *settings) -{ - // QSettings pointer is checked before emitting. + if (rows.size () > 0) + { + QModelIndex index = rows[0]; + + QFileInfo info = m_file_system_model->fileInfo (index); - int size_idx = settings->value (global_icon_size).toInt (); - size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 + if (info.isDir ()) + { + process_find_files (info.absoluteFilePath ()); + } + } + } - QStyle *st = style (); - int icon_size = st->pixelMetric (global_icon_sizes[size_idx]); - m_navigation_tool_bar->setIconSize (QSize (icon_size, icon_size)); + void files_dock_widget::notice_settings () + { + gui_settings settings; - // 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 ()); + // QSettings pointer is checked before emitting. - QDir::Filters current_filter = m_file_system_model->filter (); - 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)); + 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_navigation_tool_bar->setIconSize (QSize (icon_size, icon_size)); - m_file_tree_view->setAlternatingRowColors - (settings->value (m_columns_shown_keys.at (4),true).toBool ()); - m_file_tree_view->setModel (m_file_system_model); + // 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 ()); - // 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 (); - m_sync_octave_directory_action->setEnabled (! m_sync_octave_dir); - m_sync_browser_directory_action->setEnabled (! m_sync_octave_dir); + QDir::Filters current_filter = m_file_system_model->filter (); + 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)); - // If m_sync_octave_dir is enabled, then we want the file browser to - // update to match the current working directory of the - // interpreter. We don't want to queue any signal to change the - // interpreter's current working directory. In this case, we just - // want the GUI to match the state of the interpreter. + m_file_tree_view->setAlternatingRowColors + (settings.value (m_columns_shown_keys.at (4),true).toBool ()); + m_file_tree_view->setModel (m_file_system_model); - if (m_sync_octave_dir) - do_sync_browser_directory (); -} + // enable the buttons to sync octave/browser dir + // only if this is not done by default + m_sync_octave_dir + = 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); -void files_dock_widget::popdownmenu_home (bool) -{ - QString dir = QString::fromStdString (sys::env::get_home_directory ()); + // If m_sync_octave_dir is enabled, then we want the file browser to + // update to match the current working directory of the + // interpreter. We don't want to queue any signal to change the + // interpreter's current working directory. In this case, we just + // want the GUI to match the state of the interpreter. - if (dir.isEmpty ()) - dir = QDir::homePath (); + if (m_sync_octave_dir) + do_sync_browser_directory (); + } - set_current_directory (dir); -} + void files_dock_widget::popdownmenu_home (bool) + { + QString dir = QString::fromStdString (sys::env::get_home_directory ()); + + if (dir.isEmpty ()) + dir = QDir::homePath (); + + set_current_directory (dir); + } -void files_dock_widget::popdownmenu_search_dir (bool) -{ - // 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 ()) - opts |= QFileDialog::DontUseNativeDialog; + void files_dock_widget::popdownmenu_search_dir (bool) + { + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. + int opts = QFileDialog::ShowDirsOnly; - QString dir = QFileDialog::getExistingDirectory (this, - tr ("Set directory of file browser"), - m_file_system_model->rootPath (), - QFileDialog::Option (opts)); - set_current_directory (dir); -} + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) + opts |= QFileDialog::DontUseNativeDialog; -void files_dock_widget::popdownmenu_findfiles (bool) -{ - process_find_files (m_file_system_model->rootPath ()); -} + QString dir = QFileDialog::getExistingDirectory (this, + tr ("Set directory of file browser"), + m_file_system_model->rootPath (), + QFileDialog::Option (opts)); + set_current_directory (dir); + } -void files_dock_widget::popdownmenu_newdir (bool) -{ - process_new_dir (m_file_system_model->rootPath ()); -} + void files_dock_widget::popdownmenu_findfiles (bool) + { + process_find_files (m_file_system_model->rootPath ()); + } -void files_dock_widget::popdownmenu_newfile (bool) -{ - process_new_file (m_file_system_model->rootPath ()); -} + void files_dock_widget::popdownmenu_newdir (bool) + { + process_new_dir (m_file_system_model->rootPath ()); + } -void files_dock_widget::process_new_file (const QString& parent_dir) -{ - bool ok; + void files_dock_widget::popdownmenu_newfile (bool) + { + process_new_file (m_file_system_model->rootPath ()); + } - QString name = QInputDialog::getText (this, tr ("Create File"), - tr ("Create file in\n", "String ends with \\n!") + parent_dir, - QLineEdit::Normal, - tr ("New File.txt"), &ok); - if (ok && name.length () > 0) - { - name = parent_dir + '/' + name; + void files_dock_widget::process_new_file (const QString& parent_dir) + { + bool ok; - QFile file (name); - file.open (QIODevice::WriteOnly); - m_file_system_model->revert (); - } -} + QString name = QInputDialog::getText (this, tr ("Create File"), + tr ("Create file in\n", "String ends with \\n!") + parent_dir, + QLineEdit::Normal, + tr ("New File.txt"), &ok); + if (ok && name.length () > 0) + { + name = parent_dir + '/' + name; -void files_dock_widget::process_new_dir (const QString& parent_dir) -{ - bool ok; + QFile file (name); + file.open (QIODevice::WriteOnly); + m_file_system_model->revert (); + } + } - QString name = QInputDialog::getText (this, tr ("Create Directory"), - tr ("Create folder in\n", "String ends with \\n!") + parent_dir, - QLineEdit::Normal, - tr ("New Directory"), &ok); - if (ok && name.length () > 0) - { - QDir dir (parent_dir); - dir.mkdir (name); - m_file_system_model->revert (); - } -} + void files_dock_widget::process_new_dir (const QString& parent_dir) + { + bool ok; -void files_dock_widget::process_set_current_dir (const QString& dir) -{ - emit displayed_directory_changed (dir); -} + QString name = QInputDialog::getText (this, tr ("Create Directory"), + tr ("Create folder in\n", "String ends with \\n!") + parent_dir, + QLineEdit::Normal, + tr ("New Directory"), &ok); + if (ok && name.length () > 0) + { + QDir dir (parent_dir); + dir.mkdir (name); + m_file_system_model->revert (); + } + } -void files_dock_widget::process_find_files (const QString& dir) -{ - emit find_files_signal (dir); -} + void files_dock_widget::process_set_current_dir (const QString& dir) + { + emit displayed_directory_changed (dir); + } -void files_dock_widget::copyClipboard () -{ - if (m_file_tree_view->hasFocus ()) - contextmenu_copy_selection (true); - if (m_current_directory->hasFocus ()) - { - QClipboard *clipboard = QApplication::clipboard (); + void files_dock_widget::process_find_files (const QString& dir) + { + emit find_files_signal (dir); + } - QLineEdit *edit = m_current_directory->lineEdit (); - if (edit && edit->hasSelectedText ()) - { - clipboard->setText (edit->selectedText ()); - } - } -} + void files_dock_widget::copyClipboard () + { + if (m_file_tree_view->hasFocus ()) + contextmenu_copy_selection (true); + if (m_current_directory->hasFocus ()) + { + QClipboard *clipboard = QApplication::clipboard (); + + QLineEdit *edit = m_current_directory->lineEdit (); + if (edit && edit->hasSelectedText ()) + { + clipboard->setText (edit->selectedText ()); + } + } + } -void files_dock_widget::pasteClipboard () -{ - if (m_current_directory->hasFocus ()) - { - QClipboard *clipboard = QApplication::clipboard (); - QString str = clipboard->text (); - QLineEdit *edit = m_current_directory->lineEdit (); - if (edit && str.length () > 0) - edit->insert (str); - } -} + void files_dock_widget::pasteClipboard () + { + if (m_current_directory->hasFocus ()) + { + QClipboard *clipboard = QApplication::clipboard (); + QString str = clipboard->text (); + QLineEdit *edit = m_current_directory->lineEdit (); + if (edit && str.length () > 0) + edit->insert (str); + } + } -void files_dock_widget::selectAll () -{ - if (m_file_tree_view->hasFocus ()) - m_file_tree_view->selectAll (); - if (m_current_directory->hasFocus ()) - { - QLineEdit *edit = m_current_directory->lineEdit (); - if (edit) - { - edit->selectAll (); - } - } -} + void files_dock_widget::selectAll () + { + if (m_file_tree_view->hasFocus ()) + m_file_tree_view->selectAll (); + if (m_current_directory->hasFocus ()) + { + QLineEdit *edit = m_current_directory->lineEdit (); + if (edit) + { + edit->selectAll (); + } + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/files-dock-widget.h --- a/libgui/src/files-dock-widget.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/files-dock-widget.h Mon Jan 30 18:36:03 2023 +0100 @@ -46,194 +46,192 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - -//! Dock widget to display files in the current directory. + //! Dock widget to display files in the current directory. -class files_dock_widget : public octave_dock_widget -{ - Q_OBJECT + class files_dock_widget : public octave_dock_widget + { + Q_OBJECT -public: + public: + + files_dock_widget (QWidget *parent); - files_dock_widget (QWidget *parent, base_qobject& oct_qobj); + ~files_dock_widget () = default; - ~files_dock_widget (void) = default; + signals: -signals: + //! Emitted, whenever the user requested to open a file. - //! Emitted, whenever the user requested to open a file. + void open_file (const QString& fileName); - void open_file (const QString& fileName); + //! Emitted, whenever the currently displayed directory changed. - //! Emitted, whenever the currently displayed directory changed. + void displayed_directory_changed (const QString& dir); - void displayed_directory_changed (const QString& dir); + //! Emitted, whenever the user requested to load a file in the text editor. - //! Emitted, whenever the user requested to load a file in the text editor. + void load_file_signal (const QString& fileName); - void load_file_signal (const QString& fileName); + //! Emitted, whenever the user requested to open an unknown type file. - //! Emitted, whenever the user requested to open an unknown type file. + void open_any_signal (const QString& fileName); - void open_any_signal (const QString& fileName); + //! Emitted, whenever the user requested to run a file. - //! Emitted, whenever the user requested to run a file. + void run_file_signal (const QFileInfo& info); - void run_file_signal (const QFileInfo& info); + //! Emitted, whenever wants to search for a file . - //! Emitted, whenever wants to search for a file . + void find_files_signal (const QString& startdir); - void find_files_signal (const QString& startdir); + //! Emitted, whenever the user removes or renames a file. - //! Emitted, whenever the user removes or renames a file. + void file_remove_signal (const QString& old_name, const QString& new_name); - void file_remove_signal (const QString& old_name, const QString& new_name); + //! Emitted, when a file or directory is renamed. - //! Emitted, when a file or directory is renamed. + void file_renamed_signal (bool); - void file_renamed_signal (bool); + //! Emitted, when the path has to be modified - //! Emitted, when the path has to be modified + void modify_path_signal (const QStringList& dir_list, bool rm, + bool subdirs); - void modify_path_signal (const QStringList& dir_list, bool rm, - bool subdirs); + public slots: -public slots: + //! Slot for handling a change in directory via double click. - //! Slot for handling a change in directory via double click. + void item_double_clicked (const QModelIndex& index); - void item_double_clicked (const QModelIndex& index); + //! Slot for handling the up-directory button in the toolbar. - //! Slot for handling the up-directory button in the toolbar. + void change_directory_up (); - void change_directory_up (void); + //! Slot for handling the sync octave directory button in the toolbar. - //! Slot for handling the sync octave directory button in the toolbar. + void do_sync_octave_directory (); - void do_sync_octave_directory (void); + //! Slot for handling the sync browser directory button in the toolbar. - //! Slot for handling the sync browser directory button in the toolbar. + void do_sync_browser_directory (); - void do_sync_browser_directory (void); + //! Sets the current directory being displayed. - //! Sets the current directory being displayed. - - void set_current_directory (const QString& dir); + void set_current_directory (const QString& dir); - //! Accepts user input a the line edit for the current directory. + //! 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. + //! Set the internal variable that holds the actual octave variable. - void update_octave_directory (const QString& dir); + void update_octave_directory (const QString& dir); - //! Tells the widget to react on changed settings. + //! 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: + private slots: - void headercontextmenu_requested (const QPoint& pos); - void toggle_header (int col); + void headercontextmenu_requested (const QPoint& pos); + void toggle_header (int col); - //! Context menu wanted. + //! Context menu wanted. - void contextmenu_requested (const QPoint& pos); + void contextmenu_requested (const QPoint& pos); - //! Context menu actions. - //!@{ - void contextmenu_open (bool); - void contextmenu_open_in_editor (bool); - void contextmenu_open_in_app (bool); - void contextmenu_copy_selection (bool); - void contextmenu_run (bool); - void contextmenu_load (bool); - void contextmenu_rename (bool); - void contextmenu_delete (bool); - void contextmenu_newfile (bool); - void contextmenu_newdir (bool); - void contextmenu_setcurrentdir (bool); - void contextmenu_add_to_path (bool, bool rm=false, bool subdirs=false); - void contextmenu_add_to_path_subdirs (bool); - void contextmenu_rm_from_path (bool); - void contextmenu_rm_from_path_subdirs (bool); - void contextmenu_findfiles (bool); - //!@} + //! Context menu actions. + //!@{ + void contextmenu_open (bool); + void contextmenu_open_in_editor (bool); + void contextmenu_open_in_app (bool); + void contextmenu_copy_selection (bool); + void contextmenu_run (bool); + void contextmenu_load (bool); + void contextmenu_rename (bool); + void contextmenu_delete (bool); + void contextmenu_newfile (bool); + void contextmenu_newdir (bool); + void contextmenu_setcurrentdir (bool); + void contextmenu_add_to_path (bool, bool rm=false, bool subdirs=false); + void contextmenu_add_to_path_subdirs (bool); + void contextmenu_rm_from_path (bool); + void contextmenu_rm_from_path_subdirs (bool); + void contextmenu_findfiles (bool); + //!@} - //! Popdown menu options. - //!@{ - void popdownmenu_newfile (bool); - void popdownmenu_newdir (bool); - void popdownmenu_search_dir (bool); - void popdownmenu_findfiles (bool); - void popdownmenu_home (bool); - //!@} + //! Popdown menu options. + //!@{ + void popdownmenu_newfile (bool); + void popdownmenu_newdir (bool); + void popdownmenu_search_dir (bool); + void popdownmenu_findfiles (bool); + void popdownmenu_home (bool); + //!@} - //! Inherited from octave_doc_widget. - //!@{ - void copyClipboard (); - void pasteClipboard (); - void selectAll (); - //!@} + //! Inherited from octave_doc_widget. + //!@{ + void copyClipboard (); + void pasteClipboard (); + void selectAll (); + //!@} -private: + private: - //! Get currently selected QFileInfo object. + //! Get currently selected QFileInfo object. - QList get_selected_items_info (bool); + QList get_selected_items_info (bool); - //! Process new file/directory actions + //! Process new file/directory actions - void process_new_file (const QString& parent_name); - void process_new_dir (const QString& parent_name); + void process_new_file (const QString& parent_name); + void process_new_dir (const QString& parent_name); - //! Process setting current dir or find in files + //! Process setting current dir or find in files - void process_set_current_dir (const QString& parent_name); - void process_find_files (const QString& dir_name); + void process_set_current_dir (const QString& parent_name); + void process_find_files (const QString& dir_name); - //! set a new directory or open a file + //! set a new directory or open a file - void display_directory (const QString& dir, bool set_octave_dir = true); + void display_directory (const QString& dir, bool set_octave_dir = true); - void open_item_in_app (const QModelIndex& index); + void open_item_in_app (const QModelIndex& index); - //! Variables for the actions + //! Variables for the actions - QToolBar *m_navigation_tool_bar; - QAction *m_sync_octave_directory_action; - QAction *m_sync_browser_directory_action; - QAction *m_rename_action; + QToolBar *m_navigation_tool_bar; + QAction *m_sync_octave_directory_action; + QAction *m_sync_browser_directory_action; + QAction *m_rename_action; - //! The file system model. + //! The file system model. - QFileSystemModel *m_file_system_model; + QFileSystemModel *m_file_system_model; - //! The file system view. - //!@{ - QTreeView *m_file_tree_view; - QComboBox *m_current_directory; - //!@} + //! The file system view. + //!@{ + QTreeView *m_file_tree_view; + QComboBox *m_current_directory; + //!@} - //! Flag if syncing with Octave. + //! Flag if syncing with Octave. - bool m_sync_octave_dir; + bool m_sync_octave_dir; - //! The actual Octave directory. + //! The actual Octave directory. - QString m_octave_dir; + QString m_octave_dir; - enum { MaxMRUDirs = 10 }; + enum { MaxMRUDirs = 10 }; - QStringList m_columns_shown; - QStringList m_columns_shown_keys; - QList m_columns_shown_defs; - QSignalMapper *m_sig_mapper; -}; + QStringList m_columns_shown; + QStringList m_columns_shown_keys; + QList m_columns_shown_defs; + QSignalMapper *m_sig_mapper; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/find-files-dialog.cc --- a/libgui/src/find-files-dialog.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/find-files-dialog.cc Mon Jan 30 18:36:03 2023 +0100 @@ -49,367 +49,363 @@ #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) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + find_files_dialog::find_files_dialog (QWidget *p) + : QDialog (p) + { + gui_settings settings; - setWindowTitle (tr ("Find Files")); - setWindowIcon (rmgr.icon ("edit-find")); + setWindowTitle (tr ("Find Files")); + setWindowIcon (settings.icon ("edit-find")); - m_dir_iterator = nullptr; + m_dir_iterator = nullptr; - m_timer = new QTimer (this); - connect (m_timer, &QTimer::timeout, - this, &find_files_dialog::look_for_files); + m_timer = new QTimer (this); + 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")); - 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.string_value (ff_file_name)); + file_name_label->setBuddy (m_file_name_edit); - m_file_name_edit->setText (settings->value (ff_file_name).toString ()); - file_name_label->setBuddy (m_file_name_edit); + QLabel *start_dir_label = new QLabel (tr ("Start in:")); - 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.settings_key (), + QDir::currentPath ()).toString ()); + m_start_dir_edit->setToolTip (tr ("Enter the start directory")); + start_dir_label->setBuddy (m_start_dir_edit); - m_start_dir_edit = new QLineEdit; - m_start_dir_edit->setText (settings->value (ff_start_dir.key, - QDir::currentPath ()).toString ()); - m_start_dir_edit->setToolTip (tr ("Enter the start directory")); - start_dir_label->setBuddy (m_start_dir_edit); + m_browse_button = new QPushButton (tr ("Browse...")); + m_browse_button->setToolTip (tr ("Browse for start directory")); + connect (m_browse_button, &QPushButton::clicked, + this, &find_files_dialog::browse_folders); - m_browse_button = new QPushButton (tr ("Browse...")); - m_browse_button->setToolTip (tr ("Browse for start directory")); - connect (m_browse_button, &QPushButton::clicked, - this, &find_files_dialog::browse_folders); + m_recurse_dirs_check = new QCheckBox (tr ("Search subdirectories")); + 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_recurse_dirs_check = new QCheckBox (tr ("Search subdirectories")); - m_recurse_dirs_check->setChecked (settings->value (ff_recurse_dirs).toBool ()); - 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.bool_value (ff_include_dirs)); + m_include_dirs_check->setToolTip (tr ("Include matching directories in search results")); - 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->setToolTip (tr ("Include matching directories in search results")); + m_name_case_check = new QCheckBox (tr ("Name case insensitive")); + m_name_case_check->setChecked (settings.bool_value (ff_name_case)); + m_name_case_check->setToolTip (tr ("Set matching name is case insensitive")); - 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->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.bool_value (ff_check_text)); - 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_edit = new QLineEdit (); + m_contains_text_edit->setToolTip (tr ("Text to match")); + m_contains_text_edit->setText (settings.string_value (ff_contains_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_content_case_check = new QCheckBox (tr ("Text case insensitive")); + m_content_case_check->setChecked (settings.bool_value (ff_content_case)); + m_content_case_check->setToolTip (tr ("Set text content is case insensitive")); - 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->setToolTip (tr ("Set text content is case insensitive")); - - find_files_model *model = new find_files_model (this); + find_files_model *model = new find_files_model (this); - m_file_list = new QTableView; - m_file_list->setWordWrap (false); - m_file_list->setModel (model); - m_file_list->setShowGrid (false); - m_file_list->setSelectionBehavior (QAbstractItemView::SelectRows); - m_file_list->setSelectionMode (QAbstractItemView::SingleSelection); - 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 ()->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 (), - static_cast - (settings->value (ff_sort_files_by_order).toUInt ())); - // FIXME: use value instead of static cast after - // dropping support of Qt 5.4 + m_file_list = new QTableView; + m_file_list->setWordWrap (false); + m_file_list->setModel (model); + m_file_list->setShowGrid (false); + m_file_list->setSelectionBehavior (QAbstractItemView::SelectRows); + m_file_list->setSelectionMode (QAbstractItemView::SingleSelection); + 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.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.int_value (ff_sort_files_by_column), + static_cast + (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); + connect (m_file_list, &QTableView::doubleClicked, + this, &find_files_dialog::item_double_clicked); - m_status_bar = new QStatusBar; - m_status_bar->showMessage (tr ("Idle.")); + m_status_bar = new QStatusBar; + m_status_bar->showMessage (tr ("Idle.")); - m_find_button = new QPushButton (tr ("Find")); - m_find_button->setToolTip (tr ("Start search for matching files")); - connect (m_find_button, &QPushButton::clicked, - this, &find_files_dialog::start_find); + m_find_button = new QPushButton (tr ("Find")); + m_find_button->setToolTip (tr ("Start search for matching files")); + connect (m_find_button, &QPushButton::clicked, + this, &find_files_dialog::start_find); - m_stop_button = new QPushButton (tr ("Stop")); - m_stop_button->setToolTip (tr ("Stop searching")); - m_stop_button->setEnabled (false); - connect (m_stop_button, &QPushButton::clicked, - this, &find_files_dialog::stop_find); + m_stop_button = new QPushButton (tr ("Stop")); + m_stop_button->setToolTip (tr ("Stop searching")); + m_stop_button->setEnabled (false); + connect (m_stop_button, &QPushButton::clicked, + this, &find_files_dialog::stop_find); - // layout everything - QDialogButtonBox *button_box = new QDialogButtonBox (Qt::Vertical); - button_box->addButton (m_find_button, QDialogButtonBox::ActionRole); - button_box->addButton (m_stop_button, QDialogButtonBox::ActionRole); + // layout everything + QDialogButtonBox *button_box = new QDialogButtonBox (Qt::Vertical); + button_box->addButton (m_find_button, QDialogButtonBox::ActionRole); + button_box->addButton (m_stop_button, QDialogButtonBox::ActionRole); - // add dialog close button - m_close_button = button_box->addButton (QDialogButtonBox::Close); - connect (button_box, &QDialogButtonBox::rejected, - this, &find_files_dialog::close); + // add dialog close button + m_close_button = button_box->addButton (QDialogButtonBox::Close); + connect (button_box, &QDialogButtonBox::rejected, + this, &find_files_dialog::close); - // name options - QGroupBox *name_group = new QGroupBox (tr ("Filename/location")); - QGridLayout *name_layout = new QGridLayout; - name_group->setLayout (name_layout); + // name options + QGroupBox *name_group = new QGroupBox (tr ("Filename/location")); + QGridLayout *name_layout = new QGridLayout; + name_group->setLayout (name_layout); - name_layout->addWidget (file_name_label, 1, 1, 1, 1); - name_layout->addWidget (m_file_name_edit, 1, 2, 1, -1); + name_layout->addWidget (file_name_label, 1, 1, 1, 1); + name_layout->addWidget (m_file_name_edit, 1, 2, 1, -1); - name_layout->addWidget (start_dir_label, 2, 1); - name_layout->addWidget (m_start_dir_edit, 2, 2, 1, 3); - name_layout->addWidget (m_browse_button, 2, 5); - name_layout->setColumnStretch (2, 1); + name_layout->addWidget (start_dir_label, 2, 1); + name_layout->addWidget (m_start_dir_edit, 2, 2, 1, 3); + name_layout->addWidget (m_browse_button, 2, 5); + name_layout->setColumnStretch (2, 1); - name_layout->addWidget (m_recurse_dirs_check, 3, 1); - name_layout->addWidget (m_include_dirs_check, 3, 2); - name_layout->addWidget (m_name_case_check, 3, 3); + name_layout->addWidget (m_recurse_dirs_check, 3, 1); + name_layout->addWidget (m_include_dirs_check, 3, 2); + name_layout->addWidget (m_name_case_check, 3, 3); - // content options - QGroupBox *content_group = new QGroupBox (tr ("File contents")); - QGridLayout *content_layout = new QGridLayout; - content_group->setLayout (content_layout); - content_layout->addWidget (m_contains_text_check, 4, 1); - content_layout->addWidget (m_contains_text_edit, 4, 2, 1, 3); - content_layout->setColumnStretch (2, 1); - content_layout->addWidget (m_content_case_check, 5, 1); + // content options + QGroupBox *content_group = new QGroupBox (tr ("File contents")); + QGridLayout *content_layout = new QGridLayout; + content_group->setLayout (content_layout); + content_layout->addWidget (m_contains_text_check, 4, 1); + content_layout->addWidget (m_contains_text_edit, 4, 2, 1, 3); + content_layout->setColumnStretch (2, 1); + content_layout->addWidget (m_content_case_check, 5, 1); - QGridLayout *main_layout = new QGridLayout; - main_layout->setSizeConstraint (QLayout::SetFixedSize); - main_layout->addWidget (name_group, 0, 0); - main_layout->addWidget (content_group, 1, 0); - main_layout->addWidget (button_box, 0, 1, 3, 1); - main_layout->addWidget (m_file_list, 2, 0); - main_layout->setRowStretch (2, 1); - main_layout->addWidget (m_status_bar, 3, 0, 1, -1); + QGridLayout *main_layout = new QGridLayout; + main_layout->setSizeConstraint (QLayout::SetFixedSize); + main_layout->addWidget (name_group, 0, 0); + main_layout->addWidget (content_group, 1, 0); + main_layout->addWidget (button_box, 0, 1, 3, 1); + main_layout->addWidget (m_file_list, 2, 0); + main_layout->setRowStretch (2, 1); + main_layout->addWidget (m_status_bar, 3, 0, 1, -1); - setLayout (main_layout); + setLayout (main_layout); - connect (this, &find_files_dialog::finished, - this, &find_files_dialog::handle_done); -} + connect (this, &find_files_dialog::finished, + this, &find_files_dialog::handle_done); + } -find_files_dialog::~find_files_dialog (void) -{ - delete m_dir_iterator; -} + find_files_dialog::~find_files_dialog () + { + delete m_dir_iterator; + } -void find_files_dialog::save_settings (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (! settings) - return; + void find_files_dialog::save_settings () + { + 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 ()); + int sort_column = m_file_list->horizontalHeader ()->sortIndicatorSection (); + Qt::SortOrder sort_order + = m_file_list->horizontalHeader ()->sortIndicatorOrder (); + 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.settings_key (), m_file_name_edit->text ()); - settings->setValue (ff_file_name.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.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->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->sync (); -} + settings.sync (); + } -void find_files_dialog::set_search_dir (const QString& dir) -{ - stop_find (); - m_start_dir_edit->setText (dir); -} + void find_files_dialog::set_search_dir (const QString& dir) + { + stop_find (); + m_start_dir_edit->setText (dir); + } -void find_files_dialog::start_find (void) -{ - stop_find (); + void find_files_dialog::start_find () + { + stop_find (); + + find_files_model *m = static_cast (m_file_list->model ()); + m->clear (); - find_files_model *m = static_cast (m_file_list->model ()); - m->clear (); + QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags; + if (m_recurse_dirs_check->isChecked ()) + flags |= QDirIterator::Subdirectories; - QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags; - if (m_recurse_dirs_check->isChecked ()) - flags |= QDirIterator::Subdirectories; + QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files; + if (! m_name_case_check->isChecked ()) + filters |= QDir::CaseSensitive; - QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files; - if (! m_name_case_check->isChecked ()) - filters |= QDir::CaseSensitive; + QStringList nameFilters; + nameFilters.append (m_file_name_edit->text ()); - QStringList nameFilters; - nameFilters.append (m_file_name_edit->text ()); + if (m_dir_iterator) + delete m_dir_iterator; - if (m_dir_iterator) - delete m_dir_iterator; - - m_dir_iterator = new QDirIterator (m_start_dir_edit->text (), nameFilters, - filters, flags); + m_dir_iterator = new QDirIterator (m_start_dir_edit->text (), nameFilters, + filters, flags); - // enable/disable widgets - m_find_button->setEnabled (false); - m_stop_button->setEnabled (true); - m_close_button->setEnabled (false); - m_browse_button->setEnabled (false); - m_start_dir_edit->setEnabled (false); - m_file_name_edit->setEnabled (false); - m_recurse_dirs_check->setEnabled (false); - m_include_dirs_check->setEnabled (false); - m_name_case_check->setEnabled (false); - m_contains_text_check->setEnabled (false); - m_content_case_check->setEnabled (false); - m_contains_text_edit->setEnabled (false); + // enable/disable widgets + m_find_button->setEnabled (false); + m_stop_button->setEnabled (true); + m_close_button->setEnabled (false); + m_browse_button->setEnabled (false); + m_start_dir_edit->setEnabled (false); + m_file_name_edit->setEnabled (false); + m_recurse_dirs_check->setEnabled (false); + m_include_dirs_check->setEnabled (false); + m_name_case_check->setEnabled (false); + m_contains_text_check->setEnabled (false); + m_content_case_check->setEnabled (false); + m_contains_text_edit->setEnabled (false); - m_status_bar->showMessage (tr ("Searching...")); - m_timer->start (0); -} + m_status_bar->showMessage (tr ("Searching...")); + m_timer->start (0); + } -void find_files_dialog::stop_find (void) -{ - m_timer->stop (); + void find_files_dialog::stop_find () + { + m_timer->stop (); - m_find_button->setEnabled (true); - m_stop_button->setEnabled (false); - m_close_button->setEnabled (true); - m_browse_button->setEnabled (true); - m_start_dir_edit->setEnabled (true); - m_file_name_edit->setEnabled (true); - m_recurse_dirs_check->setEnabled (true); - m_include_dirs_check->setEnabled (true); - m_name_case_check->setEnabled (true); - m_contains_text_check->setEnabled (true); - m_content_case_check->setEnabled (true); - m_contains_text_edit->setEnabled (true); + m_find_button->setEnabled (true); + m_stop_button->setEnabled (false); + m_close_button->setEnabled (true); + m_browse_button->setEnabled (true); + m_start_dir_edit->setEnabled (true); + m_file_name_edit->setEnabled (true); + m_recurse_dirs_check->setEnabled (true); + m_include_dirs_check->setEnabled (true); + m_name_case_check->setEnabled (true); + m_contains_text_check->setEnabled (true); + m_content_case_check->setEnabled (true); + m_contains_text_edit->setEnabled (true); + + find_files_model *m = static_cast (m_file_list->model ()); + QString res_str = QString (tr ("%1 match (es)")).arg (m->rowCount ()); - find_files_model *m = static_cast (m_file_list->model ()); - QString res_str = QString (tr ("%1 match (es)")).arg (m->rowCount ()); + m_status_bar->showMessage (res_str); + } - m_status_bar->showMessage (res_str); -} + 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. -void find_files_dialog::browse_folders (void) -{ - 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 ()) - opts = QFileDialog::DontUseNativeDialog; + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) + opts = QFileDialog::DontUseNativeDialog; + + QString dir = + QFileDialog::getExistingDirectory (this, tr ("Set search directory"), + m_start_dir_edit->text (), + QFileDialog::Option (opts)); - QString dir = - QFileDialog::getExistingDirectory (this, tr ("Set search directory"), - m_start_dir_edit->text (), - QFileDialog::Option (opts)); + if (! dir.isEmpty ()) + m_start_dir_edit->setText (dir); + } - if (! dir.isEmpty ()) - m_start_dir_edit->setText (dir); -} + void find_files_dialog::item_double_clicked (const QModelIndex& idx) + { + find_files_model *m = static_cast (m_file_list->model ()); -void find_files_dialog::item_double_clicked (const QModelIndex& idx) -{ - find_files_model *m = static_cast (m_file_list->model ()); - - QFileInfo info = m->fileInfo (idx); + QFileInfo info = m->fileInfo (idx); - if (idx.column () == 1) - { - // clicked in directory part - emit dir_selected (info.absolutePath ()); - } - else - { - // clicked in filename part - if (info.isDir ()) - emit dir_selected (info.absoluteFilePath ()); - else - emit file_selected (info.absoluteFilePath ()); - } -} + if (idx.column () == 1) + { + // clicked in directory part + emit dir_selected (info.absolutePath ()); + } + else + { + // clicked in filename part + if (info.isDir ()) + emit dir_selected (info.absoluteFilePath ()); + else + emit file_selected (info.absoluteFilePath ()); + } + } -void find_files_dialog::look_for_files (void) -{ - if (m_dir_iterator && m_dir_iterator->hasNext ()) - { - QFileInfo info (m_dir_iterator->next ()); + void find_files_dialog::look_for_files () + { + if (m_dir_iterator && m_dir_iterator->hasNext ()) + { + QFileInfo info (m_dir_iterator->next ()); + + find_files_model *m + = static_cast (m_file_list->model ()); - find_files_model *m - = static_cast (m_file_list->model ()); + if (is_match (info)) + m->addFile (info); + } + else + { + stop_find (); + } + } - if (is_match (info)) - m->addFile (info); - } - else - { - stop_find (); - } -} + void find_files_dialog::handle_done (int) + { + // make sure we stopped processing + stop_find (); + } -void find_files_dialog::handle_done (int) -{ - // make sure we stopped processing - stop_find (); -} + bool find_files_dialog::is_match (const QFileInfo& info) + { + bool match = true; + if (info.isDir ()) + { + if (! m_include_dirs_check->isChecked ()) match = false; + if (m_contains_text_check->isChecked ()) match = false; + } + else + { + // a file + if (m_contains_text_check->isChecked ()) + { + match = false; -bool find_files_dialog::is_match (const QFileInfo& info) -{ - bool match = true; - if (info.isDir ()) - { - if (! m_include_dirs_check->isChecked ()) match = false; - if (m_contains_text_check->isChecked ()) match = false; - } - else - { - // a file - if (m_contains_text_check->isChecked ()) - { - match = false; + QFile file (info.absoluteFilePath ()); + if (file.open (QIODevice::ReadOnly)) + { + QTextStream stream (&file); - QFile file (info.absoluteFilePath ()); - if (file.open (QIODevice::ReadOnly)) - { - QTextStream stream (&file); + QString line; + QString match_str = m_contains_text_edit->text (); + + Qt::CaseSensitivity cs = m_content_case_check->isChecked () + ? Qt::CaseInsensitive + : Qt::CaseSensitive; - QString line; - QString match_str = m_contains_text_edit->text (); - - Qt::CaseSensitivity cs = m_content_case_check->isChecked () - ? Qt::CaseInsensitive - : Qt::CaseSensitive; + do + { + line = stream.readLine (); + match = line.contains (match_str, cs); + } + while (! line.isNull () && match == false); + } - do - { - line = stream.readLine (); - match = line.contains (match_str, cs); - } - while (! line.isNull () && match == false); - } + } + } - } - } - - return match; -} + return match; + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/find-files-dialog.h --- a/libgui/src/find-files-dialog.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/find-files-dialog.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,61 +39,57 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - -class find_files_dialog : public QDialog -{ - Q_OBJECT + class find_files_dialog : public QDialog + { + Q_OBJECT -public: + 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: + signals: - void file_selected (const QString& fileName); - void dir_selected (const QString& fileName); + void file_selected (const QString& fileName); + void dir_selected (const QString& fileName); -public slots: + public slots: - void set_search_dir (const QString& dir); + void set_search_dir (const QString& dir); -private slots: + private slots: - void start_find (void); - void stop_find (void); - void browse_folders (void); - void look_for_files (void); - void item_double_clicked (const QModelIndex&); - void handle_done (int); + void start_find (); + void stop_find (); + void browse_folders (); + void look_for_files (); + void item_double_clicked (const QModelIndex&); + void handle_done (int); -private: + private: - bool is_match (const QFileInfo& info); - - base_qobject& m_octave_qobj; + bool is_match (const QFileInfo& info); - QLineEdit *m_start_dir_edit; - QLineEdit *m_file_name_edit; - QPushButton *m_stop_button; - QPushButton *m_find_button; - QPushButton *m_close_button; - QPushButton *m_browse_button; - QTableView *m_file_list; - QTimer *m_timer; - QCheckBox *m_recurse_dirs_check; - QCheckBox *m_include_dirs_check; - QCheckBox *m_name_case_check; - QCheckBox *m_contains_text_check; - QCheckBox *m_content_case_check; - QLineEdit *m_contains_text_edit; - QDirIterator *m_dir_iterator; - QStatusBar *m_status_bar; -}; + QLineEdit *m_start_dir_edit; + QLineEdit *m_file_name_edit; + QPushButton *m_stop_button; + QPushButton *m_find_button; + QPushButton *m_close_button; + QPushButton *m_browse_button; + QTableView *m_file_list; + QTimer *m_timer; + QCheckBox *m_recurse_dirs_check; + QCheckBox *m_include_dirs_check; + QCheckBox *m_name_case_check; + QCheckBox *m_contains_text_check; + QCheckBox *m_content_case_check; + QLineEdit *m_contains_text_edit; + QDirIterator *m_dir_iterator; + QStatusBar *m_status_bar; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/find-files-model.cc --- a/libgui/src/find-files-model.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/find-files-model.cc Mon Jan 30 18:36:03 2023 +0100 @@ -95,7 +95,7 @@ m_sortorder = 0; } -void find_files_model::clear (void) +void find_files_model::clear () { beginResetModel (); diff -r 17d568574e1c -r 7860fcc69082 libgui/src/find-files-model.h --- a/libgui/src/find-files-model.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/find-files-model.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/graphics-init.cc --- a/libgui/src/graphics-init.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/graphics-init.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,6 @@ #include #include "graphics-init.h" -#include "octave-qobject.h" #include "qt-graphics-toolkit.h" #include "QtHandlesUtils.h" @@ -42,38 +41,29 @@ OCTAVE_BEGIN_NAMESPACE(octave) -void graphics_init (interpreter& interp, base_qobject& oct_qobj) -{ -#if defined (HAVE_QT_GRAPHICS) + void graphics_init (interpreter& interp) + { + gh_manager& gh_mgr = interp.get_gh_manager (); - gh_manager& gh_mgr = interp.get_gh_manager (); + autolock guard (gh_mgr.graphics_lock ()); - autolock guard (gh_mgr.graphics_lock ()); - - qRegisterMetaType ("graphics_object"); + qRegisterMetaType ("graphics_object"); - gh_mgr.enable_event_processing (true); + 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 ()) - qt_gtk->moveToThread (QApplication::instance ()->thread ()); + if (QThread::currentThread () + != QApplication::instance ()->thread ()) + qt_gtk->moveToThread (QApplication::instance ()->thread ()); - graphics_toolkit tk (qt_gtk); - - gtk_manager& gtk_mgr = interp.get_gtk_manager (); - - gtk_mgr.register_toolkit ("qt"); + graphics_toolkit tk (qt_gtk); - gtk_mgr.load_toolkit (tk); - -#else + gtk_manager& gtk_mgr = interp.get_gtk_manager (); - octave_unused_parameter (interp); - octave_unused_parameter (oct_qobj); + gtk_mgr.register_toolkit ("qt"); -#endif -} + gtk_mgr.load_toolkit (tk); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/graphics-init.h --- a/libgui/src/graphics-init.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/graphics-init.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,10 +32,9 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class interpreter; -class base_qobject; + class interpreter; -extern void graphics_init (interpreter& interp, base_qobject& oct_qobj); + extern void graphics_init (interpreter& interp); OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-cs.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-cs.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-cs.h --- a/libgui/src/gui-preferences-cs.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-cs.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-dc.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-dc.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-dc.h --- a/libgui/src/gui-preferences-dc.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-dc.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-dw.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-dw.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-dw.h --- a/libgui/src/gui-preferences-dw.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-dw.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-ed.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-ed.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-ed.h --- a/libgui/src/gui-preferences-ed.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-ed.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-fb.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-fb.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-fb.h --- a/libgui/src/gui-preferences-fb.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-fb.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-ff.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-ff.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-ff.h --- a/libgui/src/gui-preferences-ff.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-ff.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-global.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-global.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-global.h --- a/libgui/src/gui-preferences-global.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-global.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-gp.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-gp.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-gp.h --- a/libgui/src/gui-preferences-gp.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-gp.h Mon Jan 30 18:36:03 2023 +0100 @@ -30,7 +30,6 @@ // Graphics utilities -const gui_pref -gp_annotation_geometry ("annotation/geometry", QVariant ()); +extern gui_pref gp_annotation_geometry; #endif diff -r 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-hw.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-hw.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-hw.h --- a/libgui/src/gui-preferences-hw.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-hw.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-mw.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-mw.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-mw.h --- a/libgui/src/gui-preferences-mw.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-mw.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-nr.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-nr.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-nr.h --- a/libgui/src/gui-preferences-nr.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-nr.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-pd.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-pd.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-pd.h --- a/libgui/src/gui-preferences-pd.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-pd.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-sc.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-sc.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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::SHIFT + 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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-sc.h --- a/libgui/src/gui-preferences-sc.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-sc.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-sd.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-sd.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-sd.h --- a/libgui/src/gui-preferences-sd.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-sd.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-ve.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-ve.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-ve.h --- a/libgui/src/gui-preferences-ve.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-ve.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-ws.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-ws.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences-ws.h --- a/libgui/src/gui-preferences-ws.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences-ws.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/gui-preferences.h --- a/libgui/src/gui-preferences.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-preferences.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,60 +32,190 @@ #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; + + ~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; +}; + +// 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. + +class all_gui_preferences +{ +public: + + all_gui_preferences () = default; // No copying! - gui_pref (const gui_pref&) = delete; + all_gui_preferences (const all_gui_preferences&) = delete; + + all_gui_preferences& + operator = (const all_gui_preferences&) = delete; - gui_pref& operator = (const gui_pref&) = delete; + ~all_gui_preferences () = default; + + static void insert (const QString& settings_key, const gui_pref& pref); + + static const gui_pref value (const QString& settings_key); + + static QStringList keys (); - ~gui_pref (void) = default; +private: + + // Map from shortcut identifier (settings key) to gui_pref object. + QHash m_hash; + + void do_insert (const QString& settings_key, const gui_pref& pref); - const QString key; // the key name - const QVariant def; // the default value - const bool ignore; // when true, ignore, i.e. always take default + 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 () = 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; } - sc_pref (const QString& key_arg, unsigned int def_arg) - : key (key_arg), def (def_arg), def_std (QKeySequence::UnknownKey) - { } + QKeySequence def_value () const; + + QString def_text () const; + +private: + + // Description of the shortcut. + QString m_description; + + // The settings key name. + QString m_settings_key; + + // The default as key. + unsigned int m_def; - sc_pref (const QString& key_arg, QKeySequence::StandardKey def_std_arg) - : key (key_arg), def (0), def_std (def_std_arg) - { } + // 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? + +// Allow lookup of sc_pref objects when we don't know the name at +// compile time. + +class all_shortcut_preferences +{ +public: + + all_shortcut_preferences () = default; // No copying! - sc_pref (const sc_pref&) = delete; + all_shortcut_preferences (const all_shortcut_preferences&) = delete; + + all_shortcut_preferences& + operator = (const all_shortcut_preferences&) = delete; - sc_pref& operator = (const sc_pref&) = delete; + ~all_shortcut_preferences () = default; + + static void insert (const QString& settings_key, const sc_pref& scpref); + + static const sc_pref value (const QString& settings_key); + + static QStringList keys (); - ~sc_pref (void) = default; +private: + + // 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 QString key; // the key name - const unsigned int def; // the default as key - const QKeySequence::StandardKey def_std; // the default as standard key + 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 17d568574e1c -r 7860fcc69082 libgui/src/gui-settings.cc --- a/libgui/src/gui-settings.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-settings.cc Mon Jan 30 18:36:03 2023 +0100 @@ -27,85 +27,759 @@ # 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 +#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 "defaults.h" + OCTAVE_BEGIN_NAMESPACE(octave) -QColor gui_settings::get_color_value (const QVariant& def, int mode) const -{ - QColor default_color; + 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; + + // Determine whether the default value in pref is given as + // QPalette::ColorRole or as QColor + if (def.canConvert (QMetaType::QColor)) + default_color = def.value (); + else + { + // 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 + } + + if ((mode == 1) && (default_color != settings_color_no_change)) + { + // In second mode, determine the default color from the first mode + qreal h, s, l, a; + default_color.getHslF (&h, &s, &l, &a); + qreal l_new = 1.0-l*0.85; + if (l < 0.3) + l_new = 1.0-l*0.7; // convert darker into lighter colors + default_color.setHslF (h, s, l_new, a); + } + + return default_color; + } - // Determine whether the default value in pref is given as - // QPalette::ColorRole or as QColor - if (def.canConvert (QMetaType::QColor)) - default_color = def.value (); - else - { - // 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 - } + QColor gui_settings::color_value (const gui_pref& pref, int mode) const + { + QColor default_color = get_color_value (pref.def (), mode); + + return value (pref.settings_key () + settings_color_modes_ext[mode], + QVariant (default_color)).value (); + } + + void gui_settings::set_color_value (const gui_pref& pref, + const QColor& color, int mode) + { + int m = mode; + if (m > 1) + m = 1; + + setValue (pref.settings_key () + settings_color_modes_ext[m], + QVariant (color)); + } + + QString gui_settings::sc_value (const sc_pref& scpref) const + { + 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 + "/" + 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. - if ((mode == 1) && (default_color != settings_color_no_change)) - { - // In second mode, determine the default color from the first mode - qreal h, s, l, a; - default_color.getHslF (&h, &s, &l, &a); - qreal l_new = 1.0-l*0.85; - if (l < 0.3) - l_new = 1.0-l*0.7; // convert darker into lighter colors - default_color.setHslF (h, s, l_new, a); - } + 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]; + } + } - return default_color; -} + // 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; + } -QColor gui_settings::color_value (const gui_pref& pref, int mode) const -{ - QColor default_color = get_color_value (pref.def, mode); + 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 ()); + } + + } - return value (pref.key + settings_color_modes_ext[mode], - QVariant (default_color)).value (); -} +#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; + } + +#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])); -void gui_settings::set_color_value (const gui_pref& pref, - const QColor& color, int mode) -{ - int m = mode; - if (m > 1) - m = 1; + // 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) + { + 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 (); - setValue (pref.key + settings_color_modes_ext[m], QVariant (color)); -} + 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"; -QString gui_settings::sc_value (const sc_pref& pref) const -{ - QKeySequence key_seq = sc_def_value (pref); + 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++; + } - // Get the value from the settings where the key sequences are stored - // as strings - return value (sc_group + pref.key, key_seq.toString ()).toString (); -} + 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); + } -QKeySequence gui_settings::sc_def_value (const sc_pref& pref) const -{ - QKeySequence key_seq = QKeySequence (); + // get a list of all available encodings + void gui_settings::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 gui_settings::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 = string_value (ed_default_enc); - // 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); + 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); + } + + 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"); - return key_seq; -} + 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 17d568574e1c -r 7860fcc69082 libgui/src/gui-settings.h --- a/libgui/src/gui-settings.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-settings.h Mon Jan 30 18:36:03 2023 +0100 @@ -26,102 +26,195 @@ #if ! defined (octave_gui_settings_h) #define octave_gui_settings_h 1 -#include "octave-config.h" +#include +#include +#include +#if defined (HAVE_QSCINTILLA) +# include +#endif -#include +class QByteArray; +class QComboBox; +class QDateTime; +class QIcon; +class QShortcut; +class QTranslator; #include "gui-preferences.h" OCTAVE_BEGIN_NAMESPACE(octave) -class gui_settings : public QSettings -{ - Q_OBJECT + class gui_settings : public QSettings + { + Q_OBJECT + + public: + + // Location, name, and format of settings file determined by + // settings in qt_application class construtor. -public: + gui_settings (QObject *parent = nullptr) + : QSettings (parent) + { } + + gui_settings (const QString& file_name, QSettings::Format format, + QObject *parent = nullptr) + : QSettings (file_name, format, parent) + { } - gui_settings (const QString& file_name, QSettings::Format format, - QObject *parent = nullptr) - : QSettings (file_name, format, parent) - { } + gui_settings (QSettings::Format format, QSettings::Scope scope, + const QString& organization, + const QString& application = QString (), + QObject *parent = nullptr) + : QSettings (format, scope, organization, application, parent) + { } + + // No copying! - gui_settings (QSettings::Format format, QSettings::Scope scope, - const QString& organization, - const QString& application = QString (), - QObject *parent = nullptr) - : QSettings (format, scope, organization, application, parent) - { } + gui_settings (const gui_settings&) = delete; + + gui_settings& operator = (const gui_settings&) = delete; + + ~gui_settings () = default; + + QString file_name () const; + + QString directory_name () const; + + using QSettings::value; - // No copying! + QVariant value (const gui_pref& pref) const + { + if (pref.ignore ()) + return pref.def (); // ignore the current pref and always use default - gui_settings (const gui_settings&) = delete; + return value (pref.settings_key (), pref.def ()); + } - gui_settings& operator = (const gui_settings&) = delete; + // 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 () - ~gui_settings (void) = default; + bool bool_value (const gui_pref& pref) const; + + QByteArray byte_array_value (const gui_pref& pref) const; - using QSettings::value; + 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; - QVariant value (const gui_pref& pref) const - { - if (pref.ignore) - return pref.def; // ignore the current pref and always use default - - return value (pref.key, pref.def); - } + /*! + 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} - /*! - 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} + @param def Color default value given by a QVariant of QColor + 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) const; + + /*! + Reading a color from the gui_settings taking possible 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 (see get_color_value()) + + @param pref gui preference (key string, default value); the default + 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) const; - @param def Color default value given by a QVariant of QColor - or QPalette::ColorRole - @param mode Color mode (currently 0 or 1, default is 0) + /*! + Writing a color to the gui_settings taking possible color modes + into account. When @p mode is not zero (standard mode), the + extension related to the mode is appended to the settings key string + + @param pref gui preference where the color should be written + @param color QColor to write to the settings + @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; + */ + void set_color_value (const gui_pref& pref, const QColor& color, + int mode); + + QString sc_value (const sc_pref& pref) const; - /*! - Reading a color from the gui_settings taking possible 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 (see get_color_value()) + 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); - @param pref gui preference (key string, default value); the default - value can be given by QColor or QPalette::ColorRole - @param mode Color mode (currently 0 or 1, default is 0) + // 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. - @return Color as QColor - */ - QColor color_value (const gui_pref& pref, int mode = 0) const; + void config_icon_theme (); + + QIcon icon (const QString& icon_name, bool octave_only = false, + const QString& icon_alt_name = QString ()); - /*! - Writing a color to the gui_settings taking possible color modes - into account. When @p mode is not zero (standard mode), the - extension related to the mode is appended to the settings key string + QString get_default_font_family (); + + QStringList get_default_font (); + + QString get_gui_translation_dir (); - @param pref gui preference where the color should be written - @param color QColor to write to the settings - @param mode Color mode (currently 0 or 1, default is 0) + 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 set_color_value (const gui_pref& pref, const QColor& color, - int mode = 0); + void update_network_settings (); + + void get_codecs (QStringList *codecs); + + void combo_encoding (QComboBox *combo, const QString& current = QString ()); - QString sc_value (const sc_pref& pref) const; + void reload (); - QKeySequence sc_def_value (const sc_pref& pref) const; + private: -}; + void check (); + }; OCTAVE_END_NAMESPACE(octave) @@ -134,3 +227,4 @@ const int settings_reload_default_colors_flag = -1; #endif + diff -r 17d568574e1c -r 7860fcc69082 libgui/src/gui-utils.cc --- a/libgui/src/gui-utils.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/gui-utils.cc Mon Jan 30 18:36:03 2023 +0100 @@ -117,8 +117,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 17d568574e1c -r 7860fcc69082 libgui/src/history-dock-widget.cc --- a/libgui/src/history-dock-widget.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/history-dock-widget.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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,329 +47,325 @@ OCTAVE_BEGIN_NAMESPACE(octave) -history_dock_widget::history_dock_widget (QWidget *p, base_qobject& oct_qobj) -: octave_dock_widget ("HistoryDockWidget", p, oct_qobj) -{ - setStatusTip (tr ("Browse and search the command history.")); + history_dock_widget::history_dock_widget (QWidget *p) + : octave_dock_widget ("HistoryDockWidget", p) + { + setStatusTip (tr ("Browse and search the command history.")); - construct (); + construct (); - if (! p) - make_window (); -} + if (! p) + make_window (); + } -void history_dock_widget::set_history (const QStringList& hist) -{ - m_history_model->setStringList (hist); - m_history_list_view->scrollToBottom (); -} + void history_dock_widget::set_history (const QStringList& hist) + { + m_history_model->setStringList (hist); + m_history_list_view->scrollToBottom (); + } -void history_dock_widget::append_history (const QString& hist_entry) -{ - QStringList lst = m_history_model->stringList (); - lst.append (hist_entry); + void history_dock_widget::append_history (const QString& hist_entry) + { + QStringList lst = m_history_model->stringList (); + lst.append (hist_entry); - QScrollBar *scroll_bar = m_history_list_view->verticalScrollBar (); + QScrollBar *scroll_bar = m_history_list_view->verticalScrollBar (); - bool at_bottom = scroll_bar->maximum () - scroll_bar->value () < 1; + bool at_bottom = scroll_bar->maximum () - scroll_bar->value () < 1; - m_history_model->setStringList (lst); + m_history_model->setStringList (lst); - // Scroll if slider position at bottom. - if (at_bottom) - m_history_list_view->scrollToBottom (); -} + // Scroll if slider position at bottom. + if (at_bottom) + m_history_list_view->scrollToBottom (); + } -void history_dock_widget::clear_history (void) -{ - m_history_model->setStringList (QStringList ()); -} + void history_dock_widget::clear_history () + { + m_history_model->setStringList (QStringList ()); + } -void history_dock_widget::save_settings (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + void history_dock_widget::save_settings () + { + gui_settings settings; - if (! settings) - return; + settings.setValue (hw_filter_active.settings_key (), m_filter_checkbox->isChecked ()); + settings.setValue (hw_filter_shown.settings_key (), m_filter_shown); - settings->setValue (hw_filter_active.key, m_filter_checkbox->isChecked ()); - settings->setValue (hw_filter_shown.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.settings_key (), mru); - 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.sync (); - settings->sync (); - - octave_dock_widget::save_settings (); -} + octave_dock_widget::save_settings (); + } -void history_dock_widget::update_filter_history (void) -{ - QString text = m_filter->currentText (); // get current text - int index = m_filter->findText (text); // and its actual index + 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 - if (index > -1) - m_filter->removeItem (index); // remove if already existing + if (index > -1) + m_filter->removeItem (index); // remove if already existing - m_filter->insertItem (0, text); // (re)insert at beginning - m_filter->setCurrentIndex (0); -} + m_filter->insertItem (0, text); // (re)insert at beginning + m_filter->setCurrentIndex (0); + } -void history_dock_widget::set_filter_focus (bool focus) -{ - if (focus) - { - m_filter->setFocus (); - setFocusProxy (m_filter); - } - else - { - m_history_list_view->setFocus (); - setFocusProxy (m_history_list_view); - } -} + void history_dock_widget::set_filter_focus (bool focus) + { + if (focus) + { + m_filter->setFocus (); + setFocusProxy (m_filter); + } + else + { + m_history_list_view->setFocus (); + setFocusProxy (m_history_list_view); + } + } -void history_dock_widget::filter_activate (bool state) -{ - m_filter->setEnabled (state); - m_sort_filter_proxy_model.setDynamicSortFilter (state); + void history_dock_widget::filter_activate (bool state) + { + m_filter->setEnabled (state); + m_sort_filter_proxy_model.setDynamicSortFilter (state); - if (state) - m_sort_filter_proxy_model.setFilterWildcard (m_filter->currentText ()); - else - m_sort_filter_proxy_model.setFilterWildcard (QString ()); + if (state) + m_sort_filter_proxy_model.setFilterWildcard (m_filter->currentText ()); + else + m_sort_filter_proxy_model.setFilterWildcard (QString ()); - set_filter_focus (state); -} + set_filter_focus (state); + } -void history_dock_widget::ctxMenu (const QPoint& xpos) -{ - QMenu menu (this); + void history_dock_widget::ctxMenu (const QPoint& xpos) + { + QMenu menu (this); - QModelIndex index = m_history_list_view->indexAt (xpos); + QModelIndex index = m_history_list_view->indexAt (xpos); - if (index.isValid () && index.column () == 0) - { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + if (index.isValid () && index.column () == 0) + { + gui_settings settings; - menu.addAction (rmgr.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, - &history_dock_widget::handle_contextmenu_create_script); - } - if (m_filter_shown) - menu.addAction (tr ("Hide filter"), this, - &history_dock_widget::handle_contextmenu_filter); - else - menu.addAction (tr ("Show filter"), this, - &history_dock_widget::handle_contextmenu_filter); + 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 (settings.icon ("document-new"), tr ("Create script"), this, + &history_dock_widget::handle_contextmenu_create_script); + } + if (m_filter_shown) + menu.addAction (tr ("Hide filter"), this, + &history_dock_widget::handle_contextmenu_filter); + else + menu.addAction (tr ("Show filter"), this, + &history_dock_widget::handle_contextmenu_filter); - menu.exec (m_history_list_view->mapToGlobal (xpos)); -} + menu.exec (m_history_list_view->mapToGlobal (xpos)); + } -void history_dock_widget::handle_double_click (QModelIndex modelIndex) -{ - emit command_double_clicked (modelIndex.data ().toString ()); -} + void history_dock_widget::handle_double_click (QModelIndex modelIndex) + { + emit command_double_clicked (modelIndex.data ().toString ()); + } -void history_dock_widget::handle_contextmenu_copy (bool) -{ - QString text; - 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++) - { - if ((*it).isValid ()) - { - if (prev_valid_row) - text += '\n'; - text += (*it).data ().toString (); - prev_valid_row = true; - } - } - QApplication::clipboard ()->setText (text); -} + void history_dock_widget::handle_contextmenu_copy (bool) + { + QString text; + 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++) + { + if ((*it).isValid ()) + { + if (prev_valid_row) + text += '\n'; + text += (*it).data ().toString (); + prev_valid_row = true; + } + } + QApplication::clipboard ()->setText (text); + } -void history_dock_widget::handle_contextmenu_evaluate (bool) -{ - 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 ()); - } -} + void history_dock_widget::handle_contextmenu_evaluate (bool) + { + 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 ()); + } + } -void history_dock_widget::handle_contextmenu_create_script (bool) -{ - QString text; - QItemSelectionModel *selectionModel = m_history_list_view->selectionModel (); - QModelIndexList rows = selectionModel->selectedRows (); + void history_dock_widget::handle_contextmenu_create_script (bool) + { + QString text; + 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++) - { - if ((*it).isValid ()) - { - if (prev_valid_row) - text += '\n'; - text += (*it).data ().toString (); - prev_valid_row = true; - } - } + bool prev_valid_row = false; + for (auto it = rows.begin (); it != rows.end (); it++) + { + if ((*it).isValid ()) + { + if (prev_valid_row) + text += '\n'; + text += (*it).data ().toString (); + prev_valid_row = true; + } + } - if (text.length () > 0) - emit command_create_script (text); -} + if (text.length () > 0) + emit command_create_script (text); + } -void history_dock_widget::handle_contextmenu_filter (void) -{ - m_filter_shown = ! m_filter_shown; - m_filter_widget->setVisible (m_filter_shown); + void history_dock_widget::handle_contextmenu_filter () + { + m_filter_shown = ! m_filter_shown; + m_filter_widget->setVisible (m_filter_shown); - set_filter_focus (m_filter_shown && m_filter_checkbox->isChecked ()) ; -} + set_filter_focus (m_filter_shown && m_filter_checkbox->isChecked ()) ; + } -void history_dock_widget::copyClipboard (void) -{ - if (m_history_list_view->hasFocus ()) - handle_contextmenu_copy (true); - if (m_filter->lineEdit ()->hasFocus () - && m_filter->lineEdit ()->hasSelectedText ()) - { - QClipboard *clipboard = QApplication::clipboard (); - clipboard->setText (m_filter->lineEdit ()->selectedText ()); - } -} + void history_dock_widget::copyClipboard () + { + if (m_history_list_view->hasFocus ()) + handle_contextmenu_copy (true); + if (m_filter->lineEdit ()->hasFocus () + && m_filter->lineEdit ()->hasSelectedText ()) + { + QClipboard *clipboard = QApplication::clipboard (); + clipboard->setText (m_filter->lineEdit ()->selectedText ()); + } + } -void history_dock_widget::pasteClipboard (void) -{ - if (m_filter->lineEdit ()->hasFocus ()) - { - QClipboard *clipboard = QApplication::clipboard (); - QString str = clipboard->text (); - if (str.length () > 0) - m_filter->lineEdit ()->insert (str); - } -} + void history_dock_widget::pasteClipboard () + { + if (m_filter->lineEdit ()->hasFocus ()) + { + QClipboard *clipboard = QApplication::clipboard (); + QString str = clipboard->text (); + if (str.length () > 0) + m_filter->lineEdit ()->insert (str); + } + } -void history_dock_widget::selectAll (void) -{ - if (m_filter->lineEdit ()->hasFocus ()) - m_filter->lineEdit ()->selectAll (); + void history_dock_widget::selectAll () + { + if (m_filter->lineEdit ()->hasFocus ()) + m_filter->lineEdit ()->selectAll (); - if (m_history_list_view->hasFocus ()) - m_history_list_view->selectAll (); -} + if (m_history_list_view->hasFocus ()) + m_history_list_view->selectAll (); + } -void history_dock_widget::handle_visibility (bool visible) -{ - octave_dock_widget::handle_visibility (visible); + void history_dock_widget::handle_visibility (bool visible) + { + octave_dock_widget::handle_visibility (visible); - if (visible) - { - int filter_state = m_filter_checkbox->isChecked (); - filter_activate (filter_state); - } -} + if (visible) + { + int filter_state = m_filter_checkbox->isChecked (); + filter_activate (filter_state); + } + } -void history_dock_widget::construct (void) -{ - m_history_model = new QStringListModel (); - m_sort_filter_proxy_model.setSourceModel (m_history_model); - m_history_list_view = new QListView (this); - m_history_list_view->setModel (&m_sort_filter_proxy_model); - m_history_list_view->setAlternatingRowColors (true); - m_history_list_view->setEditTriggers (QAbstractItemView::NoEditTriggers); - m_history_list_view->setStatusTip - (tr ("Double-click a command to transfer it to the Command Window.")); - m_history_list_view->setSelectionMode (QAbstractItemView::ExtendedSelection); - m_history_list_view->setContextMenuPolicy (Qt::CustomContextMenu); - connect (m_history_list_view, &QListView::customContextMenuRequested, - this, &history_dock_widget::ctxMenu); + void history_dock_widget::construct () + { + m_history_model = new QStringListModel (); + m_sort_filter_proxy_model.setSourceModel (m_history_model); + m_history_list_view = new QListView (this); + m_history_list_view->setModel (&m_sort_filter_proxy_model); + m_history_list_view->setAlternatingRowColors (true); + m_history_list_view->setEditTriggers (QAbstractItemView::NoEditTriggers); + m_history_list_view->setStatusTip + (tr ("Double-click a command to transfer it to the Command Window.")); + m_history_list_view->setSelectionMode (QAbstractItemView::ExtendedSelection); + m_history_list_view->setContextMenuPolicy (Qt::CustomContextMenu); + connect (m_history_list_view, &QListView::customContextMenuRequested, + this, &history_dock_widget::ctxMenu); - m_filter = new QComboBox (this); - m_filter->setToolTip (tr ("Enter text to filter the command history")); - m_filter->setEditable (true); - m_filter->setMaxCount (MaxFilterHistory); - m_filter->setInsertPolicy (QComboBox::NoInsert); - m_filter->setSizeAdjustPolicy - (QComboBox::AdjustToMinimumContentsLengthWithIcon); - QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); - m_filter->setSizePolicy (sizePol); - m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); + m_filter = new QComboBox (this); + m_filter->setToolTip (tr ("Enter text to filter the command history")); + m_filter->setEditable (true); + m_filter->setMaxCount (MaxFilterHistory); + m_filter->setInsertPolicy (QComboBox::NoInsert); + m_filter->setSizeAdjustPolicy + (QComboBox::AdjustToMinimumContentsLengthWithIcon); + QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); + m_filter->setSizePolicy (sizePol); + m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); - QLabel *filter_label = new QLabel (tr ("Filter")); + QLabel *filter_label = new QLabel (tr ("Filter")); - m_filter_checkbox = new QCheckBox (); + m_filter_checkbox = new QCheckBox (); - set_title (tr ("Command History")); - setWidget (new QWidget ()); + set_title (tr ("Command History")); + setWidget (new QWidget ()); - m_filter_widget = new QWidget (this); - QHBoxLayout *filter_layout = new QHBoxLayout (); - filter_layout->addWidget (filter_label); - filter_layout->addWidget (m_filter_checkbox); - filter_layout->addWidget (m_filter); - filter_layout->setMargin(0); - m_filter_widget->setLayout (filter_layout); + m_filter_widget = new QWidget (this); + QHBoxLayout *filter_layout = new QHBoxLayout (); + filter_layout->addWidget (filter_label); + filter_layout->addWidget (m_filter_checkbox); + filter_layout->addWidget (m_filter); + filter_layout->setMargin(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); + QVBoxLayout *hist_layout = new QVBoxLayout (); + hist_layout->addWidget (m_filter_widget); + hist_layout->addWidget (m_history_list_view); - hist_layout->setMargin (2); - hist_layout->setSpacing (0); - widget ()->setLayout (hist_layout); + hist_layout->setMargin (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 (); + // Init state of the filter + + gui_settings settings; - m_filter_shown - = settings->value (hw_filter_shown).toBool (); - m_filter_widget->setVisible (m_filter_shown); + 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 (); - m_filter_checkbox->setChecked (filter_state); - filter_activate (filter_state); + bool filter_state = settings.bool_value (hw_filter_active); + m_filter_checkbox->setChecked (filter_state); + filter_activate (filter_state); - // Connect signals and slots - connect (m_filter, &QComboBox::editTextChanged, - &m_sort_filter_proxy_model, - &QSortFilterProxyModel::setFilterWildcard); - connect (m_filter_checkbox, &QCheckBox::toggled, - this, &history_dock_widget::filter_activate); - connect (m_filter->lineEdit (), &QLineEdit::editingFinished, - this, &history_dock_widget::update_filter_history); + // Connect signals and slots + connect (m_filter, &QComboBox::editTextChanged, + &m_sort_filter_proxy_model, + &QSortFilterProxyModel::setFilterWildcard); + connect (m_filter_checkbox, &QCheckBox::toggled, + this, &history_dock_widget::filter_activate); + connect (m_filter->lineEdit (), &QLineEdit::editingFinished, + this, &history_dock_widget::update_filter_history); - connect (m_history_list_view, &QListView::doubleClicked, - this, &history_dock_widget::handle_double_click); + connect (m_history_list_view, &QListView::doubleClicked, + this, &history_dock_widget::handle_double_click); + + m_history_list_view->setTextElideMode (Qt::ElideRight); + } - m_history_list_view->setTextElideMode (Qt::ElideRight); -} + void history_dock_widget::notice_settings () + { + gui_settings settings; -void history_dock_widget::notice_settings (const gui_settings *settings) -{ - QFont font = QFont (); + QFont font = QFont (); - font.setStyleHint (QFont::TypeWriter); - QString default_font = settings->value (global_mono_font).toString (); + font.setStyleHint (QFont::TypeWriter); + 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); -} + m_history_list_view->setFont (font); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/history-dock-widget.h --- a/libgui/src/history-dock-widget.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/history-dock-widget.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,75 +37,73 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class history_dock_widget : public octave_dock_widget + { + Q_OBJECT -class history_dock_widget : public octave_dock_widget -{ - Q_OBJECT - -public: + 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: + signals: - //! Signal emitted whenever the user double-clicks a command in the - //! history. + //! Signal emitted whenever the user double-clicks a command in the + //! history. - void command_double_clicked (const QString& command); + void command_double_clicked (const QString& command); - //! Signal emitted whenever the user selects commands and chooses - //! "Create script" from the popup menu. + //! Signal emitted whenever the user selects commands and chooses + //! "Create script" from the popup menu. - void command_create_script (const QString& commands); + void command_create_script (const QString& commands); -public slots: + public slots: - 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 set_history (const QStringList& hist); + void append_history (const QString& hist_entry); + void clear_history (); + void save_settings (); + void notice_settings (); -private slots: + private slots: - void update_filter_history (void); - void filter_activate (bool enable); + void update_filter_history (); + void filter_activate (bool enable); - void ctxMenu (const QPoint& pos); - void handle_double_click (QModelIndex modelIndex); - 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 ctxMenu (const QPoint& pos); + void handle_double_click (QModelIndex modelIndex); + void handle_contextmenu_copy (bool flag); + void handle_contextmenu_evaluate (bool flag); + void handle_contextmenu_create_script (bool flag); + 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); + virtual void handle_visibility (bool visible); -private: + private: - void construct (void); - void set_filter_focus (bool focus); + void construct (); + void set_filter_focus (bool focus); - QListView *m_history_list_view; - QSortFilterProxyModel m_sort_filter_proxy_model; + QListView *m_history_list_view; + QSortFilterProxyModel m_sort_filter_proxy_model; - //! Stores the current history_model. + //! Stores the current history_model. - QStringListModel *m_history_model; + QStringListModel *m_history_model; - QCheckBox *m_filter_checkbox; - QComboBox *m_filter; - QWidget *m_filter_widget; - bool m_filter_shown; + QCheckBox *m_filter_checkbox; + QComboBox *m_filter; + QWidget *m_filter_widget; + bool m_filter_shown; - enum { MaxFilterHistory = 10 }; -}; + enum { MaxFilterHistory = 10 }; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/interpreter-qobject.cc --- a/libgui/src/interpreter-qobject.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/interpreter-qobject.cc Mon Jan 30 18:36:03 2023 +0100 @@ -38,166 +38,164 @@ OCTAVE_BEGIN_NAMESPACE(octave) -interpreter_qobject::interpreter_qobject (base_qobject& oct_qobj) -: QObject (), m_octave_qobj (oct_qobj), m_interpreter (nullptr) -{ } + interpreter_qobject::interpreter_qobject (base_qobject& oct_qobj) + : QObject (), m_octave_qobj (oct_qobj), m_interpreter (nullptr) + { } + + void interpreter_qobject::execute () + { + // The Octave application context owns the interpreter. + + qt_application& app_context = m_octave_qobj.app_context (); -void interpreter_qobject::execute (void) -{ - // The Octave application context owns the interpreter. + interpreter& interp = app_context.create_interpreter (); + + event_manager& evmgr = interp.get_event_manager (); - qt_application& app_context = m_octave_qobj.app_context (); + evmgr.connect_link (m_octave_qobj.get_qt_interpreter_events ()); + evmgr.install_qt_event_handlers (m_octave_qobj.get_qt_interpreter_events ()); + evmgr.enable (); - interpreter& interp = app_context.create_interpreter (); - - event_manager& evmgr = interp.get_event_manager (); + int exit_status = 0; - evmgr.connect_link (m_octave_qobj.get_qt_interpreter_events ()); - evmgr.install_qt_event_handlers (m_octave_qobj.get_qt_interpreter_events ()); - evmgr.enable (); + try + { + // Final initialization. - int exit_status = 0; - - try - { - // Final initialization. + interp.initialize (); - interp.initialize (); + if (app_context.start_gui_p () + && ! m_octave_qobj.experimental_terminal_widget ()) + { + interp.PS1 (">> "); + interp.PS2 (""); + } - if (app_context.start_gui_p () - && ! m_octave_qobj.experimental_terminal_widget ()) - { - input_system& input_sys = interp.get_input_system (); + if (interp.initialized ()) + { + // The interpreter should be completely ready at this point so let + // the GUI know. - input_sys.PS1 (">> "); - input_sys.PS2 (""); - } + m_interpreter = &interp; - if (interp.initialized ()) - { - // The interpreter should be completely ready at this point so let - // the GUI know. + emit ready (); - m_interpreter = &interp; + graphics_init (interp); - emit ready (); + // Start executing commands in the command window. - graphics_init (interp, m_octave_qobj); - - // Start executing commands in the command window. + exit_status = interp.execute (); + } + } + catch (const exit_exception& xe) + { + exit_status = xe.exit_status (); + } - exit_status = interp.execute (); - } - } - catch (const exit_exception& xe) - { - exit_status = xe.exit_status (); - } + // FIXME: The following comment doesn't seem to make sense now. - // FIXME: The following comment doesn't seem to make sense now. + // Signal that the interpreter is done executing code in the + // main REPL, from script files, or command line eval arguments. + // By using a signal here, we give the GUI a chance to process + // any pending events, then signal that it is safe to shutdown + // the interpreter. Our notification here allows the GUI to + // insert the request to shutdown the interpreter in the event + // queue after any other pending signals. The application + // context owns the interpreter and will be responsible for + // deleting it later, when the application object destructor is + // executed. - // Signal that the interpreter is done executing code in the - // main REPL, from script files, or command line eval arguments. - // By using a signal here, we give the GUI a chance to process - // any pending events, then signal that it is safe to shutdown - // the interpreter. Our notification here allows the GUI to - // insert the request to shutdown the interpreter in the event - // queue after any other pending signals. The application - // context owns the interpreter and will be responsible for - // deleting it later, when the application object destructor is - // executed. + emit shutdown_finished (exit_status); + } - emit shutdown_finished (exit_status); -} + void interpreter_qobject::interpreter_event (const fcn_callback& fcn) + { + if (! m_interpreter) + return; -void interpreter_qobject::interpreter_event (const fcn_callback& fcn) -{ - if (! m_interpreter) - return; + event_manager& evmgr = m_interpreter->get_event_manager (); - event_manager& evmgr = m_interpreter->get_event_manager (); + evmgr.post_event (fcn); + } - evmgr.post_event (fcn); -} + void interpreter_qobject::interpreter_event (const meth_callback& meth) + { + if (! m_interpreter) + return; -void interpreter_qobject::interpreter_event (const meth_callback& meth) -{ - if (! m_interpreter) - return; + event_manager& evmgr = m_interpreter->get_event_manager (); - event_manager& evmgr = m_interpreter->get_event_manager (); - - evmgr.post_event (meth); -} + evmgr.post_event (meth); + } -void interpreter_qobject::interrupt (void) -{ - if (! m_interpreter) - return; + void interpreter_qobject::interrupt () + { + if (! m_interpreter) + return; + + // The following is a direct function call across threads. + // We need to ensure that it uses thread-safe functions. - // The following is a direct function call across threads. - // We need to ensure that it uses thread-safe functions. + m_interpreter->interrupt (); + } - m_interpreter->interrupt (); -} - -void interpreter_qobject::pause (void) -{ - // FIXME: Should we make this action work with the old terminal - // widget? + void interpreter_qobject::pause () + { + // FIXME: Should we make this action work with the old terminal + // widget? - if (m_octave_qobj.experimental_terminal_widget ()) - { - if (! m_interpreter) - return; + if (m_octave_qobj.experimental_terminal_widget ()) + { + if (! m_interpreter) + return; - // The following is a direct function call across threads. - // We need to ensure that it uses thread-safe functions. + // The following is a direct function call across threads. + // We need to ensure that it uses thread-safe functions. - m_interpreter->pause (); - } -} + m_interpreter->pause (); + } + } -void interpreter_qobject::stop (void) -{ - // FIXME: Should we make this action work with the old terminal - // widget? + void interpreter_qobject::stop () + { + // FIXME: Should we make this action work with the old terminal + // widget? - if (m_octave_qobj.experimental_terminal_widget ()) - { - if (! m_interpreter) - return; + if (m_octave_qobj.experimental_terminal_widget ()) + { + if (! m_interpreter) + return; - // The following is a direct function call across threads. - // We need to ensure that it uses thread-safe functions. + // The following is a direct function call across threads. + // We need to ensure that it uses thread-safe functions. - m_interpreter->stop (); - } -} + m_interpreter->stop (); + } + } -void interpreter_qobject::resume (void) -{ - // FIXME: Should we make this action work with the old terminal - // widget? + void interpreter_qobject::resume () + { + // FIXME: Should we make this action work with the old terminal + // widget? - if (m_octave_qobj.experimental_terminal_widget ()) - { - // FIXME: This action should only be available when the - // interpreter is paused. + if (m_octave_qobj.experimental_terminal_widget ()) + { + // FIXME: This action should only be available when the + // interpreter is paused. - interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD + interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD - interp.resume (); - }); - } -} + interp.resume (); + }); + } + } -qt_interpreter_events *interpreter_qobject::qt_link (void) -{ - return m_octave_qobj.qt_link (); -} + qt_interpreter_events *interpreter_qobject::qt_link () + { + return m_octave_qobj.qt_link (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/interpreter-qobject.h --- a/libgui/src/interpreter-qobject.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/interpreter-qobject.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/led-indicator.cc --- a/libgui/src/led-indicator.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/led-indicator.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/file-editor-interface.h --- a/libgui/src/m-editor/file-editor-interface.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/file-editor-interface.h Mon Jan 30 18:36:03 2023 +0100 @@ -30,77 +30,74 @@ #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 -class file_editor_interface : public octave_dock_widget -{ - Q_OBJECT + public: -public: + file_editor_interface (QWidget *p) + : octave_dock_widget ("FileEditor", p) + { } - file_editor_interface (QWidget *p, base_qobject& oct_qobj) - : octave_dock_widget ("FileEditor", p, oct_qobj) - { } - - 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 insert_global_actions (QList) = 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; + virtual void + handle_insert_debugger_pointer_request (const QString& file, int line) = 0; - virtual void - handle_delete_debugger_pointer_request (const QString& file, int line) = 0; + virtual void + handle_delete_debugger_pointer_request (const QString& file, int line) = 0; - virtual void - handle_update_breakpoint_marker_request (bool insert, const QString& file, - int line, const QString& cond) = 0; + virtual void + handle_update_breakpoint_marker_request (bool insert, const QString& file, + int line, const QString& cond) = 0; - virtual void handle_edit_file_request (const QString& file) = 0; + 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 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; + virtual void enable_menu_shortcuts (bool enable) = 0; -signals: + signals: - void interpreter_event (const fcn_callback& fcn); - void interpreter_event (const meth_callback& meth); + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); -public slots: + public slots: - virtual void toplevel_change (bool) = 0; + virtual void toplevel_change (bool) = 0; - virtual void handle_file_remove (const QString& o, const QString& n) = 0; + virtual void handle_file_remove (const QString& o, const QString& n) = 0; - virtual void request_new_file (const QString& command = QString ()) = 0; + virtual void request_new_file (const QString& command = QString ()) = 0; - virtual void request_open_file (const QString& openFileName, - const QString& encoding = QString (), - int line = -1, - bool debug_pointer = false, - bool breakpoint_marker = false, - bool insert = true, - const QString& cond = "", - int index = -1, - const QString& bookmarks = QString ()) = 0; -}; + virtual void request_open_file (const QString& openFileName, + const QString& encoding = QString (), + int line = -1, + bool debug_pointer = false, + bool breakpoint_marker = false, + bool insert = true, + const QString& cond = "", + int index = -1, + const QString& bookmarks = QString ()) = 0; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/file-editor-tab.cc Mon Jan 30 18:36:03 2023 +0100 @@ -71,10 +71,9 @@ #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" @@ -97,3285 +96,3277 @@ OCTAVE_BEGIN_NAMESPACE(octave) -//! A file_editor_tab object consists of a text area and three left margins. -//! The first holds breakpoints, bookmarks, and the debug program counter. -//! The second holds line numbers. The third holds "fold" marks, to hide -//! sections of text. - -// 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) -{ - m_lexer_apis = nullptr; - m_is_octave_file = true; - m_lines_changed = false; - m_autoc_active = false; - - m_ced = directory_arg; - - m_file_name = ""; - m_file_system_watcher.setObjectName ("_qt_autotest_force_engine_poller"); - - m_edit_area = new octave_qscintilla (this, m_octave_qobj); - m_line = 0; - m_col = 0; - - m_bp_lines.clear (); // start with empty lists of breakpoints - m_bp_conditions.clear (); - m_bp_restore_count = 0; - - m_breakpoint_info.remove_next = false; - m_breakpoint_info.remove_line = -1; - - // Initialize last modification date to now - m_last_modified = QDateTime::currentDateTimeUtc(); - - connect (m_edit_area, SIGNAL (cursorPositionChanged (int, int)), - this, SLOT (handle_cursor_moved (int,int))); - - connect (m_edit_area, SIGNAL (SCN_CHARADDED (int)), - this, SLOT (handle_char_added (int))); - - connect (m_edit_area, SIGNAL (SCN_DOUBLECLICK (int, int, int)), - this, SLOT (handle_double_click (int, int, int))); - - connect (m_edit_area, SIGNAL (linesChanged ()), - this, SLOT (handle_lines_changed ())); - - connect (m_edit_area, &octave_qscintilla::context_menu_edit_signal, - this, &file_editor_tab::handle_context_menu_edit); - - connect (m_edit_area, &octave_qscintilla::update_rowcol_indicator_signal, - this, &file_editor_tab::update_rowcol_indicator); - - // create statusbar for row/col indicator and eol mode - m_status_bar = new QStatusBar (this); - - // row- and col-indicator - m_row_indicator = new QLabel ("", this); - QFontMetrics fm = m_row_indicator->fontMetrics (); - m_row_indicator->setMinimumSize (4.5*fm.averageCharWidth (), 0); - QLabel *row_label = new QLabel (tr ("line:"), this); - m_col_indicator = new QLabel ("", this); - m_col_indicator->setMinimumSize (4*fm.averageCharWidth (), 0); - QLabel *col_label = new QLabel (tr ("col:"), this); - m_status_bar->addWidget (row_label, 0); - m_status_bar->addWidget (m_row_indicator, 0); - m_status_bar->addWidget (col_label, 0); - m_status_bar->addWidget (m_col_indicator, 0); - - // status bar: encoding - QLabel *enc_label = new QLabel (tr ("encoding:"), this); - m_enc_indicator = new QLabel ("", this); - m_status_bar->addWidget (enc_label, 0); - m_status_bar->addWidget (m_enc_indicator, 0); - m_status_bar->addWidget (new QLabel (" ", this), 0); - - // status bar: eol mode - QLabel *eol_label = new QLabel (tr ("eol:"), this); - m_eol_indicator = new QLabel ("", this); - m_status_bar->addWidget (eol_label, 0); - m_status_bar->addWidget (m_eol_indicator, 0); - m_status_bar->addWidget (new QLabel (" ", this), 0); - - // symbols - m_edit_area->setMarginType (1, QsciScintilla::SymbolMargin); - m_edit_area->setMarginSensitivity (1, true); - m_edit_area->markerDefine (QsciScintilla::RightTriangle, marker::bookmark); - m_edit_area->setMarkerBackgroundColor (QColor (0, 0, 232), marker::bookmark); - m_edit_area->markerDefine (QsciScintilla::Circle, marker::breakpoint); - m_edit_area->setMarkerBackgroundColor (QColor (192, 0, 0), marker::breakpoint); - m_edit_area->markerDefine (QsciScintilla::Circle, marker::cond_break); - m_edit_area->setMarkerBackgroundColor (QColor (255, 127, 0), marker::cond_break); - m_edit_area->markerDefine (QsciScintilla::RightArrow, - marker::debugger_position); - m_edit_area->setMarkerBackgroundColor (QColor (255, 255, 0), - marker::debugger_position); - m_edit_area->markerDefine (QsciScintilla::RightArrow, - marker::unsure_debugger_position); - m_edit_area->setMarkerBackgroundColor (QColor (192, 192, 192), - marker::unsure_debugger_position); - - connect (m_edit_area, SIGNAL (marginClicked (int, int, - Qt::KeyboardModifiers)), - this, SLOT (handle_margin_clicked (int, int, - Qt::KeyboardModifiers))); - - connect (m_edit_area, &octave_qscintilla::context_menu_break_condition_signal, - this, &file_editor_tab::handle_context_menu_break_condition); - - // line numbers - m_edit_area->setMarginsForegroundColor (QColor (96, 96, 96)); - m_edit_area->setMarginsBackgroundColor (QColor (232, 232, 220)); - m_edit_area->setMarginType (2, QsciScintilla::TextMargin); - - // other features - m_edit_area->setBraceMatching (QsciScintilla::StrictBraceMatch); - m_edit_area->setAutoIndent (true); - m_edit_area->setIndentationWidth (2); - m_edit_area->setIndentationsUseTabs (false); - - m_edit_area->setUtf8 (true); - - // auto completion - m_edit_area->SendScintilla (QsciScintillaBase::SCI_AUTOCSETCANCELATSTART, false); - - 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->setSpacing (0); - setLayout (edit_area_layout); - - // Any interpreter_event signal from a file_editor_tab_widget is - // handled the same as for the parent main_window object. - - connect (m_edit_area, QOverload::of (&octave_qscintilla::interpreter_event), - this, QOverload::of (&file_editor_tab::interpreter_event)); - - connect (m_edit_area, QOverload::of (&octave_qscintilla::interpreter_event), - this, QOverload::of (&file_editor_tab::interpreter_event)); - - // connect modified signal - connect (m_edit_area, SIGNAL (modificationChanged (bool)), - this, SLOT (update_window_title (bool))); - - connect (m_edit_area, SIGNAL (copyAvailable (bool)), - this, SLOT (handle_copy_available (bool))); - - connect (&m_file_system_watcher, &QFileSystemWatcher::fileChanged, - this, [=] (const QString& path) { file_has_changed (path); }); - - connect (this, &file_editor_tab::maybe_remove_next, - this, &file_editor_tab::handle_remove_next); - - connect (this, &file_editor_tab::dbstop_if, - this, &file_editor_tab::handle_dbstop_if); - - connect (this, &file_editor_tab::request_add_breakpoint, - this, &file_editor_tab::handle_request_add_breakpoint); - - connect (this, &file_editor_tab::api_entries_added, - this, &file_editor_tab::handle_api_entries_added); - - connect (this, &file_editor_tab::confirm_dbquit_and_save_signal, - this, &file_editor_tab::confirm_dbquit_and_save); - - 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); - - // encoding, not updated with the settings - m_encoding = settings->value (ed_default_enc.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) -{ - // Tell all connected markers to self-destruct. - emit remove_all_breakpoints_signal (); - emit remove_all_positions (); - - // Destroy lexer attached to m_edit_area, which is not the parent - // of lexer - QsciLexer *lexer = m_edit_area->lexer (); - if (lexer) - { - delete lexer; - m_edit_area->setLexer (nullptr); - } -} - -void file_editor_tab::set_encoding (const QString& new_encoding) -{ - if (new_encoding.isEmpty ()) - return; - - m_encoding = new_encoding; - m_enc_indicator->setText (m_encoding); - if (! m_edit_area->text ().isEmpty ()) - set_modified (true); -} - -void file_editor_tab::closeEvent (QCloseEvent *e) -{ - int save_dialog = check_file_modified (true); - if ((save_dialog == QMessageBox::Cancel) || - (save_dialog == QMessageBox::Save)) - { - // Ignore close event if file is saved or user cancels - // closing this window. In case of saving, tab is closed after - // successful saving. - e->ignore (); - } - else - { - e->accept (); - emit tab_remove_request (); - } -} - -void file_editor_tab::set_current_directory (const QString& dir) -{ - m_ced = dir; -} - -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; - 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) - break; - if ((pos_fct = rxfun2.indexIn (lines.at (line))) != -1) - break; - if ((pos_fct = rxfun3.indexIn (lines.at (line))) != -1) - break; - if ((pos_fct = rxfun4.indexIn (lines.at (line))) != -1) - break; - } - - if (pos_fct > -1) - { - // reg expr. found: it is an internal function - m_edit_area->setCursorPosition (line, pos_fct); - m_edit_area->SendScintilla (2232, line); // SCI_ENSUREVISIBLE - // SCI_VISIBLEFROMDOCLINE - int vis_line = m_edit_area->SendScintilla (2220, line); - m_edit_area->SendScintilla (2613, vis_line); // SCI_SETFIRSTVISIBLELINE + //! A file_editor_tab object consists of a text area and three left margins. + //! The first holds breakpoints, bookmarks, and the debug program counter. + //! The second holds line numbers. The third holds "fold" marks, to hide + //! sections of text. + + // Make parent null for the file editor tab so that warning WindowModal + // messages don't affect grandparents. + file_editor_tab::file_editor_tab (const QString& directory_arg) + { + m_lexer_apis = nullptr; + m_is_octave_file = true; + m_lines_changed = false; + m_autoc_active = false; + + m_ced = directory_arg; + + m_file_name = ""; + m_file_system_watcher.setObjectName ("_qt_autotest_force_engine_poller"); + + m_edit_area = new octave_qscintilla (this); + m_line = 0; + m_col = 0; + + m_bp_lines.clear (); // start with empty lists of breakpoints + m_bp_conditions.clear (); + m_bp_restore_count = 0; + + m_breakpoint_info.remove_next = false; + m_breakpoint_info.remove_line = -1; + + // Initialize last modification date to now + m_last_modified = QDateTime::currentDateTimeUtc(); + + connect (m_edit_area, SIGNAL (cursorPositionChanged (int, int)), + this, SLOT (handle_cursor_moved (int,int))); + + connect (m_edit_area, SIGNAL (SCN_CHARADDED (int)), + this, SLOT (handle_char_added (int))); + + connect (m_edit_area, SIGNAL (SCN_DOUBLECLICK (int, int, int)), + this, SLOT (handle_double_click (int, int, int))); + + connect (m_edit_area, SIGNAL (linesChanged ()), + this, SLOT (handle_lines_changed ())); + + connect (m_edit_area, &octave_qscintilla::context_menu_edit_signal, + this, &file_editor_tab::handle_context_menu_edit); + + connect (m_edit_area, &octave_qscintilla::update_rowcol_indicator_signal, + this, &file_editor_tab::update_rowcol_indicator); + + // create statusbar for row/col indicator and eol mode + m_status_bar = new QStatusBar (this); + + // row- and col-indicator + m_row_indicator = new QLabel ("", this); + QFontMetrics fm = m_row_indicator->fontMetrics (); + m_row_indicator->setMinimumSize (4.5*fm.averageCharWidth (), 0); + QLabel *row_label = new QLabel (tr ("line:"), this); + m_col_indicator = new QLabel ("", this); + m_col_indicator->setMinimumSize (4*fm.averageCharWidth (), 0); + QLabel *col_label = new QLabel (tr ("col:"), this); + m_status_bar->addWidget (row_label, 0); + m_status_bar->addWidget (m_row_indicator, 0); + m_status_bar->addWidget (col_label, 0); + m_status_bar->addWidget (m_col_indicator, 0); + + // status bar: encoding + QLabel *enc_label = new QLabel (tr ("encoding:"), this); + m_enc_indicator = new QLabel ("", this); + m_status_bar->addWidget (enc_label, 0); + m_status_bar->addWidget (m_enc_indicator, 0); + m_status_bar->addWidget (new QLabel (" ", this), 0); + + // status bar: eol mode + QLabel *eol_label = new QLabel (tr ("eol:"), this); + m_eol_indicator = new QLabel ("", this); + m_status_bar->addWidget (eol_label, 0); + m_status_bar->addWidget (m_eol_indicator, 0); + m_status_bar->addWidget (new QLabel (" ", this), 0); + + // symbols + m_edit_area->setMarginType (1, QsciScintilla::SymbolMargin); + m_edit_area->setMarginSensitivity (1, true); + m_edit_area->markerDefine (QsciScintilla::RightTriangle, marker::bookmark); + m_edit_area->setMarkerBackgroundColor (QColor (0, 0, 232), marker::bookmark); + m_edit_area->markerDefine (QsciScintilla::Circle, marker::breakpoint); + m_edit_area->setMarkerBackgroundColor (QColor (192, 0, 0), marker::breakpoint); + m_edit_area->markerDefine (QsciScintilla::Circle, marker::cond_break); + m_edit_area->setMarkerBackgroundColor (QColor (255, 127, 0), marker::cond_break); + m_edit_area->markerDefine (QsciScintilla::RightArrow, + marker::debugger_position); + m_edit_area->setMarkerBackgroundColor (QColor (255, 255, 0), + marker::debugger_position); + m_edit_area->markerDefine (QsciScintilla::RightArrow, + marker::unsure_debugger_position); + m_edit_area->setMarkerBackgroundColor (QColor (192, 192, 192), + marker::unsure_debugger_position); + + connect (m_edit_area, SIGNAL (marginClicked (int, int, + Qt::KeyboardModifiers)), + this, SLOT (handle_margin_clicked (int, int, + Qt::KeyboardModifiers))); + + connect (m_edit_area, &octave_qscintilla::context_menu_break_condition_signal, + this, &file_editor_tab::handle_context_menu_break_condition); + + // line numbers + m_edit_area->setMarginsForegroundColor (QColor (96, 96, 96)); + m_edit_area->setMarginsBackgroundColor (QColor (232, 232, 220)); + m_edit_area->setMarginType (2, QsciScintilla::TextMargin); + + // other features + m_edit_area->setBraceMatching (QsciScintilla::StrictBraceMatch); + m_edit_area->setAutoIndent (true); + m_edit_area->setIndentationWidth (2); + m_edit_area->setIndentationsUseTabs (false); + + m_edit_area->setUtf8 (true); + + // auto completion + m_edit_area->SendScintilla (QsciScintillaBase::SCI_AUTOCSETCANCELATSTART, false); + + 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->setSpacing (0); + setLayout (edit_area_layout); + + // Any interpreter_event signal from a file_editor_tab_widget is + // handled the same as for the parent main_window object. + + connect (m_edit_area, QOverload::of (&octave_qscintilla::interpreter_event), + this, QOverload::of (&file_editor_tab::interpreter_event)); + + connect (m_edit_area, QOverload::of (&octave_qscintilla::interpreter_event), + this, QOverload::of (&file_editor_tab::interpreter_event)); + + // connect modified signal + connect (m_edit_area, SIGNAL (modificationChanged (bool)), + this, SLOT (update_window_title (bool))); + + connect (m_edit_area, SIGNAL (copyAvailable (bool)), + this, SLOT (handle_copy_available (bool))); + + connect (&m_file_system_watcher, &QFileSystemWatcher::fileChanged, + this, [=] (const QString& path) { file_has_changed (path); }); + + connect (this, &file_editor_tab::maybe_remove_next, + this, &file_editor_tab::handle_remove_next); + + connect (this, &file_editor_tab::dbstop_if, + this, &file_editor_tab::handle_dbstop_if); + + connect (this, &file_editor_tab::request_add_breakpoint, + this, &file_editor_tab::handle_request_add_breakpoint); + + connect (this, &file_editor_tab::api_entries_added, + this, &file_editor_tab::handle_api_entries_added); + + connect (this, &file_editor_tab::confirm_dbquit_and_save_signal, + this, &file_editor_tab::confirm_dbquit_and_save); + + connect (this, &file_editor_tab::do_save_file_signal, + this, &file_editor_tab::do_save_file); + + notice_settings (true); + + gui_settings settings; + + // encoding, not updated with the settings + 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 () + { + // Tell all connected markers to self-destruct. + emit remove_all_breakpoints_signal (); + emit remove_all_positions (); + + // Destroy lexer attached to m_edit_area, which is not the parent + // of lexer + QsciLexer *lexer = m_edit_area->lexer (); + if (lexer) + { + delete lexer; + m_edit_area->setLexer (nullptr); + } + } + + void file_editor_tab::set_encoding (const QString& new_encoding) + { + if (new_encoding.isEmpty ()) return; - } - - emit edit_mfile_request (word_at_cursor, m_file_name, m_ced, -1); -} - -// If "dbstop if ..." selected from context menu, create a conditional -// breakpoint. The default condition is (a) the existing condition if there -// is already a breakpoint, (b) any selected text, or (c) empty -void file_editor_tab::handle_context_menu_break_condition (int linenr) -{ - // Ensure editor line numbers match Octave core's line numbers. - // Give users the option to save modifications if necessary. - if (! unchanged_or_saved ()) - return; - - QString cond; - - // Search for previous condition. FIXME: is there a more direct way? - if (m_edit_area->markersAtLine (linenr) & (1 << marker::cond_break)) - { - emit report_marker_linenr (m_bp_lines, m_bp_conditions); - for (int i = 0; i < m_bp_lines.length (); i++) - if (m_bp_lines.value (i) == linenr) + + m_encoding = new_encoding; + m_enc_indicator->setText (m_encoding); + if (! m_edit_area->text ().isEmpty ()) + set_modified (true); + } + + void file_editor_tab::closeEvent (QCloseEvent *e) + { + int save_dialog = check_file_modified (true); + if ((save_dialog == QMessageBox::Cancel) || + (save_dialog == QMessageBox::Save)) + { + // Ignore close event if file is saved or user cancels + // closing this window. In case of saving, tab is closed after + // successful saving. + e->ignore (); + } + else + { + e->accept (); + emit tab_remove_request (); + } + } + + void file_editor_tab::set_current_directory (const QString& dir) + { + m_ced = dir; + } + + 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; + 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) + break; + if ((pos_fct = rxfun2.indexIn (lines.at (line))) != -1) + break; + if ((pos_fct = rxfun3.indexIn (lines.at (line))) != -1) + break; + if ((pos_fct = rxfun4.indexIn (lines.at (line))) != -1) + break; + } + + if (pos_fct > -1) + { + // reg expr. found: it is an internal function + m_edit_area->setCursorPosition (line, pos_fct); + m_edit_area->SendScintilla (2232, line); // SCI_ENSUREVISIBLE + // SCI_VISIBLEFROMDOCLINE + int vis_line = m_edit_area->SendScintilla (2220, line); + m_edit_area->SendScintilla (2613, vis_line); // SCI_SETFIRSTVISIBLELINE + return; + } + + emit edit_mfile_request (word_at_cursor, m_file_name, m_ced, -1); + } + + // If "dbstop if ..." selected from context menu, create a conditional + // breakpoint. The default condition is (a) the existing condition if there + // is already a breakpoint, (b) any selected text, or (c) empty + void file_editor_tab::handle_context_menu_break_condition (int linenr) + { + // Ensure editor line numbers match Octave core's line numbers. + // Give users the option to save modifications if necessary. + if (! unchanged_or_saved ()) + return; + + QString cond; + + // Search for previous condition. FIXME: is there a more direct way? + if (m_edit_area->markersAtLine (linenr) & (1 << marker::cond_break)) + { + emit report_marker_linenr (m_bp_lines, m_bp_conditions); + for (int i = 0; i < m_bp_lines.length (); i++) + if (m_bp_lines.value (i) == linenr) + { + cond = m_bp_conditions.value (i); + break; + } + m_bp_lines.clear (); + m_bp_conditions.clear (); + } + + // If text selected by the mouse, default to that instead + // If both present, use the OR of them, to avoid accidental overwriting + // FIXME: If both are present, show old condition unselected and + // the selection (in edit area) selected (in the dialog). + if (m_edit_area->hasSelectedText ()) + { + if (cond == "") + cond = m_edit_area->selectedText (); + else + cond = '(' + cond + ") || (" + m_edit_area->selectedText () + ')'; + } + + emit dbstop_if ("dbstop if", linenr+1, cond); + } + + // Display dialog in GUI thread to get condition, then emit + // interpreter_event signal to check it in the interpreter thread. + // If the dialog returns a valid condition, then either emit a signal + // to add the breakpoint in the editor tab or a signal to display a + // new dialog. + + void file_editor_tab::handle_dbstop_if (const QString& prompt, int line, + const QString& cond) + { + bool ok; + QString new_cond + = QInputDialog::getText (this, tr ("Breakpoint condition"), + prompt, QLineEdit::Normal, cond, &ok); + + // If cancel, don't change breakpoint condition. + + if (ok && ! new_cond.isEmpty ()) + { + // 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_fetab (this); + + 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, ""); + } + }); + } + } + + void file_editor_tab::set_file_name (const QString& fileName) + { + // update tracked file if we really have a file on disk + QStringList trackedFiles = m_file_system_watcher.files (); + if (! trackedFiles.isEmpty ()) + m_file_system_watcher.removePath (m_file_name); + if (! fileName.isEmpty () && QFile::exists (fileName)) + { + m_file_system_watcher.addPath (fileName); + m_last_modified = QFileInfo (fileName).lastModified ().toUTC (); + } + + // update lexer and file name variable if file name changes + if (m_file_name != fileName) + { + m_file_name = fileName; + update_lexer (); + } + + // set the window title to actual filename (not modified) + update_window_title (m_edit_area->isModified ()); + + // update the file editor with current editing directory + emit editor_state_changed (m_copy_available, m_is_octave_file, + m_edit_area->isModified ()); + + // add the new file to the most-recently-used list + emit mru_add_file (m_file_name, m_encoding); + } + + // valid_file_name (file): checks whether "file" names a file. + // By default, "file" is empty; then m_file_name is checked + bool file_editor_tab::valid_file_name (const QString& file) + { + if (file.isEmpty ()) + { + if (m_file_name.isEmpty ()) + return false; + else + return true; + } + + return true; + } + + void file_editor_tab::enable_file_watcher (bool do_enable) + { + if (do_enable) + m_file_system_watcher.addPath (m_file_name); + else + m_file_system_watcher.removePath (m_file_name); + } + + // We cannot create a breakpoint when the file is modified + // because the line number the editor is providing might + // 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 () + { + bool retval = true; + if (m_edit_area->isModified () || ! valid_file_name ()) + { + int ans = QMessageBox::question (nullptr, tr ("Octave Editor"), + tr ("Cannot add breakpoint to modified or unnamed file.\n" + "Save and add breakpoint, or cancel?"), + QMessageBox::Save | QMessageBox::Cancel, QMessageBox::Save); + + if (ans == QMessageBox::Save) + save_file (m_file_name, false); + else + retval = false; + } + + return retval; + } + + // Toggle a breakpoint at the editor_linenr or, if this was called by + // a click with CTRL pressed, toggle a bookmark at that point. + void file_editor_tab::handle_margin_clicked (int margin, int editor_linenr, + Qt::KeyboardModifiers state) + { + if (margin == 1) + { + unsigned int markers_mask = m_edit_area->markersAtLine (editor_linenr); + + if (state & Qt::ControlModifier) { - cond = m_bp_conditions.value (i); - break; + if (markers_mask & (1 << marker::bookmark)) + m_edit_area->markerDelete (editor_linenr, marker::bookmark); + else + m_edit_area->markerAdd (editor_linenr, marker::bookmark); } - m_bp_lines.clear (); - m_bp_conditions.clear (); - } - - // If text selected by the mouse, default to that instead - // If both present, use the OR of them, to avoid accidental overwriting - // FIXME: If both are present, show old condition unselected and - // the selection (in edit area) selected (in the dialog). - if (m_edit_area->hasSelectedText ()) - { - if (cond == "") - cond = m_edit_area->selectedText (); - else - cond = '(' + cond + ") || (" + m_edit_area->selectedText () + ')'; - } - - emit dbstop_if ("dbstop if", linenr+1, cond); -} - -// Display dialog in GUI thread to get condition, then emit -// interpreter_event signal to check it in the interpreter thread. -// If the dialog returns a valid condition, then either emit a signal -// to add the breakpoint in the editor tab or a signal to display a -// new dialog. - -void file_editor_tab::handle_dbstop_if (const QString& prompt, int line, - const QString& cond) -{ - bool ok; - QString new_cond - = QInputDialog::getText (this, tr ("Breakpoint condition"), - prompt, QLineEdit::Normal, cond, &ok); - - // If cancel, don't change breakpoint condition. - - if (ok && ! new_cond.isEmpty ()) - { - // 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_fetab (this); - - 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, ""); - } - }); - } -} - -void file_editor_tab::set_file_name (const QString& fileName) -{ - // update tracked file if we really have a file on disk - QStringList trackedFiles = m_file_system_watcher.files (); - if (! trackedFiles.isEmpty ()) - m_file_system_watcher.removePath (m_file_name); - if (! fileName.isEmpty () && QFile::exists (fileName)) - { - m_file_system_watcher.addPath (fileName); - m_last_modified = QFileInfo (fileName).lastModified ().toUTC (); - } - - // update lexer and file name variable if file name changes - if (m_file_name != fileName) - { - m_file_name = fileName; - update_lexer (); - } - - // set the window title to actual filename (not modified) - update_window_title (m_edit_area->isModified ()); - - // update the file editor with current editing directory - emit editor_state_changed (m_copy_available, m_is_octave_file, - m_edit_area->isModified ()); - - // add the new file to the most-recently-used list - emit mru_add_file (m_file_name, m_encoding); -} - -// valid_file_name (file): checks whether "file" names a file. -// By default, "file" is empty; then m_file_name is checked -bool file_editor_tab::valid_file_name (const QString& file) -{ - if (file.isEmpty ()) - { - if (m_file_name.isEmpty ()) - return false; - else - return true; - } - - return true; -} - -void file_editor_tab::enable_file_watcher (bool do_enable) -{ - if (do_enable) - m_file_system_watcher.addPath (m_file_name); - else - m_file_system_watcher.removePath (m_file_name); -} - -// We cannot create a breakpoint when the file is modified -// because the line number the editor is providing might -// 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 retval = true; - if (m_edit_area->isModified () || ! valid_file_name ()) - { - int ans = QMessageBox::question (nullptr, tr ("Octave Editor"), - tr ("Cannot add breakpoint to modified or unnamed file.\n" - "Save and add breakpoint, or cancel?"), - QMessageBox::Save | QMessageBox::Cancel, QMessageBox::Save); - - if (ans == QMessageBox::Save) - save_file (m_file_name, false); - else - retval = false; - } - - return retval; -} - -// Toggle a breakpoint at the editor_linenr or, if this was called by -// a click with CTRL pressed, toggle a bookmark at that point. -void file_editor_tab::handle_margin_clicked (int margin, int editor_linenr, - Qt::KeyboardModifiers state) -{ - if (margin == 1) - { - unsigned int markers_mask = m_edit_area->markersAtLine (editor_linenr); - - if (state & Qt::ControlModifier) - { - if (markers_mask & (1 << marker::bookmark)) - m_edit_area->markerDelete (editor_linenr, marker::bookmark); - else - m_edit_area->markerAdd (editor_linenr, marker::bookmark); - } - else - { - if (markers_mask & ((1 << marker::breakpoint) - | (1 << marker::cond_break))) - handle_request_remove_breakpoint (editor_linenr + 1); - else - { - if (unchanged_or_saved ()) - handle_request_add_breakpoint (editor_linenr + 1, ""); - } - } - } -} - -void file_editor_tab::update_lexer (void) -{ - // Create a new lexer - QsciLexer *lexer = nullptr; - - m_is_octave_file = false; - - // Find the required lexer from file extensions - if (m_file_name.endsWith (".m") - || m_file_name.endsWith ("octaverc") - || m_file_name.endsWith (".cc-tst")) - { + else + { + if (markers_mask & ((1 << marker::breakpoint) + | (1 << marker::cond_break))) + handle_request_remove_breakpoint (editor_linenr + 1); + else + { + if (unchanged_or_saved ()) + handle_request_add_breakpoint (editor_linenr + 1, ""); + } + } + } + } + + void file_editor_tab::update_lexer () + { + // Create a new lexer + QsciLexer *lexer = nullptr; + + m_is_octave_file = false; + + // Find the required lexer from file extensions + if (m_file_name.endsWith (".m") + || m_file_name.endsWith ("octaverc") + || m_file_name.endsWith (".cc-tst")) + { #if defined (HAVE_LEXER_OCTAVE) - lexer = new QsciLexerOctave (); + lexer = new QsciLexerOctave (); #elif defined (HAVE_LEXER_MATLAB) - lexer = new QsciLexerMatlab (); + lexer = new QsciLexerMatlab (); #else - lexer = new octave_txt_lexer (); + lexer = new octave_txt_lexer (); #endif - m_is_octave_file = true; - } - - if (! lexer) - { - if (m_file_name.endsWith (".c") - || m_file_name.endsWith (".cc") - || m_file_name.endsWith (".cpp") - || m_file_name.endsWith (".cxx") - || m_file_name.endsWith (".c++") - || m_file_name.endsWith (".h") - || m_file_name.endsWith (".hh") - || m_file_name.endsWith (".hpp") - || m_file_name.endsWith (".h++")) - { - lexer = new QsciLexerCPP (); - } - else if (m_file_name.endsWith (".java")) - { - lexer = new QsciLexerJava (); - } - else if (m_file_name.endsWith (".pl")) - { - lexer = new QsciLexerPerl (); - } - else if (m_file_name.endsWith (".bat")) - { - lexer = new QsciLexerBatch (); - } - else if (m_file_name.endsWith (".diff")) - { - lexer = new QsciLexerDiff (); - } - else if (m_file_name.endsWith (".sh")) - { - lexer = new QsciLexerBash (); - } - else if (! valid_file_name ()) - { - // new, not yet named file: let us assume it is octave + m_is_octave_file = true; + } + + if (! lexer) + { + if (m_file_name.endsWith (".c") + || m_file_name.endsWith (".cc") + || m_file_name.endsWith (".cpp") + || m_file_name.endsWith (".cxx") + || m_file_name.endsWith (".c++") + || m_file_name.endsWith (".h") + || m_file_name.endsWith (".hh") + || m_file_name.endsWith (".hpp") + || m_file_name.endsWith (".h++")) + { + lexer = new QsciLexerCPP (); + } + else if (m_file_name.endsWith (".java")) + { + lexer = new QsciLexerJava (); + } + else if (m_file_name.endsWith (".pl")) + { + lexer = new QsciLexerPerl (); + } + else if (m_file_name.endsWith (".bat")) + { + lexer = new QsciLexerBatch (); + } + else if (m_file_name.endsWith (".diff")) + { + lexer = new QsciLexerDiff (); + } + else if (m_file_name.endsWith (".sh")) + { + lexer = new QsciLexerBash (); + } + else if (! valid_file_name ()) + { + // new, not yet named file: let us assume it is octave #if defined (HAVE_LEXER_OCTAVE) - lexer = new QsciLexerOctave (); - m_is_octave_file = true; + lexer = new QsciLexerOctave (); + m_is_octave_file = true; #elif defined (HAVE_LEXER_MATLAB) - lexer = new QsciLexerMatlab (); - m_is_octave_file = true; + lexer = new QsciLexerMatlab (); + m_is_octave_file = true; #else - lexer = new octave_txt_lexer (); + lexer = new octave_txt_lexer (); #endif - } - else - { - // other or no extension - lexer = new octave_txt_lexer (); - } - } - - // Get any existing lexer - QsciLexer *old_lexer = m_edit_area->lexer (); - - // If new file, no lexer, or lexer has changed, - // delete old one and set the newly created as current lexer - if (! old_lexer || ! valid_file_name () - || QString(old_lexer->lexer ()) != QString(lexer->lexer ())) - { - // Delete and set new lexer - if (old_lexer) - delete old_lexer; - m_edit_area->setLexer (lexer); - - // Build information for auto completion (APIs) - m_lexer_apis = new QsciAPIs (lexer); - - connect (this, &file_editor_tab::request_add_octave_apis, - this, &file_editor_tab::handle_add_octave_apis); - - // Get the settings for this new lexer - update_lexer_settings (); - } - else - { - // Otherwise, delete the newly created lexer and - // use the old, existing one. - delete lexer; - } -} - -// Update settings, which are lexer related and have to be updated -// when -// a) the lexer changes, -// b) the settings have changed, or -// c) a package was loaded/unloaded -void file_editor_tab::update_lexer_settings (bool update_apis_only) -{ - QsciLexer *lexer = m_edit_area->lexer (); - - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (m_lexer_apis) - { - m_lexer_apis->cancelPreparation (); // stop preparing if apis exists - - bool update_apis = false; // flag, whether update of apis files - - // Get path to prepared api info (cache). Temporarily set the - // application name to 'octave' instead of 'GNU Octave' name for - // not having blanks in the path. - QString tmp_app_name = QCoreApplication::applicationName (); - QCoreApplication::setApplicationName ("octave"); // Set new name + } + else + { + // other or no extension + lexer = new octave_txt_lexer (); + } + } + + // Get any existing lexer + QsciLexer *old_lexer = m_edit_area->lexer (); + + // If new file, no lexer, or lexer has changed, + // delete old one and set the newly created as current lexer + if (! old_lexer || ! valid_file_name () + || QString(old_lexer->lexer ()) != QString(lexer->lexer ())) + { + // Delete and set new lexer + if (old_lexer) + delete old_lexer; + m_edit_area->setLexer (lexer); + + // Build information for auto completion (APIs) + m_lexer_apis = new QsciAPIs (lexer); + + connect (this, &file_editor_tab::request_add_octave_apis, + this, &file_editor_tab::handle_add_octave_apis); + + // Get the settings for this new lexer + update_lexer_settings (); + } + else + { + // Otherwise, delete the newly created lexer and + // use the old, existing one. + delete lexer; + } + } + + // Update settings, which are lexer related and have to be updated + // when + // a) the lexer changes, + // b) the settings have changed, or + // c) a package was loaded/unloaded + void file_editor_tab::update_lexer_settings (bool update_apis_only) + { + QsciLexer *lexer = m_edit_area->lexer (); + + gui_settings settings; + + if (m_lexer_apis) + { + m_lexer_apis->cancelPreparation (); // stop preparing if apis exists + + bool update_apis = false; // flag, whether update of apis files + + // Get path to prepared api info (cache). Temporarily set the + // application name to 'octave' instead of 'GNU Octave' name for + // not having blanks in the path. + QString tmp_app_name = QCoreApplication::applicationName (); + QCoreApplication::setApplicationName ("octave"); // Set new name #if defined (HAVE_QSTANDARDPATHS) - QString local_data_path - = QStandardPaths::writableLocation (QStandardPaths::CacheLocation); + QString local_data_path + = QStandardPaths::writableLocation (QStandardPaths::CacheLocation); #else - QString local_data_path - = QDesktopServices::storageLocation (QDesktopServices::CacheLocation); + QString local_data_path + = QDesktopServices::storageLocation (QDesktopServices::CacheLocation); #endif - QCoreApplication::setApplicationName ("octave"); // Set temp. name - - m_prep_apis_path - = local_data_path + "/" + QString (OCTAVE_VERSION) + "/qsci/"; - - // get settings which infos are used for octave - bool octave_builtins - = settings->value (ed_code_completion_octave_builtins).toBool (); - bool octave_functions - = settings->value (ed_code_completion_octave_functions).toBool (); - - QCoreApplication::setApplicationName (tmp_app_name); // Restore name - - if (m_is_octave_file) - { - // Keywords and Builtins do not change, this information can be - // stored in prepared form in a file. Information on function are - // changing frequently, then if functions should also be auto- - // completed, the date of any existing file is checked. - - // Keywords are always used - m_prep_apis_file = m_prep_apis_path + lexer->lexer () + "_k"; - - // Builtins are only used if the user settings say so - if (octave_builtins) - m_prep_apis_file += 'b'; - - if (octave_functions) - m_prep_apis_file += 'f'; - - m_prep_apis_file += ".pap"; // final name of apis file - - // check whether the APIs info needs to be prepared and saved - QFileInfo apis_file = QFileInfo (m_prep_apis_file); - - // flag whether apis file needs update - update_apis = ! apis_file.exists (); - - if (octave_functions) - { - // Functions may change frequently. Update the apis data - // if the file is older than a few minutes preventing from - // re-preparing data when the user opens several files. - QDateTime apis_time = apis_file.lastModified (); - if (update_apis_only - || QDateTime::currentDateTime () > apis_time.addSecs (180)) - update_apis = true; - } - - } - else - { - // No octave file, just add extension. - m_prep_apis_file = m_prep_apis_path + lexer->lexer () + ".pap"; - } - - // Make sure the apis file is usable, otherwise the gui might crash, - // e.g., in case of max. number of opened files - QFile f (m_prep_apis_file); - - bool apis_usable = f.open (QIODevice::ReadOnly); - if (! apis_usable) - { - QDir ().mkpath (QFileInfo (f).absolutePath ()); - apis_usable = f.open (QIODevice::WriteOnly); - } - if (apis_usable) - f.close (); - - if (apis_usable - && (update_apis || ! m_lexer_apis->loadPrepared (m_prep_apis_file))) - { - // either we have decided to update the apis file or - // no prepared info was loaded, prepare and save if possible - - // create raw apis info - - m_lexer_apis->clear (); // Clear current contents - - if (m_is_octave_file) - { - // 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_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); - }); - } - else - { - for (int i = 1; i <= 3; i++) - { - // Get list, split, and add to API. - - QString keyword = QString (lexer->keywords (i)); - - QStringList keyword_list - = keyword.split (QRegExp (R"(\s+)")); - - for (int j = 0; j < keyword_list.size (); j++) - m_lexer_apis->add (keyword_list.at (j)); - } - - emit api_entries_added (); - } - } - } - - if (update_apis_only) - return; // We are done here - - int mode = settings->value (ed_color_mode).toInt (); - rmgr.read_lexer_settings (lexer, settings, mode); - - m_edit_area->setCaretForegroundColor (lexer->color (0)); - m_edit_area->setIndentationGuidesForegroundColor (lexer->color (0)); - - // set some colors depending on selected background color of the lexer - QColor bg = lexer->paper (0); - QColor fg = lexer->color (0); - - // margin and current line marker colors - QColor bgm, fgm; - - bgm = interpolate_color (bg, fg, 0.5, 0.2); - m_edit_area->setEdgeColor (bgm); - - m_edit_area->setMarkerForegroundColor (lexer->color (0)); - m_edit_area->setMarginsForegroundColor (lexer->color (0)); - - bgm = interpolate_color (bg, fg, 0.5, 0.125); - fgm = interpolate_color (bg, fg, 0.5, 0.25); - m_edit_area->setMarginsBackgroundColor (bgm); - m_edit_area->setFoldMarginColors (bgm, fgm); - - QColor current_line_bg - = 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 - - m_edit_area->setCaretLineBackgroundColor (bgm); - - // color indicator for highlighting all occurrences: - // applications highlight color with more transparency - QColor hg = QApplication::palette ().color (QPalette::Highlight); - m_edit_area->set_selection_marker_color (hg); - - // 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 ()) - { - // Line numbers width - auto_margin_width (); - - // Line numbers font - QFont line_numbers_font = lexer->defaultFont (); - int font_size = line_numbers_font.pointSize (); - font_size = font_size - + settings->value (ed_line_numbers_size).toInt (); - if (font_size < 4) - font_size = 4; - line_numbers_font.setPointSize (font_size); - - m_edit_area->setMarginsFont (line_numbers_font); - } - else - m_edit_area->setMarginWidth (2, 0); -} - -// function for adding entries to the octave lexer's APIs -void file_editor_tab::handle_add_octave_apis (const QStringList& api_entries) -{ - for (int idx = 0; idx < api_entries.size (); idx++) - m_lexer_apis->add (api_entries.at (idx)); - - emit api_entries_added (); -} - -void file_editor_tab::handle_api_entries_added (void) -{ - // disconnect slot for saving prepared info if already connected - disconnect (m_lexer_apis, &QsciAPIs::apiPreparationFinished, - nullptr, nullptr); - - // check whether path for prepared info exists or can be created - if (QDir ("/").mkpath (m_prep_apis_path)) - { - // path exists, apis info can be saved there - connect (m_lexer_apis, &QsciAPIs::apiPreparationFinished, - this, &file_editor_tab::save_apis_info); - } - - m_lexer_apis->prepare (); // prepare apis info -} - -void file_editor_tab::save_apis_info (void) -{ - m_lexer_apis->savePrepared (m_prep_apis_file); -} - -// slot for fetab_set_focus: sets the focus to the current edit area -void file_editor_tab::set_focus (const QWidget *ID) -{ - if (ID != this) - return; - m_edit_area->setFocus (); - emit edit_area_changed (m_edit_area); // update the edit area in find dlg -} - -void file_editor_tab::context_help (const QWidget *ID, bool doc) -{ - if (ID != this) - return; - - m_edit_area->context_help_doc (doc); -} - -void file_editor_tab::context_edit (const QWidget *ID) -{ - if (ID != this) - return; - - m_edit_area->context_edit (); -} - -void file_editor_tab::save_file (const QWidget *ID) -{ - if (ID != this) - return; - - save_file (m_file_name); -} - -void file_editor_tab::save_file (const QWidget *ID, const QString& fileName, - bool remove_on_success) -{ - if (ID != this) - return; - - save_file (fileName, remove_on_success); -} - -void file_editor_tab::save_file_as (const QWidget *ID) -{ - if (ID != this) - return; - - save_file_as (); -} - -void file_editor_tab::print_file (const QWidget *ID) -{ - if (ID != this) - return; - - QsciPrinter *printer = new QsciPrinter (QPrinter::HighResolution); - - QPrintDialog printDlg (printer, this); - - if (printDlg.exec () == QDialog::Accepted) - printer->printRange (m_edit_area); - - delete printer; -} - -void file_editor_tab::run_file (const QWidget *ID, bool step_into) -{ - if (ID != this) - return; - - if (m_edit_area->isModified () || ! valid_file_name ()) - { - save_file (m_file_name); // save file dialog - - // Running a file is disabled for non-octave files. But when saving - // a new file, an octave file is assumed but might actually saved - // as another file or with an invalid file name. - if (! (m_is_octave_file && valid_file_name ())) + QCoreApplication::setApplicationName ("octave"); // Set temp. name + + m_prep_apis_path + = local_data_path + "/" + QString (OCTAVE_VERSION) + "/qsci/"; + + // get settings which infos are used for octave + bool octave_builtins + = settings.bool_value (ed_code_completion_octave_builtins); + bool octave_functions + = settings.bool_value (ed_code_completion_octave_functions); + + QCoreApplication::setApplicationName (tmp_app_name); // Restore name + + if (m_is_octave_file) + { + // Keywords and Builtins do not change, this information can be + // stored in prepared form in a file. Information on function are + // changing frequently, then if functions should also be auto- + // completed, the date of any existing file is checked. + + // Keywords are always used + m_prep_apis_file = m_prep_apis_path + lexer->lexer () + "_k"; + + // Builtins are only used if the user settings say so + if (octave_builtins) + m_prep_apis_file += 'b'; + + if (octave_functions) + m_prep_apis_file += 'f'; + + m_prep_apis_file += ".pap"; // final name of apis file + + // check whether the APIs info needs to be prepared and saved + QFileInfo apis_file = QFileInfo (m_prep_apis_file); + + // flag whether apis file needs update + update_apis = ! apis_file.exists (); + + if (octave_functions) + { + // Functions may change frequently. Update the apis data + // if the file is older than a few minutes preventing from + // re-preparing data when the user opens several files. + QDateTime apis_time = apis_file.lastModified (); + if (update_apis_only + || QDateTime::currentDateTime () > apis_time.addSecs (180)) + update_apis = true; + } + + } + else + { + // No octave file, just add extension. + m_prep_apis_file = m_prep_apis_path + lexer->lexer () + ".pap"; + } + + // Make sure the apis file is usable, otherwise the gui might crash, + // e.g., in case of max. number of opened files + QFile f (m_prep_apis_file); + + bool apis_usable = f.open (QIODevice::ReadOnly); + if (! apis_usable) + { + QDir ().mkpath (QFileInfo (f).absolutePath ()); + apis_usable = f.open (QIODevice::WriteOnly); + } + if (apis_usable) + f.close (); + + if (apis_usable + && (update_apis || ! m_lexer_apis->loadPrepared (m_prep_apis_file))) + { + // either we have decided to update the apis file or + // no prepared info was loaded, prepare and save if possible + + // create raw apis info + + m_lexer_apis->clear (); // Clear current contents + + if (m_is_octave_file) + { + // 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_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); + }); + } + else + { + for (int i = 1; i <= 3; i++) + { + // Get list, split, and add to API. + + QString keyword = QString (lexer->keywords (i)); + + QStringList keyword_list + = keyword.split (QRegExp (R"(\s+)")); + + for (int j = 0; j < keyword_list.size (); j++) + m_lexer_apis->add (keyword_list.at (j)); + } + + emit api_entries_added (); + } + } + } + + if (update_apis_only) + return; // We are done here + + 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)); + + // set some colors depending on selected background color of the lexer + QColor bg = lexer->paper (0); + QColor fg = lexer->color (0); + + // margin and current line marker colors + QColor bgm, fgm; + + bgm = interpolate_color (bg, fg, 0.5, 0.2); + m_edit_area->setEdgeColor (bgm); + + m_edit_area->setMarkerForegroundColor (lexer->color (0)); + m_edit_area->setMarginsForegroundColor (lexer->color (0)); + + bgm = interpolate_color (bg, fg, 0.5, 0.125); + fgm = interpolate_color (bg, fg, 0.5, 0.25); + m_edit_area->setMarginsBackgroundColor (bgm); + m_edit_area->setFoldMarginColors (bgm, fgm); + + QColor current_line_bg + = 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 + + m_edit_area->setCaretLineBackgroundColor (bgm); + + // color indicator for highlighting all occurrences: + // applications highlight color with more transparency + QColor hg = QApplication::palette ().color (QPalette::Highlight); + m_edit_area->set_selection_marker_color (hg); + + // 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.bool_value (ed_show_line_numbers)) + { + // Line numbers width + auto_margin_width (); + + // Line numbers font + QFont line_numbers_font = lexer->defaultFont (); + int font_size = line_numbers_font.pointSize (); + font_size = font_size + + settings.int_value (ed_line_numbers_size); + if (font_size < 4) + font_size = 4; + line_numbers_font.setPointSize (font_size); + + m_edit_area->setMarginsFont (line_numbers_font); + } + else + m_edit_area->setMarginWidth (2, 0); + } + + // function for adding entries to the octave lexer's APIs + void file_editor_tab::handle_add_octave_apis (const QStringList& api_entries) + { + for (int idx = 0; idx < api_entries.size (); idx++) + m_lexer_apis->add (api_entries.at (idx)); + + emit api_entries_added (); + } + + void file_editor_tab::handle_api_entries_added () + { + // disconnect slot for saving prepared info if already connected + disconnect (m_lexer_apis, &QsciAPIs::apiPreparationFinished, + nullptr, nullptr); + + // check whether path for prepared info exists or can be created + if (QDir ("/").mkpath (m_prep_apis_path)) + { + // path exists, apis info can be saved there + connect (m_lexer_apis, &QsciAPIs::apiPreparationFinished, + this, &file_editor_tab::save_apis_info); + } + + m_lexer_apis->prepare (); // prepare apis info + } + + void file_editor_tab::save_apis_info () + { + m_lexer_apis->savePrepared (m_prep_apis_file); + } + + // slot for fetab_set_focus: sets the focus to the current edit area + void file_editor_tab::set_focus (const QWidget *ID) + { + if (ID != this) + return; + m_edit_area->setFocus (); + emit edit_area_changed (m_edit_area); // update the edit area in find dlg + } + + void file_editor_tab::context_help (const QWidget *ID, bool doc) + { + if (ID != this) + return; + + m_edit_area->context_help_doc (doc); + } + + void file_editor_tab::context_edit (const QWidget *ID) + { + if (ID != this) + return; + + m_edit_area->context_edit (); + } + + void file_editor_tab::save_file (const QWidget *ID) + { + if (ID != this) + return; + + save_file (m_file_name); + } + + void file_editor_tab::save_file (const QWidget *ID, const QString& fileName, + bool remove_on_success) + { + if (ID != this) + return; + + save_file (fileName, remove_on_success); + } + + void file_editor_tab::save_file_as (const QWidget *ID) + { + if (ID != this) + return; + + save_file_as (); + } + + void file_editor_tab::print_file (const QWidget *ID) + { + if (ID != this) + return; + + QsciPrinter *printer = new QsciPrinter (QPrinter::HighResolution); + + QPrintDialog printDlg (printer, this); + + if (printDlg.exec () == QDialog::Accepted) + printer->printRange (m_edit_area); + + delete printer; + } + + void file_editor_tab::run_file (const QWidget *ID, bool step_into) + { + if (ID != this) + return; + + if (m_edit_area->isModified () || ! valid_file_name ()) + { + save_file (m_file_name); // save file dialog + + // Running a file is disabled for non-octave files. But when saving + // a new file, an octave file is assumed but might actually saved + // as another file or with an invalid file name. + if (! (m_is_octave_file && valid_file_name ())) + return; + } + + if (step_into) + { + // Get current first breakpoint and set breakpoint waiting for + // the returned line number. Store whether to remove this breakpoint + // afterwards. + int first_bp_line + = m_edit_area->markerFindNext (0, (1 << marker::breakpoint)) + 1; + + // Set flag for storing the line number of the breakpoint + m_breakpoint_info.remove_next = true; + m_breakpoint_info.do_not_remove_line = first_bp_line; + + // Add breakpoint, storing its line number + handle_request_add_breakpoint (1, QString ()); + } + + QFileInfo info (m_file_name); + emit run_file_signal (info); + } + + void file_editor_tab::context_run (const QWidget *ID) + { + if (ID != this) + return; + + m_edit_area->context_run (); + } + + void file_editor_tab::toggle_bookmark (const QWidget *ID) + { + if (ID != this) + return; + + int line, cur; + m_edit_area->getCursorPosition (&line, &cur); + + if (m_edit_area->markersAtLine (line) & (1 << marker::bookmark)) + m_edit_area->markerDelete (line, marker::bookmark); + else + m_edit_area->markerAdd (line, marker::bookmark); + } + + // Move the text cursor to the closest bookmark + // after the current line. + void file_editor_tab::next_bookmark (const QWidget *ID) + { + if (ID != this) + return; + + int line, cur; + m_edit_area->getCursorPosition (&line, &cur); + + line++; // Find bookmark strictly after the current line. + + int nextline = m_edit_area->markerFindNext (line, (1 << marker::bookmark)); + + // Wrap. + if (nextline == -1) + nextline = m_edit_area->markerFindNext (1, (1 << marker::bookmark)); + + m_edit_area->setCursorPosition (nextline, 0); + } + + // Move the text cursor to the closest bookmark + // before the current line. + void file_editor_tab::previous_bookmark (const QWidget *ID) + { + if (ID != this) + return; + + int line, cur; + m_edit_area->getCursorPosition (&line, &cur); + + line--; // Find bookmark strictly before the current line. + + int prevline = m_edit_area->markerFindPrevious (line, (1 << marker::bookmark)); + + // 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)); + + m_edit_area->setCursorPosition (prevline, 0); + } + + QString file_editor_tab::get_all_bookmarks () + { + QString bmlist; + int line = 0; + + while (line > -1) + { + line = m_edit_area->markerFindNext (line, (1 << marker::bookmark)); + if (line > -1) + { + if (! bmlist.isEmpty ()) + bmlist += ","; + bmlist += QString::number (line); + line++; // search from next line, otherwise same line found again + } + } + + return bmlist; + } + + void file_editor_tab::remove_bookmark (const QWidget *ID) + { + if (ID != this) + return; + + m_edit_area->markerDeleteAll (marker::bookmark); + } + + void + file_editor_tab::handle_request_add_breakpoint (int line, + const QString& condition) + { + if (! m_is_octave_file) + return; + + add_breakpoint_event (line, condition); + } + + void file_editor_tab::handle_request_remove_breakpoint (int line) + { + 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); + }); + } + + void file_editor_tab::toggle_breakpoint (const QWidget *ID) + { + if (ID != this) + return; + + int editor_linenr, cur; + m_edit_area->getCursorPosition (&editor_linenr, &cur); + + if (m_edit_area->markersAtLine (editor_linenr) & (1 << marker::breakpoint)) + request_remove_breakpoint_via_editor_linenr (editor_linenr); + else + { + if (unchanged_or_saved ()) + handle_request_add_breakpoint (editor_linenr + 1, ""); + } + } + + // Move the text cursor to the closest breakpoint (conditional or unconditional) + // after the current line. + void file_editor_tab::next_breakpoint (const QWidget *ID) + { + if (ID != this) + return; + + int line, cur; + m_edit_area->getCursorPosition (&line, &cur); + + line++; // Find breakpoint strictly after the current line. + + int nextline = m_edit_area->markerFindNext (line, (1 << marker::breakpoint)); + int nextcond = m_edit_area->markerFindNext (line, (1 << marker::cond_break)); + + // Check if the next conditional breakpoint is before next unconditional one. + if (nextcond != -1 && (nextcond < nextline || nextline == -1)) + nextline = nextcond; + + m_edit_area->setCursorPosition (nextline, 0); + } + + // Move the text cursor to the closest breakpoint (conditional or unconditional) + // before the current line. + void file_editor_tab::previous_breakpoint (const QWidget *ID) + { + if (ID != this) + return; + + int line, cur, prevline, prevcond; + m_edit_area->getCursorPosition (&line, &cur); + + line--; // Find breakpoint strictly before the current line. + + prevline = m_edit_area->markerFindPrevious (line, (1 << marker::breakpoint)); + prevcond = m_edit_area->markerFindPrevious (line, (1 << marker::cond_break)); + + // Check if the prev conditional breakpoint is closer than the unconditional. + if (prevcond != -1 && prevcond > prevline) + prevline = prevcond; + + m_edit_area->setCursorPosition (prevline, 0); + } + + void file_editor_tab::remove_all_breakpoints (const QWidget *ID) + { + if (ID != this) + return; + + 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); + }); + } + + void file_editor_tab::scintilla_command (const QWidget *ID, + unsigned int sci_msg) + { + if (ID != this) + return; + + m_edit_area->SendScintilla (sci_msg); + } + + void file_editor_tab::comment_selected_text (const QWidget *ID, + bool input_str) + { + if (ID != this) + return; + + do_comment_selected_text (true, input_str); + } + + void file_editor_tab::uncomment_selected_text (const QWidget *ID) + { + if (ID != this) + return; + + do_comment_selected_text (false); + } + + void file_editor_tab::indent_selected_text (const QWidget *ID) + { + if (ID != this) + return; + + do_indent_selected_text (true); + } + + void file_editor_tab::unindent_selected_text (const QWidget *ID) + { + if (ID != this) + return; + + do_indent_selected_text (false); + } + + void file_editor_tab::smart_indent_line_or_selected_text (const QWidget *ID) + { + if (ID != this) + return; + + do_smart_indent_line_or_selected_text (); + } + + void file_editor_tab::convert_eol (const QWidget *ID, + QsciScintilla::EolMode eol_mode) + { + if (ID != this) + return; + + m_edit_area->convertEols (eol_mode); + m_edit_area->setEolMode (eol_mode); + update_eol_indicator (); + } + + void file_editor_tab::zoom_in (const QWidget *ID) + { + if (ID != this) + return; + + m_edit_area->zoomIn (1); + auto_margin_width (); + } + + void file_editor_tab::zoom_out (const QWidget *ID) + { + if (ID != this) + return; + + m_edit_area->zoomOut (1); + auto_margin_width (); + } + + void file_editor_tab::zoom_normal (const QWidget *ID) + { + if (ID != this) + return; + + m_edit_area->zoomTo (0); + auto_margin_width (); + } + + void file_editor_tab::add_breakpoint_event (int line, const QString& cond) + { + // 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_fetab (this); + + 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); + }); + } + + void file_editor_tab::handle_remove_next (int remove_line) + { + // Store some info breakpoint + if (m_breakpoint_info.remove_next) + { + m_breakpoint_info.remove_line = remove_line; + m_breakpoint_info.remove_next = false; + } + } + + void file_editor_tab::goto_line (const QWidget *ID, int line) + { + if (ID != this) + return; + + if (m_bp_restore_count > 0) + { + // This goto-line request is invoked by restoring a breakpoint during + // saving the file, thus, do not go to the related line + m_bp_restore_count--; return; - } - - if (step_into) - { - // Get current first breakpoint and set breakpoint waiting for - // the returned line number. Store whether to remove this breakpoint - // afterwards. - int first_bp_line - = m_edit_area->markerFindNext (0, (1 << marker::breakpoint)) + 1; - - // Set flag for storing the line number of the breakpoint - m_breakpoint_info.remove_next = true; - m_breakpoint_info.do_not_remove_line = first_bp_line; - - // Add breakpoint, storing its line number - handle_request_add_breakpoint (1, QString ()); - } - - QFileInfo info (m_file_name); - emit run_file_signal (info); -} - -void file_editor_tab::context_run (const QWidget *ID) -{ - if (ID != this) - return; - - m_edit_area->context_run (); -} - -void file_editor_tab::toggle_bookmark (const QWidget *ID) -{ - if (ID != this) - return; - - int line, cur; - m_edit_area->getCursorPosition (&line, &cur); - - if (m_edit_area->markersAtLine (line) & (1 << marker::bookmark)) - m_edit_area->markerDelete (line, marker::bookmark); - else - m_edit_area->markerAdd (line, marker::bookmark); -} - -// Move the text cursor to the closest bookmark -// after the current line. -void file_editor_tab::next_bookmark (const QWidget *ID) -{ - if (ID != this) - return; - - int line, cur; - m_edit_area->getCursorPosition (&line, &cur); - - line++; // Find bookmark strictly after the current line. - - int nextline = m_edit_area->markerFindNext (line, (1 << marker::bookmark)); - - // Wrap. - if (nextline == -1) - nextline = m_edit_area->markerFindNext (1, (1 << marker::bookmark)); - - m_edit_area->setCursorPosition (nextline, 0); -} - -// Move the text cursor to the closest bookmark -// before the current line. -void file_editor_tab::previous_bookmark (const QWidget *ID) -{ - if (ID != this) - return; - - int line, cur; - m_edit_area->getCursorPosition (&line, &cur); - - line--; // Find bookmark strictly before the current line. - - int prevline = m_edit_area->markerFindPrevious (line, (1 << marker::bookmark)); - - // 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)); - - m_edit_area->setCursorPosition (prevline, 0); -} - -QString file_editor_tab::get_all_bookmarks () -{ - QString bmlist; - int line = 0; - - while (line > -1) - { - line = m_edit_area->markerFindNext (line, (1 << marker::bookmark)); - if (line > -1) - { - if (! bmlist.isEmpty ()) - bmlist += ","; - bmlist += QString::number (line); - line++; // search from next line, otherwise same line found again - } - } - - return bmlist; -} - -void file_editor_tab::remove_bookmark (const QWidget *ID) -{ - if (ID != this) - return; - - m_edit_area->markerDeleteAll (marker::bookmark); -} - -void -file_editor_tab::handle_request_add_breakpoint (int line, - const QString& condition) -{ - if (! m_is_octave_file) - return; - - add_breakpoint_event (line, condition); -} - -void file_editor_tab::handle_request_remove_breakpoint (int line) -{ - 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); - }); -} - -void file_editor_tab::toggle_breakpoint (const QWidget *ID) -{ - if (ID != this) - return; - - int editor_linenr, cur; - m_edit_area->getCursorPosition (&editor_linenr, &cur); - - if (m_edit_area->markersAtLine (editor_linenr) & (1 << marker::breakpoint)) - request_remove_breakpoint_via_editor_linenr (editor_linenr); - else - { - if (unchanged_or_saved ()) - handle_request_add_breakpoint (editor_linenr + 1, ""); - } -} - -// Move the text cursor to the closest breakpoint (conditional or unconditional) -// after the current line. -void file_editor_tab::next_breakpoint (const QWidget *ID) -{ - if (ID != this) - return; - - int line, cur; - m_edit_area->getCursorPosition (&line, &cur); - - line++; // Find breakpoint strictly after the current line. - - int nextline = m_edit_area->markerFindNext (line, (1 << marker::breakpoint)); - int nextcond = m_edit_area->markerFindNext (line, (1 << marker::cond_break)); - - // Check if the next conditional breakpoint is before next unconditional one. - if (nextcond != -1 && (nextcond < nextline || nextline == -1)) - nextline = nextcond; - - m_edit_area->setCursorPosition (nextline, 0); -} - -// Move the text cursor to the closest breakpoint (conditional or unconditional) -// before the current line. -void file_editor_tab::previous_breakpoint (const QWidget *ID) -{ - if (ID != this) - return; - - int line, cur, prevline, prevcond; - m_edit_area->getCursorPosition (&line, &cur); - - line--; // Find breakpoint strictly before the current line. - - prevline = m_edit_area->markerFindPrevious (line, (1 << marker::breakpoint)); - prevcond = m_edit_area->markerFindPrevious (line, (1 << marker::cond_break)); - - // Check if the prev conditional breakpoint is closer than the unconditional. - if (prevcond != -1 && prevcond > prevline) - prevline = prevcond; - - m_edit_area->setCursorPosition (prevline, 0); -} - -void file_editor_tab::remove_all_breakpoints (const QWidget *ID) -{ - if (ID != this) - return; - - 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); - }); -} - -void file_editor_tab::scintilla_command (const QWidget *ID, - unsigned int sci_msg) -{ - if (ID != this) - return; - - m_edit_area->SendScintilla (sci_msg); -} - -void file_editor_tab::comment_selected_text (const QWidget *ID, - bool input_str) -{ - if (ID != this) - return; - - do_comment_selected_text (true, input_str); -} - -void file_editor_tab::uncomment_selected_text (const QWidget *ID) -{ - if (ID != this) - return; - - do_comment_selected_text (false); -} - -void file_editor_tab::indent_selected_text (const QWidget *ID) -{ - if (ID != this) - return; - - do_indent_selected_text (true); -} - -void file_editor_tab::unindent_selected_text (const QWidget *ID) -{ - if (ID != this) - return; - - do_indent_selected_text (false); -} - -void file_editor_tab::smart_indent_line_or_selected_text (const QWidget *ID) -{ - if (ID != this) - return; - - do_smart_indent_line_or_selected_text (); -} - -void file_editor_tab::convert_eol (const QWidget *ID, - QsciScintilla::EolMode eol_mode) -{ - if (ID != this) - return; - - m_edit_area->convertEols (eol_mode); - m_edit_area->setEolMode (eol_mode); - update_eol_indicator (); -} - -void file_editor_tab::zoom_in (const QWidget *ID) -{ - if (ID != this) - return; - - m_edit_area->zoomIn (1); - auto_margin_width (); -} - -void file_editor_tab::zoom_out (const QWidget *ID) -{ - if (ID != this) - return; - - m_edit_area->zoomOut (1); - auto_margin_width (); -} - -void file_editor_tab::zoom_normal (const QWidget *ID) -{ - if (ID != this) - return; - - m_edit_area->zoomTo (0); - auto_margin_width (); -} - -void file_editor_tab::add_breakpoint_event (int line, const QString& cond) -{ - // 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_fetab (this); - - 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); - }); -} - -void file_editor_tab::handle_remove_next (int remove_line) -{ - // Store some info breakpoint - if (m_breakpoint_info.remove_next) - { - m_breakpoint_info.remove_line = remove_line; - m_breakpoint_info.remove_next = false; - } -} - -void file_editor_tab::goto_line (const QWidget *ID, int line) -{ - if (ID != this) - return; - - if (m_bp_restore_count > 0) - { - // This goto-line request is invoked by restoring a breakpoint during - // saving the file, thus, do not go to the related line - m_bp_restore_count--; + } + + if (line <= 0) // ask for desired line + { + bool ok = false; + int index; + m_edit_area->getCursorPosition (&line, &index); + line = QInputDialog::getInt (m_edit_area, tr ("Goto line"), + tr ("Line number"), line+1, 1, + m_edit_area->lines (), 1, &ok); + if (ok) + m_edit_area->setCursorPosition (line-1, 0); + } + else // go to given line without dialog + m_edit_area->setCursorPosition (line-1, 0); + + center_current_line (false); // only center line if at top or bottom + } + + void file_editor_tab::move_match_brace (const QWidget *ID, bool select) + { + if (ID != this) + return; + + if (select) + m_edit_area->selectToMatchingBrace (); + else + m_edit_area->moveToMatchingBrace (); + } + + void file_editor_tab::show_auto_completion (const QWidget *ID) + { + if (ID != this) return; - } - - if (line <= 0) // ask for desired line - { - bool ok = false; - int index; - m_edit_area->getCursorPosition (&line, &index); - line = QInputDialog::getInt (m_edit_area, tr ("Goto line"), - tr ("Line number"), line+1, 1, - m_edit_area->lines (), 1, &ok); - if (ok) - m_edit_area->setCursorPosition (line-1, 0); - } - else // go to given line without dialog - m_edit_area->setCursorPosition (line-1, 0); - - center_current_line (false); // only center line if at top or bottom -} - -void file_editor_tab::move_match_brace (const QWidget *ID, bool select) -{ - if (ID != this) - return; - - if (select) - m_edit_area->selectToMatchingBrace (); - else - m_edit_area->moveToMatchingBrace (); -} - -void file_editor_tab::show_auto_completion (const QWidget *ID) -{ - if (ID != this) - return; - - m_autoc_active = true; - - QsciScintilla::AutoCompletionSource s = m_edit_area->autoCompletionSource (); - switch (s) - { - case QsciScintilla::AcsAll: - m_edit_area->autoCompleteFromAll (); - break; - - case QsciScintilla::AcsAPIs: - m_edit_area->autoCompleteFromAPIs (); - break; - - case QsciScintilla::AcsDocument: - m_edit_area->autoCompleteFromDocument (); - break; - - case QsciScintilla::AcsNone: - break; - } -} - -void file_editor_tab::do_indent_selected_text (bool indent) -{ - // FIXME: - m_edit_area->beginUndoAction (); - - if (m_edit_area->hasSelectedText ()) - { - int lineFrom, lineTo, colFrom, colTo; - m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); - - if (colTo == 0) // the beginning of last line is not selected - lineTo--; // stop at line above - - for (int i = lineFrom; i <= lineTo; i++) - { - if (indent) - m_edit_area->indent (i); - else - m_edit_area->unindent (i); - } - //set selection on (un)indented section - m_edit_area->setSelection (lineFrom, 0, lineTo, - m_edit_area->text (lineTo).length ()-1); - } - else - { - int cpline, col; - m_edit_area->getCursorPosition (&cpline, &col); - if (indent) - m_edit_area->indent (cpline); - else - m_edit_area->unindent (cpline); - } - - m_edit_area->endUndoAction (); -} - -void file_editor_tab::do_smart_indent_line_or_selected_text (void) -{ - m_edit_area->beginUndoAction (); - - int lineFrom, lineTo; - - if (m_edit_area->hasSelectedText ()) - { - int colFrom, colTo; - m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); - - if (colTo == 0) // the beginning of last line is not selected - lineTo--; // stop at line above - } - else - { - int col; - m_edit_area->getCursorPosition (&lineFrom, &col); - - lineTo = lineFrom; - } - - m_edit_area->smart_indent_line_or_selected_text (lineFrom, lineTo); - - m_edit_area->endUndoAction (); -} - -void file_editor_tab::do_comment_selected_text (bool comment, bool input_str) -{ - QRegExp rxc; - QString ws = "^(?:[ \\t]*)"; - QStringList comment_str = m_edit_area->comment_string (comment); - QString used_comment_str = comment_str.at (0); - - if (comment) - { - if (input_str) - { - bool ok; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_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 (), - &ok); - - if ((! ok) || used_comment_str.isEmpty ()) - return; // No input, do nothing - else - settings->setValue (ed_last_comment_str, used_comment_str); // Store last - } - } - else - { - // Uncommenting (several strings possible) - - // Sort strings according their length - QStringList comment_str_sorted (comment_str.at (0)); - bool inserted; - - for (int i = 1; i < comment_str.length (); i++) - { - inserted = false; - for (int j = 0; j < comment_str_sorted.length (); j++) - { - if (comment_str.at (i).length () > comment_str_sorted.at (j).length ()) - { - comment_str_sorted.insert (j, comment_str.at (i)); - inserted = true; - break; - } - } - if (! inserted) - comment_str_sorted << comment_str.at (i); - } - - // Create regular expression - QString regexp; - for (int i = 0; i < comment_str_sorted.length (); i++) - { - if (i > 0) - regexp = regexp + QString ("|"); - regexp = regexp + comment_str_sorted.at (i); - } - rxc = QRegExp (ws + "(" + regexp + ")"); - } - - // Do the commenting/uncommenting - int len = 0, lenc = 0; - m_edit_area->beginUndoAction (); - - if (m_edit_area->hasSelectedText ()) - { - int lineFrom, lineTo, colFrom, colTo; - int change_col_from = 1; - int change_col_to = 1; - bool removed; - - m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); - - if (colTo == 0) // the beginning of last line is not selected - lineTo--; // stop at line above - - for (int i = lineFrom; i <= lineTo; i++) - { - if (comment) - { - m_edit_area->insertAt (used_comment_str, i, 0); - } - else - { - QString line (m_edit_area->text (i)); - if ((removed = line.contains (rxc))) - { - len = rxc.matchedLength (); // complete length - QString matched_text = rxc.capturedTexts ().at (0); - lenc = matched_text.remove (QRegExp (ws)).length (); // only comment string - m_edit_area->setSelection (i, len-lenc, i, len); - m_edit_area->removeSelectedText (); - } - - // handle case, where the selection remains unchanged - if (i == lineFrom && (colFrom < len-lenc || ! removed)) - change_col_from = 0; // do not change start of selection - if (i == lineTo && (colTo < len-lenc || ! removed)) - change_col_to = 0; // do not change end of selection - } - } - - // update the selection area - if (comment) - { - colFrom = colFrom + lenc; // shift start position by comment length - if (colTo > 0) - colTo = colTo + lenc; // shift end position by comment length - else - lineTo++; // colTo == 0 , fully select previous line - } - else - { - if (colTo == 0) - lineTo++; // colTo == 0 , fully select previous line - colFrom = colFrom - change_col_from*lenc; - colTo = colTo - change_col_to*lenc; - } - - // set updated selection area - m_edit_area->setSelection (lineFrom, colFrom, lineTo, colTo); - } - else - { - int cpline, col; - m_edit_area->getCursorPosition (&cpline, &col); - if (comment) - m_edit_area->insertAt (used_comment_str, cpline, 0); - else - { - QString line (m_edit_area->text (cpline)); - if (line.contains (rxc)) - { - len = rxc.matchedLength (); // complete length - QString matched_text = rxc.capturedTexts ().at (0); - lenc = matched_text.remove (QRegExp (ws)).length (); // only comment string - m_edit_area->setSelection (cpline, len-lenc, cpline, len); - m_edit_area->removeSelectedText (); - } - } - } - m_edit_area->endUndoAction (); -} - -void file_editor_tab::update_window_title (bool modified) -{ - QString title (""); - QString tooltip (""); - - if (! valid_file_name ()) - title = tr (""); - else - { - QFileInfo file (m_file_name); - title = file.fileName (); - tooltip = m_file_name; - } - - emit file_name_changed (title, tooltip, modified); -} - -void file_editor_tab::handle_copy_available (bool enableCopy) -{ - m_copy_available = enableCopy; - emit editor_state_changed (m_copy_available, m_is_octave_file, - m_edit_area->isModified ()); -} - -// show_dialog: shows a modal or non modal dialog depending on input arg -void file_editor_tab::show_dialog (QDialog *dlg, bool modal) -{ - dlg->setAttribute (Qt::WA_DeleteOnClose); - if (modal) - dlg->exec (); - else - { - dlg->setWindowModality (Qt::NonModal); - dlg->show (); - } -} - -int file_editor_tab::check_file_modified (bool remove) -{ - int decision = QMessageBox::Yes; - if (m_edit_area->isModified ()) - { - // File is modified but not saved, ask user what to do. The file - // 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; - - // For now, just a warning message about closing a tab that has been - // modified seems sufficient. Exit-condition-specific messages could - // be achieved by making 'available_actions' a function input string. - QString available_actions = - tr ("Do you want to cancel closing, save or discard the changes?"); - - QString file; - if (valid_file_name ()) - file = m_file_name; - else - file = tr (""); - - QMessageBox *msgBox - = new QMessageBox (QMessageBox::Warning, tr ("Octave Editor"), - tr ("The file\n\n" - " %1\n\n" - "is about to be closed but has been modified. " - "%2"). - arg (file). arg (available_actions), - buttons, qobject_cast (parent ())); - - msgBox->setDefaultButton (QMessageBox::Save); - m_edit_area->setReadOnly (true); - - decision = msgBox->exec (); // show_dialog (msgBox, true); - - if (decision == QMessageBox::Cancel) - m_edit_area->setReadOnly (false); - else if (decision == QMessageBox::Save) - save_file (m_file_name, remove, false); - else + + m_autoc_active = true; + + QsciScintilla::AutoCompletionSource s = m_edit_area->autoCompletionSource (); + switch (s) + { + case QsciScintilla::AcsAll: + m_edit_area->autoCompleteFromAll (); + break; + + case QsciScintilla::AcsAPIs: + m_edit_area->autoCompleteFromAPIs (); + break; + + case QsciScintilla::AcsDocument: + m_edit_area->autoCompleteFromDocument (); + break; + + case QsciScintilla::AcsNone: + break; + } + } + + void file_editor_tab::do_indent_selected_text (bool indent) + { + // FIXME: + m_edit_area->beginUndoAction (); + + if (m_edit_area->hasSelectedText ()) + { + int lineFrom, lineTo, colFrom, colTo; + m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); + + if (colTo == 0) // the beginning of last line is not selected + lineTo--; // stop at line above + + for (int i = lineFrom; i <= lineTo; i++) + { + if (indent) + m_edit_area->indent (i); + else + m_edit_area->unindent (i); + } + //set selection on (un)indented section + m_edit_area->setSelection (lineFrom, 0, lineTo, + m_edit_area->text (lineTo).length ()-1); + } + else + { + int cpline, col; + m_edit_area->getCursorPosition (&cpline, &col); + if (indent) + m_edit_area->indent (cpline); + else + m_edit_area->unindent (cpline); + } + + m_edit_area->endUndoAction (); + } + + void file_editor_tab::do_smart_indent_line_or_selected_text () + { + m_edit_area->beginUndoAction (); + + int lineFrom, lineTo; + + if (m_edit_area->hasSelectedText ()) + { + int colFrom, colTo; + m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); + + if (colTo == 0) // the beginning of last line is not selected + lineTo--; // stop at line above + } + else + { + int col; + m_edit_area->getCursorPosition (&lineFrom, &col); + + lineTo = lineFrom; + } + + m_edit_area->smart_indent_line_or_selected_text (lineFrom, lineTo); + + m_edit_area->endUndoAction (); + } + + void file_editor_tab::do_comment_selected_text (bool comment, bool input_str) + { + QRegExp rxc; + QString ws = "^(?:[ \\t]*)"; + QStringList comment_str = m_edit_area->comment_string (comment); + QString used_comment_str = comment_str.at (0); + + if (comment) + { + if (input_str) + { + bool ok; + 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 (), + &ok); + + if ((! ok) || used_comment_str.isEmpty ()) + return; // No input, do nothing + else + settings.setValue (ed_last_comment_str, used_comment_str); // Store last + } + } + else + { + // Uncommenting (several strings possible) + + // Sort strings according their length + QStringList comment_str_sorted (comment_str.at (0)); + bool inserted; + + for (int i = 1; i < comment_str.length (); i++) + { + inserted = false; + for (int j = 0; j < comment_str_sorted.length (); j++) + { + if (comment_str.at (i).length () > comment_str_sorted.at (j).length ()) + { + comment_str_sorted.insert (j, comment_str.at (i)); + inserted = true; + break; + } + } + if (! inserted) + comment_str_sorted << comment_str.at (i); + } + + // Create regular expression + QString regexp; + for (int i = 0; i < comment_str_sorted.length (); i++) + { + if (i > 0) + regexp = regexp + QString ("|"); + regexp = regexp + comment_str_sorted.at (i); + } + rxc = QRegExp (ws + "(" + regexp + ")"); + } + + // Do the commenting/uncommenting + int len = 0, lenc = 0; + m_edit_area->beginUndoAction (); + + if (m_edit_area->hasSelectedText ()) + { + int lineFrom, lineTo, colFrom, colTo; + int change_col_from = 1; + int change_col_to = 1; + bool removed; + + m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); + + if (colTo == 0) // the beginning of last line is not selected + lineTo--; // stop at line above + + for (int i = lineFrom; i <= lineTo; i++) + { + if (comment) + { + m_edit_area->insertAt (used_comment_str, i, 0); + } + else + { + QString line (m_edit_area->text (i)); + if ((removed = line.contains (rxc))) + { + len = rxc.matchedLength (); // complete length + QString matched_text = rxc.capturedTexts ().at (0); + lenc = matched_text.remove (QRegExp (ws)).length (); // only comment string + m_edit_area->setSelection (i, len-lenc, i, len); + m_edit_area->removeSelectedText (); + } + + // handle case, where the selection remains unchanged + if (i == lineFrom && (colFrom < len-lenc || ! removed)) + change_col_from = 0; // do not change start of selection + if (i == lineTo && (colTo < len-lenc || ! removed)) + change_col_to = 0; // do not change end of selection + } + } + + // update the selection area + if (comment) + { + colFrom = colFrom + lenc; // shift start position by comment length + if (colTo > 0) + colTo = colTo + lenc; // shift end position by comment length + else + lineTo++; // colTo == 0 , fully select previous line + } + else + { + if (colTo == 0) + lineTo++; // colTo == 0 , fully select previous line + colFrom = colFrom - change_col_from*lenc; + colTo = colTo - change_col_to*lenc; + } + + // set updated selection area + m_edit_area->setSelection (lineFrom, colFrom, lineTo, colTo); + } + else + { + int cpline, col; + m_edit_area->getCursorPosition (&cpline, &col); + if (comment) + m_edit_area->insertAt (used_comment_str, cpline, 0); + else + { + QString line (m_edit_area->text (cpline)); + if (line.contains (rxc)) + { + len = rxc.matchedLength (); // complete length + QString matched_text = rxc.capturedTexts ().at (0); + lenc = matched_text.remove (QRegExp (ws)).length (); // only comment string + m_edit_area->setSelection (cpline, len-lenc, cpline, len); + m_edit_area->removeSelectedText (); + } + } + } + m_edit_area->endUndoAction (); + } + + void file_editor_tab::update_window_title (bool modified) + { + QString title (""); + QString tooltip (""); + + if (! valid_file_name ()) + title = tr (""); + else + { + QFileInfo file (m_file_name); + title = file.fileName (); + tooltip = m_file_name; + } + + emit file_name_changed (title, tooltip, modified); + } + + void file_editor_tab::handle_copy_available (bool enableCopy) + { + m_copy_available = enableCopy; + emit editor_state_changed (m_copy_available, m_is_octave_file, + m_edit_area->isModified ()); + } + + // show_dialog: shows a modal or non modal dialog depending on input arg + void file_editor_tab::show_dialog (QDialog *dlg, bool modal) + { + dlg->setAttribute (Qt::WA_DeleteOnClose); + if (modal) + dlg->exec (); + else + { + dlg->setWindowModality (Qt::NonModal); + dlg->show (); + } + } + + int file_editor_tab::check_file_modified (bool remove) + { + int decision = QMessageBox::Yes; + if (m_edit_area->isModified ()) + { + // File is modified but not saved, ask user what to do. The file + // 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; + + // For now, just a warning message about closing a tab that has been + // modified seems sufficient. Exit-condition-specific messages could + // be achieved by making 'available_actions' a function input string. + QString available_actions = + tr ("Do you want to cancel closing, save or discard the changes?"); + + QString file; + if (valid_file_name ()) + file = m_file_name; + else + file = tr (""); + + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Warning, tr ("Octave Editor"), + tr ("The file\n\n" + " %1\n\n" + "is about to be closed but has been modified. " + "%2"). + arg (file). arg (available_actions), + buttons, qobject_cast (parent ())); + + msgBox->setDefaultButton (QMessageBox::Save); + m_edit_area->setReadOnly (true); + + decision = msgBox->exec (); // show_dialog (msgBox, true); + + if (decision == QMessageBox::Cancel) + m_edit_area->setReadOnly (false); + else if (decision == QMessageBox::Save) + save_file (m_file_name, remove, false); + else + emit tab_ready_to_close (); + } + else + { emit tab_ready_to_close (); - } - else - { - emit tab_ready_to_close (); - } - - return decision; -} - -void file_editor_tab::set_modified (bool modified) -{ - m_edit_area->setModified (modified); -} - -void file_editor_tab::recover_from_exit (void) -{ - // reset the possibly still existing read only state - m_edit_area->setReadOnly (false); - - // if we are in this slot and the list of breakpoints is not empty, - // then this tab was saved during an exit of the applications (not - // restoring the breakpoints and not emptying the list) and the user - // canceled this closing late on. - check_restore_breakpoints (); -} - -void file_editor_tab::check_restore_breakpoints (void) -{ - if (! m_bp_lines.isEmpty ()) - { - // At least one breakpoint is present. - // Get rid of breakpoints at old (now possibly invalid) linenumbers - remove_all_breakpoints (this); - - // and set breakpoints at the new linenumbers - m_bp_restore_count = m_bp_lines.length (); - for (int i = 0; i < m_bp_lines.length (); i++) - handle_request_add_breakpoint (m_bp_lines.value (i) + 1, - m_bp_conditions.value (i)); - - // Keep the list of breakpoints empty, except after explicit requests. - m_bp_lines.clear (); - m_bp_conditions.clear (); - } -} - -QString file_editor_tab::load_file (const QString& fileName) -{ - // get the absolute path - QFileInfo file_info = QFileInfo (fileName); - QString file_to_load; - if (file_info.exists ()) - file_to_load = file_info.canonicalFilePath (); - else - file_to_load = fileName; - QFile file (file_to_load); - if (!file.open(QIODevice::ReadOnly)) - return file.errorString (); - - int col = 0, line = 0; - if (fileName == m_file_name) - { - // We have to reload the current file, thus get current cursor position - line = m_line; - col = m_col; - } - - QApplication::setOverrideCursor (Qt::WaitCursor); - - // read the file binary, decoding later - 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 ()) - { - const QByteArray eol_lf = QByteArray (1, 0x0a); - const QByteArray eol_cr = QByteArray (1, 0x0d); - - if (text_data.endsWith (eol_lf)) - text_data.chop (1); // remove LF - - if (text_data.endsWith (eol_cr)) // remove CR (altogether CRLF, too) - 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) - { - // Set read only - m_edit_area->setReadOnly (true); - - // 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); - QMessageBox *msg_box = new QMessageBox (); - msg_box->setIcon (QMessageBox::Warning); - msg_box->setText (msg); - msg_box->setWindowTitle (tr ("Octave Editor")); - msg_box->addButton (tr ("&Edit anyway"), QMessageBox::YesRole); - msg_box->addButton (tr ("Chan&ge encoding"), QMessageBox::AcceptRole); - msg_box->addButton (tr ("&Close"), QMessageBox::RejectRole); - - connect (msg_box, &QMessageBox::buttonClicked, - this, &file_editor_tab::handle_decode_warning_answer); - - msg_box->setWindowModality (Qt::WindowModal); - msg_box->setAttribute (Qt::WA_DeleteOnClose); - msg_box->show (); - } - - 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 - set_file_name (file_to_load); - - update_eol_indicator (); - - m_edit_area->setCursorPosition (line, col); - - return QString (); -} - -void file_editor_tab::handle_decode_warning_answer (QAbstractButton *btn) -{ - QString txt = btn->text (); - - if (txt == tr ("&Close")) - { - // Just close the file - close (); + } + + return decision; + } + + void file_editor_tab::set_modified (bool modified) + { + m_edit_area->setModified (modified); + } + + void file_editor_tab::recover_from_exit () + { + // reset the possibly still existing read only state + m_edit_area->setReadOnly (false); + + // if we are in this slot and the list of breakpoints is not empty, + // then this tab was saved during an exit of the applications (not + // restoring the breakpoints and not emptying the list) and the user + // canceled this closing late on. + check_restore_breakpoints (); + } + + void file_editor_tab::check_restore_breakpoints () + { + if (! m_bp_lines.isEmpty ()) + { + // At least one breakpoint is present. + // Get rid of breakpoints at old (now possibly invalid) linenumbers + remove_all_breakpoints (this); + + // and set breakpoints at the new linenumbers + m_bp_restore_count = m_bp_lines.length (); + for (int i = 0; i < m_bp_lines.length (); i++) + handle_request_add_breakpoint (m_bp_lines.value (i) + 1, + m_bp_conditions.value (i)); + + // Keep the list of breakpoints empty, except after explicit requests. + m_bp_lines.clear (); + m_bp_conditions.clear (); + } + } + + QString file_editor_tab::load_file (const QString& fileName) + { + // get the absolute path + QFileInfo file_info = QFileInfo (fileName); + QString file_to_load; + if (file_info.exists ()) + file_to_load = file_info.canonicalFilePath (); + else + file_to_load = fileName; + QFile file (file_to_load); + if (!file.open(QIODevice::ReadOnly)) + return file.errorString (); + + int col = 0, line = 0; + if (fileName == m_file_name) + { + // We have to reload the current file, thus get current cursor position + line = m_line; + col = m_col; + } + + QApplication::setOverrideCursor (Qt::WaitCursor); + + // read the file binary, decoding later + QByteArray text_data = file.readAll (); + + // remove newline at end of file if we add one again when saving + + gui_settings settings; + + if (settings.bool_value (ed_force_newline)) + { + const QByteArray eol_lf = QByteArray (1, 0x0a); + const QByteArray eol_cr = QByteArray (1, 0x0d); + + if (text_data.endsWith (eol_lf)) + text_data.chop (1); // remove LF + + if (text_data.endsWith (eol_cr)) // remove CR (altogether CRLF, too) + 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) + { + // Set read only + m_edit_area->setReadOnly (true); + + // 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); + QMessageBox *msg_box = new QMessageBox (); + msg_box->setIcon (QMessageBox::Warning); + msg_box->setText (msg); + msg_box->setWindowTitle (tr ("Octave Editor")); + msg_box->addButton (tr ("&Edit anyway"), QMessageBox::YesRole); + msg_box->addButton (tr ("Chan&ge encoding"), QMessageBox::AcceptRole); + msg_box->addButton (tr ("&Close"), QMessageBox::RejectRole); + + connect (msg_box, &QMessageBox::buttonClicked, + this, &file_editor_tab::handle_decode_warning_answer); + + msg_box->setWindowModality (Qt::WindowModal); + msg_box->setAttribute (Qt::WA_DeleteOnClose); + msg_box->show (); + } + + 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 + set_file_name (file_to_load); + + update_eol_indicator (); + + m_edit_area->setCursorPosition (line, col); + + return QString (); + } + + void file_editor_tab::handle_decode_warning_answer (QAbstractButton *btn) + { + QString txt = btn->text (); + + if (txt == tr ("&Close")) + { + // Just close the file + close (); + return; + } + + if (txt == tr ("Chan&ge encoding")) + { + // Dialog for reloading the file with another encoding + QDialog dlg; + dlg.setWindowTitle (tr ("Select new default encoding")); + + QLabel *text + = new QLabel (tr ("Please select a new encoding\n" + "for reloading the current file.\n\n" + "This does not change the default encoding.\n")); + + QComboBox *enc_combo = new QComboBox (); + 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); + + QDialogButtonBox *buttons + = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, + Qt::Horizontal); + connect (buttons, &QDialogButtonBox::accepted, &dlg, &QDialog::accept); + connect (buttons, &QDialogButtonBox::rejected, &dlg, &QDialog::reject); + + QGridLayout *main_layout = new QGridLayout; + main_layout->setSizeConstraint (QLayout::SetFixedSize); + main_layout->addWidget (text, 0, 0); + main_layout->addWidget (enc_combo, 1, 0); + main_layout->addWidget (buttons, 2, 0); + dlg.setLayout (main_layout); + + int answer = dlg.exec (); + + if (answer == QDialog::Accepted) + { + // Reload the file with new encoding but using the same tab + QString reload_file_name = m_file_name; // store file name + m_file_name = ""; // force reuse of this tab when opening a new file + emit request_open_file (reload_file_name, m_new_encoding); + } + } + + // Continue editing, set writable again + m_edit_area->setReadOnly (false); + } + + void file_editor_tab::handle_current_enc_changed (const QString& enc) + { + m_new_encoding = enc; + } + + QsciScintilla::EolMode file_editor_tab::detect_eol_mode () + { + QByteArray text = m_edit_area->text ().toLatin1 (); + + QByteArray eol_lf = QByteArray (1, 0x0a); + QByteArray eol_cr = QByteArray (1, 0x0d); + QByteArray eol_crlf = eol_cr; + eol_crlf.append (eol_lf); + + int count_crlf = text.count (eol_crlf); + int count_lf = text.count (eol_lf) - count_crlf; // isolated lf + int count_cr = text.count (eol_cr) - count_crlf; // isolated cr + + gui_settings settings; + + QsciScintilla::EolMode eol_mode + = static_cast (settings.int_value (ed_default_eol_mode)); + + int count_max = 0; + + if (count_crlf > count_max) + { + eol_mode = QsciScintilla::EolWindows; + count_max = count_crlf; + } + if (count_lf > count_max) + { + eol_mode = QsciScintilla::EolUnix; + count_max = count_lf; + } + if (count_cr > count_max) + { + eol_mode = QsciScintilla::EolMac; + } + + return eol_mode; + } + + void file_editor_tab::update_eol_indicator () + { + switch (m_edit_area->eolMode ()) + { + case QsciScintilla::EolWindows: + m_eol_indicator->setText ("CRLF"); + break; + case QsciScintilla::EolMac: + m_eol_indicator->setText ("CR"); + break; + case QsciScintilla::EolUnix: + m_eol_indicator->setText ("LF"); + break; + } + } + + void file_editor_tab::update_breakpoints () + { + if (m_file_name.isEmpty ()) return; - } - - if (txt == tr ("Chan&ge encoding")) - { - // Dialog for reloading the file with another encoding - QDialog dlg; - dlg.setWindowTitle (tr ("Select new default encoding")); - - QLabel *text - = new QLabel (tr ("Please select a new encoding\n" - "for reloading the current file.\n\n" - "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); - m_new_encoding = enc_combo->currentText (); - connect (enc_combo, &QComboBox::currentTextChanged, - this, &file_editor_tab::handle_current_enc_changed); - - QDialogButtonBox *buttons - = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, - Qt::Horizontal); - connect (buttons, &QDialogButtonBox::accepted, &dlg, &QDialog::accept); - connect (buttons, &QDialogButtonBox::rejected, &dlg, &QDialog::reject); - - QGridLayout *main_layout = new QGridLayout; - main_layout->setSizeConstraint (QLayout::SetFixedSize); - main_layout->addWidget (text, 0, 0); - main_layout->addWidget (enc_combo, 1, 0); - main_layout->addWidget (buttons, 2, 0); - dlg.setLayout (main_layout); - - int answer = dlg.exec (); - - if (answer == QDialog::Accepted) - { - // Reload the file with new encoding but using the same tab - QString reload_file_name = m_file_name; // store file name - m_file_name = ""; // force reuse of this tab when opening a new file - emit request_open_file (reload_file_name, m_new_encoding); - } - } - - // Continue editing, set writable again - m_edit_area->setReadOnly (false); -} - -void file_editor_tab::handle_current_enc_changed (const QString& enc) -{ - m_new_encoding = enc; -} - -QsciScintilla::EolMode file_editor_tab::detect_eol_mode (void) -{ - QByteArray text = m_edit_area->text ().toLatin1 (); - - QByteArray eol_lf = QByteArray (1, 0x0a); - QByteArray eol_cr = QByteArray (1, 0x0d); - QByteArray eol_crlf = eol_cr; - eol_crlf.append (eol_lf); - - int count_crlf = text.count (eol_crlf); - 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 (); - QsciScintilla::EolMode eol_mode - = static_cast (settings->value (ed_default_eol_mode).toInt ()); - - int count_max = 0; - - if (count_crlf > count_max) - { - eol_mode = QsciScintilla::EolWindows; - count_max = count_crlf; - } - if (count_lf > count_max) - { - eol_mode = QsciScintilla::EolUnix; - count_max = count_lf; - } - if (count_cr > count_max) - { - eol_mode = QsciScintilla::EolMac; - } - - return eol_mode; -} - -void file_editor_tab::update_eol_indicator (void) -{ - switch (m_edit_area->eolMode ()) - { - case QsciScintilla::EolWindows: - m_eol_indicator->setText ("CRLF"); - break; - case QsciScintilla::EolMac: - m_eol_indicator->setText ("CR"); - break; - case QsciScintilla::EolUnix: - m_eol_indicator->setText ("LF"); - break; - } -} - -void file_editor_tab::update_breakpoints () -{ - if (m_file_name.isEmpty ()) - return; - - // Create and queue the command object. - - // 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_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 ()) + + // Create and queue the command object. + + // 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_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; + + 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) + { + octave_map dbg = argout(0).map_value (); + octave_idx_type n_dbg = dbg.numel (); + + Cell file = dbg.contents ("file"); + Cell line = dbg.contents ("line"); + Cell cond = dbg.contents ("cond"); + + for (octave_idx_type i = 0; i < n_dbg; i++) + { + if (file (i).string_value () == m_file_name.toStdString ()) + do_breakpoint_marker (true, this, line (i).int_value (), + QString::fromStdString (cond (i).string_value ())); + } + } + + void file_editor_tab::new_file (const QString& commands) + { + update_window_title (false); // window title (no modification) + + 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.int_value (ed_default_eol_mode))); + + update_eol_indicator (); + + update_lexer (); + + m_edit_area->setText (commands); + m_edit_area->setModified (!commands.isEmpty ()); + } + + void file_editor_tab::confirm_dbquit_and_save (const QString& file_to_save, + const QString& base_name, + bool remove_on_success, + bool restore_breakpoints) + { + int ans = QMessageBox::question (nullptr, tr ("Debug or Save"), + tr ("This file is currently being executed.\n" + "Quit debugging and save?"), + QMessageBox::Save | QMessageBox::Cancel); + + if (ans == QMessageBox::Save) + { + // 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_fetab (this); + + 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); + }); + } + } + + void file_editor_tab::save_file (const QString& saveFileName, + bool remove_on_success, + bool restore_breakpoints) + { + // If it is a new file with no name, signal that saveFileAs + // should be performed. + if (! valid_file_name (saveFileName)) + { + save_file_as (remove_on_success); + return; + } + + 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) + return; // No valid codec + + // Get a list of breakpoint line numbers, before exiting debug mode + // and clearing function in interpreter_event action below. + + emit report_marker_linenr (m_bp_lines, m_bp_conditions); + + // get the absolute path (if existing) + QFileInfo file_info = QFileInfo (saveFileName); + QString file_to_save; + if (file_info.exists ()) + { + file_to_save = file_info.canonicalFilePath (); + QString base_name = file_info.baseName (); + + // 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_fetab (this); + + 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); + }); + } + else + emit do_save_file_signal (saveFileName, remove_on_success, + restore_breakpoints); + } + + void file_editor_tab::do_save_file (const QString& file_to_save, + bool remove_on_success, + bool restore_breakpoints) + { + QSaveFile file (file_to_save); + + // stop watching file + QStringList trackedFiles = m_file_system_watcher.files (); + if (trackedFiles.contains (file_to_save)) + m_file_system_watcher.removePath (file_to_save); + + // Remove trailing white spaces if desired + + 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 + // the modified file. + bool ro = m_edit_area->isReadOnly (); + m_edit_area->setReadOnly (false); // allow writing for replace_all + m_edit_area->replace_all ("[ \\t]+$", "", true, false, false); + m_edit_area->setReadOnly (ro); // recover read only state + } + + // open the file for writing (use QIODevice::ReadWrite for avoiding + // truncating the previous file contents) + if (! file.open (QIODevice::WriteOnly)) + { + // Unsuccessful, begin watching file again if it was being + // watched previously. + if (trackedFiles.contains (file_to_save)) + m_file_system_watcher.addPath (file_to_save); + + // Create a NonModal message about error. + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Critical, + tr ("Octave Editor"), + tr ("Could not open file %1 for write:\n%2."). + arg (file_to_save).arg (file.errorString ()), + QMessageBox::Ok, nullptr); + show_dialog (msgBox, false); + 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) -{ - octave_map dbg = argout(0).map_value (); - octave_idx_type n_dbg = dbg.numel (); - - Cell file = dbg.contents ("file"); - Cell line = dbg.contents ("line"); - Cell cond = dbg.contents ("cond"); - - for (octave_idx_type i = 0; i < n_dbg; i++) - { - if (file (i).string_value () == m_file_name.toStdString ()) - do_breakpoint_marker (true, this, line (i).int_value (), - QString::fromStdString (cond (i).string_value ())); - } -} - -void file_editor_tab::new_file (const QString& commands) -{ - update_window_title (false); // window title (no modification) - - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_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 ())); - - update_eol_indicator (); - - update_lexer (); - - m_edit_area->setText (commands); - m_edit_area->setModified (!commands.isEmpty ()); -} - -void file_editor_tab::confirm_dbquit_and_save (const QString& file_to_save, - const QString& base_name, - bool remove_on_success, - bool restore_breakpoints) -{ - int ans = QMessageBox::question (nullptr, tr ("Debug or Save"), - tr ("This file is currently being executed.\n" - "Quit debugging and save?"), - QMessageBox::Save | QMessageBox::Cancel); - - if (ans == QMessageBox::Save) - { - // 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_fetab (this); - - 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); - }); - } -} - -void file_editor_tab::save_file (const QString& saveFileName, - bool remove_on_success, - bool restore_breakpoints) -{ - // If it is a new file with no name, signal that saveFileAs - // should be performed. - if (! valid_file_name (saveFileName)) - { - save_file_as (remove_on_success); + } + + // 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); + + QApplication::setOverrideCursor (Qt::WaitCursor); + + out << m_edit_area->text (); + if (settings.bool_value (ed_force_newline) + && m_edit_area->text ().length ()) + out << m_edit_area->eol_string (); // Add newline if desired + + out.flush (); + QApplication::restoreOverrideCursor (); + + // Finish writing by committing the changes to disk, + // where nothing is done when an error occurred while writing above + bool writing_ok = file.commit (); + + if (writing_ok) + { + // Writing was successful: file exists now + QFileInfo file_info = QFileInfo (file.fileName ()); + QString full_file_to_save = file_info.canonicalFilePath (); + + // file is save -> not modified, update encoding in statusbar + m_edit_area->setModified (false); + m_enc_indicator->setText (m_encoding); + + // save filename after closing file as set_file_name starts watching again + set_file_name (full_file_to_save); // make absolute + + emit tab_ready_to_close (); + + if (remove_on_success) + { + emit tab_remove_request (); + return; // Don't touch member variables after removal + } + + // Attempt to restore the breakpoints if that is desired. + // This is only allowed if the tab is not closing since changing + // breakpoints would reopen the tab in this case. + if (restore_breakpoints) + check_restore_breakpoints (); + } + else + { + QMessageBox::critical (nullptr, + tr ("Octave Editor"), + tr ("The changes could not be saved to the file\n" + "%1") + .arg (file.fileName ()) + ); + } + } + + void file_editor_tab::save_file_as (bool remove_on_success) + { + // Simply put up the file chooser dialog box with a slot connection + // then return control to the system waiting for a file selection. + + // reset m_new_encoding + m_new_encoding = m_encoding; + + // If the tab is removed in response to a QFileDialog signal, the tab + // can't be a parent. + QFileDialog *fileDialog; + if (remove_on_success) + { + // If tab is closed, "this" cannot be parent in which case modality + // has no effect. Disable editing instead. + m_edit_area->setReadOnly (true); + fileDialog = new QFileDialog (); + } + else + fileDialog = new QFileDialog (this); + + // add the possible filters and the default suffix + QStringList filters; + filters << tr ("Octave Files (*.m)") + << tr ("All Files (*)"); + fileDialog->setNameFilters (filters); + fileDialog->setDefaultSuffix ("m"); + + if (valid_file_name ()) + { + fileDialog->selectFile (m_file_name); + QFileInfo file_info (m_file_name); + if (file_info.suffix () != "m") + { + // it is not an octave file + fileDialog->selectNameFilter (filters.at (1)); // "All Files" + fileDialog->setDefaultSuffix (""); // no default suffix + } + } + else + { + fileDialog->selectFile (""); + fileDialog->setDirectory (m_ced); + + // propose a name corresponding to the function name + // if the new file contains a function + QString fname = get_function_name (); + if (! fname.isEmpty ()) + fileDialog->selectFile (fname + ".m"); + } + + fileDialog->setAcceptMode (QFileDialog::AcceptSave); + fileDialog->setViewMode (QFileDialog::Detail); + fileDialog->setOption (QFileDialog::HideNameFilterDetails, false); + + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) + { + // Qt file dialogs + fileDialog->setOption(QFileDialog::DontUseNativeDialog); + } + else + { + // Native file dialogs: Test for already existing files is done manually + // since native file dialogs might not consider the automatically + // appended default extension when checking if the file already exists + fileDialog->setOption(QFileDialog::DontConfirmOverwrite); + } + + connect (fileDialog, &QFileDialog::filterSelected, + this, &file_editor_tab::handle_save_as_filter_selected); + + if (remove_on_success) + { + connect (fileDialog, &QFileDialog::fileSelected, + this, &file_editor_tab::handle_save_file_as_answer_close); + + connect (fileDialog, &QFileDialog::rejected, + this, &file_editor_tab::handle_save_file_as_answer_cancel); + } + else + { + connect (fileDialog, &QFileDialog::fileSelected, + this, &file_editor_tab::handle_save_file_as_answer); + } + + show_dialog (fileDialog, ! valid_file_name ()); + } + + void file_editor_tab::handle_save_as_filter_selected (const QString& filter) + { + // On some systems, the filterSelected signal is emitted without user + // action and with an empty filter string when the file dialog is shown. + // Just return in this case and do not remove the current default suffix. + if (filter.isEmpty ()) return; - } - - 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) - return; // No valid codec - - // Get a list of breakpoint line numbers, before exiting debug mode - // and clearing function in interpreter_event action below. - - emit report_marker_linenr (m_bp_lines, m_bp_conditions); - - // get the absolute path (if existing) - QFileInfo file_info = QFileInfo (saveFileName); - QString file_to_save; - if (file_info.exists ()) - { - file_to_save = file_info.canonicalFilePath (); - QString base_name = file_info.baseName (); - - // 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_fetab (this); - - 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 ()) + + 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 + else + file_dialog->setDefaultSuffix (""); // not found, clear default + } + + bool file_editor_tab::check_valid_identifier (QString file_name) + { + QFileInfo file = QFileInfo (file_name); + QString base_name = file.baseName (); + + if ((file.suffix () == "m") + && (! valid_identifier (base_name.toStdString ()))) + { + int ans = QMessageBox::question (nullptr, tr ("Octave Editor"), + tr ("\"%1\"\n" + "is not a valid identifier.\n\n" + "If you keep this filename, you will not be able to\n" + "call your script using its name as an Octave command.\n\n" + "Do you want to choose another name?").arg (base_name), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + + if (ans == QMessageBox::Yes) + return true; + } + + return false; + } + + QTextCodec* 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) + { + 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 (! can_encode) + { + QMessageBox::StandardButton pressed_button + = QMessageBox::critical (nullptr, + tr ("Octave Editor"), + tr ("The current editor contents can not be encoded\n" + "with the selected encoding %1.\n" + "Using it would result in data loss!\n\n" + "Please select another one!").arg (m_encoding), + QMessageBox::Cancel | QMessageBox::Ignore, + QMessageBox::Cancel); + + if (pressed_button == QMessageBox::Ignore) + return codec; + else + return nullptr; + } + + return codec; + } + + void file_editor_tab::handle_save_file_as_answer (const QString& save_file_name) + { + QString saveFileName = save_file_name; + QFileInfo file (saveFileName); + QFileDialog *file_dialog = qobject_cast (sender ()); + + // Test if the file dialog should have added a default file + // suffix, but the selected file still has no suffix (see Qt bug + // https://bugreports.qt.io/browse/QTBUG-59401) + if ((! file_dialog->defaultSuffix ().isEmpty ()) && file.suffix ().isEmpty ()) + { + saveFileName = saveFileName + "." + file_dialog->defaultSuffix (); + } + + file.setFile (saveFileName); + + // If overwrite confirmation was not done by the file dialog (in case + // of native file dialogs, see above), do it here + 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); + if (ans != QMessageBox::Yes) + { + // Try again, if edit area is read only, remove on success + save_file_as (m_edit_area->isReadOnly ()); 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, - restore_breakpoints); -} - -void file_editor_tab::do_save_file (const QString& file_to_save, - bool remove_on_success, - bool restore_breakpoints) -{ - QSaveFile file (file_to_save); - - // stop watching file - QStringList trackedFiles = m_file_system_watcher.files (); - if (trackedFiles.contains (file_to_save)) - 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 ()) - { - // Replace trailing spaces, make sure edit area is writable, - // which is not the case when saving at exit or when closing - // the modified file. - bool ro = m_edit_area->isReadOnly (); - m_edit_area->setReadOnly (false); // allow writing for replace_all - m_edit_area->replace_all ("[ \\t]+$", "", true, false, false); - m_edit_area->setReadOnly (ro); // recover read only state - } - - // open the file for writing (use QIODevice::ReadWrite for avoiding - // truncating the previous file contents) - if (! file.open (QIODevice::WriteOnly)) - { - // Unsuccessful, begin watching file again if it was being - // watched previously. - if (trackedFiles.contains (file_to_save)) - m_file_system_watcher.addPath (file_to_save); - - // Create a NonModal message about error. - QMessageBox *msgBox - = new QMessageBox (QMessageBox::Critical, - tr ("Octave Editor"), - tr ("Could not open file %1 for write:\n%2."). - arg (file_to_save).arg (file.errorString ()), - QMessageBox::Ok, nullptr); - show_dialog (msgBox, false); - - 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); - - 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 (); - QApplication::restoreOverrideCursor (); - - // Finish writing by committing the changes to disk, - // where nothing is done when an error occurred while writing above - bool writing_ok = file.commit (); - - if (writing_ok) - { - // Writing was successful: file exists now - QFileInfo file_info = QFileInfo (file.fileName ()); - QString full_file_to_save = file_info.canonicalFilePath (); - - // file is save -> not modified, update encoding in statusbar - m_edit_area->setModified (false); - m_enc_indicator->setText (m_encoding); - - // save filename after closing file as set_file_name starts watching again - set_file_name (full_file_to_save); // make absolute - - emit tab_ready_to_close (); - - if (remove_on_success) - { - emit tab_remove_request (); - return; // Don't touch member variables after removal - } - - // Attempt to restore the breakpoints if that is desired. - // This is only allowed if the tab is not closing since changing - // breakpoints would reopen the tab in this case. - if (restore_breakpoints) - check_restore_breakpoints (); - } - else - { - QMessageBox::critical (nullptr, - tr ("Octave Editor"), - tr ("The changes could not be saved to the file\n" - "%1") - .arg (file.fileName ()) - ); - } -} - -void file_editor_tab::save_file_as (bool remove_on_success) -{ - // Simply put up the file chooser dialog box with a slot connection - // then return control to the system waiting for a file selection. - - // reset m_new_encoding - m_new_encoding = m_encoding; - - // If the tab is removed in response to a QFileDialog signal, the tab - // can't be a parent. - QFileDialog *fileDialog; - if (remove_on_success) - { - // If tab is closed, "this" cannot be parent in which case modality - // has no effect. Disable editing instead. - m_edit_area->setReadOnly (true); - fileDialog = new QFileDialog (); - } - else - fileDialog = new QFileDialog (this); - - // add the possible filters and the default suffix - QStringList filters; - filters << tr ("Octave Files (*.m)") - << tr ("All Files (*)"); - fileDialog->setNameFilters (filters); - fileDialog->setDefaultSuffix ("m"); - - if (valid_file_name ()) - { - fileDialog->selectFile (m_file_name); - QFileInfo file_info (m_file_name); - if (file_info.suffix () != "m") - { - // it is not an octave file - fileDialog->selectNameFilter (filters.at (1)); // "All Files" - fileDialog->setDefaultSuffix (""); // no default suffix - } - } - else - { - fileDialog->selectFile (""); - fileDialog->setDirectory (m_ced); - - // propose a name corresponding to the function name - // if the new file contains a function - QString fname = get_function_name (); - if (! fname.isEmpty ()) - fileDialog->selectFile (fname + ".m"); - } - - fileDialog->setAcceptMode (QFileDialog::AcceptSave); - fileDialog->setViewMode (QFileDialog::Detail); - 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 ()) - { - // Qt file dialogs - fileDialog->setOption(QFileDialog::DontUseNativeDialog); - } - else - { - // Native file dialogs: Test for already existing files is done manually - // since native file dialogs might not consider the automatically - // appended default extension when checking if the file already exists - fileDialog->setOption(QFileDialog::DontConfirmOverwrite); - } - - connect (fileDialog, &QFileDialog::filterSelected, - this, &file_editor_tab::handle_save_as_filter_selected); - - if (remove_on_success) - { - connect (fileDialog, &QFileDialog::fileSelected, - this, &file_editor_tab::handle_save_file_as_answer_close); - - connect (fileDialog, &QFileDialog::rejected, - this, &file_editor_tab::handle_save_file_as_answer_cancel); - } - else - { - connect (fileDialog, &QFileDialog::fileSelected, - this, &file_editor_tab::handle_save_file_as_answer); - } - - show_dialog (fileDialog, ! valid_file_name ()); -} - -void file_editor_tab::handle_save_as_filter_selected (const QString& filter) -{ - // On some systems, the filterSelected signal is emitted without user - // action and with an empty filter string when the file dialog is shown. - // Just return in this case and do not remove the current default suffix. - if (filter.isEmpty ()) - return; - - 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 - else - file_dialog->setDefaultSuffix (""); // not found, clear default -} - -bool file_editor_tab::check_valid_identifier (QString file_name) -{ - QFileInfo file = QFileInfo (file_name); - QString base_name = file.baseName (); - - if ((file.suffix () == "m") - && (! valid_identifier (base_name.toStdString ()))) - { - int ans = QMessageBox::question (nullptr, tr ("Octave Editor"), - tr ("\"%1\"\n" - "is not a valid identifier.\n\n" - "If you keep this filename, you will not be able to\n" - "call your script using its name as an Octave command.\n\n" - "Do you want to choose another name?").arg (base_name), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - - if (ans == QMessageBox::Yes) - return true; - } - - return false; -} - -QTextCodec* 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) - { - 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 (! can_encode) - { - QMessageBox::StandardButton pressed_button - = QMessageBox::critical (nullptr, + } + } + + if (saveFileName == m_file_name) + { + save_file (saveFileName); + } + else + { + // Have editor check for conflict, do not delete tab after save. + if (check_valid_identifier (saveFileName)) + save_file_as (false); + else + emit editor_check_conflict_save (saveFileName, false); + } + } + + void file_editor_tab::handle_save_file_as_answer_close (const QString& saveFileName) + { + // saveFileName == m_file_name can not happen, because we only can get here + // when we close a tab and m_file_name is not a valid filename yet + + // Have editor check for conflict, delete tab after save. + if (check_valid_identifier (saveFileName)) + save_file_as (true); + else + emit editor_check_conflict_save (saveFileName, true); + } + + void file_editor_tab::handle_save_file_as_answer_cancel () + { + // User canceled, allow editing again. + m_edit_area->setReadOnly (false); + } + + void file_editor_tab::file_has_changed (const QString&, bool do_close) + { + bool file_exists = QFile::exists (m_file_name); + + if (file_exists && ! do_close) + { + // Test if file is really modified or if just the timezone has + // changed. In the latter, just return without doing anything. + QDateTime modified = QFileInfo (m_file_name).lastModified ().toUTC (); + + if (modified <= m_last_modified) + return; + + m_last_modified = modified; + } + + // Prevent popping up multiple message boxes when the file has + // been changed multiple times by temporarily removing from the + // file watcher. + QStringList trackedFiles = m_file_system_watcher.files (); + if (! trackedFiles.isEmpty ()) + m_file_system_watcher.removePath (m_file_name); + + if (file_exists && ! do_close) + { + + // The file is modified + if (m_always_reload_changed_files) + load_file (m_file_name); + + else + { + // give editor and this tab the focus, + // possibly making the editor visible if it is hidden + emit set_focus_editor_signal (this); + m_edit_area->setFocus (); + + // Create a WindowModal message that blocks the edit area + // by making m_edit_area parent. + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Warning, tr ("Octave Editor"), - tr ("The current editor contents can not be encoded\n" - "with the selected encoding %1.\n" - "Using it would result in data loss!\n\n" - "Please select another one!").arg (m_encoding), - QMessageBox::Cancel | QMessageBox::Ignore, - QMessageBox::Cancel); - - if (pressed_button == QMessageBox::Ignore) - return codec; - else - return nullptr; - } - - return codec; -} - -void file_editor_tab::handle_save_file_as_answer (const QString& save_file_name) -{ - QString saveFileName = save_file_name; - QFileInfo file (saveFileName); - QFileDialog *file_dialog = qobject_cast (sender ()); - - // Test if the file dialog should have added a default file - // suffix, but the selected file still has no suffix (see Qt bug - // https://bugreports.qt.io/browse/QTBUG-59401) - if ((! file_dialog->defaultSuffix ().isEmpty ()) && file.suffix ().isEmpty ()) - { - saveFileName = saveFileName + "." + file_dialog->defaultSuffix (); - } - - file.setFile (saveFileName); - - // If overwrite confirmation was not done by the file dialog (in case - // of native file dialogs, see above), do it here - 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); - if (ans != QMessageBox::Yes) - { - // Try again, if edit area is read only, remove on success - save_file_as (m_edit_area->isReadOnly ()); - return; - } - } - - if (saveFileName == m_file_name) - { - save_file (saveFileName); - } - else - { - // Have editor check for conflict, do not delete tab after save. - if (check_valid_identifier (saveFileName)) - save_file_as (false); + tr ("It seems that \'%1\' has been modified by another application. Do you want to reload it?"). + arg (m_file_name), + QMessageBox::Yes | QMessageBox::No, this); + + connect (msgBox, &QMessageBox::finished, + this, &file_editor_tab::handle_file_reload_answer); + + msgBox->setWindowModality (Qt::WindowModal); + msgBox->setAttribute (Qt::WA_DeleteOnClose); + msgBox->show (); + } + } + else + { + // If desired and if file is not modified, + // close the file without any user interaction + if (do_close && ! m_edit_area->isModified ()) + { + handle_file_resave_answer (QMessageBox::Cancel); + return; + } + + // give editor and this tab the focus, + // possibly making the editor visible if it is hidden + emit set_focus_editor_signal (this); + m_edit_area->setFocus (); + + QString modified = ""; + if (m_edit_area->isModified ()) + modified = tr ("\n\nWarning: The contents in the editor is modified!"); + + // Create a WindowModal message. The file 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 *msgBox + = new QMessageBox (QMessageBox::Warning, tr ("Octave Editor"), + tr ("It seems that the file\n" + "%1\n" + "has been deleted or renamed. Do you want to save it now?%2"). + arg (m_file_name).arg (modified), + QMessageBox::Save | QMessageBox::Close, nullptr); + + m_edit_area->setReadOnly (true); + + connect (msgBox, &QMessageBox::finished, + this, &file_editor_tab::handle_file_resave_answer); + + msgBox->setWindowModality (Qt::WindowModal); + msgBox->setAttribute (Qt::WA_DeleteOnClose); + msgBox->show (); + } + } + + void file_editor_tab::notice_settings (bool init) + { + gui_settings settings; + + if (! init) + update_lexer_settings (); + + // code folding + if (settings.bool_value (ed_code_folding)) + { + m_edit_area->setMarginType (3, QsciScintilla::SymbolMargin); + m_edit_area->setFolding (QsciScintilla::BoxedTreeFoldStyle, 3); + } + else + { + m_edit_area->setFolding (QsciScintilla::NoFoldStyle, 3); + } + + // status bar + 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.bool_value (ed_highlight_current_line)); + + // auto completion + 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) + if (match_document) + source = QsciScintilla::AcsAll; else - emit editor_check_conflict_save (saveFileName, false); - } -} - -void file_editor_tab::handle_save_file_as_answer_close (const QString& saveFileName) -{ - // saveFileName == m_file_name can not happen, because we only can get here - // when we close a tab and m_file_name is not a valid filename yet - - // Have editor check for conflict, delete tab after save. - if (check_valid_identifier (saveFileName)) - save_file_as (true); - else - emit editor_check_conflict_save (saveFileName, true); -} - -void file_editor_tab::handle_save_file_as_answer_cancel (void) -{ - // User canceled, allow editing again. - m_edit_area->setReadOnly (false); -} - -void file_editor_tab::file_has_changed (const QString&, bool do_close) -{ - bool file_exists = QFile::exists (m_file_name); - - if (file_exists && ! do_close) - { - // Test if file is really modified or if just the timezone has - // changed. In the latter, just return without doing anything. - QDateTime modified = QFileInfo (m_file_name).lastModified ().toUTC (); - - if (modified <= m_last_modified) - return; - - m_last_modified = modified; - } - - // Prevent popping up multiple message boxes when the file has - // been changed multiple times by temporarily removing from the - // file watcher. - QStringList trackedFiles = m_file_system_watcher.files (); - if (! trackedFiles.isEmpty ()) - m_file_system_watcher.removePath (m_file_name); - - if (file_exists && ! do_close) - { - - // The file is modified - if (m_always_reload_changed_files) - load_file (m_file_name); - - else - { - // give editor and this tab the focus, - // possibly making the editor visible if it is hidden - emit set_focus_editor_signal (this); - m_edit_area->setFocus (); - - // Create a WindowModal message that blocks the edit area - // by making m_edit_area parent. - QMessageBox *msgBox - = new QMessageBox (QMessageBox::Warning, - tr ("Octave Editor"), - tr ("It seems that \'%1\' has been modified by another application. Do you want to reload it?"). - arg (m_file_name), - QMessageBox::Yes | QMessageBox::No, this); - - connect (msgBox, &QMessageBox::finished, - this, &file_editor_tab::handle_file_reload_answer); - - msgBox->setWindowModality (Qt::WindowModal); - msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); - } - } - else - { - // If desired and if file is not modified, - // close the file without any user interaction - if (do_close && ! m_edit_area->isModified ()) - { - handle_file_resave_answer (QMessageBox::Cancel); - return; - } - - // give editor and this tab the focus, - // possibly making the editor visible if it is hidden - emit set_focus_editor_signal (this); - m_edit_area->setFocus (); - - QString modified = ""; - if (m_edit_area->isModified ()) - modified = tr ("\n\nWarning: The contents in the editor is modified!"); - - // Create a WindowModal message. The file 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 *msgBox - = new QMessageBox (QMessageBox::Warning, tr ("Octave Editor"), - tr ("It seems that the file\n" - "%1\n" - "has been deleted or renamed. Do you want to save it now?%2"). - arg (m_file_name).arg (modified), - QMessageBox::Save | QMessageBox::Close, nullptr); - - m_edit_area->setReadOnly (true); - - connect (msgBox, &QMessageBox::finished, - this, &file_editor_tab::handle_file_resave_answer); - - msgBox->setWindowModality (Qt::WindowModal); - msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); - } -} - -void file_editor_tab::notice_settings (const gui_settings *settings, bool init) -{ - if (! settings) - return; - - if (! init) - update_lexer_settings (); - - // code folding - if (settings->value (ed_code_folding).toBool ()) - { - m_edit_area->setMarginType (3, QsciScintilla::SymbolMargin); - m_edit_area->setFolding (QsciScintilla::BoxedTreeFoldStyle, 3); - } - else - { - m_edit_area->setFolding (QsciScintilla::NoFoldStyle, 3); - } - - // status bar - if (settings->value (ed_show_edit_status_bar).toBool ()) - m_status_bar->show (); - else - m_status_bar->hide (); - - //highlight current line color - m_edit_area->setCaretLineVisible - (settings->value (ed_highlight_current_line).toBool ()); - - // auto completion - bool match_keywords = settings->value - (ed_code_completion_keywords).toBool (); - bool match_document = settings->value - (ed_code_completion_document).toBool (); - - QsciScintilla::AutoCompletionSource source = QsciScintilla::AcsNone; - if (match_keywords) - if (match_document) - source = QsciScintilla::AcsAll; + source = QsciScintilla::AcsAPIs; + else if (match_document) + source = QsciScintilla::AcsDocument; + m_edit_area->setAutoCompletionSource (source); + + m_edit_area->setAutoCompletionReplaceWord + (settings.bool_value (ed_code_completion_replace)); + m_edit_area->setAutoCompletionCaseSensitivity + (settings.bool_value (ed_code_completion_case)); + + if (settings.bool_value (ed_code_completion)) + m_edit_area->setAutoCompletionThreshold + (settings.int_value (ed_code_completion_threshold)); else - source = QsciScintilla::AcsAPIs; - else if (match_document) - source = QsciScintilla::AcsDocument; - m_edit_area->setAutoCompletionSource (source); - - m_edit_area->setAutoCompletionReplaceWord - (settings->value (ed_code_completion_replace).toBool ()); - m_edit_area->setAutoCompletionCaseSensitivity - (settings->value (ed_code_completion_case).toBool ()); - - if (settings->value (ed_code_completion).toBool ()) - m_edit_area->setAutoCompletionThreshold - (settings->value (ed_code_completion_threshold).toInt ()); - else - m_edit_area->setAutoCompletionThreshold (-1); - - if (settings->value (ed_show_white_space).toBool ()) - if (settings->value (ed_show_white_space_indent).toBool ()) - 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_save_as_desired_eol = static_cast - (settings->value (ed_default_eol_mode).toInt ()); - - if (settings->value (ed_show_line_numbers).toBool ()) - { - m_edit_area->setMarginLineNumbers (2, true); - auto_margin_width (); - connect (m_edit_area, SIGNAL (linesChanged ()), - this, SLOT (auto_margin_width ())); - } - else - { - m_edit_area->setMarginLineNumbers (2, false); - disconnect (m_edit_area, SIGNAL (linesChanged ()), nullptr, nullptr); - } - - m_smart_indent = settings->value (ed_auto_indent).toBool (); - m_edit_area->setAutoIndent (m_smart_indent); - m_edit_area->setTabIndents - (settings->value (ed_tab_indents_line).toBool ()); - m_edit_area->setBackspaceUnindents - (settings->value (ed_backspace_unindents_line).toBool ()); - m_edit_area->setIndentationGuides - (settings->value (ed_show_indent_guides).toBool ()); - m_edit_area->setIndentationsUseTabs - (settings->value (ed_indent_uses_tabs).toBool ()); - m_edit_area->setIndentationWidth - (settings->value (ed_indent_width).toInt ()); - - m_edit_area->setTabWidth - (settings->value (ed_tab_width).toInt ()); - - 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 ()); - 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 (); - - // long line marker - int line_length = settings->value (ed_long_line_column).toInt (); - m_edit_area->setEdgeColumn (line_length); - - if (settings->value (ed_long_line_marker).toBool ()) - { - if (settings->value (ed_long_line_marker_line).toBool ()) - m_edit_area->setEdgeMode (QsciScintilla::EdgeLine); + m_edit_area->setAutoCompletionThreshold (-1); + + if (settings.bool_value (ed_show_white_space)) + if (settings.bool_value (ed_show_white_space_indent)) + m_edit_area->setWhitespaceVisibility (QsciScintilla::WsVisibleAfterIndent); else - { - if (settings->value (ed_long_line_marker_background) - .toBool ()) - m_edit_area->setEdgeMode (QsciScintilla::EdgeBackground); - else - m_edit_area->setEdgeMode (QsciScintilla::EdgeLine); - } - } - else - m_edit_area->setEdgeMode (QsciScintilla::EdgeNone); - - // line wrapping and breaking - m_edit_area->setWrapVisualFlags (QsciScintilla::WrapFlagByBorder); - m_edit_area->setWrapIndentMode (QsciScintilla::WrapIndentSame); - - if (settings->value (ed_wrap_lines).toBool ()) - m_edit_area->setWrapMode (QsciScintilla::WrapWord); - else - m_edit_area->setWrapMode (QsciScintilla::WrapNone); - - if (settings->value (ed_break_lines).toBool ()) - m_line_break = line_length; - else - m_line_break = 0; - - m_line_break_comments = - settings->value (ed_break_lines_comments).toBool (); - - // highlight all occurrences of a word selected by a double click - m_highlight_all_occurrences = - settings->value (ed_highlight_all_occurrences).toBool (); - - // reload changed files - m_always_reload_changed_files = - settings->value (ed_always_reload_changed_files).toBool (); - - // 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 (); - else - cursor_blinking = settings->value (cs_cursor_blinking).toBool (); - - if (cursor_blinking) - m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETCARETPERIOD, 500); - else - m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETCARETPERIOD, 0); - -} - -void file_editor_tab::auto_margin_width (void) -{ - m_edit_area->setMarginWidth (2, "1" + QString::number (m_edit_area->lines ())); -} - -// the following close request was changed from a signal slot into a -// normal function because we need the return value from close whether -// 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) -{ - return close (); -} - -void file_editor_tab::change_editor_state (const QWidget *ID) -{ - if (ID != this) - return; - - emit editor_state_changed (m_copy_available, m_is_octave_file, - m_edit_area->isModified ()); -} - -void file_editor_tab::handle_file_reload_answer (int decision) -{ - if (decision == QMessageBox::Yes) - { - // reload: file is readded to the file watcher in set_file_name () - load_file (m_file_name); - } - else - { - // do not reload: readd to the file watcher - m_file_system_watcher.addPath (m_file_name); - } -} - -void file_editor_tab::handle_file_resave_answer (int decision) -{ - // check decision of user in dialog - if (decision == QMessageBox::Save) - { - save_file (m_file_name); // readds file to watcher in set_file_name () - m_edit_area->setReadOnly (false); // delete read only flag - } - else - { - // Definitely close the file. - // Set modified to false to prevent the dialog box when the close event - // is posted. If the user cancels the close in this dialog the tab is - // left open with a non-existing file. - m_edit_area->setModified (false); - close (); - } -} - -void file_editor_tab::insert_debugger_pointer (const QWidget *ID, int line) -{ - if (ID != this || ID == nullptr) - return; - - emit remove_all_positions (); // debugger_position, unsure_debugger_position - - if (line > 0) - { - marker *dp; - - if (m_edit_area->isModified ()) - { - // The best that can be done if the editor contents have been - // modified is to see if there is a match with the original - // line number of any existing breakpoints. We can put a normal - // debugger pointer at that breakpoint position. Otherwise, it - // isn't certain whether the original line number and current line - // number match. - int editor_linenr = -1; - marker *dummy; - emit find_translated_line_number (line, editor_linenr, dummy); - if (editor_linenr != -1) - { - // Match with an existing breakpoint. - dp = new marker (m_edit_area, line, - marker::debugger_position, editor_linenr); - } - else - { - int original_linenr = -1; - editor_linenr = -1; - emit find_linenr_just_before (line, original_linenr, editor_linenr); - if (original_linenr >= 0) - { - // Make a guess by using an offset from the breakpoint. - int linenr_guess = editor_linenr + line - original_linenr; - dp = new marker (m_edit_area, line, - marker::unsure_debugger_position, - linenr_guess); - } - else - { - // Can't make a very good guess, so just use the debugger - // line number. - dp = new marker (m_edit_area, line, - marker::unsure_debugger_position); - } - } - } - else - { - dp = new marker (m_edit_area, line, marker::debugger_position); - - // In case of a not modified file we might have to remove - // a breakpoint here if we have stepped into the file - if (line == m_breakpoint_info.remove_line) - { - m_breakpoint_info.remove_line = -1; - if (line != m_breakpoint_info.do_not_remove_line) - handle_request_remove_breakpoint (line); - } - } - - connect (this, &file_editor_tab::remove_position_via_debugger_linenr, - dp, &marker::handle_remove_via_original_linenr); - - connect (this, &file_editor_tab::remove_all_positions, - dp, &marker::handle_remove); - - center_current_line (false); - } -} - -void file_editor_tab::delete_debugger_pointer (const QWidget *ID, int line) -{ - if (ID != this || ID == nullptr) - return; - - if (line > 0) - emit remove_position_via_debugger_linenr (line); -} - -void file_editor_tab::do_breakpoint_marker (bool insert, - const QWidget *ID, int line, - const QString& cond) -{ - if (ID != this || ID == nullptr) - return; - - if (line > 0) - { - if (insert) - { - int editor_linenr = -1; - marker *bp = nullptr; - - // If comes back indicating a non-zero breakpoint marker, - // reuse it if possible - emit find_translated_line_number (line, editor_linenr, bp); - if (bp != nullptr) - { - if ((cond == "") != (bp->get_cond () == "")) - { - // can only reuse conditional bp as conditional - emit remove_breakpoint_via_debugger_linenr (line); - bp = nullptr; - } - else - bp->set_cond (cond); - } - - if (bp == nullptr) - { - bp = new marker (m_edit_area, line, - cond == "" ? marker::breakpoint - : marker::cond_break, cond); - - connect (this, &file_editor_tab::remove_breakpoint_via_debugger_linenr, - bp, &marker::handle_remove_via_original_linenr); - connect (this, &file_editor_tab::request_remove_breakpoint_via_editor_linenr, - bp, &marker::handle_request_remove_via_editor_linenr); - connect (this, &file_editor_tab::remove_all_breakpoints_signal, - bp, &marker::handle_remove); - connect (this, &file_editor_tab::find_translated_line_number, - bp, &marker::handle_find_translation); - connect (this, &file_editor_tab::find_linenr_just_before, - bp, &marker::handle_find_just_before); - connect (this, &file_editor_tab::report_marker_linenr, - bp, &marker::handle_report_editor_linenr); - connect (bp, &marker::request_remove, - this, &file_editor_tab::handle_request_remove_breakpoint); - } - } - else - emit remove_breakpoint_via_debugger_linenr (line); - } -} - -void file_editor_tab::center_current_line (bool always) -{ - long int visible_lines - = m_edit_area->SendScintilla (QsciScintillaBase::SCI_LINESONSCREEN); - - if (visible_lines > 2) - { - int line, index; - m_edit_area->getCursorPosition (&line, &index); - // compensate for "folding": - // step 1: expand the current line, if it was folded - m_edit_area->SendScintilla (2232, line); // SCI_ENSUREVISIBLE - - // step 2: map file line num to "visible" one // SCI_VISIBLEFROMDOCLINE - int vis_line = m_edit_area->SendScintilla (2220, line); - - int first_line = m_edit_area->firstVisibleLine (); - - if (always || vis_line == first_line - || vis_line > first_line + visible_lines - 2) - { - first_line += (vis_line - first_line - (visible_lines - 1) / 2); - m_edit_area->SendScintilla (2613, first_line); // SCI_SETFIRSTVISIBLELINE - } - } -} - -void file_editor_tab::handle_lines_changed (void) -{ - // the related signal is emitted before cursor-move-signal! - m_lines_changed = true; -} - -void file_editor_tab::handle_cursor_moved (int line, int col) -{ - // Cursor has moved, first check wether an autocompletion list - // is active or if it was closed. Scintilla provides signals for - // completed or cancelled lists, but not for list that where hidden - // due to a new character not matching anymore with the list entries - if (m_edit_area->SendScintilla (QsciScintillaBase::SCI_AUTOCACTIVE)) - m_autoc_active = true; - else if (m_autoc_active) - { - m_autoc_active = false; - emit autoc_closed (); // Tell editor about closed list - } - - // 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); - m_lines_changed = false; - - // Update line and column indicator in the status bar - int o_line = m_line; - update_rowcol_indicator (line, col); - - // Do smart indent after update of line indicator for having - // consistent indicator data - if (do_smart_indent) - m_edit_area->smart_indent (m_smart_indent, m_auto_endif, - o_line, m_ind_char_width); -} - -void file_editor_tab::update_rowcol_indicator (int line, int col) -{ - m_line = line; - m_col = col; - m_row_indicator->setNum (line+1); - m_col_indicator->setNum (col+1); -} - -// Slot that is entered each time a new character was typed. -// It is used for handling line breaking if this is desired. -// The related signal is emitted after the signal for a moved cursor -// such that m_col and m_line can not be used for current position. -void file_editor_tab::handle_char_added (int) -{ - if (m_line_break) - { - // If line breaking is desired, get the current line and column. - // For taking the tab width into consideration, use own function - int line, col, pos; - m_edit_area->get_current_position (&pos, &line, &col); - - // immediately return if line has not reached the max. line length - if (col <= m_line_break) - return; - - // If line breaking is only desired in comments, - // return if not in a comment - int style_comment = octave_qscintilla::ST_NONE; - if (m_line_break_comments) - { - // line breaking only in comments, check for comment style - style_comment = m_edit_area->is_style_comment (); - if (! style_comment) - return; // no comment, return - } - - // Here we go for breaking the current line by inserting a newline. - // For determining the position of a specific column, we have to get - // the column from the QScintilla function without taking tab lengths - // into account, since the calculation from line/col to position - // ignores this, too. - m_edit_area->getCursorPosition (&line, &col); - int c = 0; - int col_space = col; - int indentation = m_edit_area->indentation (line); - - // Search the first occurrence of space or tab backwards starting from - // the current column (col_space). - while (c != ' ' && c != '\t' && col_space > indentation) - { - pos = m_edit_area->positionFromLineIndex (line, col_space--); - c = m_edit_area->SendScintilla (QsciScintillaBase::SCI_GETCHARAT, pos); - } - - // If a space or tab was found, break at this char, - // otherwise break at cursor position - int col_newline = col - 1; - if (c == ' ' || c == '\t') - col_newline = col_space + 1; - - // Insert a newline char for breaking the line possibly followed - // by a line comment string - QString newline = QString ("\n"); - style_comment = m_edit_area->is_style_comment (); - if (style_comment == octave_qscintilla::ST_LINE_COMMENT) - newline = newline + m_edit_area->comment_string ().at (0); - m_edit_area->insertAt (newline, line, col_newline); - - // Automatically indent the new line to the indentation of previous line - // and set the cursor position to the end of the indentation. - m_edit_area->setIndentation (line + 1, indentation); - m_edit_area->SendScintilla (QsciScintillaBase::SCI_LINEEND); - } -} - -// Slot handling a double click into the text area -void file_editor_tab::handle_double_click (int, int, int modifier) -{ - if (! modifier) - { - // double clicks without modifier - // clear any existing indicators of this type - m_edit_area->clear_selection_markers (); - - if (m_highlight_all_occurrences) - { - // Clear any previous selection. - m_edit_area->set_word_selection (); - - // highlighting of all occurrences of the clicked word is enabled - - // get the resulting cursor position - // (required if click was beyond a line ending) - int line, col; - m_edit_area->getCursorPosition (&line, &col); - - // get the word at the cursor (if any) - QString word = m_edit_area->wordAtLineIndex (line, col); - word = word.trimmed (); - - if (! word.isEmpty ()) - { - // word is not empty, so find all occurrences of the word - - // remember first visible line and x-offset for restoring the view afterwards - int first_line = m_edit_area->firstVisibleLine (); - int x_offset = m_edit_area->SendScintilla (QsciScintillaBase::SCI_GETXOFFSET); - - // search for first occurrence of the detected word - bool find_result_available - = m_edit_area->findFirst (word, - false, // no regexp - true, // case sensitive - true, // whole words only - false, // do not wrap - true, // forward - 0, 0, // from the beginning - false + m_edit_area->setWhitespaceVisibility (QsciScintilla::WsVisible); + else + m_edit_area->setWhitespaceVisibility (QsciScintilla::WsInvisible); + + m_edit_area->setEolVisibility (settings.bool_value (ed_show_eol_chars)); + + m_save_as_desired_eol = static_cast + (settings.int_value (ed_default_eol_mode)); + + if (settings.bool_value (ed_show_line_numbers)) + { + m_edit_area->setMarginLineNumbers (2, true); + auto_margin_width (); + connect (m_edit_area, SIGNAL (linesChanged ()), + this, SLOT (auto_margin_width ())); + } + else + { + m_edit_area->setMarginLineNumbers (2, false); + disconnect (m_edit_area, SIGNAL (linesChanged ()), nullptr, nullptr); + } + + m_smart_indent = settings.bool_value (ed_auto_indent); + m_edit_area->setAutoIndent (m_smart_indent); + m_edit_area->setTabIndents + (settings.bool_value (ed_tab_indents_line)); + m_edit_area->setBackspaceUnindents + (settings.bool_value (ed_backspace_unindents_line)); + m_edit_area->setIndentationGuides + (settings.bool_value (ed_show_indent_guides)); + m_edit_area->setIndentationsUseTabs + (settings.bool_value (ed_indent_uses_tabs)); + m_edit_area->setIndentationWidth + (settings.int_value (ed_indent_width)); + + m_edit_area->setTabWidth + (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.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.int_value (ed_auto_endif); + + // long line marker + int line_length = settings.int_value (ed_long_line_column); + m_edit_area->setEdgeColumn (line_length); + + if (settings.bool_value (ed_long_line_marker)) + { + if (settings.bool_value (ed_long_line_marker_line)) + m_edit_area->setEdgeMode (QsciScintilla::EdgeLine); + else + { + if (settings.bool_value (ed_long_line_marker_background)) + m_edit_area->setEdgeMode (QsciScintilla::EdgeBackground); + else + m_edit_area->setEdgeMode (QsciScintilla::EdgeLine); + } + } + else + m_edit_area->setEdgeMode (QsciScintilla::EdgeNone); + + // line wrapping and breaking + m_edit_area->setWrapVisualFlags (QsciScintilla::WrapFlagByBorder); + m_edit_area->setWrapIndentMode (QsciScintilla::WrapIndentSame); + + if (settings.bool_value (ed_wrap_lines)) + m_edit_area->setWrapMode (QsciScintilla::WrapWord); + else + m_edit_area->setWrapMode (QsciScintilla::WrapNone); + + if (settings.bool_value (ed_break_lines)) + m_line_break = line_length; + else + m_line_break = 0; + + m_line_break_comments = + settings.bool_value (ed_break_lines_comments); + + // highlight all occurrences of a word selected by a double click + m_highlight_all_occurrences = + settings.bool_value (ed_highlight_all_occurrences); + + // reload changed files + m_always_reload_changed_files = + 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.settings_key ())) + cursor_blinking = settings.bool_value (global_cursor_blinking); + else + cursor_blinking = settings.bool_value (cs_cursor_blinking); + + if (cursor_blinking) + m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETCARETPERIOD, 500); + else + m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETCARETPERIOD, 0); + + } + + void file_editor_tab::auto_margin_width () + { + m_edit_area->setMarginWidth (2, "1" + QString::number (m_edit_area->lines ())); + } + + // the following close request was changed from a signal slot into a + // normal function because we need the return value from close whether + // 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 () + { + return close (); + } + + void file_editor_tab::change_editor_state (const QWidget *ID) + { + if (ID != this) + return; + + emit editor_state_changed (m_copy_available, m_is_octave_file, + m_edit_area->isModified ()); + } + + void file_editor_tab::handle_file_reload_answer (int decision) + { + if (decision == QMessageBox::Yes) + { + // reload: file is readded to the file watcher in set_file_name () + load_file (m_file_name); + } + else + { + // do not reload: readd to the file watcher + m_file_system_watcher.addPath (m_file_name); + } + } + + void file_editor_tab::handle_file_resave_answer (int decision) + { + // check decision of user in dialog + if (decision == QMessageBox::Save) + { + save_file (m_file_name); // readds file to watcher in set_file_name () + m_edit_area->setReadOnly (false); // delete read only flag + } + else + { + // Definitely close the file. + // Set modified to false to prevent the dialog box when the close event + // is posted. If the user cancels the close in this dialog the tab is + // left open with a non-existing file. + m_edit_area->setModified (false); + close (); + } + } + + void file_editor_tab::insert_debugger_pointer (const QWidget *ID, int line) + { + if (ID != this || ID == nullptr) + return; + + emit remove_all_positions (); // debugger_position, unsure_debugger_position + + if (line > 0) + { + marker *dp; + + if (m_edit_area->isModified ()) + { + // The best that can be done if the editor contents have been + // modified is to see if there is a match with the original + // line number of any existing breakpoints. We can put a normal + // debugger pointer at that breakpoint position. Otherwise, it + // isn't certain whether the original line number and current line + // number match. + int editor_linenr = -1; + marker *dummy; + emit find_translated_line_number (line, editor_linenr, dummy); + if (editor_linenr != -1) + { + // Match with an existing breakpoint. + dp = new marker (m_edit_area, line, + marker::debugger_position, editor_linenr); + } + else + { + int original_linenr = -1; + editor_linenr = -1; + emit find_linenr_just_before (line, original_linenr, editor_linenr); + if (original_linenr >= 0) + { + // Make a guess by using an offset from the breakpoint. + int linenr_guess = editor_linenr + line - original_linenr; + dp = new marker (m_edit_area, line, + marker::unsure_debugger_position, + linenr_guess); + } + else + { + // Can't make a very good guess, so just use the debugger + // line number. + dp = new marker (m_edit_area, line, + marker::unsure_debugger_position); + } + } + } + else + { + dp = new marker (m_edit_area, line, marker::debugger_position); + + // In case of a not modified file we might have to remove + // a breakpoint here if we have stepped into the file + if (line == m_breakpoint_info.remove_line) + { + m_breakpoint_info.remove_line = -1; + if (line != m_breakpoint_info.do_not_remove_line) + handle_request_remove_breakpoint (line); + } + } + + connect (this, &file_editor_tab::remove_position_via_debugger_linenr, + dp, &marker::handle_remove_via_original_linenr); + + connect (this, &file_editor_tab::remove_all_positions, + dp, &marker::handle_remove); + + center_current_line (false); + } + } + + void file_editor_tab::delete_debugger_pointer (const QWidget *ID, int line) + { + if (ID != this || ID == nullptr) + return; + + if (line > 0) + emit remove_position_via_debugger_linenr (line); + } + + void file_editor_tab::do_breakpoint_marker (bool insert, + const QWidget *ID, int line, + const QString& cond) + { + if (ID != this || ID == nullptr) + return; + + if (line > 0) + { + if (insert) + { + int editor_linenr = -1; + marker *bp = nullptr; + + // If comes back indicating a non-zero breakpoint marker, + // reuse it if possible + emit find_translated_line_number (line, editor_linenr, bp); + if (bp != nullptr) + { + if ((cond == "") != (bp->get_cond () == "")) + { + // can only reuse conditional bp as conditional + emit remove_breakpoint_via_debugger_linenr (line); + bp = nullptr; + } + else + bp->set_cond (cond); + } + + if (bp == nullptr) + { + bp = new marker (m_edit_area, line, + cond == "" ? marker::breakpoint + : marker::cond_break, cond); + + connect (this, &file_editor_tab::remove_breakpoint_via_debugger_linenr, + bp, &marker::handle_remove_via_original_linenr); + connect (this, &file_editor_tab::request_remove_breakpoint_via_editor_linenr, + bp, &marker::handle_request_remove_via_editor_linenr); + connect (this, &file_editor_tab::remove_all_breakpoints_signal, + bp, &marker::handle_remove); + connect (this, &file_editor_tab::find_translated_line_number, + bp, &marker::handle_find_translation); + connect (this, &file_editor_tab::find_linenr_just_before, + bp, &marker::handle_find_just_before); + connect (this, &file_editor_tab::report_marker_linenr, + bp, &marker::handle_report_editor_linenr); + connect (bp, &marker::request_remove, + this, &file_editor_tab::handle_request_remove_breakpoint); + } + } + else + emit remove_breakpoint_via_debugger_linenr (line); + } + } + + void file_editor_tab::center_current_line (bool always) + { + long int visible_lines + = m_edit_area->SendScintilla (QsciScintillaBase::SCI_LINESONSCREEN); + + if (visible_lines > 2) + { + int line, index; + m_edit_area->getCursorPosition (&line, &index); + // compensate for "folding": + // step 1: expand the current line, if it was folded + m_edit_area->SendScintilla (2232, line); // SCI_ENSUREVISIBLE + + // step 2: map file line num to "visible" one // SCI_VISIBLEFROMDOCLINE + int vis_line = m_edit_area->SendScintilla (2220, line); + + int first_line = m_edit_area->firstVisibleLine (); + + if (always || vis_line == first_line + || vis_line > first_line + visible_lines - 2) + { + first_line += (vis_line - first_line - (visible_lines - 1) / 2); + m_edit_area->SendScintilla (2613, first_line); // SCI_SETFIRSTVISIBLELINE + } + } + } + + void file_editor_tab::handle_lines_changed () + { + // the related signal is emitted before cursor-move-signal! + m_lines_changed = true; + } + + void file_editor_tab::handle_cursor_moved (int line, int col) + { + // Cursor has moved, first check wether an autocompletion list + // is active or if it was closed. Scintilla provides signals for + // completed or cancelled lists, but not for list that where hidden + // due to a new character not matching anymore with the list entries + if (m_edit_area->SendScintilla (QsciScintillaBase::SCI_AUTOCACTIVE)) + m_autoc_active = true; + else if (m_autoc_active) + { + m_autoc_active = false; + emit autoc_closed (); // Tell editor about closed list + } + + // 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); + m_lines_changed = false; + + // Update line and column indicator in the status bar + int o_line = m_line; + update_rowcol_indicator (line, col); + + // Do smart indent after update of line indicator for having + // consistent indicator data + if (do_smart_indent) + m_edit_area->smart_indent (m_smart_indent, m_auto_endif, + o_line, m_ind_char_width); + } + + void file_editor_tab::update_rowcol_indicator (int line, int col) + { + m_line = line; + m_col = col; + m_row_indicator->setNum (line+1); + m_col_indicator->setNum (col+1); + } + + // Slot that is entered each time a new character was typed. + // It is used for handling line breaking if this is desired. + // The related signal is emitted after the signal for a moved cursor + // such that m_col and m_line can not be used for current position. + void file_editor_tab::handle_char_added (int) + { + if (m_line_break) + { + // If line breaking is desired, get the current line and column. + // For taking the tab width into consideration, use own function + int line, col, pos; + m_edit_area->get_current_position (&pos, &line, &col); + + // immediately return if line has not reached the max. line length + if (col <= m_line_break) + return; + + // If line breaking is only desired in comments, + // return if not in a comment + int style_comment = octave_qscintilla::ST_NONE; + if (m_line_break_comments) + { + // line breaking only in comments, check for comment style + style_comment = m_edit_area->is_style_comment (); + if (! style_comment) + return; // no comment, return + } + + // Here we go for breaking the current line by inserting a newline. + // For determining the position of a specific column, we have to get + // the column from the QScintilla function without taking tab lengths + // into account, since the calculation from line/col to position + // ignores this, too. + m_edit_area->getCursorPosition (&line, &col); + int c = 0; + int col_space = col; + int indentation = m_edit_area->indentation (line); + + // Search the first occurrence of space or tab backwards starting from + // the current column (col_space). + while (c != ' ' && c != '\t' && col_space > indentation) + { + pos = m_edit_area->positionFromLineIndex (line, col_space--); + c = m_edit_area->SendScintilla (QsciScintillaBase::SCI_GETCHARAT, pos); + } + + // If a space or tab was found, break at this char, + // otherwise break at cursor position + int col_newline = col - 1; + if (c == ' ' || c == '\t') + col_newline = col_space + 1; + + // Insert a newline char for breaking the line possibly followed + // by a line comment string + QString newline = QString ("\n"); + style_comment = m_edit_area->is_style_comment (); + if (style_comment == octave_qscintilla::ST_LINE_COMMENT) + newline = newline + m_edit_area->comment_string ().at (0); + m_edit_area->insertAt (newline, line, col_newline); + + // Automatically indent the new line to the indentation of previous line + // and set the cursor position to the end of the indentation. + m_edit_area->setIndentation (line + 1, indentation); + m_edit_area->SendScintilla (QsciScintillaBase::SCI_LINEEND); + } + } + + // Slot handling a double click into the text area + void file_editor_tab::handle_double_click (int, int, int modifier) + { + if (! modifier) + { + // double clicks without modifier + // clear any existing indicators of this type + m_edit_area->clear_selection_markers (); + + if (m_highlight_all_occurrences) + { + // Clear any previous selection. + m_edit_area->set_word_selection (); + + // highlighting of all occurrences of the clicked word is enabled + + // get the resulting cursor position + // (required if click was beyond a line ending) + int line, col; + m_edit_area->getCursorPosition (&line, &col); + + // get the word at the cursor (if any) + QString word = m_edit_area->wordAtLineIndex (line, col); + word = word.trimmed (); + + if (! word.isEmpty ()) + { + // word is not empty, so find all occurrences of the word + + // remember first visible line and x-offset for restoring the view afterwards + int first_line = m_edit_area->firstVisibleLine (); + int x_offset = m_edit_area->SendScintilla (QsciScintillaBase::SCI_GETXOFFSET); + + // search for first occurrence of the detected word + bool find_result_available + = m_edit_area->findFirst (word, + false, // no regexp + true, // case sensitive + true, // whole words only + false, // do not wrap + true, // forward + 0, 0, // from the beginning + false #if defined (HAVE_QSCI_VERSION_2_6_0) - , true + , true #endif - ); - - // loop over all occurrences and set the related indicator - int oline, ocol; - int wlen = word.length (); - - while (find_result_available) - { - // get cursor position after having found an occurrence - m_edit_area->getCursorPosition (&oline, &ocol); - // mark the selection - m_edit_area->show_selection_markers (oline, ocol-wlen, oline, ocol); - - // find next occurrence - find_result_available = m_edit_area->findNext (); - } - - // restore the visible area of the file, the cursor position, - // and the selection - m_edit_area->setFirstVisibleLine (first_line); - m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETXOFFSET, x_offset); - m_edit_area->setCursorPosition (line, col); - m_edit_area->setSelection (line, col - wlen, line, col); - m_edit_area->set_word_selection (word); - } - } - } -} - -QString file_editor_tab::get_function_name (void) -{ - 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 ]*$"); - - 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]*")); - } - - return QString (); -} + ); + + // loop over all occurrences and set the related indicator + int oline, ocol; + int wlen = word.length (); + + while (find_result_available) + { + // get cursor position after having found an occurrence + m_edit_area->getCursorPosition (&oline, &ocol); + // mark the selection + m_edit_area->show_selection_markers (oline, ocol-wlen, oline, ocol); + + // find next occurrence + find_result_available = m_edit_area->findNext (); + } + + // restore the visible area of the file, the cursor position, + // and the selection + m_edit_area->setFirstVisibleLine (first_line); + m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETXOFFSET, x_offset); + m_edit_area->setCursorPosition (line, col); + m_edit_area->setSelection (line, col - wlen, line, col); + m_edit_area->set_word_selection (word); + } + } + } + } + + 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 ]*$"); + + 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]*")); + } + + return QString (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/file-editor-tab.h Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,6 @@ #include #include -#include "gui-settings.h" #include "marker.h" #include "octave-qscintilla.h" #include "qt-interpreter-events.h" @@ -45,308 +44,305 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class file_editor; + class file_editor; + + class file_editor_tab : public QWidget + { + Q_OBJECT -class file_editor_tab : public QWidget -{ - Q_OBJECT + public: -public: + file_editor_tab (const QString& directory = ""); - file_editor_tab (base_qobject& oct_qobj, 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); + // Will initiate close if associated with the identifier tag. + bool conditional_close (); - void update_breakpoints (); - void set_file_name (const QString& fileName); - void enable_file_watcher (bool do_enable); + 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: + signals: - void tab_ready_to_close (void); - void file_name_changed (const QString& fileName, - const QString& toolTip, - bool modified); - void editor_state_changed (bool copy_available, bool is_octave_file, - bool is_modified); - void set_focus_editor_signal (QWidget *); - void edit_area_changed (octave_qscintilla *edit_area); - void tab_remove_request (void); - void mru_add_file (const QString& file_name, const QString& encoding); - void editor_check_conflict_save (const QString& saveFileName, - bool remove_on_success); - void run_file_signal (const QFileInfo& info); - void request_open_file (const QString&, const QString& = QString ()); - void edit_mfile_request (const QString&, const QString&, - const QString&, int); + void tab_ready_to_close (); + void file_name_changed (const QString& fileName, + const QString& toolTip, + bool modified); + void editor_state_changed (bool copy_available, bool is_octave_file, + bool is_modified); + void set_focus_editor_signal (QWidget *); + void edit_area_changed (octave_qscintilla *edit_area); + 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); + void run_file_signal (const QFileInfo& info); + void request_open_file (const QString&, const QString& = QString ()); + 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 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 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_breakpoint_via_debugger_linenr (int debugger_linenr); + void request_remove_breakpoint_via_editor_linenr (int editor_linenr); + 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 debug_quit_signal (void); + void debug_quit_signal (); - void interpreter_event (const fcn_callback& fcn); - void interpreter_event (const meth_callback& meth); + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); - void maybe_remove_next (int remove_line); + void maybe_remove_next (int remove_line); - 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 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 do_save_file_signal (const QString& file_to_save, - bool remove_on_success, bool restore_breakpoints); + void do_save_file_signal (const QString& file_to_save, + bool remove_on_success, bool restore_breakpoints); - void confirm_dbquit_and_save_signal (const QString& file_to_save, - const QString& base_name, - bool remove_on_success, - bool restore_breakpoints); + void confirm_dbquit_and_save_signal (const QString& file_to_save, + const QString& base_name, + bool remove_on_success, + bool restore_breakpoints); - // FIXME: The following is similar to "process_octave_code" signal. - // However, currently that signal is connected to something that simply - // focuses a window and does not actually communicate with Octave. - // - // void evaluate_octave_command (const QString& command); + // FIXME: The following is similar to "process_octave_code" signal. + // However, currently that signal is connected to something that simply + // focuses a window and does not actually communicate with Octave. + // + // void evaluate_octave_command (const QString& command); -public slots: + public slots: - void update_window_title (bool modified); - void handle_copy_available (bool enableCopy); - void handle_margin_clicked (int line, int margin, - Qt::KeyboardModifiers state); + void update_window_title (bool modified); + void handle_copy_available (bool enableCopy); + void handle_margin_clicked (int line, int margin, + Qt::KeyboardModifiers state); - // Tells the editor tab to react on changed settings. - void notice_settings (const gui_settings *settings, bool init = false); + // Tells the editor tab to react on changed settings. + void notice_settings (bool init = false); - // Change to a different editor tab by identifier tag. - void change_editor_state (const QWidget *ID); + // Change to a different editor tab by identifier tag. + void change_editor_state (const QWidget *ID); - void set_focus (const QWidget *ID); - void set_current_directory (const QString& dir); - void context_help (const QWidget *ID, bool); - void context_edit (const QWidget *ID); - void save_file (const QWidget *ID); - void save_file (const QWidget *ID, const QString& fileName, - bool remove_on_success); - void save_file_as (const QWidget *ID); - void print_file (const QWidget *ID); - void run_file (const QWidget *ID, bool step_into = false); - void context_run (const QWidget *ID); - void toggle_bookmark (const QWidget *ID); - void next_bookmark (const QWidget *ID); - void previous_bookmark (const QWidget *ID); - void remove_bookmark (const QWidget *ID); + void set_focus (const QWidget *ID); + void set_current_directory (const QString& dir); + void context_help (const QWidget *ID, bool); + void context_edit (const QWidget *ID); + void save_file (const QWidget *ID); + void save_file (const QWidget *ID, const QString& fileName, + bool remove_on_success); + void save_file_as (const QWidget *ID); + void print_file (const QWidget *ID); + void run_file (const QWidget *ID, bool step_into = false); + void context_run (const QWidget *ID); + void toggle_bookmark (const QWidget *ID); + void next_bookmark (const QWidget *ID); + void previous_bookmark (const QWidget *ID); + void remove_bookmark (const QWidget *ID); - void toggle_breakpoint (const QWidget *ID); - void next_breakpoint (const QWidget *ID); - void previous_breakpoint (const QWidget *ID); - void remove_all_breakpoints (const QWidget *ID); + void toggle_breakpoint (const QWidget *ID); + void next_breakpoint (const QWidget *ID); + void previous_breakpoint (const QWidget *ID); + void remove_all_breakpoints (const QWidget *ID); - void scintilla_command (const QWidget *, unsigned int); + void scintilla_command (const QWidget *, unsigned int); - void comment_selected_text (const QWidget *ID, bool input_str); - void uncomment_selected_text (const QWidget *ID); + void comment_selected_text (const QWidget *ID, bool input_str); + void uncomment_selected_text (const QWidget *ID); - void indent_selected_text (const QWidget *ID); - void unindent_selected_text (const QWidget *ID); - void smart_indent_line_or_selected_text (const QWidget *ID); - void convert_eol (const QWidget *ID, QsciScintilla::EolMode); + void indent_selected_text (const QWidget *ID); + void unindent_selected_text (const QWidget *ID); + void smart_indent_line_or_selected_text (const QWidget *ID); + void convert_eol (const QWidget *ID, QsciScintilla::EolMode); - void zoom_in (const QWidget *ID); - void zoom_out (const QWidget *ID); - void zoom_normal (const QWidget *ID); + void zoom_in (const QWidget *ID); + void zoom_out (const QWidget *ID); + void zoom_normal (const QWidget *ID); - void goto_line (const QWidget *ID, int line = -1); - void move_match_brace (const QWidget *ID, bool select); - void show_auto_completion (const QWidget *ID); + void goto_line (const QWidget *ID, int line = -1); + void move_match_brace (const QWidget *ID, bool select); + void show_auto_completion (const QWidget *ID); - void insert_debugger_pointer (const QWidget *ID, int line = -1); - void delete_debugger_pointer (const QWidget *ID, int line = -1); + void insert_debugger_pointer (const QWidget *ID, int line = -1); + void delete_debugger_pointer (const QWidget *ID, int line = -1); - void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1, - const QString& cond = ""); + void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1, + const QString& cond = ""); - void recover_from_exit (void); - void set_modified (bool modified = true); + void recover_from_exit (); + void set_modified (bool modified = true); - void set_encoding (const QString& new_encoding); + void set_encoding (const QString& new_encoding); - QString load_file (const QString& fileName); + QString load_file (const QString& fileName); - void new_file (const QString& commands = QString ()); + void new_file (const QString& commands = QString ()); - void file_has_changed (const QString& path, bool do_close = false); + void file_has_changed (const QString& path, bool do_close = false); - void handle_context_menu_edit (const QString&); - void handle_context_menu_break_condition (int linenr); + void handle_context_menu_edit (const QString&); + void handle_context_menu_break_condition (int linenr); - void handle_request_add_breakpoint (int line, const QString& cond); - void handle_request_remove_breakpoint (int line); + void handle_request_add_breakpoint (int line, const QString& cond); + void handle_request_remove_breakpoint (int line); - void update_breakpoints_handler (const octave_value_list& argout); - void update_rowcol_indicator (int line, int col); - void update_lexer_settings (bool update_apis_only = false); + void update_breakpoints_handler (const octave_value_list& argout); + void update_rowcol_indicator (int line, int col); + void update_lexer_settings (bool update_apis_only = false); -private slots: + private slots: - // When user closes message box for decoding problems - void handle_decode_warning_answer (QAbstractButton *btn); + // When user closes message box for decoding problems + void handle_decode_warning_answer (QAbstractButton *btn); - // When user closes message box for reload question. - void handle_file_reload_answer (int decision); + // When user closes message box for reload question. + void handle_file_reload_answer (int decision); - // When user closes message box for resave question. - void handle_file_resave_answer (int decision); + // When user closes message box for resave question. + void handle_file_resave_answer (int decision); - // 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_as_filter_selected (const QString& filter); + // 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 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 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); + // When apis preparation has finished and is ready to save + void save_apis_info (); - // When the numer of lines changes -> adapt width of margin - void auto_margin_width (void); + // When the numer of lines changes -> adapt width of margin + 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_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 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_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 do_save_file (const QString& file_to_save, bool remove_on_success, - bool restore_breakpoints); + void do_save_file (const QString& file_to_save, bool remove_on_success, + bool restore_breakpoints); - void confirm_dbquit_and_save (const QString& file_to_save, - const QString& base_name, - bool remove_on_success, - bool restore_breakpoints); + void confirm_dbquit_and_save (const QString& file_to_save, + const QString& base_name, + bool remove_on_success, + bool restore_breakpoints); -protected: + protected: - void closeEvent (QCloseEvent *event); - -private: + void closeEvent (QCloseEvent *event); - base_qobject& m_octave_qobj; + private: - void add_breakpoint_event (int line, const QString& cond); + void add_breakpoint_event (int line, const QString& cond); - bool valid_file_name (const QString& file = QString ()); - void save_file (const QString& saveFileName, bool remove_on_success = false, - 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 valid_file_name (const QString& file = QString ()); + void save_file (const QString& saveFileName, bool remove_on_success = false, + bool restore_breakpoints = true); + void save_file_as (bool remove_on_success = false); + bool check_valid_identifier (QString file_name); + QTextCodec * 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); + void show_dialog (QDialog *dlg, bool modal); -public: + public: - int check_file_modified (bool remove = false); - QString get_all_bookmarks (void); + int check_file_modified (bool remove = false); + 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); + 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 check_restore_breakpoints (void); - void center_current_line (bool always=true); + 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; + octave_qscintilla *m_edit_area; - QStatusBar *m_status_bar; - QLabel *m_row_indicator; - QLabel *m_col_indicator; - QLabel *m_eol_indicator; - QLabel *m_enc_indicator; + QStatusBar *m_status_bar; + QLabel *m_row_indicator; + QLabel *m_col_indicator; + QLabel *m_eol_indicator; + QLabel *m_enc_indicator; - QsciScintilla::EolMode m_save_as_desired_eol; + QsciScintilla::EolMode m_save_as_desired_eol; - QString m_file_name; - QString m_file_name_short; - QString m_ced; - QString m_encoding; - QString m_new_encoding; - QDateTime m_last_modified; + QString m_file_name; + QString m_file_name_short; + QString m_ced; + QString m_encoding; + QString m_new_encoding; + QDateTime m_last_modified; - bool m_autoc_active; - bool m_copy_available; - bool m_is_octave_file; - bool m_always_reload_changed_files; - bool m_smart_indent; - int m_auto_endif; - int m_ind_char_width; + bool m_autoc_active; + bool m_copy_available; + bool m_is_octave_file; + bool m_always_reload_changed_files; + bool m_smart_indent; + int m_auto_endif; + int m_ind_char_width; - QFileSystemWatcher m_file_system_watcher; + QFileSystemWatcher m_file_system_watcher; - QIntList m_bp_lines; - QStringList m_bp_conditions; + QIntList m_bp_lines; + QStringList m_bp_conditions; - QsciAPIs *m_lexer_apis; - QString m_prep_apis_path; - QString m_prep_apis_file; + QsciAPIs *m_lexer_apis; + QString m_prep_apis_path; + QString m_prep_apis_file; - int m_line_break; - bool m_line_break_comments; - int m_line; - int m_col; - bool m_lines_changed; - bool m_highlight_all_occurrences; - int m_bp_restore_count; + int m_line_break; + bool m_line_break_comments; + int m_line; + int m_col; + bool m_lines_changed; + bool m_highlight_all_occurrences; + int m_bp_restore_count; - struct breakpoint_info - { - bool remove_next; - int remove_line; - int do_not_remove_line; + struct breakpoint_info + { + bool remove_next; + int remove_line; + int do_not_remove_line; + }; + + breakpoint_info m_breakpoint_info; }; - breakpoint_info m_breakpoint_info; -}; - OCTAVE_END_NAMESPACE(octave) #endif diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/file-editor.cc Mon Jan 30 18:36:03 2023 +0100 @@ -50,10 +50,8 @@ #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 "oct-env.h" @@ -65,2823 +63,2824 @@ OCTAVE_BEGIN_NAMESPACE(octave) -// Functions of the the reimplemented tab widget - -file_editor_tab_widget::file_editor_tab_widget (QWidget *p, file_editor *fe) -: QTabWidget (p) -{ - tab_bar *bar = new tab_bar (this); - - connect (bar, &tab_bar::close_current_tab_signal, - fe, &file_editor::request_close_file); - - this->setTabBar (bar); - - setTabsClosable (true); - setUsesScrollButtons (true); - setMovable (true); -} - -tab_bar *file_editor_tab_widget::get_tab_bar (void) const -{ - return qobject_cast (tabBar ()); -} - -std::list -file_editor_tab_widget::tab_list (void) const -{ - std::list retval; - for (int i = 0; i < count (); i++) - retval.push_back (static_cast (widget (i))); - return retval; -} - -// File editor - -file_editor::file_editor (QWidget *p, base_qobject& oct_qobj) - : file_editor_interface (p, oct_qobj) -{ - // Set current editing directory before construction because loaded - // files will change ced accordingly. - m_ced = QDir::currentPath (); - - // Set actions that are later added by the main window to null, - // preventing access to them when they are still undefined. - m_undo_action = nullptr; - m_copy_action = nullptr; - m_paste_action = nullptr; - m_selectall_action = nullptr; - - m_find_dialog = nullptr; - - m_closed = false; - m_no_focus = false; - m_editor_ready = false; - - m_copy_action_enabled = false; - m_undo_action_enabled = false; - m_current_tab_modified = false; - - construct (); - - setVisible (false); - setAcceptDrops (true); - setFocusPolicy (Qt::StrongFocus); -} - -void file_editor::focusInEvent (QFocusEvent *e) -{ - // The focus is transferred to the active tab and its edit - // area in this focus in event handler. This is to avoid - // using focus proxies with conflicts in the proxy change - // presumably introduced by bug - // https://bugreports.qt.io/browse/QTBUG-61092 - reset_focus (); // Make sure editor tab with edit area get focus - - QDockWidget::focusInEvent (e); -} - -// insert global actions, that should also be displayed in the editor window, -// into the editor's menu and/or toolbar -void file_editor::insert_global_actions (QList shared_actions) -{ - // actions/menus that have to be added to the toolbar or the menu - QAction *open_action = shared_actions.at (OPEN_ACTION); - QAction *new_action = shared_actions.at (NEW_SCRIPT_ACTION); - QAction *new_fcn_action = shared_actions.at (NEW_FUNCTION_ACTION); - m_fileMenu->insertAction (m_mru_file_menu->menuAction (), open_action); - m_fileMenu->insertAction (open_action, new_fcn_action); - m_fileMenu->insertAction (new_fcn_action, new_action); - m_tool_bar->insertAction (m_popdown_mru_action, open_action); - m_tool_bar->insertAction (open_action, new_action); - - // actions that are additionally enabled/disabled later by the editor - // undo - m_undo_action = shared_actions.at (UNDO_ACTION); - m_tool_bar->insertAction (m_redo_action, m_undo_action); - m_edit_menu->insertAction (m_redo_action, m_undo_action); - // select all - m_selectall_action = shared_actions.at (SELECTALL_ACTION); - m_edit_menu->insertAction (m_find_action, m_selectall_action); - m_edit_menu->insertSeparator (m_find_action); - // paste - m_paste_action = shared_actions.at (PASTE_ACTION); - m_tool_bar->insertAction (m_find_action, m_paste_action); - m_edit_menu->insertAction (m_selectall_action, m_paste_action); - m_edit_menu->insertSeparator (m_selectall_action); - // copy - m_copy_action = shared_actions.at (COPY_ACTION); - m_tool_bar->insertAction (m_paste_action, m_copy_action); - m_edit_menu->insertAction (m_paste_action, m_copy_action); - // find files - m_find_files_action = shared_actions.at (FIND_FILES_ACTION); - m_edit_menu->insertAction (m_find_action, m_find_files_action); -} - -void file_editor::handle_enter_debug_mode (void) -{ - 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); - - if (sc_run == sc_cont) - m_run_action->setShortcut (QKeySequence ()); // prevent ambiguous shortcuts - - m_run_action->setToolTip (tr ("Continue")); // update tool tip - - emit enter_debug_mode_signal (); -} - -void file_editor::handle_exit_debug_mode (void) -{ - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - scmgr.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) -{ - // Do not include shared actions not only related to the editor - bool have_tabs = m_tab_widget->count () > 0; - - m_edit_cmd_menu->setEnabled (have_tabs); - m_edit_fmt_menu->setEnabled (have_tabs); - m_edit_nav_menu->setEnabled (have_tabs); - - m_comment_selection_action->setEnabled (have_tabs); - m_uncomment_selection_action->setEnabled (have_tabs); - m_comment_var_selection_action->setEnabled (have_tabs); - m_indent_selection_action->setEnabled (have_tabs); - m_unindent_selection_action->setEnabled (have_tabs); - m_smart_indent_line_or_selection_action->setEnabled (have_tabs); - - m_context_help_action->setEnabled (have_tabs); - m_context_doc_action->setEnabled (have_tabs); - - m_view_editor_menu->setEnabled (have_tabs); - m_zoom_in_action->setEnabled (have_tabs); - m_zoom_out_action->setEnabled (have_tabs); - m_zoom_normal_action->setEnabled (have_tabs); - - m_find_action->setEnabled (have_tabs); - m_find_next_action->setEnabled (have_tabs); - m_find_previous_action->setEnabled (have_tabs); - m_print_action->setEnabled (have_tabs); - - m_run_action->setEnabled (have_tabs && m_is_octave_file); - - m_toggle_breakpoint_action->setEnabled (have_tabs && m_is_octave_file); - m_next_breakpoint_action->setEnabled (have_tabs && m_is_octave_file); - m_previous_breakpoint_action->setEnabled (have_tabs && m_is_octave_file); - m_remove_all_breakpoints_action->setEnabled (have_tabs && m_is_octave_file); - - m_edit_function_action->setEnabled (have_tabs); - m_save_action->setEnabled (have_tabs && m_current_tab_modified); - m_save_as_action->setEnabled (have_tabs); - m_close_action->setEnabled (have_tabs); - m_close_all_action->setEnabled (have_tabs); - m_close_others_action->setEnabled (have_tabs && m_tab_widget->count () > 1); - m_sort_tabs_action->setEnabled (have_tabs && m_tab_widget->count () > 1); - - emit editor_tabs_changed_signal (have_tabs, m_is_octave_file); -} - -// empty_script determines whether we have to create an empty script -// 1. At startup, when the editor has to be (really) visible -// (Here we can not use the visibility changed signal) -// 2. When the editor becomes visible when octave is running -void file_editor::empty_script (bool startup, bool visible) -{ - - if (startup) - m_editor_ready = true; - else - { - if (! m_editor_ready) - 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 ()) - return; // do not open an empty script in the external editor - - bool real_visible; - - if (startup) - real_visible = isVisible (); - else - real_visible = visible; - - if (! real_visible || m_tab_widget->count () > 0) - return; - - if (startup && ! isFloating ()) - { - // check if editor is really visible or hidden between tabbed widgets - QWidget *parent = parentWidget (); - - if (parent) - { - QList tab_list = parent->findChildren(); - - bool in_tab = false; - int i = 0; - while ((i < tab_list.count ()) && (! in_tab)) - { - QTabBar *tab = tab_list.at (i); - i++; - - int j = 0; - while ((j < tab->count ()) && (! in_tab)) - { - // check all tabs for the editor - if (tab->tabText (j) == windowTitle ()) - { - // editor is in this tab widget - in_tab = true; - int top = tab->currentIndex (); - if (! (top > -1 && tab->tabText (top) == windowTitle ())) - return; // not current tab -> not visible - } - j++; - } - } - } - } - - request_new_file (""); -} - -void file_editor::restore_session (gui_settings *settings) -{ - //restore previous session - if (! settings->value (ed_restore_session).toBool ()) - return; - - // get the data from the settings file - QStringList sessionFileNames - = settings->value (ed_session_names).toStringList (); - - QStringList session_encodings - = settings->value (ed_session_enc).toStringList (); - - QStringList session_index - = settings->value (ed_session_ind).toStringList (); - - QStringList session_lines - = settings->value (ed_session_lines).toStringList (); - - QStringList session_bookmarks - = settings->value (ed_session_bookmarks).toStringList (); - - // fill a list of the struct and sort it (depending on index) - QList s_data; - - bool do_encoding = (session_encodings.count () == sessionFileNames.count ()); - bool do_index = (session_index.count () == sessionFileNames.count ()); - bool do_lines = (session_lines.count () == sessionFileNames.count ()); - bool do_bookmarks = (session_bookmarks.count () == sessionFileNames.count ()); - - for (int n = 0; n < sessionFileNames.count (); ++n) - { - QFileInfo file = QFileInfo (sessionFileNames.at (n)); - if (! file.exists ()) - continue; - - session_data item = { 0, -1, sessionFileNames.at (n), - QString (), QString (), QString ()}; - if (do_lines) - item.line = session_lines.at (n).toInt (); - if (do_index) - item.index = session_index.at (n).toInt (); - if (do_encoding) - item.encoding = session_encodings.at (n); - if (do_bookmarks) - item.bookmarks = session_bookmarks.at (n); - - s_data << item; - } - - std::sort (s_data.begin (), s_data.end ()); - - // finally open the files with the desired encoding in the desired order - for (int n = 0; n < s_data.count (); ++n) - request_open_file (s_data.at (n).file_name, s_data.at (n).encoding, - s_data.at (n).line, false, false, true, "", -1, - s_data.at (n).bookmarks); -} - -void file_editor::activate (void) -{ - if (m_no_focus) - return; // No focus for the editor if external open/close request - - octave_dock_widget::activate (); - - // set focus to current tab - reset_focus (); -} - -void file_editor::set_focus (QWidget *fet) -{ - setFocus (); - - // set focus to desired tab - if (fet) - m_tab_widget->setCurrentWidget (fet); -} - -// function enabling/disabling the menu accelerators depending on the -// focus of the editor -void file_editor::enable_menu_shortcuts (bool enable) -{ - // Hide or show the find dialog together with the focus of the - // editor widget depending on the overall visibility of the find dialog. - // Do not change internal visibility state. - if (m_find_dialog) - m_find_dialog->set_visible (enable); - - // Take care of the shortcuts - QHash::const_iterator i = m_hash_menu_text.constBegin (); - - while (i != m_hash_menu_text.constEnd ()) - { - i.key ()->setTitle (i.value ().at (! enable)); - ++i; - } - - // when editor loses focus, enable the actions, which are always active - // in the main window due to missing info on selected text and undo actions - if (m_copy_action && m_undo_action) - { - if (enable) - { - m_copy_action->setEnabled (m_copy_action_enabled); - m_undo_action->setEnabled (m_undo_action_enabled); - } - else - { - m_copy_action_enabled = m_copy_action->isEnabled (); - m_undo_action_enabled = m_undo_action->isEnabled (); - m_copy_action->setEnabled (true); - m_undo_action->setEnabled (true); - } - } -} - -// 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) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - QStringList fetFileNames; - QStringList fet_encodings; - QStringList fet_index; - QStringList fet_lines; - QStringList fet_bookmarks; - - std::list editor_tab_lst = m_tab_widget->tab_list (); - - for (auto editor_tab : editor_tab_lst) - { - QString file_name = editor_tab->file_name (); - - // Don't append unnamed files. - - if (! file_name.isEmpty ()) - { - fetFileNames.append (file_name); - fet_encodings.append (editor_tab->encoding ()); - - QString index; - fet_index.append (index.setNum (m_tab_widget->indexOf (editor_tab))); - - int l, c; - editor_tab->qsci_edit_area ()->getCursorPosition (&l, &c); - fet_lines.append (index.setNum (l + 1)); - - fet_bookmarks.append (editor_tab->get_all_bookmarks ()); - } - } - - 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 (); -} - -bool file_editor::check_closing (void) -{ - // 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 - // they need to be saved. During these checks tabs are not closed since - // the user might cancel closing Octave during one of these saving dialogs. - // Therefore, saving the session for restoring at next start is not done - // before the application is definitely closing. - - // Save the session. Even is closing is cancelled, this would be - // overwritten by the next attempt to close the editor - save_session (); - - std::list fe_tab_lst = m_tab_widget->tab_list (); - m_number_of_tabs = fe_tab_lst.size (); - - for (auto fe_tab : fe_tab_lst) - { - // Wait for all editor tabs to have saved their files if required - - connect (fe_tab, &file_editor_tab::tab_ready_to_close, - this, &file_editor::handle_tab_ready_to_close, - Qt::UniqueConnection); - } - - m_closing_canceled = false; - - for (auto fe_tab : fe_tab_lst) - { - // If there was a cancellation, make the already saved/discarded tabs - // recover from the exit by removing the read-only state and by - // recovering the debugger breakpoints. Finally return false in order - // to cancel closing the application or the editor. - - if (fe_tab->check_file_modified (false) == QMessageBox::Cancel) - { - emit fetab_recover_from_exit (); - - m_closing_canceled = true; - - for (auto fet : fe_tab_lst) - disconnect (fet, &file_editor_tab::tab_ready_to_close, 0, 0); - - return false; - } - } - - return true; -} - -void file_editor::handle_tab_ready_to_close (void) -{ - if (m_closing_canceled) - return; - - // FIXME: Why count down to zero here before doing anything? Why - // not remove and delete each tab that is ready to be closed, one - // per invocation? - - m_number_of_tabs--; - - if (m_number_of_tabs > 0) - return; - - // Here, the application or the editor will be closed -> store the session - - // Take care of the find dialog - if (m_find_dialog) - m_find_dialog->close (); - - // Finally close all the tabs and return indication that we can exit - // the application or close the editor. - // Closing and deleting the tabs makes the editor visible. In case it was - // hidden before, this state has to be restored afterwards. - bool vis = isVisible (); - - std::list editor_tab_lst = m_tab_widget->tab_list (); - for (auto editor_tab : editor_tab_lst) - editor_tab->deleteLater (); - - m_tab_widget->clear (); - - setVisible (vis); -} - -void file_editor::request_new_file (const QString& commands) -{ - // Custom editor? If yes, we can only call the editor without passing - // some initial contents and even without being sure a new file is opened - if (call_custom_editor ()) - return; - - // New file isn't a file_editor_tab function since the file - // editor tab has yet to be created and there is no object to - // pass a signal to. Hence, functionality is here. - - file_editor_tab *fileEditorTab = make_file_editor_tab (m_ced); - add_file_editor_tab (fileEditorTab, ""); // new tab with empty title - fileEditorTab->new_file (commands); // title is updated here - activate (); // focus editor and new tab -} - -void file_editor::request_close_file (bool) -{ - file_editor_tab *editor_tab - = static_cast (m_tab_widget->currentWidget ()); - editor_tab->conditional_close (); -} - -void file_editor::request_close_all_files (bool) -{ - file_editor_tab *editor_tab; - - // loop over all tabs starting from last one otherwise deletion changes index - for (int index = m_tab_widget->count ()-1; index >= 0; index--) - { - editor_tab = static_cast (m_tab_widget->widget (index)); - editor_tab->conditional_close (); - } -} - -void file_editor::request_close_other_files (bool) -{ - file_editor_tab *editor_tab; - QWidget *tabID = m_tab_widget->currentWidget (); - - // loop over all tabs starting from last one otherwise deletion changes index - for (int index = m_tab_widget->count ()-1; index >= 0; index--) - { - if (tabID != m_tab_widget->widget (index)) - { - editor_tab - = static_cast (m_tab_widget->widget (index)); - editor_tab->conditional_close (); - } - } -} - -void file_editor::copy_full_file_path (bool) -{ - file_editor_tab *editor_tab - = static_cast (m_tab_widget->currentWidget ()); - - if (editor_tab) - QGuiApplication::clipboard ()->setText (editor_tab->file_name ()); -} - -// open a file from the mru list -void file_editor::request_mru_open_file (QAction *action) -{ - if (action) - { - request_open_file (action->data ().toStringList ().at (0), - action->data ().toStringList ().at (1)); - } -} - -void file_editor::request_print_file (bool) -{ - emit fetab_print_file (m_tab_widget->currentWidget ()); -} - -void file_editor::request_redo (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_REDO); -} - -void file_editor::request_cut (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_CUT); -} - -void file_editor::request_context_help (bool) -{ - emit fetab_context_help (m_tab_widget->currentWidget (), false); -} - -void file_editor::request_context_doc (bool) -{ - emit fetab_context_help (m_tab_widget->currentWidget (), true); -} - -void file_editor::request_context_edit (bool) -{ - emit fetab_context_edit (m_tab_widget->currentWidget ()); -} - -void file_editor::request_save_file (bool) -{ - emit fetab_save_file (m_tab_widget->currentWidget ()); -} - -void file_editor::request_save_file_as (bool) -{ - emit fetab_save_file_as (m_tab_widget->currentWidget ()); -} - -void file_editor::request_run_file (bool) -{ - // 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_fe (this); - - 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 ()) + // Functions of the the reimplemented tab widget + + file_editor_tab_widget::file_editor_tab_widget (QWidget *p, file_editor *fe) + : QTabWidget (p) + { + tab_bar *bar = new tab_bar (this); + + connect (bar, &tab_bar::close_current_tab_signal, + fe, &file_editor::request_close_file); + + this->setTabBar (bar); + + setTabsClosable (true); + setUsesScrollButtons (true); + setMovable (true); + } + + tab_bar *file_editor_tab_widget::get_tab_bar () const + { + return qobject_cast (tabBar ()); + } + + std::list + file_editor_tab_widget::tab_list () const + { + std::list retval; + for (int i = 0; i < count (); i++) + retval.push_back (static_cast (widget (i))); + return retval; + } + + // File editor + + file_editor::file_editor (QWidget *p) + : file_editor_interface (p) + { + // Set current editing directory before construction because loaded + // files will change ced accordingly. + m_ced = QDir::currentPath (); + + // Set actions that are later added by the main window to null, + // preventing access to them when they are still undefined. + m_undo_action = nullptr; + m_copy_action = nullptr; + m_paste_action = nullptr; + m_selectall_action = nullptr; + + m_find_dialog = nullptr; + + m_closed = false; + m_no_focus = false; + m_editor_ready = false; + + m_copy_action_enabled = false; + m_undo_action_enabled = false; + m_current_tab_modified = false; + + construct (); + + setVisible (false); + setAcceptDrops (true); + setFocusPolicy (Qt::StrongFocus); + } + + void file_editor::focusInEvent (QFocusEvent *e) + { + // The focus is transferred to the active tab and its edit + // area in this focus in event handler. This is to avoid + // using focus proxies with conflicts in the proxy change + // presumably introduced by bug + // https://bugreports.qt.io/browse/QTBUG-61092 + reset_focus (); // Make sure editor tab with edit area get focus + + QDockWidget::focusInEvent (e); + } + + // insert global actions, that should also be displayed in the editor window, + // into the editor's menu and/or toolbar + void file_editor::insert_global_actions (QList shared_actions) + { + // actions/menus that have to be added to the toolbar or the menu + QAction *open_action = shared_actions.at (OPEN_ACTION); + QAction *new_action = shared_actions.at (NEW_SCRIPT_ACTION); + QAction *new_fcn_action = shared_actions.at (NEW_FUNCTION_ACTION); + m_fileMenu->insertAction (m_mru_file_menu->menuAction (), open_action); + m_fileMenu->insertAction (open_action, new_fcn_action); + m_fileMenu->insertAction (new_fcn_action, new_action); + m_tool_bar->insertAction (m_popdown_mru_action, open_action); + m_tool_bar->insertAction (open_action, new_action); + + // actions that are additionally enabled/disabled later by the editor + // undo + m_undo_action = shared_actions.at (UNDO_ACTION); + m_tool_bar->insertAction (m_redo_action, m_undo_action); + m_edit_menu->insertAction (m_redo_action, m_undo_action); + // select all + m_selectall_action = shared_actions.at (SELECTALL_ACTION); + m_edit_menu->insertAction (m_find_action, m_selectall_action); + m_edit_menu->insertSeparator (m_find_action); + // paste + m_paste_action = shared_actions.at (PASTE_ACTION); + m_tool_bar->insertAction (m_find_action, m_paste_action); + m_edit_menu->insertAction (m_selectall_action, m_paste_action); + m_edit_menu->insertSeparator (m_selectall_action); + // copy + m_copy_action = shared_actions.at (COPY_ACTION); + m_tool_bar->insertAction (m_paste_action, m_copy_action); + m_edit_menu->insertAction (m_paste_action, m_copy_action); + // find files + m_find_files_action = shared_actions.at (FIND_FILES_ACTION); + m_edit_menu->insertAction (m_find_action, m_find_files_action); + } + + void file_editor::handle_enter_debug_mode () + { + 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 + + m_run_action->setToolTip (tr ("Continue")); // update tool tip + + emit enter_debug_mode_signal (); + } + + void file_editor::handle_exit_debug_mode () + { + 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 () + { + // Do not include shared actions not only related to the editor + bool have_tabs = m_tab_widget->count () > 0; + + m_edit_cmd_menu->setEnabled (have_tabs); + m_edit_fmt_menu->setEnabled (have_tabs); + m_edit_nav_menu->setEnabled (have_tabs); + + m_comment_selection_action->setEnabled (have_tabs); + m_uncomment_selection_action->setEnabled (have_tabs); + m_comment_var_selection_action->setEnabled (have_tabs); + m_indent_selection_action->setEnabled (have_tabs); + m_unindent_selection_action->setEnabled (have_tabs); + m_smart_indent_line_or_selection_action->setEnabled (have_tabs); + + m_context_help_action->setEnabled (have_tabs); + m_context_doc_action->setEnabled (have_tabs); + + m_view_editor_menu->setEnabled (have_tabs); + m_zoom_in_action->setEnabled (have_tabs); + m_zoom_out_action->setEnabled (have_tabs); + m_zoom_normal_action->setEnabled (have_tabs); + + m_find_action->setEnabled (have_tabs); + m_find_next_action->setEnabled (have_tabs); + m_find_previous_action->setEnabled (have_tabs); + m_print_action->setEnabled (have_tabs); + + m_run_action->setEnabled (have_tabs && m_is_octave_file); + + m_toggle_breakpoint_action->setEnabled (have_tabs && m_is_octave_file); + m_next_breakpoint_action->setEnabled (have_tabs && m_is_octave_file); + m_previous_breakpoint_action->setEnabled (have_tabs && m_is_octave_file); + m_remove_all_breakpoints_action->setEnabled (have_tabs && m_is_octave_file); + + m_edit_function_action->setEnabled (have_tabs); + m_save_action->setEnabled (have_tabs && m_current_tab_modified); + m_save_as_action->setEnabled (have_tabs); + m_close_action->setEnabled (have_tabs); + m_close_all_action->setEnabled (have_tabs); + m_close_others_action->setEnabled (have_tabs && m_tab_widget->count () > 1); + m_sort_tabs_action->setEnabled (have_tabs && m_tab_widget->count () > 1); + + emit editor_tabs_changed_signal (have_tabs, m_is_octave_file); + } + + // empty_script determines whether we have to create an empty script + // 1. At startup, when the editor has to be (really) visible + // (Here we can not use the visibility changed signal) + // 2. When the editor becomes visible when octave is running + void file_editor::empty_script (bool startup, bool visible) + { + + if (startup) + m_editor_ready = true; + else + { + if (! m_editor_ready) + return; // not yet ready but got visibility changed signals + } + + 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; + + if (startup) + real_visible = isVisible (); + else + real_visible = visible; + + if (! real_visible || m_tab_widget->count () > 0) + return; + + if (startup && ! isFloating ()) + { + // check if editor is really visible or hidden between tabbed widgets + QWidget *parent = parentWidget (); + + if (parent) + { + QList tab_list = parent->findChildren(); + + bool in_tab = false; + int i = 0; + while ((i < tab_list.count ()) && (! in_tab)) + { + QTabBar *tab = tab_list.at (i); + i++; + + int j = 0; + while ((j < tab->count ()) && (! in_tab)) + { + // check all tabs for the editor + if (tab->tabText (j) == windowTitle ()) + { + // editor is in this tab widget + in_tab = true; + int top = tab->currentIndex (); + if (! (top > -1 && tab->tabText (top) == windowTitle ())) + return; // not current tab -> not visible + } + j++; + } + } + } + } + + request_new_file (""); + } + + void file_editor::restore_session () + { + gui_settings settings; + + //restore previous session + if (! settings.bool_value (ed_restore_session)) + return; + + // get the data from the settings file + QStringList sessionFileNames + = settings.string_list_value (ed_session_names); + + QStringList session_encodings + = settings.string_list_value (ed_session_enc); + + QStringList session_index + = settings.string_list_value (ed_session_ind); + + QStringList session_lines + = settings.string_list_value (ed_session_lines); + + QStringList session_bookmarks + = settings.string_list_value (ed_session_bookmarks); + + // fill a list of the struct and sort it (depending on index) + QList s_data; + + bool do_encoding = (session_encodings.count () == sessionFileNames.count ()); + bool do_index = (session_index.count () == sessionFileNames.count ()); + bool do_lines = (session_lines.count () == sessionFileNames.count ()); + bool do_bookmarks = (session_bookmarks.count () == sessionFileNames.count ()); + + for (int n = 0; n < sessionFileNames.count (); ++n) + { + QFileInfo file = QFileInfo (sessionFileNames.at (n)); + if (! file.exists ()) + continue; + + session_data item = { 0, -1, sessionFileNames.at (n), + QString (), QString (), QString ()}; + if (do_lines) + item.line = session_lines.at (n).toInt (); + if (do_index) + item.index = session_index.at (n).toInt (); + if (do_encoding) + item.encoding = session_encodings.at (n); + if (do_bookmarks) + item.bookmarks = session_bookmarks.at (n); + + s_data << item; + } + + std::sort (s_data.begin (), s_data.end ()); + + // finally open the files with the desired encoding in the desired order + for (int n = 0; n < s_data.count (); ++n) + request_open_file (s_data.at (n).file_name, s_data.at (n).encoding, + s_data.at (n).line, false, false, true, "", -1, + s_data.at (n).bookmarks); + } + + void file_editor::activate () + { + if (m_no_focus) + return; // No focus for the editor if external open/close request + + octave_dock_widget::activate (); + + // set focus to current tab + reset_focus (); + } + + void file_editor::set_focus (QWidget *fet) + { + setFocus (); + + // set focus to desired tab + if (fet) + m_tab_widget->setCurrentWidget (fet); + } + + // function enabling/disabling the menu accelerators depending on the + // focus of the editor + void file_editor::enable_menu_shortcuts (bool enable) + { + // Hide or show the find dialog together with the focus of the + // editor widget depending on the overall visibility of the find dialog. + // Do not change internal visibility state. + if (m_find_dialog) + m_find_dialog->set_visible (enable); + + // Take care of the shortcuts + QHash::const_iterator i = m_hash_menu_text.constBegin (); + + while (i != m_hash_menu_text.constEnd ()) + { + i.key ()->setTitle (i.value ().at (! enable)); + ++i; + } + + // when editor loses focus, enable the actions, which are always active + // in the main window due to missing info on selected text and undo actions + if (m_copy_action && m_undo_action) + { + if (enable) + { + m_copy_action->setEnabled (m_copy_action_enabled); + m_undo_action->setEnabled (m_undo_action_enabled); + } + else + { + m_copy_action_enabled = m_copy_action->isEnabled (); + m_undo_action_enabled = m_undo_action->isEnabled (); + m_copy_action->setEnabled (true); + m_undo_action->setEnabled (true); + } + } + } + + // 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 () + { + gui_settings settings; + + QStringList fetFileNames; + QStringList fet_encodings; + QStringList fet_index; + QStringList fet_lines; + QStringList fet_bookmarks; + + std::list editor_tab_lst = m_tab_widget->tab_list (); + + for (auto editor_tab : editor_tab_lst) + { + QString file_name = editor_tab->file_name (); + + // Don't append unnamed files. + + if (! file_name.isEmpty ()) + { + fetFileNames.append (file_name); + fet_encodings.append (editor_tab->encoding ()); + + QString index; + fet_index.append (index.setNum (m_tab_widget->indexOf (editor_tab))); + + int l, c; + editor_tab->qsci_edit_area ()->getCursorPosition (&l, &c); + fet_lines.append (index.setNum (l + 1)); + + fet_bookmarks.append (editor_tab->get_all_bookmarks ()); + } + } + + 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 () + { + // 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 + // they need to be saved. During these checks tabs are not closed since + // the user might cancel closing Octave during one of these saving dialogs. + // Therefore, saving the session for restoring at next start is not done + // before the application is definitely closing. + + // Save the session. Even is closing is cancelled, this would be + // overwritten by the next attempt to close the editor + save_session (); + + std::list fe_tab_lst = m_tab_widget->tab_list (); + m_number_of_tabs = fe_tab_lst.size (); + + for (auto fe_tab : fe_tab_lst) + { + // Wait for all editor tabs to have saved their files if required + + connect (fe_tab, &file_editor_tab::tab_ready_to_close, + this, &file_editor::handle_tab_ready_to_close, + Qt::UniqueConnection); + } + + m_closing_canceled = false; + + for (auto fe_tab : fe_tab_lst) + { + // If there was a cancellation, make the already saved/discarded tabs + // recover from the exit by removing the read-only state and by + // recovering the debugger breakpoints. Finally return false in order + // to cancel closing the application or the editor. + + if (fe_tab->check_file_modified (false) == QMessageBox::Cancel) + { + emit fetab_recover_from_exit (); + + m_closing_canceled = true; + + for (auto fet : fe_tab_lst) + disconnect (fet, &file_editor_tab::tab_ready_to_close, 0, 0); + + return false; + } + } + + return true; + } + + void file_editor::handle_tab_ready_to_close () + { + if (m_closing_canceled) + return; + + // FIXME: Why count down to zero here before doing anything? Why + // not remove and delete each tab that is ready to be closed, one + // per invocation? + + m_number_of_tabs--; + + if (m_number_of_tabs > 0) + return; + + // Here, the application or the editor will be closed -> store the session + + // Take care of the find dialog + if (m_find_dialog) + m_find_dialog->close (); + + // Finally close all the tabs and return indication that we can exit + // the application or close the editor. + // Closing and deleting the tabs makes the editor visible. In case it was + // hidden before, this state has to be restored afterwards. + bool vis = isVisible (); + + std::list editor_tab_lst = m_tab_widget->tab_list (); + for (auto editor_tab : editor_tab_lst) + editor_tab->deleteLater (); + + m_tab_widget->clear (); + + setVisible (vis); + } + + void file_editor::request_new_file (const QString& commands) + { + // Custom editor? If yes, we can only call the editor without passing + // some initial contents and even without being sure a new file is opened + if (call_custom_editor ()) + return; + + // New file isn't a file_editor_tab function since the file + // editor tab has yet to be created and there is no object to + // pass a signal to. Hence, functionality is here. + + file_editor_tab *fileEditorTab = make_file_editor_tab (m_ced); + add_file_editor_tab (fileEditorTab, ""); // new tab with empty title + fileEditorTab->new_file (commands); // title is updated here + activate (); // focus editor and new tab + } + + void file_editor::request_close_file (bool) + { + file_editor_tab *editor_tab + = static_cast (m_tab_widget->currentWidget ()); + editor_tab->conditional_close (); + } + + void file_editor::request_close_all_files (bool) + { + file_editor_tab *editor_tab; + + // loop over all tabs starting from last one otherwise deletion changes index + for (int index = m_tab_widget->count ()-1; index >= 0; index--) + { + editor_tab = static_cast (m_tab_widget->widget (index)); + editor_tab->conditional_close (); + } + } + + void file_editor::request_close_other_files (bool) + { + file_editor_tab *editor_tab; + QWidget *tabID = m_tab_widget->currentWidget (); + + // loop over all tabs starting from last one otherwise deletion changes index + for (int index = m_tab_widget->count ()-1; index >= 0; index--) + { + if (tabID != m_tab_widget->widget (index)) + { + editor_tab + = static_cast (m_tab_widget->widget (index)); + editor_tab->conditional_close (); + } + } + } + + void file_editor::copy_full_file_path (bool) + { + file_editor_tab *editor_tab + = static_cast (m_tab_widget->currentWidget ()); + + if (editor_tab) + QGuiApplication::clipboard ()->setText (editor_tab->file_name ()); + } + + // open a file from the mru list + void file_editor::request_mru_open_file (QAction *action) + { + if (action) + { + request_open_file (action->data ().toStringList ().at (0), + action->data ().toStringList ().at (1)); + } + } + + void file_editor::request_print_file (bool) + { + emit fetab_print_file (m_tab_widget->currentWidget ()); + } + + void file_editor::request_redo (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_REDO); + } + + void file_editor::request_cut (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_CUT); + } + + void file_editor::request_context_help (bool) + { + emit fetab_context_help (m_tab_widget->currentWidget (), false); + } + + void file_editor::request_context_doc (bool) + { + emit fetab_context_help (m_tab_widget->currentWidget (), true); + } + + void file_editor::request_context_edit (bool) + { + emit fetab_context_edit (m_tab_widget->currentWidget ()); + } + + void file_editor::request_save_file (bool) + { + emit fetab_save_file (m_tab_widget->currentWidget ()); + } + + void file_editor::request_save_file_as (bool) + { + emit fetab_save_file_as (m_tab_widget->currentWidget ()); + } + + void file_editor::request_run_file (bool) + { + // 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_fe (this); + + 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 ()); + }); + } + + void file_editor::request_step_into_file () + { + emit fetab_run_file (m_tab_widget->currentWidget (), true); + } + + void file_editor::request_context_run (bool) + { + emit fetab_context_run (m_tab_widget->currentWidget ()); + } + + void file_editor::request_toggle_bookmark (bool) + { + emit fetab_toggle_bookmark (m_tab_widget->currentWidget ()); + } + + void file_editor::request_next_bookmark (bool) + { + emit fetab_next_bookmark (m_tab_widget->currentWidget ()); + } + + void file_editor::request_previous_bookmark (bool) + { + emit fetab_previous_bookmark (m_tab_widget->currentWidget ()); + } + + void file_editor::request_remove_bookmark (bool) + { + emit fetab_remove_bookmark (m_tab_widget->currentWidget ()); + } + + void file_editor::request_move_match_brace (bool) + { + emit fetab_move_match_brace (m_tab_widget->currentWidget (), false); + } + + void file_editor::request_sel_match_brace (bool) + { + emit fetab_move_match_brace (m_tab_widget->currentWidget (), true); + } + + // FIXME: What should this do with conditional breakpoints? + void file_editor::request_toggle_breakpoint (bool) + { + emit fetab_toggle_breakpoint (m_tab_widget->currentWidget ()); + } + + void file_editor::request_next_breakpoint (bool) + { + emit fetab_next_breakpoint (m_tab_widget->currentWidget ()); + } + + void file_editor::request_previous_breakpoint (bool) + { + emit fetab_previous_breakpoint (m_tab_widget->currentWidget ()); + } + + void file_editor::request_remove_breakpoint (bool) + { + emit fetab_remove_all_breakpoints (m_tab_widget->currentWidget ()); + } + + // slots for Edit->Commands actions + void file_editor::request_delete_start_word (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_DELWORDLEFT); + } + + void file_editor::request_delete_end_word (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_DELWORDRIGHT); + } + + void file_editor::request_delete_start_line (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_DELLINELEFT); + } + + void file_editor::request_delete_end_line (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_DELLINERIGHT); + } + + void file_editor::request_delete_line (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_LINEDELETE); + } + + void file_editor::request_copy_line (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_LINECOPY); + } + + void file_editor::request_cut_line (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_LINECUT); + } + + void file_editor::request_duplicate_selection (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_SELECTIONDUPLICATE); + } + + void file_editor::request_transpose_line (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_LINETRANSPOSE); + } + + void file_editor::request_comment_selected_text (bool) + { + emit fetab_comment_selected_text (m_tab_widget->currentWidget (), false); + } + + void file_editor::request_uncomment_selected_text (bool) + { + emit fetab_uncomment_selected_text (m_tab_widget->currentWidget ()); + } + + void file_editor::request_comment_var_selected_text (bool) + { + emit fetab_comment_selected_text (m_tab_widget->currentWidget (), true); + } + + // slots for Edit->Format actions + void file_editor::request_upper_case (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_UPPERCASE); + } + + void file_editor::request_lower_case (bool) + { + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_LOWERCASE); + } + + void file_editor::request_indent_selected_text (bool) + { + emit fetab_indent_selected_text (m_tab_widget->currentWidget ()); + } + + void file_editor::request_unindent_selected_text (bool) + { + emit fetab_unindent_selected_text (m_tab_widget->currentWidget ()); + } + + void file_editor::request_smart_indent_line_or_selected_text () + { + emit fetab_smart_indent_line_or_selected_text (m_tab_widget->currentWidget ()); + } + + void file_editor::request_conv_eol_windows (bool) + { + emit fetab_convert_eol (m_tab_widget->currentWidget (), + QsciScintilla::EolWindows); + } + void + file_editor::request_conv_eol_unix (bool) + { + emit fetab_convert_eol (m_tab_widget->currentWidget (), + QsciScintilla::EolUnix); + } + + void file_editor::request_conv_eol_mac (bool) + { + emit fetab_convert_eol (m_tab_widget->currentWidget (), + QsciScintilla::EolMac); + } + + // Slot for initially creating and showing the find dialog + void file_editor::request_find (bool) + { + // Create the dialog + find_create (); + + // Since find_create shows the dialog without activating the widget + // (which is reuqired in other cases) do this manually here + m_find_dialog->activateWindow (); + + // Initiate search text from possible selection and save the initial + // data from the dialog on the defined structure + m_find_dialog->init_search_text (); + } + + // This method creates the find dialog. + + void file_editor::find_create () + { + if (m_find_dialog) + m_find_dialog->close (); + + if (isFloating ()) + m_find_dialog = new find_dialog (this, this); + else + m_find_dialog = new find_dialog (this, parentWidget ()); + + // Add required actions + m_find_dialog->addAction (m_find_next_action); + m_find_dialog->addAction (m_find_previous_action); + + // Update edit area + file_editor_tab *fet + = static_cast (m_tab_widget->currentWidget ()); + m_find_dialog->update_edit_area (fet->qsci_edit_area ()); + + // Icon is the same as the editor + m_find_dialog->setWindowIcon (windowIcon ()); + + // Position: lower right of editor's position + int xp = x () + frameGeometry ().width (); + int yp = y () + frameGeometry ().height (); + + if (! isFloating ()) + { + // Fix position if editor is docked + + QWidget *parent = parentWidget (); + + if (parent) + { + xp = xp + parent->x (); + yp = yp + parent->y (); + } + } + + if (yp < 0) + yp = 0; + + // The size of the find dialog is considered in restore_settings + // since its size might change depending on the options + m_find_dialog->restore_settings (QPoint (xp, yp)); + + // Set visible + m_find_dialog->set_visible (true); + } + + void file_editor::request_find_next (bool) + { + if (m_find_dialog) + m_find_dialog->find_next (); + } + + void file_editor::request_find_previous (bool) + { + if (m_find_dialog) + m_find_dialog->find_prev (); + } + + void file_editor::request_goto_line (bool) + { + emit fetab_goto_line (m_tab_widget->currentWidget ()); + } + + void file_editor::request_completion (bool) + { + emit fetab_completion (m_tab_widget->currentWidget ()); + } + + void file_editor::handle_file_name_changed (const QString& fname, + const QString& tip, + bool modified) + { + QObject *fileEditorTab = sender (); + if (fileEditorTab) + { + gui_settings settings; + + for (int i = 0; i < m_tab_widget->count (); i++) + { + if (m_tab_widget->widget (i) == fileEditorTab) + { + m_tab_widget->setTabText (i, fname); + m_tab_widget->setTabToolTip (i, tip); + + m_save_action->setEnabled (modified); + m_current_tab_modified = modified; + + if (modified) + m_tab_widget->setTabIcon (i, settings.icon ("document-save")); + else + m_tab_widget->setTabIcon (i, QIcon ()); + } + } + } + } + + void file_editor::handle_tab_close_request (int index) + { + file_editor_tab *editor_tab + = static_cast (m_tab_widget->widget (index)); + editor_tab->conditional_close (); + } + + void + file_editor::handle_tab_remove_request () + { + QObject *fileEditorTab = sender (); + if (fileEditorTab) + { + for (int i = 0; i < m_tab_widget->count (); i++) + { + if (m_tab_widget->widget (i) == fileEditorTab) + { + m_tab_widget->removeTab (i); + + // Deleting the sender (even with deleteLater) seems a + // bit strange. Is there a better way? + fileEditorTab->deleteLater (); + break; + } + } + } + check_actions (); + + activate (); // focus stays in editor when tab is closed + + } + + // context menu of edit area + void file_editor::active_tab_changed (int index) + { + emit fetab_change_request (m_tab_widget->widget (index)); + activate (); + } + + void file_editor::handle_editor_state_changed (bool copy_available, + bool is_octave_file, + bool is_modified) + { + // In case there is some scenario where traffic could be coming from + // all the file editor tabs, just process info from the current active tab. + if (sender () == m_tab_widget->currentWidget ()) + { + m_save_action->setEnabled (is_modified); + m_current_tab_modified = is_modified; + + if (m_copy_action) + m_copy_action->setEnabled (copy_available); + + m_cut_action->setEnabled (copy_available); + + m_run_selection_action->setEnabled (copy_available); + m_run_action->setEnabled (is_octave_file); + m_is_octave_file = is_octave_file; + + emit editor_tabs_changed_signal (true, m_is_octave_file); + } + + m_copy_action_enabled = m_copy_action->isEnabled (); + m_undo_action_enabled = m_undo_action->isEnabled (); + } + + void file_editor::handle_mru_add_file (const QString& file_name, + const QString& encoding) + { + int index; + while ((index = m_mru_files.indexOf (file_name)) >= 0) + { + m_mru_files.removeAt (index); + m_mru_files_encodings.removeAt (index); + } + + m_mru_files.prepend (file_name); + m_mru_files_encodings.prepend (encoding); + + mru_menu_update (); + } + + void file_editor::check_conflict_save (const QString& saveFileName, + bool remove_on_success) + { + // Check whether this file is already open in the editor. + file_editor_tab *tab = find_tab_widget (saveFileName); + + if (tab) + { + // Note: to overwrite the contents of some other file editor tab + // with the same name requires identifying which file editor tab + // that is (not too difficult) then closing that tab. Of course, + // that could trigger another dialog box if the file editor tab + // with the same name has modifications in it. This could become + // somewhat confusing to the user. For now, opt to do nothing. + + // Create a NonModal message about error. + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"), + tr ("File not saved! A file with the selected name\n%1\n" + "is already open in the editor"). + arg (saveFileName), + QMessageBox::Ok, nullptr); + + msgBox->setWindowModality (Qt::NonModal); + msgBox->setAttribute (Qt::WA_DeleteOnClose); + msgBox->show (); + 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 () -{ - emit fetab_run_file (m_tab_widget->currentWidget (), true); -} - -void file_editor::request_context_run (bool) -{ - emit fetab_context_run (m_tab_widget->currentWidget ()); -} - -void file_editor::request_toggle_bookmark (bool) -{ - emit fetab_toggle_bookmark (m_tab_widget->currentWidget ()); -} - -void file_editor::request_next_bookmark (bool) -{ - emit fetab_next_bookmark (m_tab_widget->currentWidget ()); -} - -void file_editor::request_previous_bookmark (bool) -{ - emit fetab_previous_bookmark (m_tab_widget->currentWidget ()); -} - -void file_editor::request_remove_bookmark (bool) -{ - emit fetab_remove_bookmark (m_tab_widget->currentWidget ()); -} - -void file_editor::request_move_match_brace (bool) -{ - emit fetab_move_match_brace (m_tab_widget->currentWidget (), false); -} - -void file_editor::request_sel_match_brace (bool) -{ - emit fetab_move_match_brace (m_tab_widget->currentWidget (), true); -} - -// FIXME: What should this do with conditional breakpoints? -void file_editor::request_toggle_breakpoint (bool) -{ - emit fetab_toggle_breakpoint (m_tab_widget->currentWidget ()); -} - -void file_editor::request_next_breakpoint (bool) -{ - emit fetab_next_breakpoint (m_tab_widget->currentWidget ()); -} - -void file_editor::request_previous_breakpoint (bool) -{ - emit fetab_previous_breakpoint (m_tab_widget->currentWidget ()); -} - -void file_editor::request_remove_breakpoint (bool) -{ - emit fetab_remove_all_breakpoints (m_tab_widget->currentWidget ()); -} - -// slots for Edit->Commands actions -void file_editor::request_delete_start_word (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_DELWORDLEFT); -} - -void file_editor::request_delete_end_word (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_DELWORDRIGHT); -} - -void file_editor::request_delete_start_line (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_DELLINELEFT); -} - -void file_editor::request_delete_end_line (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_DELLINERIGHT); -} - -void file_editor::request_delete_line (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_LINEDELETE); -} - -void file_editor::request_copy_line (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_LINECOPY); -} - -void file_editor::request_cut_line (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_LINECUT); -} - -void file_editor::request_duplicate_selection (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_SELECTIONDUPLICATE); -} - -void file_editor::request_transpose_line (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_LINETRANSPOSE); -} - -void file_editor::request_comment_selected_text (bool) -{ - emit fetab_comment_selected_text (m_tab_widget->currentWidget (), false); -} - -void file_editor::request_uncomment_selected_text (bool) -{ - emit fetab_uncomment_selected_text (m_tab_widget->currentWidget ()); -} - -void file_editor::request_comment_var_selected_text (bool) -{ - emit fetab_comment_selected_text (m_tab_widget->currentWidget (), true); -} - -// slots for Edit->Format actions -void file_editor::request_upper_case (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_UPPERCASE); -} - -void file_editor::request_lower_case (bool) -{ - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_LOWERCASE); -} - -void file_editor::request_indent_selected_text (bool) -{ - emit fetab_indent_selected_text (m_tab_widget->currentWidget ()); -} - -void file_editor::request_unindent_selected_text (bool) -{ - emit fetab_unindent_selected_text (m_tab_widget->currentWidget ()); -} - -void file_editor::request_smart_indent_line_or_selected_text () -{ - emit fetab_smart_indent_line_or_selected_text (m_tab_widget->currentWidget ()); -} - -void file_editor::request_conv_eol_windows (bool) -{ - emit fetab_convert_eol (m_tab_widget->currentWidget (), - QsciScintilla::EolWindows); -} -void -file_editor::request_conv_eol_unix (bool) -{ - emit fetab_convert_eol (m_tab_widget->currentWidget (), - QsciScintilla::EolUnix); -} - -void file_editor::request_conv_eol_mac (bool) -{ - emit fetab_convert_eol (m_tab_widget->currentWidget (), - QsciScintilla::EolMac); -} - -// Slot for initially creating and showing the find dialog -void file_editor::request_find (bool) -{ - // Create the dialog - find_create (); - - // Since find_create shows the dialog without activating the widget - // (which is reuqired in other cases) do this manually here - m_find_dialog->activateWindow (); - - // Initiate search text from possible selection and save the initial - // data from the dialog on the defined structure - m_find_dialog->init_search_text (); -} - -// This method creates the find dialog. - -void file_editor::find_create () -{ - if (m_find_dialog) - m_find_dialog->close (); - - if (isFloating ()) - m_find_dialog = new find_dialog (m_octave_qobj, this, this); - else - m_find_dialog = new find_dialog (m_octave_qobj, this, parentWidget ()); - - // Add required actions - m_find_dialog->addAction (m_find_next_action); - m_find_dialog->addAction (m_find_previous_action); - - // Update edit area - file_editor_tab *fet - = static_cast (m_tab_widget->currentWidget ()); - m_find_dialog->update_edit_area (fet->qsci_edit_area ()); - - // Icon is the same as the editor - m_find_dialog->setWindowIcon (windowIcon ()); - - // Position: lower right of editor's position - int xp = x () + frameGeometry ().width (); - int yp = y () + frameGeometry ().height (); - - if (! isFloating ()) - { - // Fix position if editor is docked - - QWidget *parent = parentWidget (); - - if (parent) - { - xp = xp + parent->x (); - yp = yp + parent->y (); - } - } - - if (yp < 0) - yp = 0; - - // The size of the find dialog is considered in restore_settings - // since its size might change depending on the options - m_find_dialog->restore_settings (QPoint (xp, yp)); - - // Set visible - m_find_dialog->set_visible (true); -} - -void file_editor::request_find_next (bool) -{ - if (m_find_dialog) - m_find_dialog->find_next (); -} - -void file_editor::request_find_previous (bool) -{ - if (m_find_dialog) - m_find_dialog->find_prev (); -} - -void file_editor::request_goto_line (bool) -{ - emit fetab_goto_line (m_tab_widget->currentWidget ()); -} - -void file_editor::request_completion (bool) -{ - emit fetab_completion (m_tab_widget->currentWidget ()); -} - -void file_editor::handle_file_name_changed (const QString& fname, - const QString& tip, - bool modified) -{ - QObject *fileEditorTab = sender (); - if (fileEditorTab) - { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - for (int i = 0; i < m_tab_widget->count (); i++) - { - if (m_tab_widget->widget (i) == fileEditorTab) - { - m_tab_widget->setTabText (i, fname); - m_tab_widget->setTabToolTip (i, tip); - - m_save_action->setEnabled (modified); - m_current_tab_modified = modified; - - if (modified) - m_tab_widget->setTabIcon (i, rmgr.icon ("document-save")); - else - m_tab_widget->setTabIcon (i, QIcon ()); - } - } - } -} - -void file_editor::handle_tab_close_request (int index) -{ - file_editor_tab *editor_tab - = static_cast (m_tab_widget->widget (index)); - editor_tab->conditional_close (); -} - -void -file_editor::handle_tab_remove_request (void) -{ - QObject *fileEditorTab = sender (); - if (fileEditorTab) - { - for (int i = 0; i < m_tab_widget->count (); i++) - { - if (m_tab_widget->widget (i) == fileEditorTab) - { - m_tab_widget->removeTab (i); - - // Deleting the sender (even with deleteLater) seems a - // bit strange. Is there a better way? - fileEditorTab->deleteLater (); - break; - } - } - } - check_actions (); - - activate (); // focus stays in editor when tab is closed - -} - -// context menu of edit area -void file_editor::active_tab_changed (int index) -{ - emit fetab_change_request (m_tab_widget->widget (index)); - activate (); -} - -void file_editor::handle_editor_state_changed (bool copy_available, - bool is_octave_file, - bool is_modified) -{ - // In case there is some scenario where traffic could be coming from - // all the file editor tabs, just process info from the current active tab. - if (sender () == m_tab_widget->currentWidget ()) - { - m_save_action->setEnabled (is_modified); - m_current_tab_modified = is_modified; - - if (m_copy_action) - m_copy_action->setEnabled (copy_available); - - m_cut_action->setEnabled (copy_available); - - m_run_selection_action->setEnabled (copy_available); - m_run_action->setEnabled (is_octave_file); - m_is_octave_file = is_octave_file; - - emit editor_tabs_changed_signal (true, m_is_octave_file); - } - - m_copy_action_enabled = m_copy_action->isEnabled (); - m_undo_action_enabled = m_undo_action->isEnabled (); -} - -void file_editor::handle_mru_add_file (const QString& file_name, - const QString& encoding) -{ - int index; - while ((index = m_mru_files.indexOf (file_name)) >= 0) - { - m_mru_files.removeAt (index); - m_mru_files_encodings.removeAt (index); - } - - m_mru_files.prepend (file_name); - m_mru_files_encodings.prepend (encoding); - - mru_menu_update (); -} - -void file_editor::check_conflict_save (const QString& saveFileName, - bool remove_on_success) -{ - // Check whether this file is already open in the editor. - file_editor_tab *tab = find_tab_widget (saveFileName); - - if (tab) - { - // Note: to overwrite the contents of some other file editor tab - // with the same name requires identifying which file editor tab - // that is (not too difficult) then closing that tab. Of course, - // that could trigger another dialog box if the file editor tab - // with the same name has modifications in it. This could become - // somewhat confusing to the user. For now, opt to do nothing. - - // Create a NonModal message about error. - QMessageBox *msgBox - = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"), - tr ("File not saved! A file with the selected name\n%1\n" - "is already open in the editor"). - arg (saveFileName), - QMessageBox::Ok, nullptr); - - msgBox->setWindowModality (Qt::NonModal); - msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); - - return; - } - - QObject *saveFileObject = sender (); - QWidget *saveFileWidget = nullptr; - - for (int i = 0; i < m_tab_widget->count (); i++) - { - if (m_tab_widget->widget (i) == saveFileObject) - { - saveFileWidget = m_tab_widget->widget (i); - break; - } - } - if (! saveFileWidget) - { - // Create a NonModal message about error. - QMessageBox *msgBox - = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"), - tr ("The associated file editor tab has disappeared."), - QMessageBox::Ok, nullptr); - - msgBox->setWindowModality (Qt::NonModal); - msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); - - return; - } - - // Can save without conflict, have the file editor tab do so. - emit fetab_save_file (saveFileWidget, saveFileName, remove_on_success); -} - -void file_editor::handle_insert_debugger_pointer_request (const QString& file, - int line) -{ - request_open_file (file, QString (), line, true); // default encoding -} - -void file_editor::handle_delete_debugger_pointer_request (const QString& file, - int line) -{ - if (! file.isEmpty ()) - { - // Check whether this file is already open in the editor. - file_editor_tab *tab = find_tab_widget (file); - - if (tab) - { - m_tab_widget->setCurrentWidget (tab); - - if (line > 0) - emit fetab_delete_debugger_pointer (tab, line); - - emit fetab_set_focus (tab); - } - } -} - -void file_editor::handle_update_breakpoint_marker_request (bool insert, - const QString& file, - int line, - const QString& cond) -{ - request_open_file (file, QString (), line, false, true, insert, cond); -} - -void file_editor::handle_edit_file_request (const QString& file) -{ - request_open_file (file); -} - -// Slot used for signals indicating that a file was changed/renamed or -// is going to be deleted/renamed -void file_editor::handle_file_remove (const QString& old_name, - const QString& new_name) -{ - // Clear old list of file data and declare a structure for file data - m_tmp_closed_files.clear (); - removed_file_data f_data; - - // Preprocessing old name(s) - QString old_name_clean = old_name.trimmed (); - int s = old_name_clean.size (); - - if (s > 1 && old_name_clean.at (0) == QChar ('\"') - && old_name_clean.at (s - 1) == QChar ('\"')) - old_name_clean = old_name_clean.mid (1, s - 2); - - QStringList old_names = old_name_clean.split ("\" \""); - - // Check if new name is a file or directory - QFileInfo newf (new_name); - bool new_is_dir = newf.isDir (); - - // Now loop over all old files/dirs (several files by movefile ()) - for (int i = 0; i < old_names.count (); i++) - { - // Check if old name is a file or directory - QFileInfo old (old_names.at (i)); - - if (old.isDir ()) - { - // Call the function which handles directories and return - handle_dir_remove (old_names.at (i), new_name); - } - else - { - // It is a single file. Is it open? - file_editor_tab *editor_tab = find_tab_widget (old_names.at (i)); - - if (editor_tab) - { - - editor_tab->enable_file_watcher (false); - - // For re-enabling tracking if error while removing/renaming - f_data.editor_tab = editor_tab; - // For renaming into new file (if new_file is not empty) - if (new_is_dir) - { - std::string ndir = new_name.toStdString (); - std::string ofile = old.fileName ().toStdString (); - f_data.new_file_name - = QString::fromStdString (sys::env::make_absolute (ofile, ndir)); - } - else - f_data.new_file_name = new_name; - - // Add file data to list - m_tmp_closed_files << f_data; - } - } - } -} - -// Slot for signal indicating that a file was renamed -void file_editor::handle_file_renamed (bool load_new) -{ - m_no_focus = true; // Remember for not focussing editor - - // Loop over all files that have to be handled. Start at the end of the - // list, otherwise the stored indexes are not correct. - for (int i = m_tmp_closed_files.count () - 1; i >= 0; i--) - { - if (load_new) - { - // Close file (remove) or rename into new file (rename) - 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); - } - else - { - // Something went wrong while renaming or removing: - // Leave everything as it is but reactivate tracking - m_tmp_closed_files.at (i).editor_tab->enable_file_watcher (true); - } - - } - - m_no_focus = false; // Back to normal focus - - // Clear the list of file data - m_tmp_closed_files.clear (); -} - -void file_editor::notice_settings (const gui_settings *settings) -{ - int size_idx = settings->value (global_icon_size).toInt (); - 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_tool_bar->setIconSize (QSize (icon_size, icon_size)); - - // Tab position and rotation - QTabWidget::TabPosition pos - = static_cast (settings->value (ed_tab_position).toInt ()); - bool rotated = settings->value (ed_tabs_rotated).toBool (); - - 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 - - // Get the tab bar and set the rotation - int rotation = rotated; - if (pos == QTabWidget::West) - rotation = -rotation; - - tab_bar *bar = m_tab_widget->get_tab_bar (); - bar->set_rotated (rotation); - - // Get suitable height of a tab related to font and icon size - int height = 1.5*QFontMetrics (m_tab_widget->font ()).height (); - int is = 1.5*m_tab_widget->iconSize ().height (); - if (is > height) - height = is; - - // Calculate possibly limited width and set the elide mode - int chars = settings->value (ed_tabs_max_width).toInt (); - int width = 9999; - if (chars > 0) - width = chars * QFontMetrics (m_tab_widget->font ()).averageCharWidth (); - - // Get tab bar size properties for style sheet depending on rotation - QString width_str ("width"); - QString height_str ("height"); - if ((pos == QTabWidget::West) || (pos == QTabWidget::East)) - { - width_str = QString ("height"); - height_str = QString ("width"); - } - - QString style_sheet - = QString ("QTabBar::tab {max-" + height_str + ": %1px;\n" - "max-" + width_str + ": %2px; }") - .arg (height).arg (width); + } + + QObject *saveFileObject = sender (); + QWidget *saveFileWidget = nullptr; + + for (int i = 0; i < m_tab_widget->count (); i++) + { + if (m_tab_widget->widget (i) == saveFileObject) + { + saveFileWidget = m_tab_widget->widget (i); + break; + } + } + if (! saveFileWidget) + { + // Create a NonModal message about error. + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"), + tr ("The associated file editor tab has disappeared."), + QMessageBox::Ok, nullptr); + + msgBox->setWindowModality (Qt::NonModal); + msgBox->setAttribute (Qt::WA_DeleteOnClose); + msgBox->show (); + + return; + } + + // Can save without conflict, have the file editor tab do so. + emit fetab_save_file (saveFileWidget, saveFileName, remove_on_success); + } + + void file_editor::handle_insert_debugger_pointer_request (const QString& file, + int line) + { + request_open_file (file, QString (), line, true); // default encoding + } + + void file_editor::handle_delete_debugger_pointer_request (const QString& file, + int line) + { + if (! file.isEmpty ()) + { + // Check whether this file is already open in the editor. + file_editor_tab *tab = find_tab_widget (file); + + if (tab) + { + m_tab_widget->setCurrentWidget (tab); + + if (line > 0) + emit fetab_delete_debugger_pointer (tab, line); + + emit fetab_set_focus (tab); + } + } + } + + void file_editor::handle_update_breakpoint_marker_request (bool insert, + const QString& file, + int line, + const QString& cond) + { + request_open_file (file, QString (), line, false, true, insert, cond); + } + + void file_editor::handle_edit_file_request (const QString& file) + { + request_open_file (file); + } + + // Slot used for signals indicating that a file was changed/renamed or + // is going to be deleted/renamed + void file_editor::handle_file_remove (const QString& old_name, + const QString& new_name) + { + // Clear old list of file data and declare a structure for file data + m_tmp_closed_files.clear (); + removed_file_data f_data; + + // Preprocessing old name(s) + QString old_name_clean = old_name.trimmed (); + int s = old_name_clean.size (); + + if (s > 1 && old_name_clean.at (0) == QChar ('\"') + && old_name_clean.at (s - 1) == QChar ('\"')) + old_name_clean = old_name_clean.mid (1, s - 2); + + QStringList old_names = old_name_clean.split ("\" \""); + + // Check if new name is a file or directory + QFileInfo newf (new_name); + bool new_is_dir = newf.isDir (); + + // Now loop over all old files/dirs (several files by movefile ()) + for (int i = 0; i < old_names.count (); i++) + { + // Check if old name is a file or directory + QFileInfo old (old_names.at (i)); + + if (old.isDir ()) + { + // Call the function which handles directories and return + handle_dir_remove (old_names.at (i), new_name); + } + else + { + // It is a single file. Is it open? + file_editor_tab *editor_tab = find_tab_widget (old_names.at (i)); + + if (editor_tab) + { + + editor_tab->enable_file_watcher (false); + + // For re-enabling tracking if error while removing/renaming + f_data.editor_tab = editor_tab; + // For renaming into new file (if new_file is not empty) + if (new_is_dir) + { + std::string ndir = new_name.toStdString (); + std::string ofile = old.fileName ().toStdString (); + f_data.new_file_name + = QString::fromStdString (sys::env::make_absolute (ofile, ndir)); + } + else + f_data.new_file_name = new_name; + + // Add file data to list + m_tmp_closed_files << f_data; + } + } + } + } + + // Slot for signal indicating that a file was renamed + void file_editor::handle_file_renamed (bool load_new) + { + m_no_focus = true; // Remember for not focussing editor + + // Loop over all files that have to be handled. Start at the end of the + // list, otherwise the stored indexes are not correct. + for (int i = m_tmp_closed_files.count () - 1; i >= 0; i--) + { + if (load_new) + { + // Close file (remove) or rename into new file (rename) + 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); + } + else + { + // Something went wrong while renaming or removing: + // Leave everything as it is but reactivate tracking + m_tmp_closed_files.at (i).editor_tab->enable_file_watcher (true); + } + + } + + m_no_focus = false; // Back to normal focus + + // Clear the list of file data + m_tmp_closed_files.clear (); + } + + void file_editor::notice_settings () + { + 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 (); + int icon_size = st->pixelMetric (global_icon_sizes[size_idx]); + m_tool_bar->setIconSize (QSize (icon_size, icon_size)); + + // Tab position and rotation + QTabWidget::TabPosition pos + = 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 + + // Get the tab bar and set the rotation + int rotation = rotated; + if (pos == QTabWidget::West) + rotation = -rotation; + + tab_bar *bar = m_tab_widget->get_tab_bar (); + bar->set_rotated (rotation); + + // Get suitable height of a tab related to font and icon size + int height = 1.5*QFontMetrics (m_tab_widget->font ()).height (); + int is = 1.5*m_tab_widget->iconSize ().height (); + if (is > height) + height = is; + + // Calculate possibly limited width and set the elide mode + int chars = settings.int_value (ed_tabs_max_width); + int width = 9999; + if (chars > 0) + width = chars * QFontMetrics (m_tab_widget->font ()).averageCharWidth (); + + // Get tab bar size properties for style sheet depending on rotation + QString width_str ("width"); + QString height_str ("height"); + if ((pos == QTabWidget::West) || (pos == QTabWidget::East)) + { + width_str = QString ("height"); + height_str = QString ("width"); + } + + QString style_sheet + = 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 - // in several Qt versions (https://bugreports.qt.io/browse/QTBUG-61092) - if (! rotated) - { - 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; }"); - - style_sheet = style_sheet + close_button_css_mac; - } + // FIXME: This is a workaround for missing tab close buttons on MacOS + // in several Qt versions (https://bugreports.qt.io/browse/QTBUG-61092) + if (! rotated) + { + 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; }"); + + style_sheet = style_sheet + close_button_css_mac; + } #endif - m_tab_widget->setStyleSheet (style_sheet); - - bool show_it; - show_it = settings->value (ed_show_line_numbers).toBool (); - m_show_linenum_action->setChecked (show_it); - show_it = settings->value (ed_show_white_space).toBool (); - m_show_whitespace_action->setChecked (show_it); - show_it = settings->value (ed_show_eol_chars).toBool (); - m_show_eol_action->setChecked (show_it); - show_it = settings->value (ed_show_indent_guides).toBool (); - m_show_indguide_action->setChecked (show_it); - show_it = settings->value (ed_long_line_marker).toBool (); - m_show_longline_action->setChecked (show_it); - - show_it = settings->value (ed_show_toolbar).toBool (); - m_show_toolbar_action->setChecked (show_it); - m_tool_bar->setVisible (show_it); - show_it = settings->value (ed_show_edit_status_bar).toBool (); - m_show_statusbar_action->setChecked (show_it); - show_it = settings->value (ed_show_hscroll_bar).toBool (); - m_show_hscrollbar_action->setChecked (show_it); - - set_shortcuts (); - - // Find dialog with the same icon as the editor - if (m_find_dialog) - m_find_dialog->setWindowIcon (windowIcon ()); - - // Relay signal to file editor tabs. - emit fetab_settings_changed (settings); -} - -void file_editor::set_shortcuts (void) -{ - // 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 (); - - // 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); - - // 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); - - // 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); - - // 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); - - // 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); - - // 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); - - // 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); - -} - -// This slot is a reimplementation of the virtual slot in octave_dock_widget. -// We need this for creating an empty script when the editor has no open -// files and is made visible. -void file_editor::handle_visibility (bool visible) -{ - octave_dock_widget::handle_visibility (visible); - - if (! m_editor_ready) - return; - - 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); - } - - empty_script (false, visible); -} - -// This slot is a reimplementation of the virtual slot in octave_dock_widget. -// We need this for updating the parent of the find dialog -void file_editor::toplevel_change (bool) -{ - if (m_find_dialog) - { - // close current dialog - m_find_dialog->close (); - - // re-create dialog with the new parent (editor or main-win) - find_create (); - m_find_dialog->activateWindow (); - } -} - -void file_editor::update_octave_directory (const QString& dir) -{ - m_ced = dir; - emit fetab_set_directory (m_ced); // for save dialog -} - -void file_editor::copyClipboard (void) -{ - if (editor_tab_has_focus ()) - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_COPY); -} - -void file_editor::pasteClipboard (void) -{ - if (editor_tab_has_focus ()) - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_PASTE); -} - -void file_editor::selectAll (void) -{ - if (editor_tab_has_focus ()) - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_SELECTALL); -} - -void file_editor::do_undo (void) -{ - if (editor_tab_has_focus ()) - emit fetab_scintilla_command (m_tab_widget->currentWidget (), - QsciScintillaBase::SCI_UNDO); -} - -// Open a file, if not already open, and mark the current execution location -// and/or a breakpoint with condition cond. -void file_editor::request_open_file (const QString& openFileName, - const QString& encoding, - int line, bool debug_pointer, - bool breakpoint_marker, bool insert, - 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 ()) - { - // Custom editor - if (debug_pointer || breakpoint_marker) - return; // Do not call custom editor during debugging - - if (call_custom_editor (openFileName, line)) - return; // Custom editor called - } - - bool show_dbg_file - = settings->value (ed_show_dbg_file).toBool (); - - if (openFileName.isEmpty ()) - { - // This happens if edit is called without an argument - // Open editor with empty edit area instead (as new file would do) - request_new_file (""); - } - else - { - // Check whether this file is already open in the editor. - file_editor_tab *tab = find_tab_widget (openFileName); - - if (tab) - { - m_tab_widget->setCurrentWidget (tab); - - if (line > 0) - { - if (insert) - emit fetab_goto_line (tab, line); - - if (debug_pointer) - emit fetab_insert_debugger_pointer (tab, line); - - if (breakpoint_marker) - emit fetab_do_breakpoint_marker (insert, tab, line, cond); - } - - if (show_dbg_file && ! ((breakpoint_marker || debug_pointer) - && is_editor_console_tabbed ())) - { - emit fetab_set_focus (tab); - activate (); - } - } - else - { - if (! show_dbg_file && (breakpoint_marker || debug_pointer)) - return; // Do not open a file for showing dbg markers - - if (breakpoint_marker && ! insert) - return; // Never open a file when removing breakpoints - - file_editor_tab *fileEditorTab = nullptr; - // Reuse tab if it hasn't yet been modified. - bool reusing = false; - tab = find_tab_widget (""); - if (tab) - { - fileEditorTab = tab; - if (fileEditorTab->qsci_edit_area ()->isModified ()) - fileEditorTab = nullptr; - else - reusing = true; - } - - // If was absent or modified, create a new tab. - if (! fileEditorTab) - fileEditorTab = make_file_editor_tab (); - - fileEditorTab->set_encoding (encoding); - QString result = fileEditorTab->load_file (openFileName); - if (result == "") - { - // Supply empty title then have the file_editor_tab update - // with full or short name. - if (! reusing) - add_file_editor_tab (fileEditorTab, "", index); - fileEditorTab->update_window_title (false); - // file already loaded, add file to mru list here - QFileInfo file_info = QFileInfo (openFileName); - handle_mru_add_file (file_info.canonicalFilePath (), - encoding); - - if (line > 0) - { - if (insert) - emit fetab_goto_line (fileEditorTab, line); - - if (debug_pointer) - emit fetab_insert_debugger_pointer (fileEditorTab, - line); - if (breakpoint_marker) - emit fetab_do_breakpoint_marker (insert, fileEditorTab, - line, cond); - } - } - else - { - if (! reusing) - { - delete fileEditorTab; + m_tab_widget->setStyleSheet (style_sheet); + + bool show_it; + show_it = settings.bool_value (ed_show_line_numbers); + m_show_linenum_action->setChecked (show_it); + show_it = settings.bool_value (ed_show_white_space); + m_show_whitespace_action->setChecked (show_it); + show_it = settings.bool_value (ed_show_eol_chars); + m_show_eol_action->setChecked (show_it); + show_it = settings.bool_value (ed_show_indent_guides); + m_show_indguide_action->setChecked (show_it); + show_it = settings.bool_value (ed_long_line_marker); + m_show_longline_action->setChecked (show_it); + + show_it = settings.bool_value (ed_show_toolbar); + m_show_toolbar_action->setChecked (show_it); + m_tool_bar->setVisible (show_it); + show_it = settings.bool_value (ed_show_edit_status_bar); + m_show_statusbar_action->setChecked (show_it); + show_it = settings.bool_value (ed_show_hscroll_bar); + m_show_hscrollbar_action->setChecked (show_it); + + set_shortcuts (); + + // Find dialog with the same icon as the editor + if (m_find_dialog) + m_find_dialog->setWindowIcon (windowIcon ()); + + // Relay signal to file editor tabs. + emit fetab_settings_changed (); + } + + 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 + + gui_settings settings; + + // File menu + 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 + 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 + 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 + 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 + 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 + 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 + 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. + // We need this for creating an empty script when the editor has no open + // files and is made visible. + void file_editor::handle_visibility (bool visible) + { + octave_dock_widget::handle_visibility (visible); + + if (! m_editor_ready) + return; + + if (m_closed && visible) + { + m_closed = false; + + restore_session (); + } + + empty_script (false, visible); + } + + // This slot is a reimplementation of the virtual slot in octave_dock_widget. + // We need this for updating the parent of the find dialog + void file_editor::toplevel_change (bool) + { + if (m_find_dialog) + { + // close current dialog + m_find_dialog->close (); + + // re-create dialog with the new parent (editor or main-win) + find_create (); + m_find_dialog->activateWindow (); + } + } + + void file_editor::update_octave_directory (const QString& dir) + { + m_ced = dir; + emit fetab_set_directory (m_ced); // for save dialog + } + + void file_editor::copyClipboard () + { + if (editor_tab_has_focus ()) + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_COPY); + } + + void file_editor::pasteClipboard () + { + if (editor_tab_has_focus ()) + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_PASTE); + } + + 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 () + { + if (editor_tab_has_focus ()) + emit fetab_scintilla_command (m_tab_widget->currentWidget (), + QsciScintillaBase::SCI_UNDO); + } + + // Open a file, if not already open, and mark the current execution location + // and/or a breakpoint with condition cond. + void file_editor::request_open_file (const QString& openFileName, + const QString& encoding, + int line, bool debug_pointer, + bool breakpoint_marker, bool insert, + const QString& cond, int index, + const QString& bookmarks) + { + gui_settings settings; + + if (settings.bool_value (global_use_custom_editor)) + { + // Custom editor + if (debug_pointer || breakpoint_marker) + return; // Do not call custom editor during debugging + + if (call_custom_editor (openFileName, line)) + return; // Custom editor called + } + + bool show_dbg_file = settings.bool_value (ed_show_dbg_file); + + if (openFileName.isEmpty ()) + { + // This happens if edit is called without an argument + // Open editor with empty edit area instead (as new file would do) + request_new_file (""); + } + else + { + // Check whether this file is already open in the editor. + file_editor_tab *tab = find_tab_widget (openFileName); + + if (tab) + { + m_tab_widget->setCurrentWidget (tab); + + if (line > 0) + { + if (insert) + emit fetab_goto_line (tab, line); + + if (debug_pointer) + emit fetab_insert_debugger_pointer (tab, line); + + if (breakpoint_marker) + emit fetab_do_breakpoint_marker (insert, tab, line, cond); + } + + if (show_dbg_file && ! ((breakpoint_marker || debug_pointer) + && is_editor_console_tabbed ())) + { + emit fetab_set_focus (tab); + activate (); + } + } + else + { + if (! show_dbg_file && (breakpoint_marker || debug_pointer)) + return; // Do not open a file for showing dbg markers + + if (breakpoint_marker && ! insert) + return; // Never open a file when removing breakpoints + + file_editor_tab *fileEditorTab = nullptr; + // Reuse tab if it hasn't yet been modified. + bool reusing = false; + tab = find_tab_widget (""); + if (tab) + { + fileEditorTab = tab; + if (fileEditorTab->qsci_edit_area ()->isModified ()) fileEditorTab = nullptr; - } - - if (QFile::exists (openFileName)) - { - // File not readable: - // create a NonModal message about error. - QMessageBox *msgBox - = new QMessageBox (QMessageBox::Critical, - tr ("Octave Editor"), - tr ("Could not open file\n%1\nfor read: %2."). - arg (openFileName).arg (result), - QMessageBox::Ok, this); - - msgBox->setWindowModality (Qt::NonModal); - msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); - } - else - { - // File does not exist, should it be created? - bool create_file = true; - QMessageBox *msgBox; - - if (! settings->value (ed_create_new_file).toBool ()) - { - msgBox = new QMessageBox (QMessageBox::Question, - tr ("Octave Editor"), - tr ("File\n%1\ndoes not exist. " - "Do you want to create it?").arg (openFileName), - QMessageBox::NoButton, nullptr); - QPushButton *create_button = - msgBox->addButton (tr ("Create"), QMessageBox::YesRole); - msgBox->addButton (tr ("Cancel"), QMessageBox::RejectRole); - msgBox->setDefaultButton (create_button); - msgBox->exec (); - - QAbstractButton *clicked_button = msgBox->clickedButton (); - if (clicked_button != create_button) - create_file = false; - - delete msgBox; - } - - if (create_file) - { - // create the file and call the editor again - QFile file (openFileName); - if (! file.open (QIODevice::WriteOnly)) - { - // error opening the file - msgBox = new QMessageBox (QMessageBox::Critical, - tr ("Octave Editor"), - tr ("Could not open file\n%1\nfor write: %2."). - arg (openFileName).arg (file.errorString ()), - QMessageBox::Ok, this); - - msgBox->setWindowModality (Qt::NonModal); - msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); - } - else - { - file.close (); - request_open_file (openFileName); - } - } - } - } - - if (! bookmarks.isEmpty ()) - { - // Restore bookmarks - for (const auto& bms : bookmarks.split (',')) - { - int bm = bms.toInt (); - if (fileEditorTab) - fileEditorTab->qsci_edit_area ()->markerAdd (bm, marker::bookmark); - } - } - - if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ())) - { - // update breakpoint pointers, really show editor - // and the current editor tab - if (fileEditorTab) - fileEditorTab->update_breakpoints (); - activate (); - emit file_loaded_signal (); - } - } - } -} - -void file_editor::request_preferences (bool) -{ - emit request_settings_dialog ("editor"); -} - -void file_editor::request_styles_preferences (bool) -{ - emit request_settings_dialog ("editor_styles"); -} - -void file_editor::show_line_numbers (bool) -{ - toggle_preference (ed_show_line_numbers); -} - -void file_editor::show_white_space (bool) -{ - toggle_preference (ed_show_white_space); -} - -void file_editor::show_eol_chars (bool) -{ - toggle_preference (ed_show_eol_chars); -} - -void file_editor::show_indent_guides (bool) -{ - toggle_preference (ed_show_indent_guides); -} - -void file_editor::show_long_line (bool) -{ - toggle_preference (ed_long_line_marker); -} - -void file_editor::show_toolbar (bool) -{ - toggle_preference (ed_show_toolbar); -} - -void file_editor::show_statusbar (bool) -{ - toggle_preference (ed_show_edit_status_bar); -} - -void file_editor::show_hscrollbar (bool) -{ - toggle_preference (ed_show_hscroll_bar); -} - -void file_editor::zoom_in (bool) -{ - emit fetab_zoom_in (m_tab_widget->currentWidget ()); -} - -void file_editor::zoom_out (bool) -{ - emit fetab_zoom_out (m_tab_widget->currentWidget ()); -} - -void file_editor::zoom_normal (bool) -{ - emit fetab_zoom_normal (m_tab_widget->currentWidget ()); -} - -void file_editor::create_context_menu (QMenu *menu) -{ - // remove all standard actions from scintilla - QList all_actions = menu->actions (); - - for (auto *a : all_actions) - menu->removeAction (a); - - // add editor's actions with icons and customized shortcuts - menu->addAction (m_cut_action); - menu->addAction (m_copy_action); - menu->addAction (m_paste_action); - menu->addSeparator (); - menu->addAction (m_selectall_action); - menu->addSeparator (); - menu->addAction (m_find_files_action); - menu->addAction (m_find_action); - menu->addAction (m_find_next_action); - menu->addAction (m_find_previous_action); - menu->addSeparator (); - menu->addMenu (m_edit_cmd_menu); - menu->addMenu (m_edit_fmt_menu); - menu->addMenu (m_edit_nav_menu); - menu->addSeparator (); - menu->addAction (m_run_selection_action); -} - -void file_editor::edit_status_update (bool undo, bool redo) -{ - if (m_undo_action) - m_undo_action->setEnabled (undo); - m_redo_action->setEnabled (redo); -} - -// 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 ()) - { - if (check_closing ()) - { - // All tabs are closed without cancelling, - // store closing state for restoring session when shown again. - // Editor is closing when session data is stored in preferences - m_closed = true; - e->ignore (); - } - else - { - e->ignore (); - return; - } - } - else - e->accept (); - - octave_dock_widget::closeEvent (e); -} - -void file_editor::dragEnterEvent (QDragEnterEvent *e) -{ - if (e->mimeData ()->hasUrls ()) - { - e->acceptProposedAction (); - } -} - -void file_editor::dropEvent (QDropEvent *e) -{ - if (e->mimeData ()->hasUrls ()) - { - for (const auto& url : e->mimeData ()->urls ()) - request_open_file (url.toLocalFile ()); - } -} - -bool file_editor::is_editor_console_tabbed (void) -{ - // FIXME: is there a way to do this job that doesn't require casting - // the parent to a main_window object? - - main_window *w = dynamic_cast (parentWidget ()); - - if (w) - { - QList w_list = w->tabifiedDockWidgets (this); - QDockWidget *console = - static_cast (w->get_dock_widget_list ().at (0)); - - for (int i = 0; i < w_list.count (); i++) - { - if (w_list.at (i) == console) - return true; - } - } - - return false; -} - -void file_editor::construct (void) -{ - QWidget *editor_widget = new QWidget (this); - - // FIXME: what was the intended purpose of this unused variable? - // QStyle *editor_style = QApplication::style (); - - // Menu bar: do not set it native, required in macOS and Ubuntu Unity (Qt5) - // for a visible menu bar in the editor widget. This property is ignored - // on other platforms. - m_menu_bar = new QMenuBar (editor_widget); - m_menu_bar->setNativeMenuBar (false); - - m_tool_bar = new QToolBar (editor_widget); - m_tool_bar->setMovable (true); - - 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 (); - - if (m_mru_files_encodings.count () != m_mru_files.count ()) - { - // encodings don't have the same count -> do not use them! - m_mru_files_encodings = QStringList (); - for (int i = 0; i < m_mru_files.count (); i++) - m_mru_files_encodings << QString (); - } - - for (int i = 0; i < MaxMRUFiles; ++i) - { - m_mru_file_actions[i] = new QAction (this); - m_mru_file_actions[i]->setVisible (false); - } - - // menu bar - - // file menu - - m_fileMenu = add_menu (m_menu_bar, tr ("&File")); - - // new and open menus are inserted later by the main window - m_mru_file_menu = new QMenu (tr ("&Recent Editor Files"), m_fileMenu); - for (int i = 0; i < MaxMRUFiles; ++i) - m_mru_file_menu->addAction (m_mru_file_actions[i]); - m_fileMenu->addMenu (m_mru_file_menu); - - m_fileMenu->addSeparator (); - - m_edit_function_action - = add_action (m_fileMenu, - tr ("&Edit Function"), - SLOT (request_context_edit (bool))); - - m_fileMenu->addSeparator (); - - m_save_action - = add_action (m_fileMenu, rmgr.icon ("document-save"), - tr ("&Save File"), SLOT (request_save_file (bool))); - - m_save_as_action - = add_action (m_fileMenu, rmgr.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), - tr ("&Close"), SLOT (request_close_file (bool))); - - m_close_all_action - = add_action (m_fileMenu, rmgr.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), - tr ("Close Other Files"), - SLOT (request_close_other_files (bool))); - - m_fileMenu->addSeparator (); - - m_print_action - = add_action (m_fileMenu, rmgr.icon ("document-print"), - tr ("Print..."), SLOT (request_print_file (bool))); - - // edit menu (undo, copy, paste and select all later via main window) - - m_edit_menu = add_menu (m_menu_bar, tr ("&Edit")); - - m_redo_action - = add_action (m_edit_menu, rmgr.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"), - 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"), - tr ("&Find and Replace..."), SLOT (request_find (bool))); - - m_find_next_action - = add_action (m_edit_menu, tr ("Find &Next..."), - SLOT (request_find_next (bool))); - - m_find_previous_action - = add_action (m_edit_menu, tr ("Find &Previous..."), - SLOT (request_find_previous (bool))); - - m_edit_menu->addSeparator (); - - m_edit_cmd_menu = m_edit_menu->addMenu (tr ("&Commands")); - - m_delete_line_action - = add_action (m_edit_cmd_menu, tr ("Delete Line"), - SLOT (request_delete_line (bool))); - - m_copy_line_action - = add_action (m_edit_cmd_menu, tr ("Copy Line"), - SLOT (request_copy_line (bool))); - - m_cut_line_action - = add_action (m_edit_cmd_menu, tr ("Cut Line"), - SLOT (request_cut_line (bool))); - - m_edit_cmd_menu->addSeparator (); - - m_delete_start_word_action - = add_action (m_edit_cmd_menu, tr ("Delete to Start of Word"), - SLOT (request_delete_start_word (bool))); - - m_delete_end_word_action - = add_action (m_edit_cmd_menu, tr ("Delete to End of Word"), - SLOT (request_delete_end_word (bool))); - - m_delete_start_line_action - = add_action (m_edit_cmd_menu, tr ("Delete to Start of Line"), - SLOT (request_delete_start_line (bool))); - - m_delete_end_line_action - = add_action (m_edit_cmd_menu, tr ("Delete to End of Line"), - SLOT (request_delete_end_line (bool))); - - m_edit_cmd_menu->addSeparator (); - - m_duplicate_selection_action - = add_action (m_edit_cmd_menu, tr ("Duplicate Selection/Line"), - SLOT (request_duplicate_selection (bool))); - - m_transpose_line_action - = add_action (m_edit_cmd_menu, tr ("Transpose Line"), - SLOT (request_transpose_line (bool))); - - m_edit_cmd_menu->addSeparator (); - - m_completion_action - = add_action (m_edit_cmd_menu, tr ("&Show Completion List"), - SLOT (request_completion (bool))); - - m_edit_fmt_menu = m_edit_menu->addMenu (tr ("&Format")); - - m_upper_case_action - = add_action (m_edit_fmt_menu, tr ("&Uppercase Selection"), - SLOT (request_upper_case (bool))); - - m_lower_case_action - = add_action (m_edit_fmt_menu, tr ("&Lowercase Selection"), - SLOT (request_lower_case (bool))); - - m_edit_fmt_menu->addSeparator (); - - m_comment_selection_action - = add_action (m_edit_fmt_menu, tr ("&Comment"), - SLOT (request_comment_selected_text (bool))); - - m_uncomment_selection_action - = add_action (m_edit_fmt_menu, tr ("&Uncomment"), - SLOT (request_uncomment_selected_text (bool))); - - m_comment_var_selection_action - = add_action (m_edit_fmt_menu, tr ("Comment (Choosing String)"), - SLOT (request_comment_var_selected_text (bool))); - - m_edit_fmt_menu->addSeparator (); - - m_indent_selection_action - = add_action (m_edit_fmt_menu, tr ("&Indent Selection Rigidly"), - SLOT (request_indent_selected_text (bool))); - - m_unindent_selection_action - = add_action (m_edit_fmt_menu, tr ("&Unindent Selection Rigidly"), - SLOT (request_unindent_selected_text (bool))); - - 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))); - - m_edit_fmt_menu->addSeparator (); - - m_conv_eol_windows_action - = add_action (m_edit_fmt_menu, - tr ("Convert Line Endings to &Windows (CRLF)"), - SLOT (request_conv_eol_windows (bool))); - - m_conv_eol_unix_action - = add_action (m_edit_fmt_menu, tr ("Convert Line Endings to &Unix (LF)"), - SLOT (request_conv_eol_unix (bool))); - - m_conv_eol_mac_action - = add_action (m_edit_fmt_menu, - tr ("Convert Line Endings to Legacy &Mac (CR)"), - SLOT (request_conv_eol_mac (bool))); - - m_edit_nav_menu = m_edit_menu->addMenu (tr ("Navi&gation")); - - m_goto_line_action - = add_action (m_edit_nav_menu, tr ("Go &to Line..."), - SLOT (request_goto_line (bool))); - - m_edit_cmd_menu->addSeparator (); - - m_move_to_matching_brace - = add_action (m_edit_nav_menu, tr ("Move to Matching Brace"), - SLOT (request_move_match_brace (bool))); - - m_sel_to_matching_brace - = add_action (m_edit_nav_menu, tr ("Select to Matching Brace"), - SLOT (request_sel_match_brace (bool))); - - m_edit_nav_menu->addSeparator (); - - m_next_bookmark_action - = add_action (m_edit_nav_menu, tr ("&Next Bookmark"), - SLOT (request_next_bookmark (bool))); - - m_previous_bookmark_action - = add_action (m_edit_nav_menu, tr ("Pre&vious Bookmark"), - SLOT (request_previous_bookmark (bool))); - - m_toggle_bookmark_action - = add_action (m_edit_nav_menu, tr ("Toggle &Bookmark"), - SLOT (request_toggle_bookmark (bool))); - - m_remove_bookmark_action - = add_action (m_edit_nav_menu, tr ("&Remove All Bookmarks"), - SLOT (request_remove_bookmark (bool))); - - m_edit_menu->addSeparator (); - - m_preferences_action - = add_action (m_edit_menu, rmgr.icon ("preferences-system"), - tr ("&Preferences..."), - SLOT (request_preferences (bool))); - - m_styles_preferences_action - = add_action (m_edit_menu, rmgr.icon ("preferences-system"), - tr ("&Styles Preferences..."), - SLOT (request_styles_preferences (bool))); - - // view menu - - QMenu *view_menu = add_menu (m_menu_bar, tr ("&View")); - - m_view_editor_menu = view_menu->addMenu (tr ("&Editor")); - - m_show_linenum_action - = add_action (m_view_editor_menu, tr ("Show &Line Numbers"), - SLOT (show_line_numbers (bool))); - m_show_linenum_action->setCheckable (true); - - m_show_whitespace_action - = add_action (m_view_editor_menu, tr ("Show &Whitespace Characters"), - SLOT (show_white_space (bool))); - m_show_whitespace_action->setCheckable (true); - - m_show_eol_action - = add_action (m_view_editor_menu, tr ("Show Line &Endings"), - SLOT (show_eol_chars (bool))); - m_show_eol_action->setCheckable (true); - - m_show_indguide_action - = add_action (m_view_editor_menu, tr ("Show &Indentation Guides"), - SLOT (show_indent_guides (bool))); - m_show_indguide_action->setCheckable (true); - - m_show_longline_action - = add_action (m_view_editor_menu, tr ("Show Long Line &Marker"), - SLOT (show_long_line (bool))); - m_show_longline_action->setCheckable (true); - - m_view_editor_menu->addSeparator (); - - m_show_toolbar_action - = add_action (m_view_editor_menu, tr ("Show &Toolbar"), - SLOT (show_toolbar (bool))); - m_show_toolbar_action->setCheckable (true); - - m_show_statusbar_action - = add_action (m_view_editor_menu, tr ("Show &Statusbar"), - SLOT (show_statusbar (bool))); - m_show_statusbar_action->setCheckable (true); - - m_show_hscrollbar_action - = add_action (m_view_editor_menu, tr ("Show &Horizontal Scrollbar"), - SLOT (show_hscrollbar (bool))); - m_show_hscrollbar_action->setCheckable (true); - - view_menu->addSeparator (); - - m_zoom_in_action - = add_action (view_menu, rmgr.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))); - - m_zoom_normal_action - = add_action (view_menu, rmgr.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)), - m_tab_widget->get_tab_bar ()); - - m_menu_bar->addMenu (view_menu); - - // debug menu - - m_debug_menu = add_menu (m_menu_bar, tr ("&Debug")); - - m_toggle_breakpoint_action - = add_action (m_debug_menu, rmgr.icon ("bp-toggle"), - tr ("Toggle &Breakpoint"), - SLOT (request_toggle_breakpoint (bool))); - - m_next_breakpoint_action - = add_action (m_debug_menu, rmgr.icon ("bp-next"), - tr ("&Next Breakpoint"), - SLOT (request_next_breakpoint (bool))); - - m_previous_breakpoint_action - = add_action (m_debug_menu, rmgr.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"), - tr ("&Remove All Breakpoints"), - SLOT (request_remove_breakpoint (bool))); - - m_debug_menu->addSeparator (); - - // The other debug actions will be added by the main window. - - // run menu - - QMenu *_run_menu = add_menu (m_menu_bar, tr ("&Run")); - - m_run_action - = add_action (_run_menu, - rmgr.icon ("system-run"), - tr ("Save File and Run / Continue"), - SLOT (request_run_file (bool))); - - m_run_selection_action - = add_action (_run_menu, - tr ("Run &Selection"), - SLOT (request_context_run (bool))); - m_run_selection_action->setEnabled (false); - - // help menu - - QMenu *_help_menu = add_menu (m_menu_bar, tr ("&Help")); - - m_context_help_action - = add_action (_help_menu, - tr ("&Help on Keyword"), - SLOT (request_context_help (bool))); - - m_context_doc_action - = add_action (_help_menu, - tr ("&Documentation on Keyword"), - SLOT (request_context_doc (bool))); - - // tab navigation (no menu, only actions; slots in tab_bar) - - m_switch_left_tab_action - = add_action (nullptr, "", SLOT (switch_left_tab (void)), - m_tab_widget->get_tab_bar ()); - - m_switch_right_tab_action - = add_action (nullptr, "", SLOT (switch_right_tab (void)), - m_tab_widget->get_tab_bar ()); - - m_move_tab_left_action - = add_action (nullptr, "", SLOT (move_tab_left (void)), - m_tab_widget->get_tab_bar ()); - - m_move_tab_right_action - = add_action (nullptr, "", SLOT (move_tab_right (void)), - m_tab_widget->get_tab_bar ()); - - // toolbar - - // popdown menu with mru files - QToolButton *popdown_button = new QToolButton (); - popdown_button->setToolTip (tr ("Recent Files")); - popdown_button->setMenu (m_mru_file_menu); - popdown_button->setPopupMode (QToolButton::InstantPopup); - popdown_button->setArrowType (Qt::DownArrow); - popdown_button->setToolButtonStyle (Qt::ToolButtonTextOnly); - - // new and open actions are inserted later from main window - m_popdown_mru_action = m_tool_bar->addWidget (popdown_button); - m_tool_bar->addAction (m_save_action); - m_tool_bar->addAction (m_save_as_action); - m_tool_bar->addAction (m_print_action); - m_tool_bar->addSeparator (); - // m_undo_action: later via main window - m_tool_bar->addAction (m_redo_action); - m_tool_bar->addSeparator (); - m_tool_bar->addAction (m_cut_action); - // m_copy_action: later via the main window - // m_paste_action: later via the main window - m_tool_bar->addAction (m_find_action); - //m_tool_bar->addAction (m_find_next_action); - //m_tool_bar->addAction (m_find_previous_action); - m_tool_bar->addSeparator (); - m_tool_bar->addAction (m_run_action); - m_tool_bar->addSeparator (); - m_tool_bar->addAction (m_toggle_breakpoint_action); - m_tool_bar->addAction (m_previous_breakpoint_action); - m_tool_bar->addAction (m_next_breakpoint_action); - m_tool_bar->addAction (m_remove_all_breakpoints_action); - - // layout - QVBoxLayout *vbox_layout = new QVBoxLayout (); - vbox_layout->addWidget (m_menu_bar); - vbox_layout->addWidget (m_tool_bar); - vbox_layout->addWidget (m_tab_widget); - vbox_layout->setMargin (0); - vbox_layout->setSpacing (0); - editor_widget->setLayout (vbox_layout); - setWidget (editor_widget); - - // Create the basic context menu of the tab bar with editor actions. - // Actions for selecting an tab are added when the menu is activated. - tab_bar *bar = m_tab_widget->get_tab_bar (); - QMenu *ctx_men = bar->get_context_menu (); - ctx_men->addSeparator (); - ctx_men->addAction (m_close_action); - ctx_men->addAction (m_close_all_action); - ctx_men->addAction (m_close_others_action); - ctx_men->addSeparator (); - ctx_men->addAction (m_sort_tabs_action); - add_action (ctx_men, tr ("Copy Full File &Path"), - SLOT (copy_full_file_path (bool)), this); - - // signals - connect (m_mru_file_menu, &QMenu::triggered, - this, &file_editor::request_mru_open_file); - - mru_menu_update (); - - connect (m_tab_widget, &file_editor_tab_widget::tabCloseRequested, - this, &file_editor::handle_tab_close_request); - - connect (m_tab_widget, &file_editor_tab_widget::currentChanged, - this, &file_editor::active_tab_changed); - - resize (500, 400); - set_title (tr ("Editor")); - - check_actions (); -} - -// Slot when autocompletion list was cancelled -void file_editor::handle_autoc_cancelled (void) -{ - // List was cancelled but somehow still active and blocking the - // edit area from accepting shortcuts. Only after another keypress - // shortcuts and lists are working againnas expected. This is - // probably caused by qt bug https://bugreports.qt.io/browse/QTBUG-83720 - // Hack: Accept the list, which is hidden but still active - // and undo the text insertion, if any - - file_editor_tab *f = reset_focus (); - octave_qscintilla *qsci = f->qsci_edit_area (); - - int line, col; - qsci->getCursorPosition (&line, &col); - int l1 = qsci->lineLength (line); // Current line length - - // Accept autocompletion - qsci->SendScintilla (QsciScintillaBase::SCI_AUTOCCOMPLETE); - - // Was text inserted? If yes, undo - if (qsci->text (line).length () - l1) - qsci->undo (); -} - -file_editor_tab *file_editor::reset_focus (void) -{ - // Reset the focus of the tab and the related edit area - file_editor_tab *f - = static_cast (m_tab_widget->currentWidget ()); - emit fetab_set_focus (f); - return f; -} - -file_editor_tab * -file_editor::make_file_editor_tab (const QString& directory) -{ - file_editor_tab *f = new file_editor_tab (m_octave_qobj, directory); - - // signals from the qscintilla edit area - connect (f->qsci_edit_area (), &octave_qscintilla::status_update, - this, &file_editor::edit_status_update); - - connect (f->qsci_edit_area (), &octave_qscintilla::create_context_menu_signal, - this, &file_editor::create_context_menu); - - 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))); - - // signals from the qscintilla edit area - connect (this, &file_editor::enter_debug_mode_signal, - f->qsci_edit_area (), &octave_qscintilla::handle_enter_debug_mode); - - connect (this, &file_editor::exit_debug_mode_signal, - f->qsci_edit_area (), &octave_qscintilla::handle_exit_debug_mode); - - // Signals from the file editor_tab - connect (f, &file_editor_tab::autoc_closed, - this, &file_editor::reset_focus); - - connect (f, &file_editor_tab::file_name_changed, - this, &file_editor::handle_file_name_changed); - - connect (f, &file_editor_tab::editor_state_changed, - this, &file_editor::handle_editor_state_changed); - - connect (f, &file_editor_tab::tab_remove_request, - this, &file_editor::handle_tab_remove_request); - - connect (f, &file_editor_tab::editor_check_conflict_save, - this, &file_editor::check_conflict_save); - - connect (f, &file_editor_tab::mru_add_file, - this, &file_editor::handle_mru_add_file); - - connect (f, &file_editor_tab::request_open_file, - this, [=] (const QString& fname, const QString& encoding) { request_open_file (fname, encoding); }); - - connect (f, &file_editor_tab::edit_area_changed, - this, &file_editor::edit_area_changed); - - connect (f, &file_editor_tab::set_focus_editor_signal, - this, &file_editor::set_focus); - - // 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); }); - - connect (this, &file_editor::fetab_change_request, - f, &file_editor_tab::change_editor_state); - - connect (this, QOverload::of (&file_editor::fetab_save_file), - f, QOverload::of (&file_editor_tab::save_file)); - - // Signals from the file_editor trivial operations - connect (this, &file_editor::fetab_recover_from_exit, - f, &file_editor_tab::recover_from_exit); - - connect (this, &file_editor::fetab_set_directory, - f, &file_editor_tab::set_current_directory); - - connect (this, &file_editor::fetab_zoom_in, - f, &file_editor_tab::zoom_in); - connect (this, &file_editor::fetab_zoom_out, - f, &file_editor_tab::zoom_out); - connect (this, &file_editor::fetab_zoom_normal, - f, &file_editor_tab::zoom_normal); - - connect (this, &file_editor::fetab_context_help, - f, &file_editor_tab::context_help); - - connect (this, &file_editor::fetab_context_edit, - f, &file_editor_tab::context_edit); - - connect (this, QOverload::of (&file_editor::fetab_save_file), - f, QOverload::of (&file_editor_tab::save_file)); - - connect (this, &file_editor::fetab_save_file_as, - f, QOverload::of (&file_editor_tab::save_file_as)); - - connect (this, &file_editor::fetab_print_file, - f, &file_editor_tab::print_file); - - connect (this, &file_editor::fetab_run_file, - f, &file_editor_tab::run_file); - - connect (this, &file_editor::fetab_context_run, - f, &file_editor_tab::context_run); - - connect (this, &file_editor::fetab_toggle_bookmark, - f, &file_editor_tab::toggle_bookmark); - - connect (this, &file_editor::fetab_next_bookmark, - f, &file_editor_tab::next_bookmark); - - connect (this, &file_editor::fetab_previous_bookmark, - f, &file_editor_tab::previous_bookmark); - - connect (this, &file_editor::fetab_remove_bookmark, - f, &file_editor_tab::remove_bookmark); - - connect (this, &file_editor::fetab_toggle_breakpoint, - f, &file_editor_tab::toggle_breakpoint); - - connect (this, &file_editor::fetab_next_breakpoint, - f, &file_editor_tab::next_breakpoint); - - connect (this, &file_editor::fetab_previous_breakpoint, - f, &file_editor_tab::previous_breakpoint); - - connect (this, &file_editor::fetab_remove_all_breakpoints, - f, &file_editor_tab::remove_all_breakpoints); - - connect (this, &file_editor::fetab_scintilla_command, - f, &file_editor_tab::scintilla_command); - - connect (this, &file_editor::fetab_comment_selected_text, - f, &file_editor_tab::comment_selected_text); - - connect (this, &file_editor::fetab_uncomment_selected_text, - f, &file_editor_tab::uncomment_selected_text); - - connect (this, &file_editor::fetab_indent_selected_text, - f, &file_editor_tab::indent_selected_text); - - connect (this, &file_editor::fetab_unindent_selected_text, - f, &file_editor_tab::unindent_selected_text); - - connect (this, &file_editor::fetab_smart_indent_line_or_selected_text, - f, &file_editor_tab::smart_indent_line_or_selected_text); - - connect (this, &file_editor::fetab_convert_eol, - f, &file_editor_tab::convert_eol); - - connect (this, &file_editor::fetab_goto_line, - f, &file_editor_tab::goto_line); - - connect (this, &file_editor::fetab_move_match_brace, - f, &file_editor_tab::move_match_brace); - - connect (this, &file_editor::fetab_completion, - f, &file_editor_tab::show_auto_completion); - - connect (this, &file_editor::fetab_set_focus, - f, &file_editor_tab::set_focus); - - connect (this, &file_editor::fetab_insert_debugger_pointer, - f, &file_editor_tab::insert_debugger_pointer); - - connect (this, &file_editor::fetab_delete_debugger_pointer, - f, &file_editor_tab::delete_debugger_pointer); - - connect (this, &file_editor::fetab_do_breakpoint_marker, - f, &file_editor_tab::do_breakpoint_marker); - - connect (this, &file_editor::update_gui_lexer_signal, - f, &file_editor_tab::update_lexer_settings); - - // Convert other signals from the edit area and tab to editor signals. - - connect (f->qsci_edit_area (), &octave_qscintilla::execute_command_in_terminal_signal, - this, &file_editor::execute_command_in_terminal_signal); - - connect (f->qsci_edit_area (), &octave_qscintilla::focus_console_after_command_signal, - this, &file_editor::focus_console_after_command_signal); - - connect (f, &file_editor_tab::run_file_signal, - this, &file_editor::run_file_signal); - - connect (f, &file_editor_tab::edit_mfile_request, - this, &file_editor::edit_mfile_request); - - connect (f, &file_editor_tab::debug_quit_signal, - this, &file_editor::debug_quit_signal); - - // Any interpreter_event signal from a file_editor_tab_widget is - // handled the same as for the parent main_window object. - - connect (f, QOverload::of (&file_editor_tab::interpreter_event), - this, QOverload::of (&file_editor::interpreter_event)); - - connect (f, QOverload::of (&file_editor_tab::interpreter_event), - this, QOverload::of (&file_editor::interpreter_event)); - - return f; -} - -void file_editor::add_file_editor_tab (file_editor_tab *f, const QString& fn, - int index) -{ - if (index == -1) - m_tab_widget->addTab (f, fn); - else - m_tab_widget->insertTab (index, f, fn); - - m_tab_widget->setCurrentWidget (f); - - check_actions (); -} - -void file_editor::mru_menu_update (void) -{ - int num_files = qMin (m_mru_files.size (), int (MaxMRUFiles)); - - // configure and show active actions of mru-menu - for (int i = 0; i < num_files; ++i) - { - QString text = QString ("&%1 %2"). - arg ((i+1) % int (MaxMRUFiles)).arg (m_mru_files.at (i)); - m_mru_file_actions[i]->setText (text); - - QStringList action_data; - action_data << m_mru_files.at (i) << m_mru_files_encodings.at (i); - m_mru_file_actions[i]->setData (action_data); - - m_mru_file_actions[i]->setVisible (true); - } - - // hide unused mru-menu entries - for (int j = num_files; j < MaxMRUFiles; ++j) - m_mru_file_actions[j]->setVisible (false); - - // delete entries in string-list beyond MaxMRUFiles - while (m_mru_files.size () > MaxMRUFiles) - { - m_mru_files.removeLast (); - m_mru_files_encodings.removeLast (); - } - - // 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 (); -} - -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 ()) - { - // use the external editor interface for handling the call - emit request_open_file_external (file_name, line); - - if (line < 0 && ! file_name.isEmpty ()) - handle_mru_add_file (QFileInfo (file_name).canonicalFilePath (), - QString ()); - + else + reusing = true; + } + + // If was absent or modified, create a new tab. + if (! fileEditorTab) + fileEditorTab = make_file_editor_tab (); + + fileEditorTab->set_encoding (encoding); + QString result = fileEditorTab->load_file (openFileName); + if (result == "") + { + // Supply empty title then have the file_editor_tab update + // with full or short name. + if (! reusing) + add_file_editor_tab (fileEditorTab, "", index); + fileEditorTab->update_window_title (false); + // file already loaded, add file to mru list here + QFileInfo file_info = QFileInfo (openFileName); + handle_mru_add_file (file_info.canonicalFilePath (), + encoding); + + if (line > 0) + { + if (insert) + emit fetab_goto_line (fileEditorTab, line); + + if (debug_pointer) + emit fetab_insert_debugger_pointer (fileEditorTab, + line); + if (breakpoint_marker) + emit fetab_do_breakpoint_marker (insert, fileEditorTab, + line, cond); + } + } + else + { + if (! reusing) + { + delete fileEditorTab; + fileEditorTab = nullptr; + } + + if (QFile::exists (openFileName)) + { + // File not readable: + // create a NonModal message about error. + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Critical, + tr ("Octave Editor"), + tr ("Could not open file\n%1\nfor read: %2."). + arg (openFileName).arg (result), + QMessageBox::Ok, this); + + msgBox->setWindowModality (Qt::NonModal); + msgBox->setAttribute (Qt::WA_DeleteOnClose); + msgBox->show (); + } + else + { + // File does not exist, should it be created? + bool create_file = true; + QMessageBox *msgBox; + + if (! settings.bool_value (ed_create_new_file)) + { + msgBox = new QMessageBox (QMessageBox::Question, + tr ("Octave Editor"), + tr ("File\n%1\ndoes not exist. " + "Do you want to create it?").arg (openFileName), + QMessageBox::NoButton, nullptr); + QPushButton *create_button = + msgBox->addButton (tr ("Create"), QMessageBox::YesRole); + msgBox->addButton (tr ("Cancel"), QMessageBox::RejectRole); + msgBox->setDefaultButton (create_button); + msgBox->exec (); + + QAbstractButton *clicked_button = msgBox->clickedButton (); + if (clicked_button != create_button) + create_file = false; + + delete msgBox; + } + + if (create_file) + { + // create the file and call the editor again + QFile file (openFileName); + if (! file.open (QIODevice::WriteOnly)) + { + // error opening the file + msgBox = new QMessageBox (QMessageBox::Critical, + tr ("Octave Editor"), + tr ("Could not open file\n%1\nfor write: %2."). + arg (openFileName).arg (file.errorString ()), + QMessageBox::Ok, this); + + msgBox->setWindowModality (Qt::NonModal); + msgBox->setAttribute (Qt::WA_DeleteOnClose); + msgBox->show (); + } + else + { + file.close (); + request_open_file (openFileName); + } + } + } + } + + if (! bookmarks.isEmpty ()) + { + // Restore bookmarks + for (const auto& bms : bookmarks.split (',')) + { + int bm = bms.toInt (); + if (fileEditorTab) + fileEditorTab->qsci_edit_area ()->markerAdd (bm, marker::bookmark); + } + } + + if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ())) + { + // update breakpoint pointers, really show editor + // and the current editor tab + if (fileEditorTab) + fileEditorTab->update_breakpoints (); + activate (); + emit file_loaded_signal (); + } + } + } + } + + void file_editor::request_preferences (bool) + { + emit request_settings_dialog ("editor"); + } + + void file_editor::request_styles_preferences (bool) + { + emit request_settings_dialog ("editor_styles"); + } + + void file_editor::show_line_numbers (bool) + { + toggle_preference (ed_show_line_numbers); + } + + void file_editor::show_white_space (bool) + { + toggle_preference (ed_show_white_space); + } + + void file_editor::show_eol_chars (bool) + { + toggle_preference (ed_show_eol_chars); + } + + void file_editor::show_indent_guides (bool) + { + toggle_preference (ed_show_indent_guides); + } + + void file_editor::show_long_line (bool) + { + toggle_preference (ed_long_line_marker); + } + + void file_editor::show_toolbar (bool) + { + toggle_preference (ed_show_toolbar); + } + + void file_editor::show_statusbar (bool) + { + toggle_preference (ed_show_edit_status_bar); + } + + void file_editor::show_hscrollbar (bool) + { + toggle_preference (ed_show_hscroll_bar); + } + + void file_editor::zoom_in (bool) + { + emit fetab_zoom_in (m_tab_widget->currentWidget ()); + } + + void file_editor::zoom_out (bool) + { + emit fetab_zoom_out (m_tab_widget->currentWidget ()); + } + + void file_editor::zoom_normal (bool) + { + emit fetab_zoom_normal (m_tab_widget->currentWidget ()); + } + + void file_editor::create_context_menu (QMenu *menu) + { + // remove all standard actions from scintilla + QList all_actions = menu->actions (); + + for (auto *a : all_actions) + menu->removeAction (a); + + // add editor's actions with icons and customized shortcuts + menu->addAction (m_cut_action); + menu->addAction (m_copy_action); + menu->addAction (m_paste_action); + menu->addSeparator (); + menu->addAction (m_selectall_action); + menu->addSeparator (); + menu->addAction (m_find_files_action); + menu->addAction (m_find_action); + menu->addAction (m_find_next_action); + menu->addAction (m_find_previous_action); + menu->addSeparator (); + menu->addMenu (m_edit_cmd_menu); + menu->addMenu (m_edit_fmt_menu); + menu->addMenu (m_edit_nav_menu); + menu->addSeparator (); + menu->addAction (m_run_selection_action); + } + + void file_editor::edit_status_update (bool undo, bool redo) + { + if (m_undo_action) + m_undo_action->setEnabled (undo); + m_redo_action->setEnabled (redo); + } + + // handler for the close event + void file_editor::closeEvent (QCloseEvent *e) + { + gui_settings settings; + + if (settings.bool_value (ed_hiding_closes_files)) + { + if (check_closing ()) + { + // All tabs are closed without cancelling, + // store closing state for restoring session when shown again. + // Editor is closing when session data is stored in preferences + m_closed = true; + e->ignore (); + } + else + { + e->ignore (); + return; + } + } + else + e->accept (); + + octave_dock_widget::closeEvent (e); + } + + void file_editor::dragEnterEvent (QDragEnterEvent *e) + { + if (e->mimeData ()->hasUrls ()) + { + e->acceptProposedAction (); + } + } + + void file_editor::dropEvent (QDropEvent *e) + { + if (e->mimeData ()->hasUrls ()) + { + for (const auto& url : e->mimeData ()->urls ()) + request_open_file (url.toLocalFile ()); + } + } + + 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? + + main_window *w = dynamic_cast (parentWidget ()); + + if (w) + { + QList w_list = w->tabifiedDockWidgets (this); + QDockWidget *console = + static_cast (w->get_dock_widget_list ().at (0)); + + for (int i = 0; i < w_list.count (); i++) + { + if (w_list.at (i) == console) + return true; + } + } + + return false; + } + + void file_editor::construct () + { + QWidget *editor_widget = new QWidget (this); + + // FIXME: what was the intended purpose of this unused variable? + // QStyle *editor_style = QApplication::style (); + + // Menu bar: do not set it native, required in macOS and Ubuntu Unity (Qt5) + // for a visible menu bar in the editor widget. This property is ignored + // on other platforms. + m_menu_bar = new QMenuBar (editor_widget); + m_menu_bar->setNativeMenuBar (false); + + m_tool_bar = new QToolBar (editor_widget); + m_tool_bar->setMovable (true); + + m_tab_widget = new file_editor_tab_widget (editor_widget, this); + + // the mru-list and an empty array of actions + + 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 ()) + { + // encodings don't have the same count -> do not use them! + m_mru_files_encodings = QStringList (); + for (int i = 0; i < m_mru_files.count (); i++) + m_mru_files_encodings << QString (); + } + + for (int i = 0; i < MaxMRUFiles; ++i) + { + m_mru_file_actions[i] = new QAction (this); + m_mru_file_actions[i]->setVisible (false); + } + + // menu bar + + // file menu + + m_fileMenu = add_menu (m_menu_bar, tr ("&File")); + + // new and open menus are inserted later by the main window + m_mru_file_menu = new QMenu (tr ("&Recent Editor Files"), m_fileMenu); + for (int i = 0; i < MaxMRUFiles; ++i) + m_mru_file_menu->addAction (m_mru_file_actions[i]); + m_fileMenu->addMenu (m_mru_file_menu); + + m_fileMenu->addSeparator (); + + m_edit_function_action + = add_action (m_fileMenu, + tr ("&Edit Function"), + SLOT (request_context_edit (bool))); + + m_fileMenu->addSeparator (); + + m_save_action + = add_action (m_fileMenu, settings.icon ("document-save"), + tr ("&Save File"), SLOT (request_save_file (bool))); + + m_save_as_action + = 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, settings.icon ("window-close", false), + tr ("&Close"), SLOT (request_close_file (bool))); + + m_close_all_action + = 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, 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, settings.icon ("document-print"), + tr ("Print..."), SLOT (request_print_file (bool))); + + // edit menu (undo, copy, paste and select all later via main window) + + m_edit_menu = add_menu (m_menu_bar, tr ("&Edit")); + + m_redo_action + = 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, settings.icon ("edit-cut"), + tr ("Cu&t"), SLOT (request_cut (bool))); + m_cut_action->setEnabled (false); + + m_find_action + = add_action (m_edit_menu, settings.icon ("edit-find-replace"), + tr ("&Find and Replace..."), SLOT (request_find (bool))); + + m_find_next_action + = add_action (m_edit_menu, tr ("Find &Next..."), + SLOT (request_find_next (bool))); + + m_find_previous_action + = add_action (m_edit_menu, tr ("Find &Previous..."), + SLOT (request_find_previous (bool))); + + m_edit_menu->addSeparator (); + + m_edit_cmd_menu = m_edit_menu->addMenu (tr ("&Commands")); + + m_delete_line_action + = add_action (m_edit_cmd_menu, tr ("Delete Line"), + SLOT (request_delete_line (bool))); + + m_copy_line_action + = add_action (m_edit_cmd_menu, tr ("Copy Line"), + SLOT (request_copy_line (bool))); + + m_cut_line_action + = add_action (m_edit_cmd_menu, tr ("Cut Line"), + SLOT (request_cut_line (bool))); + + m_edit_cmd_menu->addSeparator (); + + m_delete_start_word_action + = add_action (m_edit_cmd_menu, tr ("Delete to Start of Word"), + SLOT (request_delete_start_word (bool))); + + m_delete_end_word_action + = add_action (m_edit_cmd_menu, tr ("Delete to End of Word"), + SLOT (request_delete_end_word (bool))); + + m_delete_start_line_action + = add_action (m_edit_cmd_menu, tr ("Delete to Start of Line"), + SLOT (request_delete_start_line (bool))); + + m_delete_end_line_action + = add_action (m_edit_cmd_menu, tr ("Delete to End of Line"), + SLOT (request_delete_end_line (bool))); + + m_edit_cmd_menu->addSeparator (); + + m_duplicate_selection_action + = add_action (m_edit_cmd_menu, tr ("Duplicate Selection/Line"), + SLOT (request_duplicate_selection (bool))); + + m_transpose_line_action + = add_action (m_edit_cmd_menu, tr ("Transpose Line"), + SLOT (request_transpose_line (bool))); + + m_edit_cmd_menu->addSeparator (); + + m_completion_action + = add_action (m_edit_cmd_menu, tr ("&Show Completion List"), + SLOT (request_completion (bool))); + + m_edit_fmt_menu = m_edit_menu->addMenu (tr ("&Format")); + + m_upper_case_action + = add_action (m_edit_fmt_menu, tr ("&Uppercase Selection"), + SLOT (request_upper_case (bool))); + + m_lower_case_action + = add_action (m_edit_fmt_menu, tr ("&Lowercase Selection"), + SLOT (request_lower_case (bool))); + + m_edit_fmt_menu->addSeparator (); + + m_comment_selection_action + = add_action (m_edit_fmt_menu, tr ("&Comment"), + SLOT (request_comment_selected_text (bool))); + + m_uncomment_selection_action + = add_action (m_edit_fmt_menu, tr ("&Uncomment"), + SLOT (request_uncomment_selected_text (bool))); + + m_comment_var_selection_action + = add_action (m_edit_fmt_menu, tr ("Comment (Choosing String)"), + SLOT (request_comment_var_selected_text (bool))); + + m_edit_fmt_menu->addSeparator (); + + m_indent_selection_action + = add_action (m_edit_fmt_menu, tr ("&Indent Selection Rigidly"), + SLOT (request_indent_selected_text (bool))); + + m_unindent_selection_action + = add_action (m_edit_fmt_menu, tr ("&Unindent Selection Rigidly"), + SLOT (request_unindent_selected_text (bool))); + + m_smart_indent_line_or_selection_action + = add_action (m_edit_fmt_menu, tr ("Indent Code"), + SLOT (request_smart_indent_line_or_selected_text ())); + + m_edit_fmt_menu->addSeparator (); + + m_conv_eol_windows_action + = add_action (m_edit_fmt_menu, + tr ("Convert Line Endings to &Windows (CRLF)"), + SLOT (request_conv_eol_windows (bool))); + + m_conv_eol_unix_action + = add_action (m_edit_fmt_menu, tr ("Convert Line Endings to &Unix (LF)"), + SLOT (request_conv_eol_unix (bool))); + + m_conv_eol_mac_action + = add_action (m_edit_fmt_menu, + tr ("Convert Line Endings to Legacy &Mac (CR)"), + SLOT (request_conv_eol_mac (bool))); + + m_edit_nav_menu = m_edit_menu->addMenu (tr ("Navi&gation")); + + m_goto_line_action + = add_action (m_edit_nav_menu, tr ("Go &to Line..."), + SLOT (request_goto_line (bool))); + + m_edit_cmd_menu->addSeparator (); + + m_move_to_matching_brace + = add_action (m_edit_nav_menu, tr ("Move to Matching Brace"), + SLOT (request_move_match_brace (bool))); + + m_sel_to_matching_brace + = add_action (m_edit_nav_menu, tr ("Select to Matching Brace"), + SLOT (request_sel_match_brace (bool))); + + m_edit_nav_menu->addSeparator (); + + m_next_bookmark_action + = add_action (m_edit_nav_menu, tr ("&Next Bookmark"), + SLOT (request_next_bookmark (bool))); + + m_previous_bookmark_action + = add_action (m_edit_nav_menu, tr ("Pre&vious Bookmark"), + SLOT (request_previous_bookmark (bool))); + + m_toggle_bookmark_action + = add_action (m_edit_nav_menu, tr ("Toggle &Bookmark"), + SLOT (request_toggle_bookmark (bool))); + + m_remove_bookmark_action + = add_action (m_edit_nav_menu, tr ("&Remove All Bookmarks"), + SLOT (request_remove_bookmark (bool))); + + m_edit_menu->addSeparator (); + + m_preferences_action + = add_action (m_edit_menu, settings.icon ("preferences-system"), + tr ("&Preferences..."), + SLOT (request_preferences (bool))); + + m_styles_preferences_action + = add_action (m_edit_menu, settings.icon ("preferences-system"), + tr ("&Styles Preferences..."), + SLOT (request_styles_preferences (bool))); + + // view menu + + QMenu *view_menu = add_menu (m_menu_bar, tr ("&View")); + + m_view_editor_menu = view_menu->addMenu (tr ("&Editor")); + + m_show_linenum_action + = add_action (m_view_editor_menu, tr ("Show &Line Numbers"), + SLOT (show_line_numbers (bool))); + m_show_linenum_action->setCheckable (true); + + m_show_whitespace_action + = add_action (m_view_editor_menu, tr ("Show &Whitespace Characters"), + SLOT (show_white_space (bool))); + m_show_whitespace_action->setCheckable (true); + + m_show_eol_action + = add_action (m_view_editor_menu, tr ("Show Line &Endings"), + SLOT (show_eol_chars (bool))); + m_show_eol_action->setCheckable (true); + + m_show_indguide_action + = add_action (m_view_editor_menu, tr ("Show &Indentation Guides"), + SLOT (show_indent_guides (bool))); + m_show_indguide_action->setCheckable (true); + + m_show_longline_action + = add_action (m_view_editor_menu, tr ("Show Long Line &Marker"), + SLOT (show_long_line (bool))); + m_show_longline_action->setCheckable (true); + + m_view_editor_menu->addSeparator (); + + m_show_toolbar_action + = add_action (m_view_editor_menu, tr ("Show &Toolbar"), + SLOT (show_toolbar (bool))); + m_show_toolbar_action->setCheckable (true); + + m_show_statusbar_action + = add_action (m_view_editor_menu, tr ("Show &Statusbar"), + SLOT (show_statusbar (bool))); + m_show_statusbar_action->setCheckable (true); + + m_show_hscrollbar_action + = add_action (m_view_editor_menu, tr ("Show &Horizontal Scrollbar"), + SLOT (show_hscrollbar (bool))); + m_show_hscrollbar_action->setCheckable (true); + + view_menu->addSeparator (); + + m_zoom_in_action + = add_action (view_menu, settings.icon ("view-zoom-in"), tr ("Zoom &In"), + SLOT (zoom_in (bool))); + + m_zoom_out_action + = add_action (view_menu, settings.icon ("view-zoom-out"), + tr ("Zoom &Out"), SLOT (zoom_out (bool))); + + m_zoom_normal_action + = 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 ()), + m_tab_widget->get_tab_bar ()); + + m_menu_bar->addMenu (view_menu); + + // debug menu + + m_debug_menu = add_menu (m_menu_bar, tr ("&Debug")); + + m_toggle_breakpoint_action + = 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, settings.icon ("bp-next"), + tr ("&Next Breakpoint"), + SLOT (request_next_breakpoint (bool))); + + m_previous_breakpoint_action + = 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, settings.icon ("bp-rm-all"), + tr ("&Remove All Breakpoints"), + SLOT (request_remove_breakpoint (bool))); + + m_debug_menu->addSeparator (); + + // The other debug actions will be added by the main window. + + // run menu + + QMenu *_run_menu = add_menu (m_menu_bar, tr ("&Run")); + + m_run_action + = add_action (_run_menu, + settings.icon ("system-run"), + tr ("Save File and Run / Continue"), + SLOT (request_run_file (bool))); + + m_run_selection_action + = add_action (_run_menu, + tr ("Run &Selection"), + SLOT (request_context_run (bool))); + m_run_selection_action->setEnabled (false); + + // help menu + + QMenu *_help_menu = add_menu (m_menu_bar, tr ("&Help")); + + m_context_help_action + = add_action (_help_menu, + tr ("&Help on Keyword"), + SLOT (request_context_help (bool))); + + m_context_doc_action + = add_action (_help_menu, + tr ("&Documentation on Keyword"), + SLOT (request_context_doc (bool))); + + // tab navigation (no menu, only actions; slots in tab_bar) + + m_switch_left_tab_action + = 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 ()), + m_tab_widget->get_tab_bar ()); + + m_move_tab_left_action + = 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 ()), + m_tab_widget->get_tab_bar ()); + + // toolbar + + // popdown menu with mru files + QToolButton *popdown_button = new QToolButton (); + popdown_button->setToolTip (tr ("Recent Files")); + popdown_button->setMenu (m_mru_file_menu); + popdown_button->setPopupMode (QToolButton::InstantPopup); + popdown_button->setArrowType (Qt::DownArrow); + popdown_button->setToolButtonStyle (Qt::ToolButtonTextOnly); + + // new and open actions are inserted later from main window + m_popdown_mru_action = m_tool_bar->addWidget (popdown_button); + m_tool_bar->addAction (m_save_action); + m_tool_bar->addAction (m_save_as_action); + m_tool_bar->addAction (m_print_action); + m_tool_bar->addSeparator (); + // m_undo_action: later via main window + m_tool_bar->addAction (m_redo_action); + m_tool_bar->addSeparator (); + m_tool_bar->addAction (m_cut_action); + // m_copy_action: later via the main window + // m_paste_action: later via the main window + m_tool_bar->addAction (m_find_action); + //m_tool_bar->addAction (m_find_next_action); + //m_tool_bar->addAction (m_find_previous_action); + m_tool_bar->addSeparator (); + m_tool_bar->addAction (m_run_action); + m_tool_bar->addSeparator (); + m_tool_bar->addAction (m_toggle_breakpoint_action); + m_tool_bar->addAction (m_previous_breakpoint_action); + m_tool_bar->addAction (m_next_breakpoint_action); + m_tool_bar->addAction (m_remove_all_breakpoints_action); + + // layout + QVBoxLayout *vbox_layout = new QVBoxLayout (); + vbox_layout->addWidget (m_menu_bar); + vbox_layout->addWidget (m_tool_bar); + vbox_layout->addWidget (m_tab_widget); + vbox_layout->setMargin (0); + vbox_layout->setSpacing (0); + editor_widget->setLayout (vbox_layout); + setWidget (editor_widget); + + // Create the basic context menu of the tab bar with editor actions. + // Actions for selecting an tab are added when the menu is activated. + tab_bar *bar = m_tab_widget->get_tab_bar (); + QMenu *ctx_men = bar->get_context_menu (); + ctx_men->addSeparator (); + ctx_men->addAction (m_close_action); + ctx_men->addAction (m_close_all_action); + ctx_men->addAction (m_close_others_action); + ctx_men->addSeparator (); + ctx_men->addAction (m_sort_tabs_action); + add_action (ctx_men, tr ("Copy Full File &Path"), + SLOT (copy_full_file_path (bool)), this); + + // signals + connect (m_mru_file_menu, &QMenu::triggered, + this, &file_editor::request_mru_open_file); + + mru_menu_update (); + + connect (m_tab_widget, &file_editor_tab_widget::tabCloseRequested, + this, &file_editor::handle_tab_close_request); + + connect (m_tab_widget, &file_editor_tab_widget::currentChanged, + this, &file_editor::active_tab_changed); + + resize (500, 400); + set_title (tr ("Editor")); + + check_actions (); + } + + // Slot when autocompletion list was cancelled + 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 + // shortcuts and lists are working againnas expected. This is + // probably caused by qt bug https://bugreports.qt.io/browse/QTBUG-83720 + // Hack: Accept the list, which is hidden but still active + // and undo the text insertion, if any + + file_editor_tab *f = reset_focus (); + octave_qscintilla *qsci = f->qsci_edit_area (); + + int line, col; + qsci->getCursorPosition (&line, &col); + int l1 = qsci->lineLength (line); // Current line length + + // Accept autocompletion + qsci->SendScintilla (QsciScintillaBase::SCI_AUTOCCOMPLETE); + + // Was text inserted? If yes, undo + if (qsci->text (line).length () - l1) + qsci->undo (); + } + + file_editor_tab *file_editor::reset_focus () + { + // Reset the focus of the tab and the related edit area + file_editor_tab *f + = static_cast (m_tab_widget->currentWidget ()); + emit fetab_set_focus (f); + return f; + } + + file_editor_tab * + file_editor::make_file_editor_tab (const QString& 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); + + connect (f->qsci_edit_area (), &octave_qscintilla::create_context_menu_signal, + this, &file_editor::create_context_menu); + + connect (f->qsci_edit_area (), + SIGNAL (SCN_AUTOCCOMPLETED (const char *, int, int, int)), + 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, + f->qsci_edit_area (), &octave_qscintilla::handle_enter_debug_mode); + + connect (this, &file_editor::exit_debug_mode_signal, + f->qsci_edit_area (), &octave_qscintilla::handle_exit_debug_mode); + + // Signals from the file editor_tab + connect (f, &file_editor_tab::autoc_closed, + this, &file_editor::reset_focus); + + connect (f, &file_editor_tab::file_name_changed, + this, &file_editor::handle_file_name_changed); + + connect (f, &file_editor_tab::editor_state_changed, + this, &file_editor::handle_editor_state_changed); + + connect (f, &file_editor_tab::tab_remove_request, + this, &file_editor::handle_tab_remove_request); + + connect (f, &file_editor_tab::editor_check_conflict_save, + this, &file_editor::check_conflict_save); + + connect (f, &file_editor_tab::mru_add_file, + this, &file_editor::handle_mru_add_file); + + connect (f, &file_editor_tab::request_open_file, + this, [=] (const QString& fname, const QString& encoding) { request_open_file (fname, encoding); }); + + connect (f, &file_editor_tab::edit_area_changed, + this, &file_editor::edit_area_changed); + + connect (f, &file_editor_tab::set_focus_editor_signal, + this, &file_editor::set_focus); + + // Signals from the file_editor or main-win non-trivial operations + connect (this, &file_editor::fetab_settings_changed, + f, [=] () { f->notice_settings (); }); + + connect (this, &file_editor::fetab_change_request, + f, &file_editor_tab::change_editor_state); + + connect (this, QOverload::of (&file_editor::fetab_save_file), + f, QOverload::of (&file_editor_tab::save_file)); + + // Signals from the file_editor trivial operations + connect (this, &file_editor::fetab_recover_from_exit, + f, &file_editor_tab::recover_from_exit); + + connect (this, &file_editor::fetab_set_directory, + f, &file_editor_tab::set_current_directory); + + connect (this, &file_editor::fetab_zoom_in, + f, &file_editor_tab::zoom_in); + connect (this, &file_editor::fetab_zoom_out, + f, &file_editor_tab::zoom_out); + connect (this, &file_editor::fetab_zoom_normal, + f, &file_editor_tab::zoom_normal); + + connect (this, &file_editor::fetab_context_help, + f, &file_editor_tab::context_help); + + connect (this, &file_editor::fetab_context_edit, + f, &file_editor_tab::context_edit); + + connect (this, QOverload::of (&file_editor::fetab_save_file), + f, QOverload::of (&file_editor_tab::save_file)); + + connect (this, &file_editor::fetab_save_file_as, + f, QOverload::of (&file_editor_tab::save_file_as)); + + connect (this, &file_editor::fetab_print_file, + f, &file_editor_tab::print_file); + + connect (this, &file_editor::fetab_run_file, + f, &file_editor_tab::run_file); + + connect (this, &file_editor::fetab_context_run, + f, &file_editor_tab::context_run); + + connect (this, &file_editor::fetab_toggle_bookmark, + f, &file_editor_tab::toggle_bookmark); + + connect (this, &file_editor::fetab_next_bookmark, + f, &file_editor_tab::next_bookmark); + + connect (this, &file_editor::fetab_previous_bookmark, + f, &file_editor_tab::previous_bookmark); + + connect (this, &file_editor::fetab_remove_bookmark, + f, &file_editor_tab::remove_bookmark); + + connect (this, &file_editor::fetab_toggle_breakpoint, + f, &file_editor_tab::toggle_breakpoint); + + connect (this, &file_editor::fetab_next_breakpoint, + f, &file_editor_tab::next_breakpoint); + + connect (this, &file_editor::fetab_previous_breakpoint, + f, &file_editor_tab::previous_breakpoint); + + connect (this, &file_editor::fetab_remove_all_breakpoints, + f, &file_editor_tab::remove_all_breakpoints); + + connect (this, &file_editor::fetab_scintilla_command, + f, &file_editor_tab::scintilla_command); + + connect (this, &file_editor::fetab_comment_selected_text, + f, &file_editor_tab::comment_selected_text); + + connect (this, &file_editor::fetab_uncomment_selected_text, + f, &file_editor_tab::uncomment_selected_text); + + connect (this, &file_editor::fetab_indent_selected_text, + f, &file_editor_tab::indent_selected_text); + + connect (this, &file_editor::fetab_unindent_selected_text, + f, &file_editor_tab::unindent_selected_text); + + connect (this, &file_editor::fetab_smart_indent_line_or_selected_text, + f, &file_editor_tab::smart_indent_line_or_selected_text); + + connect (this, &file_editor::fetab_convert_eol, + f, &file_editor_tab::convert_eol); + + connect (this, &file_editor::fetab_goto_line, + f, &file_editor_tab::goto_line); + + connect (this, &file_editor::fetab_move_match_brace, + f, &file_editor_tab::move_match_brace); + + connect (this, &file_editor::fetab_completion, + f, &file_editor_tab::show_auto_completion); + + connect (this, &file_editor::fetab_set_focus, + f, &file_editor_tab::set_focus); + + connect (this, &file_editor::fetab_insert_debugger_pointer, + f, &file_editor_tab::insert_debugger_pointer); + + connect (this, &file_editor::fetab_delete_debugger_pointer, + f, &file_editor_tab::delete_debugger_pointer); + + connect (this, &file_editor::fetab_do_breakpoint_marker, + f, &file_editor_tab::do_breakpoint_marker); + + connect (this, &file_editor::update_gui_lexer_signal, + f, &file_editor_tab::update_lexer_settings); + + // Convert other signals from the edit area and tab to editor signals. + + connect (f->qsci_edit_area (), &octave_qscintilla::execute_command_in_terminal_signal, + this, &file_editor::execute_command_in_terminal_signal); + + connect (f->qsci_edit_area (), &octave_qscintilla::focus_console_after_command_signal, + this, &file_editor::focus_console_after_command_signal); + + connect (f, &file_editor_tab::run_file_signal, + this, &file_editor::run_file_signal); + + connect (f, &file_editor_tab::edit_mfile_request, + this, &file_editor::edit_mfile_request); + + connect (f, &file_editor_tab::debug_quit_signal, + this, &file_editor::debug_quit_signal); + + // Any interpreter_event signal from a file_editor_tab_widget is + // handled the same as for the parent main_window object. + + connect (f, QOverload::of (&file_editor_tab::interpreter_event), + this, QOverload::of (&file_editor::interpreter_event)); + + connect (f, QOverload::of (&file_editor_tab::interpreter_event), + this, QOverload::of (&file_editor::interpreter_event)); + + return f; + } + + void file_editor::add_file_editor_tab (file_editor_tab *f, const QString& fn, + int index) + { + if (index == -1) + m_tab_widget->addTab (f, fn); + else + m_tab_widget->insertTab (index, f, fn); + + m_tab_widget->setCurrentWidget (f); + + check_actions (); + } + + void file_editor::mru_menu_update () + { + int num_files = qMin (m_mru_files.size (), int (MaxMRUFiles)); + + // configure and show active actions of mru-menu + for (int i = 0; i < num_files; ++i) + { + QString text = QString ("&%1 %2"). + arg ((i+1) % int (MaxMRUFiles)).arg (m_mru_files.at (i)); + m_mru_file_actions[i]->setText (text); + + QStringList action_data; + action_data << m_mru_files.at (i) << m_mru_files_encodings.at (i); + m_mru_file_actions[i]->setData (action_data); + + m_mru_file_actions[i]->setVisible (true); + } + + // hide unused mru-menu entries + for (int j = num_files; j < MaxMRUFiles; ++j) + m_mru_file_actions[j]->setVisible (false); + + // delete entries in string-list beyond MaxMRUFiles + while (m_mru_files.size () > MaxMRUFiles) + { + m_mru_files.removeLast (); + m_mru_files_encodings.removeLast (); + } + + // save actual mru-list in settings + + 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. + + 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); + + if (line < 0 && ! file_name.isEmpty ()) + handle_mru_add_file (QFileInfo (file_name).canonicalFilePath (), + QString ()); + + return true; + } + + return false; + } + + void file_editor::toggle_preference (const gui_pref& preference) + { + 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 + void file_editor::handle_dir_remove (const QString& old_name, + const QString& new_name) + { + QDir old_dir (old_name); + removed_file_data f_data; + + std::list editor_tab_lst = m_tab_widget->tab_list (); + + for (auto editor_tab : editor_tab_lst) + { + QString file_name = editor_tab->file_name (); + + if (file_name.isEmpty ()) + continue; // Nothing to do, no valid file name + + // Get abs. file path and its path relative to the removed directory + QString rel_path_to_file = old_dir.relativeFilePath (file_name); + QString abs_path_to_file = old_dir.absoluteFilePath (file_name); + + // Test whether the file is located within the directory that will + // be removed. For this, two conditions must be met: + // 1. The path of the file rel. to the dir is not equal to the + // its absolute one. + // If both are equal, then there is no relative path and removed + // directory and file are on different drives (e.g. on windows) + // 2. The (real) relative path does not start with "../", i.e., + // the file can be reached from the directory by descending only + if ((rel_path_to_file != abs_path_to_file) + && (rel_path_to_file.left (3) != QString ("../"))) + { + // The currently considered file is included in the + // removed/renamed diectory: remeber it + if (editor_tab) + { + editor_tab->enable_file_watcher (false); + f_data.editor_tab = editor_tab; + + // Add the new file path and the encoding for later reloading + // if new_name is given + if (! new_name.isEmpty ()) + { + QDir new_dir (new_name); + QString append_to_new_dir; + if (new_dir.exists ()) + { + // The new directory already exists (movefile was used). + // This means, we have to add the name (not the path) + // of the old dir and the relative path to the file + // to new dir. + append_to_new_dir + = old_dir.dirName () + "/" + rel_path_to_file; + } + else + append_to_new_dir = rel_path_to_file; + + f_data.new_file_name + = new_dir.absoluteFilePath (append_to_new_dir); + } + else + f_data.new_file_name = ""; // no new name, just removing this file + + // Store data in list for later reloading + m_tmp_closed_files << f_data; + } + } + } + } + + bool file_editor::editor_tab_has_focus () + { + QWidget *foc_w = focusWidget (); + if (foc_w && foc_w->inherits ("octave::octave_qscintilla")) return true; - } - - return false; -} - -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); -} - -// Function for closing the files in a removed directory -void file_editor::handle_dir_remove (const QString& old_name, - const QString& new_name) -{ - QDir old_dir (old_name); - removed_file_data f_data; - - std::list editor_tab_lst = m_tab_widget->tab_list (); - - for (auto editor_tab : editor_tab_lst) - { - QString file_name = editor_tab->file_name (); - - if (file_name.isEmpty ()) - continue; // Nothing to do, no valid file name - - // Get abs. file path and its path relative to the removed directory - QString rel_path_to_file = old_dir.relativeFilePath (file_name); - QString abs_path_to_file = old_dir.absoluteFilePath (file_name); - - // Test whether the file is located within the directory that will - // be removed. For this, two conditions must be met: - // 1. The path of the file rel. to the dir is not equal to the - // its absolute one. - // If both are equal, then there is no relative path and removed - // directory and file are on different drives (e.g. on windows) - // 2. The (real) relative path does not start with "../", i.e., - // the file can be reached from the directory by descending only - if ((rel_path_to_file != abs_path_to_file) - && (rel_path_to_file.left (3) != QString ("../"))) - { - // The currently considered file is included in the - // removed/renamed diectory: remeber it - if (editor_tab) - { - editor_tab->enable_file_watcher (false); - f_data.editor_tab = editor_tab; - - // Add the new file path and the encoding for later reloading - // if new_name is given - if (! new_name.isEmpty ()) - { - QDir new_dir (new_name); - QString append_to_new_dir; - if (new_dir.exists ()) - { - // The new directory already exists (movefile was used). - // This means, we have to add the name (not the path) - // of the old dir and the relative path to the file - // to new dir. - append_to_new_dir - = old_dir.dirName () + "/" + rel_path_to_file; - } - else - append_to_new_dir = rel_path_to_file; - - f_data.new_file_name - = new_dir.absoluteFilePath (append_to_new_dir); - } - else - f_data.new_file_name = ""; // no new name, just removing this file - - // Store data in list for later reloading - m_tmp_closed_files << f_data; - } - } - } -} - -bool file_editor::editor_tab_has_focus (void) -{ - QWidget *foc_w = focusWidget (); - if (foc_w && foc_w->inherits ("octave::octave_qscintilla")) - return true; - return false; -} - -// Check whether this file is already open in the editor. -file_editor_tab *file_editor::find_tab_widget (const QString& file) -{ - std::string std_file = file.toStdString (); - - std::list fe_tab_lst = m_tab_widget->tab_list (); - - for (auto fe_tab : fe_tab_lst) - { - QString tab_file = fe_tab->file_name (); - - // We check file == tab_file because - // - // same_file ("", "") - // - // is false - - if (same_file (std_file, tab_file.toStdString ()) || file == tab_file) - return fe_tab; - } - - return nullptr; -} - -QAction * file_editor::add_action (QMenu *menu, const QString& text, - const char *member, - QWidget *receiver) -{ - return add_action (menu, QIcon (), text, member, receiver); -} - -QAction * file_editor::add_action (QMenu *menu, const QIcon& icon, - const QString& text, const char *member, - QWidget *receiver) -{ - QAction *a; - QWidget *r = this; - - if (receiver != nullptr) - r = receiver; - - if (menu) - a = menu->addAction (icon, text, r, member); - else - { - a = new QAction (this); - connect (a, SIGNAL (triggered ()), r, member); - } - - addAction (a); // important for shortcut context - a->setShortcutContext (Qt::WidgetWithChildrenShortcut); - - return a; -} - -QMenu* file_editor::add_menu (QMenuBar *p, QString name) -{ - QMenu *menu = p->addMenu (name); - - QString base_name = name; // get a copy - // replace intended '&' ("&&") by a temp. string - base_name.replace ("&&", "___octave_amp_replacement___"); - // remove single '&' (shortcut) - base_name.remove ("&"); - // restore intended '&' - base_name.replace ("___octave_amp_replacement___", "&&"); - - // remember names with and without shortcut - m_hash_menu_text[menu] = QStringList () << name << base_name; - - return menu; -} + return false; + } + + // Check whether this file is already open in the editor. + file_editor_tab *file_editor::find_tab_widget (const QString& file) + { + std::string std_file = file.toStdString (); + + std::list fe_tab_lst = m_tab_widget->tab_list (); + + for (auto fe_tab : fe_tab_lst) + { + QString tab_file = fe_tab->file_name (); + + // We check file == tab_file because + // + // same_file ("", "") + // + // is false + + if (same_file (std_file, tab_file.toStdString ()) || file == tab_file) + return fe_tab; + } + + return nullptr; + } + + QAction * file_editor::add_action (QMenu *menu, const QString& text, + const char *member, + QWidget *receiver) + { + return add_action (menu, QIcon (), text, member, receiver); + } + + QAction * file_editor::add_action (QMenu *menu, const QIcon& icon, + const QString& text, const char *member, + QWidget *receiver) + { + QAction *a; + QWidget *r = this; + + if (receiver != nullptr) + r = receiver; + + if (menu) + a = menu->addAction (icon, text, r, member); + else + { + a = new QAction (this); + connect (a, SIGNAL (triggered ()), r, member); + } + + addAction (a); // important for shortcut context + a->setShortcutContext (Qt::WidgetWithChildrenShortcut); + + return a; + } + + QMenu* file_editor::add_menu (QMenuBar *p, QString name) + { + QMenu *menu = p->addMenu (name); + + QString base_name = name; // get a copy + // replace intended '&' ("&&") by a temp. string + base_name.replace ("&&", "___octave_amp_replacement___"); + // remove single '&' (shortcut) + base_name.remove ("&"); + // restore intended '&' + base_name.replace ("___octave_amp_replacement___", "&&"); + + // remember names with and without shortcut + m_hash_menu_text[menu] = QStringList () << name << base_name; + + return menu; + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/file-editor.h Mon Jan 30 18:36:03 2023 +0100 @@ -46,71 +46,71 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class file_editor; - -// subclassed QTabWidget for using custom tabbar - -class file_editor_tab_widget : public QTabWidget -{ - Q_OBJECT + class base_qobject; + class file_editor; -public: - - file_editor_tab_widget (QWidget *p, file_editor *fe); + // subclassed QTabWidget for using custom tabbar - ~file_editor_tab_widget (void) = default; - - tab_bar * get_tab_bar (void) const; - - std::list tab_list (void) const; -}; + class file_editor_tab_widget : public QTabWidget + { + Q_OBJECT -// the class for the file editor + public: -class file_editor : public file_editor_interface -{ - Q_OBJECT - -public: + file_editor_tab_widget (QWidget *p, file_editor *fe); - // struct that allows to sort with respect to the tab index - struct session_data - { - int index; - int line; - QString file_name; - QString new_file_name; - QString encoding; - QString bookmarks; + ~file_editor_tab_widget () = default; - bool operator < (const session_data& other) const - { - return index < other.index; - } + tab_bar * get_tab_bar () const; + + std::list tab_list () const; }; - struct removed_file_data + // the class for the file editor + + class file_editor : public file_editor_interface { - file_editor_tab *editor_tab; - QString new_file_name; - }; + Q_OBJECT + + public: - file_editor (QWidget *p, base_qobject& oct_qobj); - - ~file_editor (void) = default; + // struct that allows to sort with respect to the tab index + struct session_data + { + int index; + int line; + QString file_name; + QString new_file_name; + QString encoding; + QString bookmarks; - QMenu * get_mru_menu (void) { return m_mru_file_menu; } + bool operator < (const session_data& other) const + { + return index < other.index; + } + }; - QMenu * debug_menu (void) { return m_debug_menu; } + struct removed_file_data + { + file_editor_tab *editor_tab; + QString new_file_name; + }; - QToolBar * toolbar (void) { return m_tool_bar; } + file_editor (QWidget *p); - QMenuBar * menubar (void) { return m_menu_bar; } + ~file_editor () = default; + + QMenu * get_mru_menu () { return m_mru_file_menu; } + + QMenu * debug_menu () { return m_debug_menu; } - void insert_global_actions (QList); + QToolBar * toolbar () { return m_tool_bar; } + + QMenuBar * menubar () { return m_menu_bar; } - enum shared_actions_idx + void insert_global_actions (QList); + + enum shared_actions_idx { NEW_SCRIPT_ACTION = 0, NEW_FUNCTION_ACTION, @@ -122,381 +122,383 @@ SELECTALL_ACTION }; - void check_actions (void); - void empty_script (bool startup, bool visible); - void restore_session (gui_settings *settings); + void check_actions (); + void empty_script (bool startup, bool visible); + void restore_session (); -signals: + signals: - void fetab_settings_changed (const gui_settings *settings); - 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, - bool remove_on_success); - // No fetab_open, functionality in editor - // No fetab_new, functionality in editor - void fetab_context_help (const QWidget *ID, bool); - void fetab_context_edit (const QWidget *ID); - void fetab_save_file (const QWidget *ID); - void fetab_save_file_as (const QWidget *ID); - void fetab_print_file (const QWidget *ID); - void fetab_run_file (const QWidget *ID, bool step_into = false); - void fetab_context_run (const QWidget *ID); - void fetab_toggle_bookmark (const QWidget *ID); - void fetab_next_bookmark (const QWidget *ID); - void fetab_previous_bookmark (const QWidget *ID); - void fetab_remove_bookmark (const QWidget *ID); - void fetab_toggle_breakpoint (const QWidget *ID); - void fetab_next_breakpoint (const QWidget *ID); - void fetab_previous_breakpoint (const QWidget *ID); - void fetab_remove_all_breakpoints (const QWidget *ID); - void fetab_comment_selected_text (const QWidget *ID, bool); - void fetab_uncomment_selected_text (const QWidget *ID); - void fetab_indent_selected_text (const QWidget *ID); - void fetab_unindent_selected_text (const QWidget *ID); - void fetab_smart_indent_line_or_selected_text (const QWidget *ID); - void fetab_convert_eol (const QWidget *ID, QsciScintilla::EolMode eol_mode); - void fetab_goto_line (const QWidget *ID, int line = -1); - void fetab_move_match_brace (const QWidget *ID, bool select); - void fetab_completion (const QWidget *); - void fetab_insert_debugger_pointer (const QWidget *ID, int line = -1); - void fetab_delete_debugger_pointer (const QWidget *ID, int line = -1); - void fetab_do_breakpoint_marker (bool insert, const QWidget *ID, - int line = -1, const QString& = ""); - void fetab_set_focus (const QWidget *ID); - void fetab_scintilla_command (const QWidget *ID, unsigned int sci_msg); + 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, + bool remove_on_success); + // No fetab_open, functionality in editor + // No fetab_new, functionality in editor + void fetab_context_help (const QWidget *ID, bool); + void fetab_context_edit (const QWidget *ID); + void fetab_save_file (const QWidget *ID); + void fetab_save_file_as (const QWidget *ID); + void fetab_print_file (const QWidget *ID); + void fetab_run_file (const QWidget *ID, bool step_into = false); + void fetab_context_run (const QWidget *ID); + void fetab_toggle_bookmark (const QWidget *ID); + void fetab_next_bookmark (const QWidget *ID); + void fetab_previous_bookmark (const QWidget *ID); + void fetab_remove_bookmark (const QWidget *ID); + void fetab_toggle_breakpoint (const QWidget *ID); + void fetab_next_breakpoint (const QWidget *ID); + void fetab_previous_breakpoint (const QWidget *ID); + void fetab_remove_all_breakpoints (const QWidget *ID); + void fetab_comment_selected_text (const QWidget *ID, bool); + void fetab_uncomment_selected_text (const QWidget *ID); + void fetab_indent_selected_text (const QWidget *ID); + void fetab_unindent_selected_text (const QWidget *ID); + void fetab_smart_indent_line_or_selected_text (const QWidget *ID); + void fetab_convert_eol (const QWidget *ID, QsciScintilla::EolMode eol_mode); + void fetab_goto_line (const QWidget *ID, int line = -1); + void fetab_move_match_brace (const QWidget *ID, bool select); + void fetab_completion (const QWidget *); + void fetab_insert_debugger_pointer (const QWidget *ID, int line = -1); + void fetab_delete_debugger_pointer (const QWidget *ID, int line = -1); + void fetab_do_breakpoint_marker (bool insert, const QWidget *ID, + int line = -1, const QString& = ""); + void fetab_set_focus (const QWidget *ID); + void fetab_scintilla_command (const QWidget *ID, unsigned int sci_msg); - void fetab_zoom_in (const QWidget *ID); - void fetab_zoom_out (const QWidget *ID); - void fetab_zoom_normal (const QWidget *ID); + void fetab_zoom_in (const QWidget *ID); + void fetab_zoom_out (const QWidget *ID); + void fetab_zoom_normal (const QWidget *ID); - void fetab_set_directory (const QString& dir); - void fetab_recover_from_exit (void); + void fetab_set_directory (const QString& dir); + void fetab_recover_from_exit (); - void edit_area_changed (octave_qscintilla *edit_area); + 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 request_settings_dialog (const QString&); + void request_open_file_external (const QString& file_name, int line); + void file_loaded_signal (); - void editor_tabs_changed_signal (bool, bool); - void request_dbcont_signal (void); + void editor_tabs_changed_signal (bool, bool); + 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 run_file_signal (const QFileInfo&); - void edit_mfile_request (const QString&, const QString&, const QString&, int); - void debug_quit_signal (void); + void update_gui_lexer_signal (bool); + void execute_command_in_terminal_signal (const QString&); + 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 (); -public slots: + void show_symbol_tooltip_signal (const QPoint&, const QString&); + + public slots: - void activate (void); - 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 activate (); + void set_focus (QWidget *fet); + void enable_menu_shortcuts (bool); + 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); - void request_close_all_files (bool); - void request_close_other_files (bool); - void copy_full_file_path (bool); - void request_mru_open_file (QAction *action); - void request_print_file (bool); + void request_new_file (const QString& commands); + void request_close_file (bool); + void request_close_all_files (bool); + void request_close_other_files (bool); + void copy_full_file_path (bool); + void request_mru_open_file (QAction *action); + void request_print_file (bool); - void request_redo (bool); - void request_cut (bool); - void request_context_help (bool); - void request_context_doc (bool); - void request_context_edit (bool); - void request_save_file (bool); - void request_save_file_as (bool); - void request_run_file (bool); - void request_step_into_file (); - void request_context_run (bool); - void request_toggle_bookmark (bool); - void request_next_bookmark (bool); - void request_previous_bookmark (bool); - void request_remove_bookmark (bool); + void request_redo (bool); + void request_cut (bool); + void request_context_help (bool); + void request_context_doc (bool); + void request_context_edit (bool); + void request_save_file (bool); + void request_save_file_as (bool); + void request_run_file (bool); + void request_step_into_file (); + void request_context_run (bool); + void request_toggle_bookmark (bool); + void request_next_bookmark (bool); + void request_previous_bookmark (bool); + void request_remove_bookmark (bool); - void request_move_match_brace (bool); - void request_sel_match_brace (bool); - void request_toggle_breakpoint (bool); - void request_next_breakpoint (bool); - void request_previous_breakpoint (bool); - void request_remove_breakpoint (bool); + void request_move_match_brace (bool); + void request_sel_match_brace (bool); + void request_toggle_breakpoint (bool); + void request_next_breakpoint (bool); + void request_previous_breakpoint (bool); + void request_remove_breakpoint (bool); - void request_delete_start_word (bool); - void request_delete_end_word (bool); - void request_delete_start_line (bool); - void request_delete_end_line (bool); - void request_delete_line (bool); - void request_copy_line (bool); - void request_cut_line (bool); - void request_duplicate_selection (bool); - void request_transpose_line (bool); + void request_delete_start_word (bool); + void request_delete_end_word (bool); + void request_delete_start_line (bool); + void request_delete_end_line (bool); + void request_delete_line (bool); + void request_copy_line (bool); + void request_cut_line (bool); + void request_duplicate_selection (bool); + void request_transpose_line (bool); - void request_comment_selected_text (bool); - void request_uncomment_selected_text (bool); - void request_comment_var_selected_text (bool); + void request_comment_selected_text (bool); + void request_uncomment_selected_text (bool); + void request_comment_var_selected_text (bool); - void request_upper_case (bool); - 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_conv_eol_windows (bool); - void request_conv_eol_unix (bool); - void request_conv_eol_mac (bool); - - void request_find (bool); - void request_find_next (bool); - void request_find_previous (bool); + void request_upper_case (bool); + 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 request_conv_eol_windows (bool); + void request_conv_eol_unix (bool); + void request_conv_eol_mac (bool); - void request_goto_line (bool); - void request_completion (bool); + void request_find (bool); + void request_find_next (bool); + void request_find_previous (bool); + + void request_goto_line (bool); + void request_completion (bool); - void handle_file_name_changed (const QString& fileName, - const QString& toolTip, - bool modified); - void handle_tab_close_request (int index); - void handle_tab_remove_request (void); - void active_tab_changed (int index); - void handle_editor_state_changed (bool enableCopy, bool is_octave_file, - bool is_modified); - void handle_mru_add_file (const QString& file_name, const QString& encoding); - void check_conflict_save (const QString& fileName, bool remove_on_success); + void handle_file_name_changed (const QString& fileName, + const QString& toolTip, + bool modified); + void handle_tab_close_request (int index); + 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); + void handle_mru_add_file (const QString& file_name, const QString& encoding); + void check_conflict_save (const QString& fileName, bool remove_on_success); - void handle_insert_debugger_pointer_request (const QString& file, int line); - void handle_delete_debugger_pointer_request (const QString& file, int line); - void handle_update_breakpoint_marker_request (bool insert, - const QString& file, int line, - const QString& cond); - - void handle_edit_file_request (const QString& file); + void handle_insert_debugger_pointer_request (const QString& file, int line); + void handle_delete_debugger_pointer_request (const QString& file, int line); + void handle_update_breakpoint_marker_request (bool insert, + const QString& file, int line, + const QString& cond); - void handle_file_remove (const QString&, const QString&); - void handle_file_renamed (bool load_new = true); + void handle_edit_file_request (const QString& file); - // Tells the editor to react on changed settings. - void notice_settings (const gui_settings *settings); + void handle_file_remove (const QString&, const QString&); + void handle_file_renamed (bool load_new = true); - void set_shortcuts (void); + // Tells the editor to react on changed settings. + void notice_settings (); - void handle_visibility (bool visible); + void set_shortcuts (); - void update_octave_directory (const QString& dir); + void handle_visibility (bool visible); - void toplevel_change (bool toplevel); + void update_octave_directory (const QString& dir); - void handle_autoc_cancelled (void); + void toplevel_change (bool toplevel); - file_editor_tab * reset_focus (void); + void handle_autoc_cancelled (); -protected slots: + file_editor_tab * reset_focus (); + + protected slots: - void copyClipboard (void); - void pasteClipboard (void); - void selectAll (void); - void do_undo (void); - -private slots: + void copyClipboard (); + void pasteClipboard (); + void selectAll (); + void do_undo (); - void request_open_file (const QString& fileName, - const QString& encoding = QString (), - int line = -1, bool debug_pointer = false, - bool breakpoint_marker = false, bool insert = true, - const QString& cond = "", int index = -1, - const QString& bookmarks = QString ()); - void request_preferences (bool); - void request_styles_preferences (bool); + private slots: + + void request_open_file (const QString& fileName, + const QString& encoding = QString (), + int line = -1, bool debug_pointer = false, + bool breakpoint_marker = false, bool insert = true, + const QString& cond = "", int index = -1, + const QString& bookmarks = QString ()); + void request_preferences (bool); + void request_styles_preferences (bool); - void show_line_numbers (bool); - void show_white_space (bool); - void show_eol_chars (bool); - void show_indent_guides (bool); - void show_long_line (bool); - void show_toolbar (bool); - void show_statusbar (bool); - void show_hscrollbar (bool); - void zoom_in (bool); - void zoom_out (bool); - void zoom_normal (bool); + void show_line_numbers (bool); + void show_white_space (bool); + void show_eol_chars (bool); + void show_indent_guides (bool); + void show_long_line (bool); + void show_toolbar (bool); + void show_statusbar (bool); + void show_hscrollbar (bool); + void zoom_in (bool); + void zoom_out (bool); + void zoom_normal (bool); - void create_context_menu (QMenu *); - void edit_status_update (bool, bool); + void create_context_menu (QMenu *); + void edit_status_update (bool, bool); -protected: + protected: - void closeEvent (QCloseEvent *event); - void dragEnterEvent (QDragEnterEvent *event); - void dropEvent (QDropEvent *event); - void focusInEvent (QFocusEvent *e); + void closeEvent (QCloseEvent *event); + void dragEnterEvent (QDragEnterEvent *event); + void dropEvent (QDropEvent *event); + void focusInEvent (QFocusEvent *e); -private: + private: - file_editor_tab * make_file_editor_tab (const QString& directory = ""); + file_editor_tab * make_file_editor_tab (const QString& directory = ""); - bool is_editor_console_tabbed (void); - void construct (void); - void add_file_editor_tab (file_editor_tab *f, const QString& fn, - int index = -1); - void mru_menu_update (void); - bool call_custom_editor (const QString& file_name = QString (), int line = -1); + 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 (); + bool call_custom_editor (const QString& file_name = QString (), int line = -1); - void toggle_preference (const gui_pref& preference); + void toggle_preference (const gui_pref& preference); - void handle_dir_remove (const QString& old_name, const QString& new_name); + 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, - const char *member, QWidget *receiver = nullptr); - QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text, - const char *member, QWidget *receiver = nullptr); + file_editor_tab * find_tab_widget (const QString& openFileName); + QAction * add_action (QMenu *menu, const QString& text, + const char *member, QWidget *receiver = nullptr); + QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text, + const char *member, QWidget *receiver = nullptr); - QMenu * add_menu (QMenuBar *p, QString text); + QMenu * add_menu (QMenuBar *p, QString text); - int m_number_of_tabs; - QHash m_hash_menu_text; + int m_number_of_tabs; + QHash m_hash_menu_text; - QString m_ced; + QString m_ced; - QMenuBar *m_menu_bar; - QToolBar *m_tool_bar; - QMenu *m_debug_menu; + QMenuBar *m_menu_bar; + QToolBar *m_tool_bar; + QMenu *m_debug_menu; - QAction *m_new_action; - QAction *m_new_function_action; - QAction *m_open_action; + QAction *m_new_action; + QAction *m_new_function_action; + QAction *m_open_action; - QAction *m_upper_case_action; - QAction *m_lower_case_action; - QAction *m_comment_selection_action; - QAction *m_comment_var_selection_action; - QAction *m_uncomment_selection_action; - QAction *m_indent_selection_action; - QAction *m_unindent_selection_action; - QAction *m_smart_indent_line_or_selection_action; - QAction *m_conv_eol_windows_action; - QAction *m_conv_eol_unix_action; - QAction *m_conv_eol_mac_action; + QAction *m_upper_case_action; + QAction *m_lower_case_action; + QAction *m_comment_selection_action; + QAction *m_comment_var_selection_action; + QAction *m_uncomment_selection_action; + QAction *m_indent_selection_action; + QAction *m_unindent_selection_action; + QAction *m_smart_indent_line_or_selection_action; + QAction *m_conv_eol_windows_action; + QAction *m_conv_eol_unix_action; + QAction *m_conv_eol_mac_action; - QAction *m_copy_action; - QAction *m_cut_action; - QAction *m_paste_action; - QAction *m_selectall_action; - QAction *m_context_help_action; - QAction *m_context_doc_action; + QAction *m_copy_action; + QAction *m_cut_action; + QAction *m_paste_action; + QAction *m_selectall_action; + QAction *m_context_help_action; + QAction *m_context_doc_action; - QAction *m_show_linenum_action; - QAction *m_show_whitespace_action; - QAction *m_show_eol_action; - QAction *m_show_indguide_action; - QAction *m_show_longline_action; - QAction *m_show_toolbar_action; - QAction *m_show_statusbar_action; - QAction *m_show_hscrollbar_action; - QAction *m_zoom_in_action; - QAction *m_zoom_out_action; - QAction *m_zoom_normal_action; + QAction *m_show_linenum_action; + QAction *m_show_whitespace_action; + QAction *m_show_eol_action; + QAction *m_show_indguide_action; + QAction *m_show_longline_action; + QAction *m_show_toolbar_action; + QAction *m_show_statusbar_action; + QAction *m_show_hscrollbar_action; + QAction *m_zoom_in_action; + QAction *m_zoom_out_action; + QAction *m_zoom_normal_action; - QAction *m_delete_start_word_action; - QAction *m_delete_end_word_action; - QAction *m_delete_start_line_action; - QAction *m_delete_end_line_action; - QAction *m_delete_line_action; - QAction *m_copy_line_action; - QAction *m_cut_line_action; - QAction *m_duplicate_selection_action; - QAction *m_transpose_line_action; + QAction *m_delete_start_word_action; + QAction *m_delete_end_word_action; + QAction *m_delete_start_line_action; + QAction *m_delete_end_line_action; + QAction *m_delete_line_action; + QAction *m_copy_line_action; + QAction *m_cut_line_action; + QAction *m_duplicate_selection_action; + QAction *m_transpose_line_action; - QAction *m_find_action; - QAction *m_find_next_action; - QAction *m_find_previous_action; - QAction *m_find_files_action; - QAction *m_goto_line_action; - QAction *m_completion_action; + QAction *m_find_action; + QAction *m_find_next_action; + QAction *m_find_previous_action; + QAction *m_find_files_action; + QAction *m_goto_line_action; + QAction *m_completion_action; - QAction *m_move_to_matching_brace; - QAction *m_sel_to_matching_brace; - QAction *m_next_bookmark_action; - QAction *m_previous_bookmark_action; - QAction *m_toggle_bookmark_action; - QAction *m_remove_bookmark_action; + QAction *m_move_to_matching_brace; + QAction *m_sel_to_matching_brace; + QAction *m_next_bookmark_action; + QAction *m_previous_bookmark_action; + QAction *m_toggle_bookmark_action; + QAction *m_remove_bookmark_action; - QAction *m_print_action; - QAction *m_run_action; - QAction *m_run_selection_action; + QAction *m_print_action; + QAction *m_run_action; + QAction *m_run_selection_action; - QAction *m_edit_function_action; - QAction *m_popdown_mru_action; - QAction *m_save_action; - QAction *m_save_as_action; - QAction *m_close_action; - QAction *m_close_all_action; - QAction *m_close_others_action; + QAction *m_edit_function_action; + QAction *m_popdown_mru_action; + QAction *m_save_action; + QAction *m_save_as_action; + QAction *m_close_action; + QAction *m_close_all_action; + QAction *m_close_others_action; - QAction *m_redo_action; - QAction *m_undo_action; + QAction *m_redo_action; + QAction *m_undo_action; - QAction *m_preferences_action; - QAction *m_styles_preferences_action; + QAction *m_preferences_action; + QAction *m_styles_preferences_action; - QAction *m_switch_left_tab_action; - QAction *m_switch_right_tab_action; - QAction *m_move_tab_left_action; - QAction *m_move_tab_right_action; - QAction *m_sort_tabs_action; + QAction *m_switch_left_tab_action; + QAction *m_switch_right_tab_action; + QAction *m_move_tab_left_action; + QAction *m_move_tab_right_action; + QAction *m_sort_tabs_action; - QAction *m_toggle_breakpoint_action; - QAction *m_next_breakpoint_action; - QAction *m_previous_breakpoint_action; - QAction *m_remove_all_breakpoints_action; + QAction *m_toggle_breakpoint_action; + QAction *m_next_breakpoint_action; + QAction *m_previous_breakpoint_action; + QAction *m_remove_all_breakpoints_action; - bool m_copy_action_enabled; - bool m_undo_action_enabled; - bool m_is_octave_file; - bool m_current_tab_modified; + bool m_copy_action_enabled; + bool m_undo_action_enabled; + bool m_is_octave_file; + bool m_current_tab_modified; - QMenu *m_edit_menu; - QMenu *m_edit_cmd_menu; - QMenu *m_edit_fmt_menu; - QMenu *m_edit_nav_menu; - QMenu *m_fileMenu; - QMenu *m_view_editor_menu; + QMenu *m_edit_menu; + QMenu *m_edit_cmd_menu; + QMenu *m_edit_fmt_menu; + QMenu *m_edit_nav_menu; + QMenu *m_fileMenu; + QMenu *m_view_editor_menu; - file_editor_tab_widget *m_tab_widget; + file_editor_tab_widget *m_tab_widget; - int m_marker_breakpoint; + int m_marker_breakpoint; - bool m_closing_canceled; - bool m_closed; - bool m_no_focus; - bool m_editor_ready; + bool m_closing_canceled; + bool m_closed; + bool m_no_focus; + bool m_editor_ready; - enum { MaxMRUFiles = 10 }; - QMenu *m_mru_file_menu; - QAction *m_mru_file_actions[MaxMRUFiles]; - QStringList m_mru_files; - QStringList m_mru_files_encodings; + enum { MaxMRUFiles = 10 }; + QMenu *m_mru_file_menu; + QAction *m_mru_file_actions[MaxMRUFiles]; + QStringList m_mru_files; + QStringList m_mru_files_encodings; - QPointer m_find_dialog; + QPointer m_find_dialog; - // List of data on temporarily closed files for later reloading. - QList m_tmp_closed_files; -}; + // List of data on temporarily closed files for later reloading. + QList m_tmp_closed_files; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/find-dialog.cc --- a/libgui/src/m-editor/find-dialog.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/find-dialog.cc Mon Jan 30 18:36:03 2023 +0100 @@ -83,590 +83,585 @@ #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) -{ - setWindowTitle (tr ("Editor: Find and Replace")); + 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")); - m_search_label = new QLabel (tr ("Find &what:")); - m_search_line_edit = new QComboBox (this); - m_search_line_edit->setToolTip (tr ("Enter text to search for")); - m_search_line_edit->setEditable (true); - m_search_line_edit->setMaxCount (m_mru_length); - m_search_line_edit->completer ()->setCaseSensitivity (Qt::CaseSensitive); - m_search_label->setBuddy (m_search_line_edit); + m_search_label = new QLabel (tr ("Find &what:")); + m_search_line_edit = new QComboBox (this); + m_search_line_edit->setToolTip (tr ("Enter text to search for")); + m_search_line_edit->setEditable (true); + m_search_line_edit->setMaxCount (m_mru_length); + m_search_line_edit->completer ()->setCaseSensitivity (Qt::CaseSensitive); + m_search_label->setBuddy (m_search_line_edit); - m_replace_label = new QLabel (tr ("Re&place with:")); - m_replace_line_edit = new QComboBox (this); - m_replace_line_edit->setToolTip (tr ("Enter new text replacing search hits")); - m_replace_line_edit->setEditable (true); - m_replace_line_edit->setMaxCount (m_mru_length); - m_replace_line_edit->completer ()->setCaseSensitivity (Qt::CaseSensitive); - m_replace_label->setBuddy (m_replace_line_edit); + m_replace_label = new QLabel (tr ("Re&place with:")); + m_replace_line_edit = new QComboBox (this); + m_replace_line_edit->setToolTip (tr ("Enter new text replacing search hits")); + m_replace_line_edit->setEditable (true); + m_replace_line_edit->setMaxCount (m_mru_length); + 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")); - m_wrap_check_box = new QCheckBox (tr ("&Wrap while searching")); - m_wrap_check_box->setChecked (true); - m_find_next_button = new QPushButton (tr ("&Find Next")); - m_find_prev_button = new QPushButton (tr ("Find &Previous")); - m_replace_button = new QPushButton (tr ("&Replace")); - m_replace_all_button = new QPushButton (tr ("Replace &All")); + m_case_check_box = new QCheckBox (tr ("Match &case")); + m_from_start_check_box = new QCheckBox (tr ("Search from &start")); + m_wrap_check_box = new QCheckBox (tr ("&Wrap while searching")); + m_wrap_check_box->setChecked (true); + m_find_next_button = new QPushButton (tr ("&Find Next")); + m_find_prev_button = new QPushButton (tr ("Find &Previous")); + m_replace_button = new QPushButton (tr ("&Replace")); + m_replace_all_button = new QPushButton (tr ("Replace &All")); - m_more_button = new QPushButton (tr ("&More...")); - m_more_button->setCheckable (true); - m_more_button->setAutoDefault (false); + m_more_button = new QPushButton (tr ("&More...")); + m_more_button->setCheckable (true); + m_more_button->setAutoDefault (false); - m_button_box = new QDialogButtonBox (Qt::Vertical); - m_button_box->addButton (m_find_next_button, QDialogButtonBox::ActionRole); - m_button_box->addButton (m_find_prev_button, QDialogButtonBox::ActionRole); - m_button_box->addButton (m_replace_button, QDialogButtonBox::ActionRole); - m_button_box->addButton (m_replace_all_button, QDialogButtonBox::ActionRole); - m_button_box->addButton (m_more_button, QDialogButtonBox::ActionRole); - m_button_box->addButton (QDialogButtonBox::Close); + m_button_box = new QDialogButtonBox (Qt::Vertical); + m_button_box->addButton (m_find_next_button, QDialogButtonBox::ActionRole); + m_button_box->addButton (m_find_prev_button, QDialogButtonBox::ActionRole); + m_button_box->addButton (m_replace_button, QDialogButtonBox::ActionRole); + m_button_box->addButton (m_replace_all_button, QDialogButtonBox::ActionRole); + m_button_box->addButton (m_more_button, QDialogButtonBox::ActionRole); + m_button_box->addButton (QDialogButtonBox::Close); - m_extension = new QWidget (this); - m_whole_words_check_box = new QCheckBox (tr ("&Whole words")); - m_regex_check_box = new QCheckBox (tr ("Regular E&xpressions")); - m_backward_check_box = new QCheckBox (tr ("Search &backward")); - m_search_selection_check_box = new QCheckBox (tr ("Search se&lection")); - m_search_selection_check_box->setCheckable (true); + m_extension = new QWidget (this); + m_whole_words_check_box = new QCheckBox (tr ("&Whole words")); + m_regex_check_box = new QCheckBox (tr ("Regular E&xpressions")); + m_backward_check_box = new QCheckBox (tr ("Search &backward")); + m_search_selection_check_box = new QCheckBox (tr ("Search se&lection")); + m_search_selection_check_box->setCheckable (true); - connect (m_find_next_button, &QPushButton::clicked, - this, &find_dialog::find_next); - connect (m_find_prev_button, &QPushButton::clicked, - this, &find_dialog::find_prev); - connect (m_more_button, &QPushButton::toggled, - m_extension, &QWidget::setVisible); - connect (m_replace_button, &QPushButton::clicked, - this, &find_dialog::replace); - connect (m_replace_all_button, &QPushButton::clicked, - this, &find_dialog::replace_all); - connect (m_backward_check_box, &QCheckBox::stateChanged, - this, &find_dialog::handle_backward_search_changed); - connect (m_button_box, &QDialogButtonBox::rejected, - this, &find_dialog::close); + connect (m_find_next_button, &QPushButton::clicked, + this, &find_dialog::find_next); + connect (m_find_prev_button, &QPushButton::clicked, + this, &find_dialog::find_prev); + connect (m_more_button, &QPushButton::toggled, + m_extension, &QWidget::setVisible); + connect (m_replace_button, &QPushButton::clicked, + this, &find_dialog::replace); + connect (m_replace_all_button, &QPushButton::clicked, + this, &find_dialog::replace_all); + connect (m_backward_check_box, &QCheckBox::stateChanged, + this, &find_dialog::handle_backward_search_changed); + connect (m_button_box, &QDialogButtonBox::rejected, + this, &find_dialog::close); - connect (m_search_selection_check_box, &QCheckBox::stateChanged, - this, &find_dialog::handle_sel_search_changed); + connect (m_search_selection_check_box, &QCheckBox::stateChanged, + this, &find_dialog::handle_sel_search_changed); - QVBoxLayout *extension_layout = new QVBoxLayout (); - extension_layout->setMargin (0); - extension_layout->addWidget (m_whole_words_check_box); - extension_layout->addWidget (m_backward_check_box); - extension_layout->addWidget (m_search_selection_check_box); - m_extension->setLayout (extension_layout); + QVBoxLayout *extension_layout = new QVBoxLayout (); + extension_layout->setMargin (0); + extension_layout->addWidget (m_whole_words_check_box); + extension_layout->addWidget (m_backward_check_box); + extension_layout->addWidget (m_search_selection_check_box); + m_extension->setLayout (extension_layout); - QGridLayout *top_left_layout = new QGridLayout; - top_left_layout->addWidget (m_search_label, 1, 1); - top_left_layout->addWidget (m_search_line_edit, 1, 2); - top_left_layout->addWidget (m_replace_label, 2, 1); - top_left_layout->addWidget (m_replace_line_edit, 2, 2); + QGridLayout *top_left_layout = new QGridLayout; + top_left_layout->addWidget (m_search_label, 1, 1); + top_left_layout->addWidget (m_search_line_edit, 1, 2); + top_left_layout->addWidget (m_replace_label, 2, 1); + top_left_layout->addWidget (m_replace_line_edit, 2, 2); - QVBoxLayout *left_layout = new QVBoxLayout; - left_layout->addLayout (top_left_layout); - left_layout->insertStretch (1, 5); - left_layout->addWidget (m_case_check_box); - left_layout->addWidget (m_from_start_check_box); - left_layout->addWidget (m_wrap_check_box); - left_layout->addWidget (m_regex_check_box); + QVBoxLayout *left_layout = new QVBoxLayout; + left_layout->addLayout (top_left_layout); + left_layout->insertStretch (1, 5); + left_layout->addWidget (m_case_check_box); + left_layout->addWidget (m_from_start_check_box); + left_layout->addWidget (m_wrap_check_box); + left_layout->addWidget (m_regex_check_box); - QGridLayout *main_layout = new QGridLayout; - main_layout->setSizeConstraint (QLayout::SetFixedSize); - main_layout->addLayout (left_layout, 0, 0); - main_layout->addWidget (m_button_box, 0, 1); - main_layout->addWidget (m_extension, 1, 0); - setLayout (main_layout); + QGridLayout *main_layout = new QGridLayout; + main_layout->setSizeConstraint (QLayout::SetFixedSize); + main_layout->addLayout (left_layout, 0, 0); + main_layout->addWidget (m_button_box, 0, 1); + main_layout->addWidget (m_extension, 1, 0); + setLayout (main_layout); - m_extension->hide (); - m_find_next_button->setDefault (true); - m_find_result_available = false; - m_rep_all = 0; - m_rep_active = false; + m_extension->hide (); + m_find_next_button->setDefault (true); + m_find_result_available = false; + m_rep_all = 0; + m_rep_active = false; - // Connect required external signals - connect (ed, SIGNAL (edit_area_changed (octave_qscintilla *)), - this, SLOT (update_edit_area (octave_qscintilla *))); + // Connect required external signals + connect (ed, SIGNAL (edit_area_changed (octave_qscintilla *)), + this, SLOT (update_edit_area (octave_qscintilla *))); - setWindowModality (Qt::NonModal); + setWindowModality (Qt::NonModal); - setAttribute(Qt::WA_ShowWithoutActivating); - setAttribute(Qt::WA_DeleteOnClose); -} + setAttribute(Qt::WA_ShowWithoutActivating); + setAttribute(Qt::WA_DeleteOnClose); + } -// The edit_area has changed: update relevant data of the file dialog -void find_dialog::update_edit_area (octave_qscintilla *edit_area) -{ - m_edit_area = edit_area; - m_search_selection_check_box->setEnabled (edit_area->hasSelectedText ()); + // The edit_area has changed: update relevant data of the file dialog + void find_dialog::update_edit_area (octave_qscintilla *edit_area) + { + m_edit_area = edit_area; + m_search_selection_check_box->setEnabled (edit_area->hasSelectedText ()); - connect (m_edit_area, SIGNAL (copyAvailable (bool)), - this, SLOT (handle_selection_changed (bool)), - Qt::UniqueConnection); -} + connect (m_edit_area, SIGNAL (copyAvailable (bool)), + this, SLOT (handle_selection_changed (bool)), + Qt::UniqueConnection); + } -void find_dialog::save_settings () -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *s = rmgr.get_settings (); + void find_dialog::save_settings () + { + gui_settings settings; - // Save position - QPoint dlg_pos = pos (); + // Save position + QPoint dlg_pos = pos (); #if defined (Q_OS_WIN32) - int y = dlg_pos.y (); + int y = dlg_pos.y (); #else - int y = dlg_pos.y () - geometry ().height () + frameGeometry ().height (); + int y = dlg_pos.y () - geometry ().height () + frameGeometry ().height (); #endif - m_last_position = QPoint (dlg_pos.x (), y); - - s->setValue (ed_fdlg_pos.key, m_last_position); - - // Is current search/replace text in the mru list? - mru_update (m_search_line_edit); - mru_update (m_replace_line_edit); + m_last_position = QPoint (dlg_pos.x (), y); - // Store mru lists - 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); - - 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_pos.settings_key (), m_last_position); - // 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); - - s->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 (); - - // Get mru lists for search and replace text - QStringList mru = s->value (ed_fdlg_search.key).toStringList (); - while (mru.length () > m_mru_length) - mru.removeLast (); - m_search_line_edit->addItems (mru); + // Is current search/replace text in the mru list? + mru_update (m_search_line_edit); + mru_update (m_replace_line_edit); - mru = s->value (ed_fdlg_replace.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 (); - - m_extension->setVisible (FIND_DLG_MORE & opts); - m_case_check_box->setChecked (FIND_DLG_CASE & opts); - m_from_start_check_box->setChecked (FIND_DLG_START & opts); - m_wrap_check_box->setChecked (FIND_DLG_WRAP & opts); - m_regex_check_box->setChecked (FIND_DLG_REGX & opts); - m_whole_words_check_box->setChecked (FIND_DLG_WORDS & opts); - m_backward_check_box->setChecked (FIND_DLG_BACK & opts); - m_search_selection_check_box->setChecked (FIND_DLG_SEL & opts); - - // Default position: lower right of editor's position - int xp = ed_bottom_right.x () - sizeHint ().width (); - int yp = ed_bottom_right.y () - sizeHint ().height (); - QRect default_geometry (xp, yp, sizeHint ().width (), sizeHint ().height ()); + // Store mru lists + QStringList mru; + for (int i = 0; i < m_search_line_edit->count (); i++) + mru.append (m_search_line_edit->itemText (i)); + settings.setValue (ed_fdlg_search.settings_key (), mru); - // Last position from settings - m_last_position = s->value (ed_fdlg_pos.key, QPoint (xp, yp)).toPoint (); - QRect last_geometry (m_last_position, - QSize (sizeHint ().width (), sizeHint ().height ())); - - // Make sure we are on the screen - adjust_to_screen (last_geometry, default_geometry); - m_last_position = last_geometry.topLeft (); - - move (m_last_position); -} - -// set text of "search from start" depending on backward search -void find_dialog::handle_backward_search_changed (int backward) -{ - if (backward) - m_from_start_check_box->setText (tr ("Search from end")); - else - m_from_start_check_box->setText (tr ("Search from start")); -} - -// search text has changed: reset the search -void find_dialog::handle_search_text_changed (void) -{ - // Return if nothing has changed - if (m_search_line_edit->currentText () == m_search_line_edit->itemText (0)) - return; - - if (m_search_selection_check_box->isChecked ()) - m_find_result_available = false; + mru.clear (); + for (int i = 0; i < m_replace_line_edit->count (); i++) + mru.append (m_replace_line_edit->itemText (i)); + settings.setValue (ed_fdlg_replace.settings_key (), mru); - mru_update (m_search_line_edit); -} - -// replaced text has changed: reset the search -void find_dialog::handle_replace_text_changed (void) -{ - // Return if nothing has changed - if (m_replace_line_edit->currentText () == m_replace_line_edit->itemText (0)) - return; - - mru_update (m_replace_line_edit); -} - -// Update the mru list -void find_dialog::mru_update (QComboBox *mru) -{ - // Remove possible empty entries from the mru list - int index; - while ((index = mru->findText (QString ())) >= 0) - mru->removeItem (index); - - // Get current text and return if it is empty - QString text = mru->currentText (); - - if (text.isEmpty ()) - return; - - // Remove occurrences of the current text in the mru list - while ((index = mru->findText (text)) >= 0) - mru->removeItem (index); - - // Remove the last entry from the end if the list is full - if (mru->count () == m_mru_length) - mru->removeItem (m_mru_length -1); - - // Insert new item at the beginning and set it as current item - mru->insertItem (0, text); - mru->setCurrentIndex (0); -} - -void find_dialog::handle_sel_search_changed (int selected) -{ - m_from_start_check_box->setEnabled (! selected); - m_find_result_available = false; -} + // 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; + settings.setValue (ed_fdlg_opts.settings_key (), opts); -void find_dialog::handle_selection_changed (bool has_selected) -{ - if (m_rep_active) - return; - - m_search_selection_check_box->setEnabled (has_selected); - m_find_result_available = false; -} - -// initialize search text with selected text if this is in one single line -void find_dialog::init_search_text (void) -{ - if (m_edit_area && m_edit_area->hasSelectedText ()) - { - int lbeg, lend, cbeg, cend; - m_edit_area->getSelection (&lbeg, &cbeg, &lend, &cend); - if (lbeg == lend) - m_search_line_edit->setCurrentText (m_edit_area->selectedText ()); - } - - // set focus to "Find what" and select all text - m_search_line_edit->setFocus (); - m_search_line_edit->lineEdit ()->selectAll (); + settings.sync (); + } - // Default to "find" next time. - // Otherwise, it defaults to the last action, which may be "replace all". - m_find_next_button->setDefault (true); -} - -void find_dialog::find_next (void) -{ - find (! m_backward_check_box->isChecked ()); -} + void find_dialog::restore_settings (QPoint ed_bottom_right) + { + gui_settings settings; -void find_dialog::find_prev (void) -{ - find (m_backward_check_box->isChecked ()); -} - -void find_dialog::find (bool forward) -{ - if (! m_edit_area) - return; - - handle_search_text_changed (); - - // line adn col: -1 means search starts at current position - int line = -1, col = -1; - - bool do_wrap = m_wrap_check_box->isChecked (); - bool do_forward = forward; + // Get mru lists for search and replace text + QStringList mru = settings.value (ed_fdlg_search.settings_key ()).toStringList (); + while (mru.length () > m_mru_length) + mru.removeLast (); + m_search_line_edit->addItems (mru); - // Initialize the selection begin and end if it is the first search - if (! m_find_result_available) - { - if (m_search_selection_check_box->isChecked () - && m_edit_area->hasSelectedText ()) - { - int l1, c1, l2, c2; - m_edit_area->getSelection (&l1, &c1, &l2, &c2); + mru = settings.value (ed_fdlg_replace.settings_key ()).toStringList (); + while (mru.length () > m_mru_length) + mru.removeLast (); + m_replace_line_edit->addItems (mru); - // Store the position of the selection - m_sel_beg = m_edit_area->positionFromLineIndex (l1, c1); - m_sel_end = m_edit_area->positionFromLineIndex (l2, c2); - m_in_sel = true; - } - else - m_in_sel = false; - } + // Get the dialog's options + int opts = settings.int_value (ed_fdlg_opts); - // Get the correct line/col for beginning the search - if (m_rep_all) - { - // Replace All - if (m_rep_all == 1) - { - // Start at the beginning of file/sel if it is the first try - if (m_in_sel) - m_edit_area->lineIndexFromPosition (m_sel_beg, &line, &col); - else - { - line = 0; - col = 0; - } - } - do_wrap = false; // Never wrap when replacing all - } - else - { - // Normal search (not replace all): calculate start position of - // search (in file or selection) - if (m_from_start_check_box->isChecked () - || (m_in_sel && (! m_find_result_available))) - { - // From the beginning or the end of file/sel - if (do_forward) - { - // From the beginning - if (m_in_sel) - m_edit_area->lineIndexFromPosition (m_sel_beg, &line, &col); - else - { - line = 0; - col = 0; - } - } - else - { - // From the end - if (m_in_sel) - m_edit_area->lineIndexFromPosition (m_sel_end, &line, &col); - else - { - line = m_edit_area->lines () - 1; - col = m_edit_area->text (line).length () - 1; - if (col == -1) - col = 0; - } - } - } - else if (! do_forward) - { - // Start from where the cursor is. Fix QScintilla's cursor - // positioning - m_edit_area->getCursorPosition (&line, &col); - if (m_find_result_available && m_edit_area->hasSelectedText ()) - { - int currpos = m_edit_area->positionFromLineIndex (line, col); - currpos -= (m_search_line_edit->currentText ().length ()); - if (currpos < 0) - currpos = 0; - m_edit_area->lineIndexFromPosition (currpos, &line, &col); - } - } - } + m_extension->setVisible (FIND_DLG_MORE & opts); + m_case_check_box->setChecked (FIND_DLG_CASE & opts); + m_from_start_check_box->setChecked (FIND_DLG_START & opts); + m_wrap_check_box->setChecked (FIND_DLG_WRAP & opts); + m_regex_check_box->setChecked (FIND_DLG_REGX & opts); + m_whole_words_check_box->setChecked (FIND_DLG_WORDS & opts); + m_backward_check_box->setChecked (FIND_DLG_BACK & opts); + m_search_selection_check_box->setChecked (FIND_DLG_SEL & opts); - // Do the search - m_find_result_available - = m_edit_area->findFirst (m_search_line_edit->currentText (), - m_regex_check_box->isChecked (), - m_case_check_box->isChecked (), - m_whole_words_check_box->isChecked (), - do_wrap, - do_forward, - line, col, - true -#if defined (HAVE_QSCI_VERSION_2_6_0) - , true -#endif - ); + // Default position: lower right of editor's position + int xp = ed_bottom_right.x () - sizeHint ().width (); + int yp = ed_bottom_right.y () - sizeHint ().height (); + QRect default_geometry (xp, yp, sizeHint ().width (), sizeHint ().height ()); - if (m_find_result_available) - { - // Search successful: reset search-from-start box and check for - // the current selection - m_from_start_check_box->setChecked (0); - - if (m_in_sel) - { - m_edit_area->getCursorPosition (&line, &col); - int pos = m_edit_area->positionFromLineIndex (line, col); - - int l1, c1, l2, c2; - m_edit_area->lineIndexFromPosition (m_sel_beg, &l1, &c1); - m_edit_area->lineIndexFromPosition (m_sel_end, &l2, &c2); - m_edit_area->show_selection_markers (l1, c1, l2, c2); - - // Check if new start position is still within the selection - m_find_result_available = pos >= m_sel_beg && pos <= m_sel_end; - } - } + // Last position from settings + 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 ())); - // No more search hits - if (! m_find_result_available) - { - if (m_in_sel) - { - // Restore real selection and remove marker for selection - int l1, c1, l2, c2; - m_edit_area->lineIndexFromPosition (m_sel_beg, &l1, &c1); - m_edit_area->lineIndexFromPosition (m_sel_end, &l2, &c2); - m_edit_area->setSelection (l1, c1, l2, c2); - m_edit_area->clear_selection_markers (); - } + // Make sure we are on the screen + adjust_to_screen (last_geometry, default_geometry); + m_last_position = last_geometry.topLeft (); - // Display message if not replace all - if (! m_rep_all) - no_matches_message (); - } - -} - -void find_dialog::do_replace (void) -{ - if (m_edit_area) - { - m_rep_active = true; // changes in selection not made by the user + move (m_last_position); + } - m_edit_area->replace (m_replace_line_edit->currentText ()); - if (m_in_sel) - { - // 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_rep_active = false; - } -} - -void find_dialog::replace (void) -{ - if (m_edit_area) - { - handle_replace_text_changed (); - - // Do the replace if we have selected text - if (m_find_result_available && m_edit_area->hasSelectedText ()) - do_replace (); - - find_next (); - } -} + // set text of "search from start" depending on backward search + void find_dialog::handle_backward_search_changed (int backward) + { + if (backward) + m_from_start_check_box->setText (tr ("Search from end")); + else + m_from_start_check_box->setText (tr ("Search from start")); + } -void find_dialog::replace_all (void) -{ - int line, col; - - if (m_edit_area) - { - handle_replace_text_changed (); - - m_edit_area->getCursorPosition (&line, &col); - - m_rep_all = 1; - find_next (); // find first occurrence (forward) + // search text has changed: reset the search + void find_dialog::handle_search_text_changed () + { + // Return if nothing has changed + if (m_search_line_edit->currentText () == m_search_line_edit->itemText (0)) + return; - m_edit_area->beginUndoAction (); - while (m_find_result_available) // while search string is found - { - do_replace (); - m_rep_all++; // inc counter - find_next (); // find next - } - m_edit_area->endUndoAction (); - - QMessageBox msg_box (QMessageBox::Information, tr ("Replace Result"), - tr ("%1 items replaced").arg (m_rep_all-1), - QMessageBox::Ok, this); - msg_box.exec (); - - m_rep_all = 0; + if (m_search_selection_check_box->isChecked ()) m_find_result_available = false; - if (! m_search_selection_check_box->isChecked ()) - m_edit_area->setCursorPosition (line, col); - } -} + mru_update (m_search_line_edit); + } + + // replaced text has changed: reset the search + void find_dialog::handle_replace_text_changed () + { + // Return if nothing has changed + if (m_replace_line_edit->currentText () == m_replace_line_edit->itemText (0)) + return; + + mru_update (m_replace_line_edit); + } + + // Update the mru list + void find_dialog::mru_update (QComboBox *mru) + { + // Remove possible empty entries from the mru list + int index; + while ((index = mru->findText (QString ())) >= 0) + mru->removeItem (index); + + // Get current text and return if it is empty + QString text = mru->currentText (); + + if (text.isEmpty ()) + return; + + // Remove occurrences of the current text in the mru list + while ((index = mru->findText (text)) >= 0) + mru->removeItem (index); + + // Remove the last entry from the end if the list is full + if (mru->count () == m_mru_length) + mru->removeItem (m_mru_length -1); + + // Insert new item at the beginning and set it as current item + mru->insertItem (0, text); + mru->setCurrentIndex (0); + } + + void find_dialog::handle_sel_search_changed (int selected) + { + m_from_start_check_box->setEnabled (! selected); + m_find_result_available = false; + } + + void find_dialog::handle_selection_changed (bool has_selected) + { + if (m_rep_active) + return; + + m_search_selection_check_box->setEnabled (has_selected); + m_find_result_available = false; + } -void find_dialog::no_matches_message (void) -{ - QMessageBox msg_box (QMessageBox::Information, tr ("Find Result"), - tr ("No more matches found"), QMessageBox::Ok, this); - msg_box.exec (); -} + // initialize search text with selected text if this is in one single line + void find_dialog::init_search_text () + { + if (m_edit_area && m_edit_area->hasSelectedText ()) + { + int lbeg, lend, cbeg, cend; + m_edit_area->getSelection (&lbeg, &cbeg, &lend, &cend); + if (lbeg == lend) + m_search_line_edit->setCurrentText (m_edit_area->selectedText ()); + } + + // set focus to "Find what" and select all text + m_search_line_edit->setFocus (); + m_search_line_edit->lineEdit ()->selectAll (); + + // Default to "find" next time. + // Otherwise, it defaults to the last action, which may be "replace all". + m_find_next_button->setDefault (true); + } + + void find_dialog::find_next () + { + find (! m_backward_check_box->isChecked ()); + } + + void find_dialog::find_prev () + { + find (m_backward_check_box->isChecked ()); + } -void find_dialog::reject () -{ - close (); -} + void find_dialog::find (bool forward) + { + if (! m_edit_area) + return; + + handle_search_text_changed (); + + // line adn col: -1 means search starts at current position + int line = -1, col = -1; + + bool do_wrap = m_wrap_check_box->isChecked (); + bool do_forward = forward; + + // Initialize the selection begin and end if it is the first search + if (! m_find_result_available) + { + if (m_search_selection_check_box->isChecked () + && m_edit_area->hasSelectedText ()) + { + int l1, c1, l2, c2; + m_edit_area->getSelection (&l1, &c1, &l2, &c2); + + // Store the position of the selection + m_sel_beg = m_edit_area->positionFromLineIndex (l1, c1); + m_sel_end = m_edit_area->positionFromLineIndex (l2, c2); + m_in_sel = true; + } + else + m_in_sel = false; + } -void find_dialog::closeEvent (QCloseEvent *e) -{ - save_settings (); - e->accept (); -} + // Get the correct line/col for beginning the search + if (m_rep_all) + { + // Replace All + if (m_rep_all == 1) + { + // Start at the beginning of file/sel if it is the first try + if (m_in_sel) + m_edit_area->lineIndexFromPosition (m_sel_beg, &line, &col); + else + { + line = 0; + col = 0; + } + } + do_wrap = false; // Never wrap when replacing all + } + else + { + // Normal search (not replace all): calculate start position of + // search (in file or selection) + if (m_from_start_check_box->isChecked () + || (m_in_sel && (! m_find_result_available))) + { + // From the beginning or the end of file/sel + if (do_forward) + { + // From the beginning + if (m_in_sel) + m_edit_area->lineIndexFromPosition (m_sel_beg, &line, &col); + else + { + line = 0; + col = 0; + } + } + else + { + // From the end + if (m_in_sel) + m_edit_area->lineIndexFromPosition (m_sel_end, &line, &col); + else + { + line = m_edit_area->lines () - 1; + col = m_edit_area->text (line).length () - 1; + if (col == -1) + col = 0; + } + } + } + else if (! do_forward) + { + // Start from where the cursor is. Fix QScintilla's cursor + // positioning + m_edit_area->getCursorPosition (&line, &col); + if (m_find_result_available && m_edit_area->hasSelectedText ()) + { + int currpos = m_edit_area->positionFromLineIndex (line, col); + currpos -= (m_search_line_edit->currentText ().length ()); + if (currpos < 0) + currpos = 0; + m_edit_area->lineIndexFromPosition (currpos, &line, &col); + } + } + } + + // Do the search + m_find_result_available + = m_edit_area->findFirst (m_search_line_edit->currentText (), + m_regex_check_box->isChecked (), + m_case_check_box->isChecked (), + m_whole_words_check_box->isChecked (), + do_wrap, + do_forward, + line, col, + true +#if defined (HAVE_QSCI_VERSION_2_6_0) + , true +#endif + ); + + if (m_find_result_available) + { + // Search successful: reset search-from-start box and check for + // the current selection + m_from_start_check_box->setChecked (0); + + if (m_in_sel) + { + m_edit_area->getCursorPosition (&line, &col); + int pos = m_edit_area->positionFromLineIndex (line, col); + + int l1, c1, l2, c2; + m_edit_area->lineIndexFromPosition (m_sel_beg, &l1, &c1); + m_edit_area->lineIndexFromPosition (m_sel_end, &l2, &c2); + m_edit_area->show_selection_markers (l1, c1, l2, c2); + + // Check if new start position is still within the selection + m_find_result_available = pos >= m_sel_beg && pos <= m_sel_end; + } + } -// Show and hide with (re-)storing position, otherwise there is always -// a small shift each time the dialog is shown again -void find_dialog::set_visible (bool visible) -{ - if (visible) - { - show (); - move (m_last_position); - } - else - { - m_last_position = pos (); - hide (); - } -} + // No more search hits + if (! m_find_result_available) + { + if (m_in_sel) + { + // Restore real selection and remove marker for selection + int l1, c1, l2, c2; + m_edit_area->lineIndexFromPosition (m_sel_beg, &l1, &c1); + m_edit_area->lineIndexFromPosition (m_sel_end, &l2, &c2); + m_edit_area->setSelection (l1, c1, l2, c2); + m_edit_area->clear_selection_markers (); + } + + // Display message if not replace all + if (! m_rep_all) + no_matches_message (); + } + + } + + void find_dialog::do_replace () + { + if (m_edit_area) + { + m_rep_active = true; // changes in selection not made by the user + + m_edit_area->replace (m_replace_line_edit->currentText ()); + if (m_in_sel) + { + // 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_rep_active = false; + } + } + + void find_dialog::replace () + { + if (m_edit_area) + { + handle_replace_text_changed (); + + // Do the replace if we have selected text + if (m_find_result_available && m_edit_area->hasSelectedText ()) + do_replace (); + + find_next (); + } + } + + void find_dialog::replace_all () + { + int line, col; + + if (m_edit_area) + { + handle_replace_text_changed (); + + m_edit_area->getCursorPosition (&line, &col); + + m_rep_all = 1; + find_next (); // find first occurrence (forward) + + m_edit_area->beginUndoAction (); + while (m_find_result_available) // while search string is found + { + do_replace (); + m_rep_all++; // inc counter + find_next (); // find next + } + m_edit_area->endUndoAction (); + + QMessageBox msg_box (QMessageBox::Information, tr ("Replace Result"), + tr ("%1 items replaced").arg (m_rep_all-1), + QMessageBox::Ok, this); + msg_box.exec (); + + m_rep_all = 0; + m_find_result_available = false; + + if (! m_search_selection_check_box->isChecked ()) + m_edit_area->setCursorPosition (line, col); + } + } + + void find_dialog::no_matches_message () + { + QMessageBox msg_box (QMessageBox::Information, tr ("Find Result"), + tr ("No more matches found"), QMessageBox::Ok, this); + msg_box.exec (); + } + + void find_dialog::reject () + { + close (); + } + + void find_dialog::closeEvent (QCloseEvent *e) + { + save_settings (); + e->accept (); + } + + // Show and hide with (re-)storing position, otherwise there is always + // a small shift each time the dialog is shown again + void find_dialog::set_visible (bool visible) + { + if (visible) + { + show (); + move (m_last_position); + } + else + { + m_last_position = pos (); + hide (); + } + } OCTAVE_END_NAMESPACE(octave) #endif diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/find-dialog.h --- a/libgui/src/m-editor/find-dialog.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/find-dialog.h Mon Jan 30 18:36:03 2023 +0100 @@ -79,102 +79,99 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class file_editor; + class file_editor; -class find_dialog : public QDialog -{ - Q_OBJECT + class find_dialog : public QDialog + { + Q_OBJECT -public: + 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); + //! Set dialog visible or not and storing the new visibility state + void set_visible (bool visible); - //! Restore position and the search options from the given settings - //! where def_pos is the default position suitable for the current - //! editor position - void restore_settings (QPoint def_pos); + //! Init the search text with the selected text in the editor tab + void init_search_text (); -public slots: + //! Restore position and the search options from the given settings + //! where def_pos is the default position suitable for the current + //! editor position + void restore_settings (QPoint def_pos); - void find_next (void); - void find_prev (void); + public slots: + + void find_next (); + void find_prev (); - //! Slot for updating the edit area when the active tab has changed - void update_edit_area (octave_qscintilla *); + //! Slot for updating the edit area when the active tab has changed + void update_edit_area (octave_qscintilla *); -private slots: - - void handle_sel_search_changed (int); - void handle_selection_changed (bool has_selected); + private slots: - void handle_backward_search_changed (int); + void handle_sel_search_changed (int); + void handle_selection_changed (bool has_selected); - void find (bool forward = true); - void replace (void); - void replace_all (void); + void handle_backward_search_changed (int); -private: + void find (bool forward = true); + void replace (); + void replace_all (); - base_qobject& m_octave_qobj; + private: - //! Save position and the search options in the given settings - void save_settings (); + //! Save position and the search options in the given settings + void save_settings (); - //! Reimplemented slot: close instead of hiding - void reject (); + //! Reimplemented slot: close instead of hiding + void reject (); - //! Reimplemented close event - void closeEvent (QCloseEvent *e); + //! Reimplemented close event + void closeEvent (QCloseEvent *e); - //! Update mru lists with new entry - void mru_update (QComboBox *mru); + //! 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; + octave_dock_widget *m_editor; - QLabel *m_search_label; - QComboBox *m_search_line_edit; - QLabel *m_replace_label; - QComboBox *m_replace_line_edit; - QCheckBox *m_case_check_box; - QCheckBox *m_from_start_check_box; - QCheckBox *m_wrap_check_box; - QCheckBox *m_whole_words_check_box; - QCheckBox *m_regex_check_box; - QCheckBox *m_search_selection_check_box; - QCheckBox *m_backward_check_box; - QDialogButtonBox *m_button_box; - QPushButton *m_find_next_button; - QPushButton *m_find_prev_button; - QPushButton *m_replace_button; - QPushButton *m_replace_all_button; - QPushButton *m_more_button; - QWidget *m_extension; - octave_qscintilla *m_edit_area; - bool m_find_result_available; - int m_rep_all; - bool m_rep_active; + QLabel *m_search_label; + QComboBox *m_search_line_edit; + QLabel *m_replace_label; + QComboBox *m_replace_line_edit; + QCheckBox *m_case_check_box; + QCheckBox *m_from_start_check_box; + QCheckBox *m_wrap_check_box; + QCheckBox *m_whole_words_check_box; + QCheckBox *m_regex_check_box; + QCheckBox *m_search_selection_check_box; + QCheckBox *m_backward_check_box; + QDialogButtonBox *m_button_box; + QPushButton *m_find_next_button; + QPushButton *m_find_prev_button; + QPushButton *m_replace_button; + QPushButton *m_replace_all_button; + QPushButton *m_more_button; + QWidget *m_extension; + octave_qscintilla *m_edit_area; + bool m_find_result_available; + int m_rep_all; + bool m_rep_active; - bool m_in_sel; - int m_sel_beg; - int m_sel_end; + bool m_in_sel; + int m_sel_beg; + int m_sel_end; - QPoint m_last_position; + QPoint m_last_position; - const int m_mru_length = 10; -}; + const int m_mru_length = 10; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/marker.cc --- a/libgui/src/m-editor/marker.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/marker.cc Mon Jan 30 18:36:03 2023 +0100 @@ -81,7 +81,7 @@ } } -void marker::handle_remove (void) +void marker::handle_remove () { m_edit_area->markerDeleteHandle (m_mhandle); delete this; diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/marker.h --- a/libgui/src/m-editor/marker.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/marker.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/octave-qscintilla.cc Mon Jan 30 18:36:03 2023 +0100 @@ -35,7 +35,8 @@ #include #include #include -#include +#include +#include #include #include #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) @@ -54,17 +55,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". @@ -73,1309 +74,1334 @@ OCTAVE_BEGIN_NAMESPACE(octave) -static bool -is_end (const QString& candidate, const QString& opening) -{ - bool retval = false; + static bool + is_end (const QString& candidate, const QString& opening) + { + bool retval = false; - if (opening == "do") // The only one that can't be ended by "end" - { - if (candidate == "until") - retval = true; - } - else - { - if (candidate == "end") - retval = true; - else - { - if (opening == "try") - { - if (candidate == "catch" || candidate == "end_try_catch") - retval = true; - } - else if (opening == "unwind_protect") - { - if (candidate == "unwind_protect_cleanup" - || candidate == "end_unwind_protect") - retval = true; - } - else if (candidate == "end" + opening) - retval = true; - else if (opening == "if" && candidate == "else") - retval = true; - } - } + if (opening == "do") // The only one that can't be ended by "end" + { + if (candidate == "until") + retval = true; + } + else + { + if (candidate == "end") + retval = true; + else + { + if (opening == "try") + { + if (candidate == "catch" || candidate == "end_try_catch") + retval = true; + } + else if (opening == "unwind_protect") + { + if (candidate == "unwind_protect_cleanup" + || candidate == "end_unwind_protect") + retval = true; + } + else if (candidate == "end" + opening) + retval = true; + else if (opening == "if" && candidate == "else") + retval = true; + } + } - return retval; -} + 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) -{ - connect (this, SIGNAL (textChanged (void)), - this, SLOT (text_changed (void))); + 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 ()), + this, SLOT (text_changed ())); - connect (this, SIGNAL (cursorPositionChanged (int, int)), - this, SLOT (cursor_position_changed (int, int))); + connect (this, SIGNAL (cursorPositionChanged (int, int)), + this, SLOT (cursor_position_changed (int, int))); - connect (this, &octave_qscintilla::ctx_menu_run_finished_signal, - this, &octave_qscintilla::ctx_menu_run_finished, - Qt::QueuedConnection); + connect (this, &octave_qscintilla::ctx_menu_run_finished_signal, + this, &octave_qscintilla::ctx_menu_run_finished, + Qt::QueuedConnection); - // clear scintilla edit shortcuts that are handled by the editor - QsciCommandSet *cmd_set = standardCommands (); + // clear scintilla edit shortcuts that are handled by the editor + QsciCommandSet *cmd_set = standardCommands (); - // Disable buffered drawing on all systems - SendScintilla (SCI_SETBUFFEREDDRAW, false); + // Disable buffered drawing on all systems + SendScintilla (SCI_SETBUFFEREDDRAW, false); #if defined (HAVE_QSCI_VERSION_2_6_0) - // find () was added in QScintilla 2.6 - cmd_set->find (QsciCommand::SelectionCopy)->setKey (0); - cmd_set->find (QsciCommand::SelectionCut)->setKey (0); - cmd_set->find (QsciCommand::Paste)->setKey (0); - cmd_set->find (QsciCommand::SelectAll)->setKey (0); - cmd_set->find (QsciCommand::SelectionDuplicate)->setKey (0); - cmd_set->find (QsciCommand::LineTranspose)->setKey (0); - cmd_set->find (QsciCommand::Undo)->setKey (0); - cmd_set->find (QsciCommand::Redo)->setKey (0); - cmd_set->find (QsciCommand::SelectionUpperCase)->setKey (0); - cmd_set->find (QsciCommand::SelectionLowerCase)->setKey (0); - cmd_set->find (QsciCommand::ZoomIn)->setKey (0); - cmd_set->find (QsciCommand::ZoomOut)->setKey (0); - cmd_set->find (QsciCommand::DeleteWordLeft)->setKey (0); - cmd_set->find (QsciCommand::DeleteWordRight)->setKey (0); - cmd_set->find (QsciCommand::DeleteLineLeft)->setKey (0); - cmd_set->find (QsciCommand::DeleteLineRight)->setKey (0); - cmd_set->find (QsciCommand::LineDelete)->setKey (0); - cmd_set->find (QsciCommand::LineCut)->setKey (0); - cmd_set->find (QsciCommand::LineCopy)->setKey (0); + // find () was added in QScintilla 2.6 + cmd_set->find (QsciCommand::SelectionCopy)->setKey (0); + cmd_set->find (QsciCommand::SelectionCut)->setKey (0); + cmd_set->find (QsciCommand::Paste)->setKey (0); + cmd_set->find (QsciCommand::SelectAll)->setKey (0); + cmd_set->find (QsciCommand::SelectionDuplicate)->setKey (0); + cmd_set->find (QsciCommand::LineTranspose)->setKey (0); + cmd_set->find (QsciCommand::Undo)->setKey (0); + cmd_set->find (QsciCommand::Redo)->setKey (0); + cmd_set->find (QsciCommand::SelectionUpperCase)->setKey (0); + cmd_set->find (QsciCommand::SelectionLowerCase)->setKey (0); + cmd_set->find (QsciCommand::ZoomIn)->setKey (0); + cmd_set->find (QsciCommand::ZoomOut)->setKey (0); + cmd_set->find (QsciCommand::DeleteWordLeft)->setKey (0); + cmd_set->find (QsciCommand::DeleteWordRight)->setKey (0); + cmd_set->find (QsciCommand::DeleteLineLeft)->setKey (0); + cmd_set->find (QsciCommand::DeleteLineRight)->setKey (0); + cmd_set->find (QsciCommand::LineDelete)->setKey (0); + cmd_set->find (QsciCommand::LineCut)->setKey (0); + cmd_set->find (QsciCommand::LineCopy)->setKey (0); #else - // find commands via its default key (tricky way without find ()) - QList< QsciCommand * > cmd_list = cmd_set->commands (); - for (int i = 0; i < cmd_list.length (); i++) - { - int cmd_key = cmd_list.at (i)->key (); - switch (cmd_key) - { - case Qt::Key_C | Qt::CTRL : // SelectionCopy - case Qt::Key_X | Qt::CTRL : // SelectionCut - case Qt::Key_V | Qt::CTRL : // Paste - case Qt::Key_A | Qt::CTRL : // SelectAll - case Qt::Key_D | Qt::CTRL : // SelectionDuplicate - case Qt::Key_T | Qt::CTRL : // LineTranspose - case Qt::Key_Z | Qt::CTRL : // Undo - case Qt::Key_Y | Qt::CTRL : // Redo - case Qt::Key_Z | Qt::CTRL | Qt::SHIFT : // Redo - case Qt::Key_U | Qt::CTRL : // SelectionLowerCase - case Qt::Key_U | Qt::CTRL | Qt::SHIFT : // SelectionUpperCase - case Qt::Key_Plus | Qt::CTRL : // ZoomIn - case Qt::Key_Minus | Qt::CTRL : // ZoomOut - case Qt::Key_Backspace | Qt::CTRL | Qt::SHIFT : // DeleteLineLeft - case Qt::Key_Delete | Qt::CTRL | Qt::SHIFT : // DeleteLineRight - case Qt::Key_K | Qt::META : // DeleteLineRight - case Qt::Key_Backspace | Qt::CTRL : // DeleteWordLeft - case Qt::Key_Delete | Qt::CTRL : // DeleteWordRight - case Qt::Key_L | Qt::CTRL | Qt::SHIFT : // LineDelete - case Qt::Key_L | Qt::CTRL : // LineCut - case Qt::Key_T | Qt::CTRL | Qt::SHIFT : // LineCopy - cmd_list.at (i)->setKey (0); - } - } + // find commands via its default key (tricky way without find ()) + QList< QsciCommand * > cmd_list = cmd_set->commands (); + for (int i = 0; i < cmd_list.length (); i++) + { + int cmd_key = cmd_list.at (i)->key (); + switch (cmd_key) + { + case Qt::Key_C | Qt::CTRL : // SelectionCopy + case Qt::Key_X | Qt::CTRL : // SelectionCut + case Qt::Key_V | Qt::CTRL : // Paste + case Qt::Key_A | Qt::CTRL : // SelectAll + case Qt::Key_D | Qt::CTRL : // SelectionDuplicate + case Qt::Key_T | Qt::CTRL : // LineTranspose + case Qt::Key_Z | Qt::CTRL : // Undo + case Qt::Key_Y | Qt::CTRL : // Redo + case Qt::Key_Z | Qt::CTRL | Qt::SHIFT : // Redo + case Qt::Key_U | Qt::CTRL : // SelectionLowerCase + case Qt::Key_U | Qt::CTRL | Qt::SHIFT : // SelectionUpperCase + case Qt::Key_Plus | Qt::CTRL : // ZoomIn + case Qt::Key_Minus | Qt::CTRL : // ZoomOut + case Qt::Key_Backspace | Qt::CTRL | Qt::SHIFT : // DeleteLineLeft + case Qt::Key_Delete | Qt::CTRL | Qt::SHIFT : // DeleteLineRight + case Qt::Key_K | Qt::META : // DeleteLineRight + case Qt::Key_Backspace | Qt::CTRL : // DeleteWordLeft + case Qt::Key_Delete | Qt::CTRL : // DeleteWordRight + case Qt::Key_L | Qt::CTRL | Qt::SHIFT : // LineDelete + case Qt::Key_L | Qt::CTRL : // LineCut + case Qt::Key_T | Qt::CTRL | Qt::SHIFT : // LineCopy + cmd_list.at (i)->setKey (0); + } + } #endif #if defined (Q_OS_MAC) - // Octave interprets Cmd key as Meta whereas Qscintilla interprets it - // as Ctrl. We thus invert Meta/Ctrl in Qscintilla's shortcuts list. - QList< QsciCommand * > cmd_list_mac = cmd_set->commands (); - for (int i = 0; i < cmd_list_mac.length (); i++) - { - // Primary key - int key = cmd_list_mac.at (i)->key (); - - if (static_cast (key | Qt::META) == key - && static_cast (key | Qt::CTRL) != key) - key = (key ^ Qt::META) | Qt::CTRL; - else if (static_cast (key | Qt::CTRL) == key) - key = (key ^ Qt::CTRL) | Qt::META; - - cmd_list_mac.at (i)->setKey (key); - - // Alternate key - key = cmd_list_mac.at (i)->alternateKey (); - - if (static_cast (key | Qt::META) == key - && static_cast (key | Qt::CTRL) != key) - key = (key ^ Qt::META) | Qt::CTRL; - else if (static_cast (key | Qt::CTRL) == key) - key = (key ^ Qt::CTRL) | Qt::META; - - cmd_list_mac.at (i)->setAlternateKey (key); - } -#endif - - // selection markers - - m_indicator_id = indicatorDefine (QsciScintilla::StraightBoxIndicator); - if (m_indicator_id == -1) - m_indicator_id = 1; - - setIndicatorDrawUnder (true, m_indicator_id); - - markerDefine (QsciScintilla::Minus, marker::selection); - - // init state of undo/redo action for this tab - emit status_update (isUndoAvailable (), isRedoAvailable ()); -} - -void octave_qscintilla::setCursorPosition (int line, int col) -{ - QsciScintilla::setCursorPosition (line, col); - emit update_rowcol_indicator_signal (line, col); -} - -void octave_qscintilla::set_selection_marker_color (const QColor& c) -{ - QColor ic = c; - ic.setAlphaF (0.45); - setIndicatorForegroundColor (ic, m_indicator_id); - setIndicatorOutlineColor (ic, m_indicator_id); - - setMarkerForegroundColor (c, marker::selection); - setMarkerBackgroundColor (c, marker::selection); -} - -// context menu requested -void octave_qscintilla::contextMenuEvent (QContextMenuEvent *e) -{ -#if defined (HAVE_QSCI_VERSION_2_6_0) - QPoint global_pos, local_pos; // the menu's position - QMenu *context_menu = createStandardContextMenu (); // standard menu - - bool in_left_margin = false; - - // determine position depending on mouse or keyboard event - if (e->reason () == QContextMenuEvent::Mouse) - { - // context menu by mouse - global_pos = e->globalPos (); // global mouse position - local_pos = e->pos (); // local mouse position - if (e->x () < marginWidth (1) + marginWidth (2)) - in_left_margin = true; - } - else - { - // context menu by keyboard or other: get point of text cursor - get_global_textcursor_pos (&global_pos, &local_pos); - QRect editor_rect = geometry (); // editor rect mapped to global - editor_rect.moveTopLeft - (parentWidget ()->mapToGlobal (editor_rect.topLeft ())); - if (! editor_rect.contains (global_pos)) // is cursor outside editor? - global_pos = editor_rect.topLeft (); // yes, take top left corner - } - -# if defined (HAVE_QSCI_VERSION_2_6_0) - if (! in_left_margin) -# endif - { - // fill context menu with editor's standard actions - emit create_context_menu_signal (context_menu); - - // additional custom entries of the context menu - context_menu->addSeparator (); // separator before custom entries - - // help menu: get the position of the mouse or the text cursor - // (only for octave files) - QString lexer_name = lexer ()->lexer (); - if (lexer_name == "octave" || lexer_name == "matlab") - { - m_word_at_cursor = wordAtPoint (local_pos); - if (! m_word_at_cursor.isEmpty ()) - { - context_menu->addAction (tr ("Help on") + ' ' + m_word_at_cursor, - this, &octave_qscintilla::contextmenu_help); - context_menu->addAction (tr ("Documentation on") - + ' ' + m_word_at_cursor, - this, &octave_qscintilla::contextmenu_doc); - context_menu->addAction (tr ("Edit") + ' ' + m_word_at_cursor, - this, &octave_qscintilla::contextmenu_edit); - } - } - } -# if defined (HAVE_QSCI_VERSION_2_6_0) - else - { - // remove all standard actions from scintilla - QList all_actions = context_menu->actions (); - - for (auto *a : all_actions) - context_menu->removeAction (a); - - QAction *act - = context_menu->addAction (tr ("dbstop if ..."), this, - &octave_qscintilla::contextmenu_break_condition); - act->setData (local_pos); - } -# endif - - // finally show the menu - context_menu->exec (global_pos); - -#else + // Octave interprets Cmd key as Meta whereas Qscintilla interprets it + // as Ctrl. We thus invert Meta/Ctrl in Qscintilla's shortcuts list. + QList< QsciCommand * > cmd_list_mac = cmd_set->commands (); + for (int i = 0; i < cmd_list_mac.length (); i++) + { + // Primary key + int key = cmd_list_mac.at (i)->key (); - octave_unused_parameter (e); - -#endif -} - -// common function with flag for documentation -void octave_qscintilla::contextmenu_help_doc (bool documentation) -{ - if (documentation) - m_octave_qobj.show_documentation_window (m_word_at_cursor); - 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) -{ - if (get_actual_word ()) - contextmenu_edit (true); -} - -// call edit the function related to the current word -void octave_qscintilla::context_run (void) -{ - if (hasSelectedText ()) - { - contextmenu_run (true); + if (static_cast (key | Qt::META) == key + && static_cast (key | Qt::CTRL) != key) + key = (key ^ Qt::META) | Qt::CTRL; + else if (static_cast (key | Qt::CTRL) == key) + key = (key ^ Qt::CTRL) | Qt::META; - emit interpreter_event - ([] (interpreter&) - { command_editor::erase_empty_line (false); }); - } -} - -void octave_qscintilla::get_global_textcursor_pos (QPoint *global_pos, - QPoint *local_pos) -{ - long position = SendScintilla (SCI_GETCURRENTPOS); - long point_x = SendScintilla (SCI_POINTXFROMPOSITION, 0, position); - long point_y = SendScintilla (SCI_POINTYFROMPOSITION, 0, position); - *local_pos = QPoint (point_x, point_y); // local cursor position - *global_pos = mapToGlobal (*local_pos); // global position of cursor -} - -// determine the actual word and whether we are in an octave or matlab script -bool octave_qscintilla::get_actual_word (void) -{ - QPoint global_pos, local_pos; - get_global_textcursor_pos (&global_pos, &local_pos); - m_word_at_cursor = wordAtPoint (local_pos); - QString lexer_name = lexer ()->lexer (); - return ((lexer_name == "octave" || lexer_name == "matlab") - && ! m_word_at_cursor.isEmpty ()); -} - -// helper function for clearing all indicators of a specific style -void octave_qscintilla::clear_selection_markers (void) -{ - int end_pos = text ().length (); - int end_line, end_col; - lineIndexFromPosition (end_pos, &end_line, &end_col); - clearIndicatorRange (0, 0, end_line, end_col, m_indicator_id); - - markerDeleteAll (marker::selection); -} + cmd_list_mac.at (i)->setKey (key); -QString octave_qscintilla::eol_string (void) -{ - switch (eolMode ()) - { - case QsciScintilla::EolWindows: - return ("\r\n"); - case QsciScintilla::EolMac: - return ("\r"); - case QsciScintilla::EolUnix: - return ("\n"); - } - - // Last resort, if the above goes wrong (should never happen) - return ("\r\n"); -} - -// Function returning the true cursor position where the tab length -// is taken into account. -void octave_qscintilla::get_current_position (int *pos, int *line, int *col) -{ - *pos = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS); - *line = SendScintilla (QsciScintillaBase::SCI_LINEFROMPOSITION, *pos); - *col = SendScintilla (QsciScintillaBase::SCI_GETCOLUMN, *pos); -} - -// Function returning the comment string of the current lexer -QStringList octave_qscintilla::comment_string (bool comment) -{ - int lexer = SendScintilla (SCI_GETLEXER); + // Alternate key + key = cmd_list_mac.at (i)->alternateKey (); - switch (lexer) - { -#if defined (HAVE_LEXER_OCTAVE) || defined (HAVE_LEXER_MATLAB) -#if defined (HAVE_LEXER_OCTAVE) - case SCLEX_OCTAVE: -#else - case SCLEX_MATLAB: -#endif - { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - int comment_string; + if (static_cast (key | Qt::META) == key + && static_cast (key | Qt::CTRL) != key) + key = (key ^ Qt::META) | Qt::CTRL; + else if (static_cast (key | Qt::CTRL) == key) + key = (key ^ Qt::CTRL) | Qt::META; - if (comment) - { - // The commenting string is requested - if (settings->contains (ed_comment_str.key)) - // new version (radio buttons) - comment_string = settings->value (ed_comment_str).toInt (); - else - // old version (combo box) - comment_string = settings->value (ed_comment_str_old.key, - ed_comment_str.def).toInt (); - - return (QStringList (ed_comment_strings.at (comment_string))); - } - else - { - QStringList c_str; - - // The possible uncommenting string(s) are requested - comment_string = settings->value (ed_uncomment_str).toInt (); - - for (int i = 0; i < ed_comment_strings_count; i++) - { - if (1 << i & comment_string) - c_str.append (ed_comment_strings.at (i)); - } - - return c_str; - } - + cmd_list_mac.at (i)->setAlternateKey (key); } #endif - case SCLEX_PERL: - case SCLEX_BASH: - case SCLEX_DIFF: - return QStringList ("#"); + // selection markers + + m_indicator_id = indicatorDefine (QsciScintilla::StraightBoxIndicator); + if (m_indicator_id == -1) + m_indicator_id = 1; + + setIndicatorDrawUnder (true, m_indicator_id); + + markerDefine (QsciScintilla::Minus, marker::selection); + + // init state of undo/redo action for this tab + emit status_update (isUndoAvailable (), isRedoAvailable ()); + } + + void octave_qscintilla::setCursorPosition (int line, int col) + { + QsciScintilla::setCursorPosition (line, col); + emit update_rowcol_indicator_signal (line, col); + } + + void octave_qscintilla::set_selection_marker_color (const QColor& c) + { + QColor ic = c; + ic.setAlphaF (0.45); + setIndicatorForegroundColor (ic, m_indicator_id); + setIndicatorOutlineColor (ic, m_indicator_id); - case SCLEX_CPP: - return QStringList ("//"); + setMarkerForegroundColor (c, marker::selection); + setMarkerBackgroundColor (c, marker::selection); + } + + // context menu requested + void octave_qscintilla::contextMenuEvent (QContextMenuEvent *e) + { +#if defined (HAVE_QSCI_VERSION_2_6_0) + QPoint global_pos, local_pos; // the menu's position + QMenu *context_menu = createStandardContextMenu (); // standard menu + + bool in_left_margin = false; - case SCLEX_BATCH: - return QStringList ("REM "); - } + // determine position depending on mouse or keyboard event + if (e->reason () == QContextMenuEvent::Mouse) + { + // context menu by mouse + global_pos = e->globalPos (); // global mouse position + local_pos = e->pos (); // local mouse position + if (e->x () < marginWidth (1) + marginWidth (2)) + in_left_margin = true; + } + else + { + // context menu by keyboard or other: get point of text cursor + get_global_textcursor_pos (&global_pos, &local_pos); + QRect editor_rect = geometry (); // editor rect mapped to global + editor_rect.moveTopLeft + (parentWidget ()->mapToGlobal (editor_rect.topLeft ())); + if (! editor_rect.contains (global_pos)) // is cursor outside editor? + global_pos = editor_rect.topLeft (); // yes, take top left corner + } - return QStringList ("%"); // should never happen -} +# if defined (HAVE_QSCI_VERSION_2_6_0) + if (! in_left_margin) +# endif + { + // fill context menu with editor's standard actions + emit create_context_menu_signal (context_menu); + + // additional custom entries of the context menu + context_menu->addSeparator (); // separator before custom entries -// provide the style at a specific position -int octave_qscintilla::get_style (int pos) -{ - int position; - if (pos < 0) - // The positition has to be reduced by 2 for getting the real style (?) - position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS) - 2; - else - position = pos; + // help menu: get the position of the mouse or the text cursor + // (only for octave files) + QString lexer_name = lexer ()->lexer (); + if (lexer_name == "octave" || lexer_name == "matlab") + { + m_word_at_cursor = wordAtPoint (local_pos); + if (! m_word_at_cursor.isEmpty ()) + { + context_menu->addAction (tr ("Help on") + ' ' + m_word_at_cursor, + this, &octave_qscintilla::contextmenu_help); + context_menu->addAction (tr ("Documentation on") + + ' ' + m_word_at_cursor, + this, &octave_qscintilla::contextmenu_doc); + context_menu->addAction (tr ("Edit") + ' ' + m_word_at_cursor, + this, &octave_qscintilla::contextmenu_edit); + } + } + } +# if defined (HAVE_QSCI_VERSION_2_6_0) + else + { + // remove all standard actions from scintilla + QList all_actions = context_menu->actions (); + + for (auto *a : all_actions) + context_menu->removeAction (a); + + QAction *act + = context_menu->addAction (tr ("dbstop if ..."), this, + &octave_qscintilla::contextmenu_break_condition); + act->setData (local_pos); + } +# endif + + // finally show the menu + context_menu->exec (global_pos); + +#else + + octave_unused_parameter (e); + +#endif + } + + // common function with flag for documentation + void octave_qscintilla::contextmenu_help_doc (bool documentation) + { + if (documentation) + { + std::string name = m_word_at_cursor.toStdString (); + + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD - return SendScintilla (QsciScintillaBase::SCI_GETSTYLEAT, position); -} + 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 () + { + if (get_actual_word ()) + contextmenu_edit (true); + } + + // call edit the function related to the current word + void octave_qscintilla::context_run () + { + if (hasSelectedText ()) + { + contextmenu_run (true); + + emit interpreter_event + ([] (interpreter&) + { command_editor::erase_empty_line (false); }); + } + } -// Is a specific cursor position in a line or block comment? -int octave_qscintilla::is_style_comment (int pos) -{ - int lexer = SendScintilla (QsciScintillaBase::SCI_GETLEXER); - int style = get_style (pos); + void octave_qscintilla::get_global_textcursor_pos (QPoint *global_pos, + QPoint *local_pos) + { + long position = SendScintilla (SCI_GETCURRENTPOS); + long point_x = SendScintilla (SCI_POINTXFROMPOSITION, 0, position); + long point_y = SendScintilla (SCI_POINTYFROMPOSITION, 0, position); + *local_pos = QPoint (point_x, point_y); // local cursor position + *global_pos = mapToGlobal (*local_pos); // global position of cursor + } + + // determine the actual word and whether we are in an octave or matlab script + bool octave_qscintilla::get_actual_word () + { + QPoint global_pos, local_pos; + get_global_textcursor_pos (&global_pos, &local_pos); + m_word_at_cursor = wordAtPoint (local_pos); + QString lexer_name = lexer ()->lexer (); + return ((lexer_name == "octave" || lexer_name == "matlab") + && ! m_word_at_cursor.isEmpty ()); + } + + // helper function for clearing all indicators of a specific style + void octave_qscintilla::clear_selection_markers () + { + int end_pos = text ().length (); + int end_line, end_col; + lineIndexFromPosition (end_pos, &end_line, &end_col); + clearIndicatorRange (0, 0, end_line, end_col, m_indicator_id); + + markerDeleteAll (marker::selection); + } - switch (lexer) - { - case SCLEX_CPP: - return (ST_LINE_COMMENT * (style == QsciLexerCPP::CommentLine - || style == QsciLexerCPP::CommentLineDoc) - + ST_BLOCK_COMMENT * (style == QsciLexerCPP::Comment - || style == QsciLexerCPP::CommentDoc - || style == QsciLexerCPP::CommentDocKeyword - || style == QsciLexerCPP::CommentDocKeywordError)); + QString octave_qscintilla::eol_string () + { + switch (eolMode ()) + { + case QsciScintilla::EolWindows: + return ("\r\n"); + case QsciScintilla::EolMac: + return ("\r"); + case QsciScintilla::EolUnix: + return ("\n"); + } + + // Last resort, if the above goes wrong (should never happen) + return ("\r\n"); + } + + // Function returning the true cursor position where the tab length + // is taken into account. + void octave_qscintilla::get_current_position (int *pos, int *line, int *col) + { + *pos = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS); + *line = SendScintilla (QsciScintillaBase::SCI_LINEFROMPOSITION, *pos); + *col = SendScintilla (QsciScintillaBase::SCI_GETCOLUMN, *pos); + } + + // Function returning the comment string of the current lexer + QStringList octave_qscintilla::comment_string (bool comment) + { + int lexer = SendScintilla (SCI_GETLEXER); -#if defined (HAVE_LEXER_MATLAB) - case SCLEX_MATLAB: - return (ST_LINE_COMMENT * (style == QsciLexerMatlab::Comment)); + switch (lexer) + { +#if defined (HAVE_LEXER_OCTAVE) || defined (HAVE_LEXER_MATLAB) +#if defined (HAVE_LEXER_OCTAVE) + case SCLEX_OCTAVE: +#else + case SCLEX_MATLAB: #endif -#if defined (HAVE_LEXER_OCTAVE) - case SCLEX_OCTAVE: - return (ST_LINE_COMMENT * (style == QsciLexerOctave::Comment)); + { + gui_settings settings; + + int comment_string; + + if (comment) + { + // The commenting string is requested + if (settings.contains (ed_comment_str.settings_key ())) + // new version (radio buttons) + comment_string = settings.int_value (ed_comment_str); + else + // old version (combo box) + comment_string = settings.value (ed_comment_str_old.settings_key (), + ed_comment_str.def ()).toInt (); + + return (QStringList (ed_comment_strings.at (comment_string))); + } + else + { + QStringList c_str; + + // The possible uncommenting string(s) are requested + comment_string = settings.int_value (ed_uncomment_str); + + for (int i = 0; i < ed_comment_strings_count; i++) + { + if (1 << i & comment_string) + c_str.append (ed_comment_strings.at (i)); + } + + return c_str; + } + + } #endif - case SCLEX_PERL: - return (ST_LINE_COMMENT * (style == QsciLexerPerl::Comment)); - - case SCLEX_BATCH: - return (ST_LINE_COMMENT * (style == QsciLexerBatch::Comment)); - - case SCLEX_DIFF: - return (ST_LINE_COMMENT * (style == QsciLexerDiff::Comment)); - - case SCLEX_BASH: - return (ST_LINE_COMMENT * (style == QsciLexerBash::Comment)); - - } - - return ST_NONE; -} + case SCLEX_PERL: + case SCLEX_BASH: + case SCLEX_DIFF: + return QStringList ("#"); -// Do smart indentation after if, for, ... -void octave_qscintilla::smart_indent (bool do_smart_indent, int do_auto_close, - int line, int ind_char_width) -{ - QString prevline = text (line); + case SCLEX_CPP: + return QStringList ("//"); - QRegExp bkey = QRegExp ("^[\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]*([%#][^\"']*)?$"); + case SCLEX_BATCH: + return QStringList ("REM "); + } - // 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]*(?:[%#].*)?$"); + return QStringList ("%"); // should never happen + } - int bpos = bkey.indexIn (prevline, 0); - int epos; - - if (bpos > -1) - { - // 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); + // provide the style at a specific position + int octave_qscintilla::get_style (int pos) + { + int position; + if (pos < 0) + // The positition has to be reduced by 2 for getting the real style (?) + position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS) - 2; + else + position = pos; - if (do_smart_indent && ! inline_end) - { - // Do smart indent in the current line (line+1) - indent (line+1); - setCursorPosition (line+1, indentation (line+1) / ind_char_width); - } + return SendScintilla (QsciScintillaBase::SCI_GETSTYLEAT, position); + } - if (do_auto_close - && ! inline_end - && ! first_word.contains (QRegExp ("(?:case|otherwise|unwind_protect_cleanup)"))) - { - // Do auto close - auto_close (do_auto_close, line, prevline, first_word); - } - - return; - } - - QRegExp mkey = QRegExp ("^[\t ]*(?:else|elseif|catch|unwind_protect_cleanup)" - "[\r]?[\t #%\n]"); - if (prevline.contains (mkey)) - { - int prev_ind = indentation (line-1); - int act_ind = indentation (line); + // Is a specific cursor position in a line or block comment? + int octave_qscintilla::is_style_comment (int pos) + { + int lexer = SendScintilla (QsciScintillaBase::SCI_GETLEXER); + int style = get_style (pos); - if (prev_ind == act_ind) - unindent (line); - else if (prev_ind > act_ind) - { - setIndentation (line+1, prev_ind); - setCursorPosition (line+1, prev_ind); - } - return; - } - - QRegExp case_key = QRegExp ("^[\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); + switch (lexer) + { + case SCLEX_CPP: + return (ST_LINE_COMMENT * (style == QsciLexerCPP::CommentLine + || style == QsciLexerCPP::CommentLineDoc) + + ST_BLOCK_COMMENT * (style == QsciLexerCPP::Comment + || style == QsciLexerCPP::CommentDoc + || style == QsciLexerCPP::CommentDocKeyword + || style == QsciLexerCPP::CommentDocKeywordError)); - if (last_line.contains (QRegExp ("^[\t ]*switch"))) - { - indent (line+1); - act_ind = indentation (line+1); - } - else - { - if (prev_ind == act_ind) - unindent (line); - else if (prev_ind > act_ind) - act_ind = prev_ind; - } - - setIndentation (line+1, act_ind); - setCursorPosition (line+1, act_ind); - } +#if defined (HAVE_LEXER_MATLAB) + case SCLEX_MATLAB: + return (ST_LINE_COMMENT * (style == QsciLexerMatlab::Comment)); +#endif +#if defined (HAVE_LEXER_OCTAVE) + case SCLEX_OCTAVE: + return (ST_LINE_COMMENT * (style == QsciLexerOctave::Comment)); +#endif - ekey = QRegExp ("^[\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)) - { - unindent (line+1); - unindent (line); - if (prevline.contains ("endswitch")) - { - // endswitch has to me unndented twice - unindent (line+1); - unindent (line); - } - setCursorPosition (line+1, - indentation (line)); - } - return; - } -} + case SCLEX_PERL: + return (ST_LINE_COMMENT * (style == QsciLexerPerl::Comment)); -// Do smart indentation of current selection or line. -void octave_qscintilla::smart_indent_line_or_selected_text (int lineFrom, - int lineTo) -{ - QRegExp blank_line_regexp = QRegExp ("^[\t ]*$"); + case SCLEX_BATCH: + return (ST_LINE_COMMENT * (style == QsciLexerBatch::Comment)); + + case SCLEX_DIFF: + return (ST_LINE_COMMENT * (style == QsciLexerDiff::Comment)); - // end[xxxxx] [# comment] at end of a line - QRegExp end_word_regexp - = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" - "(?:end\\w*)[\r\n\t ;]*(?:[%#].*)?$"); + case SCLEX_BASH: + return (ST_LINE_COMMENT * (style == QsciLexerBash::Comment)); - 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 #%]"); + } - QRegExp mid_block_regexp - = QRegExp ("^[\t ]*(?:elseif|else" - "|unwind_protect_cleanup|catch)" - "[\r\n\t #%]"); + return ST_NONE; + } - 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 #%]"); - - QRegExp case_block_regexp - = QRegExp ("^[\t ]*(?:case|otherwise)" - "[\r\n\t #%]"); + // Do smart indentation after if, for, ... + void octave_qscintilla::smart_indent (bool do_smart_indent, int do_auto_close, + int line, int ind_char_width) + { + QString prevline = text (line); - int indent_column = -1; - int indent_increment = indentationWidth (); - bool in_switch = false; - - for (int line = lineFrom-1; line >= 0; line--) - { - QString line_text = text (line); - - if (blank_line_regexp.indexIn (line_text) < 0) - { - // Found first non-blank line above beginning of region or - // current line. Base indentation from this line, increasing - // indentation by indentationWidth if it looks like the - // beginning of a code block. - - indent_column = indentation (line); + QRegExp bkey = QRegExp ("^[\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]*([%#][^\"']*)?$"); - if (begin_block_regexp.indexIn (line_text) > -1) - { - indent_column += indent_increment; - if (line_text.contains ("switch")) - in_switch = true; - } + // 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]*(?:[%#].*)?$"); - break; - } - } - - if (indent_column < 0) - indent_column = indentation (lineFrom); - - QString prev_line; - for (int line = lineFrom; line <= lineTo; line++) - { - QString line_text = text (line); + int bpos = bkey.indexIn (prevline, 0); + int epos; - if (end_block_regexp.indexIn (line_text) > -1) - { - indent_column -= indent_increment; - if (line_text.contains ("endswitch")) - { - // need a double de-indent for endswitch - if (in_switch) - indent_column -= indent_increment; - in_switch = false; - } - } + if (bpos > -1) + { + // Found keyword after that indentation should be added - if (mid_block_regexp.indexIn (line_text) > -1) - indent_column -= indent_increment; - - if (case_block_regexp.indexIn (line_text) > -1) - { - if (case_block_regexp.indexIn (prev_line) < 0 - && !prev_line.contains("switch")) - indent_column -= indent_increment; - in_switch = true; - } - - setIndentation (line, indent_column); + // 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); - int bpos = begin_block_regexp.indexIn (line_text); - if (bpos > -1) - { - // Check for existing end statement in the same line - int epos = end_word_regexp.indexIn (line_text, bpos); - if (epos == -1) - indent_column += indent_increment; - if (line_text.contains ("switch")) - in_switch = true; - } + if (do_smart_indent && ! inline_end) + { + // Do smart indent in the current line (line+1) + indent (line+1); + setCursorPosition (line+1, indentation (line+1) / ind_char_width); + } - if (blank_line_regexp.indexIn (line_text) < 0) - prev_line = line_text; - } -} - -void octave_qscintilla::set_word_selection (const QString& word) -{ - m_selection = word; - - if (word.isEmpty ()) - { - m_selection_line = -1; - m_selection_col = -1; + if (do_auto_close + && ! inline_end + && ! first_word.contains (QRegExp ("(?:case|otherwise|unwind_protect_cleanup)"))) + { + // Do auto close + auto_close (do_auto_close, line, prevline, first_word); + } - m_selection_replacement = ""; - - clear_selection_markers (); + return; + } - QToolTip::hideText (); - } - else - { - int pos; - get_current_position (&pos, &m_selection_line, &m_selection_col); - } -} - -void octave_qscintilla::show_selection_markers (int l1, int c1, int l2, int c2) -{ - fillIndicatorRange (l1, c1, l2, c2, m_indicator_id); - - if (l1 == l2) - markerAdd (l1, marker::selection); -} + QRegExp mkey = QRegExp ("^[\t ]*(?:else|elseif|catch|unwind_protect_cleanup)" + "[\r]?[\t #%\n]"); + if (prevline.contains (mkey)) + { + int prev_ind = indentation (line-1); + int act_ind = indentation (line); -void octave_qscintilla::contextmenu_help (bool) -{ - contextmenu_help_doc (false); -} - -void octave_qscintilla::contextmenu_doc (bool) -{ - contextmenu_help_doc (true); -} - -void octave_qscintilla::context_help_doc (bool documentation) -{ - if (get_actual_word ()) - contextmenu_help_doc (documentation); -} - -void octave_qscintilla::contextmenu_edit (bool) -{ - emit context_menu_edit_signal (m_word_at_cursor); -} + if (prev_ind == act_ind) + unindent (line); + else if (prev_ind > act_ind) + { + setIndentation (line+1, prev_ind); + setCursorPosition (line+1, prev_ind); + } + return; + } -void octave_qscintilla::contextmenu_run_temp_error (void) -{ - QMessageBox::critical (this, tr ("Octave Editor"), - tr ("Creating temporary files failed.\n" - "Make sure you have write access to temp. directory\n" - "%1\n\n" - "\"Run Selection\" requires temporary files.").arg (QDir::tempPath ())); -} - -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 (); + QRegExp case_key = QRegExp ("^[\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); - // Split contents into single lines and complete commands - QStringList lines = selectedText ().split (QRegExp ("[\r\n]"), -#if defined (HAVE_QT_SPLITBEHAVIOR_ENUM) - Qt::SkipEmptyParts); -#else - 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; + if (last_line.contains (QRegExp ("^[\t ]*switch"))) + { + indent (line+1); + act_ind = indentation (line+1); + } + else + { + if (prev_ind == act_ind) + unindent (line); + else if (prev_ind > act_ind) + act_ind = prev_ind; + } - // 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);"; + setIndentation (line+1, act_ind); + setCursorPosition (line+1, act_ind); } - // Add codeline - code += next_bp_quiet + line + next_bp_quiet_reset + "\n"; - hist += line_history + "\n"; + ekey = QRegExp ("^[\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)) + { + unindent (line+1); + unindent (line); + if (prevline.contains ("endswitch")) + { + // endswitch has to me unndented twice + unindent (line+1); + unindent (line); + } + setCursorPosition (line+1, + indentation (line)); + } + return; + } } -octave_stdout << hist.toStdString (); + // Do smart indentation of current selection or line. + void octave_qscintilla::smart_indent_line_or_selected_text (int lineFrom, + int lineTo) + { + QRegExp blank_line_regexp = QRegExp ("^[\t ]*$"); + + // end[xxxxx] [# comment] at end of a line + QRegExp end_word_regexp + = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" + "(?: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 #%]"); + + QRegExp mid_block_regexp + = QRegExp ("^[\t ]*(?:elseif|else" + "|unwind_protect_cleanup|catch)" + "[\r\n\t #%]"); -// Create tmp file with the code to be executed by the interpreter -QPointer tmp_file -= rmgr.create_tmp_file ("m", code); + 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 #%]"); + + QRegExp case_block_regexp + = QRegExp ("^[\t ]*(?:case|otherwise)" + "[\r\n\t #%]"); + + int indent_column = -1; + int indent_increment = indentationWidth (); + bool in_switch = false; + + for (int line = lineFrom-1; line >= 0; line--) + { + QString line_text = text (line); + + if (blank_line_regexp.indexIn (line_text) < 0) + { + // Found first non-blank line above beginning of region or + // current line. Base indentation from this line, increasing + // indentation by indentationWidth if it looks like the + // beginning of a code block. + + indent_column = indentation (line); -bool tmp = (tmp_file && tmp_file->open ()); -if (! tmp) - { - // tmp files not working: use old way to run selection - contextmenu_run_temp_error (); - return; + if (begin_block_regexp.indexIn (line_text) > -1) + { + indent_column += indent_increment; + if (line_text.contains ("switch")) + in_switch = true; + } + + break; + } + } + + if (indent_column < 0) + indent_column = indentation (lineFrom); + + QString prev_line; + for (int line = lineFrom; line <= lineTo; line++) + { + QString line_text = text (line); + + if (end_block_regexp.indexIn (line_text) > -1) + { + indent_column -= indent_increment; + if (line_text.contains ("endswitch")) + { + // need a double de-indent for endswitch + if (in_switch) + indent_column -= indent_increment; + in_switch = false; + } + } + + if (mid_block_regexp.indexIn (line_text) > -1) + indent_column -= indent_increment; + + if (case_block_regexp.indexIn (line_text) > -1) + { + if (case_block_regexp.indexIn (prev_line) < 0 + && !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) + { + // Check for existing end statement in the same line + int epos = end_word_regexp.indexIn (line_text, bpos); + if (epos == -1) + indent_column += indent_increment; + if (line_text.contains ("switch")) + in_switch = true; + } + + if (blank_line_regexp.indexIn (line_text) < 0) + prev_line = line_text; + } } -tmp_file->close (); + void octave_qscintilla::set_word_selection (const QString& word) + { + m_selection = word; -// Create tmp file required for adding command to history -QPointer tmp_hist -= rmgr.create_tmp_file ("", hist); // empty tmp file for history + if (word.isEmpty ()) + { + m_selection_line = -1; + m_selection_col = -1; + + m_selection_replacement = ""; + + clear_selection_markers (); -tmp = (tmp_hist && tmp_hist->open ()); -if (! tmp) + QToolTip::hideText (); + } + else + { + int pos; + get_current_position (&pos, &m_selection_line, &m_selection_col); + } + } + + void octave_qscintilla::show_selection_markers (int l1, int c1, int l2, int c2) { - // tmp files not working: use old way to run selection - contextmenu_run_temp_error (); - return; + fillIndicatorRange (l1, c1, l2, c2, m_indicator_id); + + if (l1 == l2) + markerAdd (l1, marker::selection); + } + + void octave_qscintilla::contextmenu_help (bool) + { + contextmenu_help_doc (false); } -tmp_hist->close (); + void octave_qscintilla::contextmenu_doc (bool) + { + contextmenu_help_doc (true); + } -// Add commands to the history -emit interpreter_event -([=] (interpreter& interp) - { - // INTERPRETER THREAD + void octave_qscintilla::context_help_doc (bool documentation) + { + if (get_actual_word ()) + contextmenu_help_doc (documentation); + } - if (tmp_hist.isNull ()) - return; + void octave_qscintilla::contextmenu_edit (bool) + { + emit context_menu_edit_signal (m_word_at_cursor); + } - std::string opt = "-r"; - std::string path = tmp_hist->fileName ().toStdString (); - - Fhistory (interp, ovl (opt, path)); - }); + void octave_qscintilla::contextmenu_run_temp_error () + { + QMessageBox::critical (this, tr ("Octave Editor"), + tr ("Creating temporary files failed.\n" + "Make sure you have write access to temp. directory\n" + "%1\n\n" + "\"Run Selection\" requires temporary files.").arg (QDir::tempPath ())); + } -// 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. + void octave_qscintilla::contextmenu_run (bool) + { + // 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 (); -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; + // Split contents into single lines and complete commands + QStringList lines = selectedText ().split (QRegExp ("[\r\n]"), +#if defined (HAVE_QT_SPLITBEHAVIOR_ENUM) + Qt::SkipEmptyParts); +#else + 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; - 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 + // 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);"; + } - // 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 (); + // Add codeline + code += next_bp_quiet + line + next_bp_quiet_reset + "\n"; + hist += line_history + "\n"; + } + + octave_stdout << hist.toStdString (); + + // Create tmp file with the code to be executed by the interpreter + QPointer tmp_file = create_tmp_file ("m", code); - try - { - // Do the job - interp.source_file (file); - } - catch (const execution_exception& ee) - { - // Catch errors otherwise the rest of the interpreter - // will not be executed (cleaning up). + 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 = create_tmp_file ("", hist); - // New error message and error stack - QString new_msg = QString::fromStdString (ee.message ()); - std::list stack = ee.stack_info (); + 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; + } + + // Add commands to the history + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + if (tmp_hist.isNull ()) + return; + + std::string opt = "-r"; + std::string path = tmp_hist->fileName ().toStdString (); + + Fhistory (interp, ovl (opt, path)); + }); - // 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) - { - QRegExp 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]*$"; + // Disable opening a file at a breakpoint in case keyboard () is used + gui_settings settings; + + bool show_dbg_file = settings.bool_value (ed_show_dbg_file); + settings.setValue (ed_show_dbg_file.settings_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. + + QPointer this_oq (this); + + // Let the interpreter execute the tmp file + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD - QStringList replace_list; - replace_list << "\n"; - replace_list << ""; + // 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; + + std::string file = tmp_file->fileName ().toStdString (); - 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) - { - err_line = rx.cap (1).toInt (); - new_msg = new_msg.replace (rx, replace_list.at (i)); - } - } - } - } + std::string pending_input = command_editor::get_current_line (); + + int err_line = -1; // For storing the line of a poss. error - // 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); + // 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 (); - // New exception with updated message and stack - execution_exception nee (ee.err_type (), ee.identifier (), - new_msg.toStdString (), stack); + try + { + // Do the job + interp.source_file (file); + } + catch (const execution_exception& ee) + { + // Catch errors otherwise the rest of the interpreter + // will not be executed (cleaning up). - // Throw - throw (nee); - } - - // Clean up + // New error message and error stack + QString new_msg = QString::fromStdString (ee.message ()); + std::list stack = ee.stack_info (); - 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); - - }); -} + // 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) + { + QRegExp 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]*$"; -void octave_qscintilla::ctx_menu_run_finished (bool show_dbg_file, int, - QTemporaryFile* tmp_file, QTemporaryFile* tmp_hist, - bool dbg, bool auto_repeat) -{ - emit focus_console_after_command_signal (); + QStringList replace_list; + replace_list << "\n"; + replace_list << ""; - // TODO: Use line nr. (int argument) of possible error for removing - // 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); + 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) + { + err_line = rx.cap (1).toInt (); + new_msg = new_msg.replace (rx, replace_list.at (i)); + } + } + } + } - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - if (dbg) - Fauto_repeat_debug_command (interp, ovl (auto_repeat)); - }); -} + // 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 (); -// wrappers for dbstop related context menu items + // 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); -// FIXME: Why can't the data be sent as the argument to the function??? -void octave_qscintilla::contextmenu_break_condition (bool) -{ -#if defined (HAVE_QSCI_VERSION_2_6_0) - QAction *action = qobject_cast(sender ()); - QPoint local_pos = action->data ().value (); + // New exception with updated message and stack + execution_exception nee (ee.err_type (), ee.identifier (), + new_msg.toStdString (), stack); + + // Throw + throw (nee); + } - // pick point just right of margins, so lineAt doesn't give -1 - int margins = marginWidth (1) + marginWidth (2) + marginWidth (3); - local_pos = QPoint (margins + 1, local_pos.y ()); + // Clean up + + emit ctx_menu_run_finished_signal (show_dbg_file, err_line, + tmp_file, tmp_hist, + dbg, auto_repeat); - emit context_menu_break_condition_signal (lineAt (local_pos)); -#endif -} + 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::contextmenu_break_once (const QPoint& local_pos) -{ -#if defined (HAVE_QSCI_VERSION_2_6_0) - emit context_menu_break_once (lineAt (local_pos)); -#else - octave_unused_parameter (local_pos); -#endif -} + 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 (); -void octave_qscintilla::text_changed (void) -{ - emit status_update (isUndoAvailable (), isRedoAvailable ()); -} + // TODO: Use line nr. (int argument) of possible error for removing + // lines from history that were never executed. For this, + // possible lines from commands at a debug prompt must be + // taken into consideration. + + gui_settings settings; -void octave_qscintilla::cursor_position_changed (int line, int col) -{ - // Clear the selection if we move away from it. We have to check the - // position, because we allow entering text at the point of the - // selection to trigger a search and replace that does not clear the - // selection until it is complete. + 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 (); - if (! m_selection.isEmpty () - && (line != m_selection_line || col != m_selection_col)) - set_word_selection (); -} + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + if (dbg) + Fauto_repeat_debug_command (interp, ovl (auto_repeat)); + }); + } -// when edit area gets focus update information on undo/redo actions -void octave_qscintilla::focusInEvent (QFocusEvent *focusEvent) -{ - emit status_update (isUndoAvailable (), isRedoAvailable ()); + // wrappers for dbstop related context menu items - QsciScintilla::focusInEvent (focusEvent); -} + // FIXME: Why can't the data be sent as the argument to the function??? + void octave_qscintilla::contextmenu_break_condition (bool) + { +#if defined (HAVE_QSCI_VERSION_2_6_0) + QAction *action = qobject_cast(sender ()); + QPoint local_pos = action->data ().value (); -void octave_qscintilla::show_replace_action_tooltip (void) -{ - int pos; - get_current_position (&pos, &m_selection_line, &m_selection_col); + // pick point just right of margins, so lineAt doesn't give -1 + int margins = marginWidth (1) + marginWidth (2) + marginWidth (3); + local_pos = QPoint (margins + 1, local_pos.y ()); - // Offer to replace other instances. - - QKeySequence keyseq = Qt::SHIFT + Qt::Key_Return; + emit context_menu_break_condition_signal (lineAt (local_pos)); +#endif + } - QString msg = (tr ("Press '%1' to replace all occurrences of '%2' with '%3'.") - . arg (keyseq.toString ()) - . arg (m_selection) - . arg (m_selection_replacement)); + void octave_qscintilla::contextmenu_break_once (const QPoint& local_pos) + { +#if defined (HAVE_QSCI_VERSION_2_6_0) + emit context_menu_break_once (lineAt (local_pos)); +#else + octave_unused_parameter (local_pos); +#endif + } - QPoint global_pos; - QPoint local_pos; - - get_global_textcursor_pos (&global_pos, &local_pos); - - QFontMetrics ttfm (QToolTip::font ()); + void octave_qscintilla::text_changed () + { + emit status_update (isUndoAvailable (), isRedoAvailable ()); + } - // Try to avoid overlapping with the text completion dialog - // and the text that is currently being edited. + void octave_qscintilla::cursor_position_changed (int line, int col) + { + // Clear the selection if we move away from it. We have to check the + // position, because we allow entering text at the point of the + // selection to trigger a search and replace that does not clear the + // selection until it is complete. - global_pos += QPoint (2*ttfm.maxWidth (), -3*ttfm.height ()); - - QToolTip::showText (global_pos, msg); -} + if (! m_selection.isEmpty () + && (line != m_selection_line || col != m_selection_col)) + set_word_selection (); + } -void octave_qscintilla::replace_all (const QString& o_str, const QString& n_str, - bool re, bool cs, bool wo) -{ - // get the resulting cursor position - int pos, line, col, nline, ncol; - get_current_position (&pos, &line, &col); + // when edit area gets focus update information on undo/redo actions + void octave_qscintilla::focusInEvent (QFocusEvent *focusEvent) + { + emit status_update (isUndoAvailable (), isRedoAvailable ()); + + QsciScintilla::focusInEvent (focusEvent); + } - // remember first visible line for restoring the view afterwards - int first_line = firstVisibleLine (); + 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; - // search for first occurrence of the detected word - bool find_result_available = findFirst (o_str, re, cs, wo, - false, true, 0, 0); - // replace and find more occurrences in a loop - beginUndoAction (); - while (find_result_available) - { - // findNext doesn't work properly if the length of the replacement - // text is different from the original - replace (n_str); - get_current_position (&pos, &nline, &ncol); + QString msg = (tr ("Press '%1' to replace all occurrences of '%2' with '%3'.") + . arg (keyseq.toString ()) + . arg (m_selection) + . arg (m_selection_replacement)); + + QPoint global_pos; + QPoint local_pos; + + get_global_textcursor_pos (&global_pos, &local_pos); + + QFontMetrics ttfm (QToolTip::font ()); + + // Try to avoid overlapping with the text completion dialog + // and the text that is currently being edited. - find_result_available = findFirst (o_str, re, cs, wo, - false, true, nline, ncol); - } - endUndoAction (); + global_pos += QPoint (2*ttfm.maxWidth (), -3*ttfm.height ()); - // restore the visible area - setFirstVisibleLine (first_line); + QToolTip::showText (global_pos, msg); + } - // fix cursor column if outside of new line length - int eol_len = eol_string ().length (); - if (line == lines () - 1) - eol_len = 0; - const int col_max = text (line).length () - eol_len; - if (col_max < col) - col = col_max; + void octave_qscintilla::replace_all (const QString& o_str, const QString& n_str, + bool re, bool cs, bool wo) + { + // get the resulting cursor position + int pos, line, col, nline, ncol; + get_current_position (&pos, &line, &col); - setCursorPosition (line, col); -} + // remember first visible line for restoring the view afterwards + int first_line = firstVisibleLine (); -bool octave_qscintilla::event (QEvent *e) -{ - 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(); - } + // search for first occurrence of the detected word + bool find_result_available = findFirst (o_str, re, cs, wo, + false, true, 0, 0); + // replace and find more occurrences in a loop + beginUndoAction (); + while (find_result_available) + { + // findNext doesn't work properly if the length of the replacement + // text is different from the original + replace (n_str); + get_current_position (&pos, &nline, &ncol); + + find_result_available = findFirst (o_str, re, cs, wo, + false, true, nline, ncol); + } + endUndoAction (); - return true; - } + // restore the visible area + setFirstVisibleLine (first_line); - return QsciScintilla::event(e); -} + // fix cursor column if outside of new line length + int eol_len = eol_string ().length (); + if (line == lines () - 1) + eol_len = 0; + const int col_max = text (line).length () - eol_len; + if (col_max < col) + col = col_max; + + setCursorPosition (line, col); + } + + bool octave_qscintilla::event (QEvent *e) + { + if (m_debug_mode && e->type() == QEvent::ToolTip) + { + // FIXME: can we handle display of a tooltip using an + // interpreter event or a custom signal/slot connection? -void octave_qscintilla::keyPressEvent (QKeyEvent *key_event) -{ - if (m_selection.isEmpty ()) - QsciScintilla::keyPressEvent (key_event); - else - { - int key = key_event->key (); - Qt::KeyboardModifiers modifiers = key_event->modifiers (); + QHelpEvent *help_e = static_cast (e); + QString symbol = wordAtPoint (help_e->pos()); + + emit show_symbol_tooltip_signal (help_e->globalPos (), symbol); + + return true; + } - if (key == Qt::Key_Return && modifiers == Qt::ShiftModifier) - { - replace_all (m_selection, m_selection_replacement, - false, true, true); + return QsciScintilla::event(e); + } + + void octave_qscintilla::keyPressEvent (QKeyEvent *key_event) + { + if (m_selection.isEmpty ()) + QsciScintilla::keyPressEvent (key_event); + else + { + int key = key_event->key (); + Qt::KeyboardModifiers modifiers = key_event->modifiers (); - // Clear the selection. - set_word_selection (); - } - else - { - // The idea here is to allow backspace to remove the last - // character of the replacement text to allow minimal editing - // and to also end the selection replacement action if text is - // not valid as a word constituent (control characters, - // etc.). Is there a better way than having special cases for - // DEL and ESC here? - - QString text = key_event->text (); + if (key == Qt::Key_Return && modifiers == Qt::ShiftModifier) + { + replace_all (m_selection, m_selection_replacement, + false, true, true); - bool cancel_replacement = false; + // Clear the selection. + set_word_selection (); + } + else + { + // The idea here is to allow backspace to remove the last + // character of the replacement text to allow minimal editing + // and to also end the selection replacement action if text is + // not valid as a word constituent (control characters, + // etc.). Is there a better way than having special cases for + // DEL and ESC here? - if (key == Qt::Key_Backspace) - { - if (m_selection_replacement.isEmpty ()) - cancel_replacement = true; - else - m_selection_replacement.chop (1); - } - else if (key == Qt::Key_Delete || key == Qt::Key_Escape) - cancel_replacement = true; - else if (! text.isEmpty ()) - m_selection_replacement += text; - else if (modifiers != Qt::ShiftModifier) - cancel_replacement = true; + QString text = key_event->text (); + + bool cancel_replacement = false; - // Perform default action. + if (key == Qt::Key_Backspace) + { + if (m_selection_replacement.isEmpty ()) + cancel_replacement = true; + else + m_selection_replacement.chop (1); + } + else if (key == Qt::Key_Delete || key == Qt::Key_Escape) + cancel_replacement = true; + else if (! text.isEmpty ()) + m_selection_replacement += text; + else if (modifiers != Qt::ShiftModifier) + cancel_replacement = true; - QsciScintilla::keyPressEvent (key_event); + // Perform default action. - if (cancel_replacement) - set_word_selection (); + QsciScintilla::keyPressEvent (key_event); - if (! m_selection_replacement.isEmpty ()) - show_replace_action_tooltip (); - } - } -} + if (cancel_replacement) + set_word_selection (); + + if (! m_selection_replacement.isEmpty ()) + show_replace_action_tooltip (); + } + } + } -void octave_qscintilla::auto_close (int auto_endif, int linenr, - const QString& line, QString& first_word) -{ - // Insert an "end" for an "if" etc., if needed. - // (Use of "while" allows "return" to skip the rest. - // It may be clearer to use "if" and "goto", - // but that violates the coding standards.) + void octave_qscintilla::auto_close (int auto_endif, int linenr, + const QString& line, QString& first_word) + { + // Insert an "end" for an "if" etc., if needed. + // (Use of "while" allows "return" to skip the rest. + // It may be clearer to use "if" and "goto", + // but that violates the coding standards.) - bool autofill_simple_end = (auto_endif == 2); + bool autofill_simple_end = (auto_endif == 2); - std::size_t start = line.toStdString ().find_first_not_of (" \t"); + std::size_t start = line.toStdString ().find_first_not_of (" \t"); - // Check if following line has the same or less indentation - // Check if the following line does not start with - // end* (until) (catch) - 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 - std::size_t next_start; - QString next_line; + // Check if following line has the same or less indentation + // Check if the following line does not start with + // end* (until) (catch) + 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 + std::size_t next_start; + QString next_line; - do // find next non-blank line - { - next_line = text (linenr + offset++); - next_start = next_line.toStdString ().find_first_not_of (" \t\n"); - } - while (linenr + offset < lines () - && next_start == std::string::npos); + do // find next non-blank line + { + next_line = text (linenr + offset++); + next_start = next_line.toStdString ().find_first_not_of (" \t\n"); + } + while (linenr + offset < lines () + && next_start == std::string::npos); - if (next_start == std::string::npos) - next_start = 0; - if (start == 0 && next_start == 0) - return; // bug #56160, don't add at 0 - if (next_start > start) // more indented => don't add "end" - 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)) - return; - } - } + if (next_start == std::string::npos) + next_start = 0; + if (start == 0 && next_start == 0) + return; // bug #56160, don't add at 0 + if (next_start > start) // more indented => don't add "end" + 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)) + return; + } + } - // If all of the above, insert a new line, with matching indent - // and either 'end' or 'end...', depending on a flag. + // If all of the above, insert a new line, with matching indent + // and either 'end' or 'end...', depending on a flag. + + // If we insert directly after the last line, the "end" is autoindented, + // so add a dummy line. + if (linenr + 2 == lines ()) + insertAt (QString ("\n"), linenr + 2, 0); - // If we insert directly after the last line, the "end" is autoindented, - // so add a dummy line. - if (linenr + 2 == lines ()) - insertAt (QString ("\n"), linenr + 2, 0); + // For try/catch/end, fill "end" first, so "catch" is top of undo stack + if (first_word == "try") + insertAt (QString (start, ' ') + + (autofill_simple_end ? "end\n" : "end_try_catch\n"), + linenr + 2, 0); + else if (first_word == "unwind_protect") + insertAt (QString (start, ' ') + + (autofill_simple_end ? "end\n" : "end_unwind_protect\n"), + linenr + 2, 0); - // For try/catch/end, fill "end" first, so "catch" is top of undo stack - if (first_word == "try") - insertAt (QString (start, ' ') - + (autofill_simple_end ? "end\n" : "end_try_catch\n"), - linenr + 2, 0); - else if (first_word == "unwind_protect") - insertAt (QString (start, ' ') - + (autofill_simple_end ? "end\n" : "end_unwind_protect\n"), - linenr + 2, 0); + QString next_line; + if (first_word == "do") + next_line = "until\n"; + else if (first_word == "try") + next_line = "catch\n"; + else if (first_word == "unwind_protect") + next_line = "unwind_protect_cleanup\n"; + else if (autofill_simple_end) + next_line = "end\n"; + else + { + if (first_word == "unwind_protect") + first_word = '_' + first_word; + next_line = "end" + first_word + "\n"; + } + + //insertAt (QString (start, ' ') + next_line, linenr + 2, 0); + insertAt (next_line, linenr + 2, 0); + setIndentation (linenr + 2, indentation (linenr)); + } - QString next_line; - if (first_word == "do") - next_line = "until\n"; - else if (first_word == "try") - next_line = "catch\n"; - else if (first_word == "unwind_protect") - next_line = "unwind_protect_cleanup\n"; - else if (autofill_simple_end) - next_line = "end\n"; - else - { - if (first_word == "unwind_protect") - first_word = '_' + first_word; - next_line = "end" + first_word + "\n"; - } + void octave_qscintilla::dragEnterEvent (QDragEnterEvent *e) + { + // if is not dragging a url, pass to qscintilla to handle, + // otherwise ignore it so that it will be handled by + // the parent + if (!e->mimeData ()->hasUrls ()) + { + QsciScintilla::dragEnterEvent (e); + } + else + { + e->ignore(); + } + } - //insertAt (QString (start, ' ') + next_line, linenr + 2, 0); - insertAt (next_line, linenr + 2, 0); - setIndentation (linenr + 2, indentation (linenr)); -} + void octave_qscintilla::handle_enter_debug_mode () + { + m_debug_mode = true; + } -void octave_qscintilla::dragEnterEvent (QDragEnterEvent *e) -{ - // if is not dragging a url, pass to qscintilla to handle, - // otherwise ignore it so that it will be handled by - // the parent - if (!e->mimeData ()->hasUrls ()) - { - QsciScintilla::dragEnterEvent (e); - } - else - { - e->ignore(); - } -} + 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; -void octave_qscintilla::handle_enter_debug_mode (void) -{ - m_debug_mode = true; -} + // 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)); -void octave_qscintilla::handle_exit_debug_mode (void) -{ - m_debug_mode = false; -} + if (! contents.isEmpty () && tmp_file && tmp_file->open ()) + { + tmp_file->write (contents.toUtf8 ()); + tmp_file->close (); + } + + return tmp_file; + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/octave-qscintilla.h --- a/libgui/src/m-editor/octave-qscintilla.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/octave-qscintilla.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/octave-txt-lexer.cc --- a/libgui/src/m-editor/octave-txt-lexer.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/octave-txt-lexer.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/m-editor/octave-txt-lexer.h --- a/libgui/src/m-editor/octave-txt-lexer.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/m-editor/octave-txt-lexer.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/main-window.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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" @@ -92,2836 +90,2811 @@ 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 ()) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - if (rmgr.is_first_run ()) - { - // Before wizard. - m_octave_qobj.config_translators (); - - welcome_wizard welcomeWizard (m_octave_qobj); - - if (welcomeWizard.exec () == QDialog::Rejected) - exit (1); - - // Install settings file. - rmgr.reload_settings (); - } - else - { - // Get settings file. - rmgr.reload_settings (); - - // After settings. - m_octave_qobj.config_translators (); - } - - setObjectName (gui_obj_name_main_window); - - rmgr.config_icon_theme (); - - rmgr.update_network_settings (); - - // We provide specific terminal capabilities, so ensure that - // TERM is always set appropriately. + 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_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 ()) + { + gui_settings settings; + + if (! settings.bool_value (global_skip_welcome_wizard)) + { + // Before wizard. + m_octave_qobj.config_translators (); + + welcome_wizard welcomeWizard; + + if (welcomeWizard.exec () == QDialog::Rejected) + exit (1); + + settings.setValue (global_skip_welcome_wizard.settings_key (), QVariant (true)); + + // Install settings file. + settings.reload (); + } + else + { + // Get settings file. + settings.reload (); + + // After settings. + m_octave_qobj.config_translators (); + } + + setObjectName (gui_obj_name_main_window); + + settings.config_icon_theme (); + + settings.update_network_settings (); + + // We provide specific terminal capabilities, so ensure that + // TERM is always set appropriately. #if defined (OCTAVE_USE_WINDOWS_API) - sys::env::putenv ("TERM", "cygwin"); + sys::env::putenv ("TERM", "cygwin"); #else - 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); - m_profiler_status_indicator = new led_indicator (); - QLabel *text = new QLabel (tr ("Profiler")); - m_status_bar->addPermanentWidget (text); - m_status_bar->addPermanentWidget (m_profiler_status_indicator); - - adopt_dock_widgets (); - -#if defined (HAVE_QGUIAPPLICATION_SETDESKTOPFILENAME) - QGuiApplication::setDesktopFileName ("org.octave.Octave.desktop"); + sys::env::putenv ("TERM", "xterm"); #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 (); - } - - QDateTime current = QDateTime::currentDateTime (); - QDateTime one_day_ago = current.addDays (-1); - - if (connect_to_web - && (! last_checked.isValid () || one_day_ago > last_checked)) - emit show_community_news_signal (serial); - - construct_octave_qt_link (); - - // We have to set up all our windows, before we finally launch - // octave. - - construct (); - - read_settings (); - - init_terminal_size (); - - emit init_window_menu (); - - focus_command_window (); -} - -main_window::~main_window (void) { } - -void main_window::adopt_dock_widgets (void) -{ - adopt_terminal_widget (); - adopt_documentation_widget (); - adopt_file_browser_widget (); - adopt_history_widget (); - adopt_workspace_widget (); - adopt_editor_widget (); - adopt_variable_editor_widget (); - - m_previous_dock = m_command_window; -} - -void main_window::adopt_terminal_widget (void) -{ - m_command_window = m_octave_qobj.terminal_widget (this); - - make_dock_widget_connections (m_command_window); - - connect (this, &main_window::settings_changed, - m_command_window, &terminal_dock_widget::notice_settings); - - if (! m_octave_qobj.experimental_terminal_widget ()) - { - QTerminal *cmd_widget = m_command_window->get_qterminal (); - - // The following connections were previously made in - // QTerminal::construct, QWinTerminalImpl::QWinTerminalImpl, and - // QUnixTerminalImpl::QUnixTerminalImpl. Similar actions should - // probably be possible for the new command widget. - - connect (cmd_widget, &QTerminal::report_status_message, - this, &main_window::report_status_message); - - connect (cmd_widget, &QTerminal::edit_mfile_request, - this, &main_window::edit_mfile); - - connect (cmd_widget, &QTerminal::execute_command_in_terminal_signal, - this, &main_window::execute_command_in_terminal); - - connect (this, &main_window::init_terminal_size_signal, - cmd_widget, &QTerminal::init_terminal_size); - - connect (this, &main_window::copyClipboard_signal, - cmd_widget, &QTerminal::copyClipboard); - - connect (this, &main_window::pasteClipboard_signal, - cmd_widget, &QTerminal::pasteClipboard); - - connect (this, &main_window::selectAll_signal, - cmd_widget, &QTerminal::selectAll); - - connect (cmd_widget, &QTerminal::request_edit_mfile_signal, - this, &main_window::edit_mfile); - - connect (cmd_widget, &QTerminal::request_open_file_signal, - this, QOverload::of (&main_window::open_file_signal)); - - connect (cmd_widget, &QTerminal::set_screen_size_signal, - this, &main_window::set_screen_size); - - connect (cmd_widget, &QTerminal::clear_command_window_request, - this, &main_window::handle_clear_command_window_request); - } - else - { - connect (this, &main_window::execute_command_signal, - m_command_window, &terminal_dock_widget::execute_command_signal); - } -} - -void main_window::adopt_documentation_widget (void) -{ - 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) -{ - m_file_browser_window = m_octave_qobj.file_browser_widget (this); - - make_dock_widget_connections (m_file_browser_window); - - connect (m_file_browser_window, &files_dock_widget::open_file, - this, QOverload::of (&main_window::open_file_signal)); - connect (m_file_browser_window, - &files_dock_widget::displayed_directory_changed, - this, &main_window::set_current_working_directory); - - connect (m_file_browser_window, &files_dock_widget::modify_path_signal, - this, &main_window::modify_path); - - connect (m_file_browser_window, &files_dock_widget::run_file_signal, - this, &main_window::run_file_in_terminal); - - connect (m_file_browser_window, &files_dock_widget::load_file_signal, - this, &main_window::handle_load_workspace_request); - - connect (m_file_browser_window, &files_dock_widget::open_any_signal, - this, &main_window::handle_open_any_request); - - connect (m_file_browser_window, &files_dock_widget::find_files_signal, - this, &main_window::find_files); -} - -void main_window::adopt_history_widget (void) -{ - m_history_window = m_octave_qobj.history_widget (this); - - make_dock_widget_connections (m_history_window); - - connect (m_history_window, &history_dock_widget::command_create_script, - this, &main_window::new_file_signal); - - connect (m_history_window, &history_dock_widget::command_double_clicked, - this, &main_window::execute_command_in_terminal); -} - -void main_window::adopt_workspace_widget (void) -{ - m_workspace_window = m_octave_qobj.workspace_widget (this); - - make_dock_widget_connections (m_workspace_window); - - connect (m_workspace_window, &workspace_view::command_requested, - this, &main_window::execute_command_in_terminal); -} - -void main_window::adopt_editor_widget (void) -{ - interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - - qt_interpreter_events *qt_link = interp_qobj->qt_link (); + construct_central_widget (); + + m_status_bar = new QStatusBar (this); + m_profiler_status_indicator = new led_indicator (); + QLabel *text = new QLabel (tr ("Profiler")); + m_status_bar->addPermanentWidget (text); + m_status_bar->addPermanentWidget (m_profiler_status_indicator); + + adopt_dock_widgets (); + + QGuiApplication::setDesktopFileName ("org.octave.Octave.desktop"); + + QApplication *qapp = m_octave_qobj.qapplication (); + + m_default_style = qapp->style ()->objectName (); + m_default_palette = qapp->palette (); + + bool connect_to_web = true; + QDateTime last_checked; + int serial = 0; + m_active_dock = nullptr; + + 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); + + if (connect_to_web + && (! last_checked.isValid () || one_day_ago > last_checked)) + emit show_community_news_signal (serial); + + construct_octave_qt_link (); + + // We have to set up all our windows, before we finally launch + // octave. + + construct (); + + read_settings (); + + init_terminal_size (); + + emit init_window_menu (); + + focus_command_window (); + } + + main_window::~main_window () { } + + void main_window::adopt_dock_widgets () + { + adopt_terminal_widget (); + adopt_documentation_widget (); + adopt_file_browser_widget (); + adopt_history_widget (); + adopt_workspace_widget (); + adopt_editor_widget (); + adopt_variable_editor_widget (); + + m_previous_dock = m_command_window; + } + + void main_window::adopt_terminal_widget () + { + m_command_window = m_octave_qobj.terminal_widget (this); + + make_dock_widget_connections (m_command_window); + + connect (this, &main_window::settings_changed, + m_command_window, &terminal_dock_widget::notice_settings); + + if (! m_octave_qobj.experimental_terminal_widget ()) + { + QTerminal *cmd_widget = m_command_window->get_qterminal (); + + // The following connections were previously made in + // QTerminal::construct, QWinTerminalImpl::QWinTerminalImpl, and + // QUnixTerminalImpl::QUnixTerminalImpl. Similar actions should + // probably be possible for the new command widget. + + connect (cmd_widget, &QTerminal::report_status_message, + this, &main_window::report_status_message); + + connect (cmd_widget, &QTerminal::edit_mfile_request, + this, &main_window::edit_mfile); + + connect (cmd_widget, &QTerminal::execute_command_in_terminal_signal, + this, &main_window::execute_command_in_terminal); + + connect (this, &main_window::init_terminal_size_signal, + cmd_widget, &QTerminal::init_terminal_size); + + connect (this, &main_window::copyClipboard_signal, + cmd_widget, &QTerminal::copyClipboard); + + connect (this, &main_window::pasteClipboard_signal, + cmd_widget, &QTerminal::pasteClipboard); + + connect (this, &main_window::selectAll_signal, + cmd_widget, &QTerminal::selectAll); + + connect (cmd_widget, &QTerminal::request_edit_mfile_signal, + this, &main_window::edit_mfile); + + connect (cmd_widget, &QTerminal::request_open_file_signal, + this, QOverload::of (&main_window::open_file_signal)); + + connect (cmd_widget, &QTerminal::set_screen_size_signal, + this, &main_window::set_screen_size); + + connect (cmd_widget, &QTerminal::clear_command_window_request, + this, &main_window::handle_clear_command_window_request); + } + else + { + connect (this, &main_window::execute_command_signal, + m_command_window, &terminal_dock_widget::execute_command_signal); + } + } + + 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 () + { + m_file_browser_window = m_octave_qobj.file_browser_widget (this); + + make_dock_widget_connections (m_file_browser_window); + + connect (m_file_browser_window, &files_dock_widget::open_file, + this, QOverload::of (&main_window::open_file_signal)); + connect (m_file_browser_window, + &files_dock_widget::displayed_directory_changed, + this, &main_window::set_current_working_directory); + + connect (m_file_browser_window, &files_dock_widget::modify_path_signal, + this, &main_window::modify_path); + + connect (m_file_browser_window, &files_dock_widget::run_file_signal, + this, &main_window::run_file_in_terminal); + + connect (m_file_browser_window, &files_dock_widget::load_file_signal, + this, &main_window::handle_load_workspace_request); + + connect (m_file_browser_window, &files_dock_widget::open_any_signal, + this, &main_window::handle_open_any_request); + + connect (m_file_browser_window, &files_dock_widget::find_files_signal, + this, &main_window::find_files); + } + + void main_window::adopt_history_widget () + { + m_history_window = m_octave_qobj.history_widget (this); + + make_dock_widget_connections (m_history_window); + + connect (m_history_window, &history_dock_widget::command_create_script, + this, &main_window::new_file_signal); + + connect (m_history_window, &history_dock_widget::command_double_clicked, + this, &main_window::execute_command_in_terminal); + } + + void main_window::adopt_workspace_widget () + { + m_workspace_window = m_octave_qobj.workspace_widget (this); + + make_dock_widget_connections (m_workspace_window); + + connect (m_workspace_window, &workspace_view::command_requested, + this, &main_window::execute_command_in_terminal); + } + + 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); - - make_dock_widget_connections (editor); - - // The editor is currently different from other dock widgets. Until - // those differences are resolved, make interpreter_event - // connections here instead of in base_qobject::editor_widget. - m_octave_qobj.connect_interpreter_events (editor); - - connect (editor, &file_editor::request_settings_dialog, - this, QOverload::of (&main_window::process_settings_dialog_request)); - - connect (editor, &file_editor::request_dbcont_signal, - this, &main_window::debug_continue); - - connect (this, &main_window::update_gui_lexer_signal, - editor, &file_editor::update_gui_lexer_signal); - - connect (editor, &file_editor::execute_command_in_terminal_signal, - this, &main_window::execute_command_in_terminal); - - connect (editor, &file_editor::focus_console_after_command_signal, - this, &main_window::focus_console_after_command); - - connect (editor, &file_editor::run_file_signal, - this, &main_window::run_file_in_terminal); - - connect (editor, &file_editor::edit_mfile_request, - this, &main_window::handle_edit_mfile_request); - - connect (editor, &file_editor::debug_quit_signal, - this, &main_window::debug_quit); - - connect (this, &main_window::editor_focus_changed, - editor, &file_editor::enable_menu_shortcuts); - - connect (this, &main_window::step_into_file_signal, - editor, &file_editor::request_step_into_file); - - connect (editor, &file_editor::editor_tabs_changed_signal, - this, &main_window::editor_tabs_changed); - - connect (editor, &file_editor::request_open_file_external, - m_external_editor, &external_editor_interface::call_custom_editor); - - connect (m_external_editor, &external_editor_interface::request_settings_dialog, - this, &main_window::process_settings_dialog_request); - - connect (this, &main_window::insert_debugger_pointer_signal, - editor, &file_editor::handle_insert_debugger_pointer_request); - - connect (this, &main_window::delete_debugger_pointer_signal, - editor, &file_editor::handle_delete_debugger_pointer_request); - - connect (this, &main_window::update_breakpoint_marker_signal, - editor, &file_editor::handle_update_breakpoint_marker_request); - - // Signals for removing/renaming files/dirs in the file browser - connect (m_file_browser_window, &files_dock_widget::file_remove_signal, - editor, &file_editor::handle_file_remove); - - connect (m_file_browser_window, &files_dock_widget::file_renamed_signal, - editor, &file_editor::handle_file_renamed); - - // Signals for removing/renaming files/dirs in the terminal window - connect (qt_link, &qt_interpreter_events::file_renamed_signal, - editor, &file_editor::handle_file_renamed); - - // Signals for entering/exiting debug mode - connect (qt_link, &qt_interpreter_events::enter_debugger_signal, - editor, &file_editor::handle_enter_debug_mode); - - connect (qt_link, &qt_interpreter_events::exit_debugger_signal, - editor, &file_editor::handle_exit_debug_mode); - - connect (qt_link, &qt_interpreter_events::directory_changed_signal, - editor, &file_editor::update_octave_directory); - - m_editor_window = editor; - - m_editor_menubar = m_editor_window->menubar (); - - m_active_editor = m_editor_window; - - m_editor_window->enable_menu_shortcuts (false); + file_editor *editor = new file_editor (this); + + make_dock_widget_connections (editor); + + // The editor is currently different from other dock widgets. Until + // those differences are resolved, make interpreter_event + // 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)); + + connect (editor, &file_editor::request_dbcont_signal, + this, &main_window::debug_continue); + + connect (this, &main_window::update_gui_lexer_signal, + editor, &file_editor::update_gui_lexer_signal); + + connect (editor, &file_editor::execute_command_in_terminal_signal, + this, &main_window::execute_command_in_terminal); + + connect (editor, &file_editor::focus_console_after_command_signal, + this, &main_window::focus_console_after_command); + + connect (editor, &file_editor::run_file_signal, + this, &main_window::run_file_in_terminal); + + connect (editor, &file_editor::edit_mfile_request, + this, &main_window::handle_edit_mfile_request); + + connect (editor, &file_editor::debug_quit_signal, + this, &main_window::debug_quit); + + connect (this, &main_window::editor_focus_changed, + editor, &file_editor::enable_menu_shortcuts); + + connect (this, &main_window::step_into_file_signal, + editor, &file_editor::request_step_into_file); + + connect (editor, &file_editor::editor_tabs_changed_signal, + this, &main_window::editor_tabs_changed); + + connect (editor, &file_editor::request_open_file_external, + m_external_editor, &external_editor_interface::call_custom_editor); + + connect (m_external_editor, &external_editor_interface::request_settings_dialog, + this, &main_window::process_settings_dialog_request); + + connect (this, &main_window::insert_debugger_pointer_signal, + editor, &file_editor::handle_insert_debugger_pointer_request); + + connect (this, &main_window::delete_debugger_pointer_signal, + editor, &file_editor::handle_delete_debugger_pointer_request); + + connect (this, &main_window::update_breakpoint_marker_signal, + editor, &file_editor::handle_update_breakpoint_marker_request); + + // Signals for removing/renaming files/dirs in the file browser + connect (m_file_browser_window, &files_dock_widget::file_remove_signal, + editor, &file_editor::handle_file_remove); + + connect (m_file_browser_window, &files_dock_widget::file_renamed_signal, + editor, &file_editor::handle_file_renamed); + + // Signals for removing/renaming files/dirs in the terminal window + connect (qt_link, &qt_interpreter_events::file_renamed_signal, + editor, &file_editor::handle_file_renamed); + + // Signals for entering/exiting debug mode + connect (qt_link, &qt_interpreter_events::enter_debugger_signal, + editor, &file_editor::handle_enter_debug_mode); + + connect (qt_link, &qt_interpreter_events::exit_debugger_signal, + editor, &file_editor::handle_exit_debug_mode); + + connect (qt_link, &qt_interpreter_events::directory_changed_signal, + editor, &file_editor::update_octave_directory); + + m_editor_window = editor; + + m_editor_menubar = m_editor_window->menubar (); + + m_active_editor = m_editor_window; + + m_editor_window->enable_menu_shortcuts (false); #else - m_editor_window = nullptr; - - m_editor_menubar = nullptr; - - m_active_editor = m_external_editor; + m_editor_window = nullptr; + + m_editor_menubar = nullptr; + + m_active_editor = m_external_editor; #endif - connect (qt_link, SIGNAL (edit_file_signal (const QString&)), - m_active_editor, SLOT (handle_edit_file_request (const QString&))); -} - -void main_window::adopt_variable_editor_widget (void) -{ - m_variable_editor_window = m_octave_qobj.variable_editor_widget (this); - - make_dock_widget_connections (m_variable_editor_window); -} - -void main_window::make_dock_widget_connections (octave_dock_widget *dw) -{ - connect (this, &main_window::init_window_menu, - dw, &octave_dock_widget::init_window_menu_entry); - - connect (this, &main_window::settings_changed, - dw, &octave_dock_widget::handle_settings); - - connect (this, &main_window::active_dock_changed, - dw, &octave_dock_widget::handle_active_dock_changed); - - // FIXME: shouldn't this action should be associated with closing - // the main window, not with exiting the application? At one time, - // those two actions happened together, but now it is possible to - // close the main window without exiting the application. - connect (qApp, &QApplication::aboutToQuit, - dw, &octave_dock_widget::save_settings); - - // The following is required when the exp. terminal widget is used - // and the main window is closed (no exit via interpreter) - connect (this, &main_window::close_gui_signal, - dw, &octave_dock_widget::save_settings); -} - -bool main_window::command_window_has_focus (void) const -{ - return m_command_window->has_focus (); -} - -void main_window::focus_command_window (void) -{ - m_command_window->activate (); -} - -void main_window::focus_window (const QString& win_name) -{ - if (win_name == "command") + connect (qt_link, SIGNAL (edit_file_signal (const QString&)), + m_active_editor, SLOT (handle_edit_file_request (const QString&))); + } + + void main_window::adopt_variable_editor_widget () + { + m_variable_editor_window = m_octave_qobj.variable_editor_widget (this); + + make_dock_widget_connections (m_variable_editor_window); + } + + void main_window::make_dock_widget_connections (octave_dock_widget *dw) + { + connect (this, &main_window::init_window_menu, + dw, &octave_dock_widget::init_window_menu_entry); + + connect (this, &main_window::settings_changed, + dw, &octave_dock_widget::handle_settings); + + connect (this, &main_window::active_dock_changed, + dw, &octave_dock_widget::handle_active_dock_changed); + + // FIXME: shouldn't this action should be associated with closing + // the main window, not with exiting the application? At one time, + // those two actions happened together, but now it is possible to + // close the main window without exiting the application. + connect (qApp, &QApplication::aboutToQuit, + dw, &octave_dock_widget::save_settings); + + // The following is required when the exp. terminal widget is used + // and the main window is closed (no exit via interpreter) + connect (this, &main_window::close_gui_signal, + dw, &octave_dock_widget::save_settings); + } + + bool main_window::command_window_has_focus () const + { + return m_command_window->has_focus (); + } + + void main_window::focus_command_window () + { m_command_window->activate (); - else if (win_name == "history") - m_history_window->activate (); - else if (win_name == "workspace") - m_workspace_window->activate (); - else if (win_name == "filebrowser") - m_file_browser_window->activate (); -} - -bool main_window::confirm_shutdown (void) -{ - 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 ()) - { - int ans = QMessageBox::question (this, tr ("Octave"), - tr ("Are you sure you want to exit Octave?"), - (QMessageBox::Ok - | QMessageBox::Cancel), - QMessageBox::Ok); - - if (ans != QMessageBox::Ok) - closenow = false; - } + } + + void main_window::focus_window (const QString& win_name) + { + if (win_name == "command") + m_command_window->activate (); + else if (win_name == "history") + m_history_window->activate (); + else if (win_name == "workspace") + m_workspace_window->activate (); + else if (win_name == "filebrowser") + m_file_browser_window->activate (); + } + + bool main_window::confirm_shutdown () + { + bool closenow = true; + + 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?"), + (QMessageBox::Ok + | QMessageBox::Cancel), + QMessageBox::Ok); + + if (ans != QMessageBox::Ok) + closenow = false; + } #if defined (HAVE_QSCINTILLA) - if (closenow) - closenow = m_editor_window->check_closing (); + if (closenow) + closenow = m_editor_window->check_closing (); +#endif + + return closenow; + } + + // catch focus changes and determine the active dock widget + void main_window::focus_changed (QWidget *, QWidget *new_widget) + { + // If there is no new widget or the new widget is a menu bar + // (when pressing ), we can return immediately and reset the + // focus to the previous widget + if (! new_widget + || (new_widget == menuBar ()) + || (new_widget == m_editor_menubar)) + { + if (m_active_dock) + m_active_dock->setFocus (); + + return; + } + + octave_dock_widget *dock = nullptr; + QWidget *w_new = new_widget; // get a copy of new focus widget + QWidget *start = w_new; // Save it as start of our search + int count = 0; // fallback to prevent endless loop + + QList w_list = dock_widget_list (); + + while (w_new && w_new != m_main_tool_bar && count < 100) + { + // Go through all dock widgets and check whether the current widget + // with focus is a child of one of them. + for (auto w : w_list) + { + if (w->isAncestorOf (w_new)) + dock = w; + } + + if (dock) + break; + + // If not yet found (in case w_new is not a child of its dock widget), + // test next widget in the focus chain + w_new = qobject_cast (w_new->previousInFocusChain ()); + + // Measures preventing an endless loop + if (w_new == start) + break; // We have arrived where we began ==> exit loop + count++; // Limited number of trials + } + + // editor and terminal needs extra handling + octave_dock_widget *edit_dock_widget + = static_cast (m_editor_window); + octave_dock_widget *cmd_dock_widget + = static_cast (m_command_window); + + // if new dock has focus, emit signal and store active focus + // except editor changes to a dialog (dock=0) + if ((dock || m_active_dock != edit_dock_widget) && (dock != m_active_dock)) + { + // signal to all dock widgets for updating the style + emit active_dock_changed (m_active_dock, dock); + + if (dock) + { + QList tabbed = tabifiedDockWidgets (dock); + if (tabbed.contains (m_active_dock)) + dock->set_predecessor_widget (m_active_dock); + } + + // Check whether editor loses or gains focus + int editor = 0; + if (edit_dock_widget == dock) + { + emit editor_focus_changed (true); + editor = 1; + } + else if (edit_dock_widget == m_active_dock) + { + emit editor_focus_changed (false); + editor = -1; + } + + // Check whether terminal loses or gains focus + int cmd_involved = 0; + if (cmd_dock_widget == dock) + cmd_involved = 1; + else if (cmd_dock_widget == m_active_dock) + cmd_involved = -1; + + // If we have to take care of Alt+? accelerators of the main + // window, take result of test for terminal widget above + int command = 0; + if (m_prevent_readline_conflicts_menu) + command = cmd_involved; + + // If editor or command gets/looses focus, disable/enable + // main menu accelerators (Alt + ?) + if (editor || command) + { + int sum = editor + command; + if (sum > 0) + disable_menu_shortcuts (true); + else if (sum < 0) + disable_menu_shortcuts (false); + } + + if (m_active_dock) + m_previous_dock = m_active_dock; + m_active_dock = dock; + + // En-/disable global shortcuts (preventing conflicts with + // readline. Do it here because it relies on m_active_dock + if (cmd_involved) + configure_shortcuts (); + } + } + + void main_window::request_reload_settings () + { + emit settings_changed (); + } + + void main_window::report_status_message (const QString& statusMessage) + { + m_status_bar->showMessage (statusMessage, 1000); + } + + 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. + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) + opts = QFileDialog::DontUseNativeDialog; + + QString file + = QFileDialog::getSaveFileName (this, tr ("Save Workspace As"), ".", + nullptr, nullptr, QFileDialog::Option (opts)); + + if (! file.isEmpty ()) + { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + Fsave (interp, ovl (file.toStdString ())); + }); + } + } + + void main_window::handle_load_workspace_request (const QString& file_arg) + { + // 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; + + QString file = file_arg; + + if (file.isEmpty ()) + file = QFileDialog::getOpenFileName (this, tr ("Load Workspace"), ".", + nullptr, nullptr, QFileDialog::Option (opts)); + + if (! file.isEmpty ()) + { + 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 ()); + }); + } + } + + void main_window::handle_open_any_request (const QString& file_arg) + { + if (! file_arg.isEmpty ()) + { + std::string file = file_arg.toStdString (); + + 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 ()); + }); + } + } + + void main_window::handle_clear_workspace_request () + { + emit interpreter_event + ([] (interpreter& interp) + { + // INTERPRETER THREAD + + Fclear (interp); + }); + } + + void main_window::handle_clear_command_window_request () + { + emit interpreter_event + ([] () + { + // INTERPRETER THREAD + + command_editor::kill_full_line (); + command_editor::clear_screen (); + }); + } + + 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")); + }); + } + + void main_window::handle_undo_request () + { + if (command_window_has_focus ()) + { + emit interpreter_event + ([] () + { + // INTERPRETER THREAD + + command_editor::undo (); + command_editor::redisplay (); + }); + } + else + emit undo_signal (); + } + + void main_window::modify_path (const QStringList& dir_list, + bool rm, bool subdirs) + { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + octave_value_list paths; + + // Loop over all directories in order to get all subdirs + for (octave_idx_type i = 0; i < dir_list.length (); i++) + { + std::string dir = dir_list.at(i).toStdString (); + + if (subdirs) + paths.append (Fgenpath (ovl (dir))); + else + paths.append (dir); + } + + if (rm) + Frmpath (interp, paths); + else + Faddpath (interp, paths); + }); + } + + void main_window::edit_mfile (const QString& name, int line) + { + handle_edit_mfile_request (name, QString (), QString (), line); + } + + void main_window::file_remove_proxy (const QString& o, const QString& n) + { + interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); + + qt_interpreter_events *qt_link = interp_qobj->qt_link (); + + // Wait for worker to suspend + qt_link->lock (); + // Close the file if opened +#if defined (HAVE_QSCINTILLA) + m_editor_window->handle_file_remove (o, n); +#else + octave_unused_parameter (o); + octave_unused_parameter (n); #endif - return closenow; -} - -// catch focus changes and determine the active dock widget -void main_window::focus_changed (QWidget *, QWidget *new_widget) -{ - // If there is no new widget or the new widget is a menu bar - // (when pressing ), we can return immediately and reset the - // focus to the previous widget - if (! new_widget - || (new_widget == menuBar ()) - || (new_widget == m_editor_menubar)) - { - if (m_active_dock) - m_active_dock->setFocus (); - - return; - } - - octave_dock_widget *dock = nullptr; - QWidget *w_new = new_widget; // get a copy of new focus widget - QWidget *start = w_new; // Save it as start of our search - int count = 0; // fallback to prevent endless loop - - QList w_list = dock_widget_list (); - - while (w_new && w_new != m_main_tool_bar && count < 100) - { - // Go through all dock widgets and check whether the current widget - // with focus is a child of one of them. - for (auto w : w_list) - { - if (w->isAncestorOf (w_new)) - dock = w; - } - - if (dock) - break; - - // If not yet found (in case w_new is not a child of its dock widget), - // test next widget in the focus chain - w_new = qobject_cast (w_new->previousInFocusChain ()); - - // Measures preventing an endless loop - if (w_new == start) - break; // We have arrived where we began ==> exit loop - count++; // Limited number of trials - } - - // editor and terminal needs extra handling - octave_dock_widget *edit_dock_widget - = static_cast (m_editor_window); - octave_dock_widget *cmd_dock_widget - = static_cast (m_command_window); - - // if new dock has focus, emit signal and store active focus - // except editor changes to a dialog (dock=0) - if ((dock || m_active_dock != edit_dock_widget) && (dock != m_active_dock)) - { - // signal to all dock widgets for updating the style - emit active_dock_changed (m_active_dock, dock); - - if (dock) - { - QList tabbed = tabifiedDockWidgets (dock); - if (tabbed.contains (m_active_dock)) - dock->set_predecessor_widget (m_active_dock); - } - - // Check whether editor loses or gains focus - int editor = 0; - if (edit_dock_widget == dock) - { - emit editor_focus_changed (true); - editor = 1; - } - else if (edit_dock_widget == m_active_dock) - { - emit editor_focus_changed (false); - editor = -1; - } - - // Check whether terminal loses or gains focus - int cmd_involved = 0; - if (cmd_dock_widget == dock) - cmd_involved = 1; - else if (cmd_dock_widget == m_active_dock) - cmd_involved = -1; - - // If we have to take care of Alt+? accelerators of the main - // window, take result of test for terminal widget above - int command = 0; - if (m_prevent_readline_conflicts_menu) - command = cmd_involved; - - // If editor or command gets/looses focus, disable/enable - // main menu accelerators (Alt + ?) - if (editor || command) - { - int sum = editor + command; - if (sum > 0) - disable_menu_shortcuts (true); - else if (sum < 0) - disable_menu_shortcuts (false); - } - - if (m_active_dock) - m_previous_dock = m_active_dock; - m_active_dock = dock; - - // En-/disable global shortcuts (preventing conflicts with - // readline. Do it here because it relies on m_active_dock - if (cmd_involved) - configure_shortcuts (); - } -} - -void main_window::request_reload_settings (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (settings) - emit settings_changed (settings); -} - -void main_window::report_status_message (const QString& statusMessage) -{ - m_status_bar->showMessage (statusMessage, 1000); -} - -void main_window::handle_save_workspace_request (void) -{ - // 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; - - QString file - = QFileDialog::getSaveFileName (this, tr ("Save Workspace As"), ".", - nullptr, nullptr, QFileDialog::Option (opts)); - - if (! file.isEmpty ()) - { - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Fsave (interp, ovl (file.toStdString ())); - }); - } -} - -void main_window::handle_load_workspace_request (const QString& file_arg) -{ - // 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; - - QString file = file_arg; - - if (file.isEmpty ()) - file = QFileDialog::getOpenFileName (this, tr ("Load Workspace"), ".", - nullptr, nullptr, QFileDialog::Option (opts)); - - if (! file.isEmpty ()) - { - 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 ()); - }); - } -} - -void main_window::handle_open_any_request (const QString& file_arg) -{ - if (! file_arg.isEmpty ()) - { - std::string file = file_arg.toStdString (); - - 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 ()); - }); - } -} - -void main_window::handle_clear_workspace_request (void) -{ - emit interpreter_event - ([] (interpreter& interp) - { - // INTERPRETER THREAD - - Fclear (interp); - }); -} - -void main_window::handle_clear_command_window_request (void) -{ - emit interpreter_event - ([] (void) - { - // INTERPRETER THREAD - - command_editor::kill_full_line (); - command_editor::clear_screen (); - }); -} - -void main_window::handle_clear_history_request (void) -{ - emit interpreter_event - ([] (interpreter& interp) - { - // INTERPRETER THREAD - - history_system& history_sys = interp.get_history_system (); - - history_sys.do_history (ovl ("-c")); - }); -} - -void main_window::handle_undo_request (void) -{ - if (command_window_has_focus ()) - { - emit interpreter_event - ([] (void) - { - // INTERPRETER THREAD - - command_editor::undo (); - command_editor::redisplay (); - }); - } - else - emit undo_signal (); -} - -void main_window::modify_path (const QStringList& dir_list, - bool rm, bool subdirs) -{ - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - octave_value_list paths; - - // Loop over all directories in order to get all subdirs - for (octave_idx_type i = 0; i < dir_list.length (); i++) - { - std::string dir = dir_list.at(i).toStdString (); - - if (subdirs) - paths.append (Fgenpath (ovl (dir))); - else - paths.append (dir); - } - - if (rm) - Frmpath (interp, paths); - else - Faddpath (interp, paths); - }); -} - -void main_window::edit_mfile (const QString& name, int line) -{ - handle_edit_mfile_request (name, QString (), QString (), line); -} - -void main_window::file_remove_proxy (const QString& o, const QString& n) -{ - interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - - qt_interpreter_events *qt_link = interp_qobj->qt_link (); - - // Wait for worker to suspend - qt_link->lock (); - // Close the file if opened + // We are done: Unlock and wake the worker thread + qt_link->unlock (); + qt_link->wake_all (); + } + + void main_window::open_online_documentation_page () + { + QDesktopServices::openUrl + (QUrl ("https://octave.org/doc/interpreter/index.html")); + } + + void main_window::open_bug_tracker_page () + { + QDesktopServices::openUrl (QUrl ("https://octave.org/bugs.html")); + } + + void main_window::open_octave_packages_page () + { + QDesktopServices::openUrl (QUrl ("https://packages.octave.org/index.html")); + } + + void main_window::open_contribute_page () + { + QDesktopServices::openUrl (QUrl ("https://octave.org/contribute.html")); + } + + void main_window::open_donate_page () + { + QDesktopServices::openUrl (QUrl ("https://octave.org/donate.html")); + } + + void main_window::process_settings_dialog_request (const QString& desired_tab) + { + if (m_settings_dlg) // m_settings_dlg is a guarded pointer! + { + // here the dialog is still open and called once again + if (! desired_tab.isEmpty ()) + m_settings_dlg->show_tab (desired_tab); + return; + } + + 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 () + { + std::string message + = octave_name_version_copyright_copying_warranty_and_bugs (true); + + QMessageBox::about (this, tr ("About Octave"), + QString::fromStdString (message)); + } + + void main_window::notice_settings (bool update_by_worker) + { + gui_settings settings; + + // Get desired style from preferences or take the default one if + // the desired one is not found + 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(); + + if (preferred_style == global_extra_styles.at (EXTRA_STYLE_FUSION_DARK)) + { + QStyle *new_style = QStyleFactory::create (QStringLiteral("Fusion")); + if (new_style) + qapp->setStyle (new_style); + qapp->setPalette (getFusionDarkPalette()); + qapp->setStyleSheet ("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); + } + else + { + QStyle *new_style = QStyleFactory::create (preferred_style); + if (new_style) + { + qapp->setPalette (m_default_palette); + qapp->setStyle (new_style); + } + } + + // the widget's icons (when floating) + QString icon_set = settings.string_value (dw_icon_set); + + QString icon; + for (auto *widget : dock_widget_list ()) + { + QString name = widget->objectName (); + if (! name.isEmpty ()) + { + // if child has a name + icon = dw_icon_set_names[icon_set]; + if (icon_set != "NONE") + icon += name + ".png"; // add widget name and ext. + widget->setWindowIcon (QIcon (icon)); + } + } + + 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.bool_value (global_status_bar)) + m_status_bar->show (); + else + m_status_bar->hide (); + + m_prevent_readline_conflicts + = settings.bool_value (sc_prevent_rl_conflicts); + + m_prevent_readline_conflicts_menu + = settings.bool_value (sc_prevent_rl_conflicts_menu); + + m_suppress_dbg_location + = ! settings.bool_value (cs_dbg_location); + + settings.update_network_settings (); + + emit active_dock_changed (nullptr, m_active_dock); // update dock widget styles + + configure_shortcuts (); + + bool do_disable_main_menu_shortcuts + = (m_active_dock == m_editor_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.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)) + update_default_encoding (new_default_encoding); + + // Set cursor blinking depending on the settings + // Cursor blinking: consider old terminal related setting if not yet set + // TODO: This pref. can be deprecated / removed if Qt adds support for + // getting the cursor blink preferences from all OS environments + bool cursor_blinking; + + if (settings.contains (global_cursor_blinking.settings_key ())) + cursor_blinking = settings.bool_value (global_cursor_blinking); + else + cursor_blinking = settings.bool_value (cs_cursor_blinking); + + if (cursor_blinking) + QApplication::setCursorFlashTime (1000); // 1000 ms flash time + else + QApplication::setCursorFlashTime (0); // no flashing + + } + + QPalette main_window::getFusionDarkPalette() + { + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(127, 127, 127)); + darkPalette.setColor(QPalette::Base, QColor(42, 42, 42)); + darkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66)); + darkPalette.setColor(QPalette::ToolTipBase, Qt::white); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127)); + darkPalette.setColor(QPalette::Dark, QColor(35, 35, 35)); + darkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20)); + darkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127)); + darkPalette.setColor(QPalette::BrightText, Qt::red); + darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80)); + darkPalette.setColor(QPalette::HighlightedText, Qt::white); + darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127)); + + return darkPalette; + } + + 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 + // caused it to run after gui_settings is deleted. + if (m_find_files_dlg) + m_find_files_dlg->save_settings (); + + if (m_set_path_dlg) + m_set_path_dlg->save_settings (); + + write_settings (); + + // No more active dock, otherwise, focus_changed would try to set + // the focus to a dock widget that might not exist anymore + m_active_dock = nullptr; + } + + void main_window::go_to_previous_widget () + { + m_previous_dock->activate (); + } + + void main_window::update_octave_directory (const QString& dir) + { + // Remove existing entry, if any, then add new directory at top and + // mark it as the current directory. Finally, update the file list + // widget. + + int index = m_current_directory_combo_box->findText (dir); + + if (index >= 0) + m_current_directory_combo_box->removeItem (index); + + m_current_directory_combo_box->insertItem (0, dir); + m_current_directory_combo_box->setCurrentIndex (0); + } + + void main_window::browse_for_directory () + { + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. + int opts = QFileDialog::ShowDirsOnly; + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) + opts = QFileDialog::DontUseNativeDialog; + + QString dir + = QFileDialog::getExistingDirectory (this, tr ("Browse directories"), nullptr, + QFileDialog::Option (opts)); + + set_current_working_directory (dir); + + // FIXME: on Windows systems, the command window freezes after the + // previous actions. Forcing the focus appears to unstick it. + + focus_command_window (); + } + + void main_window::set_current_working_directory (const QString& dir) + { + // Change to dir if it is an existing directory. + + QString xdir = (dir.isEmpty () ? "." : dir); + + QFileInfo fileInfo (xdir); + + if (fileInfo.exists () && fileInfo.isDir ()) + { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + interp.chdir (xdir.toStdString ()); + }); + } + } + + void main_window::change_directory_up () + { + set_current_working_directory (".."); + } + + // Slot that is called if return is pressed in the line edit of the + // 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 () + { + // 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 + // directory. + + QString dir = m_current_directory_combo_box->currentText (); + + int index = m_current_directory_combo_box->findText (dir); + + if (index < 0) + set_current_working_directory (dir); + } + + void main_window::execute_command_in_terminal (const QString& command) + { + if (m_octave_qobj.experimental_terminal_widget ()) + { + emit execute_command_signal (command); + } + else + { + emit interpreter_event + ([=] () + { + // 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 (); + } + + void main_window::run_file_in_terminal (const QFileInfo& info) + { + 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 (); + }); + + focus_console_after_command (); + } + + void main_window::handle_new_figure_request () + { + emit interpreter_event + ([] (interpreter& interp) + { + // INTERPRETER THREAD + + Fbuiltin (interp, ovl ("figure")); + Fdrawnow (interp); + }); + } + + void main_window::handle_enter_debugger () + { + setWindowTitle ("Octave (Debugging)"); + + m_debug_continue->setEnabled (true); + m_debug_step_into->setEnabled (true); + m_debug_step_over->setEnabled (true); + m_debug_step_out->setEnabled (true); + m_debug_quit->setEnabled (true); + } + + void main_window::handle_exit_debugger () + { + setWindowTitle ("Octave"); + + m_debug_continue->setEnabled (false); + m_debug_step_into->setEnabled (false); + m_debug_step_over->setEnabled (m_editor_has_tabs && m_editor_is_octave_file); + m_debug_step_out->setEnabled (false); + m_debug_quit->setEnabled (false); + } + + 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); + }); + } + + 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); + }); + } + + void main_window::debug_step_over () + { + if (m_debug_quit->isEnabled ()) + { + // We are in debug mode, just call dbstep. + + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + F__db_next_breakpoint_quiet__ (interp, + ovl (m_suppress_dbg_location)); + Fdbstep (interp); + + command_editor::interrupt (true); + }); + } + else + { + // Not in debug mode: "step into" the current editor file + emit step_into_file_signal (); + } + } + + 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); + }); + } + + void main_window::debug_quit () + { + emit interpreter_event + ([] (interpreter& interp) + { + // INTERPRETER THREAD + + Fdbquit (interp); + + command_editor::interrupt (true); + }); + } + + // + // Functions related to file editing + // + // These are moved from editor to here for also using them when octave + // is built without qscintilla + // + 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. + + gui_settings settings; + + bool is_internal = m_editor_window + && ! settings.value (global_use_custom_editor.settings_key (), + global_use_custom_editor.def ()).toBool (); + + // Create a NonModal message. + QWidget *p = this; + if (is_internal) + p = m_editor_window; + QFileDialog *fileDialog = new QFileDialog (p); + fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*)")); + + fileDialog->setAcceptMode (QFileDialog::AcceptOpen); + fileDialog->setViewMode (QFileDialog::Detail); + fileDialog->setFileMode (QFileDialog::ExistingFiles); + fileDialog->setDirectory (m_current_directory_combo_box->itemText (0)); + + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. + if (! settings.bool_value (global_use_native_dialogs)) + fileDialog->setOption(QFileDialog::DontUseNativeDialog); + + connect (fileDialog, &QFileDialog::filesSelected, + this, &main_window::request_open_files); + + fileDialog->setWindowModality (Qt::NonModal); + fileDialog->setAttribute (Qt::WA_DeleteOnClose); + fileDialog->show (); + } + + // Create a new script + void main_window::request_new_script (const QString& commands) + { + emit new_file_signal (commands); + } + + // Create a new function and open it + void main_window::request_new_function (bool) + { + bool ok; + // Get the name of the new function: Parent of the input dialog is the + // 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; + + 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); + + if (ok && new_name.length () > 0) + { + // append suffix if it does not already exist + if (new_name.rightRef (2) != ".m") + new_name.append (".m"); + // check whether new files are created without prompt + 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.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); + } + } + + void main_window::handle_edit_mfile_request (const QString& fname, + const QString& ffile, + const QString& curr_dir, + int line) + { + // 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 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) + { + QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical, + tr ("Octave Editor"), + message, QMessageBox::Ok, this); + msgBox->setWindowModality (Qt::NonModal); + msgBox->setAttribute (Qt::WA_DeleteOnClose); + msgBox->show (); + } + + void main_window::handle_insert_debugger_pointer_request (const QString& file, + int line) + { + bool cmd_focus = command_window_has_focus (); + + emit insert_debugger_pointer_signal (file, line); + + if (cmd_focus) + focus_command_window (); + } + + void main_window::handle_delete_debugger_pointer_request (const QString& file, + int line) + { + bool cmd_focus = command_window_has_focus (); + + emit delete_debugger_pointer_signal (file, line); + + if (cmd_focus) + focus_command_window (); + } + + void main_window::handle_update_breakpoint_marker_request (bool insert, + const QString& file, + int line, + const QString& cond) + { + bool cmd_focus = command_window_has_focus (); + + emit update_breakpoint_marker_signal (insert, file, line, cond); + + if (cmd_focus) + focus_command_window (); + } + + void main_window::read_settings () + { + gui_settings settings; + + set_window_layout (); + + // restore the list of the last directories + 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 (); + } + + void main_window::init_terminal_size () + { + emit init_terminal_size_signal (); + } + + 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.byte_array_value (mw_geometry))) + { + do_reset_windows (true); + return; + } + + if (isMaximized()) + { + // If the window state is restored to maximized layout, the + // horizontal layout is not preserved. This cann be avoided by + // setting the geometry to the max. available geometry. However, on + // X11, the available geometry (excluding task bar etc.) is equal to + // the total geometry leading to a full screen mode without window + // decorations. This in turn can be avoided by explicitly adding + // a title bar in the window flags. + + // Get available geometry for current screen and set this + // window's geometry to it. + QScreen *s = windowHandle ()->screen (); + QRect av_geom = s->availableGeometry (); + setGeometry (av_geom); // Set (correct) available geometry + + // Force full title bar + setWindowFlags(Qt::WindowTitleHint + | Qt::WindowMinMaxButtonsHint + | Qt::WindowSystemMenuHint + | Qt::WindowCloseButtonHint); + } + + if (! restoreState (settings.byte_array_value (mw_state))) + { + do_reset_windows (true); + return; + } + + // Restore the geometry of all dock-widgets + + for (auto *widget : dock_widget_list ()) + { + // Leave any widgets that existed before main_window was created + // as they were. + + if (widget->adopted ()) + continue; + + QString name = widget->objectName (); + + if (! name.isEmpty ()) + { + bool floating = false; + bool visible = true; + + 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) + { + widget->make_window (); + + if (visible) + { + if (settings.value (dw_is_minimized.settings_key ().arg (name), + dw_is_minimized.def ()).toBool ()) + widget->showMinimized (); + else + widget->setVisible (true); + } + else + widget->setVisible (false); + } + else // not floating + { + if (! widget->parent ()) // should not be floating but is + widget->make_widget (false); // no docking, just reparent + + widget->make_widget (); + widget->setVisible (visible); // not floating -> show + } + } + } + + show (); + } + + void main_window::write_settings () + { + 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.settings_key (), curr_dirs); + settings.sync (); + } + + void main_window::copyClipboard () + { + if (m_current_directory_combo_box->hasFocus ()) + { + QLineEdit *edit = m_current_directory_combo_box->lineEdit (); + if (edit && edit->hasSelectedText ()) + { + QClipboard *clipboard = QApplication::clipboard (); + clipboard->setText (edit->selectedText ()); + } + } + else + emit copyClipboard_signal (); + } + + void main_window::pasteClipboard () + { + if (m_current_directory_combo_box->hasFocus ()) + { + QLineEdit *edit = m_current_directory_combo_box->lineEdit (); + QClipboard *clipboard = QApplication::clipboard (); + QString str = clipboard->text (); + if (edit && str.length () > 0) + { + edit->insert (str); + } + } + else + emit pasteClipboard_signal (); + } + + void main_window::selectAll () + { + if (m_current_directory_combo_box->hasFocus ()) + { + QLineEdit *edit = m_current_directory_combo_box->lineEdit (); + if (edit) + { + edit->selectAll (); + } + } + else + emit selectAll_signal (); + } + + void main_window::handle_gui_status_update (const QString& feature, + const QString& status) + { + // Put actions that are required for updating a gui features here + + // Profiler on/off + if (! feature.compare ("profiler")) + { + if (! status.compare ("on", Qt::CaseInsensitive)) + handle_profiler_status_update (true); + else if (! status.compare ("off", Qt::CaseInsensitive)) + handle_profiler_status_update (false); + } + } + + void main_window::handle_octave_ready () + { + // actions after the startup files are executed + + gui_settings settings; + + QDir startup_dir = QDir (); // current octave dir after startup + + if (settings.bool_value (global_restore_ov_dir)) + { + // 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 ()) + { + // the configured startup dir does not exist, take actual one + startup_dir = QDir (); + } + + set_current_working_directory (startup_dir.absolutePath ()); + + if (m_editor_window) + { #if defined (HAVE_QSCINTILLA) - m_editor_window->handle_file_remove (o, n); -#else - octave_unused_parameter (o); - octave_unused_parameter (n); + // Octave ready, determine whether to create an empty script. + // 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 (); #endif - - // We are done: Unlock and wake the worker thread - qt_link->unlock (); - qt_link->wake_all (); -} - -void main_window::open_online_documentation_page (void) -{ - QDesktopServices::openUrl - (QUrl ("https://octave.org/doc/interpreter/index.html")); -} - -void main_window::open_bug_tracker_page (void) -{ - QDesktopServices::openUrl (QUrl ("https://octave.org/bugs.html")); -} - -void main_window::open_octave_packages_page (void) -{ - QDesktopServices::openUrl (QUrl ("https://packages.octave.org/index.html")); -} - -void main_window::open_contribute_page (void) -{ - QDesktopServices::openUrl (QUrl ("https://octave.org/contribute.html")); -} - -void main_window::open_donate_page (void) -{ - QDesktopServices::openUrl (QUrl ("https://octave.org/donate.html")); -} - -void main_window::process_settings_dialog_request (const QString& desired_tab) -{ - if (m_settings_dlg) // m_settings_dlg is a guarded pointer! - { - // here the dialog is still open and called once again - if (! desired_tab.isEmpty ()) - m_settings_dlg->show_tab (desired_tab); + } + + if (m_octave_qobj.experimental_terminal_widget ()) + { + // 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_THREAD + + // 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)); + }); + } + + m_command_window->init_command_prompt (); + focus_command_window (); // make sure that the command window has focus + } + + void main_window::handle_set_path_dialog_request () + { + if (m_set_path_dlg) // m_set_path_dlg is a guarded pointer! return; - } - - m_settings_dlg = new settings_dialog (this, m_octave_qobj, 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) -{ - std::string message - = octave_name_version_copyright_copying_warranty_and_bugs (true); - - QMessageBox::about (this, tr ("About Octave"), - QString::fromStdString (message)); -} - -void main_window::notice_settings (const gui_settings *settings, - bool update_by_worker) -{ - if (! settings) - return; - - // 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 ()) - preferred_style = m_default_style; - - QApplication* qapp = m_octave_qobj.qapplication(); - - if (preferred_style == global_extra_styles.at (EXTRA_STYLE_FUSION_DARK)) - { - QStyle *new_style = QStyleFactory::create (QStringLiteral("Fusion")); - if (new_style) - qapp->setStyle (new_style); - qapp->setPalette (getFusionDarkPalette()); - qapp->setStyleSheet ("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); - } - else - { - QStyle *new_style = QStyleFactory::create (preferred_style); - if (new_style) - { - qapp->setPalette (m_default_palette); - qapp->setStyle (new_style); - } - } - - // the widget's icons (when floating) - QString icon_set = settings->value (dw_icon_set).toString (); - - QString icon; - for (auto *widget : dock_widget_list ()) - { - QString name = widget->objectName (); - if (! name.isEmpty ()) - { - // if child has a name - icon = dw_icon_set_names[icon_set]; - if (icon_set != "NONE") - icon += name + ".png"; // add widget name and ext. - widget->setWindowIcon (QIcon (icon)); - } - } - - int size_idx = settings->value (global_icon_size).toInt (); - 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 ()) - m_status_bar->show (); - else - m_status_bar->hide (); - - m_prevent_readline_conflicts - = settings->value (sc_prevent_rl_conflicts).toBool (); - - m_prevent_readline_conflicts_menu - = settings->value (sc_prevent_rl_conflicts_menu).toBool (); - - m_suppress_dbg_location - = ! settings->value (cs_dbg_location).toBool (); - - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - rmgr.update_network_settings (); - - emit active_dock_changed (nullptr, m_active_dock); // update dock widget styles - - configure_shortcuts (); - - bool do_disable_main_menu_shortcuts - = (m_active_dock == m_editor_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 (); - // 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)) - update_default_encoding (new_default_encoding); - - // Set cursor blinking depending on the settings - // Cursor blinking: consider old terminal related setting if not yet set - // TODO: This pref. can be deprecated / removed if Qt adds support for - // 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 (); - else - cursor_blinking = settings->value (cs_cursor_blinking).toBool (); - - if (cursor_blinking) - QApplication::setCursorFlashTime (1000); // 1000 ms flash time - else - QApplication::setCursorFlashTime (0); // no flashing - -} - -QPalette main_window::getFusionDarkPalette() -{ - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(127, 127, 127)); - darkPalette.setColor(QPalette::Base, QColor(42, 42, 42)); - darkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66)); - darkPalette.setColor(QPalette::ToolTipBase, Qt::white); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127)); - darkPalette.setColor(QPalette::Dark, QColor(35, 35, 35)); - darkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20)); - darkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127)); - darkPalette.setColor(QPalette::BrightText, Qt::red); - darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); - darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); - darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80)); - darkPalette.setColor(QPalette::HighlightedText, Qt::white); - darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127)); - - return darkPalette; -} - -void main_window::prepare_to_exit (void) -{ - // Find files dialog is constructed dynamically, not at time of main_window - // construction. Connecting it to qApp aboutToQuit signal would have - // caused it to run after gui_settings is deleted. - if (m_find_files_dlg) - m_find_files_dlg->save_settings (); - - if (m_set_path_dlg) - m_set_path_dlg->save_settings (); - - write_settings (); - - // No more active dock, otherwise, focus_changed would try to set - // the focus to a dock widget that might not exist anymore - m_active_dock = nullptr; -} - -void main_window::go_to_previous_widget (void) -{ - m_previous_dock->activate (); -} - -void main_window::update_octave_directory (const QString& dir) -{ - // Remove existing entry, if any, then add new directory at top and - // mark it as the current directory. Finally, update the file list - // widget. - - int index = m_current_directory_combo_box->findText (dir); - - if (index >= 0) - m_current_directory_combo_box->removeItem (index); - - m_current_directory_combo_box->insertItem (0, dir); - m_current_directory_combo_box->setCurrentIndex (0); -} - -void main_window::browse_for_directory (void) -{ - // 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 ()) - opts = QFileDialog::DontUseNativeDialog; - - QString dir - = QFileDialog::getExistingDirectory (this, tr ("Browse directories"), nullptr, - QFileDialog::Option (opts)); - - set_current_working_directory (dir); - - // FIXME: on Windows systems, the command window freezes after the - // previous actions. Forcing the focus appears to unstick it. - - focus_command_window (); -} - -void main_window::set_current_working_directory (const QString& dir) -{ - // Change to dir if it is an existing directory. - - QString xdir = (dir.isEmpty () ? "." : dir); - - QFileInfo fileInfo (xdir); - - if (fileInfo.exists () && fileInfo.isDir ()) - { - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - interp.chdir (xdir.toStdString ()); - }); - } -} - -void main_window::change_directory_up (void) -{ - set_current_working_directory (".."); -} - -// Slot that is called if return is pressed in the line edit of the -// 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) -{ - // 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 - // directory. - - QString dir = m_current_directory_combo_box->currentText (); - - int index = m_current_directory_combo_box->findText (dir); - - if (index < 0) - set_current_working_directory (dir); -} - -void main_window::execute_command_in_terminal (const QString& command) -{ - if (m_octave_qobj.experimental_terminal_widget ()) - { - emit execute_command_signal (command); - } - 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 (); - }); - } - - focus_console_after_command (); -} - -void main_window::run_file_in_terminal (const QFileInfo& info) -{ - 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 (); - }); - - focus_console_after_command (); -} - -void main_window::handle_new_figure_request (void) -{ - emit interpreter_event - ([] (interpreter& interp) - { - // INTERPRETER THREAD - - Fbuiltin (interp, ovl ("figure")); - Fdrawnow (interp); - }); -} - -void main_window::handle_enter_debugger (void) -{ - setWindowTitle ("Octave (Debugging)"); - - m_debug_continue->setEnabled (true); - m_debug_step_into->setEnabled (true); - m_debug_step_over->setEnabled (true); - m_debug_step_out->setEnabled (true); - m_debug_quit->setEnabled (true); -} - -void main_window::handle_exit_debugger (void) -{ - setWindowTitle ("Octave"); - - m_debug_continue->setEnabled (false); - m_debug_step_into->setEnabled (false); - m_debug_step_over->setEnabled (m_editor_has_tabs && m_editor_is_octave_file); - m_debug_step_out->setEnabled (false); - m_debug_quit->setEnabled (false); -} - -void main_window::debug_continue (void) -{ - emit interpreter_event - ([=] (interpreter& interp) - { - // 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) -{ - 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); - }); -} - -void main_window::debug_step_over (void) -{ - if (m_debug_quit->isEnabled ()) - { - // We are in debug mode, just call dbstep. - - emit interpreter_event - ([=] (interpreter& interp) + + m_set_path_dlg = new set_path_dialog (this); + + m_set_path_dlg->setModal (false); + m_set_path_dlg->setAttribute (Qt::WA_DeleteOnClose); + m_set_path_dlg->show (); + + // Any interpreter_event signal from a set_path_dialog object is + // handled the same as for the main_window object. + + connect (m_set_path_dlg, QOverload::of (&set_path_dialog::interpreter_event), + this, QOverload::of (&main_window::interpreter_event)); + + connect (m_set_path_dlg, QOverload::of (&set_path_dialog::interpreter_event), + this, QOverload::of (&main_window::interpreter_event)); + + connect (m_set_path_dlg, &set_path_dialog::modify_path_signal, + this, &main_window::modify_path); + + interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); + + qt_interpreter_events *qt_link = interp_qobj->qt_link (); + + connect (qt_link, &qt_interpreter_events::update_path_dialog_signal, + m_set_path_dlg, &set_path_dialog::update_model); + + // Now that all the signal connections are in place for the dialog + // we can set the initial value of the path in the model. + + m_set_path_dlg->update_model (); + } + + void main_window::find_files (const QString& start_dir) + { + + if (! m_find_files_dlg) + { + m_find_files_dlg = new find_files_dialog (this); + + connect (m_find_files_dlg, &find_files_dialog::finished, + this, &main_window::find_files_finished); + + connect (m_find_files_dlg, &find_files_dialog::dir_selected, + m_file_browser_window, &files_dock_widget::set_current_directory); + + connect (m_find_files_dlg, &find_files_dialog::file_selected, + this, QOverload::of (&main_window::open_file_signal)); + + m_find_files_dlg->setWindowModality (Qt::NonModal); + } + + if (! m_find_files_dlg->isVisible ()) + { + m_find_files_dlg->show (); + } + + m_find_files_dlg->set_search_dir (start_dir); + + m_find_files_dlg->activateWindow (); + + } + + void main_window::set_screen_size (int ht, int wd) + { + emit interpreter_event + ([=] () + { + // INTERPRETER THREAD + + command_editor::set_screen_size (ht, wd); + }); + } + + void main_window::clipboard_has_changed () + { + if (m_clipboard->text ().isEmpty ()) + { + m_paste_action->setEnabled (false); + m_clear_clipboard_action->setEnabled (false); + } + else + { + m_paste_action->setEnabled (true); + m_clear_clipboard_action->setEnabled (true); + } + } + + void main_window::clear_clipboard () + { + m_clipboard->clear (QClipboard::Clipboard); + } + + void main_window::disable_menu_shortcuts (bool disable) + { + QHash::const_iterator i = m_hash_menu_text.constBegin (); + + while (i != m_hash_menu_text.constEnd ()) + { + i.key ()->setTitle (i.value ().at (disable)); + ++i; + } + } + + void main_window::restore_create_file_setting () + { + // restore the new files creation setting + + 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) + { + m_file_encoding = new_encoding; + } + + // The following slot is called after files have been selected in the + // open file dialog, possibly with a new selected encoding stored in + // m_file_encoding + void main_window::request_open_files (const QStringList& open_file_names) + { + for (int i = 0; i < open_file_names.count (); i++) + emit open_file_signal (open_file_names.at (i), m_file_encoding, -1); + } + + void main_window::profiler_session () + { + emit interpreter_event + ([=] (interpreter& interp) { // INTERPRETER THREAD - - F__db_next_breakpoint_quiet__ (interp, - ovl (m_suppress_dbg_location)); - Fdbstep (interp); - - command_editor::interrupt (true); + interp.feval (ovl ("profile", "on")); }); - } - else - { - // Not in debug mode: "step into" the current editor file - emit step_into_file_signal (); - } -} - -void main_window::debug_step_out (void) -{ - 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); - }); -} - -void main_window::debug_quit (void) -{ - emit interpreter_event - ([] (interpreter& interp) - { - // INTERPRETER THREAD - - Fdbquit (interp); - - command_editor::interrupt (true); - }); -} - -// -// Functions related to file editing -// -// These are moved from editor to here for also using them when octave -// is built without qscintilla -// -void main_window::request_open_file (void) -{ - // 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 (); - bool is_internal = m_editor_window - && ! settings->value (global_use_custom_editor.key, - global_use_custom_editor.def).toBool (); - - // Create a NonModal message. - QWidget *p = this; - if (is_internal) - p = m_editor_window; - QFileDialog *fileDialog = new QFileDialog (p); - fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*)")); - - fileDialog->setAcceptMode (QFileDialog::AcceptOpen); - fileDialog->setViewMode (QFileDialog::Detail); - fileDialog->setFileMode (QFileDialog::ExistingFiles); - 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 ()) - fileDialog->setOption(QFileDialog::DontUseNativeDialog); - - connect (fileDialog, &QFileDialog::filesSelected, - this, &main_window::request_open_files); - - fileDialog->setWindowModality (Qt::NonModal); - fileDialog->setAttribute (Qt::WA_DeleteOnClose); - fileDialog->show (); -} - -// Create a new script -void main_window::request_new_script (const QString& commands) -{ - emit new_file_signal (commands); -} - -// Create a new function and open it -void main_window::request_new_function (bool) -{ - bool ok; - // Get the name of the new function: Parent of the input dialog is the - // 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 ()) - p = this; - QString new_name = QInputDialog::getText (p, tr ("New Function"), - tr ("New function name:\n"), QLineEdit::Normal, "", &ok); - - if (ok && new_name.length () > 0) - { - // append suffix if it does not already exist - if (new_name.rightRef (2) != ".m") - new_name.append (".m"); - // check whether new files are created without prompt - if (! settings->value (ed_create_new_file).toBool ()) - { - // 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))); - } - // start the edit command - execute_command_in_terminal ("edit " + new_name); - } -} - -void main_window::handle_edit_mfile_request (const QString& fname, - const QString& ffile, - const QString& curr_dir, - int line) -{ - // 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 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) + } + + void main_window::profiler_session_resume () + { + emit interpreter_event + ([=] (interpreter& interp) { - 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) -{ - QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical, - tr ("Octave Editor"), - message, QMessageBox::Ok, this); - msgBox->setWindowModality (Qt::NonModal); - msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); -} - -void main_window::handle_insert_debugger_pointer_request (const QString& file, - int line) -{ - bool cmd_focus = command_window_has_focus (); - - emit insert_debugger_pointer_signal (file, line); - - if (cmd_focus) - focus_command_window (); -} - -void main_window::handle_delete_debugger_pointer_request (const QString& file, - int line) -{ - bool cmd_focus = command_window_has_focus (); - - emit delete_debugger_pointer_signal (file, line); - - if (cmd_focus) - focus_command_window (); -} - -void main_window::handle_update_breakpoint_marker_request (bool insert, - const QString& file, - int line, - const QString& cond) -{ - bool cmd_focus = command_window_has_focus (); - - emit update_breakpoint_marker_signal (insert, file, line, cond); - - if (cmd_focus) - focus_command_window (); -} - -void main_window::read_settings (void) -{ - 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); - - // restore the list of the last directories - QStringList curr_dirs = settings->value (mw_dir_list).toStringList (); - for (int i=0; i < curr_dirs.size (); i++) - { - m_current_directory_combo_box->addItem (curr_dirs.at (i)); - } - emit settings_changed (settings); -} - -void main_window::init_terminal_size (void) -{ - emit init_terminal_size_signal (); -} - -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 ())) - { - do_reset_windows (true); - return; - } - - if (isMaximized()) - { - // If the window state is restored to maximized layout, the - // horizontal layout is not preserved. This cann be avoided by - // setting the geometry to the max. available geometry. However, on - // X11, the available geometry (excluding task bar etc.) is equal to - // the total geometry leading to a full screen mode without window - // decorations. This in turn can be avoided by explicitly adding - // a title bar in the window flags. - - // Get available geometry for current screen and set this - // window's geometry to it. - QScreen *s = windowHandle ()->screen (); - QRect av_geom = s->availableGeometry (); - setGeometry (av_geom); // Set (correct) available geometry - - // Force full title bar - setWindowFlags(Qt::WindowTitleHint - | Qt::WindowMinMaxButtonsHint - | Qt::WindowSystemMenuHint - | Qt::WindowCloseButtonHint); - } - - if (! restoreState (settings->value (mw_state).toByteArray ())) - { - do_reset_windows (true); - return; - } - - // Restore the geometry of all dock-widgets - - for (auto *widget : dock_widget_list ()) - { - // Leave any widgets that existed before main_window was created - // as they were. - - if (widget->adopted ()) - continue; - - QString name = widget->objectName (); - - if (! name.isEmpty ()) + // INTERPRETER THREAD + interp.feval (ovl ("profile", "resume")); + }); + } + + void main_window::profiler_stop () + { + emit interpreter_event + ([=] (interpreter& interp) { - 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 (); - - // If floating, make window from widget. - if (floating) - { - widget->make_window (); - - if (visible) - { - if (settings->value (dw_is_minimized.key.arg (name), - dw_is_minimized.def).toBool ()) - widget->showMinimized (); - else - widget->setVisible (true); - } - else - widget->setVisible (false); - } - else // not floating - { - if (! widget->parent ()) // should not be floating but is - widget->make_widget (false); // no docking, just reparent - - widget->make_widget (); - widget->setVisible (visible); // not floating -> show - } - } - } - - show (); -} - -void main_window::write_settings (void) -{ - 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 ()); - // 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 (); -} - -void main_window::copyClipboard (void) -{ - if (m_current_directory_combo_box->hasFocus ()) - { - QLineEdit *edit = m_current_directory_combo_box->lineEdit (); - if (edit && edit->hasSelectedText ()) - { - QClipboard *clipboard = QApplication::clipboard (); - clipboard->setText (edit->selectedText ()); - } - } - else - emit copyClipboard_signal (); -} - -void main_window::pasteClipboard (void) -{ - if (m_current_directory_combo_box->hasFocus ()) - { - QLineEdit *edit = m_current_directory_combo_box->lineEdit (); - QClipboard *clipboard = QApplication::clipboard (); - QString str = clipboard->text (); - if (edit && str.length () > 0) - { - edit->insert (str); - } - } - else - emit pasteClipboard_signal (); -} - -void main_window::selectAll (void) -{ - if (m_current_directory_combo_box->hasFocus ()) - { - QLineEdit *edit = m_current_directory_combo_box->lineEdit (); - if (edit) - { - edit->selectAll (); - } - } - else - emit selectAll_signal (); -} - -void main_window::handle_gui_status_update (const QString& feature, - const QString& status) -{ - // Put actions that are required for updating a gui features here - - // Profiler on/off - if (! feature.compare ("profiler")) - { - if (! status.compare ("on", Qt::CaseInsensitive)) - handle_profiler_status_update (true); - else if (! status.compare ("off", Qt::CaseInsensitive)) - handle_profiler_status_update (false); - } -} - -void main_window::handle_octave_ready (void) -{ - // actions after the startup files are executed - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - QDir startup_dir = QDir (); // current octave dir after startup - - if (settings) - { - 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 ()); - } - - if (! startup_dir.exists ()) - { - // the configured startup dir does not exist, take actual one - startup_dir = QDir (); - } - - set_current_working_directory (startup_dir.absolutePath ()); - - if (m_editor_window) - { -#if defined (HAVE_QSCINTILLA) - // Octave ready, determine whether to create an empty script. - // 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); -#endif - } - - if (m_octave_qobj.experimental_terminal_widget ()) - { - // Set initial prompt. - - emit interpreter_event - ([] (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)); + // INTERPRETER THREAD + interp.feval (ovl ("profile", "off")); }); - } - - m_command_window->init_command_prompt (); - focus_command_window (); // make sure that the command window has focus -} - -void main_window::handle_set_path_dialog_request (void) -{ - 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->setModal (false); - m_set_path_dlg->setAttribute (Qt::WA_DeleteOnClose); - m_set_path_dlg->show (); - - // Any interpreter_event signal from a set_path_dialog object is - // handled the same as for the main_window object. - - connect (m_set_path_dlg, QOverload::of (&set_path_dialog::interpreter_event), - this, QOverload::of (&main_window::interpreter_event)); - - connect (m_set_path_dlg, QOverload::of (&set_path_dialog::interpreter_event), - this, QOverload::of (&main_window::interpreter_event)); - - connect (m_set_path_dlg, &set_path_dialog::modify_path_signal, - this, &main_window::modify_path); - - interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - - qt_interpreter_events *qt_link = interp_qobj->qt_link (); - - connect (qt_link, &qt_interpreter_events::update_path_dialog_signal, - m_set_path_dlg, &set_path_dialog::update_model); - - // Now that all the signal connections are in place for the dialog - // we can set the initial value of the path in the model. - - m_set_path_dlg->update_model (); -} - -void main_window::find_files (const QString& start_dir) -{ - - if (! m_find_files_dlg) - { - m_find_files_dlg = new find_files_dialog (this, m_octave_qobj); - - connect (m_find_files_dlg, &find_files_dialog::finished, - this, &main_window::find_files_finished); - - connect (m_find_files_dlg, &find_files_dialog::dir_selected, - m_file_browser_window, &files_dock_widget::set_current_directory); - - connect (m_find_files_dlg, &find_files_dialog::file_selected, - this, QOverload::of (&main_window::open_file_signal)); - - m_find_files_dlg->setWindowModality (Qt::NonModal); - } - - if (! m_find_files_dlg->isVisible ()) - { - m_find_files_dlg->show (); - } - - m_find_files_dlg->set_search_dir (start_dir); - - m_find_files_dlg->activateWindow (); - -} - -void main_window::set_screen_size (int ht, int wd) -{ - emit interpreter_event - ([=] (void) - { - // INTERPRETER THREAD - - command_editor::set_screen_size (ht, wd); - }); -} - -void main_window::clipboard_has_changed (void) -{ - if (m_clipboard->text ().isEmpty ()) - { - m_paste_action->setEnabled (false); - m_clear_clipboard_action->setEnabled (false); - } - else - { - m_paste_action->setEnabled (true); - m_clear_clipboard_action->setEnabled (true); - } -} - -void main_window::clear_clipboard (void) -{ - m_clipboard->clear (QClipboard::Clipboard); -} - -void main_window::disable_menu_shortcuts (bool disable) -{ - QHash::const_iterator i = m_hash_menu_text.constBegin (); - - while (i != m_hash_menu_text.constEnd ()) - { - i.key ()->setTitle (i.value ().at (disable)); - ++i; - } -} - -void main_window::restore_create_file_setting (void) -{ - // 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))); -} - -void main_window::set_file_encoding (const QString& new_encoding) -{ - m_file_encoding = new_encoding; -} - -// The following slot is called after files have been selected in the -// open file dialog, possibly with a new selected encoding stored in -// m_file_encoding -void main_window::request_open_files (const QStringList& open_file_names) -{ - for (int i = 0; i < open_file_names.count (); i++) - emit open_file_signal (open_file_names.at (i), m_file_encoding, -1); -} - -void main_window::profiler_session (void) -{ - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Ffeval (interp, ovl ("profile","on")); - }); -} - -void main_window::profiler_session_resume (void) -{ - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Ffeval (interp, ovl ("profile","resume")); - }); -} - -void main_window::profiler_stop (void) -{ - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Ffeval (interp, ovl ("profile","off")); - }); -} - -void main_window::handle_profiler_status_update (bool active) -{ - m_profiler_start->setEnabled (! active); - m_profiler_resume->setEnabled (! active); - m_profiler_stop->setEnabled (active); - - led_indicator::led_state state = led_indicator::LED_STATE_INACTIVE; - if (active) - state = led_indicator::LED_STATE_ACTIVE; - m_profiler_status_indicator->set_state (state); -} - -void main_window::profiler_show (void) -{ - // Do not use a separate interpreter event as in the other - // profiler slots since the output of the command "profshow" - // would obscure the prompt and we do not need to emimt a signal - // for action that is required in the gui after rhe command - execute_command_in_terminal ("profshow"); -} - -void main_window::closeEvent (QCloseEvent *e) -{ - write_settings (); - - if (confirm_shutdown ()) - { - // FIXME: Instead of ignoring the event and posting an - // interpreter event, should we just accept the event and - // shutdown and clean up the interpreter as part of closing the - // GUI? Going that route might make it easier to close the GUI - // without having to stop the interpreter, for example, if the - // GUI is started from the interpreter command line. - + } + + void main_window::handle_profiler_status_update (bool active) + { + m_profiler_start->setEnabled (! active); + m_profiler_resume->setEnabled (! active); + m_profiler_stop->setEnabled (active); + + led_indicator::led_state state = led_indicator::LED_STATE_INACTIVE; + if (active) + state = led_indicator::LED_STATE_ACTIVE; + m_profiler_status_indicator->set_state (state); + } + + 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" + // would obscure the prompt and we do not need to emimt a signal + // for action that is required in the gui after rhe command + execute_command_in_terminal ("profshow"); + } + + void main_window::closeEvent (QCloseEvent *e) + { + write_settings (); + + if (confirm_shutdown ()) + { + // FIXME: Instead of ignoring the event and posting an + // interpreter event, should we just accept the event and + // shutdown and clean up the interpreter as part of closing the + // GUI? Going that route might make it easier to close the GUI + // without having to stop the interpreter, for example, if the + // GUI is started from the interpreter command line. + + e->ignore (); + + if (m_octave_qobj.experimental_terminal_widget () + && ! m_octave_qobj.is_gui_app ()) + emit close_gui_signal (); + else + { + emit interpreter_event + ([] (interpreter& interp) + { + // INTERPRETER THREAD + + interp.quit (0, false, false); + }); + } + } + else e->ignore (); - - if (m_octave_qobj.experimental_terminal_widget () - && ! m_octave_qobj.is_gui_app ()) - emit close_gui_signal (); - else - { - emit interpreter_event - ([] (interpreter& interp) - { - // INTERPRETER THREAD - - interp.quit (0, false, false); - }); - } - } - else - e->ignore (); -} - -void main_window::construct_central_widget (void) -{ - // Create and set the central widget. QMainWindow takes ownership of - // the widget (pointer) so there is no need to delete the object upon - // destroying this main_window. - - QWidget *dummyWidget = new QWidget (); - dummyWidget->setObjectName ("CentralDummyWidget"); - dummyWidget->resize (10, 10); - dummyWidget->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); - dummyWidget->hide (); - setCentralWidget (dummyWidget); -} + } + + 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 + // destroying this main_window. + + QWidget *dummyWidget = new QWidget (); + dummyWidget->setObjectName ("CentralDummyWidget"); + dummyWidget->resize (10, 10); + dummyWidget->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); + dummyWidget->hide (); + setCentralWidget (dummyWidget); + } // Main subroutine of the constructor -void main_window::construct (void) -{ - setWindowIcon (QIcon (dw_icon_set_names["NONE"])); - - interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - - qt_interpreter_events *qt_link = interp_qobj->qt_link (); - - construct_menu_bar (); - - construct_tool_bar (); - - // FIXME: Is this action intended to be about quitting application - // or closing the main window? - connect (qApp, &QApplication::aboutToQuit, - this, &main_window::prepare_to_exit); - - connect (qApp, &QApplication::focusChanged, - this, &main_window::focus_changed); - - connect (this, &main_window::settings_changed, - this, [=] (const gui_settings *settings) { notice_settings (settings); }); - - // Connections for signals from the interpreter thread where the slot - // should be executed by the gui thread - - connect (this, &main_window::warning_function_not_found_signal, - this, &main_window::warning_function_not_found); - - setWindowTitle ("Octave"); - - setStatusBar (m_status_bar); - - // Signals for removing/renaming files/dirs in the temrinal window - connect (qt_link, &qt_interpreter_events::file_remove_signal, - this, &main_window::file_remove_proxy); - - connect (this, QOverload::of (&main_window::interpreter_event), - &m_octave_qobj, QOverload::of (&base_qobject::interpreter_event)); - - connect (this, QOverload::of (&main_window::interpreter_event), - &m_octave_qobj, QOverload::of (&base_qobject::interpreter_event)); - - configure_shortcuts (); -} - -void main_window::construct_octave_qt_link (void) -{ - interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - - qt_interpreter_events *qt_link = interp_qobj->qt_link (); - - connect (qt_link, &qt_interpreter_events::settings_changed, - this, &main_window::notice_settings); - - connect (qt_link, &qt_interpreter_events::apply_new_settings, - this, &main_window::request_reload_settings); - - connect (qt_link, &qt_interpreter_events::directory_changed_signal, - this, &main_window::update_octave_directory); - - connect (qt_link, &qt_interpreter_events::execute_command_in_terminal_signal, - this, &main_window::execute_command_in_terminal); - - connect (qt_link, &qt_interpreter_events::enter_debugger_signal, - this, &main_window::handle_enter_debugger); - - connect (qt_link, &qt_interpreter_events::exit_debugger_signal, - this, &main_window::handle_exit_debugger); - - connect (qt_link, &qt_interpreter_events::show_preferences_signal, - this, [=] () { process_settings_dialog_request (); }); - - connect (qt_link, &qt_interpreter_events::insert_debugger_pointer_signal, - this, &main_window::handle_insert_debugger_pointer_request); - - connect (qt_link, &qt_interpreter_events::delete_debugger_pointer_signal, - this, &main_window::handle_delete_debugger_pointer_request); - - connect (qt_link, &qt_interpreter_events::update_breakpoint_marker_signal, - this, &main_window::handle_update_breakpoint_marker_request); - - connect (qt_link, &qt_interpreter_events::gui_status_update_signal, - this, &main_window::handle_gui_status_update); - - connect (qt_link, &qt_interpreter_events::update_gui_lexer_signal, - this, &main_window::update_gui_lexer_signal); -} - -QAction* main_window::add_action (QMenu *menu, const QIcon& icon, - const QString& text, const char *member, - const QWidget *receiver) -{ - QAction *a; - - if (receiver) - a = menu->addAction (icon, text, receiver, member); - else - a = menu->addAction (icon, text, this, member); - - addAction (a); // important for shortcut context - a->setShortcutContext (Qt::ApplicationShortcut); - return a; -} - -QMenu* main_window::m_add_menu (QMenuBar *p, QString name) -{ - QMenu *menu = p->addMenu (name); - - QString base_name = name; // get a copy - // replace intended '&' ("&&") by a temp. string - base_name.replace ("&&", "___octave_amp_replacement___"); - // remove single '&' (shortcut) - base_name.remove ("&"); - // restore intended '&' - base_name.replace ("___octave_amp_replacement___", "&&"); - - // remember names with and without shortcut - m_hash_menu_text[menu] = QStringList ({ name, base_name }); - - return menu; -} - -void main_window::construct_menu_bar (void) -{ - QMenuBar *menu_bar = menuBar (); - - construct_file_menu (menu_bar); - - construct_edit_menu (menu_bar); - - construct_debug_menu (menu_bar); - - construct_tools_menu (menu_bar); - - construct_window_menu (menu_bar); - - construct_help_menu (menu_bar); - - construct_news_menu (menu_bar); + void main_window::construct () + { + setWindowIcon (QIcon (dw_icon_set_names["NONE"])); + + interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); + + qt_interpreter_events *qt_link = interp_qobj->qt_link (); + + construct_menu_bar (); + + construct_tool_bar (); + + // FIXME: Is this action intended to be about quitting application + // or closing the main window? + connect (qApp, &QApplication::aboutToQuit, + this, &main_window::prepare_to_exit); + + connect (qApp, &QApplication::focusChanged, + this, &main_window::focus_changed); + + // Default argument requires wrapper. + connect (this, &main_window::settings_changed, + this, [=] () { notice_settings (); }); + + // Connections for signals from the interpreter thread where the slot + // should be executed by the gui thread + + connect (this, &main_window::warning_function_not_found_signal, + this, &main_window::warning_function_not_found); + + setWindowTitle ("Octave"); + + setStatusBar (m_status_bar); + + // Signals for removing/renaming files/dirs in the temrinal window + connect (qt_link, &qt_interpreter_events::file_remove_signal, + this, &main_window::file_remove_proxy); + + connect (this, QOverload::of (&main_window::interpreter_event), + &m_octave_qobj, QOverload::of (&base_qobject::interpreter_event)); + + connect (this, QOverload::of (&main_window::interpreter_event), + &m_octave_qobj, QOverload::of (&base_qobject::interpreter_event)); + + configure_shortcuts (); + } + + void main_window::construct_octave_qt_link () + { + interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); + + qt_interpreter_events *qt_link = interp_qobj->qt_link (); + + connect (qt_link, &qt_interpreter_events::settings_changed, + this, &main_window::notice_settings); + + connect (qt_link, &qt_interpreter_events::apply_new_settings, + this, &main_window::request_reload_settings); + + connect (qt_link, &qt_interpreter_events::directory_changed_signal, + this, &main_window::update_octave_directory); + + connect (qt_link, &qt_interpreter_events::execute_command_in_terminal_signal, + this, &main_window::execute_command_in_terminal); + + connect (qt_link, &qt_interpreter_events::enter_debugger_signal, + this, &main_window::handle_enter_debugger); + + connect (qt_link, &qt_interpreter_events::exit_debugger_signal, + this, &main_window::handle_exit_debugger); + + connect (qt_link, &qt_interpreter_events::show_preferences_signal, + this, [=] () { process_settings_dialog_request (); }); + + connect (qt_link, &qt_interpreter_events::insert_debugger_pointer_signal, + this, &main_window::handle_insert_debugger_pointer_request); + + connect (qt_link, &qt_interpreter_events::delete_debugger_pointer_signal, + this, &main_window::handle_delete_debugger_pointer_request); + + connect (qt_link, &qt_interpreter_events::update_breakpoint_marker_signal, + this, &main_window::handle_update_breakpoint_marker_request); + + connect (qt_link, &qt_interpreter_events::gui_status_update_signal, + this, &main_window::handle_gui_status_update); + + connect (qt_link, &qt_interpreter_events::update_gui_lexer_signal, + this, &main_window::update_gui_lexer_signal); + } + + QAction* main_window::add_action (QMenu *menu, const QIcon& icon, + const QString& text, const char *member, + const QWidget *receiver) + { + QAction *a; + + if (receiver) + a = menu->addAction (icon, text, receiver, member); + else + a = menu->addAction (icon, text, this, member); + + addAction (a); // important for shortcut context + a->setShortcutContext (Qt::ApplicationShortcut); + return a; + } + + QMenu* main_window::m_add_menu (QMenuBar *p, QString name) + { + QMenu *menu = p->addMenu (name); + + QString base_name = name; // get a copy + // replace intended '&' ("&&") by a temp. string + base_name.replace ("&&", "___octave_amp_replacement___"); + // remove single '&' (shortcut) + base_name.remove ("&"); + // restore intended '&' + base_name.replace ("___octave_amp_replacement___", "&&"); + + // remember names with and without shortcut + m_hash_menu_text[menu] = QStringList ({ name, base_name }); + + return menu; + } + + void main_window::construct_menu_bar () + { + QMenuBar *menu_bar = menuBar (); + + construct_file_menu (menu_bar); + + construct_edit_menu (menu_bar); + + construct_debug_menu (menu_bar); + + construct_tools_menu (menu_bar); + + construct_window_menu (menu_bar); + + construct_help_menu (menu_bar); + + construct_news_menu (menu_bar); #if defined (HAVE_QSCINTILLA) - // call the editor to add actions which should also be available in the - // editor's menu and tool bar - QList shared_actions = { - m_new_script_action, - m_new_function_action, - m_open_action, - m_find_files_action, - m_undo_action, - m_copy_action, - m_paste_action, - m_select_all_action - }; - m_editor_window->insert_global_actions (shared_actions); + // call the editor to add actions which should also be available in the + // editor's menu and tool bar + QList shared_actions = { + m_new_script_action, + m_new_function_action, + m_open_action, + m_find_files_action, + m_undo_action, + m_copy_action, + m_paste_action, + m_select_all_action + }; + m_editor_window->insert_global_actions (shared_actions); #endif -} - -void main_window::construct_file_menu (QMenuBar *p) -{ - QMenu *file_menu = m_add_menu (p, tr ("&File")); - - 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); - m_open_action->setToolTip (tr ("Open an existing file in editor")); + } + + void main_window::construct_file_menu (QMenuBar *p) + { + QMenu *file_menu = m_add_menu (p, tr ("&File")); + + construct_new_menu (file_menu); + + 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) - file_menu->addMenu (m_editor_window->get_mru_menu ()); + file_menu->addMenu (m_editor_window->get_mru_menu ()); #endif - 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); - - file_menu->addSeparator (); - - m_exit_action = add_action ( - file_menu, QIcon (), tr ("Exit"), - SLOT (close (void)), this); - m_exit_action->setMenuRole (QAction::QuitRole); - - // Connect signal related to opening or creating editor files - connect (this, SIGNAL (new_file_signal (const QString&)), - m_active_editor, SLOT (request_new_file (const QString&))); - - connect (this, SIGNAL (open_file_signal (const QString&)), - m_active_editor, SLOT (request_open_file (const QString&))); - - connect (this, - SIGNAL (open_file_signal (const QString&, const QString&, int)), - m_active_editor, - SLOT (request_open_file (const QString&, const QString&, int))); -} - -void main_window::construct_new_menu (QMenu *p) -{ - 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); -} - -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 (); - m_undo_action - = edit_menu->addAction (rmgr.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, - &main_window::copyClipboard); - m_copy_action->setShortcutContext (Qt::ApplicationShortcut); - - m_paste_action - = edit_menu->addAction (rmgr.icon ("edit-paste"), tr ("Paste"), this, - &main_window::pasteClipboard); - m_paste_action->setShortcutContext (Qt::ApplicationShortcut); - - m_select_all_action - = edit_menu->addAction (tr ("Select All"), this, - &main_window::selectAll); - m_select_all_action->setShortcutContext (Qt::ApplicationShortcut); - - m_clear_clipboard_action - = edit_menu->addAction (tr ("Clear Clipboard"), this, - &main_window::clear_clipboard); - - edit_menu->addSeparator (); - - m_find_files_action - = edit_menu->addAction (rmgr.icon ("edit-find"), tr ("Find Files...")); - - edit_menu->addSeparator (); - - m_clear_command_window_action - = edit_menu->addAction (tr ("Clear Command Window")); - - m_clear_command_history_action - = edit_menu->addAction (tr ("Clear Command History")); - - m_clear_workspace_action - = edit_menu->addAction (tr ("Clear Workspace")); - - edit_menu->addSeparator (); - - m_set_path_action - = edit_menu->addAction (tr ("Set Path")); - - m_preferences_action - = edit_menu->addAction (rmgr.icon ("preferences-system"), - tr ("Preferences...")); - - connect (m_find_files_action, &QAction::triggered, - this, [=] () { find_files (); }); - - connect (m_clear_command_window_action, &QAction::triggered, - this, &main_window::handle_clear_command_window_request); - - connect (m_clear_command_history_action, &QAction::triggered, - this, &main_window::handle_clear_history_request); - - connect (m_clear_workspace_action, &QAction::triggered, - this, &main_window::handle_clear_workspace_request); - - connect (m_clipboard, &QClipboard::dataChanged, - this, &main_window::clipboard_has_changed); - clipboard_has_changed (); + file_menu->addSeparator (); + + 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 ()), this); + m_exit_action->setMenuRole (QAction::QuitRole); + + // Connect signal related to opening or creating editor files + connect (this, SIGNAL (new_file_signal (const QString&)), + m_active_editor, SLOT (request_new_file (const QString&))); + + connect (this, SIGNAL (open_file_signal (const QString&)), + m_active_editor, SLOT (request_open_file (const QString&))); + + connect (this, + SIGNAL (open_file_signal (const QString&, const QString&, int)), + m_active_editor, + SLOT (request_open_file (const QString&, const QString&, int))); + } + + void main_window::construct_new_menu (QMenu *p) + { + QMenu *new_menu = p->addMenu (tr ("New")); + + 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; + + gui_settings settings; + + m_undo_action + = edit_menu->addAction (settings.icon ("edit-undo"), tr ("Undo")); + m_undo_action->setShortcutContext (Qt::ApplicationShortcut); + + edit_menu->addSeparator (); + + m_copy_action + = 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 (settings.icon ("edit-paste"), tr ("Paste"), this, + &main_window::pasteClipboard); + m_paste_action->setShortcutContext (Qt::ApplicationShortcut); + + m_select_all_action + = edit_menu->addAction (tr ("Select All"), this, + &main_window::selectAll); + m_select_all_action->setShortcutContext (Qt::ApplicationShortcut); + + m_clear_clipboard_action + = edit_menu->addAction (tr ("Clear Clipboard"), this, + &main_window::clear_clipboard); + + edit_menu->addSeparator (); + + m_find_files_action + = edit_menu->addAction (settings.icon ("edit-find"), + tr ("Find Files...")); + + edit_menu->addSeparator (); + + m_clear_command_window_action + = edit_menu->addAction (tr ("Clear Command Window")); + + m_clear_command_history_action + = edit_menu->addAction (tr ("Clear Command History")); + + m_clear_workspace_action + = edit_menu->addAction (tr ("Clear Workspace")); + + edit_menu->addSeparator (); + + m_set_path_action + = edit_menu->addAction (tr ("Set Path")); + + m_preferences_action + = edit_menu->addAction (settings.icon ("preferences-system"), + tr ("Preferences...")); + + connect (m_find_files_action, &QAction::triggered, + this, [=] () { find_files (); }); + + connect (m_clear_command_window_action, &QAction::triggered, + this, &main_window::handle_clear_command_window_request); + + connect (m_clear_command_history_action, &QAction::triggered, + this, &main_window::handle_clear_history_request); + + connect (m_clear_workspace_action, &QAction::triggered, + this, &main_window::handle_clear_workspace_request); + + connect (m_clipboard, &QClipboard::dataChanged, + this, &main_window::clipboard_has_changed); + clipboard_has_changed (); #if defined (Q_OS_WIN32) - // Always enable paste action (unreliable clipboard signals in windows) - // FIXME: This has to be removed, when the clipboard signals in windows - // are working again - m_paste_action->setEnabled (true); - m_clear_clipboard_action->setEnabled (true); + // Always enable paste action (unreliable clipboard signals in windows) + // FIXME: This has to be removed, when the clipboard signals in windows + // are working again + m_paste_action->setEnabled (true); + m_clear_clipboard_action->setEnabled (true); #endif - connect (m_preferences_action, &QAction::triggered, - this, [=] () { process_settings_dialog_request (); }); - - connect (m_set_path_action, &QAction::triggered, - this, &main_window::handle_set_path_dialog_request); - -} - -QAction * main_window::construct_debug_menu_item (const char *icon, - 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)), - item, member); - - action->setEnabled (false); + connect (m_preferences_action, &QAction::triggered, + this, [=] () { process_settings_dialog_request (); }); + + connect (m_set_path_action, &QAction::triggered, + this, &main_window::handle_set_path_dialog_request); + + } + + QAction * main_window::construct_debug_menu_item (const char *icon, + const QString& item, + const char *member) + { + gui_settings settings; + + QAction *action = add_action (m_debug_menu, settings.icon (QString (icon)), + item, member); + + action->setEnabled (false); #if defined (HAVE_QSCINTILLA) - m_editor_window->debug_menu ()->addAction (action); - m_editor_window->toolbar ()->addAction (action); + m_editor_window->debug_menu ()->addAction (action); + m_editor_window->toolbar ()->addAction (action); #endif - return action; -} - -void main_window::construct_debug_menu (QMenuBar *p) -{ - m_debug_menu = m_add_menu (p, tr ("De&bug")); - - m_debug_step_over - = construct_debug_menu_item ("db-step", tr ("Step"), - SLOT (debug_step_over (void))); - - m_debug_step_into - = construct_debug_menu_item ("db-step-in", tr ("Step In"), - SLOT (debug_step_into (void))); - - m_debug_step_out - = construct_debug_menu_item ("db-step-out", tr ("Step Out"), - SLOT (debug_step_out (void))); - - m_debug_continue - = construct_debug_menu_item ("db-cont", tr ("Continue"), - SLOT (debug_continue (void))); - - m_debug_menu->addSeparator (); + return action; + } + + void main_window::construct_debug_menu (QMenuBar *p) + { + m_debug_menu = m_add_menu (p, tr ("De&bug")); + + m_debug_step_over + = construct_debug_menu_item ("db-step", tr ("Step"), + SLOT (debug_step_over ())); + + m_debug_step_into + = construct_debug_menu_item ("db-step-in", tr ("Step In"), + SLOT (debug_step_into ())); + + m_debug_step_out + = construct_debug_menu_item ("db-step-out", tr ("Step Out"), + SLOT (debug_step_out ())); + + m_debug_continue + = construct_debug_menu_item ("db-cont", tr ("Continue"), + SLOT (debug_continue ())); + + m_debug_menu->addSeparator (); #if defined (HAVE_QSCINTILLA) - m_editor_window->debug_menu ()->addSeparator (); + m_editor_window->debug_menu ()->addSeparator (); #endif - m_debug_quit - = construct_debug_menu_item ("db-stop", tr ("Quit Debug Mode"), - SLOT (debug_quit (void))); -} - -void main_window::construct_tools_menu (QMenuBar *p) -{ - QMenu *tools_menu = m_add_menu (p, tr ("&Tools")); - - m_profiler_start = add_action (tools_menu, QIcon (), - tr ("Start &Profiler Session"), SLOT (profiler_session ())); - - m_profiler_resume = add_action (tools_menu, QIcon (), - tr ("&Resume Profiler Session"), SLOT (profiler_session_resume ())); - - m_profiler_stop = add_action (tools_menu, QIcon (), - 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 ())); -} - -void main_window::editor_tabs_changed (bool have_tabs, bool is_octave) -{ - // Set state of actions which depend on the existence of editor tabs - m_editor_has_tabs = have_tabs; - m_editor_is_octave_file = is_octave; - m_debug_step_over->setEnabled (have_tabs && is_octave); -} - -QAction * main_window::construct_window_menu_item (QMenu *p, - const QString& item, - bool checkable, - QWidget *widget) -{ - QAction *action = p->addAction (QIcon (), item); - - addAction (action); // important for shortcut context - action->setCheckable (checkable); - action->setShortcutContext (Qt::ApplicationShortcut); - - if (widget) // might be zero for m_editor_window - { - if (checkable) - { - // action for visibility of dock widget - connect (action, SIGNAL (toggled (bool)), - widget, SLOT (setVisible (bool))); - - connect (widget, SIGNAL (active_changed (bool)), - action, SLOT (setChecked (bool))); - } - else - { - // action for focus of dock widget - connect (action, SIGNAL (triggered (void)), - widget, SLOT (activate (void))); - } - } - else - { - action->setEnabled (false); - } - - return action; -} - -void main_window::construct_window_menu (QMenuBar *p) -{ - QMenu *window_menu = m_add_menu (p, tr ("&Window")); - - m_show_command_window_action = construct_window_menu_item - (window_menu, tr ("Show Command Window"), true, m_command_window); - - m_show_history_action = construct_window_menu_item - (window_menu, tr ("Show Command History"), true, m_history_window); - - m_show_file_browser_action = construct_window_menu_item - (window_menu, tr ("Show File Browser"), true, m_file_browser_window); - - m_show_workspace_action = construct_window_menu_item - (window_menu, tr ("Show Workspace"), true, m_workspace_window); - - m_show_editor_action = construct_window_menu_item - (window_menu, tr ("Show Editor"), true, m_editor_window); - - m_show_documentation_action = construct_window_menu_item - (window_menu, tr ("Show Documentation"), true, m_doc_browser_window); - - m_show_variable_editor_action = construct_window_menu_item - (window_menu, tr ("Show Variable Editor"), true, m_variable_editor_window); - - window_menu->addSeparator (); - - m_command_window_action = construct_window_menu_item - (window_menu, tr ("Command Window"), false, m_command_window); - - m_history_action = construct_window_menu_item - (window_menu, tr ("Command History"), false, m_history_window); - - m_file_browser_action = construct_window_menu_item - (window_menu, tr ("File Browser"), false, m_file_browser_window); - - m_workspace_action = construct_window_menu_item - (window_menu, tr ("Workspace"), false, m_workspace_window); - - m_editor_action = construct_window_menu_item - (window_menu, tr ("Editor"), false, m_editor_window); - - m_documentation_action = construct_window_menu_item - (window_menu, tr ("Documentation"), false, m_doc_browser_window); - - m_variable_editor_action = construct_window_menu_item - (window_menu, tr ("Variable Editor"), false, m_variable_editor_window); - - window_menu->addSeparator (); - - m_previous_dock_action = add_action (window_menu, QIcon (), - tr ("Previous Widget"), SLOT (go_to_previous_widget (void))); - - window_menu->addSeparator (); - - m_reset_windows_action = add_action (window_menu, QIcon (), - tr ("Reset Default Window Layout"), SLOT (reset_windows (void))); -} - -void main_window::construct_help_menu (QMenuBar *p) -{ - QMenu *help_menu = m_add_menu (p, tr ("&Help")); - - construct_documentation_menu (help_menu); - - help_menu->addSeparator (); - - m_report_bug_action = add_action (help_menu, QIcon (), - tr ("Report Bug"), SLOT (open_bug_tracker_page ())); - - m_octave_packages_action = add_action (help_menu, QIcon (), - tr ("Octave Packages"), SLOT (open_octave_packages_page ())); - - m_contribute_action = add_action (help_menu, QIcon (), - tr ("Contribute"), SLOT (open_contribute_page ())); - - m_developer_action = add_action (help_menu, QIcon (), - tr ("Donate to Octave"), SLOT (open_donate_page ())); - - help_menu->addSeparator (); - - m_about_octave_action = add_action (help_menu, QIcon (), - tr ("About Octave"), SLOT (show_about_octave ())); -} - -void main_window::construct_documentation_menu (QMenu *p) -{ - QMenu *doc_menu = p->addMenu (tr ("Documentation")); - - m_ondisk_doc_action = add_action (doc_menu, QIcon (), - tr ("On Disk"), SLOT (activate ()), m_doc_browser_window); - - m_online_doc_action = add_action (doc_menu, QIcon (), - tr ("Online"), SLOT (open_online_documentation_page ())); -} - -void main_window::construct_news_menu (QMenuBar *p) -{ - QMenu *news_menu = m_add_menu (p, tr ("&News")); - - m_release_notes_action - = news_menu->addAction (QIcon (), tr ("Release Notes"), - [=] () { - emit show_release_notes_signal (); - }); - addAction (m_release_notes_action); - m_release_notes_action->setShortcutContext (Qt::ApplicationShortcut); - - m_current_news_action - = news_menu->addAction (QIcon (), tr ("Community News"), - [=] () { - emit show_community_news_signal (-1); - }); - addAction (m_current_news_action); - m_current_news_action->setShortcutContext (Qt::ApplicationShortcut); -} - -void main_window::construct_tool_bar (void) -{ - m_main_tool_bar = addToolBar (tr ("Toolbar")); - m_main_tool_bar->setStyleSheet (m_main_tool_bar->styleSheet () - + global_toolbar_style); - - m_main_tool_bar->setObjectName ("MainToolBar"); - m_main_tool_bar->addAction (m_new_script_action); - m_main_tool_bar->addAction (m_open_action); - - m_main_tool_bar->addSeparator (); - - m_main_tool_bar->addAction (m_copy_action); - m_main_tool_bar->addAction (m_paste_action); - m_main_tool_bar->addAction (m_undo_action); - - m_main_tool_bar->addSeparator (); - - m_current_directory_combo_box = new QComboBox (this); - QFontMetrics fm = m_current_directory_combo_box->fontMetrics (); - m_current_directory_combo_box->setFixedWidth (48*fm.averageCharWidth ()); - 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); - QSizePolicy sizePol (QSizePolicy::Preferred, QSizePolicy::Preferred); - m_current_directory_combo_box->setSizePolicy (sizePol); - - // addWidget takes ownership of the objects so there is no - // 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 (); - QAction *current_dir_up - = m_main_tool_bar->addAction (rmgr.icon ("folder-up", false, "go-up"), - tr ("One directory up")); - QAction *current_dir_search - = m_main_tool_bar->addAction (rmgr.icon ("folder"), - tr ("Browse directories")); - - connect (m_current_directory_combo_box, SIGNAL (activated (const QString&)), - this, SLOT (set_current_working_directory (const QString&))); - - connect (m_current_directory_combo_box->lineEdit (), - &QLineEdit::returnPressed, - this, &main_window::accept_directory_line_edit); - - connect (current_dir_search, &QAction::triggered, - this, &main_window::browse_for_directory); - - connect (current_dir_up, &QAction::triggered, - this, &main_window::change_directory_up); - - connect (m_undo_action, &QAction::triggered, - this, &main_window::handle_undo_request); -} - -void main_window::focus_console_after_command (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (settings->value (cs_focus_cmd).toBool ()) - focus_command_window (); -} - -void main_window::configure_shortcuts (void) -{ - 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); - - // 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); - - // 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); - - // 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); - - // 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); - // 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); - - // 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); - - // 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); -} - -QList main_window::dock_widget_list (void) -{ - QList list = QList (); - list.append (static_cast (m_command_window)); - list.append (static_cast (m_history_window)); - list.append (static_cast (m_file_browser_window)); - list.append (static_cast (m_doc_browser_window)); + m_debug_quit + = construct_debug_menu_item ("db-stop", tr ("Quit Debug Mode"), + SLOT (debug_quit ())); + } + + void main_window::construct_tools_menu (QMenuBar *p) + { + QMenu *tools_menu = m_add_menu (p, tr ("&Tools")); + + m_profiler_start = add_action (tools_menu, QIcon (), + tr ("Start &Profiler Session"), SLOT (profiler_session ())); + + m_profiler_resume = add_action (tools_menu, QIcon (), + tr ("&Resume Profiler Session"), SLOT (profiler_session_resume ())); + + m_profiler_stop = add_action (tools_menu, QIcon (), + 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 ())); + } + + void main_window::editor_tabs_changed (bool have_tabs, bool is_octave) + { + // Set state of actions which depend on the existence of editor tabs + m_editor_has_tabs = have_tabs; + m_editor_is_octave_file = is_octave; + m_debug_step_over->setEnabled (have_tabs && is_octave); + } + + QAction * main_window::construct_window_menu_item (QMenu *p, + const QString& item, + bool checkable, + QWidget *widget) + { + QAction *action = p->addAction (QIcon (), item); + + addAction (action); // important for shortcut context + action->setCheckable (checkable); + action->setShortcutContext (Qt::ApplicationShortcut); + + if (widget) // might be zero for m_editor_window + { + if (checkable) + { + // action for visibility of dock widget + connect (action, SIGNAL (toggled (bool)), + widget, SLOT (setVisible (bool))); + + connect (widget, SIGNAL (active_changed (bool)), + action, SLOT (setChecked (bool))); + } + else + { + // action for focus of dock widget + connect (action, SIGNAL (triggered ()), + widget, SLOT (activate ())); + } + } + else + { + action->setEnabled (false); + } + + return action; + } + + void main_window::construct_window_menu (QMenuBar *p) + { + QMenu *window_menu = m_add_menu (p, tr ("&Window")); + + m_show_command_window_action = construct_window_menu_item + (window_menu, tr ("Show Command Window"), true, m_command_window); + + m_show_history_action = construct_window_menu_item + (window_menu, tr ("Show Command History"), true, m_history_window); + + m_show_file_browser_action = construct_window_menu_item + (window_menu, tr ("Show File Browser"), true, m_file_browser_window); + + m_show_workspace_action = construct_window_menu_item + (window_menu, tr ("Show Workspace"), true, m_workspace_window); + + m_show_editor_action = construct_window_menu_item + (window_menu, tr ("Show Editor"), true, m_editor_window); + + m_show_documentation_action = construct_window_menu_item + (window_menu, tr ("Show Documentation"), true, m_doc_browser_window); + + m_show_variable_editor_action = construct_window_menu_item + (window_menu, tr ("Show Variable Editor"), true, m_variable_editor_window); + + window_menu->addSeparator (); + + m_command_window_action = construct_window_menu_item + (window_menu, tr ("Command Window"), false, m_command_window); + + m_history_action = construct_window_menu_item + (window_menu, tr ("Command History"), false, m_history_window); + + m_file_browser_action = construct_window_menu_item + (window_menu, tr ("File Browser"), false, m_file_browser_window); + + m_workspace_action = construct_window_menu_item + (window_menu, tr ("Workspace"), false, m_workspace_window); + + m_editor_action = construct_window_menu_item + (window_menu, tr ("Editor"), false, m_editor_window); + + m_documentation_action = construct_window_menu_item + (window_menu, tr ("Documentation"), false, m_doc_browser_window); + + m_variable_editor_action = construct_window_menu_item + (window_menu, tr ("Variable Editor"), false, m_variable_editor_window); + + window_menu->addSeparator (); + + m_previous_dock_action = add_action (window_menu, QIcon (), + 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 main_window::construct_help_menu (QMenuBar *p) + { + QMenu *help_menu = m_add_menu (p, tr ("&Help")); + + construct_documentation_menu (help_menu); + + help_menu->addSeparator (); + + m_report_bug_action = add_action (help_menu, QIcon (), + tr ("Report Bug"), SLOT (open_bug_tracker_page ())); + + m_octave_packages_action = add_action (help_menu, QIcon (), + tr ("Octave Packages"), SLOT (open_octave_packages_page ())); + + m_contribute_action = add_action (help_menu, QIcon (), + tr ("Contribute"), SLOT (open_contribute_page ())); + + m_developer_action = add_action (help_menu, QIcon (), + tr ("Donate to Octave"), SLOT (open_donate_page ())); + + help_menu->addSeparator (); + + m_about_octave_action = add_action (help_menu, QIcon (), + tr ("About Octave"), SLOT (show_about_octave ())); + } + + void main_window::construct_documentation_menu (QMenu *p) + { + QMenu *doc_menu = p->addMenu (tr ("Documentation")); + + m_ondisk_doc_action = add_action (doc_menu, QIcon (), + tr ("On Disk"), SLOT (activate ()), m_doc_browser_window); + + m_online_doc_action = add_action (doc_menu, QIcon (), + tr ("Online"), SLOT (open_online_documentation_page ())); + } + + void main_window::construct_news_menu (QMenuBar *p) + { + QMenu *news_menu = m_add_menu (p, tr ("&News")); + + m_release_notes_action + = news_menu->addAction (QIcon (), tr ("Release Notes"), + [=] () { + emit show_release_notes_signal (); + }); + addAction (m_release_notes_action); + m_release_notes_action->setShortcutContext (Qt::ApplicationShortcut); + + m_current_news_action + = news_menu->addAction (QIcon (), tr ("Community News"), + [=] () { + emit show_community_news_signal (-1); + }); + addAction (m_current_news_action); + m_current_news_action->setShortcutContext (Qt::ApplicationShortcut); + } + + void main_window::construct_tool_bar () + { + m_main_tool_bar = addToolBar (tr ("Toolbar")); + m_main_tool_bar->setStyleSheet (m_main_tool_bar->styleSheet () + + global_toolbar_style); + + m_main_tool_bar->setObjectName ("MainToolBar"); + m_main_tool_bar->addAction (m_new_script_action); + m_main_tool_bar->addAction (m_open_action); + + m_main_tool_bar->addSeparator (); + + m_main_tool_bar->addAction (m_copy_action); + m_main_tool_bar->addAction (m_paste_action); + m_main_tool_bar->addAction (m_undo_action); + + m_main_tool_bar->addSeparator (); + + m_current_directory_combo_box = new QComboBox (this); + QFontMetrics fm = m_current_directory_combo_box->fontMetrics (); + m_current_directory_combo_box->setFixedWidth (48*fm.averageCharWidth ()); + 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); + QSizePolicy sizePol (QSizePolicy::Preferred, QSizePolicy::Preferred); + m_current_directory_combo_box->setSizePolicy (sizePol); + + // addWidget takes ownership of the objects so there is no + // 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); + + gui_settings settings; + + QAction *current_dir_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 (settings.icon ("folder"), + tr ("Browse directories")); + + connect (m_current_directory_combo_box, SIGNAL (activated (const QString&)), + this, SLOT (set_current_working_directory (const QString&))); + + connect (m_current_directory_combo_box->lineEdit (), + &QLineEdit::returnPressed, + this, &main_window::accept_directory_line_edit); + + connect (current_dir_search, &QAction::triggered, + this, &main_window::browse_for_directory); + + connect (current_dir_up, &QAction::triggered, + this, &main_window::change_directory_up); + + connect (m_undo_action, &QAction::triggered, + this, &main_window::handle_undo_request); + } + + void main_window::focus_console_after_command () + { + gui_settings settings; + + if (settings.bool_value (cs_focus_cmd)) + focus_command_window (); + } + + void main_window::configure_shortcuts () + { + gui_settings settings; + + bool enable + = ! ((m_active_dock == m_command_window) && m_prevent_readline_conflicts); + + // file menu + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 () + { + QList list = QList (); + list.append (static_cast (m_command_window)); + list.append (static_cast (m_history_window)); + list.append (static_cast (m_file_browser_window)); + list.append (static_cast (m_doc_browser_window)); #if defined (HAVE_QSCINTILLA) - list.append (static_cast (m_editor_window)); -#endif - list.append (static_cast (m_workspace_window)); - list.append (static_cast (m_variable_editor_window)); - return list; -} - -void main_window::update_default_encoding (const QString& default_encoding) -{ - m_default_encoding = default_encoding; - std::string mfile_encoding = m_default_encoding.toStdString (); - if (m_default_encoding.startsWith ("SYSTEM", Qt::CaseInsensitive)) - mfile_encoding = "SYSTEM"; - - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - F__mfile_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 (); + list.append (static_cast (m_editor_window)); #endif -} - -// The default main window size relative to the desktop size -void main_window::set_default_geometry () -{ - int win_x, win_y; - get_screen_geometry (win_x, win_y); - - move (0, 0); - resize (2*win_x/3, 7*win_y/8); -} - -void main_window::reset_windows (void) -{ - // Slot for resetting the window layout to the default one - hide (); - showNormal (); // Unmaximize - do_reset_windows (true, true, true); // Add all widgets - - // Re-add after giving time: This seems to be a reliable way to - // reset the main window's layout - - // JWE says: The following also works for me with 0 delay, so I - // think the problem might just be that the event loop needs to run - // somewhere in the sequence of resizing and adding widgets. Maybe - // some actions in do_reset_windows should be using signal/slot - // connections so that the event loop can do what it needs to do. - // But I haven't been able to find the magic sequence. - - QTimer::singleShot (250, this, [=] () { do_reset_windows (true, true, true); }); -} - -// Create the default layout of the main window. Do not use -// restoreState () and restoreGeometry () with default values since -// this might lead to problems when the Qt version changes -void main_window::do_reset_windows (bool show, bool save, bool force_all) -{ - // Set main window default geometry and store its width for - // later resizing the command window - set_default_geometry (); - int win_x = geometry ().width (); - - // Resize command window (if docked), - //the important one in the default layout - if (dockWidgetArea (m_command_window) != Qt::NoDockWidgetArea) - resize_dock (m_command_window, 7*win_x/8, -1); - - // See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357 + list.append (static_cast (m_workspace_window)); + list.append (static_cast (m_variable_editor_window)); + return list; + } + + void main_window::update_default_encoding (const QString& default_encoding) + { + m_default_encoding = default_encoding; + std::string mfile_encoding = m_default_encoding.toStdString (); + if (m_default_encoding.startsWith ("SYSTEM", Qt::CaseInsensitive)) + mfile_encoding = "SYSTEM"; + + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + F__mfile_encoding__ (interp, ovl (mfile_encoding)); + }); + } + + void main_window::resize_dock (QDockWidget *dw, int width, int height) + { + // 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); + } + + // The default main window size relative to the desktop size + void main_window::set_default_geometry () + { + int win_x, win_y; + get_screen_geometry (win_x, win_y); + + move (0, 0); + resize (2*win_x/3, 7*win_y/8); + } + + void main_window::reset_windows () + { + // Slot for resetting the window layout to the default one + hide (); + showNormal (); // Unmaximize + do_reset_windows (true, true, true); // Add all widgets + + // Re-add after giving time: This seems to be a reliable way to + // reset the main window's layout + + // JWE says: The following also works for me with 0 delay, so I + // think the problem might just be that the event loop needs to run + // somewhere in the sequence of resizing and adding widgets. Maybe + // some actions in do_reset_windows should be using signal/slot + // connections so that the event loop can do what it needs to do. + // But I haven't been able to find the magic sequence. + + QTimer::singleShot (250, this, [=] () { do_reset_windows (true, true, true); }); + } + + // Create the default layout of the main window. Do not use + // restoreState () and restoreGeometry () with default values since + // this might lead to problems when the Qt version changes + void main_window::do_reset_windows (bool show, bool save, bool force_all) + { + // Set main window default geometry and store its width for + // later resizing the command window + set_default_geometry (); + int win_x = geometry ().width (); + + // Resize command window (if docked), + //the important one in the default layout + if (dockWidgetArea (m_command_window) != Qt::NoDockWidgetArea) + resize_dock (m_command_window, 7*win_x/8, -1); + + // See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357 #if (QT_VERSION < 0x050601) || (QT_VERSION >= 0x050701) - setDockOptions (QMainWindow::AnimatedDocks - | QMainWindow::AllowNestedDocks - | QMainWindow::AllowTabbedDocks); + setDockOptions (QMainWindow::AnimatedDocks + | QMainWindow::AllowNestedDocks + | QMainWindow::AllowTabbedDocks); #else - setDockNestingEnabled (true); + setDockNestingEnabled (true); #endif - // Add the dock widgets and show them - if (! m_file_browser_window->adopted () || force_all) - { - // FIXME: Maybe there should be a main_window::add_dock_widget - // function that combines both of these actions? - - addDockWidget (Qt::LeftDockWidgetArea, m_file_browser_window); - m_file_browser_window->set_adopted (false); - } - - if (! m_workspace_window->adopted () || force_all) - { - addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window); - m_workspace_window->set_adopted (false); - } - - if (! m_history_window->adopted () || force_all) - { - addDockWidget (Qt::LeftDockWidgetArea, m_history_window); - m_history_window->set_adopted (false); - } - - if (! m_command_window->adopted () || force_all) - { - addDockWidget (Qt::RightDockWidgetArea, m_command_window); - m_command_window->set_adopted (false); - } - - if (! m_doc_browser_window->adopted () || force_all) - { - addDockWidget (Qt::RightDockWidgetArea, m_doc_browser_window); - tabifyDockWidget (m_command_window, m_doc_browser_window); - m_doc_browser_window->set_adopted (false); - } - - if (! m_variable_editor_window->adopted () || force_all) - { - addDockWidget (Qt::RightDockWidgetArea, m_variable_editor_window); - tabifyDockWidget (m_command_window, m_variable_editor_window); - m_variable_editor_window->set_adopted (false); - } + // Add the dock widgets and show them + if (! m_file_browser_window->adopted () || force_all) + { + // FIXME: Maybe there should be a main_window::add_dock_widget + // function that combines both of these actions? + + addDockWidget (Qt::LeftDockWidgetArea, m_file_browser_window); + m_file_browser_window->set_adopted (false); + } + + if (! m_workspace_window->adopted () || force_all) + { + addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window); + m_workspace_window->set_adopted (false); + } + + if (! m_history_window->adopted () || force_all) + { + addDockWidget (Qt::LeftDockWidgetArea, m_history_window); + m_history_window->set_adopted (false); + } + + if (! m_command_window->adopted () || force_all) + { + addDockWidget (Qt::RightDockWidgetArea, m_command_window); + m_command_window->set_adopted (false); + } + + if (! m_doc_browser_window->adopted () || force_all) + { + addDockWidget (Qt::RightDockWidgetArea, m_doc_browser_window); + tabifyDockWidget (m_command_window, m_doc_browser_window); + m_doc_browser_window->set_adopted (false); + } + + if (! m_variable_editor_window->adopted () || force_all) + { + addDockWidget (Qt::RightDockWidgetArea, m_variable_editor_window); + tabifyDockWidget (m_command_window, m_variable_editor_window); + m_variable_editor_window->set_adopted (false); + } #if defined (HAVE_QSCINTILLA) - addDockWidget (Qt::RightDockWidgetArea, m_editor_window); - tabifyDockWidget (m_command_window, m_editor_window); + addDockWidget (Qt::RightDockWidgetArea, m_editor_window); + tabifyDockWidget (m_command_window, m_editor_window); #endif - // Resize command window, the important one in the default layout - resize_dock (m_command_window, 2*win_x/3, -1); - - // Show main wibdow, save state and geometry of main window and - // all dock widgets - if (show) - { - // Show all dock widgets - for (auto *widget : dock_widget_list ()) - widget->show (); - - // Show main window and store size and state - showNormal (); - - 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 ()); - } - - focus_command_window (); - } -} + // Resize command window, the important one in the default layout + resize_dock (m_command_window, 2*win_x/3, -1); + + // Show main wibdow, save state and geometry of main window and + // all dock widgets + if (show) + { + // Show all dock widgets + for (auto *widget : dock_widget_list ()) + widget->show (); + + // Show main window and store size and state + showNormal (); + + if (save) + { + gui_settings settings; + + settings.setValue (mw_geometry.settings_key (), saveGeometry ()); + settings.setValue (mw_state.settings_key (), saveState ()); + } + + focus_command_window (); + } + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/main-window.h --- a/libgui/src/main-window.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/main-window.h Mon Jan 30 18:36:03 2023 +0100 @@ -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" @@ -63,383 +62,385 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class interpreter; + class interpreter; -class settings_dialog; + class base_qobject; + class settings_dialog; -//! Represents the main window. + //! Represents the main window. -class main_window : public QMainWindow -{ - Q_OBJECT + class main_window : public QMainWindow + { + Q_OBJECT -public: + public: - typedef std::pair name_pair; - typedef std::pair int_pair; + typedef std::pair name_pair; + typedef std::pair int_pair; - main_window (base_qobject& oct_qobj); + main_window (base_qobject& oct_qobj); - ~main_window (void); + ~main_window (); - void make_dock_widget_connections (octave_dock_widget *dw); + 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: + signals: - // Note: CLOSE_GUI_SIGNAL is currently only used by the new - // experimental terminal widget. - void close_gui_signal (void); + // Note: CLOSE_GUI_SIGNAL is currently only used by the new + // experimental terminal widget. + void close_gui_signal (); - void active_dock_changed (octave_dock_widget *, octave_dock_widget *); - void editor_focus_changed (bool); + 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 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 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 show_community_news_signal (int serial); - void show_release_notes_signal (void); + void show_community_news_signal (int serial); + void show_release_notes_signal (); - void update_gui_lexer_signal (bool); + void update_gui_lexer_signal (bool); - void insert_debugger_pointer_signal (const QString& file, int line); - void delete_debugger_pointer_signal (const QString& file, int line); - void update_breakpoint_marker_signal (bool insert, const QString& file, - int line, const QString& cond); + void insert_debugger_pointer_signal (const QString& file, int line); + void delete_debugger_pointer_signal (const QString& file, int line); + 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); + void add_actions_signal (QList action_list); - void warning_function_not_found_signal (const QString& message); + void warning_function_not_found_signal (const QString& message); - void interpreter_event (const fcn_callback& fcn); - void interpreter_event (const meth_callback& meth); + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); - void execute_command_signal (const QString& command); + void execute_command_signal (const QString& command); -public slots: + 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 focus_changed (QWidget *w_old, QWidget *w_new); + void focus_window (const QString& win_name); + void request_reload_settings (); - void report_status_message (const QString& statusMessage); - void handle_save_workspace_request (void); - 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 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 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); - QPalette getFusionDarkPalette(); - void prepare_to_exit (void); - void go_to_previous_widget (void); - void reset_windows (void); - void do_reset_windows (bool show = true, bool save = true, - bool force_all = false); + void report_status_message (const QString& statusMessage); + 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 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 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 notice_settings (bool update_by_worker = false); + QPalette getFusionDarkPalette(); + 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 set_current_working_directory (const QString& dir); - void change_directory_up (void); - void accept_directory_line_edit (void); + void update_octave_directory (const QString& dir); + void browse_for_directory (); + void set_current_working_directory (const QString& dir); + 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 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 editor_tabs_changed (bool, bool); + 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_new_script (const QString& commands = QString ()); - void request_new_function (bool triggered = true); - void handle_edit_mfile_request (const QString& name, const QString& file, - const QString& curr_dir, int line); + 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, + const QString& curr_dir, int line); - void handle_insert_debugger_pointer_request (const QString& file, int line); - void handle_delete_debugger_pointer_request (const QString& file, int line); - void handle_update_breakpoint_marker_request (bool insert, - const QString& file, int line, - const QString& cond); + void handle_insert_debugger_pointer_request (const QString& file, int line); + void handle_delete_debugger_pointer_request (const QString& file, int line); + void handle_update_breakpoint_marker_request (bool insert, + 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 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 handle_profiler_status_update (bool); - void profiler_show (void); + void profiler_session (); + void profiler_session_resume (); + void profiler_stop (); + void handle_profiler_status_update (bool); + void profiler_show (); - void handle_octave_ready (); + void handle_octave_ready (); - void handle_set_path_dialog_request (void); + void handle_set_path_dialog_request (); - //! Find files dialog. - //!@{ - void find_files (const QString& startdir = QDir::currentPath ()); - void find_files_finished (int) { } - //!@} - - void set_screen_size (int ht, int wd); + //! Find files dialog. + //!@{ + void find_files (const QString& startdir = QDir::currentPath ()); + void find_files_finished (int) { } + //!@} - //! Handling the clipboard. - //!@{ - void clipboard_has_changed (void); - void clear_clipboard (); - //!@} + void set_screen_size (int ht, int wd); - //! Returns a list of dock widgets. + //! Handling the clipboard. + //!@{ + void clipboard_has_changed (); + void clear_clipboard (); + //!@} - QList get_dock_widget_list (void) - { - return dock_widget_list (); - } + //! Returns a list of dock widgets. -private slots: + QList get_dock_widget_list () + { + return dock_widget_list (); + } - void disable_menu_shortcuts (bool disable); - void restore_create_file_setting (void); - void set_file_encoding (const QString& new_encoding); - void request_open_files (const QStringList& open_file_names); + private slots: - void warning_function_not_found (const QString& message); + void disable_menu_shortcuts (bool disable); + void restore_create_file_setting (); + void set_file_encoding (const QString& new_encoding); + void request_open_files (const QStringList& open_file_names); -protected: + void warning_function_not_found (const QString& message); - void closeEvent (QCloseEvent *closeEvent); + protected: + + void closeEvent (QCloseEvent *closeEvent); -private: + 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); + 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_file_menu (QMenuBar *p); - void construct_new_menu (QMenu *p); - void construct_edit_menu (QMenuBar *p); - QAction * construct_debug_menu_item (const char *icon, const QString& item, - const char *member); - void construct_debug_menu (QMenuBar *p); - QAction * construct_window_menu_item (QMenu *p, const QString& item, - bool checkable, QWidget *); - void construct_tools_menu (QMenuBar *p); - void construct_window_menu (QMenuBar *p); - void construct_help_menu (QMenuBar *p); - void construct_documentation_menu (QMenu *p); + QMenu * m_add_menu (QMenuBar *p, QString text); + void construct_menu_bar (); + void construct_file_menu (QMenuBar *p); + void construct_new_menu (QMenu *p); + void construct_edit_menu (QMenuBar *p); + QAction * construct_debug_menu_item (const char *icon, const QString& item, + const char *member); + void construct_debug_menu (QMenuBar *p); + QAction * construct_window_menu_item (QMenu *p, const QString& item, + bool checkable, QWidget *); + void construct_tools_menu (QMenuBar *p); + void construct_window_menu (QMenuBar *p); + void construct_help_menu (QMenuBar *p); + void construct_documentation_menu (QMenu *p); - void construct_news_menu (QMenuBar *p); + 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 update_default_encoding (const QString& default_encoding); - void set_default_geometry (void); - void resize_dock (QDockWidget *dw, int width, int height); + void set_default_geometry (); + void resize_dock (QDockWidget *dw, int width, int height); - base_qobject& m_octave_qobj; + base_qobject& m_octave_qobj; - QHash m_hash_menu_text; + QHash m_hash_menu_text; - QString m_default_encoding; + QString m_default_encoding; - QString m_default_style; - QPalette m_default_palette; + QString m_default_style; + QPalette m_default_palette; - //! Toolbar. + //! Toolbar. - QStatusBar *m_status_bar; - led_indicator *m_profiler_status_indicator; + QStatusBar *m_status_bar; + led_indicator *m_profiler_status_indicator; - //! Dock widgets. - //!@{ - QPointer m_command_window; - QPointer m_history_window; - QPointer m_file_browser_window; - QPointer m_doc_browser_window; - QPointer m_editor_window; - QPointer m_workspace_window; - QPointer m_variable_editor_window; - //!@} + //! Dock widgets. + //!@{ + QPointer m_command_window; + QPointer m_history_window; + QPointer m_file_browser_window; + QPointer m_doc_browser_window; + QPointer m_editor_window; + QPointer m_workspace_window; + QPointer m_variable_editor_window; + //!@} - external_editor_interface *m_external_editor; - QWidget *m_active_editor; + external_editor_interface *m_external_editor; + QWidget *m_active_editor; - octave_dock_widget *m_previous_dock; - octave_dock_widget *m_active_dock; + octave_dock_widget *m_previous_dock; + octave_dock_widget *m_active_dock; - QToolBar *m_main_tool_bar; + QToolBar *m_main_tool_bar; - QMenu *m_debug_menu; + QMenu *m_debug_menu; - QMenuBar *m_editor_menubar; + QMenuBar *m_editor_menubar; - QAction *m_debug_continue; - QAction *m_debug_step_into; - QAction *m_debug_step_over; - QAction *m_debug_step_out; - QAction *m_debug_quit; + QAction *m_debug_continue; + QAction *m_debug_step_into; + QAction *m_debug_step_over; + QAction *m_debug_step_out; + QAction *m_debug_quit; - QAction *m_new_script_action; - QAction *m_new_function_action; - QAction *m_open_action; - QAction *m_new_figure_action; - QAction *m_load_workspace_action; - QAction *m_save_workspace_action; - QAction *m_set_path_action; - QAction *m_preferences_action; - QAction *m_exit_action; + QAction *m_new_script_action; + QAction *m_new_function_action; + QAction *m_open_action; + QAction *m_new_figure_action; + QAction *m_load_workspace_action; + QAction *m_save_workspace_action; + QAction *m_set_path_action; + QAction *m_preferences_action; + QAction *m_exit_action; - QAction *m_copy_action; - QAction *m_paste_action; - QAction *m_clear_clipboard_action; - QAction *m_undo_action; - QAction *m_clear_command_window_action; - QAction *m_clear_command_history_action; - QAction *m_clear_workspace_action; - QAction *m_find_files_action; - QAction *m_select_all_action; + QAction *m_copy_action; + QAction *m_paste_action; + QAction *m_clear_clipboard_action; + QAction *m_undo_action; + QAction *m_clear_command_window_action; + QAction *m_clear_command_history_action; + QAction *m_clear_workspace_action; + QAction *m_find_files_action; + QAction *m_select_all_action; - QAction *m_profiler_start; - QAction *m_profiler_resume; - QAction *m_profiler_stop; - QAction *m_profiler_show; + QAction *m_profiler_start; + QAction *m_profiler_resume; + QAction *m_profiler_stop; + QAction *m_profiler_show; - QAction *m_show_command_window_action; - QAction *m_show_history_action; - QAction *m_show_workspace_action; - QAction *m_show_file_browser_action; - QAction *m_show_editor_action; - QAction *m_show_documentation_action; - QAction *m_show_variable_editor_action; - QAction *m_command_window_action; - QAction *m_history_action; - QAction *m_workspace_action; - QAction *m_file_browser_action; - QAction *m_editor_action; - QAction *m_documentation_action; - QAction *m_variable_editor_action; - QAction *m_previous_dock_action; - QAction *m_reset_windows_action; + QAction *m_show_command_window_action; + QAction *m_show_history_action; + QAction *m_show_workspace_action; + QAction *m_show_file_browser_action; + QAction *m_show_editor_action; + QAction *m_show_documentation_action; + QAction *m_show_variable_editor_action; + QAction *m_command_window_action; + QAction *m_history_action; + QAction *m_workspace_action; + QAction *m_file_browser_action; + QAction *m_editor_action; + QAction *m_documentation_action; + QAction *m_variable_editor_action; + QAction *m_previous_dock_action; + QAction *m_reset_windows_action; - QAction *m_ondisk_doc_action; - QAction *m_online_doc_action; - QAction *m_report_bug_action; - QAction *m_octave_packages_action; - QAction *m_contribute_action; - QAction *m_developer_action; - QAction *m_about_octave_action; + QAction *m_ondisk_doc_action; + QAction *m_online_doc_action; + QAction *m_report_bug_action; + QAction *m_octave_packages_action; + QAction *m_contribute_action; + QAction *m_developer_action; + QAction *m_about_octave_action; - QAction *m_release_notes_action; - QAction *m_current_news_action; + QAction *m_release_notes_action; + QAction *m_current_news_action; - //! For Toolbars. - //!@{ - QComboBox *m_current_directory_combo_box; - static const int current_directory_max_visible = 16; - static const int current_directory_max_count = 16; - QLineEdit *m_current_directory_line_edit; - //!@} + //! For Toolbars. + //!@{ + QComboBox *m_current_directory_combo_box; + static const int current_directory_max_visible = 16; + static const int current_directory_max_count = 16; + QLineEdit *m_current_directory_line_edit; + //!@} - //! Settings dialog as guarded pointer (set to 0 when deleted). + //! Settings dialog as guarded pointer (set to 0 when deleted). - QPointer m_settings_dlg; + QPointer m_settings_dlg; - //! Find files dialog. + //! Find files dialog. - find_files_dialog *m_find_files_dlg; + find_files_dialog *m_find_files_dlg; - //! Set path dialog - QPointer m_set_path_dlg; + //! Set path dialog + QPointer m_set_path_dlg; - //! Release notes window. + //! Release notes window. - QWidget *m_release_notes_window; + QWidget *m_release_notes_window; - QClipboard *m_clipboard; + QClipboard *m_clipboard; - //! Some class global flags. - //!@{ - bool m_prevent_readline_conflicts; - bool m_prevent_readline_conflicts_menu; - bool m_suppress_dbg_location; - bool m_editor_has_tabs; - bool m_editor_is_octave_file; + //! Some class global flags. + //!@{ + bool m_prevent_readline_conflicts; + bool m_prevent_readline_conflicts_menu; + bool m_suppress_dbg_location; + bool m_editor_has_tabs; + bool m_editor_is_octave_file; - //! Flag for closing the whole application. + //! Flag for closing the whole application. - bool m_closing; - //!@} + bool m_closing; + //!@} - QString m_file_encoding; -}; + QString m_file_encoding; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/module.mk --- a/libgui/src/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/news-reader.cc --- a/libgui/src/news-reader.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/news-reader.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,123 +33,114 @@ #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) -{ - QString html_text; + void news_reader::process () + { + QString html_text; - if (m_connect_to_web) - { - // Run this part in a separate thread so Octave can continue to - // run while we wait for the page to load. Then emit the signal - // to display it when we have the page contents. + if (m_connect_to_web) + { + // Run this part in a separate thread so Octave can continue to + // run while we wait for the page to load. Then emit the signal + // to display it when we have the page contents. - QString url = m_base_url + '/' + m_page; - std::ostringstream buf; - url_transfer octave_dot_org (url.toStdString (), buf); + QString url = m_base_url + '/' + m_page; + std::ostringstream buf; + url_transfer octave_dot_org (url.toStdString (), buf); - if (octave_dot_org.is_valid ()) - { - Array param; - octave_dot_org.http_get (param); + if (octave_dot_org.is_valid ()) + { + Array param; + octave_dot_org.http_get (param); - if (octave_dot_org.good ()) - html_text = QString::fromStdString (buf.str ()); - } + if (octave_dot_org.good ()) + html_text = QString::fromStdString (buf.str ()); + } - if (html_text.contains ("this-is-the-gnu-octave-community-news-page")) - { - if (m_serial >= 0) - { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + if (html_text.contains ("this-is-the-gnu-octave-community-news-page")) + { + if (m_serial >= 0) + { + 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="); - QString tag ("community-news-page-serial="); - - int b = html_text.indexOf (tag); + int b = html_text.indexOf (tag); - if (b) - { - b += tag.length (); + if (b) + { + b += tag.length (); - int e = html_text.indexOf ("\n", b); + int e = html_text.indexOf ("\n", b); - QString tmp = html_text.mid (b, e-b); + QString tmp = html_text.mid (b, e-b); - int curr_page_serial = tmp.toInt (); + int curr_page_serial = tmp.toInt (); - if (curr_page_serial > m_serial) - { - if (settings) - { - settings->setValue (nr_last_news.key, - curr_page_serial); + if (curr_page_serial > m_serial) + { + settings.setValue (nr_last_news.settings_key (), curr_page_serial); + settings.sync (); + } + else + return; + } + else + return; + } + } + else + html_text = QString + (tr ("\n" + "\n" + "

\n" + "Octave's community news source seems to be unavailable.\n" + "

\n" + "

\n" + "For the latest news, please check\n" + "https://octave.org/community-news.html\n" + "when you have a connection to the web (link opens in an external browser).\n" + "

\n" + "

\n" + "— The Octave Developers, ") + OCTAVE_RELEASE_DATE + "\n" + "

\n" + "\n" + "\n"); + } + else + html_text = QString + (tr ("\n" + "\n" + "

\n" + "Connecting to the web to display the latest Octave Community news has been disabled.\n" + "

\n" + "

\n" + "For the latest news, please check\n" + "https://octave.org/community-news.html\n" + "when you have a connection to the web (link opens in an external browser)\n" + "or enable web connections for news in Octave's network settings dialog.\n" + "

\n" + "

\n" + "— The Octave Developers, ") + OCTAVE_RELEASE_DATE + "\n" + "

\n" + "\n" + "\n"); - settings->sync (); - } - } - else - return; - } - else - return; - } - } - else - html_text = QString - (tr ("\n" - "\n" - "

\n" - "Octave's community news source seems to be unavailable.\n" - "

\n" - "

\n" - "For the latest news, please check\n" - "https://octave.org/community-news.html\n" - "when you have a connection to the web (link opens in an external browser).\n" - "

\n" - "

\n" - "— The Octave Developers, ") + OCTAVE_RELEASE_DATE + "\n" - "

\n" - "\n" - "\n"); - } - else - html_text = QString - (tr ("\n" - "\n" - "

\n" - "Connecting to the web to display the latest Octave Community news has been disabled.\n" - "

\n" - "

\n" - "For the latest news, please check\n" - "https://octave.org/community-news.html\n" - "when you have a connection to the web (link opens in an external browser)\n" - "or enable web connections for news in Octave's network settings dialog.\n" - "

\n" - "

\n" - "— The Octave Developers, ") + OCTAVE_RELEASE_DATE + "\n" - "

\n" - "\n" - "\n"); + emit display_news_signal (html_text); - emit display_news_signal (html_text); - - emit finished (); -} + emit finished (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/news-reader.h --- a/libgui/src/news-reader.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/news-reader.h Mon Jan 30 18:36:03 2023 +0100 @@ -31,40 +31,35 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class news_reader : public QObject + { + Q_OBJECT -class news_reader : public QObject -{ - Q_OBJECT - -public: + 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), - m_page (page), m_serial (serial), m_connect_to_web (connect_to_web) - { } + 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) + { } -signals: + signals: - void display_news_signal (const QString& news); + void display_news_signal (const QString& news); - void finished (void); + void finished (); -public slots: + public slots: - void process (void); + void process (); -private: - - base_qobject& m_octave_qobj; + private: - QString m_base_url; - QString m_page; - int m_serial; - bool m_connect_to_web; -}; + QString m_base_url; + QString m_page; + int m_serial; + bool m_connect_to_web; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/octave-dock-widget.cc --- a/libgui/src/octave-dock-widget.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/octave-dock-widget.cc Mon Jan 30 18:36:03 2023 +0100 @@ -45,814 +45,783 @@ #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) -{ - QStyle *st = style (); - m_icon_size = 0.75*st->pixelMetric (QStyle::PM_SmallIconSize); + 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); - // keep track of the original buttons on the default title bar, - // the button further left is considered "float" - QList buttonlist = findChildren (); - if (buttonlist.size () == 2) - { - if (buttonlist.at (0)->x () < buttonlist.at (1)->x ()) - { - m_default_float_button = buttonlist.at (0); - m_default_close_button = buttonlist.at (1); - } - else - { - m_default_float_button = buttonlist.at (1); - m_default_close_button = buttonlist.at (0); - } - } + // keep track of the original buttons on the default title bar, + // the button further left is considered "float" + QList buttonlist = findChildren (); + if (buttonlist.size () == 2) + { + if (buttonlist.at (0)->x () < buttonlist.at (1)->x ()) + { + m_default_float_button = buttonlist.at (0); + m_default_close_button = buttonlist.at (1); + } + else + { + m_default_float_button = buttonlist.at (1); + m_default_close_button = buttonlist.at (0); + } + } - 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 (); + // the custom (extra) title bar of the widget + m_title_widget = new QWidget (); - m_dock_action = new QAction - (rmgr.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); - m_dock_button->setFocusPolicy (Qt::NoFocus); - m_dock_button->setIconSize (QSize (m_icon_size, m_icon_size)); + m_dock_action = new QAction + (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); + m_dock_button->setFocusPolicy (Qt::NoFocus); + m_dock_button->setIconSize (QSize (m_icon_size, m_icon_size)); - m_close_action = new QAction - (rmgr.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); - m_close_button->setFocusPolicy (Qt::NoFocus); - m_close_button->setIconSize (QSize (m_icon_size, m_icon_size)); + m_close_action = new QAction + (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); + m_close_button->setFocusPolicy (Qt::NoFocus); + m_close_button->setIconSize (QSize (m_icon_size, m_icon_size)); - QString css_button = QString ("QToolButton {background: transparent; border: 0px;}"); - m_dock_button->setStyleSheet (css_button); - m_close_button->setStyleSheet (css_button); + QString css_button = QString ("QToolButton {background: transparent; border: 0px;}"); + m_dock_button->setStyleSheet (css_button); + m_close_button->setStyleSheet (css_button); - QHBoxLayout *h_layout = new QHBoxLayout (); - h_layout->addStretch (100); - h_layout->addWidget (m_dock_button); - h_layout->addWidget (m_close_button); - h_layout->setSpacing (10); - h_layout->setContentsMargins (5, 2, 2, 2); + QHBoxLayout *h_layout = new QHBoxLayout (); + h_layout->addStretch (100); + h_layout->addWidget (m_dock_button); + h_layout->addWidget (m_close_button); + h_layout->setSpacing (10); + h_layout->setContentsMargins (5, 2, 2, 2); - m_title_widget->setLayout (h_layout); + m_title_widget->setLayout (h_layout); - if (p && (p->objectName () == gui_obj_name_main_window)) - { - // Only connect the when a parent (main window) is given - // copy & paste handling - connect (p, SIGNAL (copyClipboard_signal ()), - this, SLOT (copyClipboard ())); - connect (p, SIGNAL (pasteClipboard_signal ()), - this, SLOT (pasteClipboard ())); - connect (p, SIGNAL (selectAll_signal ()), - this, SLOT (selectAll ())); + if (p && (p->objectName () == gui_obj_name_main_window)) + { + // Only connect the when a parent (main window) is given + // copy & paste handling + connect (p, SIGNAL (copyClipboard_signal ()), + this, SLOT (copyClipboard ())); + connect (p, SIGNAL (pasteClipboard_signal ()), + this, SLOT (pasteClipboard ())); + connect (p, SIGNAL (selectAll_signal ()), + this, SLOT (selectAll ())); - // undo handling - connect (p, SIGNAL (undo_signal ()), this, SLOT (do_undo ())); - } -} + // undo handling + connect (p, SIGNAL (undo_signal ()), this, SLOT (do_undo ())); + } + } -// set the title in the dockwidgets title bar -void -label_dock_widget::set_title (const QString& title) -{ - QHBoxLayout *h_layout - = static_cast (m_title_widget->layout ()); - QLabel *label = new QLabel (title, m_title_widget); - label->setStyleSheet ("background-color: transparent;"); - h_layout->insertWidget (0, label); - setTitleBarWidget (m_title_widget); - setWindowTitle (title); -} + // set the title in the dockwidgets title bar + void + label_dock_widget::set_title (const QString& title) + { + QHBoxLayout *h_layout + = static_cast (m_title_widget->layout ()); + QLabel *label = new QLabel (title, m_title_widget); + label->setStyleSheet ("background-color: transparent;"); + h_layout->insertWidget (0, label); + setTitleBarWidget (m_title_widget); + setWindowTitle (title); + } -static QString -qdockwidget_css (const QString& close_icon, const QString& close_tooltip, - const QString& float_icon, const QString& float_tooltip, - int icon_size, const QString& titlebar_foreground, - const QString& titlebar_background) -{ - return QString ("QDockWidget\n" - "{\n" - "%6" - " border: none;\n" - " titlebar-close-icon: url(%1);\n" - " titlebar-normal-icon: url(%2);\n" - "}\n" - "\n" - "QDockWidget::close-button, QDockWidget::float-button\n" - "{\n" - " border: none;\n" - " icon-size: %3px;\n" - "}\n" - "\n" - "QAbstractButton#qt_dockwidget_closebutton\n" - "{\n" - " qproperty-toolTip: \"%4\";\n" - "}\n" - "\n" - "QAbstractButton#qt_dockwidget_floatbutton\n" - "{\n" - " qproperty-toolTip: \"%5\";\n" - "}\n" - "\n" - "QDockWidget::title {\n" - " text-align: left;\n" - "%7" - " padding-left: 1px;\n" - "}\n" - "\n" - "QDockWidget::close-button\n" - "{\n" - " right: %8px;\n" - " top: 3px;\n" - "}\n" - "\n" - "QDockWidget::float-button\n" - "{\n" - " right: %9px;\n" - " 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); -} + static QString + qdockwidget_css (const QString& close_icon, const QString& close_tooltip, + const QString& float_icon, const QString& float_tooltip, + int icon_size, const QString& titlebar_foreground, + const QString& titlebar_background) + { + return QString ("QDockWidget\n" + "{\n" + "%6" + " border: none;\n" + " titlebar-close-icon: url(%1);\n" + " titlebar-normal-icon: url(%2);\n" + "}\n" + "\n" + "QDockWidget::close-button, QDockWidget::float-button\n" + "{\n" + " border: none;\n" + " icon-size: %3px;\n" + "}\n" + "\n" + "QAbstractButton#qt_dockwidget_closebutton\n" + "{\n" + " qproperty-toolTip: \"%4\";\n" + "}\n" + "\n" + "QAbstractButton#qt_dockwidget_floatbutton\n" + "{\n" + " qproperty-toolTip: \"%5\";\n" + "}\n" + "\n" + "QDockWidget::title {\n" + " text-align: left;\n" + "%7" + " padding-left: 1px;\n" + "}\n" + "\n" + "QDockWidget::close-button\n" + "{\n" + " right: %8px;\n" + " top: 3px;\n" + "}\n" + "\n" + "QDockWidget::float-button\n" + "{\n" + " right: %9px;\n" + " 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); + } -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), - m_custom_style (false), m_focus_follows_mouse (false), - m_recent_float_geom (), m_recent_dock_geom (), - m_waiting_for_mouse_button_release (false) -{ - setObjectName (obj_name); + 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) + { + setObjectName (obj_name); - // FIXME: Can we avoid the cast here? - m_main_window = dynamic_cast (p); + // FIXME: Can we avoid the cast here? + m_main_window = dynamic_cast (p); - m_predecessor_widget = nullptr; + m_predecessor_widget = nullptr; - connect (this, &octave_dock_widget::topLevelChanged, - this, &octave_dock_widget::toplevel_change); - connect (this, &octave_dock_widget::visibilityChanged, - this, &octave_dock_widget::handle_visibility); + connect (this, &octave_dock_widget::topLevelChanged, + this, &octave_dock_widget::toplevel_change); + connect (this, &octave_dock_widget::visibilityChanged, + this, &octave_dock_widget::handle_visibility); - if (m_default_float_button != nullptr) - { - disconnect (m_default_float_button, 0, 0, 0); - connect (m_default_float_button, &QAbstractButton::clicked, - this, &octave_dock_widget::make_window); - } - connect (this, &octave_dock_widget::queue_make_window, - this, &octave_dock_widget::make_window, Qt::QueuedConnection); - connect (this, &octave_dock_widget::queue_make_widget, - this, [=] () { make_widget (); }, Qt::QueuedConnection); + if (m_default_float_button != nullptr) + { + disconnect (m_default_float_button, 0, 0, 0); + connect (m_default_float_button, &QAbstractButton::clicked, + this, &octave_dock_widget::make_window); + } + connect (this, &octave_dock_widget::queue_make_window, + this, &octave_dock_widget::make_window, Qt::QueuedConnection); + connect (this, &octave_dock_widget::queue_make_widget, + this, [=] () { make_widget (); }, Qt::QueuedConnection); + + gui_settings settings; - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - scmgr.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); + 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); - m_close_action->setShortcutContext (Qt::WidgetWithChildrenShortcut); - addAction (m_close_action); - connect (m_close_action, &QAction::triggered, - this, &octave_dock_widget::change_visibility); + 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, + this, &octave_dock_widget::change_visibility); - m_close_action->setToolTip (tr ("Hide widget")); + 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 ("")); + if (widget ()) + widget ()->setToolTip (""); - m_icon_color = ""; - m_title_3d = 50; + m_icon_color = ""; + m_title_3d = 50; - installEventFilter (this); + installEventFilter (this); - setFocusPolicy (Qt::StrongFocus); + setFocusPolicy (Qt::StrongFocus); - setFeatures (QDockWidget::DockWidgetClosable - | QDockWidget::DockWidgetMovable - | QDockWidget::DockWidgetFloatable); + setFeatures (QDockWidget::DockWidgetClosable + | 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) -{ - emit active_changed (isVisible ()); // emit once for init of window menu -} + void + octave_dock_widget::init_window_menu_entry () + { + emit active_changed (isVisible ()); // emit once for init of window menu + } -// make the widget floating -void -octave_dock_widget::make_window (bool widget_was_dragged) -{ - bool vis = isVisible (); + // make the widget floating + void + octave_dock_widget::make_window (bool widget_was_dragged) + { + bool vis = isVisible (); - // prevent follow-up calls by clearing state variable - m_waiting_for_mouse_button_release = false; + // prevent follow-up calls by clearing state variable + m_waiting_for_mouse_button_release = false; - set_focus_predecessor (); // set focus previously active widget if tabbed + set_focus_predecessor (); // set focus previously active widget if tabbed - // Before unparenting, get current geometry for restoring if dragged - QRect geom = geometry (); + // Before unparenting, get current geometry for restoring if dragged + QRect geom = geometry (); - // the widget has to be reparented (parent = 0), preferably - // from a non-toplevel widget otherwise may not have full - // decorations, e.g., no taskbar icon and always in front - if (isFloating ()) - setFloating (false); + // the widget has to be reparented (parent = 0), preferably + // from a non-toplevel widget otherwise may not have full + // decorations, e.g., no taskbar icon and always in front + if (isFloating ()) + setFloating (false); - if (m_main_window) - { - // Before making it a separate (no more parent) floating widget, - // remove the dock widget from the main window. This ensures - // that tabbed widgets keep their focus when it is re-docked - // later - m_main_window->removeDockWidget (this); - } + if (m_main_window) + { + // Before making it a separate (no more parent) floating widget, + // remove the dock widget from the main window. This ensures + // that tabbed widgets keep their focus when it is re-docked + // later + m_main_window->removeDockWidget (this); + } - setParent (0, Qt::CustomizeWindowHint | Qt::WindowTitleHint | - Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::Window); + setParent (0, Qt::CustomizeWindowHint | Qt::WindowTitleHint | + Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::Window); - // restore the last geometry when floating only if we have not dragged - // 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; - setGeometry (geom); + // restore the last geometry when floating only if we have not dragged + // 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; + setGeometry (geom); - // adjust the (un)dock action - disconnect (m_dock_action, 0, this, 0); - connect (m_dock_action, &QAction::triggered, - this, &octave_dock_widget::make_widget); + // adjust the (un)dock action + disconnect (m_dock_action, 0, this, 0); + connect (m_dock_action, &QAction::triggered, + this, &octave_dock_widget::make_widget); + + // adjust the (un)dock icon + if (titleBarWidget ()) + { + gui_settings settings; - // 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)); - m_dock_action->setToolTip (tr ("Dock widget")); - } - else - { - disconnect (m_default_float_button, 0, this, 0); - connect (m_default_float_button, &QAbstractButton::clicked, - this, &octave_dock_widget::make_widget); - } + m_dock_action->setIcon (settings.icon ("widget-dock" + m_icon_color, true)); + m_dock_action->setToolTip (tr ("Dock widget")); + } + else + { + disconnect (m_default_float_button, 0, this, 0); + connect (m_default_float_button, &QAbstractButton::clicked, + this, &octave_dock_widget::make_widget); + } - raise (); - activateWindow (); + raise (); + activateWindow (); - if (vis) - { - show (); - setFocus (); - set_style (true); - } + if (vis) + { + show (); + setFocus (); + set_style (true); + } - emit topLevelChanged (true); // Be sure signal is emitted -} + emit topLevelChanged (true); // Be sure signal is emitted + } -// dock the widget -void -octave_dock_widget::make_widget (bool) -{ - bool vis = isVisible (); + // dock the widget + void + octave_dock_widget::make_widget (bool) + { + gui_settings settings; - // 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 (); + bool vis = isVisible (); + + // Since floating widget has no parent, we have to read it - if (m_main_window) - { - settings->setValue (mw_state.key, m_main_window->saveState ()); + if (m_main_window) + { + 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 - // saved settings. - setParent (m_main_window, Qt::Window); - 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 ()); - setFloating (false); - // restore size using setGeometry instead of restoreGeometry - // following this post: - // https://forum.qt.io/topic/79326/qdockwidget-restoregeometry-not-working-correctly-when-qmainwindow-is-maximized/5 - setGeometry (m_recent_dock_geom); - } + // Stay window, otherwise will bounce back to window by default + // because there is no layout information for this widget in the + // saved settings. + setParent (m_main_window, Qt::Window); + 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.settings_key ()).toByteArray ()); + setFloating (false); + // restore size using setGeometry instead of restoreGeometry + // following this post: + // https://forum.qt.io/topic/79326/qdockwidget-restoregeometry-not-working-correctly-when-qmainwindow-is-maximized/5 + setGeometry (m_recent_dock_geom); + } - // adjust the (un)dock icon - disconnect (m_dock_action, 0, this, 0); - connect (m_dock_action, &QAction::triggered, - this, &octave_dock_widget::make_window); - if (titleBarWidget ()) - { - m_dock_action->setIcon (rmgr.icon ("widget-undock" + m_icon_color, true)); - m_dock_action->setToolTip (tr ("Undock widget")); - } - else - { - disconnect (m_default_float_button, 0, this, 0); - connect (m_default_float_button, &QAbstractButton::clicked, - this, &octave_dock_widget::make_window); - } + // adjust the (un)dock icon + disconnect (m_dock_action, 0, this, 0); + connect (m_dock_action, &QAction::triggered, + this, &octave_dock_widget::make_window); + if (titleBarWidget ()) + { + m_dock_action->setIcon (settings.icon ("widget-undock" + m_icon_color, true)); + m_dock_action->setToolTip (tr ("Undock widget")); + } + else + { + disconnect (m_default_float_button, 0, this, 0); + connect (m_default_float_button, &QAbstractButton::clicked, + this, &octave_dock_widget::make_window); + } - raise (); - QApplication::setActiveWindow (this); + raise (); + QApplication::setActiveWindow (this); - if (vis) - { - show (); - setFocus (); - set_style (true); - } -} + if (vis) + { + show (); + setFocus (); + set_style (true); + } + } -// dock the widget -void -octave_dock_widget::default_dock (bool) -{ - setFloating (false); -} + // dock the widget + void + octave_dock_widget::default_dock (bool) + { + setFloating (false); + } -// set the widget which previously had focus when tabified -void -octave_dock_widget::set_predecessor_widget (octave_dock_widget *prev_widget) -{ - m_predecessor_widget = prev_widget; -} + // set the widget which previously had focus when tabified + void + octave_dock_widget::set_predecessor_widget (octave_dock_widget *prev_widget) + { + m_predecessor_widget = prev_widget; + } -void -octave_dock_widget::set_main_window (main_window *mw) -{ - m_main_window = mw; + void + octave_dock_widget::set_main_window (main_window *mw) + { + m_main_window = mw; - if (m_main_window) - { - connect (m_main_window, &main_window::copyClipboard_signal, - this, &octave_dock_widget::copyClipboard); + if (m_main_window) + { + connect (m_main_window, &main_window::copyClipboard_signal, + this, &octave_dock_widget::copyClipboard); - connect (m_main_window, &main_window::pasteClipboard_signal, - this, &octave_dock_widget::pasteClipboard); + connect (m_main_window, &main_window::pasteClipboard_signal, + this, &octave_dock_widget::pasteClipboard); - connect (m_main_window, &main_window::selectAll_signal, - this, &octave_dock_widget::selectAll); + connect (m_main_window, &main_window::selectAll_signal, + this, &octave_dock_widget::selectAll); - connect (m_main_window, &main_window::undo_signal, - this, &octave_dock_widget::do_undo); - } -} + connect (m_main_window, &main_window::undo_signal, + this, &octave_dock_widget::do_undo); + } + } -// close event -void -octave_dock_widget::closeEvent (QCloseEvent *e) -{ - emit active_changed (false); - set_focus_predecessor (); - save_settings (); + // close event + void + octave_dock_widget::closeEvent (QCloseEvent *e) + { + emit active_changed (false); + set_focus_predecessor (); + save_settings (); - QDockWidget::closeEvent (e); -} + QDockWidget::closeEvent (e); + } -// get focus widget -QWidget * -octave_dock_widget::focusWidget (void) -{ - QWidget *w = QApplication::focusWidget (); - if (w && w->focusProxy ()) w = w->focusProxy (); - return w; -} + // get focus widget + QWidget * + octave_dock_widget::focusWidget () + { + QWidget *w = QApplication::focusWidget (); + if (w && w->focusProxy ()) w = w->focusProxy (); + return w; + } -bool -octave_dock_widget::event (QEvent *event) -{ - // low-level check of whether docked-widget became a window via - // double-click or via drag-and-drop - if ( (event->type () == QEvent::MouseButtonDblClick && ! isFloating ()) - || (event->type () == QEvent::ActivationChange - && m_waiting_for_mouse_button_release)) - { - bool retval = QDockWidget::event (event); - if (isFloating () && parent () != 0) - { - m_waiting_for_mouse_button_release = false; - emit queue_make_window (event->type () != QEvent::MouseButtonDblClick); - } - return retval; - } + bool + octave_dock_widget::event (QEvent *event) + { + // low-level check of whether docked-widget became a window via + // double-click or via drag-and-drop + if ( (event->type () == QEvent::MouseButtonDblClick && ! isFloating ()) + || (event->type () == QEvent::ActivationChange + && m_waiting_for_mouse_button_release)) + { + bool retval = QDockWidget::event (event); + if (isFloating () && parent () != 0) + { + m_waiting_for_mouse_button_release = false; + emit queue_make_window (event->type () != QEvent::MouseButtonDblClick); + } + return retval; + } - return QDockWidget::event (event); -} + return QDockWidget::event (event); + } -void -octave_dock_widget::handle_settings (const gui_settings *settings) -{ - if (! settings) - return; + void + octave_dock_widget::handle_settings () + { + 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 (); + m_custom_style + = 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); + QColor bcol (m_bg_color); + QColor bcola (m_bg_color_active); - if (! m_custom_style) - { - bcol = QWidget::palette ().color (m_title_widget->backgroundRole ()); - bcola = bcol; - } + if (! m_custom_style) + { + bcol = QWidget::palette ().color (m_title_widget->backgroundRole ()); + bcola = bcol; + } - int r, g, b; - bcol.getRgb (&r, &g, &b); - if (r+g+b < 400) - m_icon_color = "-light"; - else - m_icon_color = ""; + int r, g, b; + bcol.getRgb (&r, &g, &b); + if (r+g+b < 400) + m_icon_color = "-light"; + else + m_icon_color = ""; - bcola.getRgb (&r, &g, &b); - if (r+g+b < 400) - m_icon_color_active = "-light"; - else - m_icon_color_active = ""; + bcola.getRgb (&r, &g, &b); + if (r+g+b < 400) + m_icon_color_active = "-light"; + else + m_icon_color_active = ""; - int x, y, w, h; - QGuiApplication::primaryScreen ()->availableGeometry ().getRect (&x, &y, &w, &h); - QRect default_floating_size = QRect (x+16, y+32, w/3, h/2); + int x, y, w, h; + QGuiApplication::primaryScreen ()->availableGeometry ().getRect (&x, &y, &w, &h); + QRect default_floating_size = QRect (x+16, y+32, w/3, h/2); - QRect default_dock_size; - if (m_main_window) - { - // We have a main window, dock size depends on size of main window - m_main_window->geometry ().getRect (&x, &y, &w, &h); - default_dock_size = QRect (x+16, y+32, w/3, h/3); - } - else - { - // No main window, default dock size should never be used - default_dock_size = QRect (0, 0, w/10, h/10); - } + QRect default_dock_size; + if (m_main_window) + { + // We have a main window, dock size depends on size of main window + m_main_window->geometry ().getRect (&x, &y, &w, &h); + default_dock_size = QRect (x+16, y+32, w/3, h/3); + } + else + { + // No main window, default dock size should never be used + default_dock_size = QRect (0, 0, w/10, h/10); + } - m_recent_float_geom - = settings->value (dw_float_geometry.key.arg (objectName ()), - default_floating_size).toRect (); + m_recent_float_geom + = settings.value (dw_float_geometry.settings_key ().arg (objectName ()), + default_floating_size).toRect (); - adjust_to_screen (m_recent_float_geom, default_floating_size); + adjust_to_screen (m_recent_float_geom, default_floating_size); - // The following is required for ensure smooth transition from old - // 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); - if (dock_geom.canConvert (QMetaType::QRect)) - m_recent_dock_geom = dock_geom.toRect (); - else - m_recent_dock_geom = dw_dock_geometry.def.toRect (); + // The following is required for ensure smooth transition from old + // saveGeomety to new QRect setting (see comment for restoring size + // of docked widgets) + QVariant dock_geom + = 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 (); - notice_settings (settings); // call individual handler + notice_settings (); // call individual handler - set_style (false); + set_style (false); - // Compacter design - QToolBar *toolbar = findChild (); - if (toolbar) - toolbar->setStyleSheet (toolbar->styleSheet () + global_toolbar_style); + // Compacter design + QToolBar *toolbar = findChild (); + if (toolbar) + toolbar->setStyleSheet (toolbar->styleSheet () + global_toolbar_style); - QMenuBar *menubar = findChild (); - if (menubar) - menubar->setStyleSheet (menubar->styleSheet () + global_menubar_style); + QMenuBar *menubar = findChild (); + if (menubar) + menubar->setStyleSheet (menubar->styleSheet () + global_menubar_style); -} + } -void -octave_dock_widget::handle_active_dock_changed (octave_dock_widget *w_old, - octave_dock_widget *w_new) -{ - if (m_custom_style && this == w_old) - { - set_style (false); - update (); - } + void + octave_dock_widget::handle_active_dock_changed (octave_dock_widget *w_old, + octave_dock_widget *w_new) + { + if (m_custom_style && this == w_old) + { + set_style (false); + update (); + } - if (m_custom_style && this == w_new) - { - set_style (true); - update (); - } -} + if (m_custom_style && this == w_new) + { + set_style (true); + update (); + } + } -void -octave_dock_widget::save_settings (void) -{ - // save state of this dock-widget - QString name = objectName (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + void + octave_dock_widget::save_settings () + { + gui_settings settings; - if (! settings) - return; + // save state of this dock-widget + QString name = objectName (); - store_geometry (); + store_geometry (); - // conditional needed? - if (! m_recent_float_geom.isNull ()) - settings->setValue (dw_float_geometry.key.arg (name), m_recent_float_geom); + // conditional needed? + if (! m_recent_float_geom.isNull ()) + 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 + if (! m_recent_dock_geom.isEmpty ()) + 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) -{ - // Ignore double clicks into window decoration elements - if (e->type () == QEvent::NonClientAreaMouseButtonDblClick) - { - e->ignore (); - return true; - } + bool octave_dock_widget::eventFilter (QObject *obj, QEvent *e) + { + // Ignore double clicks into window decoration elements + if (e->type () == QEvent::NonClientAreaMouseButtonDblClick) + { + e->ignore (); + return true; + } - // Detect mouse enter events if "focus follows mouse" is desired - // for widgets docked to the main window (non floating) and activate - // the widget currently under the mouse - if (m_focus_follows_mouse && ! isFloating () && (e->type () == QEvent::Enter)) - setFocus (); + // Detect mouse enter events if "focus follows mouse" is desired + // for widgets docked to the main window (non floating) and activate + // the widget currently under the mouse + if (m_focus_follows_mouse && ! isFloating () && (e->type () == QEvent::Enter)) + setFocus (); - return QDockWidget::eventFilter (obj, e); -} + return QDockWidget::eventFilter (obj, e); + } -void -octave_dock_widget::store_geometry (void) -{ - if (isFloating ()) - { - if (! parent ()) - m_recent_float_geom = geometry (); - } - else - { - m_recent_dock_geom = geometry (); - } -} + void + octave_dock_widget::store_geometry () + { + if (isFloating ()) + { + if (! parent ()) + m_recent_float_geom = geometry (); + } + else + { + m_recent_dock_geom = geometry (); + } + } -void -octave_dock_widget::moveEvent (QMoveEvent *event) -{ - store_geometry (); + void + octave_dock_widget::moveEvent (QMoveEvent *event) + { + store_geometry (); - QDockWidget::moveEvent (event); -} + QDockWidget::moveEvent (event); + } -void -octave_dock_widget::resizeEvent (QResizeEvent *event) -{ - store_geometry (); + void + octave_dock_widget::resizeEvent (QResizeEvent *event) + { + store_geometry (); - QDockWidget::resizeEvent (event); -} + QDockWidget::resizeEvent (event); + } -// slot for hiding the widget -void -octave_dock_widget::change_visibility (bool) -{ - setVisible (false); - emit active_changed (false); -} + // slot for hiding the widget + void + octave_dock_widget::change_visibility (bool) + { + setVisible (false); + emit active_changed (false); + } -void octave_dock_widget::activate (void) -{ - if (! isVisible ()) - setVisible (true); + void octave_dock_widget::activate () + { + if (! isVisible ()) + setVisible (true); - setFocus (); - activateWindow (); - raise (); -} + setFocus (); + activateWindow (); + raise (); + } -void octave_dock_widget::handle_visibility (bool visible) -{ - if (visible) - { - emit active_changed (true); - if (! isFloating ()) - setFocus (); - } -} + void octave_dock_widget::handle_visibility (bool visible) + { + if (visible) + { + emit active_changed (true); + if (! isFloating ()) + setFocus (); + } + } -void -octave_dock_widget::toplevel_change (bool toplevel) -{ - QObject *dockobj; - const char *docksig; + void + octave_dock_widget::toplevel_change (bool toplevel) + { + QObject *dockobj; + const char *docksig; - if (titleBarWidget ()) - { - dockobj = m_dock_action; - docksig = SIGNAL (triggered (bool)); - } - else - { - dockobj = m_default_float_button; - docksig = SIGNAL (clicked (bool)); - } + if (titleBarWidget ()) + { + dockobj = m_dock_action; + docksig = SIGNAL (triggered (bool)); + } + else + { + dockobj = m_default_float_button; + docksig = SIGNAL (clicked (bool)); + } - if (toplevel) - { - // This is a fallback in case the attempt to create a floated - // top-level window fails and the QDockWidget remains a child - // of the QMainWindow. - connect (dockobj, docksig, this, SLOT (default_dock (bool))); + if (toplevel) + { + // This is a fallback in case the attempt to create a floated + // top-level window fails and the QDockWidget remains a child + // of the QMainWindow. + connect (dockobj, docksig, this, SLOT (default_dock (bool))); - // Could be dragging window, so must wait until there is a - // change in focus. - if (parent () != 0) - m_waiting_for_mouse_button_release = true; - } - else - { - // If a drag-and-drop within the QMainWindow occurred, want to remain a widget. - m_waiting_for_mouse_button_release = false; + // Could be dragging window, so must wait until there is a + // change in focus. + if (parent () != 0) + m_waiting_for_mouse_button_release = true; + } + else + { + // If a drag-and-drop within the QMainWindow occurred, want to remain a widget. + m_waiting_for_mouse_button_release = false; - // Making into a widget immediately will mangle the double-click - // status and cause problems on followup button clicks. - if (parent () == 0) - emit queue_make_widget (); - } -} + // Making into a widget immediately will mangle the double-click + // status and cause problems on followup button clicks. + if (parent () == 0) + emit queue_make_widget (); + } + } -void -octave_dock_widget::set_style (bool active) -{ - QString css_foreground; - QString css_background; - QString css_button; - QString dock_icon; + void + octave_dock_widget::set_style (bool active) + { + QString css_foreground; + QString css_background; + QString css_button; + QString dock_icon; - QString icon_col = m_icon_color; + QString icon_col = m_icon_color; - QString close_tooltip = "Close widget"; - QString dock_tooltip; + QString close_tooltip = "Close widget"; + QString dock_tooltip; - if (isFloating ()) - { - dock_icon = "widget-dock"; - dock_tooltip = "Dock widget"; - } - else - { - dock_icon = "widget-undock"; - dock_tooltip = "Undock widget"; - } + if (isFloating ()) + { + dock_icon = "widget-dock"; + dock_tooltip = "Dock widget"; + } + else + { + dock_icon = "widget-undock"; + dock_tooltip = "Undock widget"; + } #if defined (Q_OS_MAC) - QString alignment = "center"; + QString alignment = "center"; #else - QString alignment = "center left"; + QString alignment = "center left"; #endif - if (m_custom_style) - { - - QColor bg_col, fg_col; + if (m_custom_style) + { - if (active) - { - bg_col = m_bg_color_active; - fg_col = m_fg_color_active; - icon_col = m_icon_color_active; - } - else - { - bg_col = m_bg_color; - fg_col = m_fg_color; - icon_col = m_icon_color; - } + QColor bg_col, fg_col; - QColor bg_col_top, bg_col_bottom; - if (m_title_3d > 0) - { - bg_col_top = bg_col.lighter (100 + m_title_3d); - bg_col_bottom = bg_col.darker (100 + m_title_3d); - } - else - { - bg_col_top = bg_col.darker (100 - m_title_3d); - bg_col_bottom = bg_col.lighter (100 - m_title_3d); - } + if (active) + { + bg_col = m_bg_color_active; + fg_col = m_fg_color_active; + icon_col = m_icon_color_active; + } + else + { + bg_col = m_bg_color; + fg_col = m_fg_color; + icon_col = m_icon_color; + } - css_foreground = QString (" color: %1;\n").arg (fg_col.name ()); + QColor bg_col_top, bg_col_bottom; + if (m_title_3d > 0) + { + bg_col_top = bg_col.lighter (100 + m_title_3d); + bg_col_bottom = bg_col.darker (100 + m_title_3d); + } + else + { + bg_col_top = bg_col.darker (100 - m_title_3d); + bg_col_bottom = bg_col.lighter (100 - m_title_3d); + } - css_background = - QString (" background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," - " stop: 0 %1, stop: 0.60 %2, stop: 0.95 %2 stop: 1.0 %3);\n"). - arg (bg_col_top.name ()). - arg (bg_col.name ()). - arg (bg_col_bottom.name ()); - } - else - { - css_foreground = QString (""); - css_background = QString (""); - } + css_foreground = QString (" color: %1;\n").arg (fg_col.name ()); - 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 (); - 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)); - } - else - { - setStyleSheet (qdockwidget_css (global_icon_paths.at (ICON_THEME_OCTAVE) + full_close_icon + ".png", - close_tooltip, - global_icon_paths.at (ICON_THEME_OCTAVE) + full_dock_icon + ".png", - dock_tooltip, - m_icon_size, - css_foreground, - css_background)); - } -} + css_background = + QString (" background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," + " stop: 0 %1, stop: 0.60 %2, stop: 0.95 %2 stop: 1.0 %3);\n"). + arg (bg_col_top.name ()). + arg (bg_col.name ()). + arg (bg_col_bottom.name ()); + } + else + { + css_foreground = ""; + css_background = ""; + } + + QString full_dock_icon = dock_icon + icon_col; + QString full_close_icon = "widget-close" + icon_col; + if (titleBarWidget ()) + { + gui_settings settings; -// set focus to previously active widget in tabbed widget stack -void -octave_dock_widget::set_focus_predecessor (void) -{ - // only != 0 if widget was tabbed - if (m_predecessor_widget && m_predecessor_widget->isVisible ()) - m_predecessor_widget->setFocus (); - - m_predecessor_widget = nullptr; + 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 (settings.icon (full_dock_icon, true)); + m_close_action->setIcon (settings.icon (full_close_icon, true)); + } + else + { + setStyleSheet (qdockwidget_css (global_icon_paths.at (ICON_THEME_OCTAVE) + full_close_icon + ".png", + close_tooltip, + global_icon_paths.at (ICON_THEME_OCTAVE) + full_dock_icon + ".png", + dock_tooltip, + m_icon_size, + css_foreground, + css_background)); + } + } - // 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 (); + // set focus to previously active widget in tabbed widget stack + 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 (); - 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); -} + m_predecessor_widget = nullptr; + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/octave-dock-widget.h --- a/libgui/src/octave-dock-widget.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/octave-dock-widget.h Mon Jan 30 18:36:03 2023 +0100 @@ -31,158 +31,155 @@ #include #include -#include "gui-settings.h" #include "qt-interpreter-events.h" OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -class main_window; + class main_window; -// The few decoration items common to both main window and variable editor. + // The few decoration items common to both main window and variable editor. -class label_dock_widget : public QDockWidget -{ - Q_OBJECT + class label_dock_widget : public QDockWidget + { + Q_OBJECT -public: + 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) - void set_title (const QString&); + // set_title() uses the custom title bar while setWindowTitle() uses + // the default title bar (with style sheets) + void set_title (const QString&); -protected slots: + protected slots: - //! Slots to handle copy & paste. - //!@{ - virtual void copyClipboard (void) { } - virtual void pasteClipboard (void) { } - virtual void selectAll (void) { } - //!@} + //! Slots to handle copy & paste. + //!@{ + virtual void copyClipboard () { } + virtual void pasteClipboard () { } + virtual void selectAll () { } + //!@} - //! Slot to handle undo. - - virtual void do_undo (void) { } + //! Slot to handle undo. -protected: + virtual void do_undo () { } - base_qobject& m_octave_qobj; + protected: - int m_icon_size; - QWidget *m_title_widget; - QToolButton *m_dock_button; - QToolButton *m_close_button; - QAction *m_dock_action; - QAction *m_close_action; + int m_icon_size; + QWidget *m_title_widget; + QToolButton *m_dock_button; + QToolButton *m_close_button; + QAction *m_dock_action; + QAction *m_close_action; - QAbstractButton *m_default_float_button; - QAbstractButton *m_default_close_button; -}; + QAbstractButton *m_default_float_button; + QAbstractButton *m_default_close_button; + }; -class octave_dock_widget : public label_dock_widget -{ - Q_OBJECT + class octave_dock_widget : public label_dock_widget + { + Q_OBJECT -public: + public: + + octave_dock_widget (const QString& obj_name, QWidget *p); - octave_dock_widget (const QString& obj_name, QWidget *p, - base_qobject& oct_qobj); + ~octave_dock_widget () = default; + + void set_predecessor_widget (octave_dock_widget *prev_widget); - ~octave_dock_widget (void) = default; + void set_main_window (main_window *mw); - 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 () const { return m_adopted; } - void set_adopted (bool adopted = true) { m_adopted = adopted; } - bool adopted (void) const { return m_adopted; } + signals: -signals: + //! Custom signal that tells whether a user has clicked away that dock + //! widget, i.e. the active dock widget has changed. - //! Custom signal that tells whether a user has clicked away that dock - //! widget, i.e. the active dock widget has changed. + void active_changed (bool active); - void active_changed (bool active); + void queue_make_window (bool widget_was_dragged); - void queue_make_window (bool widget_was_dragged); + void queue_make_widget (); - void queue_make_widget (void); + protected: -protected: + virtual void closeEvent (QCloseEvent *e); - virtual void closeEvent (QCloseEvent *e); + QWidget * focusWidget (); - QWidget * focusWidget (void); + bool event (QEvent *event); - bool event (QEvent *event); + public slots: -public slots: + virtual void activate (); - virtual void activate (void); + virtual void handle_visibility (bool visible); - virtual void handle_visibility (bool visible); + virtual void notice_settings () { } - virtual void notice_settings (const gui_settings *) { } + virtual void save_settings (); - virtual void save_settings (void); + void init_window_menu_entry (); - void init_window_menu_entry (void); + void handle_settings (); - void handle_settings (const gui_settings *); + void handle_active_dock_changed (octave_dock_widget *, octave_dock_widget *); - void handle_active_dock_changed (octave_dock_widget *, octave_dock_widget *); + void moveEvent (QMoveEvent *event); - void moveEvent (QMoveEvent *event); + void resizeEvent (QResizeEvent *event); - void resizeEvent (QResizeEvent *event); + void make_window (bool widget_was_dragged = false); - void make_window (bool widget_was_dragged = false); + void make_widget (bool not_used = false); - void make_widget (bool not_used = false); + void default_dock (bool not_used = false); - void default_dock (bool not_used = false); + protected slots: -protected slots: + virtual void toplevel_change (bool); - virtual void toplevel_change (bool); + //! Event filter for double clicks into the window decoration elements. - //! Event filter for double clicks into the window decoration elements. + bool eventFilter (QObject *obj, QEvent *e); - bool eventFilter (QObject *obj, QEvent *e); + private slots: -private slots: + void change_visibility (bool); - void change_visibility (bool); + private: -private: + void set_style (bool active); + void set_focus_predecessor (); + void store_geometry (); - void set_style (bool active); - void set_focus_predecessor (void); - void store_geometry (void); + private: - //! Stores the parent, since we are reparenting to 0. + //! Stores the parent, since we are reparenting to 0. - main_window *m_main_window; + main_window *m_main_window; - bool m_adopted; - bool m_custom_style; - bool m_focus_follows_mouse; - int m_title_3d; - QColor m_bg_color; - QColor m_bg_color_active; - QColor m_fg_color; - QColor m_fg_color_active; - QString m_icon_color; - QString m_icon_color_active; - octave_dock_widget *m_predecessor_widget; - QRect m_recent_float_geom; - QRect m_recent_dock_geom; - bool m_waiting_for_mouse_button_release; -}; + bool m_adopted; + bool m_custom_style; + bool m_focus_follows_mouse; + int m_title_3d; + QColor m_bg_color; + QColor m_bg_color_active; + QColor m_fg_color; + QColor m_fg_color_active; + QString m_icon_color; + QString m_icon_color_active; + octave_dock_widget *m_predecessor_widget; + QRect m_recent_float_geom; + QRect m_recent_dock_geom; + bool m_waiting_for_mouse_button_release; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/octave-qobject.cc --- a/libgui/src/octave-qobject.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/octave-qobject.cc Mon Jan 30 18:36:03 2023 +0100 @@ -46,6 +46,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 +54,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 +73,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; @@ -131,911 +130,916 @@ OCTAVE_BEGIN_NAMESPACE(octave) -// Disable all Qt messages by default. + // Disable all Qt messages by default. -static void -message_handler (QtMsgType, const QMessageLogContext&, const QString&) -{ } + static void + message_handler (QtMsgType, const QMessageLogContext&, const QString&) + { } -//! Reimplement QApplication::notify. Octave's own exceptions are -//! caught and rethrown in the interpreter thread. + //! Reimplement QApplication::notify. Octave's own exceptions are + //! caught and rethrown in the interpreter thread. -bool octave_qapplication::notify (QObject *receiver, QEvent *ev) -{ - try - { - return QApplication::notify (receiver, ev); - } - catch (execution_exception& ee) - { - emit interpreter_event - ([=] (void) - { - // INTERPRETER THREAD - throw ee; - }); - } + bool octave_qapplication::notify (QObject *receiver, QEvent *ev) + { + try + { + return QApplication::notify (receiver, ev); + } + catch (execution_exception& ee) + { + emit interpreter_event + ([=] () + { + // INTERPRETER THREAD + throw ee; + }); + } - return false; -} - -// We will create a QApplication object, even if START_GUI is false, -// so that we can use Qt widgets for plot windows when running in -// command-line mode. Note that we are creating an -// octave_qapplication object but handling it as a QApplication object -// because the octave_qapplication should behave identically to a -// QApplication object except that it overrides the notify method so -// we can handle forward Octave interpreter exceptions from the GUI -// thread to the interpreter thread. + return false; + } -base_qobject::base_qobject (qt_application& app_context, bool gui_app) - : QObject (), - m_app_context (app_context), - 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 ()), - m_translators_installed (false), - m_qt_interpreter_events (new qt_interpreter_events (*this)), - m_interpreter_qobj (new interpreter_qobject (*this)), - m_main_thread (new QThread ()), - m_gui_app (gui_app), - m_interpreter_ready (false), - m_workspace_model (new workspace_model ()), - m_documentation_widget (), - m_file_browser_widget (), - m_history_widget (), - m_workspace_widget (), - m_editor_widget (), - m_variable_editor_widget (), - m_main_window (nullptr) -{ - std::string show_gui_msgs = - sys::env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); + // We will create a QApplication object, even if START_GUI is false, + // so that we can use Qt widgets for plot windows when running in + // command-line mode. Note that we are creating an + // octave_qapplication object but handling it as a QApplication object + // because the octave_qapplication should behave identically to a + // QApplication object except that it overrides the notify method so + // we can handle forward Octave interpreter exceptions from the GUI + // thread to the interpreter thread. - // Installing our handler suppresses the messages. + base_qobject::base_qobject (qt_application& app_context, bool gui_app) + : QObject (), + m_app_context (app_context), + m_argc (m_app_context.sys_argc ()), + m_argv (m_app_context.sys_argv ()), + m_qapplication (new octave_qapplication (m_argc, m_argv)), + m_qt_tr (new QTranslator ()), + m_gui_tr (new QTranslator ()), + m_qsci_tr (new QTranslator ()), + m_translators_installed (false), + m_qt_interpreter_events (new qt_interpreter_events (*this)), + m_interpreter_qobj (new interpreter_qobject (*this)), + m_main_thread (new QThread ()), + m_gui_app (gui_app), + m_interpreter_ready (false), + m_workspace_model (new workspace_model ()), + m_documentation_widget (), + m_file_browser_widget (), + m_history_widget (), + m_workspace_widget (), + m_editor_widget (), + m_variable_editor_widget (), + m_main_window (nullptr) + { + std::string show_gui_msgs = sys::env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); - if (show_gui_msgs.empty ()) - qInstallMessageHandler (message_handler); + // Installing our handler suppresses the messages. - // Set the codec for all strings (before wizard or any GUI object) + if (show_gui_msgs.empty ()) + qInstallMessageHandler (message_handler); + + // Set the codec for all strings (before wizard or any GUI object) #if ! defined (Q_OS_WIN32) - QTextCodec::setCodecForLocale (QTextCodec::codecForName ("UTF-8")); + QTextCodec::setCodecForLocale (QTextCodec::codecForName ("UTF-8")); #endif - // Initialize global Qt application metadata. + // Register octave_value_list for connecting thread crossing signals. - QCoreApplication::setApplicationName ("GNU Octave"); - QCoreApplication::setApplicationVersion (OCTAVE_VERSION); - - // Register octave_value_list for connecting thread crossing signals. + qRegisterMetaType ("octave_value_list"); - qRegisterMetaType ("octave_value_list"); - - // Bug #55940 (Disable App Nap on Mac) + // Bug #55940 (Disable App Nap on Mac) #if defined (Q_OS_MAC) - // Mac App Nap feature causes pause() and sleep() to misbehave. - // Disable it for the entire program run. - disable_app_nap (); + // 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) - m_qapplication->setLayoutDirection (Qt::LeftToRight); + // Force left-to-right alignment (see bug #46204) + m_qapplication->setLayoutDirection (Qt::LeftToRight); - // Qt docs recommend using Qt::QueuedConnection when connecting to - // the QCoreApplication::exit slot. - connect (m_interpreter_qobj, &interpreter_qobject::shutdown_finished, - m_qapplication, &octave_qapplication::exit, - Qt::QueuedConnection); + // Qt docs recommend using Qt::QueuedConnection when connecting to + // the QCoreApplication::exit slot. + connect (m_interpreter_qobj, &interpreter_qobject::shutdown_finished, + m_qapplication, &octave_qapplication::exit, + Qt::QueuedConnection); - connect (m_interpreter_qobj, &interpreter_qobject::ready, - this, &base_qobject::interpreter_ready); + connect (m_interpreter_qobj, &interpreter_qobject::ready, + this, &base_qobject::interpreter_ready); - connect (m_main_thread, &QThread::finished, - m_main_thread, &QThread::deleteLater); + connect (m_main_thread, &QThread::finished, + m_main_thread, &QThread::deleteLater); - // Handle any interpreter_event signal from the octave_qapplication - // object here. + // Handle any interpreter_event signal from the octave_qapplication + // object here. - connect (m_qapplication, QOverload::of (&octave_qapplication::interpreter_event), - this, QOverload::of (&base_qobject::interpreter_event)); + connect (m_qapplication, QOverload::of (&octave_qapplication::interpreter_event), + this, QOverload::of (&base_qobject::interpreter_event)); - connect (m_qapplication, QOverload::of (&octave_qapplication::interpreter_event), - this, QOverload::of (&base_qobject::interpreter_event)); + connect (m_qapplication, QOverload::of (&octave_qapplication::interpreter_event), + this, QOverload::of (&base_qobject::interpreter_event)); - if (m_app_context.experimental_terminal_widget ()) - { - connect (qt_link (), &qt_interpreter_events::start_gui_signal, - this, &base_qobject::start_gui); + if (m_app_context.experimental_terminal_widget ()) + { + connect (qt_link (), &qt_interpreter_events::start_gui_signal, + this, &base_qobject::start_gui); - connect (qt_link (), &qt_interpreter_events::show_terminal_window_signal, - this, &base_qobject::show_terminal_window); - } + connect (qt_link (), &qt_interpreter_events::show_terminal_window_signal, + this, &base_qobject::show_terminal_window); + } - connect (qt_link (), &qt_interpreter_events::copy_image_to_clipboard_signal, - this, &base_qobject::copy_image_to_clipboard); + connect (qt_link (), &qt_interpreter_events::copy_image_to_clipboard_signal, + this, &base_qobject::copy_image_to_clipboard); - connect (qt_link (), &qt_interpreter_events::show_documentation_signal, - this, &base_qobject::show_documentation_window); + connect (qt_link (), &qt_interpreter_events::show_documentation_signal, + this, &base_qobject::show_documentation_window); - connect (qt_link (), &qt_interpreter_events::show_file_browser_signal, - this, &base_qobject::show_file_browser_window); + connect (qt_link (), &qt_interpreter_events::show_file_browser_signal, + this, &base_qobject::show_file_browser_window); - connect (qt_link (), &qt_interpreter_events::show_command_history_signal, - this, &base_qobject::show_command_history_window); + connect (qt_link (), &qt_interpreter_events::show_command_history_signal, + this, &base_qobject::show_command_history_window); - connect (qt_link (), &qt_interpreter_events::show_workspace_signal, - this, &base_qobject::show_workspace_window); + connect (qt_link (), &qt_interpreter_events::show_workspace_signal, + this, &base_qobject::show_workspace_window); - connect (qt_link (), &qt_interpreter_events::edit_variable_signal, - this, &base_qobject::show_variable_editor_window); + connect (qt_link (), &qt_interpreter_events::edit_variable_signal, + this, &base_qobject::show_variable_editor_window); - connect (qt_link (), &qt_interpreter_events::show_community_news_signal, - this, &base_qobject::show_community_news); + connect (qt_link (), &qt_interpreter_events::show_community_news_signal, + this, &base_qobject::show_community_news); - connect (qt_link (), &qt_interpreter_events::show_release_notes_signal, - this, &base_qobject::show_release_notes); + connect (qt_link (), &qt_interpreter_events::show_release_notes_signal, + this, &base_qobject::show_release_notes); - if (m_app_context.experimental_terminal_widget ()) - { - m_qapplication->setQuitOnLastWindowClosed (false); - } - else - { - if (gui_app) - { - m_main_window = new main_window (*this); + if (m_app_context.experimental_terminal_widget ()) + { + m_qapplication->setQuitOnLastWindowClosed (false); + } + else + { + if (gui_app) + { + m_main_window = new main_window (*this); - connect (m_main_window, &main_window::show_community_news_signal, - this, &base_qobject::show_community_news); + connect (m_main_window, &main_window::show_community_news_signal, + this, &base_qobject::show_community_news); - connect (m_main_window, &main_window::show_release_notes_signal, - this, &base_qobject::show_release_notes); + connect (m_main_window, &main_window::show_release_notes_signal, + this, &base_qobject::show_release_notes); - if (m_interpreter_ready) - m_main_window->handle_octave_ready (); - else - connect (m_interpreter_qobj, &interpreter_qobject::ready, - m_main_window, &main_window::handle_octave_ready); + if (m_interpreter_ready) + m_main_window->handle_octave_ready (); + else + connect (m_interpreter_qobj, &interpreter_qobject::ready, + m_main_window, &main_window::handle_octave_ready); - connect (qt_link (), &qt_interpreter_events::focus_window_signal, - m_main_window, &main_window::focus_window); + connect (qt_link (), &qt_interpreter_events::focus_window_signal, + m_main_window, &main_window::focus_window); - m_app_context.gui_running (true); - } - else - { - // Get settings file. - m_resource_manager.reload_settings (); + m_app_context.gui_running (true); + } + else + { + // Get settings file. + gui_settings settings; + + settings.reload (); - // After settings. - config_translators (); - m_resource_manager.config_icon_theme (); + // After settings. + config_translators (); - // Initilize the shortcut-manager - m_shortcut_manager.init_data (); + settings.config_icon_theme (); - m_qapplication->setQuitOnLastWindowClosed (false); - } - } + m_qapplication->setQuitOnLastWindowClosed (false); + } + } - start_main_thread (); -} + start_main_thread (); + } -base_qobject::~base_qobject (void) -{ - // 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 - // finished signal. + 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 + // finished signal. - // FIXME: Why are dock widget settings and/or the main window - // configuration not saved correctly if the main window is deleted - // after the dock widgets? + // FIXME: Why are dock widget settings and/or the main window + // configuration not saved correctly if the main window is deleted + // after the dock widgets? - // Calling close will cause settings to be saved. - // If m_main_window exists, the widgets are closed by the main window + // Calling close will cause settings to be saved. + // If m_main_window exists, the widgets are closed by the main window - if (! m_main_window) - { - if (m_terminal_widget) - m_terminal_widget->close (); + if (! m_main_window) + { + if (m_terminal_widget) + m_terminal_widget->close (); - if (m_documentation_widget) - m_documentation_widget->close (); + if (m_documentation_widget) + m_documentation_widget->close (); - if (m_file_browser_widget) - m_file_browser_widget->close (); + if (m_file_browser_widget) + m_file_browser_widget->close (); - if (m_history_widget) - m_history_widget->close (); + if (m_history_widget) + m_history_widget->close (); - if (m_workspace_widget) - m_workspace_widget->close (); + if (m_workspace_widget) + m_workspace_widget->close (); - if (m_editor_widget) - m_editor_widget->close (); + if (m_editor_widget) + m_editor_widget->close (); - if (m_variable_editor_widget) - m_variable_editor_widget->close (); + if (m_variable_editor_widget) + m_variable_editor_widget->close (); - if (m_community_news) - m_community_news->close (); - } - else - { - delete m_main_window; - } + if (m_community_news) + m_community_news->close (); + } + else + { + delete m_main_window; + } - delete m_terminal_widget; - delete m_documentation_widget; - delete m_file_browser_widget; - delete m_history_widget; - delete m_workspace_widget; - delete m_editor_widget; - delete m_variable_editor_widget; - delete m_community_news; + delete m_terminal_widget; + delete m_documentation_widget; + delete m_file_browser_widget; + delete m_history_widget; + delete m_workspace_widget; + delete m_editor_widget; + delete m_variable_editor_widget; + delete m_community_news; - delete m_interpreter_qobj; - delete m_qsci_tr; - delete m_gui_tr; - delete m_qt_tr; - delete m_qapplication; - delete m_workspace_model; + delete m_interpreter_qobj; + delete m_qsci_tr; + delete m_gui_tr; + delete m_qt_tr; + delete m_qapplication; + delete m_workspace_model; - string_vector::delete_c_str_vec (m_argv); -} + string_vector::delete_c_str_vec (m_argv); + } -void base_qobject::config_translators (void) -{ - if (m_translators_installed) - return; + 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); - m_qapplication->installTranslator (m_qsci_tr); + m_qapplication->installTranslator (m_qt_tr); + m_qapplication->installTranslator (m_gui_tr); + m_qapplication->installTranslator (m_qsci_tr); - m_translators_installed = true; -} + m_translators_installed = true; + } -void base_qobject::start_main_thread (void) -{ - // Note: if using the new experimental terminal widget, we defer - // initializing and executing the interpreter until the main event - // loop begins executing. + 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 + // loop begins executing. - // With the old terminal widget, we defer initializing and executing - // the interpreter until after the main window and QApplication are - // running to prevent race conditions. + // With the old terminal widget, we defer initializing and executing + // 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_interpreter_qobj->moveToThread (m_main_thread); - m_main_thread->start (); -} + m_main_thread->start (); + } -int base_qobject::exec (void) -{ - int status = m_qapplication->exec (); + int base_qobject::exec () + { + int status = m_qapplication->exec (); #if defined (Q_OS_MAC) - // fprintf to stderr is needed by macOS, for poorly-understood reasons. - fprintf (stderr, "\n"); + // fprintf to stderr is needed by macOS, for poorly-understood reasons. + fprintf (stderr, "\n"); #endif - m_main_thread->quit (); - m_main_thread->wait (); + m_main_thread->quit (); + m_main_thread->wait (); + + return status; + } - return status; -} + // Provided for convenience. Will be removed once we eliminate the + // old terminal widget. + bool base_qobject::experimental_terminal_widget () const + { + return m_app_context.experimental_terminal_widget (); + } -// Provided for convenience. Will be removed once we eliminate the -// old terminal widget. -bool base_qobject::experimental_terminal_widget (void) const -{ - return m_app_context.experimental_terminal_widget (); -} + bool base_qobject::gui_running () const + { + return m_app_context.gui_running (); + } -bool base_qobject::gui_running (void) const -{ - return m_app_context.gui_running (); -} + QPointer + base_qobject::terminal_widget (main_window *mw) + { + if (m_terminal_widget && mw) + { + m_terminal_widget->set_main_window (mw); + m_terminal_widget->set_adopted (true); + } + else if (! m_terminal_widget) + { + bool etw = m_app_context.experimental_terminal_widget (); -QPointer -base_qobject::terminal_widget (main_window *mw) -{ - if (m_terminal_widget && mw) - { - m_terminal_widget->set_main_window (mw); - m_terminal_widget->set_adopted (true); - } - else if (! m_terminal_widget) - { - m_terminal_widget - = QPointer (new terminal_dock_widget (mw, *this)); - if (experimental_terminal_widget ()) - { + m_terminal_widget + = QPointer (new terminal_dock_widget (mw, etw)); + + if (etw) + { #if defined (HAVE_QSCINTILLA) - command_widget *cmd_widget - = m_terminal_widget->get_command_widget (); + command_widget *cmd_widget + = m_terminal_widget->get_command_widget (); - connect (cmd_widget, &command_widget::interpreter_pause, - this, &base_qobject::interpreter_pause); + connect (cmd_widget, &command_widget::interpreter_pause, + this, &base_qobject::interpreter_pause); + + connect (cmd_widget, &command_widget::interpreter_resume, + this, &base_qobject::interpreter_resume); - connect (cmd_widget, &command_widget::interpreter_resume, - this, &base_qobject::interpreter_resume); + connect (cmd_widget, &command_widget::interpreter_stop, + this, &base_qobject::interpreter_stop); - connect (cmd_widget, &command_widget::interpreter_stop, - this, &base_qobject::interpreter_stop); - - connect (qt_link (), &qt_interpreter_events::interpreter_output_signal, - m_terminal_widget, &terminal_dock_widget::interpreter_output_signal); + connect (qt_link (), &qt_interpreter_events::interpreter_output_signal, + m_terminal_widget, &terminal_dock_widget::interpreter_output_signal); - connect (qt_link (), &qt_interpreter_events::update_prompt_signal, - m_terminal_widget, &terminal_dock_widget::update_prompt_signal); - - connect (qt_link (), &qt_interpreter_events::new_command_line_signal, - m_terminal_widget, &terminal_dock_widget::new_command_line_signal); + connect (qt_link (), &qt_interpreter_events::update_prompt_signal, + m_terminal_widget, &terminal_dock_widget::update_prompt_signal); - connect_interpreter_events (cmd_widget); -#endif - } - else - { - QTerminal *cmd_widget = m_terminal_widget->get_qterminal (); + 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 the interrupt signal (emitted by Ctrl-C) - connect (cmd_widget, &QTerminal::interrupt_signal, - this, &base_qobject::interpreter_interrupt); - } - } + connect_interpreter_events (cmd_widget); +#endif + } + else + { + QTerminal *cmd_widget = m_terminal_widget->get_qterminal (); - return m_terminal_widget; -} + // Connect the interrupt signal (emitted by Ctrl-C) + connect (cmd_widget, &QTerminal::interrupt_signal, + this, &base_qobject::interpreter_interrupt); + + connect_interpreter_events (cmd_widget); + } + } -QPointer -base_qobject::documentation_widget (main_window *mw) -{ - if (m_documentation_widget && mw) - { - m_documentation_widget->set_main_window (mw); - m_documentation_widget->set_adopted (true); - } - else if (! m_documentation_widget) - { - m_documentation_widget - = QPointer (new documentation_dock_widget (mw, *this)); + return m_terminal_widget; + } - connect (qt_link (), - &qt_interpreter_events::register_documentation_signal, - m_documentation_widget, - &documentation_dock_widget::registerDoc); - - connect (qt_link (), - &qt_interpreter_events::unregister_documentation_signal, - m_documentation_widget, - &documentation_dock_widget::unregisterDoc); - } + QPointer + base_qobject::documentation_widget (main_window *mw) + { + if (m_documentation_widget && mw) + { + m_documentation_widget->set_main_window (mw); + m_documentation_widget->set_adopted (true); + } + else if (! m_documentation_widget) + { + m_documentation_widget + = QPointer (new documentation_dock_widget (mw)); - return m_documentation_widget; -} + connect (qt_link (), + &qt_interpreter_events::register_documentation_signal, + m_documentation_widget, + &documentation_dock_widget::registerDoc); -QPointer -base_qobject::file_browser_widget (main_window *mw) -{ - if (m_file_browser_widget) - { - m_file_browser_widget->set_main_window (mw); - m_file_browser_widget->set_adopted (true); - } - else if (! m_file_browser_widget) - m_file_browser_widget - = QPointer (new files_dock_widget (mw, *this)); + connect (qt_link (), + &qt_interpreter_events::unregister_documentation_signal, + m_documentation_widget, + &documentation_dock_widget::unregisterDoc); + } - connect (qt_link (), &qt_interpreter_events::directory_changed_signal, - m_file_browser_widget, &files_dock_widget::update_octave_directory); + return m_documentation_widget; + } - return m_file_browser_widget; -} + QPointer + base_qobject::file_browser_widget (main_window *mw) + { + if (m_file_browser_widget) + { + m_file_browser_widget->set_main_window (mw); + m_file_browser_widget->set_adopted (true); + } + else if (! m_file_browser_widget) + m_file_browser_widget + = QPointer (new files_dock_widget (mw)); -QPointer -base_qobject::history_widget (main_window *mw) -{ - if (m_history_widget) - { - m_history_widget->set_main_window (mw); - m_history_widget->set_adopted (true); - } - else if (! m_history_widget) - { - m_history_widget - = QPointer (new history_dock_widget (mw, *this)); + connect (qt_link (), &qt_interpreter_events::directory_changed_signal, + m_file_browser_widget, &files_dock_widget::update_octave_directory); - connect (qt_link (), &qt_interpreter_events::set_history_signal, - m_history_widget, &history_dock_widget::set_history); + return m_file_browser_widget; + } - connect (qt_link (), &qt_interpreter_events::append_history_signal, - m_history_widget, &history_dock_widget::append_history); + QPointer + base_qobject::history_widget (main_window *mw) + { + if (m_history_widget) + { + m_history_widget->set_main_window (mw); + m_history_widget->set_adopted (true); + } + else if (! m_history_widget) + { + m_history_widget + = QPointer (new history_dock_widget (mw)); - connect (qt_link (), &qt_interpreter_events::clear_history_signal, - m_history_widget, &history_dock_widget::clear_history); + connect (qt_link (), &qt_interpreter_events::set_history_signal, + m_history_widget, &history_dock_widget::set_history); - emit interpreter_event - ([=] (interpreter& interp) { - // INTERPRETER THREAD + connect (qt_link (), &qt_interpreter_events::append_history_signal, + m_history_widget, &history_dock_widget::append_history); - event_manager& xevmgr = interp.get_event_manager (); + connect (qt_link (), &qt_interpreter_events::clear_history_signal, + m_history_widget, &history_dock_widget::clear_history); - xevmgr.set_history (); - }); - } + emit interpreter_event + ([=] (interpreter& interp) { + // INTERPRETER THREAD + + event_manager& xevmgr = interp.get_event_manager (); - return m_history_widget; -} + xevmgr.set_history (); + }); + } + + return m_history_widget; + } -QPointer -base_qobject::workspace_widget (main_window *mw) -{ - if (m_workspace_widget) - { - m_workspace_widget->set_main_window (mw); - m_workspace_widget->set_adopted (true); - } - else if (! m_workspace_widget) - { - m_workspace_widget - = QPointer (new workspace_view (mw, *this)); + QPointer + base_qobject::workspace_widget (main_window *mw) + { + if (m_workspace_widget) + { + m_workspace_widget->set_main_window (mw); + m_workspace_widget->set_adopted (true); + } + else if (! m_workspace_widget) + { + m_workspace_widget + = QPointer (new workspace_view (mw)); - m_workspace_widget->setModel (m_workspace_model); + m_workspace_widget->setModel (m_workspace_model); - connect (m_workspace_model, &workspace_model::model_changed, - m_workspace_widget, &workspace_view::handle_model_changed); - - connect (qt_link (), &qt_interpreter_events::set_workspace_signal, - m_workspace_model, &workspace_model::set_workspace); + connect (m_workspace_model, &workspace_model::model_changed, + m_workspace_widget, &workspace_view::handle_model_changed); - connect (qt_link (), &qt_interpreter_events::clear_workspace_signal, - m_workspace_model, &workspace_model::clear_workspace); + connect (qt_link (), &qt_interpreter_events::set_workspace_signal, + m_workspace_model, &workspace_model::set_workspace); - connect (m_workspace_widget, - &workspace_view::copy_variable_value_to_clipboard, - [=] (const QString& var_name) { - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD + connect (qt_link (), &qt_interpreter_events::clear_workspace_signal, + m_workspace_model, &workspace_model::clear_workspace); - octave_value val = interp.varval (var_name.toStdString ()); - - if (val.is_undefined ()) - val = 0; + connect (m_workspace_widget, + &workspace_view::copy_variable_value_to_clipboard, + [=] (const QString& var_name) { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD - std::ostringstream buf; - val.print_raw (buf, true); + octave_value val = interp.varval (var_name.toStdString ()); - // FIXME: is the following operation thread safe or should - // it be done with a signal/slot connection? + if (val.is_undefined ()) + val = 0; - QClipboard *clipboard = QApplication::clipboard (); - clipboard->setText (QString::fromStdString (buf.str ())); - }); - }); + 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? - connect (m_workspace_widget, &workspace_view::rename_variable_signal, - [=] (const QString& old_name, const QString& new_name) { - emit interpreter_event - ([=] (interpreter& interp) { - // INTERPRETER THREAD + QClipboard *clipboard = QApplication::clipboard (); + clipboard->setText (QString::fromStdString (buf.str ())); + }); + }); - symbol_scope scope = interp.get_current_scope (); + connect (m_workspace_widget, &workspace_view::rename_variable_signal, + [=] (const QString& old_name, const QString& new_name) { + emit interpreter_event + ([=] (interpreter& interp) { + // INTERPRETER THREAD - if (scope) - { - scope.rename (old_name.toStdString (), - new_name.toStdString ()); + symbol_scope scope = interp.get_current_scope (); - tree_evaluator& tw = interp.get_evaluator (); + if (scope) + { + scope.rename (old_name.toStdString (), + new_name.toStdString ()); + + 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 ()); - } + xevmgr.set_workspace (true, tw.get_symbol_info ()); + } - // FIXME: if this action fails, do we need a way to - // display that info in the GUI? - }); - }); + // FIXME: if this action fails, do we need a way to + // display that info in the GUI? + }); + }); - connect (m_workspace_widget, &workspace_view::edit_variable_signal, - [=] (const QString& var_name) { - emit interpreter_event - ([=] (interpreter& interp) { - // INTERPRETER THREAD + connect (m_workspace_widget, &workspace_view::edit_variable_signal, + [=] (const QString& var_name) { + emit interpreter_event + ([=] (interpreter& interp) { + // INTERPRETER THREAD - std::string name = var_name.toStdString (); - octave_value val = interp.varval (name); + std::string name = var_name.toStdString (); + octave_value val = interp.varval (name); - event_manager& xevmgr = interp.get_event_manager (); + event_manager& xevmgr = interp.get_event_manager (); - xevmgr.edit_variable (name, val); - }); - }); + xevmgr.edit_variable (name, val); + }); + }); - emit interpreter_event - ([=] (interpreter& interp) { - // INTERPRETER THREAD + emit interpreter_event + ([=] (interpreter& interp) { + // INTERPRETER THREAD - event_manager& xevmgr = interp.get_event_manager (); + event_manager& xevmgr = interp.get_event_manager (); - xevmgr.set_workspace (); - }); - } + xevmgr.set_workspace (); + }); + } - return m_workspace_widget; -} + return m_workspace_widget; + } -QPointer -base_qobject::editor_widget (main_window */*mw*/) -{ + 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); + 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); #endif - return m_editor_widget; -} + return m_editor_widget; + } -QPointer -base_qobject::variable_editor_widget (main_window *mw) -{ - if (m_variable_editor_widget && mw) - { - m_variable_editor_widget->set_main_window (mw); - m_variable_editor_widget->set_adopted (true); - } - else if (! m_variable_editor_widget) - { - m_variable_editor_widget - = QPointer (new variable_editor (mw, *this)); + QPointer + base_qobject::variable_editor_widget (main_window *mw) + { + if (m_variable_editor_widget && mw) + { + m_variable_editor_widget->set_main_window (mw); + m_variable_editor_widget->set_adopted (true); + } + else if (! m_variable_editor_widget) + { + m_variable_editor_widget + = QPointer (new variable_editor (mw)); - connect (m_variable_editor_widget, &variable_editor::updated, - this, &base_qobject::handle_variable_editor_update); + connect (m_variable_editor_widget, &variable_editor::updated, + this, &base_qobject::handle_variable_editor_update); - connect (m_variable_editor_widget, &variable_editor::command_signal, - this, &base_qobject::execute_command); + connect (m_variable_editor_widget, &variable_editor::command_signal, + this, &base_qobject::execute_command); - connect (qt_link (), - &qt_interpreter_events::refresh_variable_editor_signal, - m_variable_editor_widget, &variable_editor::refresh); + connect (qt_link (), + &qt_interpreter_events::refresh_variable_editor_signal, + m_variable_editor_widget, &variable_editor::refresh); - connect_interpreter_events (m_variable_editor_widget); - } + connect_interpreter_events (m_variable_editor_widget); + } - return m_variable_editor_widget; -} + return m_variable_editor_widget; + } -QPointer base_qobject::community_news_widget (int serial) -{ - if (! m_community_news) - m_community_news - = QPointer (new community_news (*this, serial)); + QPointer base_qobject::community_news_widget (int serial) + { + if (! m_community_news) + m_community_news + = QPointer (new community_news (serial)); - return m_community_news; -} + return m_community_news; + } -QPointer base_qobject::release_notes_widget (void) -{ - if (! m_release_notes) - m_release_notes = QPointer (new release_notes (*this)); + QPointer base_qobject::release_notes_widget () + { + if (! m_release_notes) + m_release_notes = QPointer (new release_notes ()); - return m_release_notes; -} + return m_release_notes; + } -bool base_qobject::confirm_shutdown (void) -{ - // Currently, we forward to main_window::confirm_shutdown instead of - // just displaying a dialog box here because the main_window also - // knows about and is responsible for notifying the editor. + 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 + // knows about and is responsible for notifying the editor. - return m_main_window ? m_main_window->confirm_shutdown () : true; -} + return m_main_window ? m_main_window->confirm_shutdown () : true; + } -void base_qobject::start_gui (bool gui_app) -{ - if (m_app_context.experimental_terminal_widget ()) - { - if (m_main_window) - return; + void base_qobject::start_gui (bool gui_app) + { + if (m_app_context.experimental_terminal_widget ()) + { + if (m_main_window) + return; - m_gui_app = gui_app; + m_gui_app = gui_app; - m_main_window = new main_window (*this); + m_main_window = new main_window (*this); - connect (qt_link (), &qt_interpreter_events::focus_window_signal, - m_main_window, &main_window::focus_window); + connect (qt_link (), &qt_interpreter_events::focus_window_signal, + m_main_window, &main_window::focus_window); - connect (qt_link (), &qt_interpreter_events::close_gui_signal, - this, &base_qobject::close_gui); + connect (qt_link (), &qt_interpreter_events::close_gui_signal, + this, &base_qobject::close_gui); - connect (m_main_window, &main_window::close_gui_signal, - this, &base_qobject::close_gui); + connect (m_main_window, &main_window::close_gui_signal, + this, &base_qobject::close_gui); - connect (m_main_window, &main_window::show_community_news_signal, - this, &base_qobject::show_community_news); + connect (m_main_window, &main_window::show_community_news_signal, + this, &base_qobject::show_community_news); - connect (m_main_window, &main_window::show_release_notes_signal, - this, &base_qobject::show_release_notes); + connect (m_main_window, &main_window::show_release_notes_signal, + this, &base_qobject::show_release_notes); - if (m_interpreter_ready) - m_main_window->handle_octave_ready (); - else - connect (m_interpreter_qobj, &interpreter_qobject::ready, - m_main_window, &main_window::handle_octave_ready); + if (m_interpreter_ready) + m_main_window->handle_octave_ready (); + else + connect (m_interpreter_qobj, &interpreter_qobject::ready, + m_main_window, &main_window::handle_octave_ready); - if (m_gui_app) - m_qapplication->setQuitOnLastWindowClosed (true); - else - { - // FIXME: Save current values of PS1 and PS2 so they can be - // restored when we return to the command line? - } + if (m_gui_app) + m_qapplication->setQuitOnLastWindowClosed (true); + else + { + // FIXME: Save current values of PS1 and PS2 so they can be + // restored when we return to the command line? + } - m_app_context.gui_running (true); - } -} + m_app_context.gui_running (true); + } + } -void base_qobject::show_terminal_window (void) -{ - terminal_dock_widget *widget - = (m_terminal_widget - ? m_terminal_widget : terminal_widget ()); + void base_qobject::show_terminal_window () + { + terminal_dock_widget *widget + = (m_terminal_widget + ? m_terminal_widget : terminal_widget ()); - if (! widget->isVisible ()) - { - widget->show (); - widget->raise (); - } -} + if (! widget->isVisible ()) + { + widget->show (); + widget->raise (); + } + } -void base_qobject::show_documentation_window (const QString& file) -{ - documentation_dock_widget *widget - = (m_documentation_widget - ? m_documentation_widget : documentation_widget ()); + void base_qobject::show_documentation_window (const QString& file) + { + documentation_dock_widget *widget + = (m_documentation_widget + ? m_documentation_widget : documentation_widget ()); - widget->showDoc (file); + widget->showDoc (file); - if (! widget->isVisible ()) - { - widget->show (); - widget->raise (); - } -} + if (! widget->isVisible ()) + { + widget->show (); + widget->raise (); + } + } -void base_qobject::show_file_browser_window (void) -{ - files_dock_widget *widget - = m_file_browser_widget ? m_file_browser_widget : file_browser_widget (); + void base_qobject::show_file_browser_window () + { + files_dock_widget *widget + = m_file_browser_widget ? m_file_browser_widget : file_browser_widget (); - if (! widget->isVisible ()) - { - widget->show (); - widget->raise (); - } -} + if (! widget->isVisible ()) + { + widget->show (); + widget->raise (); + } + } -void base_qobject::show_command_history_window (void) -{ - history_dock_widget *widget - = m_history_widget ? m_history_widget : history_widget (); + void base_qobject::show_command_history_window () + { + history_dock_widget *widget + = m_history_widget ? m_history_widget : history_widget (); - if (! widget->isVisible ()) - { - widget->show (); - widget->raise (); - } -} + if (! widget->isVisible ()) + { + widget->show (); + widget->raise (); + } + } -void base_qobject::show_workspace_window (void) -{ - workspace_view *widget - = m_workspace_widget ? m_workspace_widget : workspace_widget (); + void base_qobject::show_workspace_window () + { + workspace_view *widget + = m_workspace_widget ? m_workspace_widget : workspace_widget (); - if (! widget->isVisible ()) - { - widget->show (); - widget->raise (); - } -} + if (! widget->isVisible ()) + { + widget->show (); + widget->raise (); + } + } -void base_qobject::show_variable_editor_window (const QString& name, - const octave_value& value) -{ - variable_editor *widget - = (m_variable_editor_widget - ? m_variable_editor_widget : variable_editor_widget ()); + void base_qobject::show_variable_editor_window (const QString& name, + const octave_value& value) + { + variable_editor *widget + = (m_variable_editor_widget + ? m_variable_editor_widget : variable_editor_widget ()); - if (! widget->isVisible ()) - { - widget->show (); - widget->raise (); - } + if (! widget->isVisible ()) + { + widget->show (); + widget->raise (); + } - // FIXME: Should this be done with a signal/slot connection? - widget->edit_variable (name, value); -} + // FIXME: Should this be done with a signal/slot connection? + widget->edit_variable (name, value); + } -void base_qobject::handle_variable_editor_update (void) -{ - // Called when the variable editor emits the updated signal. The size - // of a variable may have changed, so we refresh the workspace in the - // interpreter. That will eventually cause the workspace view in the - // GUI to be updated. + 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 + // interpreter. That will eventually cause the workspace view in the + // GUI to be updated. - interpreter_event - ([] (interpreter& interp) - { - // INTERPRETER THREAD + interpreter_event + ([] (interpreter& interp) + { + // 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) -{ - // Ensure widget exists. - community_news_widget (serial); + void base_qobject::show_community_news (int serial) + { + // Ensure widget exists. + community_news_widget (serial); - m_community_news->display (); -} + m_community_news->display (); + } -void base_qobject::show_release_notes (void) -{ - // Ensure widget exists. - release_notes_widget (); + void base_qobject::show_release_notes () + { + // Ensure widget exists. + release_notes_widget (); - m_release_notes->display (); -} + m_release_notes->display (); + } -void base_qobject::execute_command (const QString& command) -{ - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD + void base_qobject::execute_command (const QString& command) + { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD - // FIXME: Do we need to do anything special about errors here? - // Currently the eval function will just call error() in the - // interpreter event loop and throw an execution error. It will - // be caught, so shouldn't crash the interpreter, but the - // message may not go anywhere useful depending on how the GUI - // is being used or if Octave running server mode. + // FIXME: Do we need to do anything special about errors here? + // Currently the eval function will just call error() in the + // interpreter event loop and throw an execution error. It will + // be caught, so shouldn't crash the interpreter, but the + // message may not go anywhere useful depending on how the GUI + // is being used or if Octave running server mode. - interp.eval (command.toStdString (), 0); - }); -} + interp.eval (command.toStdString (), 0); + }); + } -void base_qobject::close_gui (void) -{ - if (m_app_context.experimental_terminal_widget ()) - { - if (! m_main_window) - return; + void base_qobject::close_gui () + { + if (m_app_context.experimental_terminal_widget ()) + { + if (! m_main_window) + return; - // FIXME: Restore previous values of PS1 and PS2 if we are - // returning to the command line? + // FIXME: Restore previous values of PS1 and PS2 if we are + // returning to the command line? - interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD + interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD - application *app = interp.get_app_context (); + application *app = interp.get_app_context (); - cmdline_options opts = app->options (); + cmdline_options opts = app->options (); - if (opts.gui ()) - interp.quit (0, false, false); - }); + if (opts.gui ()) + interp.quit (0, false, false); + }); - m_app_context.gui_running (false); + m_app_context.gui_running (false); - if (m_main_window) - { - m_main_window->deleteLater (); + if (m_main_window) + { + m_main_window->deleteLater (); - m_main_window = nullptr; - } - } -} + m_main_window = nullptr; + } + } + } -void base_qobject::interpreter_ready (void) -{ - m_interpreter_ready = true; -} + void base_qobject::interpreter_ready () + { + m_interpreter_ready = true; + } -void base_qobject::interpreter_event (const fcn_callback& fcn) -{ - // The following is a direct function call across threads. It works - // because it is accessing a thread-safe queue of events that - // are later executed by the Octave interpreter in the other thread. + void base_qobject::interpreter_event (const fcn_callback& fcn) + { + // The following is a direct function call across threads. It works + // because it is accessing a thread-safe queue of events that + // are later executed by the Octave interpreter in the other thread. - // See also the comments in interpreter-qobject.h about - // interpreter_qobject slots. + // See also the comments in interpreter-qobject.h about + // interpreter_qobject slots. - m_interpreter_qobj->interpreter_event (fcn); -} + m_interpreter_qobj->interpreter_event (fcn); + } -void base_qobject::interpreter_event (const meth_callback& meth) -{ - // The following is a direct function call across threads. It works - // because it is accessing a thread-safe queue of events that - // are later executed by the Octave interpreter in the other thread. + void base_qobject::interpreter_event (const meth_callback& meth) + { + // The following is a direct function call across threads. It works + // because it is accessing a thread-safe queue of events that + // are later executed by the Octave interpreter in the other thread. - // See also the comments in interpreter-qobject.h about - // interpreter_qobject slots. + // See also the comments in interpreter-qobject.h about + // interpreter_qobject slots. - m_interpreter_qobj->interpreter_event (meth); -} + m_interpreter_qobj->interpreter_event (meth); + } -void base_qobject::interpreter_interrupt (void) -{ - m_interpreter_qobj->interrupt (); -} + void base_qobject::interpreter_interrupt () + { + m_interpreter_qobj->interrupt (); + } -// FIXME: Should we try to make the pause, stop, and resume actions -// work for both the old and new terminal widget? + // 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) -{ - if (m_app_context.experimental_terminal_widget ()) - m_interpreter_qobj->pause (); -} + void base_qobject::interpreter_pause () + { + if (m_app_context.experimental_terminal_widget ()) + m_interpreter_qobj->pause (); + } -void base_qobject::interpreter_stop (void) -{ - if (m_app_context.experimental_terminal_widget ()) - m_interpreter_qobj->stop (); -} + void base_qobject::interpreter_stop () + { + if (m_app_context.experimental_terminal_widget ()) + m_interpreter_qobj->stop (); + } -void base_qobject::interpreter_resume (void) -{ - if (m_app_context.experimental_terminal_widget ()) - m_interpreter_qobj->resume (); -} + void base_qobject::interpreter_resume () + { + if (m_app_context.experimental_terminal_widget ()) + m_interpreter_qobj->resume (); + } -void base_qobject::copy_image_to_clipboard (const QString& file, - bool remove_file) -{ - QClipboard *clipboard = QApplication::clipboard (); + void base_qobject::copy_image_to_clipboard (const QString& file, + bool remove_file) + { + QClipboard *clipboard = QApplication::clipboard (); - QImage img (file); + QImage img (file); - if (img.isNull ()) - { - // Report error? - return; - } + if (img.isNull ()) + { + // Report error? + return; + } - clipboard->setImage (img); + clipboard->setImage (img); - if (remove_file) - QFile::remove (file); -} + if (remove_file) + QFile::remove (file); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/octave-qobject.h --- a/libgui/src/octave-qobject.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/octave-qobject.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/octave-qtutils.h --- a/libgui/src/octave-qtutils.h Mon Jan 30 18:30:33 2023 +0100 +++ /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 17d568574e1c -r 7860fcc69082 libgui/src/qt-application.cc --- a/libgui/src/qt-application.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/qt-application.cc Mon Jan 30 18:36:03 2023 +0100 @@ -27,6 +27,10 @@ # include "config.h" #endif +#include +#include +#include + #include "main-window.h" #include "octave-qobject.h" #include "qt-application.h" @@ -42,35 +46,60 @@ OCTAVE_BEGIN_NAMESPACE(octave) -qt_application::qt_application (int argc, char **argv) -: application (argc, argv) -{ - // This should probably happen early. - sysdep_init (); -} + 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)); -bool qt_application::start_gui_p (void) const -{ - // Note: this function is not needed if using the experimental - // terminal widget, so return a dummy value of false in that case. + if (! application_name.empty ()) + QCoreApplication::setApplicationName + (QString::fromStdString (application_name)); - return experimental_terminal_widget () ? false : m_options.gui (); -} + 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 (); + } -int qt_application::execute (void) -{ - octave_block_interrupt_signal (); + qt_application::qt_application (int argc, char **argv) + : application (argc, argv) + { + // This should probably happen early. + sysdep_init (); + } - set_application_id (); + 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. - // Create and show main window. + return experimental_terminal_widget () ? false : m_options.gui (); + } - // Note: the second argument is ignored if using the new terminal - // widget. + int qt_application::execute () + { + octave_block_interrupt_signal (); + + set_application_id (); + + // Create and show main window. - base_qobject qt_interface (*this, start_gui_p ()); + // Note: the second argument is ignored if using the new terminal + // widget. - return qt_interface.exec (); -} + base_qobject qt_interface (*this, start_gui_p ()); + + return qt_interface.exec (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/qt-application.h --- a/libgui/src/qt-application.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/qt-application.h Mon Jan 30 18:36:03 2023 +0100 @@ -26,48 +26,55 @@ #if ! defined (octave_qt_application_h) #define octave_qt_application_h 1 +#include + #include "octave.h" OCTAVE_BEGIN_NAMESPACE(octave) -// Programming Note: This file must not include any Qt headers. Any -// Qt header files required by the qt_application::execute function -// must be included only in the corresponding .cc file. + // Programming Note: This file must not include any Qt headers. Any + // Qt header files required by the qt_application::execute function + // must be included only in the corresponding .cc file. -//! This class inherits from the pure-virtual base class -//! application and provides an implementation of the -//! application::execute method that starts an interface to Octave -//! that is based on Qt. It may start a command-line interface that -//! allows Qt graphics to be used or it may start an interface that -//! provides the full GUI experience. + //! This class inherits from the pure-virtual base class + //! application and provides an implementation of the + //! application::execute method that starts an interface to Octave + //! that is based on Qt. It may start a command-line interface that + //! 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 -{ - public: + { + public: - qt_application (int argc, char **argv); + qt_application (const std::string& organization_name, + const std::string& application_name, + const std::string& application_version, + int argc, char **argv); - // No copying, at least not yet. + qt_application (int argc, char **argv); - qt_application (const qt_application&) = delete; + // No copying, at least not yet. - qt_application& operator = (const qt_application&) = delete; + qt_application (const qt_application&) = delete; - ~qt_application (void) = default; + qt_application& operator = (const qt_application&) = delete; - // Should we start the GUI or fall back to the CLI? - bool start_gui_p (void) const; + ~qt_application () = default; - int execute (void); + // Should we start the GUI or fall back to the CLI? + bool start_gui_p () const; + + int execute (); - bool gui_running (void) const { return m_gui_running; } - void gui_running (bool arg) { m_gui_running = arg; } + 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; -}; + // If TRUE, the GUI should be started. + bool m_gui_running = false; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/qt-interpreter-events.cc --- a/libgui/src/qt-interpreter-events.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/qt-interpreter-events.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,6 +39,7 @@ #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" @@ -64,690 +65,690 @@ OCTAVE_BEGIN_NAMESPACE(octave) -static QStringList -make_qstring_list (const std::list& lst) -{ - QStringList retval; + static QStringList + make_qstring_list (const std::list& lst) + { + QStringList retval; - for (const auto& s : lst) - retval.append (QString::fromStdString (s)); + for (const auto& s : lst) + retval.append (QString::fromStdString (s)); - return retval; -} + return retval; + } -static QStringList -make_filter_list (const event_manager::filter_list& lst) -{ - QStringList retval; + static QStringList + make_filter_list (const event_manager::filter_list& lst) + { + QStringList retval; - // We have pairs of data, first being the list of extensions - // exta;exb;extc etc second the name to use as filter name - // (optional). Qt wants a list of filters in the format of - // 'FilterName (space separated exts)'. + // We have pairs of data, first being the list of extensions + // exta;exb;extc etc second the name to use as filter name + // (optional). Qt wants a list of filters in the format of + // 'FilterName (space separated exts)'. - for (const auto& ext_name : lst) - { - QString ext = QString::fromStdString (ext_name.first); - QString name = QString::fromStdString (ext_name.second); + for (const auto& ext_name : lst) + { + QString ext = QString::fromStdString (ext_name.first); + QString name = QString::fromStdString (ext_name.second); - // Strip out extensions from name and replace ';' with spaces in list. + // Strip out extensions from name and replace ';' with spaces in list. - name.replace (QRegExp (R"(\(.*\))"), ""); - ext.replace (";", " "); + name.replace (QRegExp (R"(\(.*\))"), ""); + ext.replace (";", " "); - if (name.isEmpty ()) - { - // No name field. Build one from the extensions. - name = ext.toUpper () + " Files"; - } + if (name.isEmpty ()) + { + // No name field. Build one from the extensions. + name = ext.toUpper () + " Files"; + } - retval.append (name + " (" + ext + ')'); - } + retval.append (name + " (" + ext + ')'); + } - return retval; -} + return retval; + } -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_waitcondition () -{ - qRegisterMetaType ("QIntList"); - qRegisterMetaType ("QFloatList"); + qt_interpreter_events::qt_interpreter_events (base_qobject& oct_qobj) + : interpreter_events (), m_octave_qobj (oct_qobj), + m_uiwidget_creator (), m_result (), m_mutex (), + m_waitcondition () + { + qRegisterMetaType ("QIntList"); + qRegisterMetaType ("QFloatList"); - qRegisterMetaType ("octave_value"); - qRegisterMetaType ("symbol_info_list"); + qRegisterMetaType ("octave_value"); + qRegisterMetaType ("symbol_info_list"); - qRegisterMetaType ("fcn_callback"); - qRegisterMetaType ("meth_callback"); + qRegisterMetaType ("fcn_callback"); + qRegisterMetaType ("meth_callback"); - connect (this, &qt_interpreter_events::confirm_shutdown_signal, - this, &qt_interpreter_events::confirm_shutdown_octave); + connect (this, &qt_interpreter_events::confirm_shutdown_signal, + this, &qt_interpreter_events::confirm_shutdown_octave); - connect (this, &qt_interpreter_events::get_named_icon_signal, - this, &qt_interpreter_events::get_named_icon_slot); + connect (this, &qt_interpreter_events::get_named_icon_signal, + this, &qt_interpreter_events::get_named_icon_slot); - connect (this, &qt_interpreter_events::gui_preference_signal, - this, &qt_interpreter_events::gui_preference_slot); -} + connect (this, &qt_interpreter_events::gui_preference_signal, + this, &qt_interpreter_events::gui_preference_slot); + } -void qt_interpreter_events::start_gui (bool gui_app) -{ - if (m_octave_qobj.experimental_terminal_widget ()) - emit start_gui_signal (gui_app); -} + void qt_interpreter_events::start_gui (bool gui_app) + { + if (m_octave_qobj.experimental_terminal_widget ()) + emit start_gui_signal (gui_app); + } -void qt_interpreter_events::close_gui (void) -{ - if (m_octave_qobj.experimental_terminal_widget ()) - emit close_gui_signal (); -} + void qt_interpreter_events::close_gui () + { + if (m_octave_qobj.experimental_terminal_widget ()) + emit close_gui_signal (); + } -std::list -qt_interpreter_events::file_dialog (const filter_list& filter, - const std::string& title, - const std::string& filename, - const std::string& dirname, - const std::string& multimode) -{ - QStringList lst - = m_uiwidget_creator.file_dialog (make_filter_list (filter), - QString::fromStdString (title), - QString::fromStdString (filename), - QString::fromStdString (dirname), - QString::fromStdString (multimode)); + std::list + qt_interpreter_events::file_dialog (const filter_list& filter, + const std::string& title, + const std::string& filename, + const std::string& dirname, + const std::string& multimode) + { + QStringList lst + = m_uiwidget_creator.file_dialog (make_filter_list (filter), + QString::fromStdString (title), + QString::fromStdString (filename), + QString::fromStdString (dirname), + QString::fromStdString (multimode)); - std::list retval; + std::list retval; - for (const auto& s : lst) - retval.push_back (s.toStdString ()); + for (const auto& s : lst) + retval.push_back (s.toStdString ()); - return retval; -} + return retval; + } -std::list -qt_interpreter_events::input_dialog (const std::list& prompt, - const std::string& title, - const std::list& nr, - const std::list& nc, - const std::list& defaults) -{ - QStringList lst - = m_uiwidget_creator.input_dialog (make_qstring_list (prompt), - QString::fromStdString (title), - std_list_to_qt_list (nr), - std_list_to_qt_list (nc), - make_qstring_list (defaults)); - std::list retval; + std::list + qt_interpreter_events::input_dialog (const std::list& prompt, + const std::string& title, + const std::list& nr, + const std::list& nc, + const std::list& defaults) + { + QStringList lst + = m_uiwidget_creator.input_dialog (make_qstring_list (prompt), + QString::fromStdString (title), + std_list_to_qt_list (nr), + std_list_to_qt_list (nc), + make_qstring_list (defaults)); + std::list retval; - for (const auto& s : lst) - retval.push_back (s.toStdString ()); + for (const auto& s : lst) + retval.push_back (s.toStdString ()); - return retval; -} + return retval; + } -std::pair, int> -qt_interpreter_events::list_dialog (const std::list& list, - const std::string& mode, - int width, int height, - const std::list& initial, - const std::string& name, - const std::list& prompt, - const std::string& ok_string, - const std::string& cancel_string) -{ - QPair result - = m_uiwidget_creator.list_dialog (make_qstring_list (list), - QString::fromStdString (mode), - width, height, - std_list_to_qt_list (initial), - QString::fromStdString (name), - make_qstring_list (prompt), - QString::fromStdString (ok_string), - QString::fromStdString (cancel_string)); + std::pair, int> + qt_interpreter_events::list_dialog (const std::list& list, + const std::string& mode, + int width, int height, + const std::list& initial, + const std::string& name, + const std::list& prompt, + const std::string& ok_string, + const std::string& cancel_string) + { + QPair result + = m_uiwidget_creator.list_dialog (make_qstring_list (list), + QString::fromStdString (mode), + width, height, + std_list_to_qt_list (initial), + QString::fromStdString (name), + make_qstring_list (prompt), + QString::fromStdString (ok_string), + QString::fromStdString (cancel_string)); - QIntList& lst = result.first; - return std::pair, int> (std::list (lst.begin (), - lst.end ()), - result.second); -} + QIntList& lst = result.first; + return std::pair, int> (std::list (lst.begin (), + lst.end ()), + result.second); + } -std::string -qt_interpreter_events::question_dialog (const std::string& msg, - const std::string& title, - const std::string& btn1, - const std::string& btn2, - const std::string& btn3, - const std::string& btndef) -{ - QString icon = "quest"; - QStringList buttons; - QStringList role; + std::string + qt_interpreter_events::question_dialog (const std::string& msg, + const std::string& title, + const std::string& btn1, + const std::string& btn2, + const std::string& btn3, + const std::string& btndef) + { + QString icon = "quest"; + QStringList buttons; + QStringList role; - // Must use ResetRole which is left-aligned for all OS and WM. - role << "ResetRole" << "ResetRole" << "ResetRole"; + // Must use ResetRole which is left-aligned for all OS and WM. + role << "ResetRole" << "ResetRole" << "ResetRole"; - buttons << QString::fromStdString (btn1); - if (btn2 == "") - role.removeAt (0); - else - buttons << QString::fromStdString (btn2); - buttons << QString::fromStdString (btn3); + buttons << QString::fromStdString (btn1); + if (btn2 == "") + role.removeAt (0); + else + buttons << QString::fromStdString (btn2); + buttons << QString::fromStdString (btn3); - QString answer - = m_uiwidget_creator.message_dialog (QString::fromStdString (msg), - QString::fromStdString (title), - icon, buttons, - QString::fromStdString (btndef), - role); + QString answer + = m_uiwidget_creator.message_dialog (QString::fromStdString (msg), + QString::fromStdString (title), + icon, buttons, + QString::fromStdString (btndef), + role); - return answer.toStdString (); -} + return answer.toStdString (); + } -void qt_interpreter_events::update_path_dialog (void) -{ - emit update_path_dialog_signal (); -} + void qt_interpreter_events::update_path_dialog () + { + emit update_path_dialog_signal (); + } -void qt_interpreter_events::show_preferences (void) -{ - emit show_preferences_signal (); -} + void qt_interpreter_events::show_preferences () + { + emit show_preferences_signal (); + } -void qt_interpreter_events::apply_preferences (void) -{ - emit apply_new_settings (); -} + void qt_interpreter_events::apply_preferences () + { + emit apply_new_settings (); + } -void qt_interpreter_events::show_terminal_window (void) -{ - emit show_terminal_window_signal (); -} + void qt_interpreter_events::show_terminal_window () + { + emit show_terminal_window_signal (); + } -bool qt_interpreter_events::show_documentation (const std::string& file) -{ - emit show_documentation_signal (QString::fromStdString (file)); + bool qt_interpreter_events::show_documentation (const std::string& file) + { + emit show_documentation_signal (QString::fromStdString (file)); - return true; -} + return true; + } -void qt_interpreter_events::show_file_browser (void) -{ - emit show_file_browser_signal (); -} + void qt_interpreter_events::show_file_browser () + { + emit show_file_browser_signal (); + } -void qt_interpreter_events::show_command_history (void) -{ - emit show_command_history_signal (); -} + void qt_interpreter_events::show_command_history () + { + emit show_command_history_signal (); + } -void qt_interpreter_events::show_workspace (void) -{ - emit show_workspace_signal (); -} + void qt_interpreter_events::show_workspace () + { + emit show_workspace_signal (); + } -void qt_interpreter_events::show_community_news (int serial) -{ - emit show_community_news_signal (serial); -} + void qt_interpreter_events::show_community_news (int serial) + { + emit show_community_news_signal (serial); + } -void qt_interpreter_events::show_release_notes (void) -{ - emit show_release_notes_signal (); -} + void qt_interpreter_events::show_release_notes () + { + emit show_release_notes_signal (); + } -bool qt_interpreter_events::edit_file (const std::string& file) -{ - emit edit_file_signal (QString::fromStdString (file)); + bool qt_interpreter_events::edit_file (const std::string& file) + { + emit edit_file_signal (QString::fromStdString (file)); - return true; -} + return true; + } -void qt_interpreter_events::edit_variable (const std::string& expr, - const octave_value& val) -{ - emit edit_variable_signal (QString::fromStdString (expr), val); -} + void qt_interpreter_events::edit_variable (const std::string& expr, + const octave_value& val) + { + emit edit_variable_signal (QString::fromStdString (expr), val); + } -bool qt_interpreter_events::confirm_shutdown (void) -{ - QMutexLocker autolock (&m_mutex); + bool qt_interpreter_events::confirm_shutdown () + { + QMutexLocker autolock (&m_mutex); - emit confirm_shutdown_signal (); + emit confirm_shutdown_signal (); - // Wait for result. - wait (); + // Wait for result. + wait (); - return m_result.toBool (); -} + return m_result.toBool (); + } -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 (); + bool qt_interpreter_events::prompt_new_edit_file (const std::string& file) + { + gui_settings settings; + + if (settings.bool_value (ed_create_new_file)) + return true; - if (! settings || settings->value (ed_create_new_file).toBool ()) - return true; - - std::string abs_fname = sys::env::make_absolute (file); + std::string abs_fname = sys::env::make_absolute (file); - QStringList btn; - QStringList role; - role << "YesRole" << "RejectRole"; - btn << tr ("Create") << tr ("Cancel"); + QStringList btn; + QStringList role; + role << "YesRole" << "RejectRole"; + btn << tr ("Create") << tr ("Cancel"); + + QString answer = m_uiwidget_creator.message_dialog + (tr ("File\n%1\ndoes not exist. Do you want to create it?"). + arg (QString::fromStdString (abs_fname)), + tr ("Octave Editor"), "quest", btn, tr ("Create"), role); - QString answer = m_uiwidget_creator.message_dialog - (tr ("File\n%1\ndoes not exist. Do you want to create it?"). - arg (QString::fromStdString (abs_fname)), - tr ("Octave Editor"), "quest", btn, tr ("Create"), role); + return (answer == tr ("Create")); + } - return (answer == tr ("Create")); -} - -// Prompt to allow file to be run by setting cwd (or if -// addpath_option==true, alternatively setting the path). + // Prompt to allow file to be run by setting cwd (or if + // addpath_option==true, alternatively setting the path). -int -qt_interpreter_events::debug_cd_or_addpath_error (const std::string& file, - const std::string& dir, - bool addpath_option) -{ - int retval = -1; + int + qt_interpreter_events::debug_cd_or_addpath_error (const std::string& file, + const std::string& dir, + bool addpath_option) + { + int retval = -1; - QString qdir = QString::fromStdString (dir); - QString qfile = QString::fromStdString (file); - QString msg - = (addpath_option - ? tr ("The file %1 does not exist in the load path. To run or debug the function you are editing, you must either change to the directory %2 or add that directory to the load path.").arg (qfile).arg (qdir) - : tr ("The file %1 is shadowed by a file with the same name in the load path. To run or debug the function you are editing, change to the directory %2.").arg (qfile).arg (qdir)); + QString qdir = QString::fromStdString (dir); + QString qfile = QString::fromStdString (file); + QString msg + = (addpath_option + ? tr ("The file %1 does not exist in the load path. To run or debug the function you are editing, you must either change to the directory %2 or add that directory to the load path.").arg (qfile).arg (qdir) + : tr ("The file %1 is shadowed by a file with the same name in the load path. To run or debug the function you are editing, change to the directory %2.").arg (qfile).arg (qdir)); + + QString title = tr ("Change Directory or Add Directory to Load Path"); - QString title = tr ("Change Directory or Add Directory to Load Path"); - - QString cd_txt = tr ("&Change Directory"); - QString addpath_txt = tr ("&Add Directory to Load Path"); - QString cancel_txt = tr ("Cancel"); + QString cd_txt = tr ("&Change Directory"); + QString addpath_txt = tr ("&Add Directory to Load Path"); + QString cancel_txt = tr ("Cancel"); - QStringList btn; - QStringList role; - btn << cd_txt; - role << "YesRole"; - if (addpath_option) - { - btn << addpath_txt; - role << "AcceptRole"; - } - btn << cancel_txt; - role << "RejectRole"; + QStringList btn; + QStringList role; + btn << cd_txt; + role << "YesRole"; + if (addpath_option) + { + btn << addpath_txt; + role << "AcceptRole"; + } + btn << cancel_txt; + role << "RejectRole"; - QString result - = m_uiwidget_creator.message_dialog (msg, title, "quest", btn, - cancel_txt, role); + QString result + = m_uiwidget_creator.message_dialog (msg, title, "quest", btn, + cancel_txt, role); - if (result == cd_txt) - retval = 1; - else if (result == addpath_txt) - retval = 2; + if (result == cd_txt) + retval = 1; + else if (result == addpath_txt) + retval = 2; - return retval; -} + return retval; + } -uint8NDArray qt_interpreter_events::get_named_icon (const std::string& name) -{ - QMutexLocker autolock (&m_mutex); + uint8NDArray qt_interpreter_events::get_named_icon (const std::string& name) + { + QMutexLocker autolock (&m_mutex); - emit get_named_icon_signal (QString::fromStdString (name)); + emit get_named_icon_signal (QString::fromStdString (name)); - // Wait for result. - wait (); + // Wait for result. + wait (); - uint8NDArray empty_img; + uint8NDArray empty_img; - QIcon icon = m_result.value (); + QIcon icon = m_result.value (); - if (icon.isNull ()) - return empty_img; + if (icon.isNull ()) + return empty_img; - QImage img = icon.pixmap (QSize (32, 32)).toImage (); + QImage img = icon.pixmap (QSize (32, 32)).toImage (); - if (img.format () != QImage::Format_ARGB32_Premultiplied) - return empty_img; + if (img.format () != QImage::Format_ARGB32_Premultiplied) + return empty_img; - dim_vector dims (img.height (), img.width (), 4); + dim_vector dims (img.height (), img.width (), 4); - uint8NDArray retval (dims, 0); + uint8NDArray retval (dims, 0); - uint8_t *bits = img.bits (); + uint8_t *bits = img.bits (); - for (int i = 0; i < img.height (); i++) - { - for (int j = 0; j < img.width (); j++) - { - retval(i, j, 2) = bits[0]; - retval(i, j, 1) = bits[1]; - retval(i, j, 0) = bits[2]; - retval(i, j, 3) = bits[3]; + for (int i = 0; i < img.height (); i++) + { + for (int j = 0; j < img.width (); j++) + { + retval(i, j, 2) = bits[0]; + retval(i, j, 1) = bits[1]; + retval(i, j, 0) = bits[2]; + retval(i, j, 3) = bits[3]; - bits += 4; - } - } + bits += 4; + } + } - return retval; -} + return retval; + } + + void qt_interpreter_events::get_named_icon_slot (const QString& name) + { + QMutexLocker autolock (&m_mutex); -void qt_interpreter_events::get_named_icon_slot (const QString& name) -{ - QMutexLocker autolock (&m_mutex); + gui_settings settings; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - m_result = QVariant::fromValue (rmgr.icon (name)); + m_result = QVariant::fromValue (settings.icon (name)); - wake_all (); -} + wake_all (); + } -std::string -qt_interpreter_events::gui_preference (const std::string& key, - const std::string& value) -{ - QString pref_value; + std::string + qt_interpreter_events::gui_preference (const std::string& key, + const std::string& value) + { + QString pref_value; - QMutexLocker autolock (&m_mutex); + QMutexLocker autolock (&m_mutex); - // Emit the signal for changing or getting a preference - emit gui_preference_signal (QString::fromStdString (key), - QString::fromStdString (value)); + // Emit the signal for changing or getting a preference + emit gui_preference_signal (QString::fromStdString (key), + QString::fromStdString (value)); - // Wait for response (pref_value). - wait (); + // Wait for response (pref_value). + wait (); - QString pref = m_result.toString (); + QString pref = m_result.toString (); - return pref.toStdString (); -} + return pref.toStdString (); + } -bool qt_interpreter_events::copy_image_to_clipboard (const std::string& file) -{ - emit copy_image_to_clipboard_signal (QString::fromStdString (file), true); + bool qt_interpreter_events::copy_image_to_clipboard (const std::string& file) + { + emit copy_image_to_clipboard_signal (QString::fromStdString (file), true); - return true; -} + return true; + } -void qt_interpreter_events::focus_window (const std::string win_name) -{ - emit focus_window_signal (QString::fromStdString (win_name)); -} + void qt_interpreter_events::focus_window (const std::string win_name) + { + emit focus_window_signal (QString::fromStdString (win_name)); + } -void qt_interpreter_events::execute_command_in_terminal -(const std::string& command) -{ - emit execute_command_in_terminal_signal (QString::fromStdString (command)); -} + void qt_interpreter_events::execute_command_in_terminal + (const std::string& command) + { + emit execute_command_in_terminal_signal (QString::fromStdString (command)); + } -void qt_interpreter_events::register_documentation (const std::string& file) -{ - emit register_documentation_signal (QString::fromStdString (file)); -} + void qt_interpreter_events::register_documentation (const std::string& file) + { + emit register_documentation_signal (QString::fromStdString (file)); + } -void qt_interpreter_events::unregister_documentation (const std::string& file) -{ - emit unregister_documentation_signal (QString::fromStdString (file)); -} + void qt_interpreter_events::unregister_documentation (const std::string& file) + { + emit unregister_documentation_signal (QString::fromStdString (file)); + } -void qt_interpreter_events::interpreter_output (const std::string& msg) -{ - if (m_octave_qobj.experimental_terminal_widget () - && m_octave_qobj.have_terminal_window ()) - emit interpreter_output_signal (QString::fromStdString (msg)); - else - { - // FIXME: is this the correct thing to do? - std::cout << msg; - } -} + void qt_interpreter_events::interpreter_output (const std::string& msg) + { + if (m_octave_qobj.experimental_terminal_widget () + && m_octave_qobj.have_terminal_window ()) + emit interpreter_output_signal (QString::fromStdString (msg)); + else + { + // FIXME: is this the correct thing to do? + std::cout << msg; + } + } -void qt_interpreter_events::display_exception (const execution_exception& ee, - bool beep) -{ - if (m_octave_qobj.experimental_terminal_widget () - && m_octave_qobj.have_terminal_window ()) - { - // Output the exception message - std::ostringstream buf; - ee.display (buf); - emit interpreter_output_signal (QString::fromStdString (buf.str ())); - // Create w new command line - emit new_command_line_signal (); - } - else - { - if (beep) - std::cerr << "\a"; + void qt_interpreter_events::display_exception (const execution_exception& ee, + bool beep) + { + if (m_octave_qobj.experimental_terminal_widget () + && m_octave_qobj.have_terminal_window ()) + { + // Output the exception message + std::ostringstream buf; + ee.display (buf); + emit interpreter_output_signal (QString::fromStdString (buf.str ())); + // Create w new command line + emit new_command_line_signal (); + } + else + { + if (beep) + std::cerr << "\a"; - ee.display (std::cerr); - } -} + ee.display (std::cerr); + } + } -void qt_interpreter_events::gui_status_update (const std::string& feature, - const std::string& status) -{ - emit gui_status_update_signal (QString::fromStdString (feature), - QString::fromStdString (status)); -} + void qt_interpreter_events::gui_status_update (const std::string& feature, + const std::string& status) + { + emit gui_status_update_signal (QString::fromStdString (feature), + QString::fromStdString (status)); + } -void qt_interpreter_events::update_gui_lexer (void) -{ - emit update_gui_lexer_signal (true); -} + void qt_interpreter_events::update_gui_lexer () + { + emit update_gui_lexer_signal (true); + } -void qt_interpreter_events::directory_changed (const std::string& dir) -{ - emit directory_changed_signal (QString::fromStdString (dir)); -} + void qt_interpreter_events::directory_changed (const std::string& dir) + { + emit directory_changed_signal (QString::fromStdString (dir)); + } -void qt_interpreter_events::file_remove (const std::string& old_name, - const std::string& new_name) -{ - QMutexLocker autolock (&m_mutex); + void qt_interpreter_events::file_remove (const std::string& old_name, + const std::string& new_name) + { + QMutexLocker autolock (&m_mutex); - // Emit the signal for the editor for closing the file if it is open - emit file_remove_signal (QString::fromStdString (old_name), - QString::fromStdString (new_name)); + // Emit the signal for the editor for closing the file if it is open + emit file_remove_signal (QString::fromStdString (old_name), + QString::fromStdString (new_name)); - // Wait for file removal to complete before continuing. - wait (); -} + // Wait for file removal to complete before continuing. + wait (); + } -void qt_interpreter_events::file_renamed (bool load_new) -{ - emit file_renamed_signal (load_new); -} + void qt_interpreter_events::file_renamed (bool load_new) + { + emit file_renamed_signal (load_new); + } -void qt_interpreter_events::set_workspace (bool top_level, bool debug, - const symbol_info_list& syminfo, - bool update_variable_editor) -{ - if (! top_level && ! debug) - return; + void qt_interpreter_events::set_workspace (bool top_level, bool debug, + const symbol_info_list& syminfo, + bool update_variable_editor) + { + if (! top_level && ! debug) + return; - emit set_workspace_signal (top_level, debug, syminfo); + emit set_workspace_signal (top_level, debug, syminfo); - if (update_variable_editor) - emit refresh_variable_editor_signal (); -} + if (update_variable_editor) + emit refresh_variable_editor_signal (); + } -void qt_interpreter_events::clear_workspace (void) -{ - emit clear_workspace_signal (); -} + void qt_interpreter_events::clear_workspace () + { + emit clear_workspace_signal (); + } + + void qt_interpreter_events::update_prompt (const std::string& prompt) + { + emit update_prompt_signal (QString::fromStdString (prompt)); + } + + void qt_interpreter_events::set_history (const string_vector& hist) + { + QStringList qt_hist; + + for (octave_idx_type i = 0; i < hist.numel (); i++) + qt_hist.append (QString::fromStdString (hist[i])); -void qt_interpreter_events::update_prompt (const std::string& prompt) -{ - emit update_prompt_signal (QString::fromStdString (prompt)); -} + emit set_history_signal (qt_hist); + } + + void qt_interpreter_events::append_history (const std::string& hist_entry) + { + emit append_history_signal (QString::fromStdString (hist_entry)); + } -void qt_interpreter_events::set_history (const string_vector& hist) -{ - QStringList qt_hist; + void qt_interpreter_events::clear_history () + { + emit clear_history_signal (); + } - for (octave_idx_type i = 0; i < hist.numel (); i++) - qt_hist.append (QString::fromStdString (hist[i])); + void qt_interpreter_events::pre_input_event () + { } + + void qt_interpreter_events::post_input_event () + { } - emit set_history_signal (qt_hist); -} + void qt_interpreter_events::enter_debugger_event (const std::string& /*fcn_name*/, + const std::string& fcn_file_name, + int line) + { + if (fcn_file_name.empty ()) + return; + + insert_debugger_pointer (fcn_file_name, line); -void qt_interpreter_events::append_history (const std::string& hist_entry) -{ - emit append_history_signal (QString::fromStdString (hist_entry)); -} + emit enter_debugger_signal (); + } + + void + qt_interpreter_events::execute_in_debugger_event (const std::string& file, + int line) + { + delete_debugger_pointer (file, line); + } -void qt_interpreter_events::clear_history (void) -{ - emit clear_history_signal (); -} + void qt_interpreter_events::exit_debugger_event () + { + emit exit_debugger_signal (); + } -void qt_interpreter_events::pre_input_event (void) -{ } + // Display (if @insert true) or remove the appropriate symbol for a breakpoint + // in @file at @line with condition @cond. + void qt_interpreter_events::update_breakpoint (bool insert, + const std::string& file, + int line, + const std::string& cond) + { + emit update_breakpoint_marker_signal (insert, QString::fromStdString (file), + line, QString::fromStdString (cond)); + } -void qt_interpreter_events::post_input_event (void) -{ } - -void qt_interpreter_events::enter_debugger_event (const std::string& /*fcn_name*/, - const std::string& fcn_file_name, + void + qt_interpreter_events::insert_debugger_pointer (const std::string& file, int line) -{ - if (fcn_file_name.empty ()) - return; - - insert_debugger_pointer (fcn_file_name, line); - - emit enter_debugger_signal (); -} - -void -qt_interpreter_events::execute_in_debugger_event (const std::string& file, - int line) -{ - delete_debugger_pointer (file, line); -} - -void qt_interpreter_events::exit_debugger_event (void) -{ - emit exit_debugger_signal (); -} + { + emit insert_debugger_pointer_signal (QString::fromStdString (file), line); + } -// Display (if @insert true) or remove the appropriate symbol for a breakpoint -// in @file at @line with condition @cond. -void qt_interpreter_events::update_breakpoint (bool insert, - const std::string& file, - int line, - const std::string& cond) -{ - emit update_breakpoint_marker_signal (insert, QString::fromStdString (file), - line, QString::fromStdString (cond)); -} - -void -qt_interpreter_events::insert_debugger_pointer (const std::string& file, - int line) -{ - emit insert_debugger_pointer_signal (QString::fromStdString (file), line); -} - -void -qt_interpreter_events::delete_debugger_pointer (const std::string& file, - int line) -{ - emit delete_debugger_pointer_signal (QString::fromStdString (file), line); -} + void + qt_interpreter_events::delete_debugger_pointer (const std::string& file, + int line) + { + emit delete_debugger_pointer_signal (QString::fromStdString (file), line); + } -void -qt_interpreter_events::confirm_shutdown_octave (void) -{ - QMutexLocker autolock (&m_mutex); + void + qt_interpreter_events::confirm_shutdown_octave () + { + QMutexLocker autolock (&m_mutex); - m_result = m_octave_qobj.confirm_shutdown (); + m_result = m_octave_qobj.confirm_shutdown (); - wake_all (); -} + wake_all (); + } -// If VALUE is empty, return current value of preference named by KEY. -// -// If VALUE is not empty, set preference named by KEY to VALUE return -// previous value. -// -// FIXME: should we have separate get and set functions? With only -// one, we don't allow a preference value to be set to the empty -// string. + // If VALUE is empty, return current value of preference named by KEY. + // + // If VALUE is not empty, set preference named by KEY to VALUE return + // previous value. + // + // FIXME: should we have separate get and set functions? With only + // one, we don't allow a preference value to be set to the empty + // string. -void -qt_interpreter_events::gui_preference_slot (const QString& key, - const QString& value) -{ - QMutexLocker autolock (&m_mutex); + void + qt_interpreter_events::gui_preference_slot (const QString& key, + const QString& value) + { + 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); + // Some preferences need extra handling + QString adjusted_value = gui_preference_adjust (key, value); - if (! adjusted_value.isEmpty () && (read_value != adjusted_value)) - { - // Change settings only for new, non-empty values - settings->setValue (key, QVariant (adjusted_value)); + if (! adjusted_value.isEmpty () && (read_value != adjusted_value)) + { + // Change settings only for new, non-empty values + 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; + m_result = read_value; - wake_all (); -} + wake_all (); + } -QString -qt_interpreter_events::gui_preference_adjust (const QString& key, - const QString& value) -{ - // Immediately return if no new value is given. + QString + qt_interpreter_events::gui_preference_adjust (const QString& key, + const QString& value) + { + // Immediately return if no new value is given. - if (value.isEmpty ()) - return value; + if (value.isEmpty ()) + return value; - QString adjusted_value = value; + QString adjusted_value = value; - // Not all encodings are available. Encodings are uppercase and do - // not use CPxxx but IBMxxx or WINDOWS-xxx. + // Not all encodings are available. Encodings are uppercase and do + // not use CPxxx but IBMxxx or WINDOWS-xxx. - if (key == ed_default_enc.key) - { - adjusted_value = adjusted_value.toUpper (); + 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); + gui_settings settings; + QStringList codecs; + settings.get_codecs (&codecs); - QRegExp re ("^CP(\\d+)$"); + 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 (); - } + 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; -} + return adjusted_value; + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/qt-interpreter-events.h --- a/libgui/src/qt-interpreter-events.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/qt-interpreter-events.h Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,6 @@ #include #include "dialog.h" -#include "gui-settings.h" #include "event-manager.h" @@ -47,284 +46,284 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class base_qobject; -// The functions in this class are not normally called directly, but -// are invoked from the Octave interpreter thead by methods in the -// event_manager class. In most cases, they should only translate -// data from the types typically used in the interpreter to whatever -// is required by the GUI (for example, std::string to QString) and -// emit a Qt signal. -// -// The use of Qt signals provides a thread-safe way for the Octave -// interpreter to notify the GUI of events (directory or workspace has -// changed, for example) or to request that the GUI perform actions -// (display a dialog, for example). -// -// By using this class as a wrapper around the Qt signals, we maintain -// a separation between the Octave interpreter and any specific GUI -// toolkit (no Qt headers are used in the Octave interpreter sources). + // The functions in this class are not normally called directly, but + // are invoked from the Octave interpreter thead by methods in the + // event_manager class. In most cases, they should only translate + // data from the types typically used in the interpreter to whatever + // is required by the GUI (for example, std::string to QString) and + // emit a Qt signal. + // + // The use of Qt signals provides a thread-safe way for the Octave + // interpreter to notify the GUI of events (directory or workspace has + // changed, for example) or to request that the GUI perform actions + // (display a dialog, for example). + // + // By using this class as a wrapper around the Qt signals, we maintain + // a separation between the Octave interpreter and any specific GUI + // toolkit (no Qt headers are used in the Octave interpreter sources). -class qt_interpreter_events : public QObject, public interpreter_events -{ - Q_OBJECT + class qt_interpreter_events : public QObject, public interpreter_events + { + Q_OBJECT -public: + public: - qt_interpreter_events (base_qobject& oct_qobj); + qt_interpreter_events (base_qobject& oct_qobj); - // No copying! + // No copying! - qt_interpreter_events (const qt_interpreter_events&) = delete; + qt_interpreter_events (const qt_interpreter_events&) = delete; - qt_interpreter_events& operator = (const qt_interpreter_events&) = delete; + 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); + // Note: these functions currently do nothing with the old terminal + // widget. + void start_gui (bool gui_app = false); + 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, - const std::string& filename, const std::string& pathname, - const std::string& multimode); + std::list + file_dialog (const filter_list& filter, const std::string& title, + const std::string& filename, const std::string& pathname, + const std::string& multimode); - std::list - input_dialog (const std::list& prompt, - const std::string& title, const std::list& nr, - const std::list& nc, - const std::list& defaults); + std::list + input_dialog (const std::list& prompt, + const std::string& title, const std::list& nr, + const std::list& nc, + const std::list& defaults); - std::pair, int> - list_dialog (const std::list& list, - const std::string& mode, int width, int height, - const std::list& initial_value, - const std::string& name, - const std::list& prompt, - const std::string& ok_string, - const std::string& cancel_string); + std::pair, int> + list_dialog (const std::list& list, + const std::string& mode, int width, int height, + const std::list& initial_value, + const std::string& name, + const std::list& prompt, + const std::string& ok_string, + const std::string& cancel_string); - std::string - question_dialog (const std::string& msg, const std::string& title, - const std::string& btn1, const std::string& btn2, - const std::string& btn3, const std::string& btndef); + std::string + question_dialog (const std::string& msg, const std::string& title, + 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); + 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_community_news (int serial); + void show_release_notes (); - bool edit_file (const std::string& file); + bool edit_file (const std::string& file); - void edit_variable (const std::string& name, const octave_value& val); + 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); + bool prompt_new_edit_file (const std::string& file); - int debug_cd_or_addpath_error (const std::string& file, - const std::string& dir, - bool addpath_option); + int debug_cd_or_addpath_error (const std::string& file, + const std::string& dir, + bool addpath_option); - uint8NDArray get_named_icon (const std::string& icon_name); + uint8NDArray get_named_icon (const std::string& icon_name); - std::string gui_preference (const std::string& key, - const std::string& value); + std::string gui_preference (const std::string& key, + const std::string& value); - bool copy_image_to_clipboard (const std::string& file); + bool copy_image_to_clipboard (const std::string& file); - void focus_window (const std::string win_name); + void focus_window (const std::string win_name); - void execute_command_in_terminal (const std::string& command); + void execute_command_in_terminal (const std::string& command); - void register_documentation (const std::string& file); + void register_documentation (const std::string& file); - void unregister_documentation (const std::string& file); + void unregister_documentation (const std::string& file); - // Note: this function currently does nothing with the old terminal - // widget. - void interpreter_output (const std::string& msg); + // Note: this function currently does nothing with the old terminal + // widget. + void interpreter_output (const std::string& msg); - void display_exception (const execution_exception& ee, bool beep); + void display_exception (const execution_exception& ee, bool beep); - void gui_status_update (const std::string& feature, const std::string& status); + 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); + void directory_changed (const std::string& dir); - void file_remove (const std::string& old_name, - const std::string& new_name); + void file_remove (const std::string& old_name, + const std::string& new_name); - void file_renamed (bool load_new = true); + void file_renamed (bool load_new = true); - void set_workspace (bool top_level, bool debug, - const symbol_info_list& syminfo, - bool update_variable_editor); + void set_workspace (bool top_level, bool debug, + const symbol_info_list& syminfo, + bool update_variable_editor); - void clear_workspace (void); + void clear_workspace (); - void update_prompt (const std::string& prompt); + void update_prompt (const std::string& prompt); - void set_history (const string_vector& hist); + void set_history (const string_vector& hist); - void append_history (const std::string& hist_entry); + 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 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 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 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: + public slots: - void confirm_shutdown_octave (void); + void confirm_shutdown_octave (); - void get_named_icon_slot (const QString& name); + void get_named_icon_slot (const QString& name); - void gui_preference_slot (const QString& key, const QString& value); + void gui_preference_slot (const QString& key, const QString& value); -signals: + signals: - // Note: these signals are not currently used by the old terminal widget. - void start_gui_signal (bool gui_app); - void close_gui_signal (void); + // Note: these signals are not currently used by the old terminal widget. + void start_gui_signal (bool gui_app); + void close_gui_signal (); - void copy_image_to_clipboard_signal (const QString& file, bool remove_file); + void copy_image_to_clipboard_signal (const QString& file, bool remove_file); - void focus_window_signal (const QString& win_name); + void focus_window_signal (const QString& win_name); - void edit_file_signal (const QString& file); + void edit_file_signal (const QString& file); - void directory_changed_signal (const QString& dir); + 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); + void file_remove_signal (const QString& old_name, const QString& new_name); - void file_renamed_signal (bool load_new); + void file_renamed_signal (bool load_new); - void execute_command_in_terminal_signal (const QString& command); + void execute_command_in_terminal_signal (const QString& command); - void set_workspace_signal (bool top_level, bool debug, - const symbol_info_list& syminfo); + 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); + void update_prompt_signal (const QString& prompt); - void set_history_signal (const QStringList& hist); + void set_history_signal (const QStringList& hist); - void append_history_signal (const QString& hist_entry); + 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); + void update_breakpoint_marker_signal (bool insert, const QString& file, + int line, const QString& cond); - void insert_debugger_pointer_signal (const QString&, int); + void insert_debugger_pointer_signal (const QString&, int); - void delete_debugger_pointer_signal (const QString&, int); + 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 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); + void show_documentation_signal (const QString& file); - void register_documentation_signal (const QString& file); + void register_documentation_signal (const QString& file); - void unregister_documentation_signal (const QString& file); + 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_community_news_signal (int serial); + 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); - void new_command_line_signal (const QString& msg = QString ()); + // Note: the next two signals are currently not used by the old terminal widget. + void interpreter_output_signal (const QString& msg); + void new_command_line_signal (const QString& msg = QString ()); - void gui_status_update_signal (const QString& feature, const QString& status); + void gui_status_update_signal (const QString& feature, const QString& status); - void update_gui_lexer_signal (bool update_apis_only); + void update_gui_lexer_signal (bool update_apis_only); - void edit_variable_signal (const QString& name, const octave_value& val); + 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 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: + private: - QString gui_preference_adjust (const QString& key, const QString& value); + QString gui_preference_adjust (const QString& key, const QString& value); - void insert_debugger_pointer (const std::string& file, int line); + void insert_debugger_pointer (const std::string& file, int line); - void delete_debugger_pointer (const std::string& file, int line); + void delete_debugger_pointer (const std::string& file, int line); - base_qobject& m_octave_qobj; + base_qobject& m_octave_qobj; - QUIWidgetCreator m_uiwidget_creator; + QUIWidgetCreator m_uiwidget_creator; - QVariant m_result; + QVariant m_result; - QMutex m_mutex; + QMutex m_mutex; - QWaitCondition m_waitcondition; -}; + QWaitCondition m_waitcondition; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/release-notes.cc --- a/libgui/src/release-notes.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/release-notes.cc Mon Jan 30 18:36:03 2023 +0100 @@ -40,83 +40,83 @@ #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.string_value (dw_icon_set); - // The icon - QString icon_set = settings->value (dw_icon_set).toString (); - if (icon_set != "NONE") - m_release_notes_icon = dw_icon_set_names[icon_set] - + "ReleaseWidget.png"; - else - m_release_notes_icon = dw_icon_set_names[icon_set]; + if (icon_set != "NONE") + m_release_notes_icon = dw_icon_set_names[icon_set] + + "ReleaseWidget.png"; + else + m_release_notes_icon = dw_icon_set_names[icon_set]; - std::string news_file = config::oct_etc_dir () + "/NEWS"; + std::string news_file = config::oct_etc_dir () + "/NEWS"; - QString news; + QString news; - QFile *file = new QFile (QString::fromStdString (news_file)); - if (file->open (QFile::ReadOnly)) - { - QTextStream *stream = new QTextStream (file); - news = stream->readAll (); - if (! news.isEmpty ()) - { - // Convert '<', '>' which would be interpreted as HTML - news.replace ("<", "<"); - news.replace (">", ">"); - // Add HTML tags for pre-formatted text - news.prepend ("
");
-          news.append ("
"); - } - else - news = (tr ("The release notes file '%1' is empty.") - . arg (QString::fromStdString (news_file))); - } - else - news = (tr ("The release notes file '%1' cannot be read.") - . arg (QString::fromStdString (news_file))); + QFile *file = new QFile (QString::fromStdString (news_file)); + if (file->open (QFile::ReadOnly)) + { + QTextStream *stream = new QTextStream (file); + news = stream->readAll (); + if (! news.isEmpty ()) + { + // Convert '<', '>' which would be interpreted as HTML + news.replace ("<", "<"); + news.replace (">", ">"); + // Add HTML tags for pre-formatted text + news.prepend ("
");
+            news.append ("
"); + } + else + news = (tr ("The release notes file '%1' is empty.") + . arg (QString::fromStdString (news_file))); + } + else + news = (tr ("The release notes file '%1' cannot be read.") + . arg (QString::fromStdString (news_file))); - m_browser = new QTextBrowser (this); - m_browser->setText (news); + m_browser = new QTextBrowser (this); + m_browser->setText (news); - QVBoxLayout *vlayout = new QVBoxLayout; - vlayout->addWidget (m_browser); + QVBoxLayout *vlayout = new QVBoxLayout; + vlayout->addWidget (m_browser); - setLayout (vlayout); - setWindowTitle (tr ("Octave Release Notes")); + setLayout (vlayout); + setWindowTitle (tr ("Octave Release Notes")); - m_browser->document ()->adjustSize (); + m_browser->document ()->adjustSize (); - int win_x, win_y; - get_screen_geometry (win_x, win_y); + int win_x, win_y; + get_screen_geometry (win_x, win_y); - resize (win_x*2/5, win_y*2/3); - move (20, 20); // move to the top left corner -} + resize (win_x*2/5, win_y*2/3); + move (20, 20); // move to the top left corner + } -void release_notes::display (void) -{ - if (! isVisible ()) - show (); - else if (isMinimized ()) - showNormal (); + void release_notes::display () + { + if (! isVisible ()) + show (); + else if (isMinimized ()) + showNormal (); - setWindowIcon (QIcon (m_release_notes_icon)); + setWindowIcon (QIcon (m_release_notes_icon)); - raise (); - activateWindow (); -} + raise (); + activateWindow (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/release-notes.h --- a/libgui/src/release-notes.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/release-notes.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,27 +33,25 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class release_notes : public QWidget + { + Q_OBJECT -class release_notes : public QWidget -{ - Q_OBJECT + public: -public: + release_notes (); - release_notes (base_qobject& qct_qobj); + ~release_notes () = default; - ~release_notes (void) = default; + public slots: -public slots: - - void display (void); + void display (); -private: + private: - QTextBrowser *m_browser; - QString m_release_notes_icon; -}; + QTextBrowser *m_browser; + QString m_release_notes_icon; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/resource-manager.cc --- a/libgui/src/resource-manager.cc Mon Jan 30 18:30:33 2023 +0100 +++ /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 17d568574e1c -r 7860fcc69082 libgui/src/resource-manager.h --- a/libgui/src/resource-manager.h Mon Jan 30 18:30:33 2023 +0100 +++ /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 17d568574e1c -r 7860fcc69082 libgui/src/set-path-dialog.cc --- a/libgui/src/set-path-dialog.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/set-path-dialog.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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,256 +58,255 @@ OCTAVE_BEGIN_NAMESPACE(octave) -set_path_dialog::set_path_dialog (QWidget *parent, base_qobject& oct_qobj) -: QDialog (parent), m_octave_qobj (oct_qobj) -{ - setWindowTitle (tr ("Set Path")); + set_path_dialog::set_path_dialog (QWidget *parent) + : QDialog (parent) + { + setWindowTitle (tr ("Set Path")); - set_path_model *model = new set_path_model (this); + set_path_model *model = new set_path_model (this); - m_info_label = new QLabel (tr ("All changes take effect immediately.")); + m_info_label = new QLabel (tr ("All changes take effect immediately.")); - m_add_folder_button = new QPushButton (tr ("Add Folder...")); + m_add_folder_button = new QPushButton (tr ("Add Folder...")); - QMenu *add_dir_menu = new QMenu (); - m_add_folder_button->setMenu (add_dir_menu); - add_dir_menu->addAction (tr ("Single Folder"), - this, &set_path_dialog::add_dir); - add_dir_menu->addAction (tr ("Folder With Subfolders"), - this, &set_path_dialog::add_dir_subdirs); + QMenu *add_dir_menu = new QMenu (); + m_add_folder_button->setMenu (add_dir_menu); + add_dir_menu->addAction (tr ("Single Folder"), + this, &set_path_dialog::add_dir); + add_dir_menu->addAction (tr ("Folder With Subfolders"), + this, &set_path_dialog::add_dir_subdirs); - m_move_to_top_button = new QPushButton (tr ("Move to Top")); - m_move_to_bottom_button = new QPushButton (tr ("Move to Bottom")); - m_move_up_button = new QPushButton (tr ("Move Up")); - m_move_down_button = new QPushButton (tr ("Move Down")); - m_remove_button = new QPushButton (tr ("Remove")); + m_move_to_top_button = new QPushButton (tr ("Move to Top")); + m_move_to_bottom_button = new QPushButton (tr ("Move to Bottom")); + m_move_up_button = new QPushButton (tr ("Move Up")); + m_move_down_button = new QPushButton (tr ("Move Down")); + m_remove_button = new QPushButton (tr ("Remove")); - m_reload_button = new QPushButton (tr ("Reload")); - m_save_button = new QPushButton (tr ("Save")); + m_reload_button = new QPushButton (tr ("Reload")); + m_save_button = new QPushButton (tr ("Save")); - m_revert_button = new QPushButton (tr ("Revert")); + m_revert_button = new QPushButton (tr ("Revert")); - QMenu *revert_menu = new QMenu (); - m_revert_button->setMenu (revert_menu); - revert_menu->addAction (tr ("Revert Last Change"), - model, &set_path_model::revert_last); - revert_menu->addAction (tr ("Revert All Changes"), - model, &set_path_model::revert); + QMenu *revert_menu = new QMenu (); + m_revert_button->setMenu (revert_menu); + revert_menu->addAction (tr ("Revert Last Change"), + model, &set_path_model::revert_last); + revert_menu->addAction (tr ("Revert All Changes"), + model, &set_path_model::revert); - m_save_button->setFocus (); + m_save_button->setFocus (); - connect (m_remove_button, &QPushButton::clicked, - this, &set_path_dialog::rm_dir); + connect (m_remove_button, &QPushButton::clicked, + this, &set_path_dialog::rm_dir); - connect (m_move_to_top_button, &QPushButton::clicked, - this, &set_path_dialog::move_dir_top); + connect (m_move_to_top_button, &QPushButton::clicked, + this, &set_path_dialog::move_dir_top); - connect (m_move_to_bottom_button, &QPushButton::clicked, - this, &set_path_dialog::move_dir_bottom); + connect (m_move_to_bottom_button, &QPushButton::clicked, + this, &set_path_dialog::move_dir_bottom); - connect (m_move_up_button, &QPushButton::clicked, - this, &set_path_dialog::move_dir_up); + connect (m_move_up_button, &QPushButton::clicked, + this, &set_path_dialog::move_dir_up); - connect (m_move_down_button, &QPushButton::clicked, - this, &set_path_dialog::move_dir_down); + connect (m_move_down_button, &QPushButton::clicked, + this, &set_path_dialog::move_dir_down); - connect (m_reload_button, &QPushButton::clicked, - model, &set_path_model::path_to_model); + connect (m_reload_button, &QPushButton::clicked, + model, &set_path_model::path_to_model); - connect (m_save_button, &QPushButton::clicked, - model, &set_path_model::save); + connect (m_save_button, &QPushButton::clicked, + model, &set_path_model::save); - // Any interpreter_event signal from a set_path_model object is - // handled the same as for the parent set_path_dialog object. + // Any interpreter_event signal from a set_path_model object is + // handled the same as for the parent set_path_dialog object. - connect (model, QOverload::of (&set_path_model::interpreter_event), - this, QOverload::of (&set_path_dialog::interpreter_event)); + connect (model, QOverload::of (&set_path_model::interpreter_event), + this, QOverload::of (&set_path_dialog::interpreter_event)); - connect (model, QOverload::of (&set_path_model::interpreter_event), - this, QOverload::of (&set_path_dialog::interpreter_event)); + connect (model, QOverload::of (&set_path_model::interpreter_event), + this, QOverload::of (&set_path_dialog::interpreter_event)); - m_path_list = new QListView (this); - m_path_list->setWordWrap (false); - m_path_list->setModel (model); - m_path_list->setSelectionBehavior (QAbstractItemView::SelectRows); - m_path_list->setSelectionMode (QAbstractItemView::ExtendedSelection); - m_path_list->setAlternatingRowColors (true); - m_path_list->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_path_list = new QListView (this); + m_path_list->setWordWrap (false); + m_path_list->setModel (model); + m_path_list->setSelectionBehavior (QAbstractItemView::SelectRows); + m_path_list->setSelectionMode (QAbstractItemView::ExtendedSelection); + m_path_list->setAlternatingRowColors (true); + m_path_list->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - // layout everything - QDialogButtonBox *button_box = new QDialogButtonBox (Qt::Horizontal); - button_box->addButton (m_save_button, QDialogButtonBox::ActionRole); - button_box->addButton (m_reload_button, QDialogButtonBox::ActionRole); + // layout everything + QDialogButtonBox *button_box = new QDialogButtonBox (Qt::Horizontal); + button_box->addButton (m_save_button, QDialogButtonBox::ActionRole); + button_box->addButton (m_reload_button, QDialogButtonBox::ActionRole); - // add dialog close button - m_close_button = button_box->addButton (QDialogButtonBox::Close); - connect (button_box, &QDialogButtonBox::rejected, - this, &set_path_dialog::close); + // add dialog close button + m_close_button = button_box->addButton (QDialogButtonBox::Close); + connect (button_box, &QDialogButtonBox::rejected, + this, &set_path_dialog::close); - button_box->addButton (m_revert_button, QDialogButtonBox::ActionRole); + button_box->addButton (m_revert_button, QDialogButtonBox::ActionRole); - // path edit options - QDialogButtonBox *path_edit_layout = new QDialogButtonBox (Qt::Vertical); - path_edit_layout->addButton (m_add_folder_button, QDialogButtonBox::ActionRole); - path_edit_layout->addButton (m_move_to_top_button, QDialogButtonBox::ActionRole); - path_edit_layout->addButton (m_move_up_button, QDialogButtonBox::ActionRole); - path_edit_layout->addButton (m_move_down_button, QDialogButtonBox::ActionRole); - path_edit_layout->addButton (m_move_to_bottom_button, QDialogButtonBox::ActionRole); - path_edit_layout->addButton (m_remove_button, QDialogButtonBox::ActionRole); + // path edit options + QDialogButtonBox *path_edit_layout = new QDialogButtonBox (Qt::Vertical); + path_edit_layout->addButton (m_add_folder_button, QDialogButtonBox::ActionRole); + path_edit_layout->addButton (m_move_to_top_button, QDialogButtonBox::ActionRole); + path_edit_layout->addButton (m_move_up_button, QDialogButtonBox::ActionRole); + path_edit_layout->addButton (m_move_down_button, QDialogButtonBox::ActionRole); + path_edit_layout->addButton (m_move_to_bottom_button, QDialogButtonBox::ActionRole); + path_edit_layout->addButton (m_remove_button, QDialogButtonBox::ActionRole); - // main layout - QHBoxLayout *main_hboxlayout = new QHBoxLayout; - main_hboxlayout->addWidget(path_edit_layout); - main_hboxlayout->addWidget(m_path_list); + // main layout + QHBoxLayout *main_hboxlayout = new QHBoxLayout; + main_hboxlayout->addWidget(path_edit_layout); + main_hboxlayout->addWidget(m_path_list); - QGridLayout *main_layout = new QGridLayout; - main_layout->addWidget (m_info_label, 0, 0); - main_layout->addLayout (main_hboxlayout, 1, 0); - main_layout->addWidget (button_box, 2, 0); + QGridLayout *main_layout = new QGridLayout; + main_layout->addWidget (m_info_label, 0, 0); + main_layout->addLayout (main_hboxlayout, 1, 0); + main_layout->addWidget (button_box, 2, 0); - setLayout (main_layout); + setLayout (main_layout); + + gui_settings settings; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - restoreGeometry ( - settings->value(pd_geometry.key).toByteArray()); -} + restoreGeometry (settings.value(pd_geometry.settings_key ()).toByteArray()); + } -void set_path_dialog::update_model (void) -{ - set_path_model *m = static_cast (m_path_list->model ()); - m->path_to_model (); -} + void set_path_dialog::update_model () + { + set_path_model *m = static_cast (m_path_list->model ()); + m->path_to_model (); + } -void set_path_dialog::add_dir_common (bool subdirs) -{ - QString dir - = QFileDialog::getExistingDirectory (this, tr ("Open Directory"), - "", - (QFileDialog::ShowDirsOnly - | QFileDialog::DontResolveSymlinks)); + void set_path_dialog::add_dir_common (bool subdirs) + { + QString dir + = QFileDialog::getExistingDirectory (this, tr ("Open Directory"), + "", + (QFileDialog::ShowDirsOnly + | QFileDialog::DontResolveSymlinks)); - if (! dir.isEmpty ()) - { - if (subdirs) - { - // Use existing method mofifying load path and updating dialog - // instead of adding string and updating load path - emit modify_path_signal (QStringList (dir), false, true); - } - else - { - set_path_model *m - = static_cast (m_path_list->model ()); - m->add_dir (dir); - } - } -} + if (! dir.isEmpty ()) + { + if (subdirs) + { + // Use existing method mofifying load path and updating dialog + // instead of adding string and updating load path + emit modify_path_signal (QStringList (dir), false, true); + } + else + { + set_path_model *m + = static_cast (m_path_list->model ()); + m->add_dir (dir); + } + } + } -void set_path_dialog::add_dir(void) -{ - add_dir_common (false); -} + void set_path_dialog::add_dir() + { + add_dir_common (false); + } -void set_path_dialog::add_dir_subdirs (void) -{ - add_dir_common (true); -} + void set_path_dialog::add_dir_subdirs () + { + add_dir_common (true); + } -void set_path_dialog::rm_dir (void) -{ - set_path_model *m = static_cast (m_path_list->model ()); - QItemSelectionModel *selmodel = m_path_list->selectionModel (); - QModelIndexList indexlist = selmodel->selectedIndexes(); - m->rm_dir (indexlist); + void set_path_dialog::rm_dir () + { + set_path_model *m = static_cast (m_path_list->model ()); + QItemSelectionModel *selmodel = m_path_list->selectionModel (); + QModelIndexList indexlist = selmodel->selectedIndexes(); + m->rm_dir (indexlist); - selmodel->clearSelection (); -} + selmodel->clearSelection (); + } -void set_path_dialog::move_dir_up (void) -{ - set_path_model *m = static_cast (m_path_list->model ()); - QItemSelectionModel *selmodel = m_path_list->selectionModel (); - QModelIndexList indexlist = selmodel->selectedIndexes(); - m->move_dir_up (indexlist); + void set_path_dialog::move_dir_up () + { + set_path_model *m = static_cast (m_path_list->model ()); + QItemSelectionModel *selmodel = m_path_list->selectionModel (); + QModelIndexList indexlist = selmodel->selectedIndexes(); + m->move_dir_up (indexlist); - // Update selection and view - selmodel->clearSelection (); - int min_row = m->rowCount () - 1; - for (int i = 0; i < indexlist.length (); i++) - { - int new_row = std::max (indexlist.at (i).row () - 1, 0); - min_row = std::min (min_row, new_row); - selmodel->select (m->index (new_row), QItemSelectionModel::Select); - } + // Update selection and view + selmodel->clearSelection (); + int min_row = m->rowCount () - 1; + for (int i = 0; i < indexlist.length (); i++) + { + int new_row = std::max (indexlist.at (i).row () - 1, 0); + min_row = std::min (min_row, new_row); + selmodel->select (m->index (new_row), QItemSelectionModel::Select); + } - m_path_list->scrollTo (m->index (min_row)); -} + m_path_list->scrollTo (m->index (min_row)); + } -void set_path_dialog::move_dir_down (void) -{ - set_path_model *m = static_cast (m_path_list->model ()); - QItemSelectionModel *selmodel = m_path_list->selectionModel (); - QModelIndexList indexlist = selmodel->selectedIndexes(); - m->move_dir_down (indexlist); + void set_path_dialog::move_dir_down () + { + set_path_model *m = static_cast (m_path_list->model ()); + QItemSelectionModel *selmodel = m_path_list->selectionModel (); + QModelIndexList indexlist = selmodel->selectedIndexes(); + m->move_dir_down (indexlist); - // Update selection and view - selmodel->clearSelection (); - int max_row = 0; - for (int i = 0; i < indexlist.length (); i++) - { - int new_row = std::min (indexlist.at (i).row () + 1, m->rowCount () - 1); - max_row = std::max (max_row, new_row); - selmodel->select (m->index (new_row), QItemSelectionModel::Select); - } + // Update selection and view + selmodel->clearSelection (); + int max_row = 0; + for (int i = 0; i < indexlist.length (); i++) + { + int new_row = std::min (indexlist.at (i).row () + 1, m->rowCount () - 1); + max_row = std::max (max_row, new_row); + selmodel->select (m->index (new_row), QItemSelectionModel::Select); + } - m_path_list->scrollTo (m->index (max_row)); -} + m_path_list->scrollTo (m->index (max_row)); + } -void set_path_dialog::move_dir_top (void) -{ - set_path_model *m = static_cast (m_path_list->model ()); - QItemSelectionModel *selmodel = m_path_list->selectionModel (); - QModelIndexList indexlist = selmodel->selectedIndexes(); - m->move_dir_top (indexlist); + void set_path_dialog::move_dir_top () + { + set_path_model *m = static_cast (m_path_list->model ()); + QItemSelectionModel *selmodel = m_path_list->selectionModel (); + QModelIndexList indexlist = selmodel->selectedIndexes(); + m->move_dir_top (indexlist); - // Update selection and view - selmodel->clearSelection (); - for (int i = 0; i < indexlist.length (); i++) - selmodel->select (m->index (i), QItemSelectionModel::Select); + // Update selection and view + selmodel->clearSelection (); + for (int i = 0; i < indexlist.length (); i++) + selmodel->select (m->index (i), QItemSelectionModel::Select); - m_path_list->scrollTo (m->index (0)); -} + m_path_list->scrollTo (m->index (0)); + } -void set_path_dialog::move_dir_bottom (void) -{ - set_path_model *m = static_cast (m_path_list->model ()); - QItemSelectionModel *selmodel = m_path_list->selectionModel (); - QModelIndexList indexlist = selmodel->selectedIndexes(); - m->move_dir_bottom (indexlist); + void set_path_dialog::move_dir_bottom () + { + set_path_model *m = static_cast (m_path_list->model ()); + QItemSelectionModel *selmodel = m_path_list->selectionModel (); + QModelIndexList indexlist = selmodel->selectedIndexes(); + m->move_dir_bottom (indexlist); - // Update selection and view - selmodel->clearSelection (); - int row_count = m->rowCount (); - for (int i = 0; i < indexlist.length (); i++) - selmodel->select (m->index (row_count - 1 - i), - QItemSelectionModel::Select); + // Update selection and view + selmodel->clearSelection (); + int row_count = m->rowCount (); + for (int i = 0; i < indexlist.length (); i++) + selmodel->select (m->index (row_count - 1 - i), + QItemSelectionModel::Select); - m_path_list->scrollTo (m->index (row_count - 1)); -} + m_path_list->scrollTo (m->index (row_count - 1)); + } + + void set_path_dialog::save_settings () + { + gui_settings settings; -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 ()); -} + settings.setValue (pd_geometry.settings_key (), saveGeometry ()); + } -void set_path_dialog::closeEvent (QCloseEvent *e) -{ - save_settings (); + void set_path_dialog::closeEvent (QCloseEvent *e) + { + save_settings (); - QWidget::closeEvent (e); -} + QWidget::closeEvent (e); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/set-path-dialog.h --- a/libgui/src/set-path-dialog.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/set-path-dialog.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,79 +41,75 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class set_path_dialog : public QDialog + { + Q_OBJECT -class set_path_dialog : public QDialog -{ - Q_OBJECT - -public: + public: - // You must call update_model to fully initialize the path displayed - // in the dialog. That may only be done after the intepreter_event - // signal connections are made to the Octave interpreter. + // You must call update_model to fully initialize the path displayed + // 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: + signals: - //! Emitted, when the path has to be modified + //! Emitted, when the path has to be modified - void modify_path_signal (const QStringList& dir_list, bool rm, - bool subdirs); + void modify_path_signal (const QStringList& dir_list, bool rm, + bool subdirs); - void interpreter_event (const fcn_callback& fcn); - void interpreter_event (const meth_callback& meth); + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); -public slots: + public slots: - void update_model (void); + void update_model (); -protected: + protected: - void closeEvent (QCloseEvent *e); + void closeEvent (QCloseEvent *e); -private slots: + private slots: - void add_dir (void); - void add_dir_subdirs (void); + void add_dir (); + void add_dir_subdirs (); - void rm_dir (void); - - void move_dir_up (void); + void rm_dir (); - void move_dir_down (void); + void move_dir_up (); - void move_dir_top (void); + void move_dir_down (); - void move_dir_bottom (void); + void move_dir_top (); -private: + void move_dir_bottom (); - void add_dir_common (bool subdirs); + private: - base_qobject& m_octave_qobj; + void add_dir_common (bool subdirs); - QLabel *m_info_label; - QPushButton *m_reload_button; - QPushButton *m_save_button; - QPushButton *m_close_button; - QPushButton *m_revert_button; - QPushButton *m_revert_last_button; + QLabel *m_info_label; + QPushButton *m_reload_button; + QPushButton *m_save_button; + QPushButton *m_close_button; + QPushButton *m_revert_button; + QPushButton *m_revert_last_button; - QListView *m_path_list; + QListView *m_path_list; - QPushButton *m_add_folder_button; - QPushButton *m_move_to_top_button; - QPushButton *m_move_to_bottom_button; - QPushButton *m_move_up_button; - QPushButton *m_move_down_button; - QPushButton *m_remove_button; -}; + QPushButton *m_add_folder_button; + QPushButton *m_move_to_top_button; + QPushButton *m_move_to_bottom_button; + QPushButton *m_move_up_button; + QPushButton *m_move_down_button; + QPushButton *m_remove_button; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/set-path-model.cc --- a/libgui/src/set-path-model.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/set-path-model.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/set-path-model.h --- a/libgui/src/set-path-model.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/set-path-model.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/settings-dialog.cc Mon Jan 30 18:36:03 2023 +0100 @@ -64,1555 +64,1650 @@ #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) -{ - setupUi (this); + settings_dialog::settings_dialog (QWidget *p, const QString& desired_tab) + : QDialog (p), Ui::settings_dialog () + { + setupUi (this); + + gui_settings settings; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + // look for available language files and the actual settings + QString qm_dir_name = settings.get_gui_translation_dir (); + + QDir qm_dir (qm_dir_name); + QFileInfoList qm_files = qm_dir.entryInfoList (QStringList ("*.qm"), + QDir::Files | QDir::Readable, QDir::Name); - if (! settings) - { - QMessageBox msgBox - (QMessageBox::Warning, tr ("Octave Preferences"), - tr ("Unable to save preferences. Missing preferences file or unknown directory.")); - - msgBox.exec (); - - return; - } - - // 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.string_value (global_language); + if (language == global_language.def ().toString ()) + language = tr ("System setting"); + int selected = comboBox_language->findText (language); + if (selected >= 0) + comboBox_language->setCurrentIndex (selected); + else + comboBox_language->setCurrentIndex (0); // System is default - 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 ()) - language = tr ("System setting"); - int selected = comboBox_language->findText (language); - if (selected >= 0) - comboBox_language->setCurrentIndex (selected); - 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.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); - // 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 (); - 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.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.settings_key ()).toInt (); + combo_box_icon_theme->setCurrentIndex (theme); - // 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 (); - 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 (); - 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); + QString widget_icon_set = + 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"); - // 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 (); - 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.color_value (dw_title_bg_color); + 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); + + connect (cb_widget_custom_style, &QCheckBox::toggled, + m_widget_title_bg_color, &color_picker::setEnabled); + + QColor bg_color_active = settings.color_value (dw_title_bg_color_active); + 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); - // 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); + connect (cb_widget_custom_style, &QCheckBox::toggled, + m_widget_title_bg_color_active, &color_picker::setEnabled); + + QColor fg_color = settings.color_value (dw_title_fg_color); + 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); - 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_fg_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); + QColor fg_color_active = settings.color_value (dw_title_fg_color_active); + 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_bg_color_active, &color_picker::setEnabled); + connect (cb_widget_custom_style, &QCheckBox::toggled, + m_widget_title_fg_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); + sb_3d_title->setValue (settings.int_value (dw_title_3d)); + cb_widget_custom_style->setChecked (settings.bool_value (dw_title_custom_style)); - connect (cb_widget_custom_style, &QCheckBox::toggled, - m_widget_title_fg_color, &color_picker::setEnabled); - - 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); + // 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.bool_value (global_use_native_dialogs)); - connect (cb_widget_custom_style, &QCheckBox::toggled, - m_widget_title_fg_color_active, &color_picker::setEnabled); - - 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 ()); - - // 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 ()); + // 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.settings_key ())) + { + // Preference exists, read its value + 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.bool_value (cs_cursor_blinking)); + } - // 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)) - { - // Preference exists, read its value - cb_cursor_blinking->setChecked (settings->value - (global_cursor_blinking.key, global_cursor_blinking.def).toBool ()); - } - 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 ()); - } + // focus follows mouse + cb_focus_follows_mouse->setChecked (settings.bool_value (dw_focus_follows_mouse)); + + // prompt on exit + cb_prompt_to_exit->setChecked (settings.bool_value (global_prompt_to_exit)); - // focus follows mouse - cb_focus_follows_mouse->setChecked ( - settings->value (dw_focus_follows_mouse).toBool ()); + // Main status bar + cb_status_bar->setChecked (settings.bool_value (global_status_bar)); - // prompt on exit - cb_prompt_to_exit->setChecked ( - settings->value (global_prompt_to_exit.key, global_prompt_to_exit.def).toBool ()); + // Octave startup + 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); - // Main status bar - cb_status_bar->setChecked ( - settings->value (global_status_bar.key, global_status_bar.def).toBool ()); + // + // editor + // + 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)); - // 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 ()); + settings.combo_encoding (editor_combo_encoding); - 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 ()); - - rmgr.combo_encoding (editor_combo_encoding); + 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.bool_value (ed_long_line_marker_line); + editor_long_line_marker_line->setChecked (long_line); + bool long_back = + 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.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_highlightCurrentLine->setChecked (settings->value (ed_highlight_current_line).toBool ()); - editor_long_line_marker->setChecked (settings->value (ed_long_line_marker).toBool ()); - bool long_line = - settings->value (ed_long_line_marker_line).toBool (); - editor_long_line_marker_line->setChecked (long_line); - bool long_back = - settings->value (ed_long_line_marker_background).toBool (); - 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_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.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.int_value (ed_tab_position)); - 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_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_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.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.settings_key (), ed_comment_str.def ()).toInt (); - 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 ()); + selected_uncomment_string = settings.int_value (ed_uncomment_str); - editor_cb_tabs_rotated->setChecked (settings->value (ed_tabs_rotated).toBool ()); - editor_sb_tabs_max_width->setValue (settings->value (ed_tabs_max_width).toInt ()); + for (int i = 0; i < ed_comment_strings_count; i++) + { + m_rb_comment_strings[i] = new QRadioButton (); + m_rb_uncomment_strings[i] = new QCheckBox (); - int selected_comment_string, selected_uncomment_string; + 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); - if (settings->contains (ed_comment_str.key)) // new version (radio buttons) - selected_comment_string = settings->value (ed_comment_str).toInt (); - else // old version (combo box) - selected_comment_string = settings->value (ed_comment_str_old.key, ed_comment_str.def).toInt (); - - selected_uncomment_string = settings->value (ed_uncomment_str).toInt (); - - for (int i = 0; i < ed_comment_strings_count; i++) - { - m_rb_comment_strings[i] = new QRadioButton (); - m_rb_uncomment_strings[i] = new QCheckBox (); + 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]); - 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]); - } + 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 ()); + // terminal + 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"); + terminal_cursorType->addItems (items); + terminal_cursorType->setItemText (0, tr ("IBeam Cursor")); + terminal_cursorType->setItemText (1, tr ("Block Cursor")); + terminal_cursorType->setItemText (2, tr ("Underline Cursor")); - QStringList items; - items << QString ("0") << QString ("1") << QString ("2"); - terminal_cursorType->addItems (items); - terminal_cursorType->setItemText (0, tr ("IBeam Cursor")); - terminal_cursorType->setItemText (1, tr ("Block Cursor")); - terminal_cursorType->setItemText (2, tr ("Underline Cursor")); + for (unsigned int i = 0; i < cs_cursor_types.size (); i++) + { + if (cursor_type.toStdString () == cs_cursor_types[i]) + { + terminal_cursorType->setCurrentIndex (i); + break; + } + } - for (unsigned int i = 0; i < cs_cursor_types.size (); i++) - { - if (cursor_type.toStdString () == cs_cursor_types[i]) - { - terminal_cursorType->setCurrentIndex (i); - break; - } - } + read_terminal_colors (); - read_terminal_colors (settings); - - // file browser - connect (sync_octave_directory, &QCheckBox::toggled, - this, &settings_dialog::set_disabled_pref_file_browser_dir); + // 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 ()); + 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 ()); - 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 ()); + le_file_browser_extensions->setText (settings.string_value (fb_txt_file_ext)); - checkbox_allow_web_connect->setChecked (settings->value (nr_allow_connection).toBool ()); + 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 (); - 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); - for (int i = 0; i < global_proxy_all_types.length (); i++) - { - if (proxy_type->itemText (i) == proxy_type_string) - { - proxy_type->setCurrentIndex (i); - break; - } - } - // 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); - // Check whehter line edits have to be enabled - proxy_items_update (); + // Proxy + 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.string_value (global_proxy_type); + proxy_type->addItems (global_proxy_all_types); + for (int i = 0; i < global_proxy_all_types.length (); i++) + { + if (proxy_type->itemText (i) == proxy_type_string) + { + proxy_type->setCurrentIndex (i); + break; + } + } + // Fill all line edits + 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)); + // 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); + // Check whehter line edits have to be enabled + proxy_items_update (); - // Workspace - read_workspace_colors (settings); - - // variable editor - varedit_columnWidth->setValue (settings->value (ve_column_width).toInt ()); - varedit_rowHeight->setValue (settings->value (ve_row_height).toInt ()); + // Workspace + read_workspace_colors (); - 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 ()); - varedit_font->setDisabled (varedit_useTerminalFont->isChecked ()); - varedit_fontSize->setDisabled (varedit_useTerminalFont->isChecked ()); + // variable editor + varedit_columnWidth->setValue (settings.int_value (ve_column_width)); + varedit_rowHeight->setValue (settings.int_value (ve_row_height)); - varedit_alternate->setChecked (settings->value (ve_alternate_rows).toBool ()); + 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)); + connect (varedit_useTerminalFont, &QCheckBox::toggled, + varedit_font, &QFontComboBox::setDisabled); + connect (varedit_useTerminalFont, &QCheckBox::toggled, + varedit_fontSize, &QSpinBox::setDisabled); + varedit_useTerminalFont->setChecked (settings.bool_value (ve_use_terminal_font)); + varedit_font->setDisabled (varedit_useTerminalFont->isChecked ()); + varedit_fontSize->setDisabled (varedit_useTerminalFont->isChecked ()); - // variable editor colors - read_varedit_colors (settings); - - // shortcuts - - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + varedit_alternate->setChecked (settings.bool_value (ve_alternate_rows)); - 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 ()); + // variable editor colors + read_varedit_colors (); - // initialize the tree view with all shortcut data - scmgr.fill_treewidget (shortcuts_treewidget); + // shortcuts + + 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); + // connect the buttons for import/export of the shortcut sets + // FIXME: Should there also be a button to discard changes? + + 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 (); + 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 (), + this); + 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); + 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); }); + // 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 (); #endif - // which tab is the desired one? - show_tab (desired_tab); + // which tab is the desired one? + show_tab (desired_tab); - // connect button box signal - connect (button_box, &QDialogButtonBox::clicked, - this, &settings_dialog::button_clicked); + // 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)); -} + // restore last geometry + if (settings.contains (sd_geometry.settings_key ())) + restoreGeometry (settings.byte_array_value (sd_geometry)); + else + setGeometry (QRect (10, 50, 1000, 600)); + } + + void settings_dialog::show_tab (const QString& tab) + { + gui_settings settings; -void settings_dialog::show_tab (const QString& tab) -{ - 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 ()); - } - else - { - QHash tab_hash; - tab_hash["editor"] = tab_editor; - tab_hash["editor_styles"] = tab_editor; - tabWidget->setCurrentIndex (tabWidget->indexOf (tab_hash.value (tab))); - if (tab == "editor_styles") - tab_editor_scroll_area->ensureWidgetVisible (group_box_editor_styles); - } -} + if (tab.isEmpty ()) + tabWidget->setCurrentIndex (settings.int_value (sd_last_tab)); + else + { + QHash tab_hash; + tab_hash["editor"] = tab_editor; + tab_hash["editor_styles"] = tab_editor; + tabWidget->setCurrentIndex (tabWidget->indexOf (tab_hash.value (tab))); + if (tab == "editor_styles") + tab_editor_scroll_area->ensureWidgetVisible (group_box_editor_styles); + } + } + + void settings_dialog::get_octave_dir () + { + get_dir (le_octave_dir, tr ("Set Octave Startup Directory")); + } + + void settings_dialog::get_file_browser_dir () + { + get_dir (le_file_browser_dir, tr ("Set File Browser Startup Directory")); + } -void settings_dialog::get_octave_dir (void) -{ - get_dir (le_octave_dir, tr ("Set Octave Startup Directory")); -} + void settings_dialog::get_dir (QLineEdit *line_edit, const QString& title) + { + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. + int opts = QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks; + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) + opts |= QFileDialog::DontUseNativeDialog; -void settings_dialog::get_file_browser_dir (void) -{ - get_dir (le_file_browser_dir, tr ("Set File Browser Startup Directory")); -} + QString dir = QFileDialog::getExistingDirectory + (this, title, line_edit->text (), QFileDialog::Option (opts)); + + line_edit->setText (dir); + } + + void settings_dialog::button_clicked (QAbstractButton *button) + { + QDialogButtonBox::ButtonRole button_role = button_box->buttonRole (button); -void settings_dialog::get_dir (QLineEdit *line_edit, const QString& title) -{ - // 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 ()) - opts |= QFileDialog::DontUseNativeDialog; + if (button_role == QDialogButtonBox::ApplyRole + || button_role == QDialogButtonBox::AcceptRole) + { + write_changed_settings (); + emit apply_new_settings (); + } - QString dir = QFileDialog::getExistingDirectory - (this, title, line_edit->text (), QFileDialog::Option (opts)); + if (button_role == QDialogButtonBox::RejectRole + || button_role == QDialogButtonBox::AcceptRole) + { + // save last settings dialog's geometry and close - line_edit->setText (dir); -} + gui_settings settings; -void settings_dialog::button_clicked (QAbstractButton *button) -{ - QDialogButtonBox::ButtonRole button_role = button_box->buttonRole (button); + settings.setValue (sd_last_tab.settings_key (), tabWidget->currentIndex ()); + settings.setValue (sd_geometry.settings_key (), saveGeometry ()); + settings.sync (); - if (button_role == QDialogButtonBox::ApplyRole - || button_role == QDialogButtonBox::AcceptRole) - { - write_changed_settings (button_role == QDialogButtonBox::AcceptRole); - emit apply_new_settings (); - } + close (); + } + } + + void settings_dialog::set_disabled_pref_file_browser_dir (bool disable) + { + cb_restore_file_browser_dir->setDisabled (disable); - 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 (); + if (! disable) + { + le_file_browser_dir->setDisabled (cb_restore_file_browser_dir->isChecked ()); + pb_file_browser_dir->setDisabled (cb_restore_file_browser_dir->isChecked ()); + } + else + { + le_file_browser_dir->setDisabled (disable); + pb_file_browser_dir->setDisabled (disable); + } + } - settings->setValue (sd_last_tab.key, tabWidget->currentIndex ()); - settings->setValue (sd_geometry.key, saveGeometry ()); - settings->sync (); - - close (); - } -} + // slot for updating enabled state of proxy settings + void settings_dialog::proxy_items_update () + { + bool use_proxy = use_proxy_server->isChecked (); -void settings_dialog::set_disabled_pref_file_browser_dir (bool disable) -{ - cb_restore_file_browser_dir->setDisabled (disable); + bool manual = false; + for (int i = 0; i < global_proxy_manual_types.length (); i++) + { + if (proxy_type->currentIndex () == global_proxy_manual_types.at (i)) + { + manual = true; + break; + } + } - if (! disable) - { - le_file_browser_dir->setDisabled (cb_restore_file_browser_dir->isChecked ()); - pb_file_browser_dir->setDisabled (cb_restore_file_browser_dir->isChecked ()); - } - else - { - le_file_browser_dir->setDisabled (disable); - pb_file_browser_dir->setDisabled (disable); - } -} + proxy_type->setEnabled (use_proxy); + proxy_host_name_label->setEnabled (use_proxy && manual); + proxy_host_name->setEnabled (use_proxy && manual); + proxy_port_label->setEnabled (use_proxy && manual); + proxy_port->setEnabled (use_proxy && manual); + proxy_username_label->setEnabled (use_proxy && manual); + proxy_username->setEnabled (use_proxy && manual); + proxy_password_label->setEnabled (use_proxy && manual); + proxy_password->setEnabled (use_proxy && manual); + } -// slot for updating enabled state of proxy settings -void settings_dialog::proxy_items_update (void) -{ - bool use_proxy = use_proxy_server->isChecked (); + // slots for import/export of shortcut sets + + // 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. - bool manual = false; - for (int i = 0; i < global_proxy_manual_types.length (); i++) - { - if (proxy_type->currentIndex () == global_proxy_manual_types.at (i)) - { - manual = true; - break; - } - } + void settings_dialog::import_shortcut_set () + { + if (! overwrite_all_shortcuts ()) + return; + + QString file = get_shortcuts_file_name (OSC_IMPORT); + + gui_settings osc_settings (file, QSettings::IniFormat); - proxy_type->setEnabled (use_proxy); - proxy_host_name_label->setEnabled (use_proxy && manual); - proxy_host_name->setEnabled (use_proxy && manual); - proxy_port_label->setEnabled (use_proxy && manual); - proxy_port->setEnabled (use_proxy && manual); - proxy_username_label->setEnabled (use_proxy && manual); - proxy_username->setEnabled (use_proxy && manual); - proxy_password_label->setEnabled (use_proxy && manual); - proxy_password->setEnabled (use_proxy && manual); -} + 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)); + } -// slots for import/export of shortcut sets + // 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::import_shortcut_set (void) -{ - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + void settings_dialog::export_shortcut_set () + { + QString file = get_shortcuts_file_name (OSC_EXPORT); + + gui_settings osc_settings (file, QSettings::IniFormat); - scmgr.import_export (shortcut_manager::OSC_IMPORT); -} - -void settings_dialog::export_shortcut_set (void) -{ - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + 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)); + } - scmgr.import_export (shortcut_manager::OSC_EXPORT); -} + // 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 (void) -{ - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + void settings_dialog::default_shortcut_set () + { + 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) -{ + 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.settings_key ()); - QCheckBox *cb_color_mode - = group_box_editor_styles->findChild (ed_color_mode.key); + int m = 0; + if (cb_color_mode && cb_color_mode->isChecked ()) + m = 1; - int m = 0; - if (cb_color_mode && cb_color_mode->isChecked ()) - m = 1; + color_picker *c_picker = findChild (ed_highlight_current_line_color.settings_key ()); + if (c_picker) + { + gui_settings settings; - color_picker *c_picker = findChild (ed_highlight_current_line_color.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 (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)); - } - } + 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)); + } + else + { + // Get the default value + c_picker->set_color (settings.get_color_value (ed_highlight_current_line_color.def (), m)); + } + } - // editor styles: create lexer, read settings, and - // create or update dialog elements - QsciLexer *lexer; + // editor styles: create lexer, read settings, and + // create or update dialog elements + QsciLexer *lexer; # if defined (HAVE_LEXER_OCTAVE) - lexer = new QsciLexerOctave (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new QsciLexerOctave (); + update_lexer (lexer, m, def); + delete lexer; # elif defined (HAVE_LEXER_MATLAB) - lexer = new QsciLexerMatlab (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new QsciLexerMatlab (); + update_lexer (lexer, m, def); + delete lexer; # endif - lexer = new QsciLexerCPP (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new QsciLexerCPP (); + update_lexer (lexer, m, def); + delete lexer; - lexer = new QsciLexerJava (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new QsciLexerJava (); + update_lexer (lexer, m, def); + delete lexer; - lexer = new QsciLexerPerl (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new QsciLexerPerl (); + update_lexer (lexer, m, def); + delete lexer; - lexer = new QsciLexerBatch (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new QsciLexerBatch (); + update_lexer (lexer, m, def); + delete lexer; - lexer = new QsciLexerDiff (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new QsciLexerDiff (); + update_lexer (lexer, m, def); + delete lexer; - lexer = new QsciLexerBash (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new QsciLexerBash (); + update_lexer (lexer, m, def); + delete lexer; - lexer = new octave_txt_lexer (); - update_lexer (lexer, settings, m, def); - delete lexer; + lexer = new octave_txt_lexer (); + update_lexer (lexer, m, def); + delete lexer; #else - octave_unused_parameter (def); + octave_unused_parameter (def); #endif -} + } #if defined (HAVE_QSCINTILLA) -void settings_dialog::update_lexer (QsciLexer *lexer, gui_settings *settings, - 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); + 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 + 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. - QString lexer_name = lexer->language (); + // When reloading default styles, the style tabs do already exists. + // Otherwise, check if they exist or not. + QString lexer_name = lexer->language (); - int index = -1; - for (int i = 0; i < tabs_editor_lexers->count (); i++) - { - if (tabs_editor_lexers->tabText (i) == lexer_name) - { - index = i; - break; - } - } + int index = -1; + for (int i = 0; i < tabs_editor_lexers->count (); i++) + { + if (tabs_editor_lexers->tabText (i) == lexer_name) + { + index = i; + break; + } + } - if (index == -1) - { - // This is not an update, call get_lexer_settings for building - // the settings tab - get_lexer_settings (lexer, settings); - return; - } + if (index == -1) + { + // This is not an update, call get_lexer_settings for building + // the settings tab + 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 = settings.get_valid_lexer_styles (lexer, styles); + QWidget *tab = tabs_editor_lexers->widget (index); + int default_size = 0; + QString default_family; - // 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); - QWidget *tab = tabs_editor_lexers->widget (index); - int default_size = 0; - QString default_family; + for (int i = 0; i < max_style; i++) // create dialog elements for all styles + { + QString actual_name = lexer->description (styles[i]); + color_picker *bg_color + = tab->findChild (actual_name + "_bg_color"); + if (bg_color) + { + // Update + if (styles[i] == 0) + bg_color->set_color (lexer->defaultPaper ()); + else + { + if (lexer->paper (styles[i]) == lexer->defaultPaper ()) + bg_color->set_color (settings_color_no_change); + else + bg_color->set_color (lexer->paper (styles[i])); + } + } + + color_picker *color = tab->findChild (actual_name + "_color"); + if (color) + color->set_color (lexer->color (styles[i])); + + QFont font = lexer->font (styles[i]); + + QCheckBox *cb = tab->findChild (actual_name + "_bold"); + if (cb) + cb->setChecked (font.bold ()); + cb = tab->findChild (actual_name + "_italic"); + if (cb) + cb->setChecked (font.italic ()); + cb = tab->findChild (actual_name + "_underline"); + if (cb) + cb->setChecked (font.underline ()); - for (int i = 0; i < max_style; i++) // create dialog elements for all styles - { - QString actual_name = lexer->description (styles[i]); - color_picker *bg_color - = tab->findChild (actual_name + "_bg_color"); - if (bg_color) - { - // Update - if (styles[i] == 0) - bg_color->set_color (lexer->defaultPaper ()); - else - { - if (lexer->paper (styles[i]) == lexer->defaultPaper ()) - bg_color->set_color (settings_color_no_change); - else - bg_color->set_color (lexer->paper (styles[i])); - } - } + QFontComboBox *fcb = tab->findChild (actual_name + "_font"); + if (fcb) + { + if (styles[i] == 0) + { + default_family = font.family (); + fcb->setEditText (default_family); + } + else + { + if (font.family () == default_family) + fcb->setEditText (lexer->description (0)); + else + fcb->setEditText (font.family ()); + } + } + QSpinBox *fs = tab->findChild (actual_name + "_size"); + if (fs) + { + if (styles[i] == 0) + { + default_size = font.pointSize (); + fs->setValue (default_size); + } + else + fs->setValue (font.pointSize () - default_size); + } + } - color_picker *color = tab->findChild (actual_name + "_color"); - if (color) - color->set_color (lexer->color (styles[i])); + } + + void settings_dialog::get_lexer_settings (QsciLexer *lexer) + { + gui_settings settings; - QFont font = lexer->font (styles[i]); - - QCheckBox *cb = tab->findChild (actual_name + "_bold"); - if (cb) - cb->setChecked (font.bold ()); - cb = tab->findChild (actual_name + "_italic"); - if (cb) - cb->setChecked (font.italic ()); - cb = tab->findChild (actual_name + "_underline"); - if (cb) - cb->setChecked (font.underline ()); + int styles[ed_max_lexer_styles]; // array for saving valid styles + // (enum is not continuous) + int max_style = settings.get_valid_lexer_styles (lexer, styles); + QGridLayout *style_grid = new QGridLayout (); + QVector description (max_style); + QVector select_font (max_style); + QVector font_size (max_style); + QVector attrib_font (3 * max_style); + QVector color (max_style); + QVector bg_color (max_style); + int default_size = 10; + QFont default_font = QFont (); + int label_width; + QColor default_color = QColor (); - QFontComboBox *fcb = tab->findChild (actual_name + "_font"); - if (fcb) - { - if (styles[i] == 0) - { - default_family = font.family (); - fcb->setEditText (default_family); - } - else - { - if (font.family () == default_family) - fcb->setEditText (lexer->description (0)); - else - fcb->setEditText (font.family ()); - } - } - QSpinBox *fs = tab->findChild (actual_name + "_size"); - if (fs) - { - if (styles[i] == 0) - { - default_size = font.pointSize (); - fs->setValue (default_size); - } - else - fs->setValue (font.pointSize () - default_size); - } - } + for (int i = 0; i < max_style; i++) // create dialog elements for all styles + { + QString actual_name = lexer->description (styles[i]); + QFont actual_font = lexer->font (styles[i]); + description[i] = new QLabel (actual_name); + description[i]->setWordWrap (true); + label_width = 24*description[i]->fontMetrics ().averageCharWidth (); + description[i]->setMaximumSize (label_width, QWIDGETSIZE_MAX); + description[i]->setMinimumSize (label_width, 1); + select_font[i] = new QFontComboBox (); + select_font[i]->setObjectName (actual_name + "_font"); + select_font[i]->setMaximumSize (label_width, QWIDGETSIZE_MAX); + select_font[i]->setMinimumSize (label_width, 1); + font_size[i] = new QSpinBox (); + font_size[i]->setObjectName (actual_name + "_size"); + if (styles[i] == 0) // the default + { + select_font[i]->setCurrentFont (actual_font); + default_font = actual_font; + font_size[i]->setRange (6, 24); + default_size = actual_font.pointSize (); + font_size[i]->setValue (default_size); + default_color = lexer->defaultPaper (); + bg_color[i] = new color_picker (default_color); + } + else // other styles + { + select_font[i]->setCurrentFont (actual_font); + if (actual_font.family () == default_font.family ()) + select_font[i]->setEditText (lexer->description (0)); + font_size[i]->setRange (-4, 4); + font_size[i]->setValue (actual_font.pointSize ()-default_size); + font_size[i]->setToolTip (QObject::tr ("Difference to the default size")); + if (lexer->paper (styles[i]) == default_color) + bg_color[i] = new color_picker (settings_color_no_change); + else + bg_color[i] = new color_picker (lexer->paper (styles[i])); + bg_color[i]->setToolTip + (QObject::tr ("Background color, magenta (255, 0, 255) means default")); + } + attrib_font[0+3*i] = new QCheckBox (QObject::tr ("b", "short form for bold")); + attrib_font[1+3*i] = new QCheckBox (QObject::tr ("i", "short form for italic")); + attrib_font[2+3*i] = new QCheckBox (QObject::tr ("u", "short form for underlined")); + attrib_font[0+3*i]->setChecked (actual_font.bold ()); + attrib_font[0+3*i]->setObjectName (actual_name + "_bold"); + attrib_font[1+3*i]->setChecked (actual_font.italic ()); + attrib_font[1+3*i]->setObjectName (actual_name + "_italic"); + attrib_font[2+3*i]->setChecked (actual_font.underline ()); + attrib_font[2+3*i]->setObjectName (actual_name + "_underline"); + color[i] = new color_picker (lexer->color (styles[i])); + color[i]->setObjectName (actual_name + "_color"); + bg_color[i]->setObjectName (actual_name + "_bg_color"); + int column = 1; + style_grid->addWidget (description[i], i, column++); + style_grid->addWidget (select_font[i], i, column++); + style_grid->addWidget (font_size[i], i, column++); + style_grid->addWidget (attrib_font[0+3*i], i, column++); + style_grid->addWidget (attrib_font[1+3*i], i, column++); + style_grid->addWidget (attrib_font[2+3*i], i, column++); + style_grid->addWidget (color[i], i, column++); + style_grid->addWidget (bg_color[i], i, column++); + } -} + // place grid with elements into the tab + QScrollArea *scroll_area = new QScrollArea (); + QWidget *scroll_area_contents = new QWidget (); + scroll_area_contents->setObjectName (QString (lexer->language ()) + "_styles"); + scroll_area_contents->setLayout (style_grid); + scroll_area->setWidget (scroll_area_contents); + tabs_editor_lexers->addTab (scroll_area, lexer->language ()); + + tabs_editor_lexers->setCurrentIndex (settings.int_value (sd_last_editor_styles_tab)); + } -void settings_dialog::get_lexer_settings (QsciLexer *lexer, - gui_settings *settings) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + void settings_dialog::write_lexer_settings (QsciLexer *lexer) + { + gui_settings settings; + + QCheckBox *cb_color_mode + = 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.settings_key (), mode); - 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); - QGridLayout *style_grid = new QGridLayout (); - QVector description (max_style); - QVector select_font (max_style); - QVector font_size (max_style); - QVector attrib_font (3 * max_style); - QVector color (max_style); - QVector bg_color (max_style); - int default_size = 10; - QFont default_font = QFont (); - int label_width; - QColor default_color = QColor (); + 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 = settings.get_valid_lexer_styles (lexer, styles); + + QFontComboBox *select_font; + QSpinBox *font_size; + QCheckBox *attrib_font[3]; + color_picker *color; + color_picker *bg_color; + int default_size = 10; + + color = findChild (ed_highlight_current_line_color.settings_key ()); + if (color) + settings.setValue (ed_highlight_current_line_color.settings_key () + + settings_color_modes_ext[mode], color->color ()); + + QString default_font_name + = settings.string_value (global_mono_font); + QFont default_font = QFont (default_font_name, 10, -1, 0); + QColor default_color = QColor (); - for (int i = 0; i < max_style; i++) // create dialog elements for all styles - { - QString actual_name = lexer->description (styles[i]); - QFont actual_font = lexer->font (styles[i]); - description[i] = new QLabel (actual_name); - description[i]->setWordWrap (true); - label_width = 24*description[i]->fontMetrics ().averageCharWidth (); - description[i]->setMaximumSize (label_width, QWIDGETSIZE_MAX); - description[i]->setMinimumSize (label_width, 1); - select_font[i] = new QFontComboBox (); - select_font[i]->setObjectName (actual_name + "_font"); - select_font[i]->setMaximumSize (label_width, QWIDGETSIZE_MAX); - select_font[i]->setMinimumSize (label_width, 1); - font_size[i] = new QSpinBox (); - font_size[i]->setObjectName (actual_name + "_size"); - if (styles[i] == 0) // the default - { - select_font[i]->setCurrentFont (actual_font); - default_font = actual_font; - font_size[i]->setRange (6, 24); - default_size = actual_font.pointSize (); - font_size[i]->setValue (default_size); - default_color = lexer->defaultPaper (); - bg_color[i] = new color_picker (default_color); - } - else // other styles - { - select_font[i]->setCurrentFont (actual_font); - if (actual_font.family () == default_font.family ()) - select_font[i]->setEditText (lexer->description (0)); - font_size[i]->setRange (-4, 4); - font_size[i]->setValue (actual_font.pointSize ()-default_size); - font_size[i]->setToolTip (QObject::tr ("Difference to the default size")); - if (lexer->paper (styles[i]) == default_color) - bg_color[i] = new color_picker (settings_color_no_change); - else - bg_color[i] = new color_picker (lexer->paper (styles[i])); - bg_color[i]->setToolTip - (QObject::tr ("Background color, magenta (255, 0, 255) means default")); - } - attrib_font[0+3*i] = new QCheckBox (QObject::tr ("b", "short form for bold")); - attrib_font[1+3*i] = new QCheckBox (QObject::tr ("i", "short form for italic")); - attrib_font[2+3*i] = new QCheckBox (QObject::tr ("u", "short form for underlined")); - attrib_font[0+3*i]->setChecked (actual_font.bold ()); - attrib_font[0+3*i]->setObjectName (actual_name + "_bold"); - attrib_font[1+3*i]->setChecked (actual_font.italic ()); - attrib_font[1+3*i]->setObjectName (actual_name + "_italic"); - attrib_font[2+3*i]->setChecked (actual_font.underline ()); - attrib_font[2+3*i]->setObjectName (actual_name + "_underline"); - color[i] = new color_picker (lexer->color (styles[i])); - color[i]->setObjectName (actual_name + "_color"); - bg_color[i]->setObjectName (actual_name + "_bg_color"); - int column = 1; - style_grid->addWidget (description[i], i, column++); - style_grid->addWidget (select_font[i], i, column++); - style_grid->addWidget (font_size[i], i, column++); - style_grid->addWidget (attrib_font[0+3*i], i, column++); - style_grid->addWidget (attrib_font[1+3*i], i, column++); - style_grid->addWidget (attrib_font[2+3*i], i, column++); - style_grid->addWidget (color[i], i, column++); - style_grid->addWidget (bg_color[i], i, column++); - } + for (int i = 0; i < max_style; i++) // get dialog elements and their contents + { + QString actual_name = lexer->description (styles[i]); + select_font = tab->findChild (actual_name + "_font"); + font_size = tab->findChild (actual_name + "_size"); + attrib_font[0] = tab->findChild (actual_name + "_bold"); + attrib_font[1] = tab->findChild (actual_name + "_italic"); + attrib_font[2] = tab->findChild (actual_name + "_underline"); + color = tab->findChild (actual_name + "_color"); + bg_color = tab->findChild (actual_name + "_bg_color"); + QFont new_font = default_font; + if (select_font) + { + new_font = select_font->currentFont (); + if (styles[i] == 0) + default_font = new_font; + else if (select_font->currentText () == lexer->description (0)) + new_font = default_font; + } + if (font_size) + { + if (styles[i] == 0) + { + default_size = font_size->value (); + new_font.setPointSize (font_size->value ()); + } + else + new_font.setPointSize (font_size->value ()+default_size); + } + if (attrib_font[0]) + new_font.setBold (attrib_font[0]->isChecked ()); + if (attrib_font[1]) + new_font.setItalic (attrib_font[1]->isChecked ()); + if (attrib_font[2]) + new_font.setUnderline (attrib_font[2]->isChecked ()); + lexer->setFont (new_font, styles[i]); + if (styles[i] == 0) + lexer->setDefaultFont (new_font); + if (color) + lexer->setColor (color->color (), styles[i]); + if (bg_color) + { + if (styles[i] == 0) + { + default_color = bg_color->color (); + lexer->setPaper (default_color, styles[i]); + lexer->setDefaultPaper (default_color); + } + else + { + if (bg_color->color () == settings_color_no_change) + lexer->setPaper (default_color, styles[i]); + else + lexer->setPaper (bg_color->color (), styles[i]); + } + } + } + + const std::string group = + QString ("Scintilla" + settings_color_modes_ext[mode]).toStdString (); - // place grid with elements into the tab - QScrollArea *scroll_area = new QScrollArea (); - QWidget *scroll_area_contents = new QWidget (); - scroll_area_contents->setObjectName (QString (lexer->language ()) + "_styles"); - scroll_area_contents->setLayout (style_grid); - scroll_area->setWidget (scroll_area_contents); - tabs_editor_lexers->addTab (scroll_area, lexer->language ()); + lexer->writeSettings (settings, group.c_str ()); + + settings.setValue (sd_last_editor_styles_tab.settings_key (), + tabs_editor_lexers->currentIndex ()); + settings.sync (); + } + +#endif + + void settings_dialog::write_changed_settings () + { + gui_settings settings; - tabs_editor_lexers->setCurrentIndex (settings->value (sd_last_editor_styles_tab).toInt ()); -} + // the icon set + QString widget_icon_set = "NONE"; + if (general_icon_letter->isChecked ()) + widget_icon_set = "LETTER"; + else if (general_icon_graphic->isChecked ()) + widget_icon_set = "GRAPHIC"; + 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.settings_key (), language); -void settings_dialog::write_lexer_settings (QsciLexer *lexer, - gui_settings *settings) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + // style + QString selected_style = combo_styles->currentText (); + 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.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 ()); - QCheckBox *cb_color_mode - = group_box_editor_styles->findChild (ed_color_mode.key); - int mode = 0; - if (cb_color_mode && cb_color_mode->isChecked ()) - mode = 1; + // icon size and theme + int icon_size = icon_size_large->isChecked () - icon_size_small->isChecked (); + 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.settings_key (), cb_use_native_file_dialogs->isChecked ()); - settings->setValue (ed_color_mode.key, mode); + // cursor blinking + settings.setValue (global_cursor_blinking.settings_key (), cb_cursor_blinking->isChecked ()); + + // focus follows mouse + settings.setValue (dw_focus_follows_mouse.settings_key (), cb_focus_follows_mouse->isChecked ()); + + // promp to exit + settings.setValue (global_prompt_to_exit.settings_key (), cb_prompt_to_exit->isChecked ()); + + // status bar + settings.setValue (global_status_bar.settings_key (), cb_status_bar->isChecked ()); - 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); - QFontComboBox *select_font; - QSpinBox *font_size; - QCheckBox *attrib_font[3]; - color_picker *color; - color_picker *bg_color; - int default_size = 10; + // Octave startup + 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 ()); - color = findChild (ed_highlight_current_line_color.key); - if (color) - settings->setValue (ed_highlight_current_line_color.key - + settings_color_modes_ext[mode], color->color ()); + //editor + 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 ()); - QString default_font_name - = settings->value (global_mono_font).toString (); - QFont default_font = QFont (default_font_name, 10, -1, 0); - QColor default_color = QColor (); + 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; + for (int i = 0; i < ed_comment_strings_count; i++) + { + if (m_rb_comment_strings[i]->isChecked ()) + { + settings.setValue (ed_comment_str.settings_key (), i); + if (i < 3) + settings.setValue (ed_comment_str_old.settings_key (), i); + else + 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.settings_key (), rb_uncomment); - for (int i = 0; i < max_style; i++) // get dialog elements and their contents - { - QString actual_name = lexer->description (styles[i]); - select_font = tab->findChild (actual_name + "_font"); - font_size = tab->findChild (actual_name + "_size"); - attrib_font[0] = tab->findChild (actual_name + "_bold"); - attrib_font[1] = tab->findChild (actual_name + "_italic"); - attrib_font[2] = tab->findChild (actual_name + "_underline"); - color = tab->findChild (actual_name + "_color"); - bg_color = tab->findChild (actual_name + "_bg_color"); - QFont new_font = default_font; - if (select_font) - { - new_font = select_font->currentFont (); - if (styles[i] == 0) - default_font = new_font; - else if (select_font->currentText () == lexer->description (0)) - new_font = default_font; - } - if (font_size) - { - if (styles[i] == 0) - { - default_size = font_size->value (); - new_font.setPointSize (font_size->value ()); - } - else - new_font.setPointSize (font_size->value ()+default_size); - } - if (attrib_font[0]) - new_font.setBold (attrib_font[0]->isChecked ()); - if (attrib_font[1]) - new_font.setItalic (attrib_font[1]->isChecked ()); - if (attrib_font[2]) - new_font.setUnderline (attrib_font[2]->isChecked ()); - lexer->setFont (new_font, styles[i]); - if (styles[i] == 0) - lexer->setDefaultFont (new_font); - if (color) - lexer->setColor (color->color (), styles[i]); - if (bg_color) - { - if (styles[i] == 0) - { - default_color = bg_color->color (); - lexer->setPaper (default_color, styles[i]); - lexer->setDefaultPaper (default_color); - } - else - { - if (bg_color->color () == settings_color_no_change) - lexer->setPaper (default_color, styles[i]); - else - lexer->setPaper (bg_color->color (), styles[i]); - } - } - } + 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.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.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 ()); - const std::string group = - QString ("Scintilla" + settings_color_modes_ext[mode]).toStdString (); + // command window + 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 (); - lexer->writeSettings (*settings, group.c_str ()); + // the cursor + QString cursor_type; + unsigned int cursor_int = terminal_cursorType->currentIndex (); + 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 (); - settings->setValue (sd_last_editor_styles_tab.key, - tabs_editor_lexers->currentIndex ()); - settings->sync (); -} + settings.setValue (cs_cursor.settings_key (), cursor_type); + +#if defined (HAVE_QSCINTILLA) + // editor styles: create lexer, get dialog contents, and write settings + QsciLexer *lexer; + +#if defined (HAVE_LEXER_OCTAVE) + + lexer = new QsciLexerOctave (); + write_lexer_settings (lexer); + delete lexer; + +#elif defined (HAVE_LEXER_MATLAB) + + lexer = new QsciLexerMatlab (); + write_lexer_settings (lexer); + delete lexer; #endif -void settings_dialog::write_changed_settings (bool closing) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - // the icon set - QString widget_icon_set = "NONE"; - if (general_icon_letter->isChecked ()) - widget_icon_set = "LETTER"; - else if (general_icon_graphic->isChecked ()) - widget_icon_set = "GRAPHIC"; - settings->setValue (dw_icon_set.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); - - // 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); - - // 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 ()); - - // 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 ()); - - // native file dialogs - settings->setValue (global_use_native_dialogs.key, cb_use_native_file_dialogs->isChecked ()); - - // cursor blinking - settings->setValue (global_cursor_blinking.key, cb_cursor_blinking->isChecked ()); + lexer = new QsciLexerCPP (); + write_lexer_settings (lexer); + delete lexer; - // focus follows mouse - settings->setValue (dw_focus_follows_mouse.key, cb_focus_follows_mouse->isChecked ()); - - // promp to exit - settings->setValue (global_prompt_to_exit.key, cb_prompt_to_exit->isChecked ()); - - // status bar - settings->setValue (global_status_bar.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 ()); + lexer = new QsciLexerJava (); + write_lexer_settings (lexer); + delete lexer; - //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 (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 ()); + lexer = new QsciLexerPerl (); + write_lexer_settings (lexer); + delete lexer; - // Comment strings - int rb_uncomment = 0; - for (int i = 0; i < ed_comment_strings_count; i++) - { - if (m_rb_comment_strings[i]->isChecked ()) - { - settings->setValue (ed_comment_str.key, i); - if (i < 3) - settings->setValue (ed_comment_str_old.key, i); - else - settings->setValue (ed_comment_str_old.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); + lexer = new QsciLexerBatch (); + write_lexer_settings (lexer); + delete lexer; - 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 ()); - - // 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 ()); - - // 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 ()); + lexer = new QsciLexerDiff (); + write_lexer_settings (lexer); + delete lexer; - // 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); - - // the cursor - QString cursor_type; - unsigned int cursor_int = terminal_cursorType->currentIndex (); - 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 (); - - settings->setValue (cs_cursor.key, cursor_type); - -#if defined (HAVE_QSCINTILLA) - // editor styles: create lexer, get dialog contents, and write settings - QsciLexer *lexer; - -#if defined (HAVE_LEXER_OCTAVE) - - lexer = new QsciLexerOctave (); - write_lexer_settings (lexer, settings); - delete lexer; - -#elif defined (HAVE_LEXER_MATLAB) + lexer = new QsciLexerBash (); + write_lexer_settings (lexer); + delete lexer; - lexer = new QsciLexerMatlab (); - write_lexer_settings (lexer, settings); - delete lexer; - -#endif - - lexer = new QsciLexerCPP (); - write_lexer_settings (lexer, settings); - delete lexer; - - lexer = new QsciLexerJava (); - write_lexer_settings (lexer, settings); - delete lexer; - - lexer = new QsciLexerPerl (); - write_lexer_settings (lexer, settings); - delete lexer; - - lexer = new QsciLexerBatch (); - write_lexer_settings (lexer, settings); - delete lexer; - - lexer = new QsciLexerDiff (); - write_lexer_settings (lexer, settings); - delete lexer; - - lexer = new QsciLexerBash (); - write_lexer_settings (lexer, settings); - delete lexer; - - lexer = new octave_txt_lexer (); - write_lexer_settings (lexer, settings); - delete lexer; + lexer = new octave_txt_lexer (); + write_lexer_settings (lexer); + delete lexer; #endif - // Workspace - write_workspace_colors (settings); + // Workspace + write_workspace_colors (); + + // Variable editor + 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 (); - // 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); + // shortcuts + + 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 ()); + + shortcuts_treewidget->write_settings (); - // shortcuts + settings.sync (); + } + + void settings_dialog::read_workspace_colors () + { + gui_settings settings; - 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); + // Construct the grid with all color related settings + QGridLayout *style_grid = new QGridLayout (); + QVector description (ws_colors_count); + QVector color (ws_colors_count); - settings->sync (); -} + int column = 0; + const int color_columns = 3; // place colors in so many columns + int row = 0; + 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); -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); - QVector color (ws_colors_count); + m_ws_hide_tool_tips = new QCheckBox (tr ("Hide tools tips")); + style_grid->addWidget (m_ws_hide_tool_tips, row++, column, 1, 4); + connect (m_ws_enable_colors, &QCheckBox::toggled, + m_ws_hide_tool_tips, &QCheckBox::setEnabled); + m_ws_hide_tool_tips->setChecked + (settings.bool_value (ws_hide_tool_tips)); - 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 (); - - m_ws_enable_colors = new QCheckBox (tr ("Enable attribute colors")); - style_grid->addWidget (m_ws_enable_colors, row++, column, 1, 4); + 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.settings_key ()); + connect (m_ws_enable_colors, &QCheckBox::toggled, + cb_color_mode, &QCheckBox::setEnabled); + style_grid->addWidget (cb_color_mode, row, column); - m_ws_hide_tool_tips = new QCheckBox (tr ("Hide tools tips")); - style_grid->addWidget (m_ws_hide_tool_tips, row++, column, 1, 4); - 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 ()); + QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_colors.toStdString ().data ())); + pb_reload_default_colors->setToolTip (tr (settings_reload_colors_tooltip.toStdString ().data ())); + connect (m_ws_enable_colors, &QCheckBox::toggled, + pb_reload_default_colors, &QPushButton::setEnabled); + style_grid->addWidget (pb_reload_default_colors, row+1, column++); + + bool colors_enabled = settings.bool_value (ws_enable_colors); - 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); - connect (m_ws_enable_colors, &QCheckBox::toggled, - cb_color_mode, &QCheckBox::setEnabled); - style_grid->addWidget (cb_color_mode, row, column); + for (int i = 0; i < ws_colors_count; i++) + { + description[i] = new QLabel (" " + + 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); - QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_colors.toStdString ().data ())); - pb_reload_default_colors->setToolTip (tr (settings_reload_colors_tooltip.toStdString ().data ())); - connect (m_ws_enable_colors, &QCheckBox::toggled, - 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 (); + QColor setting_color = settings.color_value (ws_colors[i], mode); + color[i] = new color_picker (setting_color); + 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, + color[i], &color_picker::setEnabled); - for (int i = 0; i < ws_colors_count; i++) - { - description[i] = new QLabel (" " - + 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); + style_grid->addWidget (description[i], row, 3*column); + style_grid->addWidget (color[i], row, 3*column+1); + if (++column > color_columns) + { + style_grid->setColumnStretch (4*column, 10); + row++; + column = 1; + } + } + + // Load enable settings at the end for having signals already connected + m_ws_enable_colors->setChecked (colors_enabled); + m_ws_hide_tool_tips->setEnabled (colors_enabled); + cb_color_mode->setEnabled (colors_enabled); + pb_reload_default_colors->setEnabled (colors_enabled); - 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]->setMinimumSize (30, 10); - color[i]->setEnabled (colors_enabled); - connect (m_ws_enable_colors, &QCheckBox::toggled, - color[i], &color_picker::setEnabled); + // place grid with elements into the tab + workspace_colors_box->setLayout (style_grid); - style_grid->addWidget (description[i], row, 3*column); - style_grid->addWidget (color[i], row, 3*column+1); - if (++column > color_columns) - { - style_grid->setColumnStretch (4*column, 10); - row++; - column = 1; - } - } + // update colors depending on second theme selection or reloading + // the dfault values + connect (cb_color_mode, &QCheckBox::stateChanged, + this, &settings_dialog::update_workspace_colors); + connect (pb_reload_default_colors, &QPushButton::clicked, + [=] () { update_workspace_colors (settings_reload_default_colors_flag); }); + } + + void settings_dialog::update_workspace_colors (int def) + { + QCheckBox *cb_color_mode + = workspace_colors_box->findChild (ws_color_mode.settings_key ()); + + int m = 0; + if (cb_color_mode && cb_color_mode->isChecked ()) + m = 1; - // Load enable settings at the end for having signals already connected - m_ws_enable_colors->setChecked (colors_enabled); - m_ws_hide_tool_tips->setEnabled (colors_enabled); - cb_color_mode->setEnabled (colors_enabled); - pb_reload_default_colors->setEnabled (colors_enabled); + gui_settings settings; + + color_picker *c_picker; - // place grid with elements into the tab - workspace_colors_box->setLayout (style_grid); + for (unsigned int i = 0; i < ws_colors_count; i++) + { + 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)); + } + else + { + // Get the default value + c_picker->set_color (settings.get_color_value (ws_colors[i].def (), m)); + } + } + } + } + + void settings_dialog::write_workspace_colors () + { + gui_settings settings; - // update colors depending on second theme selection or reloading - // the dfault values - connect (cb_color_mode, &QCheckBox::stateChanged, - this, &settings_dialog::update_workspace_colors); - connect (pb_reload_default_colors, &QPushButton::clicked, - [=] () { update_workspace_colors (settings_reload_default_colors_flag); }); -} + 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.settings_key ()); + + int mode = 0; + if (cb_color_mode && cb_color_mode->isChecked ()) + mode = 1; + + color_picker *color; -void settings_dialog::update_workspace_colors (int def) -{ - QCheckBox *cb_color_mode - = workspace_colors_box->findChild (ws_color_mode.key); + for (int i = 0; i < ws_colors_count; i++) + { + color = workspace_colors_box->findChild (ws_colors[i].settings_key ()); + if (color) + settings.set_color_value (ws_colors[i], color->color (), mode); + } - int m = 0; - if (cb_color_mode && cb_color_mode->isChecked ()) - m = 1; + settings.setValue (ws_color_mode.settings_key (), mode); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + settings.sync (); + } - color_picker *c_picker; + void settings_dialog::read_terminal_colors () + { + gui_settings settings; - for (unsigned int i = 0; i < ws_colors_count; i++) - { - c_picker = workspace_colors_box->findChild (ws_colors[i].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)); - } - else - { - // Get the default value - c_picker->set_color (settings->get_color_value (ws_colors[i].def, m)); - } - } - } -} + QGridLayout *style_grid = new QGridLayout (); + QVector description (cs_colors_count); + QVector color (cs_colors_count); + + int mode = settings.int_value (cs_color_mode); -void settings_dialog::write_workspace_colors (gui_settings *settings) -{ - settings->setValue (ws_enable_colors.key, m_ws_enable_colors->isChecked ()); - settings->setValue (ws_hide_tool_tips.key, m_ws_hide_tool_tips->isChecked ()); + 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.settings_key ()); + style_grid->addWidget (cb_color_mode, 0, 0); - QCheckBox *cb_color_mode - = workspace_colors_box->findChild (ws_color_mode.key); - - int mode = 0; - if (cb_color_mode && cb_color_mode->isChecked ()) - mode = 1; + QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_colors.toStdString ().data ())); + pb_reload_default_colors->setToolTip (tr (settings_reload_colors_tooltip.toStdString ().data ())); + style_grid->addWidget (pb_reload_default_colors, 1, 0); - color_picker *color; - - for (int i = 0; i < ws_colors_count; i++) - { - color = workspace_colors_box->findChild (ws_colors[i].key); - if (color) - settings->set_color_value (ws_colors[i], color->color (), mode); - } - - settings->setValue (ws_color_mode.key, mode); - - settings->sync (); -} + int column = 1; // column 0 is for the color mode checkbox + const int color_columns = 2; // place colors in so many columns + int row = 0; + for (unsigned int i = 0; i < cs_colors_count; i++) + { + description[i] = new QLabel (" " + + tr (cs_color_names.at (i).toStdString ().data ())); + description[i]->setAlignment (Qt::AlignRight); + QColor setting_color = settings.color_value (cs_colors[i], mode); + color[i] = new color_picker (setting_color); + 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); + if (++column > color_columns) + { + style_grid->setColumnStretch (3*column, 10); + row++; + column = 1; + } + } -void settings_dialog::read_terminal_colors (gui_settings *settings) -{ - QGridLayout *style_grid = new QGridLayout (); - QVector description (cs_colors_count); - QVector color (cs_colors_count); + // place grid with elements into the tab + terminal_colors_box->setLayout (style_grid); - int mode = settings->value (cs_color_mode).toInt (); + // update colors depending on second theme selection + connect (cb_color_mode, &QCheckBox::stateChanged, + this, &settings_dialog::update_terminal_colors); + connect (pb_reload_default_colors, &QPushButton::clicked, + [=] () { update_terminal_colors (settings_reload_default_colors_flag); }); + } - 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); - style_grid->addWidget (cb_color_mode, 0, 0); + void settings_dialog::update_terminal_colors (int def) + { + QCheckBox *cb_color_mode + = terminal_colors_box->findChild (cs_color_mode.settings_key ()); - QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_colors.toStdString ().data ())); - pb_reload_default_colors->setToolTip (tr (settings_reload_colors_tooltip.toStdString ().data ())); - style_grid->addWidget (pb_reload_default_colors, 1, 0); + int m = 0; + if (cb_color_mode && cb_color_mode->isChecked ()) + m = 1; + + gui_settings settings; + + color_picker *c_picker; - int column = 1; // column 0 is for the color mode checkbox - const int color_columns = 2; // place colors in so many columns - int row = 0; - for (unsigned int i = 0; i < cs_colors_count; i++) - { - description[i] = new QLabel (" " - + tr (cs_color_names.at (i).toStdString ().data ())); - description[i]->setAlignment (Qt::AlignRight); - 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]->setMinimumSize (30, 10); - style_grid->addWidget (description[i], row, 2*column); - style_grid->addWidget (color[i], row, 2*column+1); - if (++column > color_columns) - { - style_grid->setColumnStretch (3*column, 10); - row++; - column = 1; - } - } + for (unsigned int i = 0; i < cs_colors_count; i++) + { + 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)); + } + else + { + // Get the default value + c_picker->set_color (settings.get_color_value (cs_colors[i].def (), m)); + } + } + } + } + + void settings_dialog::write_terminal_colors () + { + QCheckBox *cb_color_mode + = terminal_colors_box->findChild (cs_color_mode.settings_key ()); - // place grid with elements into the tab - terminal_colors_box->setLayout (style_grid); + int mode = 0; + if (cb_color_mode && cb_color_mode->isChecked ()) + mode = 1; + + gui_settings settings; - // update colors depending on second theme selection - connect (cb_color_mode, &QCheckBox::stateChanged, - this, &settings_dialog::update_terminal_colors); - connect (pb_reload_default_colors, &QPushButton::clicked, - [=] () { update_terminal_colors (settings_reload_default_colors_flag); }); -} + color_picker *color; + + for (int i = 0; i < cs_color_names.size (); i++) + { + color = terminal_colors_box->findChild (cs_colors[i].settings_key ()); + if (color) + settings.set_color_value (cs_colors[i], color->color (), mode); + } -void settings_dialog::update_terminal_colors (int def) -{ - QCheckBox *cb_color_mode - = terminal_colors_box->findChild (cs_color_mode.key); + settings.setValue (cs_color_mode.settings_key (), mode); + + settings.sync (); + } - int m = 0; - if (cb_color_mode && cb_color_mode->isChecked ()) - m = 1; + void settings_dialog::read_varedit_colors () + { + gui_settings settings; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + QGridLayout *style_grid = new QGridLayout (); + QVector description (ve_colors_count); + QVector color (ve_colors_count); - color_picker *c_picker; + int mode = settings.int_value (ve_color_mode); - for (unsigned int i = 0; i < cs_colors_count; i++) - { - c_picker = terminal_colors_box->findChild (cs_colors[i].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)); - } - else - { - // Get the default value - c_picker->set_color (settings->get_color_value (cs_colors[i].def, m)); - } - } - } -} + 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.settings_key ()); + style_grid->addWidget (cb_color_mode, 0, 0); -void settings_dialog::write_terminal_colors (gui_settings *settings) -{ - QCheckBox *cb_color_mode - = terminal_colors_box->findChild (cs_color_mode.key); + QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_colors.toStdString ().data ())); + pb_reload_default_colors->setToolTip (tr (settings_reload_colors_tooltip.toStdString ().data ())); + style_grid->addWidget (pb_reload_default_colors, 1, 0); + + int column = 1; + int color_columns = 2; + int row = 0; + for (int i = 0; i < ve_colors_count; i++) + { + description[i] = new QLabel (" " + + tr (ve_color_names.at (i).toStdString ().data ())); + description[i]->setAlignment (Qt::AlignRight); - int mode = 0; - if (cb_color_mode && cb_color_mode->isChecked ()) - mode = 1; - - color_picker *color; + QColor setting_color = settings.color_value (ve_colors[i], mode); + color[i] = new color_picker (setting_color); + 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); + if (++column > color_columns) + { + style_grid->setColumnStretch (3*column, 10); + row++; + column = 1; + } + } - for (int i = 0; i < cs_color_names.size (); i++) - { - color = terminal_colors_box->findChild (cs_colors[i].key); - if (color) - settings->set_color_value (cs_colors[i], color->color (), mode); - } + // place grid with elements into the tab + varedit_colors_box->setLayout (style_grid); - settings->setValue (cs_color_mode.key, mode); - - settings->sync (); -} + // update colors depending on second theme selection + connect (cb_color_mode, &QCheckBox::stateChanged, + this, &settings_dialog::update_varedit_colors); + connect (pb_reload_default_colors, &QPushButton::clicked, + [=] () { update_varedit_colors (settings_reload_default_colors_flag); }); + } -void settings_dialog::read_varedit_colors (gui_settings *settings) -{ - QGridLayout *style_grid = new QGridLayout (); - QVector description (ve_colors_count); - QVector color (ve_colors_count); + void settings_dialog::update_varedit_colors (int def) + { + QCheckBox *cb_color_mode + = varedit_colors_box->findChild (ve_color_mode.settings_key ()); - int mode = settings->value (ve_color_mode).toInt (); + int m = 0; + if (cb_color_mode && cb_color_mode->isChecked ()) + m = 1; + + gui_settings settings; + + color_picker *c_picker; - 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); - style_grid->addWidget (cb_color_mode, 0, 0); + for (unsigned int i = 0; i < ve_colors_count; i++) + { + 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)); + } + else + { + // Get the default value + c_picker->set_color (settings.get_color_value (ve_colors[i].def (), m)); + } + } + } + } - QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_colors.toStdString ().data ())); - pb_reload_default_colors->setToolTip (tr (settings_reload_colors_tooltip.toStdString ().data ())); - style_grid->addWidget (pb_reload_default_colors, 1, 0); + void settings_dialog::write_varedit_colors () + { + QCheckBox *cb_color_mode + = varedit_colors_box->findChild (ve_color_mode.settings_key ()); - int column = 1; - int color_columns = 2; - int row = 0; - for (int i = 0; i < ve_colors_count; i++) - { - description[i] = new QLabel (" " - + tr (ve_color_names.at (i).toStdString ().data ())); - description[i]->setAlignment (Qt::AlignRight); + int mode = 0; + if (cb_color_mode && cb_color_mode->isChecked ()) + mode = 1; + + gui_settings settings; - 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]->setMinimumSize (30, 10); - style_grid->addWidget (description[i], row, 2*column); - style_grid->addWidget (color[i], row, 2*column+1); - if (++column > color_columns) - { - style_grid->setColumnStretch (3*column, 10); - row++; - column = 1; - } - } + color_picker *color; + + for (int i = 0; i < ve_colors_count; i++) + { + color = varedit_colors_box->findChild (ve_colors[i].settings_key ()); + if (color) + settings.set_color_value (ve_colors[i], color->color (), mode); + } + + settings.setValue (ve_color_mode.settings_key (), mode); + + settings.sync (); + } - // place grid with elements into the tab - varedit_colors_box->setLayout (style_grid); + 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; - // update colors depending on second theme selection - connect (cb_color_mode, &QCheckBox::stateChanged, - this, &settings_dialog::update_varedit_colors); - connect (pb_reload_default_colors, &QPushButton::clicked, - [=] () { update_varedit_colors (settings_reload_default_colors_flag); }); -} + if (! settings.bool_value (global_use_native_dialogs)) + opts = QFileDialog::DontUseNativeDialog; -void settings_dialog::update_varedit_colors (int def) -{ - QCheckBox *cb_color_mode - = varedit_colors_box->findChild (ve_color_mode.key); + 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)); - int m = 0; - if (cb_color_mode && cb_color_mode->isChecked ()) - m = 1; + 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. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + // 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). - color_picker *c_picker; + bool settings_dialog::overwrite_all_shortcuts () + { + QMessageBox msg_box; - for (unsigned int i = 0; i < ve_colors_count; i++) - { - c_picker = varedit_colors_box->findChild (ve_colors[i].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)); - } - else - { - // Get the default value - c_picker->set_color (settings->get_color_value (ve_colors[i].def, m)); - } - } - } -} + 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; -void settings_dialog::write_varedit_colors (gui_settings *settings) -{ - QCheckBox *cb_color_mode - = varedit_colors_box->findChild (ve_color_mode.key); + if (ret == QMessageBox::Save) + { + QString file = get_shortcuts_file_name (OSC_EXPORT); - int mode = 0; - if (cb_color_mode && cb_color_mode->isChecked ()) - mode = 1; - - color_picker *color; + gui_settings osc_settings (file, QSettings::IniFormat); - for (int i = 0; i < ve_colors_count; i++) - { - color = varedit_colors_box->findChild (ve_colors[i].key); - if (color) - settings->set_color_value (ve_colors[i], color->color (), mode); - } + 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)); + } - settings->setValue (ve_color_mode.key, mode); - - settings->sync (); -} + return false; + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/settings-dialog.h --- a/libgui/src/settings-dialog.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/settings-dialog.h Mon Jan 30 18:36:03 2023 +0100 @@ -33,86 +33,93 @@ #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. + // Ui::settings_dialog is a generated class. -class settings_dialog : public QDialog, private Ui::settings_dialog -{ - Q_OBJECT public: + class settings_dialog : public QDialog, private Ui::settings_dialog + { + Q_OBJECT + + public: - explicit settings_dialog (QWidget *parent, base_qobject& octave_qobj, - const QString& desired_tab = QString ()); + explicit settings_dialog (QWidget *parent, + const QString& desired_tab = QString ()); - ~settings_dialog (void) = default; + ~settings_dialog () = default; - void show_tab (const QString&); + void show_tab (const QString&); -signals: + signals: - void apply_new_settings (void); + void apply_new_settings (); -private slots: + private slots: - void get_octave_dir (void); - void get_file_browser_dir (void); - void get_dir (QLineEdit *, const QString&); - void set_disabled_pref_file_browser_dir (bool disable); - void proxy_items_update (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 (); + + // slots updating colors depending on theme + void update_terminal_colors (int def = 0); + void update_workspace_colors (int def = 0); + void update_varedit_colors (int def = 0); + void update_editor_lexers (int def = 0); - // slots updating colors depending on theme - void update_terminal_colors (int def = 0); - void update_workspace_colors (int def = 0); - void update_varedit_colors (int def = 0); - void update_editor_lexers (int def = 0); + // slots for dialog's buttons + void button_clicked (QAbstractButton *button); + + // slots for import/export-buttons of shortcut sets + void import_shortcut_set (); + void export_shortcut_set (); + void default_shortcut_set (); - // slots for dialog's buttons - void button_clicked (QAbstractButton *button); + private: - // slots for import/export-buttons of shortcut sets - void import_shortcut_set (void); - void export_shortcut_set (void); - void default_shortcut_set (void); - -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 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 (gui_settings *settings); - void write_terminal_colors (gui_settings *settings); + void read_terminal_colors (); + void write_terminal_colors (); - void read_varedit_colors (gui_settings *settings); - void write_varedit_colors (gui_settings *settings); + void read_varedit_colors (); + void write_varedit_colors (); + + QString get_shortcuts_file_name (import_export_action action); - base_qobject& m_octave_qobj; + bool overwrite_all_shortcuts (); - color_picker *m_widget_title_bg_color; - color_picker *m_widget_title_bg_color_active; - color_picker *m_widget_title_fg_color; - color_picker *m_widget_title_fg_color_active; + color_picker *m_widget_title_bg_color; + color_picker *m_widget_title_bg_color_active; + color_picker *m_widget_title_fg_color; + color_picker *m_widget_title_fg_color_active; - QRadioButton *m_rb_comment_strings[ed_comment_strings_count]; - QCheckBox *m_rb_uncomment_strings[ed_comment_strings_count]; + QRadioButton *m_rb_comment_strings[ed_comment_strings_count]; + QCheckBox *m_rb_uncomment_strings[ed_comment_strings_count]; - QCheckBox *m_ws_enable_colors; - QCheckBox *m_ws_hide_tool_tips; -}; + QCheckBox *m_ws_enable_colors; + QCheckBox *m_ws_hide_tool_tips; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/settings-dialog.ui Mon Jan 30 18:36:03 2023 +0100 @@ -2681,7 +2681,7 @@ 0 - + 0 @@ -2959,6 +2959,13 @@ + + + octave::shortcuts_tree_widget + QTreeWidget +
shortcuts-tree-widget.h
+
+
diff -r 17d568574e1c -r 7860fcc69082 libgui/src/shortcut-manager.cc --- a/libgui/src/shortcut-manager.cc Mon Jan 30 18:30:33 2023 +0100 +++ /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 17d568574e1c -r 7860fcc69082 libgui/src/shortcut-manager.h --- a/libgui/src/shortcut-manager.h Mon Jan 30 18:30:33 2023 +0100 +++ /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 17d568574e1c -r 7860fcc69082 libgui/src/shortcuts-tree-widget.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/shortcuts-tree-widget.cc Mon Jan 30 18:36:03 2023 +0100 @@ -0,0 +1,709 @@ +//////////////////////////////////////////////////////////////////////// +// +// 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 17d568574e1c -r 7860fcc69082 libgui/src/shortcuts-tree-widget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/shortcuts-tree-widget.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/tab-bar.cc --- a/libgui/src/tab-bar.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/tab-bar.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/tab-bar.h --- a/libgui/src/tab-bar.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/tab-bar.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libgui/src/terminal-dock-widget.cc --- a/libgui/src/terminal-dock-widget.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/terminal-dock-widget.cc Mon Jan 30 18:36:03 2023 +0100 @@ -27,6 +27,7 @@ # include "config.h" #endif +#include #include // This header is only needed for the new terminal widget. @@ -39,133 +40,177 @@ #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 ()) -{ - // 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) - { + terminal_dock_widget::terminal_dock_widget (QWidget *p, + 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); - console *con = widget->get_console (); + command_widget *widget = new command_widget (this); + console *con = widget->get_console (); - connect (this, &terminal_dock_widget::settings_changed, - widget, &command_widget::notice_settings); + connect (this, &terminal_dock_widget::settings_changed, + widget, &command_widget::notice_settings); - connect (this, &terminal_dock_widget::update_prompt_signal, - widget, &command_widget::update_prompt); + connect (this, &terminal_dock_widget::update_prompt_signal, + widget, &command_widget::update_prompt); - connect (this, &terminal_dock_widget::interpreter_output_signal, - widget, &command_widget::insert_interpreter_output); + connect (this, &terminal_dock_widget::interpreter_output_signal, + widget, &command_widget::insert_interpreter_output); - connect (this, &terminal_dock_widget::execute_command_signal, - con, &console::execute_command); + connect (this, &terminal_dock_widget::execute_command_signal, + con, &console::execute_command); - connect (this, &terminal_dock_widget::new_command_line_signal, - con, &console::new_command_line); + connect (this, &terminal_dock_widget::new_command_line_signal, + con, &console::new_command_line); - m_terminal = widget; + m_terminal = widget; #endif - } - else - { - QTerminal *widget = QTerminal::create (oct_qobj, this); + } + else + { + QTerminal *widget = QTerminal::create (this); - connect (this, &terminal_dock_widget::settings_changed, - widget, &QTerminal::notice_settings); + connect (this, &terminal_dock_widget::settings_changed, + widget, &QTerminal::notice_settings); - // Connect the visibility signal to the terminal for - // dis-/enabling timers. - connect (this, &terminal_dock_widget::visibilityChanged, - widget, &QTerminal::handle_visibility_changed); + // Connect the visibility signal to the terminal for + // dis-/enabling timers. + connect (this, &terminal_dock_widget::visibilityChanged, + widget, &QTerminal::handle_visibility_changed); - m_terminal = widget; - } + connect (widget, QOverload::of (&QTerminal::interpreter_event), + this, QOverload::of (&terminal_dock_widget::interpreter_event)); - m_terminal->setObjectName ("OctaveTerminal"); - m_terminal->setFocusPolicy (Qt::StrongFocus); + connect (widget, QOverload::of (&QTerminal::interpreter_event), + this, QOverload::of (&terminal_dock_widget::interpreter_event)); - set_title (tr ("Command Window")); - - setWidget (m_terminal); - setFocusProxy (m_terminal); + m_terminal = widget; + } - // 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 (); + m_terminal->setObjectName ("OctaveTerminal"); + m_terminal->setFocusPolicy (Qt::StrongFocus); + + set_title (tr ("Command Window")); + + setWidget (m_terminal); + setFocusProxy (m_terminal); - QFont font = QFont (); - font.setStyleHint (QFont::TypeWriter); - QString default_font = settings->value (global_mono_font).toString (); - font.setFamily - (settings->value (cs_font.key, default_font).toString ()); - font.setPointSize - (settings->value (cs_font_size).toInt ()); + // Chose a reasonable size at startup in order to avoid truncated + // startup messages + + gui_settings settings; - QFontMetrics metrics(font); + QFont font = QFont (); + font.setStyleHint (QFont::TypeWriter); + QString default_font = settings.string_value (global_mono_font); + font.setFamily + (settings.value (cs_font.settings_key (), default_font).toString ()); + font.setPointSize + (settings.int_value (cs_font_size)); - int win_x = metrics.maxWidth()*80; - int win_y = metrics.height()*25; + QFontMetrics metrics(font); - int max_x = QGuiApplication::primaryScreen ()->availableGeometry ().width (); - int max_y = QGuiApplication::primaryScreen ()->availableGeometry ().height (); + int win_x = metrics.maxWidth()*80; + int win_y = metrics.height()*25; + + int max_x = QGuiApplication::primaryScreen ()->availableGeometry ().width (); + int max_y = QGuiApplication::primaryScreen ()->availableGeometry ().height (); - if (win_x > max_x) - win_x = max_x; - if (win_y > max_y) - win_y = max_y; + if (win_x > max_x) + win_x = max_x; + if (win_y > max_y) + win_y = max_y; - setGeometry (0, 0, win_x, win_y); + setGeometry (0, 0, win_x, win_y); - if (! p) - make_window (); -} + if (! p) + make_window (); + } -bool terminal_dock_widget::has_focus (void) const -{ - QWidget *w = widget (); - return w->hasFocus (); -} + bool terminal_dock_widget::has_focus () const + { + QWidget *w = widget (); + return w->hasFocus (); + } -QTerminal * terminal_dock_widget::get_qterminal (void) -{ - return (m_experimental_terminal_widget - ? nullptr : dynamic_cast (m_terminal)); -} + 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) -{ - return (m_experimental_terminal_widget - ? dynamic_cast (m_terminal) : nullptr); -} + 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) -{ - emit settings_changed (settings); -} + void terminal_dock_widget::notice_settings () + { + emit settings_changed (); + } + + void terminal_dock_widget::init_command_prompt () + { + if (m_experimental_terminal_widget) + { +#if defined (HAVE_QSCINTILLA) + command_widget *cmd = get_command_widget (); + if (cmd) + cmd->init_command_prompt (); +#endif + } + } + + 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); -void terminal_dock_widget::init_command_prompt () -{ - if (m_experimental_terminal_widget) - { -#if defined (HAVE_QSCINTILLA) - command_widget *cmd = get_command_widget (); - if (cmd) - cmd->init_command_prompt (); -#endif - } -} + 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 17d568574e1c -r 7860fcc69082 libgui/src/terminal-dock-widget.h --- a/libgui/src/terminal-dock-widget.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/terminal-dock-widget.h Mon Jan 30 18:36:03 2023 +0100 @@ -34,61 +34,66 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class command_widget; -class base_qobject; + class command_widget; + + class terminal_dock_widget : public octave_dock_widget + { + Q_OBJECT -class terminal_dock_widget : public octave_dock_widget -{ - Q_OBJECT + public: -public: + terminal_dock_widget (QWidget *parent, + bool experimental_terminal_widget = false); - terminal_dock_widget (QWidget *parent, base_qobject& oct_qobj); + ~terminal_dock_widget () = default; - ~terminal_dock_widget (void) = default; + bool has_focus () const; - bool has_focus (void) const; + void init_command_prompt (); - 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. + // 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); + // Only valid if using the old terminal widget. + QTerminal * get_qterminal (); #if defined (HAVE_QSCINTILLA) - // Only valid if using the new terminal widget. - command_widget * get_command_widget (void); + // Only valid if using the new terminal widget. + command_widget * get_command_widget (); #endif -signals: + 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. - // Note: the following four signals are - // currently only used by the new experimental terminal widget. + void update_prompt_signal (const QString&); + + void interpreter_output_signal (const QString&); - void update_prompt_signal (const QString&); + void new_command_line_signal (const QString& = QString ()); - void interpreter_output_signal (const QString&); - - void new_command_line_signal (const QString& = QString ()); + void execute_command_signal (const QString&); - void execute_command_signal (const QString&); + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); -public slots: + public slots: - void notice_settings (const gui_settings *settings); + void notice_settings (); -private: + private: - bool m_experimental_terminal_widget; + bool m_experimental_terminal_widget; - // FIXME!!! Maybe my_term should just be derived from QTerminal? - QWidget *m_terminal; -}; + // FIXME!!! Maybe my_term should just be derived from QTerminal? + QWidget *m_terminal; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/variable-editor-model.cc --- a/libgui/src/variable-editor-model.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/variable-editor-model.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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,7 +330,7 @@ maybe_resize_columns (m_data_cols + 16); } - ~numeric_model (void) = default; + ~numeric_model () = default; // No copying! @@ -394,7 +394,7 @@ m_display_cols = 1; } - ~string_model (void) = default; + ~string_model () = default; // No copying! @@ -431,7 +431,7 @@ maybe_resize_columns (m_data_cols + 16); } - ~cell_model (void) = default; + ~cell_model () = default; // No copying! @@ -532,7 +532,7 @@ m_display_cols = 1; } - ~scalar_struct_model (void) = default; + ~scalar_struct_model () = default; // No copying! @@ -655,7 +655,7 @@ m_display_cols = m_data_cols; } - ~display_only_model (void) = default; + ~display_only_model () = default; // No copying! @@ -663,7 +663,7 @@ 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 +679,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,7 +706,7 @@ m_display_cols = m_data_cols; } - ~vector_struct_model (void) = default; + ~vector_struct_model () = default; // No copying! @@ -839,7 +839,7 @@ maybe_resize_columns (m_data_cols + 16); } - ~struct_model (void) = default; + ~struct_model () = default; // No copying! @@ -1255,7 +1255,7 @@ } void -variable_editor_model::update_data_cache (void) +variable_editor_model::update_data_cache () { emit interpreter_event ([=] (interpreter& interp) @@ -1383,7 +1383,7 @@ } void -variable_editor_model::invalidate (void) +variable_editor_model::invalidate () { beginResetModel (); diff -r 17d568574e1c -r 7860fcc69082 libgui/src/variable-editor-model.h --- a/libgui/src/variable-editor-model.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/variable-editor-model.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,7 +45,7 @@ base_ve_model (const QString& expr, const octave_value& val); - virtual ~base_ve_model (void) = default; + virtual ~base_ve_model () = default; // No copying! @@ -57,15 +57,15 @@ 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 +85,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 +98,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,7 +145,7 @@ variable_editor_model (const QString& expr, const octave_value& val, QObject *parent = nullptr); - ~variable_editor_model (void) + ~variable_editor_model () { delete rep; } @@ -156,12 +156,12 @@ variable_editor_model& operator = (const variable_editor_model&) = delete; - std::string name (void) const + std::string name () const { return rep->name (); } - bool is_editable (void) const + bool is_editable () const { return rep->is_editable (); } @@ -171,7 +171,7 @@ return rep->value_at (idx); } - int column_width (void) const + int column_width () const { return rep->column_width (); } @@ -233,7 +233,7 @@ return rep->update_pending_data (idx); } - void clear_update_pending (void) + void clear_update_pending () { rep->clear_update_pending (); } @@ -258,22 +258,22 @@ return rep->subscript_expression (idx); } - int display_rows (void) const + int display_rows () const { return rep->display_rows (); } - octave_idx_type data_rows (void) const + octave_idx_type data_rows () const { return rep->data_rows (); } - int display_columns (void) const + int display_columns () const { return rep->display_columns (); } - octave_idx_type data_columns (void) const + octave_idx_type data_columns () const { return rep->data_columns (); } @@ -303,7 +303,7 @@ void update_data (const octave_value& val); - void update_data_cache (void); + void update_data_cache (); void double_click (const QModelIndex& idx); @@ -323,7 +323,7 @@ octave_value retrieve_variable (interpreter&, const std::string& name); - bool is_valid (void) const + bool is_valid () const { return rep->is_valid (); } @@ -331,14 +331,14 @@ 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 (); } void reset (const octave_value& val); - void invalidate (void); + void invalidate (); void update_description (const QString& description = QString ()); diff -r 17d568574e1c -r 7860fcc69082 libgui/src/variable-editor.cc --- a/libgui/src/variable-editor.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/variable-editor.cc Mon Jan 30 18:36:03 2023 +0100 @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -55,1742 +56,1734 @@ #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" OCTAVE_BEGIN_NAMESPACE(octave) -// Code reuse functions + // Code reuse functions -static QSignalMapper * -make_plot_mapper (QMenu *menu) -{ - QList list; - list << "plot" << "bar" << "stem" << "stairs" << "area" << "pie" << "hist"; + static QSignalMapper * + make_plot_mapper (QMenu *menu) + { + QList list; + list << "plot" << "bar" << "stem" << "stairs" << "area" << "pie" << "hist"; - QSignalMapper *plot_mapper = new QSignalMapper (menu); + QSignalMapper *plot_mapper = new QSignalMapper (menu); - for (int i = 0; i < list.size(); ++i) - plot_mapper->setMapping - (menu->addAction (list.at (i), plot_mapper, SLOT (map ())), list.at (i)); + for (int i = 0; i < list.size(); ++i) + plot_mapper->setMapping + (menu->addAction (list.at (i), plot_mapper, SLOT (map ())), list.at (i)); - return plot_mapper; -} - -// Variable dock widget + return plot_mapper; + } -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::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); - setAttribute (Qt::WA_DeleteOnClose); + { + setFocusPolicy (Qt::StrongFocus); + setAttribute (Qt::WA_DeleteOnClose); - connect (m_dock_action, &QAction::triggered, - this, &variable_dock_widget::change_floating); - connect (m_close_action, &QAction::triggered, - this, &variable_dock_widget::change_existence); - connect (this, &variable_dock_widget::topLevelChanged, - this, &variable_dock_widget::toplevel_change); + connect (m_dock_action, &QAction::triggered, + this, &variable_dock_widget::change_floating); + connect (m_close_action, &QAction::triggered, + this, &variable_dock_widget::change_existence); + connect (this, &variable_dock_widget::topLevelChanged, + this, &variable_dock_widget::toplevel_change); #define DOCKED_FULLSCREEN_BUTTON_TOOLTIP "Fullscreen undock" #define UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP "Fullscreen" - // Add a fullscreen button + // Add a fullscreen button - m_fullscreen_action = nullptr; - m_full_screen = false; - m_prev_floating = false; - m_prev_geom = QRect (0, 0, 0, 0); + m_fullscreen_action = nullptr; + m_full_screen = false; + m_prev_floating = false; + m_prev_geom = QRect (0, 0, 0, 0); + + QHBoxLayout *h_layout = m_title_widget->findChild (); - QHBoxLayout *h_layout = m_title_widget->findChild (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - m_fullscreen_action - = new QAction (rmgr.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); - fullscreen_button->setFocusPolicy (Qt::NoFocus); - fullscreen_button->setIconSize (QSize (m_icon_size, m_icon_size)); - QString css_button = QString ("QToolButton {background: transparent; border: 0px;}"); - fullscreen_button->setStyleSheet (css_button); + gui_settings settings; + m_fullscreen_action + = 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); + fullscreen_button->setFocusPolicy (Qt::NoFocus); + fullscreen_button->setIconSize (QSize (m_icon_size, m_icon_size)); + QString css_button = QString ("QToolButton {background: transparent; border: 0px;}"); + fullscreen_button->setStyleSheet (css_button); - connect (m_fullscreen_action, &QAction::triggered, - this, &variable_dock_widget::change_fullscreen); + connect (m_fullscreen_action, &QAction::triggered, + this, &variable_dock_widget::change_fullscreen); - int index = -1; - QToolButton *first = m_title_widget->findChild (); - if (first != nullptr) - index = h_layout->indexOf (first); - h_layout->insertWidget (index, fullscreen_button); + int index = -1; + QToolButton *first = m_title_widget->findChild (); + if (first != nullptr) + index = h_layout->indexOf (first); + h_layout->insertWidget (index, fullscreen_button); - // Custom title bars cause loss of decorations, add a frame - m_frame = new QFrame (this); - m_frame->setFrameStyle (QFrame::Box | QFrame::Sunken); - m_frame->setAttribute (Qt::WA_TransparentForMouseEvents); -} + // Custom title bars cause loss of decorations, add a frame + m_frame = new QFrame (this); + m_frame->setFrameStyle (QFrame::Box | QFrame::Sunken); + m_frame->setAttribute (Qt::WA_TransparentForMouseEvents); + } -// slot for (un)dock action -void -variable_dock_widget::change_floating (bool) -{ - if (isFloating ()) - { - 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)); - m_full_screen = false; - } - m_fullscreen_action->setToolTip (tr (DOCKED_FULLSCREEN_BUTTON_TOOLTIP)); - } - else - m_fullscreen_action->setToolTip (tr (UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP)); + // slot for (un)dock action + void + variable_dock_widget::change_floating (bool) + { + if (isFloating ()) + { + if (m_full_screen) + { + setGeometry (m_prev_geom); + 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)); + } + else + m_fullscreen_action->setToolTip (tr (UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP)); - setFloating (! isFloating ()); -} + setFloating (! isFloating ()); + } -// slot for hiding the widget -void -variable_dock_widget::change_existence (bool) -{ - close (); -} + // slot for hiding the widget + void + variable_dock_widget::change_existence (bool) + { + close (); + } -void -variable_dock_widget::toplevel_change (bool toplevel) -{ - if (toplevel) - { - m_dock_action->setIcon (QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) - + "widget-dock.png")); - m_dock_action->setToolTip (tr ("Dock widget")); + void + variable_dock_widget::toplevel_change (bool toplevel) + { + if (toplevel) + { + m_dock_action->setIcon (QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) + + "widget-dock.png")); + m_dock_action->setToolTip (tr ("Dock widget")); - setWindowFlags (Qt::Window); - setWindowTitle (tr ("Variable Editor: ") + objectName ()); + setWindowFlags (Qt::Window); + setWindowTitle (tr ("Variable Editor: ") + objectName ()); - show (); - activateWindow (); - setFocus (); + show (); + 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; + m_waiting_for_mouse_move = true; #endif - } - else - { - m_dock_action->setIcon (QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) - + "widget-undock.png")); - m_dock_action->setToolTip (tr ("Undock widget")); + } + else + { + m_dock_action->setIcon (QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) + + "widget-undock.png")); + m_dock_action->setToolTip (tr ("Undock widget")); - setFocus (); + 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; + m_waiting_for_mouse_move = false; + m_waiting_for_mouse_button_release = false; #endif - } -} + } + } -void -variable_dock_widget::change_fullscreen (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + void + variable_dock_widget::change_fullscreen () + { + gui_settings settings; - if (! m_full_screen) - { - m_prev_floating = isFloating (); - m_fullscreen_action->setIcon (rmgr.icon ("view-restore", false)); - if (m_prev_floating) - m_fullscreen_action->setToolTip (tr ("Restore geometry")); - else - { - m_fullscreen_action->setToolTip (tr ("Redock")); - setFloating (true); - } - m_prev_geom = geometry (); + if (! m_full_screen) + { + m_prev_floating = isFloating (); + m_fullscreen_action->setIcon (settings.icon ("view-restore", false)); + if (m_prev_floating) + m_fullscreen_action->setToolTip (tr ("Restore geometry")); + else + { + m_fullscreen_action->setToolTip (tr ("Redock")); + setFloating (true); + } + m_prev_geom = geometry (); - // showFullscreen() and setWindowState() only work for QWindow objects. - QScreen *pscreen = QGuiApplication::primaryScreen (); - QRect rect (0, 0, 0, 0); - rect = pscreen->availableGeometry (); - setGeometry (rect); + // showFullscreen() and setWindowState() only work for QWindow objects. + QScreen *pscreen = QGuiApplication::primaryScreen (); + QRect rect (0, 0, 0, 0); + rect = pscreen->availableGeometry (); + setGeometry (rect); - m_full_screen = true; - } - else - { - m_fullscreen_action->setIcon (rmgr.icon ("view-fullscreen", false)); - setGeometry (m_prev_geom); - if (m_prev_floating) - m_fullscreen_action->setToolTip (tr (UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP)); - else - { - setFloating (false); - m_fullscreen_action->setToolTip (tr (DOCKED_FULLSCREEN_BUTTON_TOOLTIP)); - } + m_full_screen = true; + } + else + { + 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)); + else + { + setFloating (false); + m_fullscreen_action->setToolTip (tr (DOCKED_FULLSCREEN_BUTTON_TOOLTIP)); + } - m_full_screen = false; - } + m_full_screen = false; + } #undef DOCKED_FULLSCREEN_BUTTON_TOOLTIP #undef UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP -} + } -void -variable_dock_widget::closeEvent (QCloseEvent *e) -{ - QDockWidget::closeEvent (e); -} + void + variable_dock_widget::closeEvent (QCloseEvent *e) + { + QDockWidget::closeEvent (e); + } -void -variable_dock_widget::handle_focus_change (QWidget *old, QWidget *now) -{ - octave_unused_parameter (now); + void + variable_dock_widget::handle_focus_change (QWidget *old, QWidget *now) + { + octave_unused_parameter (now); - // This is a proxied test - if (hasFocus ()) - { - if (old == this) - return; + // This is a proxied test + if (hasFocus ()) + { + if (old == this) + return; - if (titleBarWidget () != nullptr) - { - QLabel *label = titleBarWidget ()->findChild (); - if (label != nullptr) - { - label->setBackgroundRole (QPalette::Highlight); - label->setStyleSheet ("background-color: palette(highlight); color: palette(highlightedText);"); - } - } + if (titleBarWidget () != nullptr) + { + QLabel *label = titleBarWidget ()->findChild (); + if (label != nullptr) + { + label->setBackgroundRole (QPalette::Highlight); + label->setStyleSheet ("background-color: palette(highlight); color: palette(highlightedText);"); + } + } - emit variable_focused_signal (objectName ()); - } - else if (old == focusWidget()) - { - if (titleBarWidget () != nullptr) - { - QLabel *label = titleBarWidget ()->findChild (); - if (label != nullptr) - { - label->setBackgroundRole (QPalette::NoRole); - label->setStyleSheet (";"); - } - } - } -} + emit variable_focused_signal (objectName ()); + } + else if (old == focusWidget()) + { + if (titleBarWidget () != nullptr) + { + QLabel *label = titleBarWidget ()->findChild (); + if (label != nullptr) + { + label->setBackgroundRole (QPalette::NoRole); + label->setStyleSheet (";"); + } + } + } + } -void variable_dock_widget::resizeEvent (QResizeEvent *) -{ - if (m_frame) - m_frame->resize (size ()); -} + void variable_dock_widget::resizeEvent (QResizeEvent *) + { + if (m_frame) + m_frame->resize (size ()); + } // See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 #if (QT_VERSION >= 0x050302) && (QT_VERSION <= QTBUG_44813_FIX_VERSION) -bool -variable_dock_widget::event (QEvent *event) -{ - // low-level check of whether docked-widget became a window via - // via drag-and-drop - if (event->type () == QEvent::MouseButtonPress) - { - m_waiting_for_mouse_move = false; - m_waiting_for_mouse_button_release = false; - } - if (event->type () == QEvent::MouseMove && m_waiting_for_mouse_move) - { - m_waiting_for_mouse_move = false; - m_waiting_for_mouse_button_release = true; - } - if (event->type () == QEvent::MouseButtonRelease - && m_waiting_for_mouse_button_release) - { - m_waiting_for_mouse_button_release = false; - bool retval = QDockWidget::event (event); - if (isFloating ()) - emit queue_unfloat_float (); - return retval; - } + bool + variable_dock_widget::event (QEvent *event) + { + // low-level check of whether docked-widget became a window via + // via drag-and-drop + if (event->type () == QEvent::MouseButtonPress) + { + m_waiting_for_mouse_move = false; + m_waiting_for_mouse_button_release = false; + } + if (event->type () == QEvent::MouseMove && m_waiting_for_mouse_move) + { + m_waiting_for_mouse_move = false; + m_waiting_for_mouse_button_release = true; + } + if (event->type () == QEvent::MouseButtonRelease + && m_waiting_for_mouse_button_release) + { + m_waiting_for_mouse_button_release = false; + bool retval = QDockWidget::event (event); + if (isFloating ()) + emit queue_unfloat_float (); + return retval; + } - return QDockWidget::event (event); -} + return QDockWidget::event (event); + } -void -variable_dock_widget::unfloat_float (void) -{ - hide (); - setFloating (false); - // Avoid a Ubunty Unity issue by queuing this rather than direct. - emit queue_float (); - m_waiting_for_mouse_move = false; - m_waiting_for_mouse_button_release = false; -} + void + variable_dock_widget::unfloat_float () + { + hide (); + setFloating (false); + // Avoid a Ubunty Unity issue by queuing this rather than direct. + emit queue_float (); + m_waiting_for_mouse_move = false; + m_waiting_for_mouse_button_release = false; + } -void -variable_dock_widget::refloat (void) -{ - setFloating (true); - m_waiting_for_mouse_move = false; - m_waiting_for_mouse_button_release = false; - show (); - activateWindow (); - setFocus (); -} + void + variable_dock_widget::refloat () + { + setFloating (true); + m_waiting_for_mouse_move = false; + m_waiting_for_mouse_button_release = false; + show (); + activateWindow (); + setFocus (); + } #else -void -variable_dock_widget::unfloat_float (void) -{ } + void + variable_dock_widget::unfloat_float () + { } -void -variable_dock_widget::refloat (void) -{ } + void + variable_dock_widget::refloat () + { } #endif -// Variable editor stack + // 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)) -{ - setFocusPolicy (Qt::StrongFocus); + variable_editor_stack::variable_editor_stack (QWidget *p) + : QStackedWidget (p), m_edit_view (new variable_editor_view (this)) + { + setFocusPolicy (Qt::StrongFocus); + + m_disp_view = make_disp_view (this); - m_disp_view = make_disp_view (this); + addWidget (m_edit_view); + addWidget (m_disp_view); + } - addWidget (m_edit_view); - addWidget (m_disp_view); -} - -QTextEdit * -variable_editor_stack::make_disp_view (QWidget *parent) -{ - QTextEdit *viewer = new QTextEdit (parent); + QTextEdit * + variable_editor_stack::make_disp_view (QWidget *parent) + { + QTextEdit *viewer = new QTextEdit (parent); - viewer->setLineWrapMode (QTextEdit::NoWrap); - viewer->setReadOnly (true); + viewer->setLineWrapMode (QTextEdit::NoWrap); + viewer->setReadOnly (true); - return viewer; -} + return viewer; + } -void -variable_editor_stack::set_editable (bool editable) -{ - // The QTableView is for editable data models - // and the QTextEdit is for non-editable models. + void + variable_editor_stack::set_editable (bool editable) + { + // The QTableView is for editable data models + // and the QTextEdit is for non-editable models. - if (editable) - { - if (m_edit_view != nullptr) - { - setCurrentWidget (m_edit_view); - setFocusProxy (m_edit_view); - m_edit_view->setFocusPolicy (Qt::StrongFocus); - } + if (editable) + { + if (m_edit_view != nullptr) + { + setCurrentWidget (m_edit_view); + setFocusProxy (m_edit_view); + m_edit_view->setFocusPolicy (Qt::StrongFocus); + } - if (m_disp_view != nullptr) - m_disp_view->setFocusPolicy (Qt::NoFocus); - } - else - { - if (m_disp_view != nullptr) - { - setCurrentWidget (m_disp_view); - setFocusProxy (m_disp_view); + if (m_disp_view != nullptr) + m_disp_view->setFocusPolicy (Qt::NoFocus); + } + else + { + if (m_disp_view != nullptr) + { + setCurrentWidget (m_disp_view); + setFocusProxy (m_disp_view); - QAbstractTableModel *model = findChild (); - if (model != nullptr) - m_disp_view->setPlainText (model->data (QModelIndex ()).toString ()); - else - m_disp_view->setPlainText (""); - } + QAbstractTableModel *model = findChild (); + if (model != nullptr) + m_disp_view->setPlainText (model->data (QModelIndex ()).toString ()); + else + m_disp_view->setPlainText (""); + } - if (m_edit_view != nullptr) - m_edit_view->setFocusPolicy (Qt::NoFocus); - } -} + if (m_edit_view != nullptr) + m_edit_view->setFocusPolicy (Qt::NoFocus); + } + } -void -variable_editor_stack::levelUp (void) -{ - if (! hasFocus ()) - return; + void + variable_editor_stack::levelUp () + { + if (! hasFocus ()) + return; - QString name = objectName (); + QString name = objectName (); - // FIXME: Is there a better way? + // FIXME: Is there a better way? - if (name.endsWith (')') || name.endsWith ('}')) - { - name.remove ( QRegExp ("[({][^({]*[)}]$)") ); - emit edit_variable_signal (name, octave_value ()); - } -} + if (name.endsWith (')') || name.endsWith ('}')) + { + name.remove ( QRegExp ("[({][^({]*[)}]$)") ); + emit edit_variable_signal (name, octave_value ()); + } + } -// Slot for saving a variable into a file -void -variable_editor_stack::save (const QString& format) -{ - if (! hasFocus ()) - return; + // Slot for saving a variable into a file + void + variable_editor_stack::save (const QString& format) + { + if (! hasFocus ()) + return; - // Check whether a format for saving the variable is given - QString format_string; - if (! format.isEmpty ()) - { - format_string = "-" + format; - do_save (format_string, format_string); - return; - } + // Check whether a format for saving the variable is given + QString format_string; + if (! format.isEmpty ()) + { + format_string = "-" + format; + do_save (format_string, format_string); + return; + } - // 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_ves (this); + QPointer this_ves (this); - // No format given, test save default options - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD + // No format given, test save default options + 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. + // 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 -void -variable_editor_stack::do_save (const QString& format, const QString& save_opts) -{ - QString file_ext = "txt"; - for (int i = 0; i < ve_save_formats_ext.length ()/2; i++) - { - if (save_opts.contains (ve_save_formats_ext.at (2*i), Qt::CaseInsensitive)) - { - file_ext = ve_save_formats_ext.at (2*i + 1); - break; - } - } + // Perform saving the variable after desired format is determined + void + variable_editor_stack::do_save (const QString& format, const QString& save_opts) + { + QString file_ext = "txt"; + for (int i = 0; i < ve_save_formats_ext.length ()/2; i++) + { + if (save_opts.contains (ve_save_formats_ext.at (2*i), Qt::CaseInsensitive)) + { + file_ext = ve_save_formats_ext.at (2*i + 1); + break; + } + } + + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. + int opts = 0; // No options by default. + + gui_settings settings; - // 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 (! settings.bool_value (global_use_native_dialogs)) + opts = QFileDialog::DontUseNativeDialog; - QString name = objectName (); - QString file - = QFileDialog::getSaveFileName (this, - tr ("Save Variable %1 As").arg (name), - QString ("./%1.%2").arg (name).arg (file_ext), - 0, 0, QFileDialog::Option (opts)); + QString name = objectName (); + QString file + = QFileDialog::getSaveFileName (this, + tr ("Save Variable %1 As").arg (name), + QString ("./%1.%2").arg (name).arg (file_ext), + 0, 0, QFileDialog::Option (opts)); - if (file.isEmpty ()) - return; // No file selected: Just return + if (file.isEmpty ()) + return; // No file selected: Just return - // Let the interpreter thread do the saving - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD + // Let the interpreter thread do the saving + emit interpreter_event + ([=] (interpreter& interp) + { + // 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 + // 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) -{ - setWordWrap (false); - setContextMenuPolicy (Qt::CustomContextMenu); - setSelectionMode (QAbstractItemView::ContiguousSelection); +variable_editor_view::variable_editor_view (QWidget *p) + : QTableView (p), m_var_model (nullptr) + { + setWordWrap (false); + setContextMenuPolicy (Qt::CustomContextMenu); + setSelectionMode (QAbstractItemView::ContiguousSelection); - horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu); - verticalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu); + horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu); + verticalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu); - setHorizontalScrollMode (QAbstractItemView::ScrollPerPixel); - setVerticalScrollMode (QAbstractItemView::ScrollPerPixel); + setHorizontalScrollMode (QAbstractItemView::ScrollPerPixel); + setVerticalScrollMode (QAbstractItemView::ScrollPerPixel); - verticalHeader ()->setSectionResizeMode (QHeaderView::Interactive); -} + verticalHeader ()->setSectionResizeMode (QHeaderView::Interactive); + } -void -variable_editor_view::setModel (QAbstractItemModel *model) -{ - QTableView::setModel (model); + void + variable_editor_view::setModel (QAbstractItemModel *model) + { + QTableView::setModel (model); - horizontalHeader ()->setSectionResizeMode (QHeaderView::Interactive); + horizontalHeader ()->setSectionResizeMode (QHeaderView::Interactive); - m_var_model = parent ()->findChild (); + m_var_model = parent ()->findChild (); - if (m_var_model != nullptr && m_var_model->column_width () > 0) - { - // col_width is in characters. The font should be a fixed-width - // font, so any character will do. If not, you lose! + if (m_var_model != nullptr && m_var_model->column_width () > 0) + { + // col_width is in characters. The font should be a fixed-width + // font, so any character will do. If not, you lose! - QFontMetrics fm (font ()); - int w = (m_var_model->column_width () - * qt_fontmetrics_horizontal_advance (fm, '0')); - horizontalHeader ()->setDefaultSectionSize (w); - } -} + QFontMetrics fm (font ()); + int w = (m_var_model->column_width () + * qt_fontmetrics_horizontal_advance (fm, '0')); + horizontalHeader ()->setDefaultSectionSize (w); + } + } -QList -variable_editor_view::range_selected (void) -{ - QItemSelectionModel *sel = selectionModel (); + QList + variable_editor_view::range_selected () + { + QItemSelectionModel *sel = selectionModel (); - // Return early if nothing selected. - if (! sel->hasSelection ()) - return QList (); + // Return early if nothing selected. + if (! sel->hasSelection ()) + return QList (); - QList indices = sel->selectedIndexes (); + QList indices = sel->selectedIndexes (); - // FIXME: Shouldn't this be keyed to octave_idx_type? + // FIXME: Shouldn't this be keyed to octave_idx_type? - int32_t from_row = std::numeric_limits::max (); - int32_t to_row = 0; - int32_t from_col = std::numeric_limits::max (); - int32_t to_col = 0; + int32_t from_row = std::numeric_limits::max (); + int32_t to_row = 0; + int32_t from_col = std::numeric_limits::max (); + int32_t to_col = 0; - for (const auto& idx : indices) - { - from_row = std::min (from_row, idx.row ()); - to_row = std::max (to_row, idx.row ()); - from_col = std::min (from_col, idx.column ()); - to_col = std::max (to_col, idx.column ()); - } + for (const auto& idx : indices) + { + from_row = std::min (from_row, idx.row ()); + to_row = std::max (to_row, idx.row ()); + from_col = std::min (from_col, idx.column ()); + to_col = std::max (to_col, idx.column ()); + } - QVector vect; - vect << from_row + 1 << to_row + 1 << from_col + 1 << to_col + 1; - QList range = QList::fromVector(vect); + QVector vect; + vect << from_row + 1 << to_row + 1 << from_col + 1 << to_col + 1; + QList range = QList::fromVector(vect); - return range; -} + return range; + } -void -variable_editor_view::selected_command_requested (const QString& cmd) -{ - if (! hasFocus ()) - return; + void + variable_editor_view::selected_command_requested (const QString& cmd) + { + if (! hasFocus ()) + return; - QList range = range_selected (); - if (range.isEmpty ()) - { - // Nothing selected, apply print command to all data - range << 1 << m_var_model->data_rows () - << 1 << m_var_model->data_columns (); - } + QList range = range_selected (); + if (range.isEmpty ()) + { + // Nothing selected, apply print command to all data + range << 1 << m_var_model->data_rows () + << 1 << m_var_model->data_columns (); + } - int s1 = m_var_model->data_rows (); - int s2 = m_var_model->data_columns (); - if (s1 < range.at (0) || s2 < range.at (2)) - return; // Selected range does not contain data + int s1 = m_var_model->data_rows (); + int s2 = m_var_model->data_columns (); + if (s1 < range.at (0) || s2 < range.at (2)) + return; // Selected range does not contain data - s1 = std::min (s1, range.at (1)); - s2 = std::min (s2, range.at (3)); + s1 = std::min (s1, range.at (1)); + s2 = std::min (s2, range.at (3)); - // 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); + // 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); - // Desired command as string - QString command; - if (cmd == "create") - command = QString ("unnamed = %1;").arg (variable); - else - command = QString ("figure (); %1 (%2); title ('%2');") - .arg (cmd).arg (variable); + // Desired command as string + QString command; + if (cmd == "create") + command = QString ("unnamed = %1;").arg (variable); + else + command = QString ("figure (); %1 (%2); title ('%2');") + .arg (cmd).arg (variable); - emit command_signal (command); -} + emit command_signal (command); + } -void -variable_editor_view::add_edit_actions (QMenu *menu, - const QString& qualifier_string) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + void + variable_editor_view::add_edit_actions (QMenu *menu, + const QString& qualifier_string) + { + gui_settings settings; - menu->addAction (rmgr.icon ("edit-cut"), - tr ("Cut") + qualifier_string, - this, &variable_editor_view::cutClipboard); + menu->addAction (settings.icon ("edit-cut"), + tr ("Cut") + qualifier_string, + this, &variable_editor_view::cutClipboard); - menu->addAction (rmgr.icon ("edit-copy"), - tr ("Copy") + qualifier_string, - this, &variable_editor_view::copyClipboard); + menu->addAction (settings.icon ("edit-copy"), + tr ("Copy") + qualifier_string, + this, &variable_editor_view::copyClipboard); - menu->addAction (rmgr.icon ("edit-paste"), - tr ("Paste"), - this, &variable_editor_view::pasteClipboard); + menu->addAction (settings.icon ("edit-paste"), + tr ("Paste"), + this, &variable_editor_view::pasteClipboard); - menu->addSeparator (); + menu->addSeparator (); - menu->addAction (rmgr.icon ("edit-delete"), - tr ("Clear") + qualifier_string, - this, &variable_editor_view::clearContent); + menu->addAction (settings.icon ("edit-delete"), + tr ("Clear") + qualifier_string, + this, &variable_editor_view::clearContent); - menu->addAction (rmgr.icon ("edit-delete"), - tr ("Delete") + qualifier_string, - this, &variable_editor_view::delete_selected); + menu->addAction (settings.icon ("edit-delete"), + tr ("Delete") + qualifier_string, + this, &variable_editor_view::delete_selected); - menu->addAction (rmgr.icon ("document-new"), - tr ("Variable from Selection"), - this, &variable_editor_view::createVariable); -} + menu->addAction (settings.icon ("document-new"), + tr ("Variable from Selection"), + this, &variable_editor_view::createVariable); + } -void -variable_editor_view::createContextMenu (const QPoint& qpos) -{ - QModelIndex index = indexAt (qpos); + void + variable_editor_view::createContextMenu (const QPoint& qpos) + { + QModelIndex index = indexAt (qpos); - if (index.isValid ()) - { - QMenu *menu = new QMenu (this); + if (index.isValid ()) + { + QMenu *menu = new QMenu (this); - add_edit_actions (menu, tr ("")); + add_edit_actions (menu, tr ("")); - // FIXME: addAction for sort? - // FIXME: Add icon for transpose. + // FIXME: addAction for sort? + // FIXME: Add icon for transpose. - menu->addAction (tr ("Transpose"), - this, &variable_editor_view::transposeContent); + menu->addAction (tr ("Transpose"), + this, &variable_editor_view::transposeContent); - QItemSelectionModel *sel = selectionModel (); + QItemSelectionModel *sel = selectionModel (); - QList indices = sel->selectedIndexes (); + QList indices = sel->selectedIndexes (); - if (! indices.isEmpty ()) - { - menu->addSeparator (); + if (! indices.isEmpty ()) + { + menu->addSeparator (); - QSignalMapper *plot_mapper = make_plot_mapper (menu); + QSignalMapper *plot_mapper = make_plot_mapper (menu); - connect (plot_mapper, SIGNAL (mapped (const QString&)), - this, SLOT (selected_command_requested (const QString&))); - } + connect (plot_mapper, SIGNAL (mapped (const QString&)), + this, SLOT (selected_command_requested (const QString&))); + } + + menu->exec (mapToGlobal (qpos)); + } + } - menu->exec (mapToGlobal (qpos)); - } -} + void + variable_editor_view::createColumnMenu (const QPoint& pt) + { + int index = horizontalHeader ()->logicalIndexAt (pt); -void -variable_editor_view::createColumnMenu (const QPoint& pt) -{ - int index = horizontalHeader ()->logicalIndexAt (pt); + if (index < 0 || index > model ()->columnCount ()) + return; - if (index < 0 || index > model ()->columnCount ()) - return; + QList coords = range_selected (); - QList coords = range_selected (); + bool nothingSelected = coords.isEmpty (); - bool nothingSelected = coords.isEmpty (); + bool whole_columns_selected + = (nothingSelected + ? false + : (coords[0] == 1 && coords[1] == model ()->rowCount ())); - bool whole_columns_selected - = (nothingSelected - ? false - : (coords[0] == 1 && coords[1] == model ()->rowCount ())); + bool current_column_selected + = nothingSelected ? false : (coords[2] <= index+1 && coords[3] > index); - bool current_column_selected - = nothingSelected ? false : (coords[2] <= index+1 && coords[3] > index); - - int column_selection_count - = nothingSelected ? 0 : (coords[3] - coords[2] + 1); + int column_selection_count + = nothingSelected ? 0 : (coords[3] - coords[2] + 1); - if (! whole_columns_selected || ! current_column_selected) - { - selectColumn (index); - column_selection_count = 1; - } + if (! whole_columns_selected || ! current_column_selected) + { + selectColumn (index); + column_selection_count = 1; + } - QString column_string - = column_selection_count > 1 ? tr (" columns") : tr (" column"); + QString column_string + = column_selection_count > 1 ? tr (" columns") : tr (" column"); + + QMenu *menu = new QMenu (this); - QMenu *menu = new QMenu (this); + add_edit_actions (menu, column_string); - add_edit_actions (menu, column_string); + menu->addSeparator (); - menu->addSeparator (); + QSignalMapper *plot_mapper = make_plot_mapper (menu); - QSignalMapper *plot_mapper = make_plot_mapper (menu); - - connect (plot_mapper, SIGNAL (mapped (const QString&)), - this, SLOT (selected_command_requested (const QString&))); + connect (plot_mapper, SIGNAL (mapped (const QString&)), + this, SLOT (selected_command_requested (const QString&))); - QPoint menupos = pt; - menupos.setY (horizontalHeader ()->height ()); + QPoint menupos = pt; + menupos.setY (horizontalHeader ()->height ()); - menu->exec (mapToGlobal (menupos)); -} + menu->exec (mapToGlobal (menupos)); + } -void -variable_editor_view::createRowMenu (const QPoint& pt) -{ - int index = verticalHeader ()->logicalIndexAt (pt); + void + variable_editor_view::createRowMenu (const QPoint& pt) + { + int index = verticalHeader ()->logicalIndexAt (pt); - if (index < 0 || index > model ()->columnCount ()) - return; + if (index < 0 || index > model ()->columnCount ()) + return; - QList coords = range_selected (); + QList coords = range_selected (); - bool nothingSelected = coords.isEmpty (); + bool nothingSelected = coords.isEmpty (); - bool whole_rows_selected - = (nothingSelected - ? false - : (coords[2] == 1 && coords[3] == model ()->columnCount ())); + bool whole_rows_selected + = (nothingSelected + ? false + : (coords[2] == 1 && coords[3] == model ()->columnCount ())); - bool current_row_selected - = (nothingSelected ? false : (coords[0] <= index+1 && coords[1] > index)); + bool current_row_selected + = (nothingSelected ? false : (coords[0] <= index+1 && coords[1] > index)); - int rowselection_count = nothingSelected ? 0 : (coords[3] - coords[2] + 1); + int rowselection_count = nothingSelected ? 0 : (coords[3] - coords[2] + 1); - if (! whole_rows_selected || ! current_row_selected) - { - selectRow (index); - rowselection_count = 1; - } + if (! whole_rows_selected || ! current_row_selected) + { + selectRow (index); + rowselection_count = 1; + } - QString row_string = rowselection_count > 1 ? tr (" rows") : tr (" row"); + QString row_string = rowselection_count > 1 ? tr (" rows") : tr (" row"); - QMenu *menu = new QMenu (this); + QMenu *menu = new QMenu (this); - add_edit_actions (menu, row_string); + add_edit_actions (menu, row_string); - menu->addSeparator (); + menu->addSeparator (); - QSignalMapper *plot_mapper = make_plot_mapper (menu); + QSignalMapper *plot_mapper = make_plot_mapper (menu); - connect (plot_mapper, SIGNAL (mapped (const QString&)), - this, SLOT (selected_command_requested (const QString&))); + connect (plot_mapper, SIGNAL (mapped (const QString&)), + this, SLOT (selected_command_requested (const QString&))); - QPoint menupos = pt; - menupos.setX (verticalHeader ()->width ()); + QPoint menupos = pt; + menupos.setX (verticalHeader ()->width ()); - // FIXME: What was the intent here? - // setY (verticalHeader ()->sectionPosition (index+1) + - // verticalHeader ()->sectionSize (index)); + // FIXME: What was the intent here? + // setY (verticalHeader ()->sectionPosition (index+1) + + // verticalHeader ()->sectionSize (index)); - menu->exec (mapToGlobal (menupos)); -} + menu->exec (mapToGlobal (menupos)); + } -void -variable_editor_view::createVariable (void) -{ - // FIXME: Create unnamed1..n if exist ('unnamed', 'var') is true. + void + variable_editor_view::createVariable () + { + // FIXME: Create unnamed1..n if exist ('unnamed', 'var') is true. - selected_command_requested ("create"); -} + selected_command_requested ("create"); + } -void -variable_editor_view::transposeContent (void) -{ - if (! hasFocus ()) - return; + void + variable_editor_view::transposeContent () + { + if (! hasFocus ()) + return; - emit command_signal (QString ("%1 = %1';").arg (objectName ())); -} + emit command_signal (QString ("%1 = %1';").arg (objectName ())); + } -void -variable_editor_view::delete_selected (void) -{ - if (! hasFocus ()) - return; + void + variable_editor_view::delete_selected () + { + if (! hasFocus ()) + return; - QAbstractItemModel *mod = model (); - QList coords = range_selected (); + QAbstractItemModel *mod = model (); + QList coords = range_selected (); - if (coords.isEmpty ()) - return; + if (coords.isEmpty ()) + return; - bool whole_columns_selected - = coords[0] == 1 && coords[1] == mod->rowCount (); + bool whole_columns_selected + = coords[0] == 1 && coords[1] == mod->rowCount (); - bool whole_rows_selected - = coords[2] == 1 && coords[3] == mod->columnCount (); + bool whole_rows_selected + = coords[2] == 1 && coords[3] == mod->columnCount (); - // Must be deleting whole columns or whole rows, and not the whole thing. + // Must be deleting whole columns or whole rows, and not the whole thing. - if (whole_columns_selected == whole_rows_selected) - return; + if (whole_columns_selected == whole_rows_selected) + return; - if (whole_rows_selected) - mod->removeRows (coords[0], coords[1] - coords[0]); + if (whole_rows_selected) + mod->removeRows (coords[0], coords[1] - coords[0]); - if (whole_columns_selected) - mod->removeColumns (coords[2], coords[3] - coords[2]); -} + if (whole_columns_selected) + mod->removeColumns (coords[2], coords[3] - coords[2]); + } -void -variable_editor_view::clearContent (void) -{ - if (! hasFocus ()) - return; + void + variable_editor_view::clearContent () + { + if (! hasFocus ()) + return; - if (m_var_model == nullptr) - return; + if (m_var_model == nullptr) + return; - QItemSelectionModel *sel = selectionModel (); - QList indices = sel->selectedIndexes (); + QItemSelectionModel *sel = selectionModel (); + QList indices = sel->selectedIndexes (); - // FIXME: Use [] for empty cells? + // FIXME: Use [] for empty cells? - for (const auto& idx : indices) - m_var_model->clear_content (idx); -} + for (const auto& idx : indices) + m_var_model->clear_content (idx); + } -void -variable_editor_view::cutClipboard (void) -{ - copyClipboard (); + void + variable_editor_view::cutClipboard () + { + copyClipboard (); - clearContent (); -} + clearContent (); + } -void -variable_editor_view::copyClipboard (void) -{ - if (! hasFocus ()) - return; + void + variable_editor_view::copyClipboard () + { + if (! hasFocus ()) + return; - QItemSelectionModel *sel = selectionModel (); - QList indices = sel->selectedIndexes (); - std::sort (indices.begin (), indices.end ()); + QItemSelectionModel *sel = selectionModel (); + QList indices = sel->selectedIndexes (); + std::sort (indices.begin (), indices.end ()); - if (indices.isEmpty ()) - return; + if (indices.isEmpty ()) + return; - // Convert selected items into TSV format and copy that. - // Spreadsheet tools should understand that. + // Convert selected items into TSV format and copy that. + // Spreadsheet tools should understand that. - QAbstractItemModel *mod = model (); - QModelIndex previous = indices.first (); - QString copy = mod->data (previous).toString (); - indices.removeFirst (); - for (auto idx : indices) - { - copy.push_back (previous.row () != idx.row () ? '\n' : '\t'); - copy.append (mod->data (idx).toString ()); - previous = idx; - } + QAbstractItemModel *mod = model (); + QModelIndex previous = indices.first (); + QString copy = mod->data (previous).toString (); + indices.removeFirst (); + for (auto idx : indices) + { + copy.push_back (previous.row () != idx.row () ? '\n' : '\t'); + copy.append (mod->data (idx).toString ()); + previous = idx; + } - QClipboard *clipboard = QApplication::clipboard (); - clipboard->setText (copy); -} + QClipboard *clipboard = QApplication::clipboard (); + clipboard->setText (copy); + } -void -variable_editor_view::pasteClipboard (void) -{ - if (! hasFocus ()) - return; + void + variable_editor_view::pasteClipboard () + { + if (! hasFocus ()) + return; - QAbstractItemModel *mod = model (); - QItemSelectionModel *sel = selectionModel (); - QList indices = sel->selectedIndexes (); + QAbstractItemModel *mod = model (); + QItemSelectionModel *sel = selectionModel (); + QList indices = sel->selectedIndexes (); - QClipboard *clipboard = QApplication::clipboard (); - QString text = clipboard->text (); + QClipboard *clipboard = QApplication::clipboard (); + QString text = clipboard->text (); - QPoint start, end; + QPoint start, end; - QPoint tabsize = QPoint (mod->rowCount (), mod->columnCount ()); + QPoint tabsize = QPoint (mod->rowCount (), mod->columnCount ()); - if (indices.isEmpty ()) - { - start = QPoint (0, 0); - end = tabsize; - } - else if (indices.size () == 1) - { - start = QPoint (indices[0].row (), indices[0].column ()); - end = tabsize; - } - else - { - end = QPoint (0, 0); - start = tabsize; + if (indices.isEmpty ()) + { + start = QPoint (0, 0); + end = tabsize; + } + else if (indices.size () == 1) + { + start = QPoint (indices[0].row (), indices[0].column ()); + end = tabsize; + } + else + { + end = QPoint (0, 0); + start = tabsize; - for (int i = 0; i < indices.size (); i++) - { - if (indices[i].column () < start.y ()) - start.setY (indices[i].column ()); + for (int i = 0; i < indices.size (); i++) + { + if (indices[i].column () < start.y ()) + start.setY (indices[i].column ()); - if (indices[i].column () > end.y ()) - end.setY (indices[i].column ()); + if (indices[i].column () > end.y ()) + end.setY (indices[i].column ()); - if (indices[i].row () < start.x ()) - start.setX (indices[i].column ()); + if (indices[i].row () < start.x ()) + start.setX (indices[i].column ()); - if (indices[i].row () > end.x ()) - end.setX (indices[i].column ()); - } - } + if (indices[i].row () > end.x ()) + end.setX (indices[i].column ()); + } + } - int rownum = 0; - int colnum = 0; + int rownum = 0; + int colnum = 0; - QStringList rows = text.split ('\n'); - for (const auto& row : rows) - { - if (rownum > end.x () - start.x ()) - continue; + QStringList rows = text.split ('\n'); + for (const auto& row : rows) + { + if (rownum > end.x () - start.x ()) + continue; - QStringList cols = row.split ('\t'); - if (cols.isEmpty ()) - continue; + QStringList cols = row.split ('\t'); + if (cols.isEmpty ()) + continue; - for (const auto& col : cols) - { - if (col.isEmpty ()) - continue; - if (colnum > end.y () - start.y () ) - continue; + for (const auto& col : cols) + { + if (col.isEmpty ()) + continue; + if (colnum > end.y () - start.y () ) + continue; - mod->setData (mod->index (rownum + start.x (), - colnum + start.y ()), - QVariant (col)); + mod->setData (mod->index (rownum + start.x (), + colnum + start.y ()), + QVariant (col)); - colnum++; - } + colnum++; + } - colnum = 0; - rownum++; - } -} + colnum = 0; + rownum++; + } + } -void -variable_editor_view::handle_horizontal_scroll_action (int action) -{ - if (action == QAbstractSlider::SliderSingleStepAdd - || action == QAbstractSlider::SliderPageStepAdd - || action == QAbstractSlider::SliderToMaximum - || action == QAbstractSlider::SliderMove) - { - if (m_var_model != nullptr) - { - QScrollBar *sb = horizontalScrollBar (); + void + variable_editor_view::handle_horizontal_scroll_action (int action) + { + if (action == QAbstractSlider::SliderSingleStepAdd + || action == QAbstractSlider::SliderPageStepAdd + || action == QAbstractSlider::SliderToMaximum + || action == QAbstractSlider::SliderMove) + { + if (m_var_model != nullptr) + { + QScrollBar *sb = horizontalScrollBar (); - if (sb && sb->value () == sb->maximum ()) - { - int new_cols = m_var_model->display_columns () + 16; + if (sb && sb->value () == sb->maximum ()) + { + int new_cols = m_var_model->display_columns () + 16; - m_var_model->maybe_resize_columns (new_cols); - } - } - } -} + m_var_model->maybe_resize_columns (new_cols); + } + } + } + } -void -variable_editor_view::handle_vertical_scroll_action (int action) -{ - if (action == QAbstractSlider::SliderSingleStepAdd - || action == QAbstractSlider::SliderPageStepAdd - || action == QAbstractSlider::SliderToMaximum - || action == QAbstractSlider::SliderMove) - { - if (m_var_model != nullptr) - { - QScrollBar *sb = verticalScrollBar (); + void + variable_editor_view::handle_vertical_scroll_action (int action) + { + if (action == QAbstractSlider::SliderSingleStepAdd + || action == QAbstractSlider::SliderPageStepAdd + || action == QAbstractSlider::SliderToMaximum + || action == QAbstractSlider::SliderMove) + { + if (m_var_model != nullptr) + { + QScrollBar *sb = verticalScrollBar (); - if (sb && sb->value () == sb->maximum ()) - { - int new_rows = m_var_model->display_rows () + 16; + if (sb && sb->value () == sb->maximum ()) + { + int new_rows = m_var_model->display_rows () + 16; - m_var_model->maybe_resize_rows (new_rows); - } - } - } -} + m_var_model->maybe_resize_rows (new_rows); + } + } + } + } -// Gadgets for focus restoration + // Gadgets for focus restoration -HoverToolButton::HoverToolButton (QWidget *parent) - : QToolButton (parent) -{ - installEventFilter (this); -} + HoverToolButton::HoverToolButton (QWidget *parent) + : QToolButton (parent) + { + installEventFilter (this); + } -bool HoverToolButton::eventFilter (QObject *obj, QEvent *ev) -{ - if (ev->type () == QEvent::HoverEnter) - emit hovered_signal (); - else if (ev->type () == QEvent::MouseButtonPress) - emit popup_shown_signal (); + bool HoverToolButton::eventFilter (QObject *obj, QEvent *ev) + { + if (ev->type () == QEvent::HoverEnter) + emit hovered_signal (); + else if (ev->type () == QEvent::MouseButtonPress) + emit popup_shown_signal (); - return QToolButton::eventFilter (obj, ev); -} + return QToolButton::eventFilter (obj, ev); + } -ReturnFocusToolButton::ReturnFocusToolButton (QWidget *parent) - : HoverToolButton (parent) -{ - installEventFilter (this); -} + ReturnFocusToolButton::ReturnFocusToolButton (QWidget *parent) + : HoverToolButton (parent) + { + installEventFilter (this); + } -bool ReturnFocusToolButton::eventFilter (QObject *obj, QEvent *ev) -{ + bool ReturnFocusToolButton::eventFilter (QObject *obj, QEvent *ev) + { - if (ev->type () == QEvent::MouseButtonRelease && isDown ()) - { - emit about_to_activate (); + if (ev->type () == QEvent::MouseButtonRelease && isDown ()) + { + emit about_to_activate (); - setDown (false); - QAction *action = defaultAction (); - if (action != nullptr) - action->activate (QAction::Trigger); + setDown (false); + QAction *action = defaultAction (); + if (action != nullptr) + action->activate (QAction::Trigger); - return true; - } + return true; + } - return HoverToolButton::eventFilter (obj, ev); -} + return HoverToolButton::eventFilter (obj, ev); + } -ReturnFocusMenu::ReturnFocusMenu (QWidget *parent) - : QMenu (parent) -{ - installEventFilter (this); -} + ReturnFocusMenu::ReturnFocusMenu (QWidget *parent) + : QMenu (parent) + { + installEventFilter (this); + } -bool ReturnFocusMenu::eventFilter (QObject *obj, QEvent *ev) -{ - if (ev->type () == QEvent::MouseButtonRelease && underMouse ()) - { - emit about_to_activate (); - } + bool ReturnFocusMenu::eventFilter (QObject *obj, QEvent *ev) + { + if (ev->type () == QEvent::MouseButtonRelease && underMouse ()) + { + emit about_to_activate (); + } - return QMenu::eventFilter (obj, ev); -} + return QMenu::eventFilter (obj, ev); + } -// Variable editor. + // 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)), - m_tool_bar (new QToolBar (m_main)), - m_default_width (30), - m_default_height (100), - m_add_font_height (0), - m_use_terminal_font (true), - m_alternate_rows (true), - m_stylesheet (""), - m_font (), - m_sel_font (), - m_table_colors (), - m_current_focus_vname (""), - m_hovered_focus_vname (""), - m_plot_mapper (nullptr), - m_focus_widget (nullptr), - m_focus_widget_vdw (nullptr) -{ - set_title (tr ("Variable Editor")); - setStatusTip (tr ("Edit variables.")); - setAttribute (Qt::WA_AlwaysShowToolTips); + 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), + m_add_font_height (0), + m_use_terminal_font (true), + m_alternate_rows (true), + m_stylesheet (""), + m_font (), + m_sel_font (), + m_table_colors (), + m_current_focus_vname (""), + m_hovered_focus_vname (""), + m_plot_mapper (nullptr), + m_focus_widget (nullptr), + m_focus_widget_vdw (nullptr) + { + set_title (tr ("Variable Editor")); + setStatusTip (tr ("Edit variables.")); + setAttribute (Qt::WA_AlwaysShowToolTips); - m_main->setParent (this); - // See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357 + m_main->setParent (this); +// 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 | - QMainWindow::VerticalTabs); + m_main->setDockOptions (QMainWindow::AnimatedDocks | + QMainWindow::AllowNestedDocks | + QMainWindow::VerticalTabs); #else - m_main->setDockNestingEnabled (true); + m_main->setDockNestingEnabled (true); #endif - // Tool Bar. + // Tool Bar. - construct_tool_bar (); - m_main->addToolBar (m_tool_bar); + construct_tool_bar (); + m_main->addToolBar (m_tool_bar); - // Colors. + // Colors. - for (int i = 0; i < ve_colors_count; i++) - m_table_colors.append (QColor (Qt::white)); + for (int i = 0; i < ve_colors_count; i++) + m_table_colors.append (QColor (Qt::white)); - // Use an MDI area that is shrunk to nothing as the central widget. - // Future feature might be to switch to MDI mode in which the dock - // area is shrunk to nothing and the widgets live in the MDI window. + // Use an MDI area that is shrunk to nothing as the central widget. + // Future feature might be to switch to MDI mode in which the dock + // area is shrunk to nothing and the widgets live in the MDI window. - QMdiArea *central_mdiarea = new QMdiArea (m_main); - central_mdiarea->setMinimumSize (QSize (0, 0)); - central_mdiarea->setMaximumSize (QSize (0, 0)); - central_mdiarea->resize (QSize (0, 0)); - m_main->setCentralWidget (central_mdiarea); + QMdiArea *central_mdiarea = new QMdiArea (m_main); + central_mdiarea->setMinimumSize (QSize (0, 0)); + central_mdiarea->setMaximumSize (QSize (0, 0)); + central_mdiarea->resize (QSize (0, 0)); + m_main->setCentralWidget (central_mdiarea); - setWidget (m_main); + setWidget (m_main); - if (! p) - make_window (); -} + if (! p) + make_window (); + } -void variable_editor::focusInEvent (QFocusEvent *ev) -{ - octave_dock_widget::focusInEvent (ev); + void variable_editor::focusInEvent (QFocusEvent *ev) + { + octave_dock_widget::focusInEvent (ev); - // set focus to the current variable or most recent if still valid - if (m_focus_widget != nullptr) - { - // Activating a floating window causes problems. - if (! m_focus_widget_vdw->isFloating ()) - activateWindow (); - m_focus_widget->setFocus (); - } - else - { - QWidget *fw = m_main->focusWidget (); - if (fw != nullptr) - { + // set focus to the current variable or most recent if still valid + if (m_focus_widget != nullptr) + { + // Activating a floating window causes problems. + if (! m_focus_widget_vdw->isFloating ()) activateWindow (); - fw->setFocus (); - } - else - { - QDockWidget *any_qdw = m_main->findChild (); - if (any_qdw != nullptr) - { - activateWindow (); - any_qdw->setFocus (); - } - else - setFocus(); - } - } -} + m_focus_widget->setFocus (); + } + else + { + QWidget *fw = m_main->focusWidget (); + if (fw != nullptr) + { + activateWindow (); + fw->setFocus (); + } + else + { + QDockWidget *any_qdw = m_main->findChild (); + if (any_qdw != nullptr) + { + activateWindow (); + any_qdw->setFocus (); + } + else + setFocus(); + } + } + } -variable_editor::~variable_editor (void) -{ - // FIXME: Maybe toolbar actions could be handled with signals and - // slots so that deleting the toolbar here would disconnect all - // toolbar actions and any other slots that might try to access the - // toolbar would work properly (I'm looking at you, - // handle_focus_change). + variable_editor::~variable_editor () + { + // FIXME: Maybe toolbar actions could be handled with signals and + // slots so that deleting the toolbar here would disconnect all + // toolbar actions and any other slots that might try to access the + // toolbar would work properly (I'm looking at you, + // handle_focus_change). - delete m_tool_bar; - m_tool_bar = nullptr; -} - -void -variable_editor::edit_variable (const QString& name, const octave_value& val) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + delete m_tool_bar; + m_tool_bar = nullptr; + } - if (m_stylesheet.isEmpty ()) - { - gui_settings *settings = rmgr.get_settings (); - notice_settings (settings); - } + void + variable_editor::edit_variable (const QString& name, const octave_value& val) + { + if (m_stylesheet.isEmpty ()) + notice_settings (); - QDockWidget *existing_qdw = m_main->findChild (name); - if (existing_qdw) - { - // Already open. + QDockWidget *existing_qdw = m_main->findChild (name); + if (existing_qdw) + { + // Already open. - // Put current focused variable out of focus - if (m_main->focusWidget () != nullptr) - { - QFocusEvent event (QEvent::FocusOut, Qt::OtherFocusReason); - QApplication::sendEvent (m_main->focusWidget (), &event); - } + // Put current focused variable out of focus + if (m_main->focusWidget () != nullptr) + { + QFocusEvent event (QEvent::FocusOut, Qt::OtherFocusReason); + QApplication::sendEvent (m_main->focusWidget (), &event); + } - // Put existing variable in focus and raise - m_main->parentWidget ()->show (); - existing_qdw->show (); - existing_qdw->raise (); - existing_qdw->activateWindow (); - tab_to_front (); - existing_qdw->setFocus (); + // Put existing variable in focus and raise + m_main->parentWidget ()->show (); + existing_qdw->show (); + existing_qdw->raise (); + existing_qdw->activateWindow (); + tab_to_front (); + existing_qdw->setFocus (); - return; - } + 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); + page->setObjectName (name); + m_main->addDockWidget (Qt::LeftDockWidgetArea, page); - // The old-style signal/slot connection appears to be needed here to - // prevent a crash when closing a variable_dock_widget object. - connect (qApp, SIGNAL (focusChanged (QWidget *, QWidget *)), - page, SLOT (handle_focus_change (QWidget *, QWidget *))); + // The old-style signal/slot connection appears to be needed here to + // prevent a crash when closing a variable_dock_widget object. + connect (qApp, SIGNAL (focusChanged (QWidget *, QWidget *)), + page, SLOT (handle_focus_change (QWidget *, QWidget *))); - connect (this, &variable_editor::visibilityChanged, - page, &variable_dock_widget::setVisible); + connect (this, &variable_editor::visibilityChanged, + page, &variable_dock_widget::setVisible); - // Notify the variable editor for page actions. - connect (page, &variable_dock_widget::destroyed, - this, &variable_editor::variable_destroyed); - connect (page, &variable_dock_widget::variable_focused_signal, - this, &variable_editor::variable_focused); + // Notify the variable editor for page actions. + connect (page, &variable_dock_widget::destroyed, + this, &variable_editor::variable_destroyed); + connect (page, &variable_dock_widget::variable_focused_signal, + this, &variable_editor::variable_focused); - // 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) - connect (page, SIGNAL (queue_unfloat_float ()), - page, SLOT (unfloat_float ()), Qt::QueuedConnection); - connect (page, SIGNAL (queue_float ()), - page, SLOT (refloat ()), Qt::QueuedConnection); + connect (page, SIGNAL (queue_unfloat_float ()), + page, SLOT (unfloat_float ()), Qt::QueuedConnection); + connect (page, SIGNAL (queue_float ()), + 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); - page->setFocusProxy (stack); + stack->setObjectName (name); + page->setWidget (stack); + page->setFocusProxy (stack); - // Any interpreter_event signal from a variable_editor_stack object is - // handled the same as for the parent variable_editor object. - connect (stack, QOverload::of (&variable_editor_stack::interpreter_event), - this, QOverload::of (&variable_editor::interpreter_event)); + // Any interpreter_event signal from a variable_editor_stack object is + // handled the same as for the parent variable_editor object. + connect (stack, QOverload::of (&variable_editor_stack::interpreter_event), + this, QOverload::of (&variable_editor::interpreter_event)); - connect (stack, QOverload::of (&variable_editor_stack::interpreter_event), - this, QOverload::of (&variable_editor::interpreter_event)); + connect (stack, QOverload::of (&variable_editor_stack::interpreter_event), + this, QOverload::of (&variable_editor::interpreter_event)); - connect (stack, &variable_editor_stack::edit_variable_signal, - this, &variable_editor::edit_variable); - connect (this, &variable_editor::level_up_signal, - stack, &variable_editor_stack::levelUp); - connect (this, &variable_editor::save_signal, - stack, [=] () { stack->save (); }); + connect (stack, &variable_editor_stack::edit_variable_signal, + this, &variable_editor::edit_variable); + connect (this, &variable_editor::level_up_signal, + stack, &variable_editor_stack::levelUp); + connect (this, &variable_editor::save_signal, + stack, [=] () { stack->save (); }); - variable_editor_view *edit_view = stack->edit_view (); + variable_editor_view *edit_view = stack->edit_view (); - edit_view->setObjectName (name); - edit_view->setFont (m_font); - edit_view->setStyleSheet (m_stylesheet); - edit_view->setAlternatingRowColors (m_alternate_rows); - edit_view->verticalHeader ()->setDefaultSectionSize (m_default_height - + m_add_font_height); + edit_view->setObjectName (name); + edit_view->setFont (m_font); + edit_view->setStyleSheet (m_stylesheet); + edit_view->setAlternatingRowColors (m_alternate_rows); + edit_view->verticalHeader ()->setDefaultSectionSize (m_default_height + + m_add_font_height); - connect (m_plot_mapper, SIGNAL (mapped (const QString&)), - edit_view, SLOT (selected_command_requested (const QString&))); - connect (m_save_mapper, SIGNAL (mapped (const QString&)), - stack, SLOT (save (const QString&))); + connect (m_plot_mapper, SIGNAL (mapped (const QString&)), + edit_view, SLOT (selected_command_requested (const QString&))); + connect (m_save_mapper, SIGNAL (mapped (const QString&)), + stack, SLOT (save (const QString&))); - connect (edit_view, &variable_editor_view::command_signal, - this, &variable_editor::command_signal); - connect (this, &variable_editor::delete_selected_signal, - edit_view, &variable_editor_view::delete_selected); - connect (this, &variable_editor::clear_content_signal, - edit_view, &variable_editor_view::clearContent); - connect (this, &variable_editor::copy_clipboard_signal, - edit_view, &variable_editor_view::copyClipboard); - connect (this, &variable_editor::paste_clipboard_signal, - edit_view, &variable_editor_view::pasteClipboard); - connect (edit_view->horizontalHeader (), - &QHeaderView::customContextMenuRequested, - edit_view, &variable_editor_view::createColumnMenu); - connect (edit_view->verticalHeader (), - &QHeaderView::customContextMenuRequested, - edit_view, &variable_editor_view::createRowMenu); - connect (edit_view, &variable_editor_view::customContextMenuRequested, - edit_view, &variable_editor_view::createContextMenu); - connect (edit_view->horizontalScrollBar (), &QScrollBar::actionTriggered, - edit_view, &variable_editor_view::handle_horizontal_scroll_action); - connect (edit_view->verticalScrollBar (), &QScrollBar::actionTriggered, - edit_view, &variable_editor_view::handle_vertical_scroll_action); + connect (edit_view, &variable_editor_view::command_signal, + this, &variable_editor::command_signal); + connect (this, &variable_editor::delete_selected_signal, + edit_view, &variable_editor_view::delete_selected); + connect (this, &variable_editor::clear_content_signal, + edit_view, &variable_editor_view::clearContent); + connect (this, &variable_editor::copy_clipboard_signal, + edit_view, &variable_editor_view::copyClipboard); + connect (this, &variable_editor::paste_clipboard_signal, + edit_view, &variable_editor_view::pasteClipboard); + connect (edit_view->horizontalHeader (), + &QHeaderView::customContextMenuRequested, + edit_view, &variable_editor_view::createColumnMenu); + connect (edit_view->verticalHeader (), + &QHeaderView::customContextMenuRequested, + edit_view, &variable_editor_view::createRowMenu); + connect (edit_view, &variable_editor_view::customContextMenuRequested, + edit_view, &variable_editor_view::createContextMenu); + connect (edit_view->horizontalScrollBar (), &QScrollBar::actionTriggered, + edit_view, &variable_editor_view::handle_horizontal_scroll_action); + connect (edit_view->verticalScrollBar (), &QScrollBar::actionTriggered, + edit_view, &variable_editor_view::handle_vertical_scroll_action); - variable_editor_model *model = - new variable_editor_model (name, val, stack); + variable_editor_model *model = + new variable_editor_model (name, val, stack); - connect (model, &variable_editor_model::edit_variable_signal, - this, &variable_editor::edit_variable); - connect (model, &variable_editor_model::dataChanged, - this, &variable_editor::callUpdate); - connect (this, &variable_editor::refresh_signal, - model, &variable_editor_model::update_data_cache); - connect (model, &variable_editor_model::set_editable_signal, - stack, &variable_editor_stack::set_editable); + connect (model, &variable_editor_model::edit_variable_signal, + this, &variable_editor::edit_variable); + connect (model, &variable_editor_model::dataChanged, + this, &variable_editor::callUpdate); + connect (this, &variable_editor::refresh_signal, + model, &variable_editor_model::update_data_cache); + connect (model, &variable_editor_model::set_editable_signal, + stack, &variable_editor_stack::set_editable); - edit_view->setModel (model); - connect (edit_view, &variable_editor_view::doubleClicked, - model, &variable_editor_model::double_click); + edit_view->setModel (model); + connect (edit_view, &variable_editor_view::doubleClicked, + model, &variable_editor_model::double_click); - // Any interpreter_event signal from a variable_editor_model object is - // handled the same as for the parent variable_editor object. + // Any interpreter_event signal from a variable_editor_model object is + // handled the same as for the parent variable_editor object. - connect (model, QOverload::of (&variable_editor_model::interpreter_event), - this, QOverload::of (&variable_editor::interpreter_event)); + connect (model, QOverload::of (&variable_editor_model::interpreter_event), + this, QOverload::of (&variable_editor::interpreter_event)); - connect (model, QOverload::of (&variable_editor_model::interpreter_event), - this, QOverload::of (&variable_editor::interpreter_event)); + connect (model, QOverload::of (&variable_editor_model::interpreter_event), + this, QOverload::of (&variable_editor::interpreter_event)); - // Must supply a title for a QLabel to be created. Calling set_title() - // more than once will add more QLabels. Could change octave_dock_widget - // to always supply a QLabel (initially empty) and then simply update its - // contents. - page->set_title (name); - if (page->titleBarWidget () != nullptr) - { - QLabel *existing_ql = page->titleBarWidget ()->findChild (); + // Must supply a title for a QLabel to be created. Calling set_title() + // more than once will add more QLabels. Could change octave_dock_widget + // to always supply a QLabel (initially empty) and then simply update its + // contents. + page->set_title (name); + if (page->titleBarWidget () != nullptr) + { + QLabel *existing_ql = page->titleBarWidget ()->findChild (); - // FIXME: What was the intent here? update_label_signal does - // not seem to exist now. - connect (model, SIGNAL (description_changed (const QString&)), - existing_ql, SLOT (setText (const QString&))); - existing_ql->setMargin (2); - } + // FIXME: What was the intent here? update_label_signal does + // not seem to exist now. + connect (model, SIGNAL (description_changed (const QString&)), + existing_ql, SLOT (setText (const QString&))); + existing_ql->setMargin (2); + } - model->update_data (val); + model->update_data (val); - if (m_tool_bar) - { - QList viewlist = findChildren (); - if (viewlist.size () == 1 && m_tool_bar) - m_tool_bar->setEnabled (true); - } + if (m_tool_bar) + { + QList viewlist = findChildren (); + if (viewlist.size () == 1 && m_tool_bar) + m_tool_bar->setEnabled (true); + } - show (); - page->show (); - page->raise (); - page->activateWindow (); - tab_to_front (); - page->setFocus (); -} + show (); + page->show (); + page->raise (); + page->activateWindow (); + tab_to_front (); + page->setFocus (); + } -void -variable_editor::tab_to_front (void) -{ - QWidget *parent = parentWidget (); + void + variable_editor::tab_to_front () + { + QWidget *parent = parentWidget (); - if (parent) - { - QList barlist = parent->findChildren (); + if (parent) + { + QList barlist = parent->findChildren (); - QVariant this_value (reinterpret_cast (this)); + QVariant this_value (reinterpret_cast (this)); - for (auto *tbar : barlist) - { - for (int i = 0; i < tbar->count (); i++) - { - if (tbar->tabData (i) == this_value) - { - tbar->setCurrentIndex (i); - return; - } - } - } - } -} + for (auto *tbar : barlist) + { + for (int i = 0; i < tbar->count (); i++) + { + if (tbar->tabData (i) == this_value) + { + tbar->setCurrentIndex (i); + return; + } + } + } + } + } -void -variable_editor::refresh (void) -{ - emit refresh_signal (); -} + void + variable_editor::refresh () + { + emit refresh_signal (); + } -void -variable_editor::callUpdate (const QModelIndex&, const QModelIndex&) -{ - emit updated (); -} + void + variable_editor::callUpdate (const QModelIndex&, const QModelIndex&) + { + emit updated (); + } -void -variable_editor::notice_settings (const gui_settings *settings) -{ - m_main->notice_settings (settings); // update settings in parent main win + void + variable_editor::notice_settings () + { + 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_alternate_rows = settings->value (ve_alternate_rows).toBool (); + m_default_height = settings.int_value (ve_row_height); - m_use_terminal_font = settings->value (ve_use_terminal_font).toBool (); + m_alternate_rows = settings.bool_value (ve_alternate_rows); - QString font_name; - int font_size; - QString default_font = settings->value (global_mono_font).toString (); + m_use_terminal_font = settings.bool_value (ve_use_terminal_font); - if (m_use_terminal_font) - { - font_name = settings->value (cs_font.key, default_font).toString (); - font_size = settings->value (cs_font_size).toInt (); - } - else - { - font_name = settings->value (ve_font_name.key, default_font).toString (); - font_size = settings->value (ve_font_size).toInt (); - } + QString font_name; + int font_size; + QString default_font = settings.string_value (global_mono_font); - m_font = QFont (font_name, font_size); + if (m_use_terminal_font) + { + 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.settings_key (), default_font).toString (); + font_size = settings.int_value (ve_font_size); + } - QFontMetrics fm (m_font); + m_font = QFont (font_name, font_size); - m_add_font_height = fm.height (); + QFontMetrics fm (m_font); + + 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); - m_table_colors.replace (i, setting_color); - } + for (int i = 0; i < ve_colors_count; i++) + { + QColor setting_color = settings.color_value (ve_colors[i], mode); + m_table_colors.replace (i, setting_color); + } - update_colors (); + update_colors (); - // Icon size in the toolbar. + // Icon size in the toolbar. - if (m_tool_bar) - { - int size_idx = settings->value (global_icon_size).toInt (); - 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_tool_bar->setIconSize (QSize (icon_size, icon_size)); - } + if (m_tool_bar) + { + 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 - // Shortcuts (same as file editor) - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - scmgr.set_shortcut (m_save_action, sc_edit_file_save); -} + QStyle *st = style (); + int icon_size = st->pixelMetric (global_icon_sizes[size_idx]); + m_tool_bar->setIconSize (QSize (icon_size, icon_size)); + } -void -variable_editor::closeEvent (QCloseEvent *e) -{ - emit finished (); + // Shortcuts (same as file editor) + settings.set_shortcut (m_save_action, sc_edit_file_save); + } + + void + variable_editor::closeEvent (QCloseEvent *e) + { + emit finished (); - octave_dock_widget::closeEvent (e); -} + octave_dock_widget::closeEvent (e); + } -void -variable_editor::variable_destroyed (QObject *obj) -{ - // Invalidate the focus-restoring widget pointer if currently active. - if (m_focus_widget_vdw == obj) - { - m_focus_widget = nullptr; - m_focus_widget_vdw = nullptr; - } + void + variable_editor::variable_destroyed (QObject *obj) + { + // Invalidate the focus-restoring widget pointer if currently active. + if (m_focus_widget_vdw == obj) + { + m_focus_widget = nullptr; + m_focus_widget_vdw = nullptr; + } - if (m_tool_bar) - { - // If no variable pages remain, deactivate the tool bar. - QList vdwlist = findChildren (); - if (vdwlist.isEmpty ()) - m_tool_bar->setEnabled (false); - } + if (m_tool_bar) + { + // If no variable pages remain, deactivate the tool bar. + QList vdwlist = findChildren (); + if (vdwlist.isEmpty ()) + m_tool_bar->setEnabled (false); + } - QFocusEvent ev (QEvent::FocusIn); - focusInEvent (&ev); -} + QFocusEvent ev (QEvent::FocusIn); + focusInEvent (&ev); + } -void -variable_editor::variable_focused (const QString& name) -{ - m_current_focus_vname = name; + void + variable_editor::variable_focused (const QString& name) + { + m_current_focus_vname = name; - // focusWidget() appears lost in transition to/from main window - // so keep a record of the widget. + // focusWidget() appears lost in transition to/from main window + // so keep a record of the widget. - QWidget *current = QApplication::focusWidget (); - m_focus_widget = nullptr; - m_focus_widget_vdw = nullptr; - if (current != nullptr) - { - QList vdwlist = findChildren (); - for (int i = 0; i < vdwlist.size (); i++) - { - variable_dock_widget *vdw = vdwlist.at (i); - if (vdw->isAncestorOf (current)) - { - m_focus_widget = current; - m_focus_widget_vdw = vdw; - break; - } - } - } -} + QWidget *current = QApplication::focusWidget (); + m_focus_widget = nullptr; + m_focus_widget_vdw = nullptr; + if (current != nullptr) + { + QList vdwlist = findChildren (); + for (int i = 0; i < vdwlist.size (); i++) + { + variable_dock_widget *vdw = vdwlist.at (i); + if (vdw->isAncestorOf (current)) + { + m_focus_widget = current; + m_focus_widget_vdw = vdw; + break; + } + } + } + } -void -variable_editor::record_hovered_focus_variable (void) -{ - m_hovered_focus_vname = m_current_focus_vname; -} + void + variable_editor::record_hovered_focus_variable () + { + m_hovered_focus_vname = m_current_focus_vname; + } -void -variable_editor::restore_hovered_focus_variable (void) -{ - variable_dock_widget *tofocus = findChild (m_hovered_focus_vname); - if (tofocus != nullptr) - { - // Note that this may be platform and window system dependent. - // On a particular Linux system, activateWindow() alone didn't - // immediately set the active window and there was a race - // between the window focus and action signal. Setting the - // active window via the QApplication route did work. - QApplication::setActiveWindow(tofocus->window()); - tofocus->activateWindow (); - tofocus->setFocus (Qt::OtherFocusReason); - } -} + void + variable_editor::restore_hovered_focus_variable () + { + variable_dock_widget *tofocus = findChild (m_hovered_focus_vname); + if (tofocus != nullptr) + { + // Note that this may be platform and window system dependent. + // On a particular Linux system, activateWindow() alone didn't + // immediately set the active window and there was a race + // between the window focus and action signal. Setting the + // active window via the QApplication route did work. + QApplication::setActiveWindow(tofocus->window()); + tofocus->activateWindow (); + tofocus->setFocus (Qt::OtherFocusReason); + } + } -void -variable_editor::save (void) -{ - emit save_signal (); -} + void + variable_editor::save () + { + emit save_signal (); + } -void -variable_editor::cutClipboard (void) -{ - copyClipboard (); + void + variable_editor::cutClipboard () + { + copyClipboard (); - emit clear_content_signal (); -} + emit clear_content_signal (); + } -void -variable_editor::copyClipboard (void) -{ - emit copy_clipboard_signal (); -} + void + variable_editor::copyClipboard () + { + emit copy_clipboard_signal (); + } -void -variable_editor::pasteClipboard (void) -{ - emit paste_clipboard_signal (); + void + variable_editor::pasteClipboard () + { + emit paste_clipboard_signal (); - emit updated (); -} + emit updated (); + } -void -variable_editor::levelUp (void) -{ - emit level_up_signal (); -} + void + variable_editor::levelUp () + { + emit level_up_signal (); + } -// Also updates the font. + // Also updates the font. -void variable_editor::update_colors (void) -{ - m_stylesheet = ""; + void variable_editor::update_colors () + { + m_stylesheet = ""; - if (m_table_colors.length () > 0) - m_stylesheet += "QTableView::item{ color: " - + m_table_colors[0].name () +" }"; + if (m_table_colors.length () > 0) + m_stylesheet += "QTableView::item{ color: " + + m_table_colors[0].name () +" }"; - if (m_table_colors.length () > 1) - m_stylesheet += "QTableView::item{ background-color: " - + m_table_colors[1].name () +" }"; + if (m_table_colors.length () > 1) + m_stylesheet += "QTableView::item{ background-color: " + + m_table_colors[1].name () +" }"; - if (m_table_colors.length () > 2) - m_stylesheet += "QTableView::item{ selection-color: " - + m_table_colors[2].name () +" }"; + if (m_table_colors.length () > 2) + m_stylesheet += "QTableView::item{ selection-color: " + + m_table_colors[2].name () +" }"; - if (m_table_colors.length () > 3) - m_stylesheet += "QTableView::item:selected{ background-color: " - + m_table_colors[3].name () +" }"; + if (m_table_colors.length () > 3) + m_stylesheet += "QTableView::item:selected{ background-color: " + + 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 () +" }"; + if (m_table_colors.length () > 4 && m_alternate_rows) + { + m_stylesheet += "QTableView::item:alternate{ background-color: " + + m_table_colors[4].name () +" }"; - m_stylesheet += "QTableView::item:alternate:selected{ background-color: " - + m_table_colors[3].name () +" }"; - } + m_stylesheet += "QTableView::item:alternate:selected{ background-color: " + + m_table_colors[3].name () +" }"; + } - QList viewlist = findChildren (); - for (int i = 0; i < viewlist.size (); i++) - { - QTableView *view = viewlist.at (i); + QList viewlist = findChildren (); + for (int i = 0; i < viewlist.size (); i++) + { + QTableView *view = viewlist.at (i); - if (! view) - continue; + if (! view) + continue; - view->setAlternatingRowColors (m_alternate_rows); - view->setStyleSheet (m_stylesheet); - view->setFont (m_font); - } + view->setAlternatingRowColors (m_alternate_rows); + view->setStyleSheet (m_stylesheet); + view->setFont (m_font); + } -} + } -QAction * -variable_editor::add_tool_bar_button (const QIcon& icon, - const QString& text, - const QObject *receiver, - const char *member) -{ - QAction *action = new QAction (icon, text, this); - connect(action, SIGNAL (triggered ()), receiver, member); - QToolButton *button = new ReturnFocusToolButton (m_tool_bar); - button->setDefaultAction (action); - button->setText (text); - button->setToolTip (text); - button->setIcon (icon); - m_tool_bar->addWidget (button); + QAction * + variable_editor::add_tool_bar_button (const QIcon& icon, + const QString& text, + const QObject *receiver, + const char *member) + { + QAction *action = new QAction (icon, text, this); + connect(action, SIGNAL (triggered ()), receiver, member); + QToolButton *button = new ReturnFocusToolButton (m_tool_bar); + button->setDefaultAction (action); + button->setText (text); + button->setToolTip (text); + button->setIcon (icon); + m_tool_bar->addWidget (button); - return action; -} + return action; + } -void -variable_editor::construct_tool_bar (void) -{ - m_tool_bar->setAllowedAreas (Qt::TopToolBarArea); + void + variable_editor::construct_tool_bar () + { + m_tool_bar->setAllowedAreas (Qt::TopToolBarArea); - m_tool_bar->setObjectName ("VariableEditorToolBar"); + m_tool_bar->setObjectName ("VariableEditorToolBar"); - m_tool_bar->setWindowTitle (tr ("Variable Editor Toolbar")); + 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 ())); - addAction (m_save_action); - m_save_action->setShortcutContext (Qt::WidgetWithChildrenShortcut); - m_save_action->setStatusTip(tr("Save variable to a file")); + 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); + 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->setPopupMode (QToolButton::InstantPopup); + 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 (settings.icon ("document-save-as")); + save_tool_button->setPopupMode (QToolButton::InstantPopup); - QMenu *save_menu = new ReturnFocusMenu (save_tool_button); - save_menu->setTitle (tr ("Save in format ...")); - save_menu->setSeparatorsCollapsible (false); + QMenu *save_menu = new ReturnFocusMenu (save_tool_button); + save_menu->setTitle (tr ("Save in format ...")); + save_menu->setSeparatorsCollapsible (false); - m_save_mapper = new QSignalMapper (save_menu); - for (int i = 0; i < ve_save_formats.length (); i++) - m_save_mapper->setMapping - (save_menu->addAction (ve_save_formats.at (i), - m_save_mapper, SLOT (map ())), - ve_save_formats.at (i)); + m_save_mapper = new QSignalMapper (save_menu); + for (int i = 0; i < ve_save_formats.length (); i++) + m_save_mapper->setMapping + (save_menu->addAction (ve_save_formats.at (i), + m_save_mapper, SLOT (map ())), + ve_save_formats.at (i)); - save_tool_button->setMenu (save_menu); - m_tool_bar->addWidget (save_tool_button); + save_tool_button->setMenu (save_menu); + m_tool_bar->addWidget (save_tool_button); - m_tool_bar->addSeparator (); + m_tool_bar->addSeparator (); - action = add_tool_bar_button (rmgr.icon ("edit-cut"), tr ("Cut"), - this, SLOT (cutClipboard ())); - action->setStatusTip(tr("Cut data to clipboard")); + 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"), - this, SLOT (copyClipboard ())); - action->setStatusTip(tr("Copy data to clipboard")); + 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"), - this, SLOT (pasteClipboard ())); - action->setStatusTip(tr("Paste clipboard into variable data")); + action = add_tool_bar_button (settings.icon ("edit-paste"), tr ("Paste"), + this, SLOT (pasteClipboard ())); + action->setStatusTip(tr("Paste clipboard into variable data")); - m_tool_bar->addSeparator (); + m_tool_bar->addSeparator (); - // FIXME: Add a print item? - // QAction *print_action; /icons/fileprint.png - // m_tool_bar->addSeparator (); + // FIXME: Add a print item? + // QAction *print_action; /icons/fileprint.png + // m_tool_bar->addSeparator (); - action = new QAction (rmgr.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); + 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->setText (tr ("Plot")); + plot_tool_button->setToolTip (tr ("Plot selected data")); + plot_tool_button->setIcon (settings.icon ("plot-xy-curve")); - plot_tool_button->setPopupMode (QToolButton::InstantPopup); + plot_tool_button->setPopupMode (QToolButton::InstantPopup); - QMenu *plot_menu = new ReturnFocusMenu (plot_tool_button); - plot_menu->setTitle (tr ("Plot")); - plot_menu->setSeparatorsCollapsible (false); + QMenu *plot_menu = new ReturnFocusMenu (plot_tool_button); + plot_menu->setTitle (tr ("Plot")); + plot_menu->setSeparatorsCollapsible (false); - m_plot_mapper = make_plot_mapper (plot_menu); + m_plot_mapper = make_plot_mapper (plot_menu); - plot_tool_button->setMenu (plot_menu); + plot_tool_button->setMenu (plot_menu); - m_tool_bar->addWidget (plot_tool_button); + m_tool_bar->addWidget (plot_tool_button); - m_tool_bar->addSeparator (); + m_tool_bar->addSeparator (); - action = add_tool_bar_button (rmgr.icon ("go-up"), tr ("Up"), this, - SLOT (levelUp ())); - action->setStatusTip(tr("Go one level up in variable hierarchy")); + action = add_tool_bar_button (settings.icon ("go-up"), tr ("Up"), this, + SLOT (levelUp ())); + action->setStatusTip(tr("Go one level up in variable hierarchy")); - // The QToolButton mouse-clicks change active window, so connect all - // HoverToolButton and ReturnFocusToolButton objects to the mechanism - // that restores active window and focus before acting. - QList hbuttonlist - = m_tool_bar->findChildren ("" - , Qt::FindDirectChildrenOnly - ); - for (int i = 0; i < hbuttonlist.size (); i++) - { - connect (hbuttonlist.at (i), &HoverToolButton::hovered_signal, - this, &variable_editor::record_hovered_focus_variable); - connect (hbuttonlist.at (i), &HoverToolButton::popup_shown_signal, - this, &variable_editor::restore_hovered_focus_variable); - } + // The QToolButton mouse-clicks change active window, so connect all + // HoverToolButton and ReturnFocusToolButton objects to the mechanism + // that restores active window and focus before acting. + QList hbuttonlist + = m_tool_bar->findChildren ("" + , Qt::FindDirectChildrenOnly + ); + for (int i = 0; i < hbuttonlist.size (); i++) + { + connect (hbuttonlist.at (i), &HoverToolButton::hovered_signal, + this, &variable_editor::record_hovered_focus_variable); + connect (hbuttonlist.at (i), &HoverToolButton::popup_shown_signal, + this, &variable_editor::restore_hovered_focus_variable); + } - QList rfbuttonlist - = m_tool_bar->findChildren ("" - , Qt::FindDirectChildrenOnly - ); - for (int i = 0; i < rfbuttonlist.size (); i++) - { - connect (rfbuttonlist.at (i), &ReturnFocusToolButton::about_to_activate, - this, &variable_editor::restore_hovered_focus_variable); - } + QList rfbuttonlist + = m_tool_bar->findChildren ("" + , Qt::FindDirectChildrenOnly + ); + for (int i = 0; i < rfbuttonlist.size (); i++) + { + connect (rfbuttonlist.at (i), &ReturnFocusToolButton::about_to_activate, + this, &variable_editor::restore_hovered_focus_variable); + } - // Same for QMenu - QList menulist - = m_tool_bar->findChildren (); - for (int i = 0; i < menulist.size (); i++) - { - connect (menulist.at (i), &ReturnFocusMenu::about_to_activate, - this, &variable_editor::restore_hovered_focus_variable); - } + // Same for QMenu + QList menulist + = m_tool_bar->findChildren (); + for (int i = 0; i < menulist.size (); i++) + { + connect (menulist.at (i), &ReturnFocusMenu::about_to_activate, + this, &variable_editor::restore_hovered_focus_variable); + } - m_tool_bar->setAttribute(Qt::WA_ShowWithoutActivating); - m_tool_bar->setFocusPolicy (Qt::NoFocus); + m_tool_bar->setAttribute(Qt::WA_ShowWithoutActivating); + m_tool_bar->setFocusPolicy (Qt::NoFocus); - // Disabled when no tab is present. + // Disabled when no tab is present. - m_tool_bar->setEnabled (false); -} + m_tool_bar->setEnabled (false); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/variable-editor.h --- a/libgui/src/variable-editor.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/variable-editor.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,6 @@ #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,375 +44,369 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class variable_editor_model; + class variable_editor_view; -class variable_editor_model; -class variable_editor_view; - -// The individual variable subwindow class + // The individual variable subwindow class -class variable_dock_widget : public label_dock_widget -{ - Q_OBJECT + class variable_dock_widget : public label_dock_widget + { + Q_OBJECT -public: + public: - variable_dock_widget (QWidget *p, base_qobject& oct_qobj); + variable_dock_widget (QWidget *p); + + ~variable_dock_widget () = default; - ~variable_dock_widget (void) = default; + signals: -signals: + void variable_focused_signal (const QString& name); - void variable_focused_signal (const QString& name); + protected: -protected: + virtual void closeEvent (QCloseEvent *e); - virtual void closeEvent (QCloseEvent *e); + void resizeEvent (QResizeEvent *event); - void resizeEvent (QResizeEvent *event); + public slots: -public slots: + void handle_focus_change (QWidget *old, QWidget *now); - void handle_focus_change (QWidget *old, QWidget *now); - -private slots: + private slots: - void change_floating (bool); + void change_floating (bool); - void change_existence (bool); + void change_existence (bool); - void toplevel_change (bool); + void toplevel_change (bool); - void change_fullscreen (void); + void change_fullscreen (); -protected: + protected: - QFrame *m_frame; + QFrame *m_frame; - QAction *m_fullscreen_action; + QAction *m_fullscreen_action; - bool m_full_screen; + bool m_full_screen; - bool m_prev_floating; + bool m_prev_floating; - QRect m_prev_geom; + 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: + signals: - void queue_unfloat_float (void); + void queue_unfloat_float (); - void queue_float (void); + void queue_float (); -protected slots: + 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: + protected: - bool event (QEvent *event); + bool event (QEvent *event); -private: + private: - bool m_waiting_for_mouse_move; + bool m_waiting_for_mouse_move; - bool m_waiting_for_mouse_button_release; + bool m_waiting_for_mouse_button_release; #endif -}; + }; -class variable_editor_stack : public QStackedWidget -{ - Q_OBJECT + class variable_editor_stack : public QStackedWidget + { + Q_OBJECT -public: + 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: + signals: - void edit_variable_signal (const QString& name, const octave_value& val); + void edit_variable_signal (const QString& name, const octave_value& val); - void do_save_signal (const QString& format, const QString& save_opts); + void do_save_signal (const QString& format, const QString& save_opts); - void interpreter_event (const fcn_callback& fcn); - void interpreter_event (const meth_callback& meth); + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); -public slots: + public slots: - void set_editable (bool editable); + void set_editable (bool editable); - void levelUp (void); + void levelUp (); - void save (const QString& format = QString ()); + void save (const QString& format = QString ()); - void do_save (const QString& format, const QString& save_opts); + void do_save (const QString& format, const QString& save_opts); -private: + private: - QTextEdit * make_disp_view (QWidget *parent); + QTextEdit * make_disp_view (QWidget *parent); - base_qobject& m_octave_qobj; + variable_editor_view *m_edit_view; - variable_editor_view *m_edit_view; + QTextEdit *m_disp_view; + }; - QTextEdit *m_disp_view; -}; + class variable_editor_view : public QTableView + { + Q_OBJECT -class variable_editor_view : public QTableView -{ - Q_OBJECT + public: -public: + variable_editor_view (QWidget *p); + + ~variable_editor_view () = default; - variable_editor_view (QWidget *p, base_qobject& oct_qobj); + void setModel (QAbstractItemModel *model); - ~variable_editor_view (void) = default; - - void setModel (QAbstractItemModel *model); + signals: -signals: + void command_signal (const QString& cmd); - void command_signal (const QString& cmd); + void add_edit_actions_signal (QMenu *menu, const QString& qualifier_string); - void add_edit_actions_signal (QMenu *menu, const QString& qualifier_string); + public slots: -public slots: + void createVariable (); - void createVariable (void); + void transposeContent (); - void transposeContent (void); + QList range_selected (); - QList range_selected (void); + void delete_selected (); - void delete_selected (void); + void clearContent (); - void clearContent (void); + void cutClipboard (); - void cutClipboard (void); + void copyClipboard (); - void copyClipboard (void); - - void pasteClipboard (void); + void pasteClipboard (); - void handle_horizontal_scroll_action (int action); + void handle_horizontal_scroll_action (int action); - void handle_vertical_scroll_action (int action); + void handle_vertical_scroll_action (int action); - void createContextMenu (const QPoint& pt); + void createContextMenu (const QPoint& pt); - void createColumnMenu (const QPoint& pt); + void createColumnMenu (const QPoint& pt); - void createRowMenu (const QPoint& pt); + void createRowMenu (const QPoint& pt); - void selected_command_requested (const QString& cmd); + void selected_command_requested (const QString& cmd); -private: + private: - void add_edit_actions (QMenu *menu, const QString& qualifier_string); + void add_edit_actions (QMenu *menu, const QString& qualifier_string); - base_qobject& m_octave_qobj; + variable_editor_model *m_var_model; + }; - variable_editor_model *m_var_model; -}; + // Gadgets to keep track of and restore what variable window was in focus + // just prior to selecting something on the menu bar. -// Gadgets to keep track of and restore what variable window was in focus -// just prior to selecting something on the menu bar. + class HoverToolButton : public QToolButton + { + Q_OBJECT -class HoverToolButton : public QToolButton -{ - Q_OBJECT + public: -public: + HoverToolButton (QWidget *parent = nullptr); - HoverToolButton (QWidget *parent = nullptr); + ~HoverToolButton () = default; - ~HoverToolButton (void) = default; + signals: -signals: + void hovered_signal (); - void hovered_signal (void); + void popup_shown_signal (); - void popup_shown_signal (void); + protected: -protected: + bool eventFilter (QObject *obj, QEvent *ev); + }; - bool eventFilter (QObject *obj, QEvent *ev); -}; + class ReturnFocusToolButton : public HoverToolButton + { + Q_OBJECT -class ReturnFocusToolButton : public HoverToolButton -{ - Q_OBJECT + public: -public: + ReturnFocusToolButton (QWidget *parent = nullptr); + + ~ReturnFocusToolButton () = default; - ReturnFocusToolButton (QWidget *parent = nullptr); - - ~ReturnFocusToolButton (void) = default; + signals: -signals: + void about_to_activate (); - void about_to_activate (void); + protected: -protected: + bool eventFilter (QObject *obj, QEvent *ev); + }; - bool eventFilter (QObject *obj, QEvent *ev); -}; + class ReturnFocusMenu : public QMenu + { + Q_OBJECT -class ReturnFocusMenu : public QMenu -{ - Q_OBJECT + public: -public: + ReturnFocusMenu (QWidget *parent = nullptr); - ReturnFocusMenu (QWidget *parent = nullptr); + ~ReturnFocusMenu () = default; - ~ReturnFocusMenu (void) = default; + signals: -signals: + void about_to_activate (); - void about_to_activate (void); - -protected: + protected: - bool eventFilter (QObject *obj, QEvent *ev); -}; + bool eventFilter (QObject *obj, QEvent *ev); + }; -// The variable editor class + // The variable editor class -class variable_editor : public octave_dock_widget -{ - Q_OBJECT + class variable_editor : public octave_dock_widget + { + Q_OBJECT + + public: -public: + variable_editor (QWidget *parent); - variable_editor (QWidget *parent, base_qobject& oct_qobj); + ~variable_editor (); - ~variable_editor (void); + // No copying! - // No copying! + variable_editor (const variable_editor&) = delete; - variable_editor (const variable_editor&) = delete; + variable_editor& operator = (const variable_editor&) = delete; - variable_editor& operator = (const variable_editor&) = delete; + void refresh (); - void refresh (void); + void tab_to_front (); - void tab_to_front (void); + signals: -signals: + void updated (); - void updated (void); + void finished (); - void finished (void); + void command_signal (const QString& cmd); - void command_signal (const QString& cmd); + void refresh_signal (); - void refresh_signal (void); + void clear_content_signal (); - void clear_content_signal (void); + void copy_clipboard_signal (); - void copy_clipboard_signal (void); + void paste_clipboard_signal (); - void paste_clipboard_signal (void); - - 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); + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); -public slots: + public slots: - void callUpdate (const QModelIndex&, const QModelIndex&); + 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); + void edit_variable (const QString& name, const octave_value& val); - void variable_destroyed (QObject *obj); + void variable_destroyed (QObject *obj); - void variable_focused (const QString& name); + 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: + protected slots: - void closeEvent (QCloseEvent *); + 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: + protected: - void focusInEvent (QFocusEvent *ev); + void focusInEvent (QFocusEvent *ev); -private: + private: - dw_main_window *m_main; + dw_main_window *m_main; - QToolBar *m_tool_bar; - QAction *m_save_action; + QToolBar *m_tool_bar; + QAction *m_save_action; - int m_default_width; + int m_default_width; - int m_default_height; + int m_default_height; - int m_add_font_height; + int m_add_font_height; - bool m_use_terminal_font; + bool m_use_terminal_font; - bool m_alternate_rows; + bool m_alternate_rows; - QString m_stylesheet; + QString m_stylesheet; - QFont m_font; + QFont m_font; - // If use_terminal_font is true then this will be different since - // "font" will contain the terminal font. - QFont m_sel_font; + // If use_terminal_font is true then this will be different since + // "font" will contain the terminal font. + QFont m_sel_font; - QList m_table_colors; + 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); + 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; + QString m_current_focus_vname; - QString m_hovered_focus_vname; + QString m_hovered_focus_vname; - QSignalMapper *m_plot_mapper; - QSignalMapper *m_save_mapper; + QSignalMapper *m_plot_mapper; + QSignalMapper *m_save_mapper; - QWidget *m_focus_widget; + QWidget *m_focus_widget; - variable_dock_widget *m_focus_widget_vdw; -}; + variable_dock_widget *m_focus_widget_vdw; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/welcome-wizard.cc --- a/libgui/src/welcome-wizard.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/welcome-wizard.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,352 +39,343 @@ #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) -static QLabel * -make_octave_logo (QWidget *p = nullptr, int height = 100) -{ - QLabel *logo = new QLabel (p); - QPixmap logo_pixmap (dw_icon_set_names["NONE"]); - logo->setPixmap (logo_pixmap.scaledToHeight (height)); - return logo; -}; + static QLabel * + make_octave_logo (QWidget *p = nullptr, int height = 100) + { + QLabel *logo = new QLabel (p); + QPixmap logo_pixmap (dw_icon_set_names["NONE"]); + logo->setPixmap (logo_pixmap.scaledToHeight (height)); + 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)), - m_allow_web_connect_state (false), - m_max_height (0), m_max_width (0) -{ - m_page_ctor_list.push_back (initial_page::create); - m_page_ctor_list.push_back (setup_community_news::create); - m_page_ctor_list.push_back (final_page::create); + 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) + { + m_page_ctor_list.push_back (initial_page::create); + m_page_ctor_list.push_back (setup_community_news::create); + m_page_ctor_list.push_back (final_page::create); - m_page_list_iterator = m_page_ctor_list.begin (); + m_page_list_iterator = m_page_ctor_list.begin (); - setWindowTitle (tr ("Welcome to GNU Octave")); + setWindowTitle (tr ("Welcome to GNU Octave")); - setEnabled (true); + setEnabled (true); - setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - // Create all pages for pre-setting the minimal required size for all pages - show_page (); - adjust_size (); - next_page (); - adjust_size (); - next_page (); - adjust_size (); - // now go back to the first page - previous_page (); - previous_page (); + // Create all pages for pre-setting the minimal required size for all pages + show_page (); + adjust_size (); + next_page (); + adjust_size (); + next_page (); + adjust_size (); + // now go back to the first page + previous_page (); + previous_page (); - // Set the size determined above - resize (m_max_width, m_max_height); + // Set the size determined above + resize (m_max_width, m_max_height); #if defined (OCTAVE_USE_WINDOWS_API) - // HACK to forceshow of dialog if started minimized - ShowWindow (reinterpret_cast (winId ()), SW_SHOWNORMAL); + // HACK to forceshow of dialog if started minimized + ShowWindow (reinterpret_cast (winId ()), SW_SHOWNORMAL); #endif -} + } -void welcome_wizard::adjust_size (void) -{ - // Get adjusted size for the current page - adjustSize (); - QSize sz = size (); + void welcome_wizard::adjust_size () + { + // Get adjusted size for the current page + adjustSize (); + QSize sz = size (); - // Update the max. size of the three pages if required + // Update the max. size of the three pages if required - if (sz.height () > m_max_height) - m_max_height = sz.height (); + if (sz.height () > m_max_height) + m_max_height = sz.height (); - if (sz.width () > m_max_width) - m_max_width = sz.width (); -} - -void welcome_wizard::handle_web_connect_option (int state) -{ - m_allow_web_connect_state = state == Qt::Checked; -} + if (sz.width () > m_max_width) + m_max_width = sz.width (); + } -void welcome_wizard::show_page (void) -{ - delete m_current_page; - delete layout (); + void welcome_wizard::handle_web_connect_option (int state) + { + m_allow_web_connect_state = state == Qt::Checked; + } - m_current_page = (*m_page_list_iterator) (m_octave_qobj, this); + void welcome_wizard::show_page () + { + delete m_current_page; + delete layout (); - QVBoxLayout *new_layout = new QVBoxLayout (); - setLayout (new_layout); + m_current_page = (*m_page_list_iterator) (this); - new_layout->addWidget (m_current_page); -} + QVBoxLayout *new_layout = new QVBoxLayout (); + setLayout (new_layout); -void welcome_wizard::previous_page (void) -{ - --m_page_list_iterator; + new_layout->addWidget (m_current_page); + } - show_page (); -} + void welcome_wizard::previous_page () + { + --m_page_list_iterator; -void welcome_wizard::next_page (void) -{ - ++m_page_list_iterator; - - show_page (); -} + show_page (); + } -void welcome_wizard::accept (void) -{ - // Create default settings file. + void welcome_wizard::next_page () + { + ++m_page_list_iterator; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - rmgr.reload_settings (); - - gui_settings *settings = rmgr.get_settings (); + show_page (); + } - if (settings) - { - settings->setValue (nr_allow_connection.key, - m_allow_web_connect_state); + void welcome_wizard::accept () + { + // Create default settings file. + + gui_settings settings; - settings->sync (); - } + settings.setValue (nr_allow_connection.settings_key (), m_allow_web_connect_state); - QDialog::accept (); -} + settings.sync (); + + QDialog::accept (); + } -initial_page::initial_page (base_qobject& oct_qobj, welcome_wizard *wizard) - : QWidget (wizard), - m_title (new QLabel (tr ("Welcome to Octave!"), this)), - m_message (new QLabel (this)), - m_logo (make_octave_logo (this)), - m_next (new QPushButton (tr ("Next"), this)), - m_cancel (new QPushButton (tr ("Cancel"), this)) -{ - QFont ft; - ft.setPointSize (20); - m_title->setFont (ft); + initial_page::initial_page (welcome_wizard *wizard) + : QWidget (wizard), + m_title (new QLabel (tr ("Welcome to Octave!"), this)), + m_message (new QLabel (this)), + m_logo (make_octave_logo (this)), + m_next (new QPushButton (tr ("Next"), this)), + m_cancel (new QPushButton (tr ("Cancel"), this)) + { + QFont ft; + ft.setPointSize (20); + m_title->setFont (ft); - resource_manager& rmgr = oct_qobj.get_resource_manager (); + gui_settings settings; - m_message->setText - (tr ("\n" - "

You seem to be using the Octave graphical interface for the first time on this computer.\n" - "Click 'Next' to create a configuration file and launch Octave.

\n" - "

The configuration file is stored in
%1.

\n" - ""). - arg (rmgr.get_settings_file ())); - m_message->setWordWrap (true); - m_message->setMinimumWidth (400); + m_message->setText + (tr ("\n" + "

You seem to be using the Octave graphical interface for the first time on this computer.\n" + "Click 'Next' to create a configuration file and launch Octave.

\n" + "

The configuration file is stored in
%1.

\n" + ""). + arg (settings.file_name ())); + m_message->setWordWrap (true); + m_message->setMinimumWidth (400); - QVBoxLayout *message_layout = new QVBoxLayout; + QVBoxLayout *message_layout = new QVBoxLayout; - message_layout->addWidget (m_title); - message_layout->addWidget (m_message); + message_layout->addWidget (m_title); + message_layout->addWidget (m_message); - QHBoxLayout *message_and_logo = new QHBoxLayout; + QHBoxLayout *message_and_logo = new QHBoxLayout; - message_and_logo->addLayout (message_layout); - message_and_logo->addStretch (10); - message_and_logo->addWidget (m_logo, 0, Qt::AlignTop); - - QHBoxLayout *button_bar = new QHBoxLayout; + message_and_logo->addLayout (message_layout); + message_and_logo->addStretch (10); + message_and_logo->addWidget (m_logo, 0, Qt::AlignTop); - button_bar->addStretch (10); - button_bar->addWidget (m_next); - button_bar->addWidget (m_cancel); + QHBoxLayout *button_bar = new QHBoxLayout; - QVBoxLayout *page_layout = new QVBoxLayout (this); - setLayout (page_layout); + button_bar->addStretch (10); + button_bar->addWidget (m_next); + button_bar->addWidget (m_cancel); + + QVBoxLayout *page_layout = new QVBoxLayout (this); + setLayout (page_layout); - page_layout->addLayout (message_and_logo); - page_layout->addStretch (10); - page_layout->addSpacing (20); - page_layout->addLayout (button_bar); + page_layout->addLayout (message_and_logo); + page_layout->addStretch (10); + page_layout->addSpacing (20); + page_layout->addLayout (button_bar); - setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - m_next->setDefault (true); - m_next->setFocus (); + m_next->setDefault (true); + m_next->setFocus (); - connect (m_next, &QPushButton::clicked, wizard, &welcome_wizard::next_page); - connect (m_cancel, &QPushButton::clicked, wizard, &welcome_wizard::reject); -} + connect (m_next, &QPushButton::clicked, wizard, &welcome_wizard::next_page); + connect (m_cancel, &QPushButton::clicked, wizard, &welcome_wizard::reject); + } -setup_community_news::setup_community_news (base_qobject&, - welcome_wizard *wizard) - : QWidget (wizard), - m_title (new QLabel (tr ("Community News"), this)), - m_message (new QLabel (this)), - m_checkbox (new QCheckBox (this)), - m_checkbox_message (new QLabel (this)), - m_logo (make_octave_logo (this)), - m_previous (new QPushButton (tr ("Previous"), this)), - m_next (new QPushButton (tr ("Next"), this)), - m_cancel (new QPushButton (tr ("Cancel"), this)) -{ - QFont ft; - ft.setPointSize (20); - m_title->setFont (ft); + setup_community_news::setup_community_news (welcome_wizard *wizard) + : QWidget (wizard), + m_title (new QLabel (tr ("Community News"), this)), + m_message (new QLabel (this)), + m_checkbox (new QCheckBox (this)), + m_checkbox_message (new QLabel (this)), + m_logo (make_octave_logo (this)), + m_previous (new QPushButton (tr ("Previous"), this)), + m_next (new QPushButton (tr ("Next"), this)), + m_cancel (new QPushButton (tr ("Cancel"), this)) + { + QFont ft; + ft.setPointSize (20); + m_title->setFont (ft); - m_message->setText - (tr ("\n" - "

When Octave starts, it will optionally check the Octave web site for current news and information about the Octave community.\n" - "The check will happen at most once each day and news will only be displayed if there is something new since the last time you viewed the news.

\n" - "

You may also view the news by selecting the \"Community News\" item in the \"Help\" menu, or by visiting\n" - "https://octave.org/community-news.html.

\n" - "")); - m_message->setWordWrap (true); - m_message->setMinimumWidth (400); - m_message->setOpenExternalLinks (true); + m_message->setText + (tr ("\n" + "

When Octave starts, it will optionally check the Octave web site for current news and information about the Octave community.\n" + "The check will happen at most once each day and news will only be displayed if there is something new since the last time you viewed the news.

\n" + "

You may also view the news by selecting the \"Community News\" item in the \"Help\" menu, or by visiting\n" + "https://octave.org/community-news.html.

\n" + "")); + m_message->setWordWrap (true); + m_message->setMinimumWidth (400); + m_message->setOpenExternalLinks (true); - QVBoxLayout *message_layout = new QVBoxLayout; + QVBoxLayout *message_layout = new QVBoxLayout; - message_layout->addWidget (m_title); - message_layout->addWidget (m_message); + message_layout->addWidget (m_title); + message_layout->addWidget (m_message); - QHBoxLayout *message_and_logo = new QHBoxLayout; + QHBoxLayout *message_and_logo = new QHBoxLayout; - message_and_logo->addLayout (message_layout); - message_and_logo->addStretch (10); - message_and_logo->addWidget (m_logo, 0, Qt::AlignTop); + message_and_logo->addLayout (message_layout); + message_and_logo->addStretch (10); + message_and_logo->addWidget (m_logo, 0, Qt::AlignTop); - QHBoxLayout *checkbox_layout = new QHBoxLayout; + QHBoxLayout *checkbox_layout = new QHBoxLayout; - bool allow_connection = nr_allow_connection.def.toBool (); - if (allow_connection) - m_checkbox->setCheckState (Qt::Checked); - else - m_checkbox->setCheckState (Qt::Unchecked); + bool allow_connection = nr_allow_connection.def ().toBool (); + if (allow_connection) + m_checkbox->setCheckState (Qt::Checked); + else + m_checkbox->setCheckState (Qt::Unchecked); - m_checkbox_message->setText - (tr ("\n" - "\n" - "

Allow Octave to connect to the Octave web site when it starts to display current news and information about the Octave community.

\n" - "")); - m_checkbox_message->setWordWrap (true); - m_checkbox_message->setOpenExternalLinks (true); - m_checkbox_message->setMinimumWidth (500); + m_checkbox_message->setText + (tr ("\n" + "\n" + "

Allow Octave to connect to the Octave web site when it starts to display current news and information about the Octave community.

\n" + "")); + m_checkbox_message->setWordWrap (true); + m_checkbox_message->setOpenExternalLinks (true); + m_checkbox_message->setMinimumWidth (500); - checkbox_layout->addWidget (m_checkbox, 0, Qt::AlignTop); - checkbox_layout->addSpacing (20); - checkbox_layout->addWidget (m_checkbox_message, 0, Qt::AlignTop); - checkbox_layout->addStretch (10); + checkbox_layout->addWidget (m_checkbox, 0, Qt::AlignTop); + checkbox_layout->addSpacing (20); + checkbox_layout->addWidget (m_checkbox_message, 0, Qt::AlignTop); + checkbox_layout->addStretch (10); - QVBoxLayout *message_logo_and_checkbox = new QVBoxLayout; + QVBoxLayout *message_logo_and_checkbox = new QVBoxLayout; - message_logo_and_checkbox->addLayout (message_and_logo); - message_logo_and_checkbox->addSpacing (20); - message_logo_and_checkbox->addLayout (checkbox_layout); + message_logo_and_checkbox->addLayout (message_and_logo); + message_logo_and_checkbox->addSpacing (20); + message_logo_and_checkbox->addLayout (checkbox_layout); - QHBoxLayout *button_bar = new QHBoxLayout; + QHBoxLayout *button_bar = new QHBoxLayout; - button_bar->addStretch (10); - button_bar->addWidget (m_previous); - button_bar->addWidget (m_next); - button_bar->addWidget (m_cancel); + button_bar->addStretch (10); + button_bar->addWidget (m_previous); + button_bar->addWidget (m_next); + button_bar->addWidget (m_cancel); - QVBoxLayout *page_layout = new QVBoxLayout (this); - setLayout (page_layout); + QVBoxLayout *page_layout = new QVBoxLayout (this); + setLayout (page_layout); - page_layout->addLayout (message_logo_and_checkbox); - page_layout->addStretch (10); - page_layout->addSpacing (20); - page_layout->addLayout (button_bar); + page_layout->addLayout (message_logo_and_checkbox); + page_layout->addStretch (10); + page_layout->addSpacing (20); + page_layout->addLayout (button_bar); - setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - m_next->setDefault (true); - m_next->setFocus (); + m_next->setDefault (true); + m_next->setFocus (); - connect (m_checkbox, &QCheckBox::stateChanged, - wizard, &welcome_wizard::handle_web_connect_option); + connect (m_checkbox, &QCheckBox::stateChanged, + wizard, &welcome_wizard::handle_web_connect_option); - connect (m_previous, &QPushButton::clicked, wizard, &welcome_wizard::previous_page); - connect (m_next, &QPushButton::clicked, wizard, &welcome_wizard::next_page); - connect (m_cancel, &QPushButton::clicked, wizard, &welcome_wizard::reject); -} + connect (m_previous, &QPushButton::clicked, wizard, &welcome_wizard::previous_page); + connect (m_next, &QPushButton::clicked, wizard, &welcome_wizard::next_page); + connect (m_cancel, &QPushButton::clicked, wizard, &welcome_wizard::reject); + } -final_page::final_page (base_qobject&, welcome_wizard *wizard) - : QWidget (wizard), - m_title (new QLabel (tr ("Enjoy!"), this)), - m_message (new QLabel (this)), - m_logo (make_octave_logo (this)), - m_links (new QLabel (this)), - m_previous (new QPushButton (tr ("Previous"), this)), - m_finish (new QPushButton (tr ("Finish"), this)), - m_cancel (new QPushButton (tr ("Cancel"), this)) -{ - QFont ft; - ft.setPointSize (20); - m_title->setFont (ft); + final_page::final_page (welcome_wizard *wizard) + : QWidget (wizard), + m_title (new QLabel (tr ("Enjoy!"), this)), + m_message (new QLabel (this)), + m_logo (make_octave_logo (this)), + m_links (new QLabel (this)), + m_previous (new QPushButton (tr ("Previous"), this)), + m_finish (new QPushButton (tr ("Finish"), this)), + m_cancel (new QPushButton (tr ("Cancel"), this)) + { + QFont ft; + ft.setPointSize (20); + m_title->setFont (ft); - m_message->setText - (tr ("\n" - "

We hope you find Octave to be a useful tool.

\n" - "

If you encounter problems, there are a number of ways to get help, including commercial support options, a mailing list, a wiki, and other community-based support channels.\n" - "You can find more information about each of these by visiting https://octave.org/support.html (opens in external browser).

\n" - "")); - m_message->setWordWrap (true); - m_message->setMinimumWidth (400); - m_message->setOpenExternalLinks (true); + m_message->setText + (tr ("\n" + "

We hope you find Octave to be a useful tool.

\n" + "

If you encounter problems, there are a number of ways to get help, including commercial support options, a mailing list, a wiki, and other community-based support channels.\n" + "You can find more information about each of these by visiting https://octave.org/support.html (opens in external browser).

\n" + "")); + m_message->setWordWrap (true); + m_message->setMinimumWidth (400); + m_message->setOpenExternalLinks (true); - QVBoxLayout *message_layout = new QVBoxLayout; + QVBoxLayout *message_layout = new QVBoxLayout; - message_layout->addWidget (m_title); - message_layout->addWidget (m_message); + message_layout->addWidget (m_title); + message_layout->addWidget (m_message); - QHBoxLayout *message_and_logo = new QHBoxLayout; + QHBoxLayout *message_and_logo = new QHBoxLayout; - message_and_logo->addLayout (message_layout); - message_and_logo->addStretch (10); - message_and_logo->addWidget (m_logo, 0, Qt::AlignTop); + message_and_logo->addLayout (message_layout); + message_and_logo->addStretch (10); + message_and_logo->addWidget (m_logo, 0, Qt::AlignTop); - m_links->setText - (tr ("\n" - "\n" - "

For more information about Octave:

\n" - "
    \n" - "
  • Visit https://octave.org (opens in external browser)
  • \n" - "
  • Get the documentation online as html- or pdf-document (opens in external browser)
  • \n" - "
  • Open the documentation browser of the Octave GUI with the help menu
  • \n" - "
\n" - "")); - m_links->setWordWrap (true); - m_links->setOpenExternalLinks (true); + m_links->setText + (tr ("\n" + "\n" + "

For more information about Octave:

\n" + "
    \n" + "
  • Visit https://octave.org (opens in external browser)
  • \n" + "
  • Get the documentation online as html- or pdf-document (opens in external browser)
  • \n" + "
  • Open the documentation browser of the Octave GUI with the help menu
  • \n" + "
\n" + "")); + m_links->setWordWrap (true); + m_links->setOpenExternalLinks (true); - QHBoxLayout *button_bar = new QHBoxLayout; + QHBoxLayout *button_bar = new QHBoxLayout; - button_bar->addStretch (10); - button_bar->addWidget (m_previous); - button_bar->addWidget (m_finish); - button_bar->addWidget (m_cancel); + button_bar->addStretch (10); + button_bar->addWidget (m_previous); + button_bar->addWidget (m_finish); + button_bar->addWidget (m_cancel); - QVBoxLayout *page_layout = new QVBoxLayout (this); - setLayout (page_layout); + QVBoxLayout *page_layout = new QVBoxLayout (this); + setLayout (page_layout); - page_layout->addLayout (message_and_logo); - page_layout->addSpacing (20); - page_layout->addWidget (m_links); - page_layout->addStretch (10); - page_layout->addSpacing (20); - page_layout->addLayout (button_bar); + page_layout->addLayout (message_and_logo); + page_layout->addSpacing (20); + page_layout->addWidget (m_links); + page_layout->addStretch (10); + page_layout->addSpacing (20); + page_layout->addLayout (button_bar); - setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - m_finish->setDefault (true); - m_finish->setFocus (); + m_finish->setDefault (true); + m_finish->setFocus (); - connect (m_previous, &QPushButton::clicked, - wizard, &welcome_wizard::previous_page); - connect (m_finish, &QPushButton::clicked, wizard, &welcome_wizard::accept); - connect (m_cancel, &QPushButton::clicked, wizard, &welcome_wizard::reject); -} + connect (m_previous, &QPushButton::clicked, + wizard, &welcome_wizard::previous_page); + connect (m_finish, &QPushButton::clicked, wizard, &welcome_wizard::accept); + connect (m_cancel, &QPushButton::clicked, wizard, &welcome_wizard::reject); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/welcome-wizard.h --- a/libgui/src/welcome-wizard.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/welcome-wizard.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,123 +32,119 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class welcome_wizard : public QDialog + { + Q_OBJECT -class welcome_wizard : public QDialog -{ - Q_OBJECT + public: -public: + typedef QWidget *(*page_creator_fptr) (welcome_wizard *); - typedef QWidget *(*page_creator_fptr) (base_qobject&, welcome_wizard *); + welcome_wizard (QWidget *parent = nullptr); - welcome_wizard (base_qobject& oct_qobj, QWidget *parent = nullptr); + ~welcome_wizard () = default; - ~welcome_wizard (void) = default; + void adjust_size (); - void adjust_size (void); - -private: + private: - base_qobject& m_octave_qobj; + QList m_page_ctor_list; + QList::iterator m_page_list_iterator; + QWidget *m_current_page; + bool m_allow_web_connect_state; + int m_max_height; + int m_max_width; - QList m_page_ctor_list; - QList::iterator m_page_list_iterator; - QWidget *m_current_page; - bool m_allow_web_connect_state; - int m_max_height; - int m_max_width; + public slots: -public slots: + void handle_web_connect_option (int state); - void handle_web_connect_option (int state); + void show_page (); + void previous_page (); + void next_page (); - void show_page (void); - void previous_page (void); - void next_page (void); + void accept (); + }; - void accept (void); -}; + class initial_page : public QWidget + { + Q_OBJECT -class initial_page : public QWidget -{ - Q_OBJECT + public: -public: + initial_page (welcome_wizard *wizard); - initial_page (base_qobject& oct_qobj, welcome_wizard *wizard); + ~initial_page () = default; - ~initial_page (void) = default; + static QWidget * + create (welcome_wizard *wizard) + { + return new initial_page (wizard); + } - static QWidget * - create (base_qobject& oct_qobj, welcome_wizard *wizard) - { - return new initial_page (oct_qobj, wizard); - } - -private: + private: - QLabel *m_title; - QLabel *m_message; - QLabel *m_logo; - QPushButton *m_next; - QPushButton *m_cancel; -}; + QLabel *m_title; + QLabel *m_message; + QLabel *m_logo; + QPushButton *m_next; + QPushButton *m_cancel; + }; -class setup_community_news : public QWidget -{ - Q_OBJECT + class setup_community_news : public QWidget + { + Q_OBJECT -public: + 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) - { - return new setup_community_news (oct_qobj, wizard); - } + static QWidget * + create (welcome_wizard *wizard) + { + return new setup_community_news (wizard); + } -private: + private: - QLabel *m_title; - QLabel *m_message; - QCheckBox *m_checkbox; - QLabel *m_checkbox_message; - QLabel *m_logo; - QPushButton *m_previous; - QPushButton *m_next; - QPushButton *m_cancel; -}; + QLabel *m_title; + QLabel *m_message; + QCheckBox *m_checkbox; + QLabel *m_checkbox_message; + QLabel *m_logo; + QPushButton *m_previous; + QPushButton *m_next; + QPushButton *m_cancel; + }; -class final_page : public QWidget -{ - Q_OBJECT + class final_page : public QWidget + { + Q_OBJECT -public: + 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) - { - return new final_page (oct_qobj, wizard); - } + static QWidget * + create (welcome_wizard *wizard) + { + return new final_page (wizard); + } -private: + private: - QLabel *m_title; - QLabel *m_message; - QLabel *m_logo; - QLabel *m_links; - QPushButton *m_previous; - QPushButton *m_finish; - QPushButton *m_cancel; -}; + QLabel *m_title; + QLabel *m_message; + QLabel *m_logo; + QLabel *m_links; + QPushButton *m_previous; + QPushButton *m_finish; + QPushButton *m_cancel; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/workspace-model.cc --- a/libgui/src/workspace-model.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/workspace-model.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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" @@ -41,235 +41,249 @@ OCTAVE_BEGIN_NAMESPACE(octave) -workspace_model::workspace_model (QObject *p) -: QAbstractTableModel (p) -{ - // The header names. Use tr () again when accessing them since - // the translator si not yet initialized when this ctor is called - m_columnNames.append (tr ("Name")); - m_columnNames.append (tr ("Class")); - m_columnNames.append (tr ("Dimension")); - m_columnNames.append (tr ("Value")); - m_columnNames.append (tr ("Attribute")); + workspace_model::workspace_model (QObject *p) + : QAbstractTableModel (p) + { + // The header names. Use tr () again when accessing them since + // the translator si not yet initialized when this ctor is called + m_columnNames.append (tr ("Name")); + m_columnNames.append (tr ("Class")); + m_columnNames.append (tr ("Dimension")); + m_columnNames.append (tr ("Value")); + m_columnNames.append (tr ("Attribute")); - // Initialize the background and foreground colors of special - // classes in the workspace view. The structure is - // m_storage_class_colors(1,2,...,colors): background colors - // m_storage_class_colors(colors+1,...,2*colors): foreground colors - for (unsigned int i = 0; i < 2*ws_colors_count; i++) - m_storage_class_colors.append (QColor (Qt::white)); + // Initialize the background and foreground colors of special + // classes in the workspace view. The structure is + // m_storage_class_colors(1,2,...,colors): background colors + // m_storage_class_colors(colors+1,...,2*colors): foreground colors + for (unsigned int i = 0; i < 2*ws_colors_count; i++) + m_storage_class_colors.append (QColor (Qt::white)); -} + } + + int + workspace_model::rowCount (const QModelIndex&) const + { + return m_symbols.size (); + } -int -workspace_model::rowCount (const QModelIndex&) const -{ - return m_symbols.size (); -} + int + workspace_model::columnCount (const QModelIndex&) const + { + return m_columnNames.size (); + } -int -workspace_model::columnCount (const QModelIndex&) const -{ - return m_columnNames.size (); -} + Qt::ItemFlags + workspace_model::flags (const QModelIndex& idx) const + { + Qt::ItemFlags retval = Qt::NoItemFlags; + + if (idx.isValid ()) + { + retval |= Qt::ItemIsEnabled; -Qt::ItemFlags -workspace_model::flags (const QModelIndex& idx) const -{ - Qt::ItemFlags retval = Qt::NoItemFlags; + if (m_top_level && idx.column () == 0) + retval |= Qt::ItemIsSelectable; + } + + return retval; + } - if (idx.isValid ()) - { - retval |= Qt::ItemIsEnabled; - - if (m_top_level && idx.column () == 0) - retval |= Qt::ItemIsSelectable; - } - - return retval; -} + QVariant + workspace_model::headerData (int section, Qt::Orientation orientation, + int role) const + { + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return tr (m_columnNames[section].toStdString ().data ()); + else + return QVariant (); + } -QVariant -workspace_model::headerData (int section, Qt::Orientation orientation, - int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return tr (m_columnNames[section].toStdString ().data ()); - else - return QVariant (); -} + QVariant + workspace_model::data (const QModelIndex& idx, int role) const + { + QVariant retval; -QVariant -workspace_model::data (const QModelIndex& idx, int role) const -{ - QVariant retval; + if (idx.isValid ()) + { + if ((role == Qt::BackgroundRole || role == Qt::ForegroundRole) + && m_enable_colors) + { + int actual_class + = ws_class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ()); + if (actual_class >= 0) + { + // Valid class: Get background (normal indexes) or foreground + // color (indexes with offset) + if (role == Qt::ForegroundRole) + actual_class += ws_colors_count; - if (idx.isValid ()) - { - if ((role == Qt::BackgroundRole || role == Qt::ForegroundRole) - && m_enable_colors) - { - int actual_class - = ws_class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ()); - if (actual_class >= 0) - { - // Valid class: Get background (normal indexes) or foreground - // color (indexes with offset) - if (role == Qt::ForegroundRole) - actual_class += ws_colors_count; + return QVariant (m_storage_class_colors.at (actual_class)); + } + else + return retval; + } - return QVariant (m_storage_class_colors.at (actual_class)); - } - else - return retval; - } + if (role == Qt::DisplayRole + || (idx.column () == 0 && role == Qt::EditRole) + || (idx.column () == 0 && role == Qt::ToolTipRole)) + { + switch (idx.column ()) + { + case 0: + if (role == Qt::ToolTipRole) + retval + = QVariant (tr ("Right click to copy, rename, or display")); + else + retval = QVariant (m_symbols[idx.row ()]); + break; + + case 1: + retval = QVariant (m_class_names[idx.row ()]); + break; - if (role == Qt::DisplayRole - || (idx.column () == 0 && role == Qt::EditRole) - || (idx.column () == 0 && role == Qt::ToolTipRole)) - { - switch (idx.column ()) - { - case 0: - if (role == Qt::ToolTipRole) - retval - = QVariant (tr ("Right click to copy, rename, or display")); - else - retval = QVariant (m_symbols[idx.row ()]); - break; + case 2: + retval = QVariant (m_dimensions[idx.row ()]); + break; + + case 3: + retval = QVariant (m_values[idx.row ()]); + break; - case 1: - retval = QVariant (m_class_names[idx.row ()]); - break; - - case 2: - retval = QVariant (m_dimensions[idx.row ()]); - break; + case 4: + { + QString sclass; - case 3: - retval = QVariant (m_values[idx.row ()]); - break; + int actual_class + = ws_class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ()); - case 4: - { - QString sclass; + if (actual_class >= 0) + sclass = ws_color_names.at (actual_class); - int actual_class - = ws_class_chars.indexOf (m_scopes[idx.row ()].toLatin1 ()); - - if (actual_class >= 0) - sclass = ws_color_names.at (actual_class); + if (m_complex_flags[idx.row ()]) + { + if (sclass.isEmpty ()) + sclass = tr ("complex"); + else + sclass += ", " + tr ("complex"); + } - if (m_complex_flags[idx.row ()]) - { - if (sclass.isEmpty ()) - sclass = tr ("complex"); - else - sclass += ", " + tr ("complex"); - } + retval = QVariant (sclass); + } + break; + } + } + } - retval = QVariant (sclass); - } - break; - } - } - } + return retval; + } - return retval; -} + void + workspace_model::set_workspace (bool top_level, bool /* debug */, + const symbol_info_list& syminfo) + { + clear_data (); + + m_top_level = top_level; + m_syminfo_list = syminfo; -void -workspace_model::set_workspace (bool top_level, bool /* debug */, - const symbol_info_list& syminfo) -{ - clear_data (); + update_table (); + } - m_top_level = top_level; - m_syminfo_list = syminfo; + void + workspace_model::clear_workspace () + { + clear_data (); + update_table (); + } - update_table (); -} + void + workspace_model::notice_settings () + { + gui_settings settings; -void -workspace_model::clear_workspace (void) -{ - clear_data (); - update_table (); -} + 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); -void -workspace_model::notice_settings (const gui_settings *settings) -{ - m_enable_colors = settings->value (ws_enable_colors).toBool (); - - int mode = settings->value (ws_color_mode).toInt (); + QPalette p (setting_color); + m_storage_class_colors.replace (i, setting_color); - for (int i = 0; i < ws_colors_count; i++) - { - QColor setting_color = settings->color_value (ws_colors[i], mode); + QColor fg_color = p.color (QPalette::WindowText); + m_storage_class_colors.replace (i + ws_colors_count, fg_color); - QPalette p (setting_color); - m_storage_class_colors.replace (i, setting_color); + } + } - QColor fg_color = p.color (QPalette::WindowText); - m_storage_class_colors.replace (i + ws_colors_count, fg_color); + 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 (void) -{ - m_top_level = false; - m_syminfo_list = symbol_info_list (); - m_scopes = QString (); - m_symbols = QStringList (); - m_class_names = QStringList (); - m_dimensions = QStringList (); - m_values = QStringList (); - m_complex_flags = QIntList (); -} + void + workspace_model::clear_data () + { + m_top_level = false; + m_syminfo_list = symbol_info_list (); + m_scopes = QString (); + m_symbols = QStringList (); + m_class_names = QStringList (); + m_dimensions = QStringList (); + m_values = QStringList (); + m_complex_flags = QIntList (); + } -void -workspace_model::update_table (void) -{ - beginResetModel (); - - for (const auto& syminfo : m_syminfo_list) - { - std::string nm = syminfo.name (); - - octave_value val = syminfo.value (); + void + workspace_model::update_table () + { + beginResetModel (); - // FIXME: fix size for objects, see kluge in ov.cc - Matrix sz = val.size (); - dim_vector dv = dim_vector::alloc (sz.numel ()); - for (octave_idx_type i = 0; i < dv.ndims (); i++) - dv(i) = sz(i); + for (const auto& syminfo : m_syminfo_list) + { + std::string nm = syminfo.name (); + + octave_value val = syminfo.value (); - char storage = ' '; - if (syminfo.is_formal ()) - storage = 'a'; - else if (syminfo.is_global ()) - storage = 'g'; - else if (syminfo.is_persistent ()) - storage = 'p'; + // FIXME: fix size for objects, see kluge in ov.cc + Matrix sz = val.size (); + dim_vector dv = dim_vector::alloc (sz.numel ()); + for (octave_idx_type i = 0; i < dv.ndims (); i++) + dv(i) = sz(i); - std::ostringstream buf; - val.short_disp (buf); - std::string short_disp_str = buf.str (); + char storage = ' '; + if (syminfo.is_formal ()) + storage = 'a'; + else if (syminfo.is_global ()) + storage = 'g'; + else if (syminfo.is_persistent ()) + storage = 'p'; + + std::ostringstream buf; + val.short_disp (buf); + std::string short_disp_str = buf.str (); - m_scopes.append (storage); - m_symbols.append (QString::fromStdString (nm)); - m_class_names.append (QString::fromStdString (val.class_name ())); - m_dimensions.append (QString::fromStdString (dv.str ())); - m_values.append (QString::fromStdString (short_disp_str)); - m_complex_flags.append (val.iscomplex ()); - } + m_scopes.append (storage); + m_symbols.append (QString::fromStdString (nm)); + m_class_names.append (QString::fromStdString (val.class_name ())); + m_dimensions.append (QString::fromStdString (dv.str ())); + m_values.append (QString::fromStdString (short_disp_str)); + m_complex_flags.append (val.iscomplex ()); + } - endResetModel (); + endResetModel (); - emit model_changed (); -} + emit model_changed (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/workspace-model.h --- a/libgui/src/workspace-model.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/workspace-model.h Mon Jan 30 18:36:03 2023 +0100 @@ -34,8 +34,6 @@ #include #include -#include "gui-settings.h" - #include "syminfo.h" // Defined for purposes of sending QList as part of signal. @@ -43,73 +41,75 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class workspace_model : public QAbstractTableModel -{ - Q_OBJECT + class workspace_model : public QAbstractTableModel + { + Q_OBJECT -public: + public: - workspace_model (QObject *parent = nullptr); + workspace_model (QObject *parent = nullptr); - ~workspace_model (void) = default; + ~workspace_model () = default; - int rowCount (const QModelIndex& parent = QModelIndex ()) const; + int rowCount (const QModelIndex& parent = QModelIndex ()) const; - int columnCount (const QModelIndex& parent = QModelIndex ()) const; + int columnCount (const QModelIndex& parent = QModelIndex ()) const; - Qt::ItemFlags flags (const QModelIndex& index) const; + Qt::ItemFlags flags (const QModelIndex& index) const; - QVariant headerData (int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; + QVariant headerData (int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; - QVariant data (const QModelIndex& index, int role) const; + 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); - } + 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: -signals: + void model_changed (); + void prompt_variable_editor(); - void model_changed (void); - void prompt_variable_editor(void); + public slots: -public slots: + void set_workspace (bool top_level, bool debug, + const symbol_info_list& syminfo); - void set_workspace (bool top_level, bool debug, - const symbol_info_list& syminfo); + void clear_workspace (); + + void notice_settings (); - void clear_workspace (void); + void show_symbol_tooltip (const QPoint& pos, const QString& symbol); - void notice_settings (const gui_settings *); - -private: + 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; - QString m_scopes; - QStringList m_symbols; - QStringList m_class_names; - QStringList m_dimensions; - QStringList m_values; - QIntList m_complex_flags; + bool m_top_level; + symbol_info_list m_syminfo_list; + QString m_scopes; + QStringList m_symbols; + QStringList m_class_names; + QStringList m_dimensions; + QStringList m_values; + QIntList m_complex_flags; - QStringList m_columnNames; + QStringList m_columnNames; - QList m_storage_class_colors; - bool m_enable_colors; + QList m_storage_class_colors; + bool m_enable_colors; -}; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/workspace-view.cc --- a/libgui/src/workspace-view.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/workspace-view.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,515 +42,506 @@ #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)) -{ - set_title (tr ("Workspace")); - setStatusTip (tr ("View the variables in the active workspace.")); + 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->setInsertPolicy (QComboBox::NoInsert); + m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); + QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); + m_filter->setSizePolicy (sizePol); + m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); + + QLabel *filter_label = new QLabel (tr ("Filter")); + + m_view->setWordWrap (false); + m_view->setContextMenuPolicy (Qt::CustomContextMenu); + m_view->setShowGrid (false); + (m_view->verticalHeader) ()->hide (); + m_view->setAlternatingRowColors (true); + m_view_previous_row_count = 0; - 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->setInsertPolicy (QComboBox::NoInsert); - m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); - QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); - m_filter->setSizePolicy (sizePol); - m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); + // Set an empty widget, so we can assign a layout to it. + setWidget (new QWidget (this)); + + // Create the layouts + QHBoxLayout *filter_layout = new QHBoxLayout (); - QLabel *filter_label = new QLabel (tr ("Filter")); + filter_layout->addWidget (filter_label); + filter_layout->addWidget (m_filter_checkbox); + filter_layout->addWidget (m_filter); + filter_layout->setMargin (0); + + m_filter_widget->setLayout (filter_layout); - m_view->setWordWrap (false); - m_view->setContextMenuPolicy (Qt::CustomContextMenu); - m_view->setShowGrid (false); - (m_view->verticalHeader) ()->hide (); - m_view->setAlternatingRowColors (true); - m_view_previous_row_count = 0; + QVBoxLayout *ws_layout = new QVBoxLayout (); + ws_layout->addWidget (m_filter_widget); + ws_layout->addWidget (m_view); + ws_layout->setSpacing (0); + + gui_settings settings; - // Set an empty widget, so we can assign a layout to it. - setWidget (new QWidget (this)); + m_filter_shown = settings.bool_value (ws_filter_shown); + m_filter_widget->setVisible (m_filter_shown); + + ws_layout->setMargin (2); - // Create the layouts - QHBoxLayout *filter_layout = new QHBoxLayout (); + // Set the empty widget to have our layout. + widget ()->setLayout (ws_layout); + + // Initialize collapse/expand state of the workspace subcategories. - filter_layout->addWidget (filter_label); - filter_layout->addWidget (m_filter_checkbox); - filter_layout->addWidget (m_filter); - filter_layout->setMargin (0); + //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 ()); - m_filter_widget->setLayout (filter_layout); + // 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 - QVBoxLayout *ws_layout = new QVBoxLayout (); - ws_layout->addWidget (m_filter_widget); - ws_layout->addWidget (m_view); - ws_layout->setSpacing (0); + m_view->horizontalHeader ()->setSortIndicatorShown (true); + + m_view->horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu); + connect (m_view->horizontalHeader (), + &QTableView::customContextMenuRequested, + this, &workspace_view::header_contextmenu_requested); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + // Init state of the filter + m_filter->addItems (settings.value (ws_mru_list.settings_key ()).toStringList ()); - if (settings) - { - m_filter_shown = settings->value (ws_filter_shown).toBool (); - m_filter_widget->setVisible (m_filter_shown); + bool filter_state = settings.bool_value (ws_filter_active); + m_filter_checkbox->setChecked (filter_state); + filter_activate (filter_state); + + // Connect signals and slots. - ws_layout->setMargin (2); + connect (m_filter, &QComboBox::editTextChanged, + this, &workspace_view::filter_update); + connect (m_filter_checkbox, &QCheckBox::toggled, + this, &workspace_view::filter_activate); + connect (m_filter->lineEdit (), &QLineEdit::editingFinished, + this, &workspace_view::update_filter_history); - // Set the empty widget to have our layout. - widget ()->setLayout (ws_layout); + connect (m_view, &QTableView::customContextMenuRequested, + this, &workspace_view::contextmenu_requested); - // Initialize collapse/expand state of the workspace subcategories. + connect (m_view, &QTableView::activated, + this, &workspace_view::handle_contextmenu_edit); - //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 ()); + if (! p) + make_window (); + } + + void workspace_view::setModel (workspace_model *model) + { + m_filter_model.setSourceModel (model); + m_filter_model.setFilterKeyColumn(0); - // 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 ())); + m_view->setModel (&m_filter_model); + + // set the sorting after the model is set, it would be ignored otherwise + + 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_view->horizontalHeader ()->setSortIndicatorShown (true); + m_model = model; + } - m_view->horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu); - connect (m_view->horizontalHeader (), - &QTableView::customContextMenuRequested, - this, &workspace_view::header_contextmenu_requested); + void + workspace_view::notice_settings () + { + gui_settings settings; - // Init state of the filter - m_filter->addItems (settings->value (ws_mru_list.key).toStringList ()); + m_model->notice_settings (); // update colors of model first - bool filter_state = - settings->value (ws_filter_active).toBool (); - m_filter_checkbox->setChecked (filter_state); - filter_activate (filter_state); - } + 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 ()); + + QString tool_tip; - // Connect signals and slots. - - connect (m_filter, &QComboBox::editTextChanged, - this, &workspace_view::filter_update); - connect (m_filter_checkbox, &QCheckBox::toggled, - this, &workspace_view::filter_activate); - connect (m_filter->lineEdit (), &QLineEdit::editingFinished, - this, &workspace_view::update_filter_history); + 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:")); - connect (m_view, &QTableView::customContextMenuRequested, - this, &workspace_view::contextmenu_requested); - - connect (m_view, &QTableView::activated, - this, &workspace_view::handle_contextmenu_edit); - - if (! p) - make_window (); -} + for (int i = 0; i < ws_colors_count; i++) + { + tool_tip += + QString (R"(
%3
)") + .arg (m_model->storage_class_color (i).name ()) + .arg (m_model->storage_class_color (i + ws_colors_count).name ()) + .arg (QCoreApplication::translate ("octave::settings_dialog", + ws_color_names.at (i).toStdString ().data ())); + } + } -void workspace_view::setModel (workspace_model *model) -{ - m_filter_model.setSourceModel (model); - m_filter_model.setFilterKeyColumn(0); - - m_view->setModel (&m_filter_model); + setToolTip (tool_tip); + } - // 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 + void + workspace_view::save_settings () + { + gui_settings settings; + + settings.setValue (ws_column_state.settings_key (), + m_view->horizontalHeader ()->saveState ()); - m_model = model; -} + int sort_column = m_view->horizontalHeader ()->sortIndicatorSection (); + Qt::SortOrder sort_order = m_view->horizontalHeader ()->sortIndicatorOrder (); + settings.setValue (ws_sort_column.settings_key (), sort_column); + settings.setValue (ws_sort_order.settings_key (), sort_order); -void -workspace_view::notice_settings (const gui_settings *settings) -{ - m_model->notice_settings (settings); // update colors of model first + settings.setValue (ws_filter_active.settings_key (), m_filter_checkbox->isChecked ()); + settings.setValue (ws_filter_shown.settings_key (), m_filter_shown); - 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 ()); - - QString tool_tip; + QStringList mru; + for (int i = 0; i < m_filter->count (); i++) + mru.append (m_filter->itemText (i)); + settings.setValue (ws_mru_list.settings_key (), mru); - if (settings->value (ws_enable_colors).toBool () - && ! settings->value (ws_hide_tool_tips).toBool ()) - { - tool_tip = QString (tr ("View the variables in the active workspace.
")); - tool_tip += QString (tr ("Colors for variable attributes:")); + settings.sync (); + + octave_dock_widget::save_settings (); + } - for (int i = 0; i < ws_colors_count; i++) - { - tool_tip += - QString (R"(
%3
)") - .arg (m_model->storage_class_color (i).name ()) - .arg (m_model->storage_class_color (i + ws_colors_count).name ()) - .arg (QCoreApplication::translate ("octave::settings_dialog", - ws_color_names.at (i).toStdString ().data ())); - } - } - - setToolTip (tool_tip); -} + void workspace_view::set_filter_focus (bool focus) + { + if (focus) + { + m_filter->setFocus (); + setFocusProxy (m_filter); + } + else + { + m_view->setFocus (); + setFocusProxy (m_view); + } + } -void -workspace_view::save_settings (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (! settings) - return; + void + workspace_view::filter_update (const QString& expression) + { + m_filter_model.setFilterWildcard (expression); + handle_model_changed (); + } - settings->setValue (ws_column_state.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_filter_active.key, m_filter_checkbox->isChecked ()); - settings->setValue (ws_filter_shown.key, m_filter_shown); + void + workspace_view::filter_activate (bool state) + { + m_filter->setEnabled (state); + m_filter_model.setDynamicSortFilter (state); - QStringList mru; - for (int i = 0; i < m_filter->count (); i++) - mru.append (m_filter->itemText (i)); - settings->setValue (ws_mru_list.key, mru); + if (state) + filter_update (m_filter->currentText ()); + else + filter_update (QString ()); - settings->sync (); - - octave_dock_widget::save_settings (); -} + set_filter_focus (state); + } -void workspace_view::set_filter_focus (bool focus) -{ - if (focus) - { - m_filter->setFocus (); - setFocusProxy (m_filter); - } - else - { - m_view->setFocus (); - setFocusProxy (m_view); - } -} + void + workspace_view::update_filter_history () + { + QString text = m_filter->currentText (); // get current text + int index = m_filter->findText (text); // and its actual index + + if (index > -1) + m_filter->removeItem (index); // remove if already existing -void -workspace_view::filter_update (const QString& expression) -{ - m_filter_model.setFilterWildcard (expression); - handle_model_changed (); -} + m_filter->insertItem (0, text); // (re)insert at beginning + m_filter->setCurrentIndex (0); + } -void -workspace_view::filter_activate (bool state) -{ - m_filter->setEnabled (state); - m_filter_model.setDynamicSortFilter (state); + void + workspace_view::header_contextmenu_requested (const QPoint& mpos) + { + QMenu menu (this); + QSignalMapper sig_mapper (this); - if (state) - filter_update (m_filter->currentText ()); - else - filter_update (QString ()); - - set_filter_focus (state); -} + gui_settings settings; -void -workspace_view::update_filter_history (void) -{ - QString text = m_filter->currentText (); // get current text - int index = m_filter->findText (text); // and its actual index - - if (index > -1) - m_filter->removeItem (index); // remove if already existing + for (int i = 0; i < ws_columns_shown.length (); i++) + { + QAction *action + = menu.addAction (tr (ws_columns_shown.at (i).toStdString ().data ()), + &sig_mapper, SLOT (map ())); + sig_mapper.setMapping (action, i); + action->setCheckable (true); + action->setChecked (settings.value (ws_columns_shown_keys.at (i), true).toBool ()); + } - m_filter->insertItem (0, text); // (re)insert at beginning - m_filter->setCurrentIndex (0); -} - -void -workspace_view::header_contextmenu_requested (const QPoint& mpos) -{ - QMenu menu (this); - QSignalMapper sig_mapper (this); + // FIXME: We could use + // + // connect (&m_sig_mapper, QOverload::of (&QSignalMapper::mapped), + // this, &workspace_view::toggle_header); + // + // but referring to QSignalMapper::mapped will generate deprecated + // function warnings from GCC. We could also use + // + // connect (&m_sig_mapper, &QSignalMapper::mappedInt, + // this, &workspace_view::toggle_header); + // + // but the function mappedInt was not introduced until Qt 5.15 so + // we'll need a feature test. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + connect (&sig_mapper, SIGNAL (mapped (int)), + this, SLOT (toggle_header (int))); + + menu.exec (m_view->mapToGlobal (mpos)); + } - for (int i = 0; i < ws_columns_shown.length (); i++) - { - QAction *action - = menu.addAction (tr (ws_columns_shown.at (i).toStdString ().data ()), - &sig_mapper, SLOT (map ())); - sig_mapper.setMapping (action, i); - action->setCheckable (true); - action->setChecked (settings->value (ws_columns_shown_keys.at (i), true).toBool ()); - } + void + workspace_view::toggle_header (int col) + { + gui_settings settings; + + QString key = ws_columns_shown_keys.at (col); + bool shown = settings.value (key, true).toBool (); - // FIXME: We could use - // - // connect (&m_sig_mapper, QOverload::of (&QSignalMapper::mapped), - // this, &workspace_view::toggle_header); - // - // but referring to QSignalMapper::mapped will generate deprecated - // function warnings from GCC. We could also use - // - // connect (&m_sig_mapper, &QSignalMapper::mappedInt, - // this, &workspace_view::toggle_header); - // - // but the function mappedInt was not introduced until Qt 5.15 so - // we'll need a feature test. + m_view->setColumnHidden (col + 1, shown); + + settings.setValue (key, ! shown); + settings.sync (); + + octave_dock_widget::save_settings (); + } + + void + workspace_view::contextmenu_requested (const QPoint& qpos) + { + QMenu menu (this); - connect (&sig_mapper, SIGNAL (mapped (int)), - this, SLOT (toggle_header (int))); + QModelIndex index = m_view->indexAt (qpos); - menu.exec (m_view->mapToGlobal (mpos)); -} + // if it isn't Local, Global etc, allow the ctx menu + if (index.isValid () && index.column () == 0) + { + QString var_name = get_var_name (index); -void -workspace_view::toggle_header (int col) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + menu.addAction (tr ("Open in Variable Editor"), this, + &workspace_view::handle_contextmenu_edit); - QString key = ws_columns_shown_keys.at (col); - bool shown = settings->value (key, true).toBool (); + menu.addAction (tr ("Copy name"), this, + &workspace_view::handle_contextmenu_copy); - m_view->setColumnHidden (col + 1, shown); + menu.addAction (tr ("Copy value"), this, + &workspace_view::handle_contextmenu_copy_value); - settings->setValue (key, ! shown); - settings->sync (); - - octave_dock_widget::save_settings (); -} - -void -workspace_view::contextmenu_requested (const QPoint& qpos) -{ - QMenu menu (this); + QAction *rename + = menu.addAction (tr ("Rename"), this, + &workspace_view::handle_contextmenu_rename); - QModelIndex index = m_view->indexAt (qpos); + // Use m_model here instead of using "m_view->model ()" because + // that points to the proxy model. + if (! m_model->is_top_level ()) + { + rename->setDisabled (true); + rename->setToolTip (tr ("Only top-level symbols may be renamed")); + } - // if it isn't Local, Global etc, allow the ctx menu - if (index.isValid () && index.column () == 0) - { - QString var_name = get_var_name (index); + menu.addAction ("Clear " + var_name, this, + &workspace_view::handle_contextmenu_clear); - menu.addAction (tr ("Open in Variable Editor"), this, - &workspace_view::handle_contextmenu_edit); + menu.addSeparator (); - menu.addAction (tr ("Copy name"), this, - &workspace_view::handle_contextmenu_copy); + menu.addAction ("disp (" + var_name + ')', this, + &workspace_view::handle_contextmenu_disp); - menu.addAction (tr ("Copy value"), this, - &workspace_view::handle_contextmenu_copy_value); + menu.addAction ("plot (" + var_name + ')', this, + &workspace_view::handle_contextmenu_plot); - QAction *rename - = menu.addAction (tr ("Rename"), this, - &workspace_view::handle_contextmenu_rename); + menu.addAction ("stem (" + var_name + ')', this, + &workspace_view::handle_contextmenu_stem); + + menu.addSeparator (); + + } - // Use m_model here instead of using "m_view->model ()" because - // that points to the proxy model. - if (! m_model->is_top_level ()) - { - rename->setDisabled (true); - rename->setToolTip (tr ("Only top-level symbols may be renamed")); - } - - menu.addAction ("Clear " + var_name, this, - &workspace_view::handle_contextmenu_clear); + if (m_filter_shown) + menu.addAction (tr ("Hide filter"), this, + &workspace_view::handle_contextmenu_filter); + else + menu.addAction (tr ("Show filter"), this, + &workspace_view::handle_contextmenu_filter); - menu.addSeparator (); - - menu.addAction ("disp (" + var_name + ')', this, - &workspace_view::handle_contextmenu_disp); + menu.exec (m_view->mapToGlobal (qpos)); + } - menu.addAction ("plot (" + var_name + ')', this, - &workspace_view::handle_contextmenu_plot); - - menu.addAction ("stem (" + var_name + ')', this, - &workspace_view::handle_contextmenu_stem); + void + workspace_view::handle_contextmenu_copy () + { + QModelIndex index = m_view->currentIndex (); - menu.addSeparator (); - - } + if (index.isValid ()) + { + QString var_name = get_var_name (index); - if (m_filter_shown) - menu.addAction (tr ("Hide filter"), this, - &workspace_view::handle_contextmenu_filter); - else - menu.addAction (tr ("Show filter"), this, - &workspace_view::handle_contextmenu_filter); + QClipboard *clipboard = QApplication::clipboard (); + + clipboard->setText (var_name); + } + } - menu.exec (m_view->mapToGlobal (qpos)); -} + void + workspace_view::handle_contextmenu_copy_value () + { + QModelIndex index = m_view->currentIndex (); -void -workspace_view::handle_contextmenu_copy (void) -{ - QModelIndex index = m_view->currentIndex (); + if (index.isValid ()) + emit copy_variable_value_to_clipboard (get_var_name (index)); + } - if (index.isValid ()) - { - QString var_name = get_var_name (index); - - QClipboard *clipboard = QApplication::clipboard (); + void + workspace_view::handle_contextmenu_rename () + { + QModelIndex index = m_view->currentIndex (); - clipboard->setText (var_name); - } -} + if (index.isValid ()) + { + QString var_name = get_var_name (index); -void -workspace_view::handle_contextmenu_copy_value (void) -{ - QModelIndex index = m_view->currentIndex (); + QInputDialog *inputDialog = new QInputDialog (); - if (index.isValid ()) - emit copy_variable_value_to_clipboard (get_var_name (index)); -} + inputDialog->setOptions (QInputDialog::NoButtons); + + bool ok = false; -void -workspace_view::handle_contextmenu_rename (void) -{ - QModelIndex index = m_view->currentIndex (); + QString new_name + = inputDialog->getText (nullptr, "Rename Variable", "New name:", + QLineEdit::Normal, var_name, &ok); - if (index.isValid ()) - { - QString var_name = get_var_name (index); + if (ok && ! new_name.isEmpty ()) + emit rename_variable_signal (var_name, new_name); + } + } - QInputDialog *inputDialog = new QInputDialog (); - - inputDialog->setOptions (QInputDialog::NoButtons); - - bool ok = false; + void + workspace_view::handle_contextmenu_edit () + { + QModelIndex index = m_view->currentIndex (); - QString new_name - = inputDialog->getText (nullptr, "Rename Variable", "New name:", - QLineEdit::Normal, var_name, &ok); - - if (ok && ! new_name.isEmpty ()) - emit rename_variable_signal (var_name, new_name); - } -} + if (index.isValid ()) + emit edit_variable_signal (get_var_name (index)); + } -void -workspace_view::handle_contextmenu_edit (void) -{ - QModelIndex index = m_view->currentIndex (); + void + workspace_view::handle_contextmenu_clear () + { + relay_contextmenu_command ("clear", true); + } - if (index.isValid ()) - emit edit_variable_signal (get_var_name (index)); -} - -void -workspace_view::handle_contextmenu_clear (void) -{ - relay_contextmenu_command ("clear", true); -} + void + workspace_view::handle_contextmenu_disp () + { + relay_contextmenu_command ("disp"); + } -void -workspace_view::handle_contextmenu_disp (void) -{ - relay_contextmenu_command ("disp"); -} - -void -workspace_view::handle_contextmenu_plot (void) -{ - relay_contextmenu_command ("figure (); plot"); -} + void + workspace_view::handle_contextmenu_plot () + { + relay_contextmenu_command ("figure (); plot"); + } -void -workspace_view::handle_contextmenu_stem (void) -{ - relay_contextmenu_command ("figure (); stem"); -} + void + workspace_view::handle_contextmenu_stem () + { + relay_contextmenu_command ("figure (); stem"); + } -void -workspace_view::handle_contextmenu_filter (void) -{ - m_filter_shown = ! m_filter_shown; - m_filter_widget->setVisible (m_filter_shown); + void + workspace_view::handle_contextmenu_filter () + { + m_filter_shown = ! m_filter_shown; + m_filter_widget->setVisible (m_filter_shown); - set_filter_focus (m_filter_shown && m_filter_checkbox->isChecked ()); -} + set_filter_focus (m_filter_shown && m_filter_checkbox->isChecked ()); + } -void -workspace_view::handle_model_changed (void) -{ - // m_view->resizeRowsToContents (); - // Just modify those rows that have been added rather than go through - // the whole list. For-loop test will handle when number of rows reduced. - QFontMetrics fm = m_view->fontMetrics (); - int row_height = fm.height (); - int new_row_count = m_filter_model.rowCount (); - for (int i = m_view_previous_row_count; i < new_row_count; i++) - m_view->setRowHeight (i, row_height); - m_view_previous_row_count = new_row_count; -} + void + workspace_view::handle_model_changed () + { + // m_view->resizeRowsToContents (); + // Just modify those rows that have been added rather than go through + // the whole list. For-loop test will handle when number of rows reduced. + QFontMetrics fm = m_view->fontMetrics (); + int row_height = fm.height (); + int new_row_count = m_filter_model.rowCount (); + for (int i = m_view_previous_row_count; i < new_row_count; i++) + m_view->setRowHeight (i, row_height); + m_view_previous_row_count = new_row_count; + } -void -workspace_view::copyClipboard () -{ - if (m_view->hasFocus ()) - handle_contextmenu_copy (); -} + void + workspace_view::copyClipboard () + { + if (m_view->hasFocus ()) + handle_contextmenu_copy (); + } -void -workspace_view::selectAll () -{ - if (m_view->hasFocus ()) - m_view->selectAll (); -} + void + workspace_view::selectAll () + { + if (m_view->hasFocus ()) + m_view->selectAll (); + } -void -workspace_view::relay_contextmenu_command (const QString& cmdname, bool str) -{ - QModelIndex index = m_view->currentIndex (); + void + workspace_view::relay_contextmenu_command (const QString& cmdname, bool str) + { + QModelIndex index = m_view->currentIndex (); - if (index.isValid ()) - { - QString var_name; + if (index.isValid ()) + { + QString var_name; - if (str) - var_name = "\'" + get_var_name (index) + "\'"; - else - var_name = get_var_name (index); + if (str) + var_name = "\'" + get_var_name (index) + "\'"; + else + var_name = get_var_name (index); - emit command_requested (cmdname + " (" + var_name + ");"); - } -} + emit command_requested (cmdname + " (" + var_name + ");"); + } + } -QString -workspace_view::get_var_name (const QModelIndex& index) -{ - // We are using a sort model proxy so m_model won't provide the - // correct ordering. + QString + workspace_view::get_var_name (const QModelIndex& index) + { + // We are using a sort model proxy so m_model won't provide the + // correct ordering. - QAbstractItemModel *m = m_view->model (); + QAbstractItemModel *m = m_view->model (); - QMap item_data - = m->itemData (index.sibling (index.row (), 0)); + QMap item_data + = m->itemData (index.sibling (index.row (), 0)); - return item_data[0].toString (); -} + return item_data[0].toString (); + } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libgui/src/workspace-view.h --- a/libgui/src/workspace-view.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libgui/src/workspace-view.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,95 +39,93 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; + class workspace_view : public octave_dock_widget + { + Q_OBJECT -class workspace_view : public octave_dock_widget -{ - Q_OBJECT + public: -public: + workspace_view (QWidget *parent); - workspace_view (QWidget *parent, base_qobject& oct_qobj); + ~workspace_view () = default; - ~workspace_view (void) = default; + signals: -signals: + //! Signal that user had requested a command on a variable. - //! Signal that user had requested a command on a variable. + void command_requested (const QString& cmd); - void command_requested (const QString& cmd); + //! Signal that user wnats to copy a variable value to the + //! clipboard. - //! Signal that user wnats to copy a variable value to the - //! clipboard. + void copy_variable_value_to_clipboard (const QString&); - void copy_variable_value_to_clipboard (const QString&); + //! Signal that user wants to rename a variable. - //! Signal that user wants to rename a variable. - - void rename_variable_signal (const QString&, const QString&); + void rename_variable_signal (const QString&, const QString&); - //! Signal that user wants to edit a variable. + //! Signal that user wants to edit a variable. - void edit_variable_signal (const QString&); + void edit_variable_signal (const QString&); -public slots: + public slots: - void setModel (workspace_model *model); + void setModel (workspace_model *model); - void notice_settings (const gui_settings *); + void notice_settings (); - void save_settings (void); + void save_settings (); -protected slots: + protected slots: - void filter_update (const QString& expression); - void filter_activate (bool enable); - void update_filter_history (void); + void filter_update (const QString& expression); + void filter_activate (bool enable); + void update_filter_history (); - void header_contextmenu_requested (const QPoint& mpos); + void header_contextmenu_requested (const QPoint& mpos); - void toggle_header (int column); + void toggle_header (int column); - void contextmenu_requested (const QPoint& pos); + 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: + public slots: - void handle_model_changed (void); + void handle_model_changed (); - void copyClipboard (void); - void selectAll (void); + void copyClipboard (); + void selectAll (); -private: + private: - void relay_contextmenu_command (const QString& cmdname, bool str = false); - void set_filter_focus (bool focus); + void relay_contextmenu_command (const QString& cmdname, bool str = false); + void set_filter_focus (bool focus); - QString get_var_name (const QModelIndex& index); + QString get_var_name (const QModelIndex& index); - QTableView *m_view; - int m_view_previous_row_count; + QTableView *m_view; + int m_view_previous_row_count; - // We are using a sort model proxy so m_model won't provide the - // correct ordering. It is still OK to use this pointer to access - // other info attached to the model, for example the scope or colors. - workspace_model *m_model; + // We are using a sort model proxy so m_model won't provide the + // correct ordering. It is still OK to use this pointer to access + // other info attached to the model, for example the scope or colors. + workspace_model *m_model; - QSortFilterProxyModel m_filter_model; - QCheckBox *m_filter_checkbox; - QComboBox *m_filter; - QWidget *m_filter_widget; - bool m_filter_shown; -}; + QSortFilterProxyModel m_filter_model; + QCheckBox *m_filter_checkbox; + QComboBox *m_filter; + QWidget *m_filter_widget; + bool m_filter_shown; + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/build-env.h --- a/libinterp/build-env.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/build-env.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/build-env.in.cc --- a/libinterp/build-env.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/build-env.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/Cell.cc --- a/libinterp/corefcn/Cell.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/Cell.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/Cell.h --- a/libinterp/corefcn/Cell.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/Cell.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/__contourc__.cc --- a/libinterp/corefcn/__contourc__.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/__contourc__.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/__eigs__.cc --- a/libinterp/corefcn/__eigs__.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/__eigs__.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/__magick_read__.cc --- a/libinterp/corefcn/__magick_read__.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/__magick_read__.cc Mon Jan 30 18:36:03 2023 +0100 @@ -216,28 +216,28 @@ image_region& operator = (const image_region&) = default; image_region& operator = (image_region&&) = default; - ~image_region (void) = default; + ~image_region () = 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 +343,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 +355,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 +794,7 @@ } static void -maybe_initialize_magick (void) +maybe_initialize_magick () { static bool initialized = false; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/amd.cc --- a/libinterp/corefcn/amd.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/amd.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/auto-shlib.cc --- a/libinterp/corefcn/auto-shlib.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/auto-shlib.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,7 +34,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -auto_shlib::auto_shlib (void) +auto_shlib::auto_shlib () : dynamic_library (get_current_shlib ()) { } diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/auto-shlib.h --- a/libinterp/corefcn/auto-shlib.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/auto-shlib.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/base-text-renderer.h --- a/libinterp/corefcn/base-text-renderer.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/base-text-renderer.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ ROTATION_270 = 3 }; - base_text_renderer (void) : text_processor () { } + base_text_renderer () : text_processor () { } // No copying! @@ -61,7 +61,7 @@ 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 +78,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/bsxfun.cc --- a/libinterp/corefcn/bsxfun.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/bsxfun.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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) @@ -414,14 +413,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 +462,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/c-file-ptr-stream.cc --- a/libinterp/corefcn/c-file-ptr-stream.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/c-file-ptr-stream.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 (); } @@ -285,7 +285,7 @@ } int -c_zfile_ptr_buf::sync (void) +c_zfile_ptr_buf::sync () { flush (); @@ -293,7 +293,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 +303,7 @@ } int -c_zfile_ptr_buf::buf_close (void) +c_zfile_ptr_buf::buf_close () { int retval = -1; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/c-file-ptr-stream.h --- a/libinterp/corefcn/c-file-ptr-stream.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/c-file-ptr-stream.h Mon Jan 30 18:36:03 2023 +0100 @@ -46,7 +46,7 @@ typedef int (*close_fcn) (FILE *); - FILE * stdiofile (void) { return m_f; } + FILE * stdiofile () { return m_f; } c_file_ptr_buf (FILE *f, close_fcn cf = file_close) : std::streambuf (), m_f (f), m_cf (cf) @@ -58,13 +58,13 @@ 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 +78,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); @@ -124,18 +124,18 @@ c_file_ptr_stream& operator = (const c_file_ptr_stream&) = delete; - ~c_file_ptr_stream (void) { delete m_buf; m_buf = nullptr; } + ~c_file_ptr_stream () { delete m_buf; m_buf = nullptr; } - BUF_T * rdbuf (void) { return m_buf; } + BUF_T * rdbuf () { 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,7 +161,7 @@ typedef int (*close_fcn) (gzFile); - gzFile stdiofile (void) { return m_f; } + gzFile stdiofile () { return m_f; } c_zfile_ptr_buf (gzFile f, close_fcn cf = file_close) : std::streambuf (), m_f (f), m_cf (cf) @@ -173,13 +173,13 @@ 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 +193,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 +232,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/call-stack.cc --- a/libinterp/corefcn/call-stack.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/call-stack.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 (octave_value (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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/call-stack.h --- a/libinterp/corefcn/call-stack.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/call-stack.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/cellfun.cc --- a/libinterp/corefcn/cellfun.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/cellfun.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 (); @@ -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) @@ -2166,7 +2161,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 @@ -2258,15 +2253,23 @@ octave_value retval; + octave_value a = args(0); + octave_idx_type num_dims = std::max (nargin-1, a.ndims ()); + // Prepare indices. - OCTAVE_LOCAL_BUFFER (Array, d, nargin-1); + OCTAVE_LOCAL_BUFFER (Array, d, num_dims); for (int i = 1; i < nargin; i++) d[i-1] = args(i).octave_idx_type_vector_value (true); - octave_value a = args(0); + // Omitted input for trailing dimensions means that the input array + // should not be split along those dimensions. + Array a_dims = a.dims ().as_array (); + for (int i = nargin-1; i < a.ndims (); i++) + d[i] = a_dims.index (i); + bool sparse = a.issparse (); - if (sparse && nargin > 3) + if (sparse && num_dims > 2) error ("mat2cell: sparse arguments only support 2-D indexing"); switch (a.builtin_type ()) @@ -2274,9 +2277,9 @@ case btyp_double: { if (sparse) - retval = do_mat2cell_2d (a.sparse_matrix_value (), d, nargin-1); + retval = do_mat2cell_2d (a.sparse_matrix_value (), d, num_dims); else - retval = do_mat2cell (a.array_value (), d, nargin - 1); + retval = do_mat2cell (a.array_value (), d, num_dims); } break; @@ -2284,16 +2287,16 @@ { if (sparse) retval = do_mat2cell_2d (a.sparse_complex_matrix_value (), d, - nargin-1); + num_dims); else - retval = do_mat2cell (a.complex_array_value (), d, nargin - 1); + retval = do_mat2cell (a.complex_array_value (), d, num_dims); } break; -#define BTYP_BRANCH(X, Y) \ - case btyp_ ## X: \ - retval = do_mat2cell (a.Y ## _value (), d, nargin - 1); \ - break +#define BTYP_BRANCH(X, Y) \ + case btyp_ ## X: \ + retval = do_mat2cell (a.Y ## _value (), d, num_dims); \ + break BTYP_BRANCH (float, float_array); BTYP_BRANCH (float_complex, float_complex_array); @@ -2319,7 +2322,7 @@ break; default: - retval = do_mat2cell (a, d, nargin-1); + retval = do_mat2cell (a, d, num_dims); break; } @@ -2337,6 +2340,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 no splitting for them +%!test +%! 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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/daspk.cc --- a/libinterp/corefcn/daspk.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/daspk.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/dasrt.cc --- a/libinterp/corefcn/dasrt.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/dasrt.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/dassl.cc --- a/libinterp/corefcn/dassl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/dassl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/data.cc --- a/libinterp/corefcn/data.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/data.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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) { @@ -6523,7 +6527,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/data.h --- a/libinterp/corefcn/data.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/data.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/debug.cc --- a/libinterp/corefcn/debug.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/debug.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/defaults.cc --- a/libinterp/corefcn/defaults.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/defaults.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/defaults.h --- a/libinterp/corefcn/defaults.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/defaults.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/defun.cc --- a/libinterp/corefcn/defun.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/defun.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/display.cc --- a/libinterp/corefcn/display.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/display.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -void display_info::initialize (void) +void display_info::initialize () { int avail = 0; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/display.h --- a/libinterp/corefcn/display.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/display.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/dot.cc --- a/libinterp/corefcn/dot.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/dot.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/dynamic-ld.cc --- a/libinterp/corefcn/dynamic-ld.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/dynamic-ld.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/dynamic-ld.h --- a/libinterp/corefcn/dynamic-ld.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/dynamic-ld.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ typedef std::list::iterator iterator; typedef std::list::const_iterator const_iterator; - shlibs_list (void) : m_lib_list () { } + shlibs_list () : m_lib_list () { } // No copying! @@ -60,7 +60,7 @@ shlibs_list& operator = (const shlibs_list&) = delete; - ~shlibs_list (void) = default; + ~shlibs_list () = default; void append (const dynamic_library& shl); @@ -68,7 +68,7 @@ dynamic_library find_file (const std::string& file_name) const; - void display (void) const; + void display () const; private: @@ -89,7 +89,7 @@ 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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/environment.cc --- a/libinterp/corefcn/environment.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/environment.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/environment.h --- a/libinterp/corefcn/environment.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/environment.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ { public: - environment (void) + environment () : m_editor (init_editor ()), m_exec_path (init_exec_path ()), m_image_path (init_image_path ()) @@ -47,7 +47,7 @@ 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 +56,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 +77,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/error.cc --- a/libinterp/corefcn/error.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/error.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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? diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/error.h --- a/libinterp/corefcn/error.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/error.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,14 +52,14 @@ 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 +73,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 +87,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 +104,7 @@ m_discard_warning_messages = flag; } - bool discard_warning_messages (void) const + bool discard_warning_messages () const { return m_discard_warning_messages; } @@ -121,7 +121,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 +135,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 +149,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 +163,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 +172,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 +190,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 +205,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 +221,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 +235,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 +249,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 +305,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 +314,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 +334,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 +566,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/errwarn.cc --- a/libinterp/corefcn/errwarn.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/errwarn.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/errwarn.h --- a/libinterp/corefcn/errwarn.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/errwarn.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/event-manager.cc --- a/libinterp/corefcn/event-manager.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/event-manager.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/event-manager.h --- a/libinterp/corefcn/event-manager.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/event-manager.h Mon Jan 30 18:36:03 2023 +0100 @@ -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. @@ -303,7 +303,7 @@ 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 +312,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 +337,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 +376,7 @@ m_instance->start_gui (gui_app); } - void close_gui (void) + void close_gui () { if (enabled ()) m_instance->close_gui (); @@ -384,7 +384,7 @@ // Dialogs - bool have_dialogs (void) const + bool have_dialogs () const { return m_qt_event_handlers && m_qt_event_handlers->have_dialogs (); } @@ -442,13 +442,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 +459,7 @@ return false; } - bool apply_preferences (void) + bool apply_preferences () { if (enabled ()) { @@ -470,7 +470,7 @@ return false; } - void show_terminal_window (void) + void show_terminal_window () { if (enabled ()) m_instance->show_terminal_window (); @@ -481,19 +481,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 +505,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 +527,7 @@ return false; } - bool confirm_shutdown (void) + bool confirm_shutdown () { bool retval = true; @@ -637,7 +637,7 @@ return false; } - bool update_gui_lexer (void) + bool update_gui_lexer () { if (enabled ()) { @@ -667,7 +667,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 +677,7 @@ update_variable_editor); } - void clear_workspace (void) + void clear_workspace () { if (enabled ()) m_instance->clear_workspace (); @@ -689,7 +689,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 +703,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 +738,7 @@ m_instance->execute_in_debugger_event (file, line); } - void exit_debugger_event (void) + void exit_debugger_event () { if (enabled () && m_debugging) { @@ -755,7 +755,7 @@ m_instance->update_breakpoint (insert, file, line, cond); } - void interpreter_interrupted (void) + void interpreter_interrupted () { if (enabled ()) m_instance->interpreter_interrupted (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/event-queue.cc --- a/libinterp/corefcn/event-queue.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/event-queue.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/event-queue.h --- a/libinterp/corefcn/event-queue.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/event-queue.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ { public: - event_queue (void) : m_fifo () { } + event_queue () : m_fifo () { } // No copying! @@ -51,9 +51,9 @@ // 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 +64,7 @@ } } - void discard_first (void) + void discard_first () { if (! empty ()) { @@ -74,7 +74,7 @@ } } - std::size_t size (void) const { return m_fifo.size (); } + std::size_t size () const { return m_fifo.size (); } protected: @@ -97,7 +97,7 @@ { public: - event_queue_safe (void) : event_queue () { } + event_queue_safe () : event_queue () { } // No copying! @@ -105,7 +105,7 @@ event_queue_safe& operator = (const event_queue_safe&) = delete; - ~event_queue_safe (void) + ~event_queue_safe () { while (! empty ()) { @@ -122,7 +122,7 @@ private: - void warn_unhandled_exception (void) const; + void warn_unhandled_exception () const; }; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/fcn-info.cc --- a/libinterp/corefcn/fcn-info.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/fcn-info.cc Mon Jan 30 18:36:03 2023 +0100 @@ -91,7 +91,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 +241,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++) @@ -999,7 +999,7 @@ } octave_value -fcn_info::fcn_info_rep::find_autoload (void) +fcn_info::fcn_info_rep::find_autoload () { // Autoloaded function. @@ -1030,7 +1030,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 +1060,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 +1098,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 +1183,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/fcn-info.h --- a/libinterp/corefcn/fcn-info.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/fcn-info.h Mon Jan 30 18:36:03 2023 +0100 @@ -74,13 +74,13 @@ 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 +97,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 +171,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 +194,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 +247,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 +276,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 +347,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/ft-text-renderer.cc --- a/libinterp/corefcn/ft-text-renderer.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/ft-text-renderer.cc Mon Jan 30 18:36:03 2023 +0100 @@ -102,7 +102,7 @@ { private: - ft_manager (void) + ft_manager () : m_library (), m_freetype_initialized (false), m_fontconfig_initialized (false) { @@ -129,7 +129,7 @@ private: - ~ft_manager (void) + ~ft_manager () { if (m_freetype_initialized) FT_Done_FreeType (m_library); @@ -146,7 +146,7 @@ public: - static bool instance_ok (void) + static bool instance_ok () { bool retval = true; @@ -159,7 +159,7 @@ return retval; } - static void cleanup_instance (void) + static void cleanup_instance () { delete m_instance; m_instance = nullptr; } static FT_Face get_font (const std::string& name, const std::string& weight, @@ -171,7 +171,7 @@ : nullptr); } - static octave_map get_system_fonts (void) + static octave_map get_system_fonts () { return (instance_ok () ? m_instance->do_get_system_fonts () @@ -189,7 +189,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; @@ -468,7 +468,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 (), @@ -482,7 +482,7 @@ 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 +504,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 +522,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 +543,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 +553,7 @@ ft_font (const ft_font& ft); - ~ft_font (void) + ~ft_font () { if (m_face) FT_Done_Face (m_face); @@ -561,20 +561,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 +660,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 +727,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 +761,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 +1368,7 @@ } void -ft_text_renderer::reset (void) +ft_text_renderer::reset () { set_mode (MODE_BBOX); set_color (Matrix (1, 3, 0.0)); @@ -1509,7 +1509,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 +1534,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/ft-text-renderer.h --- a/libinterp/corefcn/ft-text-renderer.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/ft-text-renderer.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/genprops.awk --- a/libinterp/corefcn/genprops.awk Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/genprops.awk Mon Jan 30 18:36:03 2023 +0100 @@ -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,15 @@ { printf ("public:\n"); printf (" properties (const graphics_handle& mh, const graphics_handle& p);\n\n"); - printf (" ~properties (void) { }\n\n"); + printf (" ~properties () { }\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 +300,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 +357,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 +418,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 +593,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 +638,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 +658,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 +681,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/gh-manager.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/gh-manager.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/gh-manager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/gh-manager.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/gl-render.cc --- a/libinterp/corefcn/gl-render.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/gl-render.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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,7 @@ m_tx (double(m_w)/m_tw), m_ty (double(m_h)/m_th), m_valid (true) { } - ~texture_rep (void) + ~texture_rep () { if (m_valid) m_glfcns.glDeleteTextures (1, &m_id); @@ -152,7 +153,7 @@ opengl_texture (const opengl_texture&) = default; - ~opengl_texture (void) = default; + ~opengl_texture () = default; opengl_texture& operator = (const opengl_texture&) = default; @@ -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,12 +346,12 @@ #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 (); } + opengl_tessellator () : m_glu_tess (nullptr), m_fill () { init (); } // No copying! @@ -358,7 +359,7 @@ opengl_tessellator operator = (const opengl_tessellator&) = delete; - virtual ~opengl_tessellator (void) + virtual ~opengl_tessellator () { if (m_glu_tess) gluDeleteTess (m_glu_tess); } void begin_polygon (bool filled = true) @@ -369,13 +370,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 +385,7 @@ protected: virtual void begin (GLenum /*type*/) { } - virtual void end (void) { } + virtual void end () { } virtual void vertex (void * /*data*/) { } @@ -396,7 +397,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 +415,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 +451,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 () @@ -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 ()); @@ -537,7 +538,7 @@ glfcns.glBegin (type); } - void end (void) + void end () { opengl_functions& glfcns = m_renderer->get_opengl_functions (); @@ -1252,7 +1253,7 @@ } void -opengl_renderer::finish (void) +opengl_renderer::finish () { #if defined (HAVE_OPENGL) @@ -3880,7 +3881,7 @@ } void -opengl_renderer::set_ortho_coordinates (void) +opengl_renderer::set_ortho_coordinates () { #if defined (HAVE_OPENGL) @@ -3905,7 +3906,7 @@ } void -opengl_renderer::restore_previous_coordinates (void) +opengl_renderer::restore_previous_coordinates () { #if defined (HAVE_OPENGL) @@ -4191,7 +4192,7 @@ } Matrix -opengl_renderer::get_viewport_scaled (void) const +opengl_renderer::get_viewport_scaled () const { Matrix retval (1, 4, 0.0); @@ -4497,7 +4498,7 @@ } void -opengl_renderer::end_marker (void) +opengl_renderer::end_marker () { #if defined (HAVE_OPENGL) @@ -4573,7 +4574,7 @@ } void -opengl_renderer::init_maxlights (void) +opengl_renderer::init_maxlights () { #if defined (HAVE_OPENGL) diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/gl-render.h --- a/libinterp/corefcn/gl-render.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/gl-render.h Mon Jan 30 18:36:03 2023 +0100 @@ -49,9 +49,9 @@ opengl_renderer& operator = (const opengl_renderer&) = delete; - virtual ~opengl_renderer (void) = default; + virtual ~opengl_renderer () = 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 +62,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 +73,7 @@ const Matrix& bordercolor, double borderalpha, double borderwidth); - virtual void finish (void); + virtual void finish (); protected: @@ -118,7 +118,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 +180,7 @@ class patch_tessellator; - void init_maxlights (void); + void init_maxlights (); std::string get_string (unsigned int id) const; @@ -208,9 +208,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/gl2ps-print.cc --- a/libinterp/corefcn/gl2ps-print.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/gl2ps-print.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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,7 @@ m_fontname (), m_buffer_overflow (false), m_svg_def_index (0) { } - ~gl2ps_renderer (void) = default; + ~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 diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/graphics-toolkit.cc --- a/libinterp/corefcn/graphics-toolkit.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/graphics-toolkit.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/graphics-toolkit.h --- a/libinterp/corefcn/graphics-toolkit.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/graphics-toolkit.h Mon Jan 30 18:36:03 2023 +0100 @@ -55,14 +55,14 @@ : m_name (nm) { } - virtual ~base_graphics_toolkit (void) = default; + virtual ~base_graphics_toolkit () = default; - std::string get_name (void) const + std::string get_name () const { return m_name; } - virtual bool is_valid (void) const + virtual bool is_valid () const { return false; } @@ -96,13 +96,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 +146,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 +183,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 +222,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 +273,7 @@ } // Close the graphics toolkit. - void close (void) + void close () { m_rep->close (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/graphics-utils.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/graphics-utils.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/graphics-utils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/graphics-utils.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/graphics.cc --- a/libinterp/corefcn/graphics.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/graphics.cc Mon Jan 30 18:36:03 2023 +0100 @@ -51,6 +51,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 +62,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 +70,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 +136,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 +220,7 @@ } static double -default_screendepth (void) +default_screendepth () { octave::display_info& dpy_info = octave::__get_display_info__ (); @@ -230,7 +228,7 @@ } static Matrix -default_screensize (void) +default_screensize () { Matrix retval (1, 4); @@ -245,7 +243,7 @@ } static double -default_screenpixelsperinch (void) +default_screenpixelsperinch () { octave::display_info& dpy_info = octave::__get_display_info__ (); @@ -253,7 +251,7 @@ } static Matrix -default_colororder (void) +default_colororder () { Matrix retval (7, 3, 0.0); @@ -307,7 +305,7 @@ } static Matrix -default_data (void) +default_data () { Matrix retval (1, 2); @@ -318,7 +316,7 @@ } static Matrix -default_data_lim (void) +default_data_lim () { Matrix retval (1, 4); @@ -331,7 +329,7 @@ } static Matrix -default_image_cdata (void) +default_image_cdata () { Matrix m (64, 64); @@ -347,7 +345,7 @@ } static Matrix -default_surface_xdata (void) +default_surface_xdata () { Matrix m (3, 3); @@ -359,7 +357,7 @@ } static Matrix -default_surface_ydata (void) +default_surface_ydata () { Matrix m (3, 3); @@ -371,7 +369,7 @@ } static Matrix -default_surface_zdata (void) +default_surface_zdata () { Matrix m (3, 3, 0.0); @@ -382,13 +380,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 +398,7 @@ } static Matrix -default_patch_vertices (void) +default_patch_vertices () { Matrix m (3, 2, 0.0); @@ -412,7 +410,7 @@ } static Matrix -default_patch_xdata (void) +default_patch_xdata () { Matrix m (3, 1, 0.0); @@ -422,7 +420,7 @@ } static Matrix -default_patch_ydata (void) +default_patch_ydata () { Matrix m (3, 1, 1.0); @@ -432,7 +430,7 @@ } static Matrix -default_axes_position (void) +default_axes_position () { Matrix m (1, 4); @@ -445,7 +443,7 @@ } static Matrix -default_axes_outerposition (void) +default_axes_outerposition () { Matrix m (1, 4); @@ -458,7 +456,7 @@ } static Matrix -default_axes_view (void) +default_axes_view () { Matrix m (1, 2); @@ -469,7 +467,7 @@ } static Matrix -default_axes_tick (void) +default_axes_tick () { Matrix m (1, 6); @@ -484,7 +482,7 @@ } static Matrix -default_axes_ticklength (void) +default_axes_ticklength () { Matrix m (1, 2); @@ -495,7 +493,7 @@ } static Matrix -default_figure_position (void) +default_figure_position () { Matrix m (1, 4); @@ -508,7 +506,7 @@ } static Matrix -default_figure_papersize (void) +default_figure_papersize () { Matrix m (1, 2); @@ -519,7 +517,7 @@ } static Matrix -default_figure_paperposition (void) +default_figure_paperposition () { Matrix m (1, 4); @@ -533,7 +531,7 @@ } static std::string -default_graphics_toolkit (void) +default_graphics_toolkit () { octave::gtk_manager& gtk_mgr = octave::__get_gtk_manager__ (); @@ -541,7 +539,7 @@ } static Matrix -default_control_position (void) +default_control_position () { Matrix retval (1, 4); @@ -554,7 +552,7 @@ } static Matrix -default_control_sliderstep (void) +default_control_sliderstep () { Matrix retval (1, 2); @@ -565,7 +563,7 @@ } static Matrix -default_panel_position (void) +default_panel_position () { Matrix retval (1, 4); @@ -578,7 +576,7 @@ } static Matrix -default_light_position (void) +default_light_position () { Matrix m (1, 3); @@ -590,7 +588,7 @@ } static Matrix -default_table_position (void) +default_table_position () { Matrix retval (1, 4); @@ -603,7 +601,7 @@ } static Matrix -default_table_backgroundcolor (void) +default_table_backgroundcolor () { Matrix retval (2, 3); retval(0, 0) = 1; @@ -922,7 +920,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 +1200,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 +1328,7 @@ } std::string -radio_values::values_as_string (void) const +radio_values::values_as_string () const { std::string retval; @@ -1359,7 +1357,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 +1723,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 +1935,15 @@ { public: - callback_props (void) : m_set () { } + callback_props () : 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 () = default; + + bool empty () const { return m_set.empty (); } void insert (const callback_property *ptr) { @@ -2023,8 +2021,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 +2232,7 @@ } void -figure::properties::update_handlevisibility (void) +figure::properties::update_handlevisibility () { if (! is_handle_visible ()) { @@ -2294,7 +2291,7 @@ } void -figure::properties::update___device_pixel_ratio__ (void) +figure::properties::update___device_pixel_ratio__ () { update_text_pos (get___myhandle__ ()); } @@ -2818,226 +2815,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 +2827,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 +2836,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__ (); @@ -3369,7 +3040,7 @@ } std::set -base_properties::dynamic_property_names (void) const +base_properties::dynamic_property_names () const { return m_dynamic_properties; } @@ -3462,7 +3133,7 @@ */ void -base_properties::mark_modified (void) +base_properties::mark_modified () { // Mark existing object as modified m___modified__ = "on"; @@ -3512,7 +3183,7 @@ } void -base_properties::update_contextmenu (void) const +base_properties::update_contextmenu () const { if (m_contextmenu.get ().isempty ()) return; @@ -3530,14 +3201,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 +3221,7 @@ } void -base_properties::update_boundingbox (void) +base_properties::update_boundingbox () { Matrix kids = get_children (); @@ -3577,7 +3248,7 @@ } void -base_properties::update_handlevisibility (void) +base_properties::update_handlevisibility () { if (is_handle_visible ()) return; @@ -3726,7 +3397,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 +3456,7 @@ } void -base_graphics_object::reset_default_properties (void) +base_graphics_object::reset_default_properties () { if (valid_object ()) { @@ -3800,7 +3471,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 +3535,7 @@ } octave_scalar_map -base_graphics_object::values_as_struct (void) +base_graphics_object::values_as_struct () { octave_scalar_map retval; @@ -4020,7 +3691,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 +3796,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 +3850,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 +3859,7 @@ } octave::graphics_toolkit -figure::properties::get_toolkit (void) const +figure::properties::get_toolkit () const { return m_toolkit; } @@ -4572,7 +4243,7 @@ } Matrix -figure::properties::get_auto_paperposition (void) +figure::properties::get_auto_paperposition () { Matrix pos = get_position ().matrix_value (); Matrix sz; @@ -4742,7 +4413,7 @@ } void -figure::properties::update_papertype (void) +figure::properties::update_papertype () { std::string typ = get_papertype (); if (typ != "") @@ -4760,7 +4431,7 @@ } void -figure::properties::update_papersize (void) +figure::properties::update_papersize () { Matrix sz = get_papersize ().matrix_value (); if (sz(0) > sz(1)) @@ -4928,7 +4599,7 @@ */ void -figure::properties::update_paperorientation (void) +figure::properties::update_paperorientation () { std::string porient = get_paperorientation (); Matrix sz = get_papersize ().matrix_value (); @@ -5011,7 +4682,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 +4727,7 @@ } void -figure::reset_default_properties (void) +figure::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -5076,7 +4747,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 +4945,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 +5337,7 @@ } octave_value -axes::properties::get_colormap (void) const +axes::properties::get_colormap () const { if (m___colormap__.get ().isempty ()) { @@ -5783,7 +5454,7 @@ } inline Matrix -xform_matrix (void) +xform_matrix () { Matrix m (4, 4, 0.0); @@ -5794,7 +5465,7 @@ } inline ColumnVector -xform_vector (void) +xform_vector () { ColumnVector v (4, 0.0); @@ -5913,7 +5584,7 @@ } inline Matrix -unit_cube (void) +unit_cube () { static double data[32] = { @@ -5950,7 +5621,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 +5837,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 +6000,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 +6087,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 +6191,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 +6295,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 +6421,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 +6522,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 +7031,7 @@ } Matrix -graphics_xform::xform_eye (void) +graphics_xform::xform_eye () { return octave::xform_matrix (); } @@ -7491,7 +7162,7 @@ } void -axes::properties::update_outerposition (void) +axes::properties::update_outerposition () { set_positionconstraint ("outerposition"); caseless_str old_units = get_units (); @@ -7550,7 +7221,7 @@ } void -axes::properties::update_position (void) +axes::properties::update_position () { set_positionconstraint ("innerposition"); caseless_str old_units = get_units (); @@ -7598,7 +7269,7 @@ } void -axes::properties::update_looseinset (void) +axes::properties::update_looseinset () { caseless_str old_units = get_units (); set_units ("normalized"); @@ -9044,7 +8715,7 @@ } void -axes::properties::push_zoom_stack (void) +axes::properties::push_zoom_stack () { if (m_zoom_stack.empty ()) { @@ -9270,7 +8941,7 @@ } void -axes::properties::unzoom (void) +axes::properties::unzoom () { if (m_zoom_stack.size () >= 7) { @@ -9306,7 +8977,7 @@ } void -axes::properties::update_handlevisibility (void) +axes::properties::update_handlevisibility () { if (! is_handle_visible ()) { @@ -9335,7 +9006,7 @@ } void -figure::properties::init_toolkit (void) +figure::properties::init_toolkit () { octave::gtk_manager& gtk_mgr = octave::__get_gtk_manager__ (); @@ -9355,7 +9026,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; @@ -9384,7 +9055,7 @@ } void -axes::reset_default_properties (void) +axes::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -9415,7 +9086,7 @@ // --------------------------------------------------------------------- Matrix -line::properties::compute_xlim (void) const +line::properties::compute_xlim () const { Matrix m (1, 4); @@ -9428,7 +9099,7 @@ } Matrix -line::properties::compute_ylim (void) const +line::properties::compute_ylim () const { Matrix m (1, 4); @@ -9443,7 +9114,7 @@ // --------------------------------------------------------------------- Matrix -text::properties::get_data_position (void) const +text::properties::get_data_position () const { Matrix pos = get_position ().matrix_value (); @@ -9498,7 +9169,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.) @@ -9555,7 +9226,7 @@ } void -text::properties::update_font (void) +text::properties::update_font () { double dpr = device_pixel_ratio (get___myhandle__ ()); @@ -9577,7 +9248,7 @@ } void -text::properties::update_text_extent (void) +text::properties::update_text_extent () { int halign = 0; int valign = 0; @@ -9622,7 +9293,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")) @@ -9630,7 +9301,7 @@ } void -text::properties::update_units (void) +text::properties::update_units () { if (! units_is ("data")) { @@ -9687,7 +9358,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); } @@ -9706,7 +9377,7 @@ } void -light::properties::update_visible (void) +light::properties::update_visible () { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -9723,7 +9394,7 @@ // --------------------------------------------------------------------- bool -patch::properties::get_do_lighting (void) const +patch::properties::get_do_lighting () const { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -9736,7 +9407,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 ()) @@ -9748,7 +9419,7 @@ static bool updating_patch_data = false; void -patch::properties::update_fvc (void) +patch::properties::update_fvc () { if (updating_patch_data) return; @@ -9927,7 +9598,7 @@ } void -patch::properties::update_data (void) +patch::properties::update_data () { if (updating_patch_data) return; @@ -10308,7 +9979,7 @@ void -patch::reset_default_properties (void) +patch::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -10323,7 +9994,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 ()) @@ -10333,7 +10004,7 @@ } void -scatter::properties::update_data (void) +scatter::properties::update_data () { Matrix xd = get_xdata ().matrix_value (); Matrix yd = get_ydata ().matrix_value (); @@ -10373,7 +10044,7 @@ static bool updating_scatter_cdata = false; void -scatter::properties::update_color (void) +scatter::properties::update_color () { if (updating_scatter_cdata) return; @@ -10436,13 +10107,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__ (); @@ -10768,7 +10439,7 @@ } void -hggroup::properties::update_limits (void) const +hggroup::properties::update_limits () const { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -11002,7 +10673,7 @@ // --------------------------------------------------------------------- void -uicontextmenu::properties::update_beingdeleted (void) +uicontextmenu::properties::update_beingdeleted () { // Clear the uicontextmenu property of dependent objects if (m_beingdeleted.is ("on")) @@ -11052,7 +10723,7 @@ // --------------------------------------------------------------------- octave_value -uicontrol::properties::get_extent (void) const +uicontrol::properties::get_extent () const { Matrix m = m_extent.get ().matrix_value (); @@ -11067,7 +10738,7 @@ } void -uicontrol::properties::update_text_extent (void) +uicontrol::properties::update_text_extent () { // FIXME: support multiline text @@ -11079,7 +10750,7 @@ } void -uicontrol::properties::update_units (void) +uicontrol::properties::update_units () { Matrix pos = get_position ().matrix_value (); @@ -11817,14 +11488,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 (); @@ -11835,13 +11506,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 (); @@ -11883,7 +11554,7 @@ } void -uitoolbar::reset_default_properties (void) +uitoolbar::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -11916,118 +11587,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 { @@ -12044,7 +11603,7 @@ : base_graphics_event (busyaction), m_handle (h), m_callback_name (), m_callback (cb), m_callback_data (data) { } - void execute (void) + void execute () { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -12055,7 +11614,7 @@ } private: - callback_event (void) + callback_event () : base_graphics_event (), m_handle (), m_callback_name (), m_callback_data () { } @@ -12076,7 +11635,7 @@ : base_graphics_event (busyaction), m_handle (h), m_mcode (cmd) { } - void execute (void) + void execute () { if (! m_mcode.empty ()) { @@ -12093,7 +11652,7 @@ } private: - mcode_event (void) + mcode_event () : base_graphics_event (), m_handle (), m_mcode () { } @@ -12109,7 +11668,7 @@ // function_event objects must be created with at least a function. - function_event (void) = delete; + function_event () = delete; function_event (graphics_event::event_fcn fcn, void *data = nullptr) : base_graphics_event (), m_function (fcn), m_function_data (data) @@ -12121,7 +11680,7 @@ function_event& operator = (const function_event&) = delete; - void execute (void) + void execute () { m_function (m_function_data); } @@ -12145,7 +11704,7 @@ m_redraw_figure (redraw_figure) { } - void execute (void) + void execute () { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -12197,7 +11756,7 @@ } private: - set_event (void) + set_event () : base_graphics_event (), m_handle (), m_property_name (), m_property_value () { } @@ -12252,375 +11811,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; @@ -13162,8 +12354,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)); @@ -14320,14 +13511,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 (); @@ -14385,7 +13577,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) { @@ -14408,7 +13600,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; } } @@ -14562,7 +13754,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/graphics.in.h --- a/libinterp/corefcn/graphics.in.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/graphics.in.h Mon Jan 30 18:36:03 2023 +0100 @@ -66,9 +66,9 @@ class OCTINTERP_API base_scaler { public: - base_scaler (void) { } - - virtual ~base_scaler (void) = default; + base_scaler () { } + + virtual ~base_scaler () = default; virtual Matrix scale (const Matrix&) const { @@ -93,14 +93,14 @@ 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) { } + lin_scaler () { } Matrix scale (const Matrix& m) const { return m; } @@ -110,15 +110,15 @@ 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) { } + log_scaler () { } Matrix scale (const Matrix& m) const { @@ -144,7 +144,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 +158,7 @@ class OCTINTERP_API neg_log_scaler : public base_scaler { public: - neg_log_scaler (void) { } + neg_log_scaler () { } Matrix scale (const Matrix& m) const { @@ -184,7 +184,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 +198,7 @@ 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 +212,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 +226,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 +286,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 +301,25 @@ 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; } + 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 +328,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 +408,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: @@ -445,10 +445,10 @@ string_property (const string_property& p) : base_property (p), m_str (p.m_str) { } - octave_value get (void) const + 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 +456,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) @@ -530,7 +530,7 @@ : 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 + octave_value get () const { if (m_desired_type == string_t) return octave_value (string_value ()); @@ -538,7 +538,7 @@ return octave_value (cell_value ()); } - std::string string_value (void) const + std::string string_value () const { std::string s; @@ -552,9 +552,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 +562,7 @@ return *this; } - base_property * clone (void) const + base_property * clone () const { return new string_array_property (*this); } protected: @@ -736,13 +736,13 @@ : base_property (p), m_value (p.m_value), m_stored_type (p.m_stored_type) { } - bool empty (void) const + 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 +750,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 +767,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: @@ -862,7 +862,7 @@ return *this; } - std::string default_value (void) const { return m_default_val; } + std::string default_value () const { return m_default_val; } bool validate (const std::string& val, std::string& match) { @@ -913,11 +913,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 @@ -946,19 +946,19 @@ 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_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 +966,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) @@ -1045,11 +1045,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++) { @@ -1113,7 +1113,7 @@ 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_value get () const { if (m_current_type == color_t) return m_color_val.rgb (); @@ -1121,14 +1121,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 +1136,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 +1150,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); @@ -1195,9 +1195,9 @@ 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; } + 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 +1205,7 @@ return *this; } - base_property * clone (void) const + base_property * clone () const { double_property *p = new double_property (*this); @@ -1319,7 +1319,7 @@ 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_value get () const { if (m_current_type == double_t) return m_dval; @@ -1327,14 +1327,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 +1342,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 +1356,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 +1376,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 +1412,7 @@ m_maxval (std::pair (octave_NaN, true)) { } - octave_value get (void) const { return m_data; } + octave_value get () const { return m_data; } void add_constraint (const std::string& type) { m_type_constraints.insert (type); } @@ -1431,12 +1431,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 +1454,7 @@ return *this; } - base_property * clone (void) const + base_property * clone () const { array_property *p = new array_property (*this); @@ -1494,7 +1494,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; @@ -1564,7 +1564,7 @@ return *this; } - base_property * clone (void) const + base_property * clone () const { row_vector_property *p = new row_vector_property (*this); @@ -1619,7 +1619,7 @@ bool_property (const bool_property& p) : radio_property (p) { } - bool is_on (void) const { return is ("on"); } + bool is_on () const { return is ("on"); } bool_property& operator = (const octave_value& val) { @@ -1627,7 +1627,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) @@ -1652,9 +1652,9 @@ 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; } + 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 +1668,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); } @@ -1696,7 +1696,7 @@ any_property (const any_property& p) : base_property (p), m_data (p.m_data) { } - octave_value get (void) const { return m_data; } + octave_value get () const { return m_data; } any_property& operator = (const octave_value& val) { @@ -1704,7 +1704,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 +1722,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 +1747,7 @@ return *this; } - base_property * clone (void) const { return new children_property (*this); } + base_property * clone () const { return new children_property (*this); } bool remove_child (double val) { @@ -1759,22 +1759,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 +1877,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; @@ -1921,11 +1921,11 @@ callback_property (const callback_property& p) : base_property (p), m_callback (p.m_callback) { } - octave_value get (void) const { return m_callback; } + 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 +1936,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 +1962,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 +1973,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,26 +2053,26 @@ 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 + const string_property& as_string_property () const { return *(dynamic_cast (m_rep)); } - const radio_property& as_radio_property (void) const + const radio_property& as_radio_property () const { return *(dynamic_cast (m_rep)); } - const color_property& as_color_property (void) const + const color_property& as_color_property () const { return *(dynamic_cast (m_rep)); } - const double_property& as_double_property (void) const + const double_property& as_double_property () const { return *(dynamic_cast (m_rep)); } - const bool_property& as_bool_property (void) const + const bool_property& as_bool_property () const { return *(dynamic_cast (m_rep)); } - const handle_property& as_handle_property (void) const + const handle_property& as_handle_property () const { return *(dynamic_cast (m_rep)); } #endif @@ -2163,17 +2163,17 @@ property_list (const plist_map_type& m = plist_map_type ()) : m_plist_map (m) { } - ~property_list (void) = default; + ~property_list () = default; 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 +2204,11 @@ 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); + 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 +2257,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 +2275,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 +2302,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 +2328,7 @@ // Redirect calls to "uicontextmenu" to "contextmenu". - graphics_handle get_uicontextmenu (void) const + graphics_handle get_uicontextmenu () const { return get_contextmenu (); } @@ -2348,7 +2348,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 +2365,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 +2431,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 +2456,7 @@ protected: - virtual void init (void) + virtual void init () { m_contextmenu.add_constraint ("uicontextmenu"); } @@ -2467,7 +2467,7 @@ public: friend class graphics_object; - base_graphics_object (void) : m_toolkit_flag (false) { } + base_graphics_object () : m_toolkit_flag (false) { } // No copying! @@ -2475,9 +2475,9 @@ base_graphics_object& operator = (const base_graphics_object&) = delete; - virtual ~base_graphics_object (void) = default; - - virtual void mark_modified (void) + virtual ~base_graphics_object () = default; + + virtual void mark_modified () { if (! valid_object ()) error ("base_graphics_object::mark_modified: invalid graphics object"); @@ -2539,12 +2539,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 +2552,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 +2569,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 +2577,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 +2587,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 +2619,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 +2628,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 +2647,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 +2662,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 +2686,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 +2723,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 +2731,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 +2800,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 +2824,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 +2835,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 +2849,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 +2871,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 +2926,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 +3001,20 @@ 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 () = default; root_figure (const root_figure&) = delete; root_figure& operator = (const root_figure&) = delete; - void mark_modified (void) { } + void mark_modified () { } void override_defaults (base_graphics_object& obj) { @@ -3077,33 +3077,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 +3120,7 @@ property_list m_factory_properties; static OCTINTERP_API property_list::plist_map_type - init_factory_properties (void); + init_factory_properties (); }; // --------------------------------------------------------------------- @@ -3142,7 +3142,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 +3151,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 +3185,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 +3270,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 +3292,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; }; @@ -3315,7 +3315,7 @@ : base_graphics_object (), m_properties (mh, p), m_default_properties () { } - ~figure (void) = default; + ~figure () = default; void override_defaults (base_graphics_object& obj) { @@ -3356,23 +3356,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 +3392,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 +3410,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 +3426,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 +3495,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 +3509,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 +3518,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 +3557,7 @@ // Redirect calls to "innerposition" to "position". - octave_value get_innerposition (void) const + octave_value get_innerposition () const { return get_position (); } @@ -3568,63 +3568,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 +3662,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 +3673,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 +3908,7 @@ END_PROPERTIES protected: - OCTINTERP_API void init (void); + OCTINTERP_API void init (); private: @@ -3923,67 +3923,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 +4000,7 @@ (xaxislocation_is ("bottom") ? -1 : 1)), m_ylim); } - void update_yaxislocation (void) + void update_yaxislocation () { sync_positions (); update_axes_layout (); @@ -4020,7 +4020,7 @@ m_ylim); update_ylabel_position (); } - void update_xaxislocation (void) + void update_xaxislocation () { sync_positions (); update_axes_layout (); @@ -4041,15 +4041,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 +4104,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 +4130,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 +4140,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 +4239,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 +4284,7 @@ update_xlim (); } - void update_ylim (void) + void update_ylim () { update_axis_limits ("ylim"); @@ -4312,7 +4312,7 @@ update_ylim (); } - void update_zlim (void) + void update_zlim () { update_axis_limits ("zlim"); @@ -4336,7 +4336,7 @@ update_zlim (); } - void trigger_normals_calc (void); + void trigger_normals_calc (); }; @@ -4350,7 +4350,7 @@ m_properties.update_transform (); } - ~axes (void) = default; + ~axes () = default; void override_defaults (base_graphics_object& obj) { @@ -4397,28 +4397,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 +4476,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 +4501,13 @@ : 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; } + ~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 +4531,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 +4601,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 +4620,7 @@ } private: - void update_position (void) + void update_position () { Matrix pos = get_data_position (); Matrix lim; @@ -4646,19 +4646,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 +4667,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 +4696,13 @@ 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; } + ~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 +4723,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 +4762,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_xdata.add_constraint (2); m_xdata.add_constraint (dim_vector (0, 0)); @@ -4788,7 +4788,7 @@ } private: - void update_alphadata (void) + void update_alphadata () { if (alphadatamapping_is ("scaled")) set_alim (m_alphadata.get_limits ()); @@ -4796,7 +4796,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 +4810,7 @@ update_ydata (); } - void update_xdata (void) + void update_xdata () { if (m_xdata.get ().isempty ()) set_xdatamode ("auto"); @@ -4829,7 +4829,7 @@ set_xlim (limits); } - void update_ydata (void) + void update_ydata () { if (m_ydata.get ().isempty ()) set_ydatamode ("auto"); @@ -4848,7 +4848,7 @@ set_ylim (limits); } - Matrix get_auto_xdata (void) + Matrix get_auto_xdata () { dim_vector dv = get_cdata ().dims (); Matrix data; @@ -4860,7 +4860,7 @@ return data; } - Matrix get_auto_ydata (void) + Matrix get_auto_ydata () { dim_vector dv = get_cdata ().dims (); Matrix data; @@ -4890,12 +4890,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 +4911,13 @@ 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; } + ~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 +4947,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 +4964,13 @@ : 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; } + ~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 +4994,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 +5004,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 +5071,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 +5127,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 +5156,7 @@ set_xlim (m_xdata.get_limits ()); } - void update_ydata (void) + void update_ydata () { if (get_ydata ().isempty ()) { @@ -5174,14 +5174,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 +5192,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 +5234,13 @@ : 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; } + ~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 +5250,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 +5267,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 +5277,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 +5336,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 +5379,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 +5403,7 @@ update_data (); } - void update_ydata (void) + void update_ydata () { if (get_ydata ().isempty ()) { @@ -5420,19 +5420,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 +5442,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 +5470,13 @@ // 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; } + ~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 +5501,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 +5570,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 +5619,7 @@ private: - void update_alphadata (void) + void update_alphadata () { if (alphadatamapping_is ("scaled")) set_alim (m_alphadata.get_limits ()); @@ -5627,7 +5627,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 +5635,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 +5656,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 +5684,13 @@ : 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; } + ~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 +5737,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 +5755,13 @@ : 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; } + ~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 +5824,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 +5835,7 @@ } // Make "Callback" an alias for "MenuSelectedFcn". - octave_value get_callback (void) const + octave_value get_callback () const { return get_menuselectedfcn (); } @@ -5846,7 +5846,7 @@ } protected: - void init (void) + void init () { m_position.add_constraint ("min", 0, true); } @@ -5860,13 +5860,13 @@ : 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; } + ~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 +5894,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 +5910,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 +5921,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 +5933,13 @@ : 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; } + ~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 +6008,7 @@ std::string m_cached_units; protected: - void init (void) + void init () { m_cdata.add_constraint ("double"); m_cdata.add_constraint ("single"); @@ -6021,20 +6021,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 +6046,13 @@ : 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; } + ~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 +6119,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 +6146,13 @@ : 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; } + ~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 +6211,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 +6231,13 @@ : 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; } + ~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 +6303,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 +6321,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 +6340,13 @@ : 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; } + ~uitable () { } + + 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 +6377,7 @@ END_PROPERTIES protected: - void init (void) + void init () { } }; @@ -6389,7 +6389,7 @@ : base_graphics_object (), m_properties (mh, p), m_default_properties () { } - ~uitoolbar (void) = default; + ~uitoolbar () = default; void override_defaults (base_graphics_object& obj) { @@ -6430,23 +6430,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 +6487,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_cdata.add_constraint ("double"); m_cdata.add_constraint ("single"); @@ -6505,13 +6505,13 @@ : 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; } + ~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 +6553,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_cdata.add_constraint ("double"); m_cdata.add_constraint ("single"); @@ -6571,13 +6571,13 @@ : 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; } + ~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 +6611,7 @@ friend class graphics_event; - base_graphics_event (void) + base_graphics_event () : m_busyaction (QUEUE) { }; @@ -6619,11 +6619,11 @@ : m_busyaction (busyaction) { }; - virtual ~base_graphics_event (void) = default; - - int get_busyaction (void) { return m_busyaction; }; - - virtual void execute (void) = 0; + virtual ~base_graphics_event () = default; + + int get_busyaction () { return m_busyaction; }; + + virtual void execute () = 0; private: int m_busyaction; @@ -6637,17 +6637,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 +6655,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 +6691,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 +6704,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/gtk-manager.cc --- a/libinterp/corefcn/gtk-manager.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/gtk-manager.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/gtk-manager.h --- a/libinterp/corefcn/gtk-manager.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/gtk-manager.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,18 +37,20 @@ 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) + ~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 +76,7 @@ return graphics_toolkit (); } - Cell available_toolkits_list (void) const + Cell available_toolkits_list () const { Cell m (1, m_available_toolkits.size ()); @@ -85,7 +87,7 @@ return m; } - Cell loaded_toolkits_list (void) const + Cell loaded_toolkits_list () const { Cell m (1, m_loaded_toolkits.size ()); @@ -96,7 +98,7 @@ return m; } - void unload_all_toolkits (void) + void unload_all_toolkits () { while (! m_loaded_toolkits.empty ()) { @@ -112,10 +114,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/help.cc --- a/libinterp/corefcn/help.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/help.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/help.h --- a/libinterp/corefcn/help.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/help.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/hook-fcn.cc --- a/libinterp/corefcn/hook-fcn.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/hook-fcn.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/hook-fcn.h --- a/libinterp/corefcn/hook-fcn.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/hook-fcn.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,15 +42,15 @@ { public: - base_hook_function (void) = default; + base_hook_function () = default; base_hook_function (const base_hook_function&) = default; - virtual ~base_hook_function (void) = default; + virtual ~base_hook_function () = default; - virtual std::string id (void) const { return ""; } + virtual std::string id () 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 +59,7 @@ { public: - hook_function (void) + hook_function () { static std::shared_ptr nil_rep (new base_hook_function ()); @@ -70,15 +70,15 @@ hook_function (const octave_value& f, const octave_value& d = octave_value ()); - ~hook_function (void) = default; + ~hook_function () = default; hook_function (const hook_function& hf) = default; hook_function& operator = (const hook_function& hf) = default; - std::string id (void) const { return m_rep->id (); } + std::string id () 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) { @@ -100,9 +100,9 @@ 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: @@ -132,9 +132,9 @@ 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 +156,17 @@ typedef map_type::iterator iterator; typedef map_type::const_iterator const_iterator; - hook_function_list (void) = default; + hook_function_list () = default; - ~hook_function_list (void) = default; + ~hook_function_list () = default; hook_function_list (const hook_function_list& lst) = default; hook_function_list& operator = (const hook_function_list& lst) = default; - bool empty (void) const { return m_fcn_map.empty (); } + bool empty () 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 +183,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 +214,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/input.cc --- a/libinterp/corefcn/input.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/input.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 (); @@ -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, diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/input.h --- a/libinterp/corefcn/input.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/input.h Mon Jan 30 18:36:03 2023 +0100 @@ -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: @@ -233,19 +233,19 @@ : m_interpreter (x.m_interpreter) { } - 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: @@ -272,29 +272,29 @@ input_reader& operator = (const input_reader& ir) = default; - ~input_reader (void) = default; + ~input_reader () = default; 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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/interpreter-private.cc --- a/libinterp/corefcn/interpreter-private.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/interpreter-private.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/interpreter-private.h --- a/libinterp/corefcn/interpreter-private.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/interpreter-private.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/interpreter.cc --- a/libinterp/corefcn/interpreter.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/interpreter.cc Mon Jan 30 18:36:03 2023 +0100 @@ -314,7 +314,7 @@ return ovl (interp.traditional ()); } -temporary_file_list::~temporary_file_list (void) +temporary_file_list::~temporary_file_list () { cleanup (); } @@ -324,7 +324,7 @@ m_files.insert (file); } -void temporary_file_list::cleanup (void) +void temporary_file_list::cleanup () { while (! m_files.empty ()) { @@ -339,39 +339,7 @@ // 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) -{ - 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; -} - -static void initialize_version_info (void) +static void initialize_version_info () { octave_value_list args; @@ -383,12 +351,12 @@ 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 +368,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 +407,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 +441,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), @@ -657,7 +625,7 @@ OCTAVE_THREAD_LOCAL interpreter *interpreter::m_instance = nullptr; -interpreter::~interpreter (void) +interpreter::~interpreter () { if (! m_app_context) shutdown (); @@ -736,7 +704,7 @@ // This may be called separately from execute -void interpreter::initialize (void) +void interpreter::initialize () { if (m_initialized) return; @@ -789,7 +757,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 (); } @@ -808,7 +776,7 @@ cli_input_reader& operator = (const cli_input_reader&) = delete; - ~cli_input_reader (void) + ~cli_input_reader () { // FIXME: Would it be better to ensure that // interpreter::get_line_and_eval exits and then call @@ -817,7 +785,7 @@ m_thread.detach (); } - void start (void) + void start () { m_thread = std::thread (&interpreter::get_line_and_eval, &m_interpreter); } @@ -838,7 +806,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 +933,7 @@ } \ while (0) -void interpreter::shutdown (void) +void interpreter::shutdown () { // Attempt to prevent more than one call to shutdown. @@ -1075,7 +1043,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 +1060,7 @@ } } -void interpreter::display_startup_message (void) const +void interpreter::display_startup_message () const { bool inhibit_startup_message = false; @@ -1111,7 +1079,7 @@ // 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; @@ -1261,7 +1229,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 +1262,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 +1311,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 +1361,7 @@ return scope; } -profiler& interpreter::get_profiler (void) +profiler& interpreter::get_profiler () { return m_evaluator.get_profiler (); } @@ -1710,7 +1678,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 +1698,7 @@ m_evaluator.clear_all (force); } -void interpreter::clear_objects (void) +void interpreter::clear_objects () { m_evaluator.clear_objects (); } @@ -1750,7 +1718,7 @@ m_evaluator.clear_variable_regexp (pattern); } -void interpreter::clear_variables (void) +void interpreter::clear_variables () { m_evaluator.clear_variables (); } @@ -1770,7 +1738,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 +1778,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 +1806,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 +1834,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 +1843,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 +1854,7 @@ interrupt (); } -void interpreter::resume (void) +void interpreter::resume () { // FIXME: To be reliable, these tree_evaluator functions must be // made thread safe. @@ -1898,9 +1866,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 +1949,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,7 +1971,7 @@ recover_from_exception (); } -void interpreter::recover_from_exception (void) +void interpreter::recover_from_exception () { if (octave_interrupt_state) m_event_manager.interpreter_interrupted (); @@ -1960,7 +1988,7 @@ m_tmp_files.insert (file); } -void interpreter::cleanup_tmp_files (void) +void interpreter::cleanup_tmp_files () { m_tmp_files.cleanup (); } @@ -2035,12 +2063,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"); @@ -2082,4 +2109,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/interpreter.h --- a/libinterp/corefcn/interpreter.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/interpreter.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,6 +44,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" @@ -90,7 +91,7 @@ { public: - temporary_file_list (void) : m_files () { } + temporary_file_list () : m_files () { } // No copying! @@ -98,11 +99,11 @@ 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: @@ -127,7 +128,7 @@ // Clean up the interpreter object. - ~interpreter (void); + ~interpreter (); void intern_nargin (octave_idx_type nargs); @@ -147,12 +148,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 +165,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 +199,7 @@ m_traditional = flag; } - bool traditional (void) const + bool traditional () const { return m_traditional; } @@ -208,12 +209,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 +224,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 +433,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 +441,7 @@ void clear_all (bool force = false); - void clear_objects (void); + void clear_objects (); void clear_variable (const std::string& name); @@ -448,7 +449,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 +457,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 +473,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 +503,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 +552,34 @@ bool remove_atexit_fcn (const std::string& fname); - static interpreter * the_interpreter (void) { return m_instance; } + static interpreter * the_interpreter () { return m_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 diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/jsondecode.cc --- a/libinterp/corefcn/jsondecode.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/jsondecode.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/kron.cc --- a/libinterp/corefcn/kron.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/kron.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/latex-text-renderer.cc --- a/libinterp/corefcn/latex-text-renderer.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/latex-text-renderer.cc Mon Jan 30 18:36:03 2023 +0100 @@ -56,7 +56,7 @@ 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 +77,7 @@ m_debug = ! sys::env::getenv ("OCTAVE_LATEX_DEBUG_FLAG").empty (); } - ~latex_renderer (void) + ~latex_renderer () { if (! m_tmp_dir.empty () && ! m_debug) sys::recursive_rmdir (m_tmp_dir); @@ -144,9 +144,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 +183,7 @@ }; bool -latex_renderer::ok (void) +latex_renderer::ok () { // Only run the test once in a session static bool tested = false; @@ -522,7 +522,7 @@ } base_text_renderer * -make_latex_text_renderer (void) +make_latex_text_renderer () { latex_renderer *renderer = new latex_renderer (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/latex-text-renderer.h --- a/libinterp/corefcn/latex-text-renderer.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/latex-text-renderer.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/load-path.cc --- a/libinterp/corefcn/load-path.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/load-path.cc Mon Jan 30 18:36:03 2023 +0100 @@ -147,45 +147,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 +168,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 @@ -335,7 +278,7 @@ } void -load_path::clear (void) +load_path::clear () { m_dir_info_list.clear (); @@ -454,7 +397,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 @@ -893,7 +836,7 @@ } string_vector -load_path::dirs (void) const +load_path::dirs () const { std::size_t len = m_dir_info_list.size (); @@ -908,7 +851,7 @@ } std::list -load_path::dir_list (void) const +load_path::dir_list () const { std::list retval; @@ -947,13 +890,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 +964,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) { @@ -1223,7 +1183,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 +1294,45 @@ 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; + + sys::file_stat fs (pfname); + + if (fs.exists () && fs.is_reg ()) + retval = pfname; + } + } + + return retval; +} + load_path::dir_info::fcn_file_map_type get_fcn_files (const std::string& d) { @@ -1389,7 +1388,7 @@ } bool -load_path::dir_info::update (void) +load_path::dir_info::update () { sys::file_stat fs (dir_name); @@ -1483,7 +1482,7 @@ } void -load_path::dir_info::initialize (void) +load_path::dir_info::initialize () { is_relative = ! sys::env::absolute_pathname (dir_name); @@ -1897,7 +1896,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 (); @@ -2500,13 +2499,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 +2600,7 @@ lp.set (path, true); - rehash_internal (); + lp.rehash (); } if (nargout > 0) @@ -2754,7 +2755,7 @@ } if (need_to_update) - rehash_internal (); + lp.rehash (); return retval; } @@ -2814,7 +2815,7 @@ } if (need_to_update) - rehash_internal (); + lp.rehash (); return retval; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/load-path.h --- a/libinterp/corefcn/load-path.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/load-path.h Mon Jan 30 18:36:03 2023 +0100 @@ -55,11 +55,11 @@ 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 +69,7 @@ bool remove (const std::string& dir); - void update (void); + void update (); bool contains_canonical (const std::string& dir_name) const; @@ -159,24 +159,24 @@ 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; } - std::function get_remove_hook (void) + std::function get_remove_hook () { return remove_hook; } @@ -204,12 +204,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 +232,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 +249,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 +270,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 +282,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 +303,7 @@ private: - void initialize (void); + void initialize (); void get_file_list (const std::string& d); @@ -325,7 +327,7 @@ 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: @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/load-save.cc --- a/libinterp/corefcn/load-save.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/load-save.cc Mon Jan 30 18:36:03 2023 +0100 @@ -268,7 +268,7 @@ #endif } -load_save_system::~load_save_system (void) +load_save_system::~load_save_system () { #if defined (HAVE_HDF5) H5close (); @@ -732,7 +732,7 @@ } } -void load_save_system::dump_octave_core (void) +void load_save_system::dump_octave_core () { if (m_crash_dumps_octave_core) { @@ -1074,7 +1074,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 @@ -2060,13 +2060,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/load-save.h --- a/libinterp/corefcn/load-save.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/load-save.h Mon Jan 30 18:36:03 2023 +0100 @@ -75,7 +75,7 @@ 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; @@ -84,7 +84,7 @@ 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 +97,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 +110,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 +123,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 +136,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 +149,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 +186,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 +252,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 +277,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 +294,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/ls-ascii-helper.h --- a/libinterp/corefcn/ls-ascii-helper.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/ls-ascii-helper.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/ls-hdf5.cc --- a/libinterp/corefcn/ls-hdf5.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/ls-hdf5.cc Mon Jan 30 18:36:03 2023 +0100 @@ -100,7 +100,7 @@ } void -hdf5_fstreambase::close (void) +hdf5_fstreambase::close () { #if defined (HAVE_HDF5) diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/ls-hdf5.h --- a/libinterp/corefcn/ls-hdf5.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/ls-hdf5.h Mon Jan 30 18:36:03 2023 +0100 @@ -56,7 +56,7 @@ 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,7 +101,7 @@ struct hdf5_callback_data { public: - hdf5_callback_data (void) + hdf5_callback_data () : name (), global (false), tc (), doc () { } // the following fields are set by hdf5_read_data on successful return: diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/ls-mat5.cc --- a/libinterp/corefcn/ls-mat5.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/ls-mat5.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/ls-utils.h --- a/libinterp/corefcn/ls-utils.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/ls-utils.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/lsode.cc --- a/libinterp/corefcn/lsode.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/lsode.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/mex.cc --- a/libinterp/corefcn/mex.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/mex.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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" @@ -3113,28 +3112,24 @@ 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 (); @@ -4917,7 +4912,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/module.mk --- a/libinterp/corefcn/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -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 \ diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/mxarray.h --- a/libinterp/corefcn/mxarray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/mxarray.h Mon Jan 30 18:36:03 2023 +0100 @@ -94,17 +94,17 @@ public: - virtual mxArray_base * dup (void) const = 0; + virtual mxArray_base * dup () const = 0; - virtual mxArray * as_mxArray (void) const { return nullptr; } + virtual mxArray * as_mxArray () const { return nullptr; } - virtual ~mxArray_base (void) = default; + virtual ~mxArray_base () = default; - virtual bool is_octave_value (void) const { return false; } + 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 +118,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 +171,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 +207,36 @@ virtual void set_cell (mwIndex idx, mxArray *val) = 0; - virtual double get_scalar (void) const = 0; + virtual double get_scalar () const = 0; - virtual void * get_data (void) const = 0; + virtual void * get_data () 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 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 mxComplexDouble * get_complex_doubles (void) const = 0; - virtual mxComplexSingle * get_complex_singles (void) const = 0; + virtual mxComplexDouble * get_complex_doubles () const = 0; + virtual mxComplexSingle * get_complex_singles () 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; + virtual mxComplexInt8 * get_complex_int8s () const = 0; + virtual mxComplexInt16 * get_complex_int16s () const = 0; + virtual mxComplexInt32 * get_complex_int32s () const = 0; + virtual mxComplexInt64 * get_complex_int64s () const = 0; + virtual mxComplexUint8 * get_complex_uint8s () const = 0; + virtual mxComplexUint16 * get_complex_uint16s () const = 0; + virtual mxComplexUint32 * get_complex_uint32s () const = 0; + virtual mxComplexUint64 * get_complex_uint64s () const = 0; #endif - virtual void * get_imag_data (void) const = 0; + virtual void * get_imag_data () const = 0; virtual void set_data (void *pr) = 0; @@ -267,11 +267,11 @@ 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 +288,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,17 +296,17 @@ 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: @@ -377,7 +377,7 @@ OCTINTERP_API mxArray (bool interleaved, mwSize m, mwSize n); - mxArray * dup (void) const + mxArray * dup () const { mxArray *retval = m_rep->as_mxArray (); @@ -399,60 +399,60 @@ mxArray& operator = (const mxArray&) = delete; - OCTINTERP_API ~mxArray (void); + OCTINTERP_API ~mxArray (); - 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 +462,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 +492,74 @@ 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 + mxComplexInt8 * get_complex_int8s () const { DO_MUTABLE_METHOD (mxComplexInt8 *, get_complex_int8s ()); } - mxComplexInt16 * get_complex_int16s (void) const + mxComplexInt16 * get_complex_int16s () const { DO_MUTABLE_METHOD (mxComplexInt16 *, get_complex_int16s ()); } - mxComplexInt32 * get_complex_int32s (void) const + mxComplexInt32 * get_complex_int32s () const { DO_MUTABLE_METHOD (mxComplexInt32 *, get_complex_int32s ()); } - mxComplexInt64 * get_complex_int64s (void) const + mxComplexInt64 * get_complex_int64s () const { DO_MUTABLE_METHOD (mxComplexInt64 *, get_complex_int64s ()); } - mxComplexUint8 * get_complex_uint8s (void) const + mxComplexUint8 * get_complex_uint8s () const { DO_MUTABLE_METHOD (mxComplexUint8 *, get_complex_uint8s ()); } - mxComplexUint16 * get_complex_uint16s (void) const + mxComplexUint16 * get_complex_uint16s () const { DO_MUTABLE_METHOD (mxComplexUint16 *, get_complex_uint16s ()); } - mxComplexUint32 * get_complex_uint32s (void) const + mxComplexUint32 * get_complex_uint32s () const { DO_MUTABLE_METHOD (mxComplexUint32 *, get_complex_uint32s ()); } - mxComplexUint64 * get_complex_uint64s (void) const + mxComplexUint64 * get_complex_uint64s () 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)); } @@ -629,11 +629,11 @@ 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 +652,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 +664,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 +702,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 +740,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-errno.h --- a/libinterp/corefcn/oct-errno.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-errno.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,22 +39,22 @@ { protected: - octave_errno (void); + octave_errno (); public: - ~octave_errno (void) = default; + ~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,7 +67,7 @@ int do_lookup (const std::string& name); - octave_scalar_map do_list (void); + octave_scalar_map do_list (); //-------- diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-errno.in.cc --- a/libinterp/corefcn/oct-errno.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-errno.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-fstrm.cc --- a/libinterp/corefcn/oct-fstrm.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-fstrm.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-fstrm.h --- a/libinterp/corefcn/oct-fstrm.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-fstrm.h Mon Jan 30 18:36:03 2023 +0100 @@ -61,25 +61,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 +90,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-handle.h --- a/libinterp/corefcn/oct-handle.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-handle.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-hdf5-types.h --- a/libinterp/corefcn/oct-hdf5-types.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-hdf5-types.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-hist.cc --- a/libinterp/corefcn/oct-hist.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-hist.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-hist.h --- a/libinterp/corefcn/oct-hist.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-hist.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,16 +48,16 @@ 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 +70,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 +99,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-iostrm.cc --- a/libinterp/corefcn/oct-iostrm.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-iostrm.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-iostrm.h --- a/libinterp/corefcn/oct-iostrm.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-iostrm.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ protected: - ~base_iostream (void) = default; + ~base_iostream () = default; public: @@ -62,25 +62,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 @@ -98,21 +98,21 @@ // 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"; } + const char * stream_type () const { return "istream"; } // No copying! @@ -136,21 +136,21 @@ // 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"; } + const char * stream_type () const { return "ostream"; } // No copying! @@ -161,17 +161,4 @@ 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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-map.cc --- a/libinterp/corefcn/oct-map.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-map.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-map.h --- a/libinterp/corefcn/oct-map.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-map.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,7 +45,7 @@ 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) { } @@ -57,21 +57,21 @@ 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 +105,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 +120,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,9 +149,9 @@ { 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 (); } @@ -165,7 +165,7 @@ 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 () : m_keys (), m_vals () { } octave_scalar_map (const string_vector& k) : m_keys (k), m_vals (k.numel ()) { } @@ -189,11 +189,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 +215,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 +224,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 +243,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 +252,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 (); @@ -285,7 +285,7 @@ typedef octave_scalar_map element_type; - octave_map (void) : m_keys (), m_vals (), m_dimensions () { } + octave_map () : m_keys (), m_vals (), m_dimensions () { } octave_map (const dim_vector& dv) : m_keys (), m_vals (), m_dimensions (dv) { } @@ -315,11 +315,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 +341,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 +350,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 +370,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 +379,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 +423,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 +491,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-opengl.h --- a/libinterp/corefcn/oct-opengl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-opengl.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-prcstrm.cc --- a/libinterp/corefcn/oct-prcstrm.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-prcstrm.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-prcstrm.h --- a/libinterp/corefcn/oct-prcstrm.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-prcstrm.h Mon Jan 30 18:36:03 2023 +0100 @@ -65,7 +65,7 @@ protected: - ~octave_iprocstream (void); + ~octave_iprocstream (); }; class @@ -93,19 +93,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-procbuf.cc --- a/libinterp/corefcn/oct-procbuf.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-procbuf.cc Mon Jan 30 18:36:03 2023 +0100 @@ -182,7 +182,7 @@ } procbuf * -procbuf::close (void) +procbuf::close () { #if defined (__CYGWIN__) || defined (__MINGW32__) || defined (_MSC_VER) diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-procbuf.h --- a/libinterp/corefcn/oct-procbuf.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-procbuf.h Mon Jan 30 18:36:03 2023 +0100 @@ -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) { } @@ -58,17 +58,17 @@ 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 +83,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-process.h --- a/libinterp/corefcn/oct-process.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-process.h Mon Jan 30 18:36:03 2023 +0100 @@ -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 () { } @@ -54,13 +54,13 @@ 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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-stdstrm.h --- a/libinterp/corefcn/oct-stdstrm.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-stdstrm.h Mon Jan 30 18:36:03 2023 +0100 @@ -65,43 +65,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 +109,7 @@ protected: - ~tstdiostream (void) { delete m_stream; } + ~tstdiostream () { delete m_stream; } //-------- @@ -155,7 +155,7 @@ protected: - ~stdiostream (void) = default; + ~stdiostream () = default; }; #if defined (HAVE_ZLIB) @@ -192,21 +192,11 @@ 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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-stream.cc --- a/libinterp/corefcn/oct-stream.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-stream.cc Mon Jan 30 18:36:03 2023 +0100 @@ -262,7 +262,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; @@ -297,24 +297,24 @@ scanf_format_list& operator = (const scanf_format_list&) = delete; - ~scanf_format_list (void); - - octave_idx_type num_conversions (void) { return m_nconv; } + ~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 +337,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 +449,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 +665,7 @@ } void -scanf_format_list::printme (void) const +scanf_format_list::printme () const { std::size_t n = m_fmt_elts.size (); @@ -693,7 +693,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 +723,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 +767,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; @@ -805,22 +805,22 @@ 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) + ~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 +837,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 +958,7 @@ } } -printf_format_list::~printf_format_list (void) +printf_format_list::~printf_format_list () { std::size_t n = m_fmt_elts.size (); @@ -1160,7 +1160,7 @@ } void -printf_format_list::printme (void) const +printf_format_list::printme () const { std::size_t n = m_fmt_elts.size (); @@ -1198,7 +1198,7 @@ } static Cell -init_inf_nan (void) +init_inf_nan () { Cell retval (dim_vector (1, 2)); @@ -1237,11 +1237,11 @@ delimited_stream& operator = (const delimited_stream&) = delete; - ~delimited_stream (void); + ~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 +1253,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 +1262,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 +1288,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 +1316,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 +1398,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 +1415,7 @@ // if necessary. int -delimited_stream::get_undelim (void) +delimited_stream::get_undelim () { int retval; if (eof ()) @@ -1449,7 +1449,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 (); @@ -1735,24 +1735,24 @@ textscan_format_list& operator = (const textscan_format_list&) = delete; - ~textscan_format_list (void); - - octave_idx_type num_conversions (void) const { return m_nconv; } + ~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 +1772,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 +1789,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: @@ -1852,7 +1852,7 @@ textscan& operator = (const textscan&) = delete; - ~textscan (void) = default; + ~textscan () = default; octave_value scan (std::istream& isp, const std::string& fmt, octave_idx_type ntimes, @@ -1922,7 +1922,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 (); } //-------- @@ -2088,7 +2088,7 @@ m_buf.str (""); } -textscan_format_list::~textscan_format_list (void) +textscan_format_list::~textscan_format_list () { std::size_t n = numel (); @@ -2474,7 +2474,7 @@ } void -textscan_format_list::printme (void) const +textscan_format_list::printme () const { std::size_t n = numel (); @@ -4084,14 +4084,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 +4288,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 +4304,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 +4353,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 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? 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 +4447,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 +4514,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 +4588,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 +4631,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 +4645,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 +4662,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 +4706,7 @@ tmp = string::u8_from_encoding (who, tmp, encoding ()); \ width = tmp.length (); \ \ - if (is) \ + if (is && width > 0) \ { \ int i = 0; \ \ @@ -5048,10 +5078,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 +5500,7 @@ // (output streams are those that define os). int -base_stream::flush (void) +base_stream::flush () { int retval = -1; @@ -5516,7 +5546,7 @@ printf_value_cache& operator = (const printf_value_cache&) = delete; - ~printf_value_cache (void) = default; + ~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 +5555,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 +5694,7 @@ } int -printf_value_cache::int_value (void) +printf_value_cache::int_value () { octave_value val = get_next_value (); @@ -6132,7 +6162,7 @@ } int -stream::flush (void) +stream::flush () { int retval = -1; @@ -6372,7 +6402,7 @@ } off_t -stream::tell (void) +stream::tell () { off_t retval = -1; @@ -6383,13 +6413,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 +6430,7 @@ } void -stream::close (void) +stream::close () { if (stream_ok ()) { @@ -7297,7 +7327,7 @@ } bool -stream::eof (void) const +stream::eof () const { int retval = -1; @@ -7319,7 +7349,7 @@ } std::string -stream::name (void) const +stream::name () const { std::string retval; @@ -7330,7 +7360,7 @@ } int -stream::mode (void) const +stream::mode () const { int retval = 0; @@ -7341,7 +7371,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 +7442,7 @@ m_stderr_file = insert (stderr_stream); } -stream_list::~stream_list (void) +stream_list::~stream_list () { clear (); } @@ -7620,7 +7650,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 +7682,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 +7740,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-stream.h --- a/libinterp/corefcn/oct-stream.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-stream.h Mon Jan 30 18:36:03 2023 +0100 @@ -85,7 +85,7 @@ 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 +96,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 +145,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 +158,7 @@ } } - virtual int file_number (void) const + virtual int file_number () const { // Kluge alert! @@ -172,7 +172,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 +180,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 +193,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 +273,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 +314,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 +346,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 +408,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,38 +428,38 @@ 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->preferred_output_stream () : nullptr); } - void clearerr (void) { if (m_rep) m_rep->clearerr (); } + void clearerr () { if (m_rep) m_rep->clearerr (); } private: @@ -508,7 +508,7 @@ stream_list (const stream_list&) = delete; stream_list& operator = (const stream_list&) = delete; - OCTINTERP_API ~stream_list (void); + OCTINTERP_API ~stream_list (); OCTINTERP_API int insert (stream& os); @@ -525,15 +525,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-strstrm.cc --- a/libinterp/corefcn/oct-strstrm.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-strstrm.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-strstrm.h --- a/libinterp/corefcn/oct-strstrm.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-strstrm.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ protected: - ~base_strstream (void) = default; + ~base_strstream () = default; public: @@ -64,17 +64,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 @@ -102,7 +102,7 @@ protected: - ~istrstream (void) = default; + ~istrstream () = default; public: @@ -119,22 +119,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: @@ -159,7 +159,7 @@ protected: - ~ostrstream (void) = default; + ~ostrstream () = default; public: @@ -170,22 +170,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 +194,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/oct-tex-lexer.in.ll --- a/libinterp/corefcn/oct-tex-lexer.in.ll Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/oct-tex-lexer.in.ll Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/ordschur.cc --- a/libinterp/corefcn/ordschur.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/ordschur.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/pager.cc --- a/libinterp/corefcn/pager.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/pager.cc Mon Jan 30 18:36:03 2023 +0100 @@ -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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/pager.h --- a/libinterp/corefcn/pager.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/pager.h Mon Jan 30 18:36:03 2023 +0100 @@ -47,15 +47,15 @@ { public: - pager_buf (void) : std::stringbuf (), m_diary_skip (0) { } + pager_buf () : std::stringbuf (), m_diary_skip (0) { } - void flush_current_contents_to_diary (void); + void flush_current_contents_to_diary (); - void set_diary_skip (void); + void set_diary_skip (); protected: - int sync (void); + int sync (); private: @@ -68,7 +68,7 @@ { public: - pager_stream (void); + pager_stream (); // No copying! @@ -76,15 +76,15 @@ pager_stream& operator = (const pager_stream&) = delete; - ~pager_stream (void); + ~pager_stream (); - void flush_current_contents_to_diary (void); + void flush_current_contents_to_diary (); - void set_diary_skip (void); + void set_diary_skip (); - std::ostream& stream (void); + std::ostream& stream (); - void reset (void); + void reset (); private: @@ -97,11 +97,11 @@ { public: - diary_buf (void) : std::stringbuf () { } + diary_buf () : std::stringbuf () { } protected: - int sync (void); + int sync (); }; class @@ -110,7 +110,7 @@ { public: - diary_stream (void); + diary_stream (); // No copying! @@ -118,18 +118,18 @@ 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 { @@ -141,13 +141,13 @@ 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 +158,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 +169,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 +181,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 +196,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 +205,7 @@ return val; } - bool write_to_diary_file (void) const + bool write_to_diary_file () const { return m_write_to_diary_file; } @@ -217,7 +217,7 @@ return val; } - bool really_flush_to_pager (void) const + bool really_flush_to_pager () const { return m_really_flush_to_pager; } @@ -229,7 +229,7 @@ return val; } - bool flushing_output_to_pager (void) const + bool flushing_output_to_pager () const { return m_flushing_output_to_pager; } @@ -241,25 +241,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 +300,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 17d568574e1c -r 7860fcc69082 libinterp/corefcn/pr-flt-fmt.cc --- a/libinterp/corefcn/pr-flt-fmt.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/pr-flt-fmt.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ static int Voutput_precision = 5; int -output_precision (void) +output_precision () { return Voutput_precision; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/pr-flt-fmt.h --- a/libinterp/corefcn/pr-flt-fmt.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/pr-flt-fmt.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ template class pr_rational_float; -extern OCTINTERP_API int output_precision (void); +extern OCTINTERP_API int output_precision (); extern OCTINTERP_API void set_output_prec (int prec); @@ -60,33 +60,33 @@ float_format& operator = (const float_format&) = default; - ~float_format (void) = default; + ~float_format () = default; - float_format& scientific (void) + float_format& scientific () { m_fmt = std::ios::scientific; return *this; } - float_format& fixed (void) + float_format& fixed () { m_fmt = std::ios::fixed; return *this; } - float_format& general (void) + float_format& general () { m_fmt = 0; return *this; } - float_format& uppercase (void) + float_format& uppercase () { m_up = std::ios::uppercase; return *this; } - float_format& lowercase (void) + float_format& lowercase () { m_up = 0; return *this; @@ -117,57 +117,57 @@ return *this; } - std::ios::fmtflags format_flags (void) const + std::ios::fmtflags format_flags () const { return static_cast (m_fmt | m_up | m_sp); } - int format (void) const + int format () const { return m_fmt; } - bool is_scientific (void) const + bool is_scientific () const { return m_fmt == std::ios::scientific; } - bool is_fixed (void) const + bool is_fixed () const { return m_fmt == std::ios::fixed; } - bool is_general (void) const + bool is_general () const { return m_fmt == 0; } - bool is_uppercase (void) const + bool is_uppercase () const { return m_up == std::ios::uppercase; } - bool is_lowercase (void) const + bool is_lowercase () const { return m_up == 0; } - int precision (void) const + int precision () const { return m_prec; } - int width (void) const + int width () const { return m_fw; } - int exponent_width (void) const + int exponent_width () const { return m_ex; } - bool show_trailing_zeros (void) const + bool show_trailing_zeros () const { return m_sp == std::ios::showpoint; } @@ -211,7 +211,7 @@ { public: - float_display_format (void) = default; + float_display_format () = default; float_display_format (double scale, const float_format& real_fmt, const float_format& imag_fmt = float_format ()) @@ -227,13 +227,13 @@ float_display_format& operator = (const float_display_format&) = default; - ~float_display_format (void) = default; + ~float_display_format () = default; - double scale_factor (void) const { return m_scale; } + double scale_factor () const { return m_scale; } - float_format real_format (void) const { return m_real_fmt; } + float_format real_format () const { return m_real_fmt; } - float_format imag_format (void) const { return m_imag_fmt; } + float_format imag_format () const { return m_imag_fmt; } void set_precision (int prec) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/pr-output.cc --- a/libinterp/corefcn/pr-output.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/pr-output.cc Mon Jan 30 18:36:03 2023 +0100 @@ -50,11 +50,11 @@ #include "defun.h" #include "error.h" #include "errwarn.h" +#include "interpreter.h" #include "ovl.h" #include "oct-stream.h" #include "octave-preserve-stream-state.h" #include "pager.h" -#include "parse.h" #include "pr-flt-fmt.h" #include "pr-output.h" #include "sysdep.h" @@ -170,14 +170,14 @@ template int -pr_engineering_float::exponent (void) const +pr_engineering_float::exponent () const { return engineering_exponent (m_val); } template T -pr_engineering_float::mantissa (void) const +pr_engineering_float::mantissa () const { return m_val / std::pow (static_cast (10), exponent ()); } @@ -3448,8 +3448,8 @@ %! end_unwind_protect */ -DEFUN (display, args, , - classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64 +DEFMETHOD (display, interp, args, , + classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64 doc: /* -*- texinfo -*- @deftypefn {} {} display (@var{obj}) Display the contents of the object @var{obj} prepended by its name. @@ -3521,7 +3521,7 @@ // Use feval so that dispatch will also work for disp. - feval ("disp", ovl (value)); + interp.feval ("disp", ovl (value)); if (print_newlines) octave_stdout << std::endl; @@ -3558,7 +3558,7 @@ */ static inline void -init_format_state (void) +init_format_state () { free_format = false; plus_format = false; @@ -3606,7 +3606,7 @@ frame.protect_var (Vcompact_format); frame.protect_var (uppercase_format); int prec = output_precision (); - frame.add ([=] (void) { set_output_prec (prec); }); + frame.add ([=] () { set_output_prec (prec); }); format = format_string; // Initialize with existing value while (argc-- > 0) diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/pr-output.h --- a/libinterp/corefcn/pr-output.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/pr-output.h Mon Jan 30 18:36:03 2023 +0100 @@ -517,9 +517,9 @@ T m_val; - int exponent (void) const; + int exponent () const; - T mantissa (void) const; + T mantissa () const; pr_engineering_float (const float_format& ff, T val) : m_ff (ff), m_val (val) { } diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/procstream.cc --- a/libinterp/corefcn/procstream.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/procstream.cc Mon Jan 30 18:36:03 2023 +0100 @@ -59,7 +59,7 @@ } int -procstreambase::close (void) +procstreambase::close () { int status = 0; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/procstream.h --- a/libinterp/corefcn/procstream.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/procstream.h Mon Jan 30 18:36:03 2023 +0100 @@ -43,13 +43,13 @@ { public: - procstreambase (void) : m_pb () { pb_init (); } + procstreambase () : m_pb () { pb_init (); } procstreambase (const std::string& name, int mode); procstreambase (const char *name, int mode); - ~procstreambase (void) { close (); } + ~procstreambase () { close (); } void open (const std::string& name, int mode) { @@ -58,19 +58,19 @@ void open (const char *name, int mode); - int is_open (void) const { return m_pb.is_open (); } + int is_open () const { return m_pb.is_open (); } - int close (void); + int close (); - pid_t pid (void) const { return m_pb.pid (); } + pid_t pid () const { return m_pb.pid (); } - int file_number (void) const { return m_pb.file_number (); } + int file_number () const { return m_pb.file_number (); } private: procbuf m_pb; - void pb_init (void) + void pb_init () { // Explicit initialization of the std::ios object is needed. // FIXME: is there a better way to organize these classes? @@ -88,7 +88,7 @@ { public: - iprocstream (void) : std::istream (nullptr), procstreambase () { } + iprocstream () : std::istream (nullptr), procstreambase () { } iprocstream (const std::string& name, int mode = std::ios::in) : std::istream (nullptr), procstreambase (name, mode) @@ -98,7 +98,7 @@ : std::istream (nullptr), procstreambase (name, mode) { } - ~iprocstream (void) = default; + ~iprocstream () = default; void open (const std::string& name, int mode = std::ios::in) { @@ -123,7 +123,7 @@ { public: - oprocstream (void) : std::ostream (nullptr), procstreambase () { } + oprocstream () : std::ostream (nullptr), procstreambase () { } oprocstream (const std::string& name, int mode = std::ios::out) : std::ostream (nullptr), procstreambase (name, mode) { } @@ -131,7 +131,7 @@ oprocstream (const char *name, int mode = std::ios::out) : std::ostream (nullptr), procstreambase (name, mode) { } - ~oprocstream (void) = default; + ~oprocstream () = default; void open (const std::string& name, int mode = std::ios::out) { @@ -156,7 +156,7 @@ { public: - procstream (void) : std::iostream (nullptr), procstreambase () { } + procstream () : std::iostream (nullptr), procstreambase () { } procstream (const std::string& name, int mode) : std::iostream (nullptr), procstreambase (name, mode) @@ -166,7 +166,7 @@ : std::iostream (nullptr), procstreambase (name, mode) { } - ~procstream (void) = default; + ~procstream () = default; void open (const std::string& name, int mode) { @@ -187,20 +187,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::procstreambase' instead") -typedef octave::procstreambase procstreambase; - -OCTAVE_DEPRECATED (7, "use 'octave::iprocstream' instead") -typedef octave::iprocstream iprocstream; - -OCTAVE_DEPRECATED (7, "use 'octave::oprocstream' instead") -typedef octave::oprocstream oprocstream; - -OCTAVE_DEPRECATED (7, "use 'octave::procstream' instead") -typedef octave::procstream procstream; - #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/quad.cc --- a/libinterp/corefcn/quad.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/quad.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,8 +36,8 @@ #include "error.h" #include "errwarn.h" #include "interpreter-private.h" +#include "interpreter.h" #include "pager.h" -#include "parse.h" #include "ov.h" #include "ovl.h" #include "unwind-prot.h" @@ -71,7 +71,9 @@ try { - tmp = feval (quad_fcn, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (quad_fcn, args, 1); } catch (execution_exception& ee) { @@ -107,7 +109,9 @@ try { - tmp = feval (quad_fcn, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (quad_fcn, args, 1); } catch (execution_exception& ee) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/quadcc.cc --- a/libinterp/corefcn/quadcc.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/quadcc.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,8 +37,8 @@ #include "defun.h" #include "error.h" #include "interpreter-private.h" +#include "interpreter.h" #include "ovl.h" -#include "parse.h" #include "utils.h" #include "variables.h" @@ -1715,7 +1715,7 @@ ex(i) = m + xi[i]*h; } fargs(0) = ex; - fvals = feval (fcn, fargs, 1); + fvals = interp.feval (fcn, fargs, 1); if (fvals.length () != 1 || ! fvals(0).is_real_matrix ()) error ("quadcc: integrand F must return a single, real-valued vector"); @@ -1825,7 +1825,7 @@ ex(i) = m + xi[(2*i + 1) * skip[d]] * h; } fargs(0) = ex; - fvals = feval (fcn, fargs, 1); + fvals = interp.feval (fcn, fargs, 1); if (fvals.length () != 1 || ! fvals(0).is_real_matrix ()) error ("quadcc: integrand F must return a single, real-valued vector"); @@ -1958,7 +1958,7 @@ ex(i) = ml + xi[(i + 1) * skip[0]] * hl; } fargs(0) = ex; - fvals = feval (fcn, fargs, 1); + fvals = interp.feval (fcn, fargs, 1); if (fvals.length () != 1 || ! fvals(0).is_real_matrix ()) error ("quadcc: integrand F must return a single, real-valued vector"); @@ -2049,7 +2049,7 @@ ex(i) = mr + xi[(i + 1) * skip[0]] * hr; } fargs(0) = ex; - fvals = feval (fcn, fargs, 1); + fvals = interp.feval (fcn, fargs, 1); if (fvals.length () != 1 || ! fvals(0).is_real_matrix ()) error ("quadcc: integrand F must return a single, real-valued vector"); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/settings.cc --- a/libinterp/corefcn/settings.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/settings.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -settings::settings (void) +settings::settings () : m_display_tokens (false), m_token_count (0), m_lexer_debug_flag (false) { } diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/settings.h --- a/libinterp/corefcn/settings.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/settings.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,17 +45,17 @@ { public: - settings (void); + settings (); settings (const settings&) = delete; settings& operator = (const settings&) = delete; - ~settings (void) = default; + ~settings () = default; octave_value display_tokens (const octave_value_list& args, int nargout); - bool display_tokens (void) const { return m_display_tokens; } + bool display_tokens () const { return m_display_tokens; } bool display_tokens (bool flag) { @@ -65,13 +65,13 @@ } // Read only. - std::size_t token_count (void) const { return m_token_count; } + std::size_t token_count () const { return m_token_count; } - void increment_token_count (void) { ++m_token_count; } + void increment_token_count () { ++m_token_count; } octave_value lexer_debug_flag (const octave_value_list& args, int nargout); - bool lexer_debug_flag (void) const { return m_lexer_debug_flag; } + bool lexer_debug_flag () const { return m_lexer_debug_flag; } bool lexer_debug_flag (bool flag) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/sighandlers.cc --- a/libinterp/corefcn/sighandlers.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/sighandlers.cc Mon Jan 30 18:36:03 2023 +0100 @@ -107,7 +107,7 @@ // we have caught. void -respond_to_pending_signals (void) +respond_to_pending_signals () { // The list of signals is relatively short, so we will just go // linearly through the list. @@ -323,7 +323,7 @@ } interrupt_handler -catch_interrupts (void) +catch_interrupts () { interrupt_handler retval; @@ -334,7 +334,7 @@ } interrupt_handler -ignore_interrupts (void) +ignore_interrupts () { interrupt_handler retval; @@ -362,7 +362,7 @@ // Install all the handlers for the signals we might care about. void -install_signal_handlers (void) +install_signal_handlers () { if (! signals_caught) signals_caught = new bool [octave_num_signals ()]; @@ -445,7 +445,7 @@ } static octave_scalar_map -make_sig_struct (void) +make_sig_struct () { octave_scalar_map m; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/sighandlers.h --- a/libinterp/corefcn/sighandlers.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/sighandlers.h Mon Jan 30 18:36:03 2023 +0100 @@ -66,13 +66,13 @@ set_signal_handler (const char *signame, sig_handler *h, bool restart_syscalls = true); -extern OCTINTERP_API void install_signal_handlers (void); +extern OCTINTERP_API void install_signal_handlers (); -extern OCTINTERP_API void respond_to_pending_signals (void); +extern OCTINTERP_API void respond_to_pending_signals (); -extern OCTINTERP_API interrupt_handler catch_interrupts (void); +extern OCTINTERP_API interrupt_handler catch_interrupts (); -extern OCTINTERP_API interrupt_handler ignore_interrupts (void); +extern OCTINTERP_API interrupt_handler ignore_interrupts (); extern OCTINTERP_API interrupt_handler set_interrupt_handler (const volatile interrupt_handler& h, diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/sparse-xdiv.h --- a/libinterp/corefcn/sparse-xdiv.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/sparse-xdiv.h Mon Jan 30 18:36:03 2023 +0100 @@ -104,207 +104,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline Matrix -xdiv (const Matrix& a, const SparseMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexMatrix -xdiv (const Matrix& a, const SparseComplexMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexMatrix -xdiv (const ComplexMatrix& a, const SparseMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexMatrix -xdiv (const ComplexMatrix& a, const SparseComplexMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline SparseMatrix -xdiv (const SparseMatrix& a, const SparseMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline SparseComplexMatrix -xdiv (const SparseMatrix& a, const SparseComplexMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline SparseComplexMatrix -xdiv (const SparseComplexMatrix& a, const SparseMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline SparseComplexMatrix -xdiv (const SparseComplexMatrix& a, const SparseComplexMatrix& b, - MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline SparseMatrix -xdiv (const SparseMatrix& a, const DiagMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline SparseComplexMatrix -xdiv (const SparseMatrix& a, const ComplexDiagMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline SparseComplexMatrix -xdiv (const SparseComplexMatrix& a, const DiagMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline SparseComplexMatrix -xdiv (const SparseComplexMatrix& a, const ComplexDiagMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline Matrix -x_el_div (double a, const SparseMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexMatrix -x_el_div (double a, const SparseComplexMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexMatrix -x_el_div (const Complex& a, const SparseMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexMatrix -x_el_div (const Complex& a, const SparseComplexMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline Matrix -xleftdiv (const SparseMatrix& a, const Matrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexMatrix -xleftdiv (const SparseMatrix& a, const ComplexMatrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexMatrix -xleftdiv (const SparseComplexMatrix& a, const Matrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexMatrix -xleftdiv (const SparseComplexMatrix& a, const ComplexMatrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline SparseMatrix -xleftdiv (const SparseMatrix& a, const SparseMatrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline SparseComplexMatrix -xleftdiv (const SparseMatrix& a, const SparseComplexMatrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline SparseComplexMatrix -xleftdiv (const SparseComplexMatrix& a, const SparseMatrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline SparseComplexMatrix -xleftdiv (const SparseComplexMatrix& a, const SparseComplexMatrix& b, - MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline SparseMatrix -xleftdiv (const DiagMatrix& a, const SparseMatrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline SparseComplexMatrix -xleftdiv (const ComplexDiagMatrix& a, const SparseMatrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline SparseComplexMatrix -xleftdiv (const DiagMatrix& a, const SparseComplexMatrix& b, MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline SparseComplexMatrix -xleftdiv (const ComplexDiagMatrix& a, const SparseComplexMatrix& b, - MatrixType& typ) -{ - return octave::xleftdiv (a, b, typ); -} - #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/sparse-xpow.h --- a/libinterp/corefcn/sparse-xpow.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/sparse-xpow.h Mon Jan 30 18:36:03 2023 +0100 @@ -62,106 +62,4 @@ OCTAVE_END_NAMESPACE(octave) -#if (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const SparseMatrix& a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const SparseComplexMatrix& a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (double a, const SparseMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (double a, const SparseComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const SparseMatrix& a, double b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const SparseMatrix& a, const SparseMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const SparseMatrix& a, const Complex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const SparseMatrix& a, const SparseComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Complex& a, const SparseMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Complex& a, const SparseComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const SparseComplexMatrix& a, double b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const SparseComplexMatrix& a, const SparseMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const SparseComplexMatrix& a, const Complex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const SparseComplexMatrix& a, const SparseComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/stack-frame.cc --- a/libinterp/corefcn/stack-frame.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/stack-frame.cc Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - compiled_fcn_stack_frame (void) = delete; + compiled_fcn_stack_frame () = delete; compiled_fcn_stack_frame (tree_evaluator& tw, octave_function *fcn, std::size_t index, @@ -70,16 +70,16 @@ compiled_fcn_stack_frame& operator = (const compiled_fcn_stack_frame& elt) = delete; - ~compiled_fcn_stack_frame (void) = default; - - bool is_compiled_fcn_frame (void) const { return true; } - - symbol_scope get_scope (void) const + ~compiled_fcn_stack_frame () = default; + + bool is_compiled_fcn_frame () const { return true; } + + symbol_scope get_scope () const { return m_static_link->get_scope (); } - octave_function * function (void) const { return m_fcn; } + octave_function * function () const { return m_fcn; } symbol_record lookup_symbol (const std::string& name) const { @@ -175,7 +175,7 @@ { public: - script_stack_frame (void) = delete; + script_stack_frame () = delete; script_stack_frame (tree_evaluator& tw, octave_user_script *script, std::size_t index, @@ -186,36 +186,36 @@ script_stack_frame& operator = (const script_stack_frame& elt) = delete; - ~script_stack_frame (void) + ~script_stack_frame () { delete m_unwind_protect_frame; } - bool is_user_script_frame (void) const { return true; } + bool is_user_script_frame () const { return true; } static std::shared_ptr get_access_link (const std::shared_ptr& static_link); static std::size_t get_num_symbols (octave_user_script *script); - void set_script_offsets (void); + void set_script_offsets (); void set_script_offsets_internal (const std::map& symbols); void resize_and_update_script_offsets (const symbol_record& sym); - symbol_scope get_scope (void) const { return m_script->scope (); } - - octave_function * function (void) const { return m_script; } - - unwind_protect * unwind_protect_frame (void); + symbol_scope get_scope () const { return m_script->scope (); } + + octave_function * function () const { return m_script; } + + unwind_protect * unwind_protect_frame (); symbol_record lookup_symbol (const std::string& name) const; symbol_record insert_symbol (const std::string&); - std::size_t size (void) const { return m_lexical_frame_offsets.size (); } + std::size_t size () const { return m_lexical_frame_offsets.size (); } void resize (std::size_t size) { @@ -288,7 +288,7 @@ { public: - base_value_stack_frame (void) = delete; + base_value_stack_frame () = delete; base_value_stack_frame (tree_evaluator& tw, std::size_t num_symbols, std::size_t index, @@ -306,9 +306,9 @@ base_value_stack_frame& operator = (const base_value_stack_frame& elt) = delete; - ~base_value_stack_frame (void) = default; - - std::size_t size (void) const + ~base_value_stack_frame () = default; + + std::size_t size () const { return m_values.size (); } @@ -394,7 +394,7 @@ { public: - user_fcn_stack_frame (void) = delete; + user_fcn_stack_frame () = delete; user_fcn_stack_frame (tree_evaluator& tw, octave_user_function *fcn, std::size_t index, @@ -433,12 +433,12 @@ user_fcn_stack_frame& operator = (const user_fcn_stack_frame& elt) = delete; - ~user_fcn_stack_frame (void) + ~user_fcn_stack_frame () { delete m_unwind_protect_frame; } - bool is_user_fcn_frame (void) const { return true; } + bool is_user_fcn_frame () const { return true; } static std::shared_ptr get_access_link (octave_user_function *fcn, @@ -451,13 +451,13 @@ return fcn_scope.num_symbols (); } - void clear_values (void); - - symbol_scope get_scope (void) const { return m_fcn->scope (); } - - octave_function * function (void) const { return m_fcn; } - - unwind_protect * unwind_protect_frame (void); + void clear_values (); + + symbol_scope get_scope () const { return m_fcn->scope (); } + + octave_function * function () const { return m_fcn; } + + unwind_protect * unwind_protect_frame (); symbol_record lookup_symbol (const std::string& name) const; @@ -505,7 +505,7 @@ { public: - scope_stack_frame (void) = delete; + scope_stack_frame () = delete; scope_stack_frame (tree_evaluator& tw, const symbol_scope& scope, std::size_t index, @@ -520,11 +520,11 @@ scope_stack_frame& operator = (const scope_stack_frame& elt) = delete; - ~scope_stack_frame (void) = default; - - bool is_scope_frame (void) const { return true; } - - symbol_scope get_scope (void) const { return m_scope; } + ~scope_stack_frame () = default; + + bool is_scope_frame () const { return true; } + + symbol_scope get_scope () const { return m_scope; } symbol_record lookup_symbol (const std::string& name) const { @@ -588,9 +588,9 @@ { protected: - stack_frame_walker (void) { } - - virtual ~stack_frame_walker (void) = default; + stack_frame_walker () { } + + virtual ~stack_frame_walker () = default; public: @@ -639,7 +639,7 @@ symbol_cleaner& operator = (const symbol_cleaner&) = delete; - ~symbol_cleaner (void) = default; + ~symbol_cleaner () = default; void visit_compiled_fcn_stack_frame (compiled_fcn_stack_frame& frame) { @@ -800,9 +800,9 @@ symbol_info_accumulator& operator = (const symbol_info_accumulator&) = delete; - ~symbol_info_accumulator (void) = default; - - bool is_empty (void) const + ~symbol_info_accumulator () = default; + + bool is_empty () const { for (const auto& nm_sil : m_sym_inf_list) { @@ -815,7 +815,7 @@ return true; } - std::list names (void) const + std::list names () const { std::list retval; @@ -832,7 +832,7 @@ return retval; } - symbol_info_list symbol_info (void) const + symbol_info_list symbol_info () const { symbol_info_list retval; @@ -847,7 +847,7 @@ return retval; } - octave_map map_value (void) const + octave_map map_value () const { octave_map retval; @@ -1089,7 +1089,7 @@ // user_fcn stack frames. Anything else indicates an error in the // implementation, but we'll simply warn if that happens. -void stack_frame::clear_values (void) +void stack_frame::clear_values () { warning ("invalid call to stack_frame::clear_values; please report"); } @@ -1158,7 +1158,7 @@ // Return first occurrence of variables in current stack frame and any // parent frames reachable through access links. -symbol_info_list stack_frame::all_variables (void) +symbol_info_list stack_frame::all_variables () { symbol_info_accumulator sia (true, true); @@ -1167,7 +1167,7 @@ return sia.symbol_info (); } -octave_value stack_frame::workspace (void) +octave_value stack_frame::workspace () { std::list ws_list; @@ -1205,7 +1205,7 @@ // FIXME: Should this function also find any variables in parent // scopes accessible through access_links? -std::list stack_frame::variable_names (void) const +std::list stack_frame::variable_names () const { std::list retval; @@ -1242,7 +1242,7 @@ return sia.symbol_info (); } -std::size_t stack_frame::size (void) const +std::size_t stack_frame::size () const { // This function should only be called for user_fcn_stack_frame or // scope_stack_frame objects. Anything else indicates an error in @@ -1342,7 +1342,7 @@ panic_impossible (); } -void stack_frame::clear_objects (void) +void stack_frame::clear_objects () { symbol_cleaner sc (true, true); @@ -1384,7 +1384,7 @@ accept (sc); } -void stack_frame::clear_variables (void) +void stack_frame::clear_variables () { symbol_cleaner sc; @@ -1491,7 +1491,7 @@ return script_scope.num_symbols (); } -void script_stack_frame::set_script_offsets (void) +void script_stack_frame::set_script_offsets () { // Set frame and data offsets inside stack frame based on enclosing // scope(s). @@ -1639,7 +1639,7 @@ return alink; } -unwind_protect *script_stack_frame::unwind_protect_frame (void) +unwind_protect *script_stack_frame::unwind_protect_frame () { if (! m_unwind_protect_frame) m_unwind_protect_frame = new unwind_protect (); @@ -2131,7 +2131,7 @@ return alink; } -void user_fcn_stack_frame::clear_values (void) +void user_fcn_stack_frame::clear_values () { symbol_scope fcn_scope = m_fcn->scope (); @@ -2165,7 +2165,7 @@ } } -unwind_protect *user_fcn_stack_frame::unwind_protect_frame (void) +unwind_protect *user_fcn_stack_frame::unwind_protect_frame () { if (! m_unwind_protect_frame) m_unwind_protect_frame = new unwind_protect (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/stack-frame.h --- a/libinterp/corefcn/stack-frame.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/stack-frame.h Mon Jan 30 18:36:03 2023 +0100 @@ -137,7 +137,7 @@ NUM_AUTO_VARS }; - stack_frame (void) = delete; + stack_frame () = delete; stack_frame (tree_evaluator& tw, std::size_t index, const std::shared_ptr& parent_link, @@ -186,28 +186,28 @@ stack_frame& operator = (const stack_frame& elt) = delete; - virtual ~stack_frame (void) = default; + virtual ~stack_frame () = default; // FIXME: It would be nice to eliminate these but there are a few // places where we still need to know the specific type of the // stack frame that we are handling. - virtual bool is_compiled_fcn_frame (void) const { return false; } - virtual bool is_user_script_frame (void) const { return false; } - virtual bool is_user_fcn_frame (void) const { return false; } - virtual bool is_scope_frame (void) const { return false; } + virtual bool is_compiled_fcn_frame () const { return false; } + virtual bool is_user_script_frame () const { return false; } + virtual bool is_user_fcn_frame () const { return false; } + virtual bool is_scope_frame () const { return false; } - virtual void clear_values (void); + virtual void clear_values (); - std::size_t index (void) const { return m_index; } + std::size_t index () const { return m_index; } void line (int l) { m_line = l; } - int line (void) const { return m_line; } + int line () const { return m_line; } void column (int c) { m_column = c; } - int column (void) const { return m_column; } + int column () const { return m_column; } - std::string fcn_file_name (void) const + std::string fcn_file_name () const { octave_function *fcn = function (); @@ -238,11 +238,11 @@ return retval; } - virtual symbol_scope get_scope (void) const = 0; + virtual symbol_scope get_scope () const = 0; - virtual octave_function * function (void) const { return nullptr; } + virtual octave_function * function () const { return nullptr; } - virtual unwind_protect * unwind_protect_frame (void) { return nullptr; } + virtual unwind_protect * unwind_protect_frame () { return nullptr; } symbol_info_list make_symbol_info_list (const std::list& symrec_list) const; @@ -252,11 +252,11 @@ const std::string& whos_line_fmt, const std::string& msg); - symbol_info_list all_variables (void); + symbol_info_list all_variables (); - octave_value workspace (void); + octave_value workspace (); - std::list variable_names (void) const; + std::list variable_names () const; // Look for named symbol visible from current scope. Don't // attempt to insert if missing. @@ -270,7 +270,7 @@ symbol_info_list regexp_symbol_info (const std::string& pattern); - symbol_info_list get_symbol_info (void) + symbol_info_list get_symbol_info () { return all_variables (); } @@ -308,15 +308,15 @@ } std::shared_ptr - parent_link (void) const {return m_parent_link; } + parent_link () const {return m_parent_link; } std::shared_ptr - static_link (void) const {return m_static_link; } + static_link () const {return m_static_link; } std::shared_ptr - access_link (void) const {return m_access_link; } + access_link () const {return m_access_link; } - virtual std::size_t size (void) const; + virtual std::size_t size () const; virtual void resize (std::size_t); @@ -525,7 +525,7 @@ unmark_persistent (sym); } - void clear_objects (void); + void clear_objects (); void clear_variable (const std::string& name); @@ -535,9 +535,9 @@ void clear_variable_regexp (const std::string& pattern); void clear_variable_regexp (const string_vector& patterns); - void clear_variables (void); + void clear_variables (); - std::string get_dispatch_class (void) const { return m_dispatch_class; } + std::string get_dispatch_class () const { return m_dispatch_class; } void set_dispatch_class (const std::string& class_name) { @@ -554,8 +554,8 @@ virtual void break_closure_cycles (const std::shared_ptr&) { } - void mark_closure_context (void) { m_is_closure_context = true; } - bool is_closure_context (void) const { return m_is_closure_context; } + void mark_closure_context () { m_is_closure_context = true; } + bool is_closure_context () const { return m_is_closure_context; } protected: diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/strfns.cc --- a/libinterp/corefcn/strfns.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/strfns.cc Mon Jan 30 18:36:03 2023 +0100 @@ -1219,8 +1219,7 @@ if (nargin < 1 || nargin > 3) print_usage (); - string_vector s = args( - 0).xstring_vector_value ("list_in_columns: ARG must be a cellstr or char array"); + string_vector s = args(0).xstring_vector_value ("list_in_columns: ARG must be a cellstr or char array"); int width = -1; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/svd.cc --- a/libinterp/corefcn/svd.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/svd.cc Mon Jan 30 18:36:03 2023 +0100 @@ -62,7 +62,7 @@ template static typename math::svd::Driver -svd_driver (void) +svd_driver () { if (Vsvd_driver == "gejsv") return math::svd::Driver::GEJSV; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/syminfo.cc --- a/libinterp/corefcn/syminfo.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/syminfo.cc Mon Jan 30 18:36:03 2023 +0100 @@ -177,7 +177,7 @@ return octave_value (); } -std::list symbol_info_list::names (void) const +std::list symbol_info_list::names () const { std::list retval; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/syminfo.h --- a/libinterp/corefcn/syminfo.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/syminfo.h Mon Jan 30 18:36:03 2023 +0100 @@ -63,19 +63,19 @@ m_is_global (is_global), m_is_persistent (is_persistent) { } - std::string name (void) const { return m_name; } + std::string name () const { return m_name; } - octave_value value (void) const { return m_value; } + octave_value value () const { return m_value; } - bool is_complex (void) const { return m_is_complex; } + bool is_complex () const { return m_is_complex; } - bool is_sparse (void) const { return m_is_sparse; } + bool is_sparse () const { return m_is_sparse; } - bool is_formal (void) const { return m_is_formal; } + bool is_formal () const { return m_is_formal; } - bool is_global (void) const { return m_is_global; } + bool is_global () const { return m_is_global; } - bool is_persistent (void) const { return m_is_persistent; } + bool is_persistent () const { return m_is_persistent; } void display_line (std::ostream& os, const std::list& params) const; @@ -96,17 +96,17 @@ { public: - symbol_info_list (void) = default; + symbol_info_list () = default; symbol_info_list (const symbol_info_list&) = default; symbol_info_list& operator = (const symbol_info_list&) = default; - ~symbol_info_list (void) = default; + ~symbol_info_list () = default; octave_value varval (const std::string& name) const; - std::list names (void) const; + std::list names () const; octave_map map_value (const std::string& caller_function_name, int nesting_level) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/symrec.cc --- a/libinterp/corefcn/symrec.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/symrec.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,13 +42,13 @@ OCTAVE_BEGIN_NAMESPACE(octave) std::shared_ptr -symbol_record::symbol_record_rep::dup (void) const +symbol_record::symbol_record_rep::dup () const { return std::shared_ptr (new symbol_record_rep (*this)); } octave_value -symbol_record::symbol_record_rep::dump (void) const +symbol_record::symbol_record_rep::dump () const { std::map m = {{ "frame_offset", m_frame_offset }, diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/symrec.h --- a/libinterp/corefcn/symrec.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/symrec.h Mon Jan 30 18:36:03 2023 +0100 @@ -76,90 +76,90 @@ symbol_record_rep& operator = (const symbol_record_rep&) = default; - ~symbol_record_rep (void) = default; + ~symbol_record_rep () = default; // FIXME: use special storage class instead? - bool is_valid (void) const { return ! m_name.empty (); } + bool is_valid () const { return ! m_name.empty (); } void set_frame_offset (std::size_t offset) { m_frame_offset = offset; } - std::size_t frame_offset (void) const { return m_frame_offset; } + std::size_t frame_offset () const { return m_frame_offset; } void set_data_offset (std::size_t offset) { m_data_offset = offset; } - std::size_t data_offset (void) const { return m_data_offset; } + std::size_t data_offset () const { return m_data_offset; } - bool is_local (void) const + bool is_local () const { return m_storage_class & LOCAL; } - bool is_formal (void) const + bool is_formal () const { return m_storage_class & FORMAL; } - bool is_added_static (void) const + bool is_added_static () const { return m_storage_class & ADDED_STATIC; } - bool is_variable (void) const + bool is_variable () const { return m_storage_class & VARIABLE; } - void mark_local (void) + void mark_local () { m_storage_class = static_cast (m_storage_class | LOCAL); } - void mark_formal (void) + void mark_formal () { // Formal parameters are also variables. m_storage_class = static_cast (m_storage_class | FORMAL | VARIABLE); } - void mark_added_static (void) + void mark_added_static () { m_storage_class = static_cast (m_storage_class | ADDED_STATIC); } - void mark_as_variable (void) + void mark_as_variable () { m_storage_class = static_cast (m_storage_class | VARIABLE); } - void unmark_local (void) + void unmark_local () { m_storage_class = static_cast (m_storage_class & ~LOCAL); } - void unmark_formal (void) + void unmark_formal () { m_storage_class = static_cast (m_storage_class & ~FORMAL); } - void unmark_added_static (void) + void unmark_added_static () { m_storage_class = static_cast (m_storage_class & ~ADDED_STATIC); } - void unmark_as_variable (void) + void unmark_as_variable () { m_storage_class = static_cast (m_storage_class & ~VARIABLE); } - unsigned int storage_class (void) const { return m_storage_class; } + unsigned int storage_class () const { return m_storage_class; } - std::shared_ptr dup (void) const; + std::shared_ptr dup () const; - octave_value dump (void) const; + octave_value dump () const; - std::string name (void) const { return m_name; } + std::string name () const { return m_name; } void rename (const std::string& new_name) { m_name = new_name; } @@ -188,46 +188,46 @@ symbol_record& operator = (const symbol_record&) = default; - ~symbol_record (void) = default; + ~symbol_record () = default; - bool is_valid (void) const { return m_rep->is_valid (); } + bool is_valid () const { return m_rep->is_valid (); } explicit operator bool () const { return is_valid (); } void set_frame_offset (std::size_t offset) { m_rep->set_frame_offset (offset); } - std::size_t frame_offset (void) const { return m_rep->frame_offset (); } + std::size_t frame_offset () const { return m_rep->frame_offset (); } void set_data_offset (std::size_t offset) { m_rep->set_data_offset (offset); } - std::size_t data_offset (void) const { return m_rep->data_offset (); } + std::size_t data_offset () const { return m_rep->data_offset (); } - symbol_record dup (void) const { return symbol_record (m_rep->dup ()); } + symbol_record dup () const { return symbol_record (m_rep->dup ()); } - std::string name (void) const { return m_rep->name (); } + std::string name () const { return m_rep->name (); } void rename (const std::string& new_name) { m_rep->rename (new_name); } - bool is_local (void) const { return m_rep->is_local (); } - bool is_formal (void) const { return m_rep->is_formal (); } - bool is_added_static (void) const { return m_rep->is_added_static (); } - bool is_variable (void) const { return m_rep->is_variable (); } + bool is_local () const { return m_rep->is_local (); } + bool is_formal () const { return m_rep->is_formal (); } + bool is_added_static () const { return m_rep->is_added_static (); } + bool is_variable () const { return m_rep->is_variable (); } - void mark_local (void) { m_rep->mark_local (); } - void mark_formal (void) { m_rep->mark_formal (); } - void mark_added_static (void) { m_rep->mark_added_static (); } - void mark_as_variable (void) { m_rep->mark_as_variable (); } + void mark_local () { m_rep->mark_local (); } + void mark_formal () { m_rep->mark_formal (); } + void mark_added_static () { m_rep->mark_added_static (); } + void mark_as_variable () { m_rep->mark_as_variable (); } - void unmark_local (void) { m_rep->unmark_local (); } - void unmark_formal (void) { m_rep->unmark_formal (); } - void unmark_added_static (void) { m_rep->unmark_added_static (); } - void unmark_as_variable (void) { m_rep->unmark_as_variable (); } + void unmark_local () { m_rep->unmark_local (); } + void unmark_formal () { m_rep->unmark_formal (); } + void unmark_added_static () { m_rep->unmark_added_static (); } + void unmark_as_variable () { m_rep->unmark_as_variable (); } - unsigned int storage_class (void) const { return m_rep->storage_class (); } + unsigned int storage_class () const { return m_rep->storage_class (); } - octave_value dump (void) const { return m_rep->dump (); } + octave_value dump () const { return m_rep->dump (); } private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/symscope.cc --- a/libinterp/corefcn/symscope.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/symscope.cc Mon Jan 30 18:36:03 2023 +0100 @@ -92,7 +92,7 @@ return p->second; } -std::list symbol_scope_rep::localfunctions (void) const +std::list symbol_scope_rep::localfunctions () const { std::list retval; @@ -130,7 +130,7 @@ } octave_value -symbol_scope_rep::dump (void) const +symbol_scope_rep::dump () const { std::map m = {{ "name", m_name }, @@ -145,7 +145,7 @@ } octave_value -symbol_scope_rep::dump_symbols_map (void) const +symbol_scope_rep::dump_symbols_map () const { std::map info_map; @@ -159,7 +159,7 @@ return octave_value (info_map); } -std::list symbol_scope_rep::symbol_list (void) const +std::list symbol_scope_rep::symbol_list () const { std::list retval; @@ -198,7 +198,7 @@ } std::list -symbol_scope_rep::parent_fcn_names (void) const +symbol_scope_rep::parent_fcn_names () const { std::list retval; @@ -304,7 +304,7 @@ return false; } -void symbol_scope_rep::update_nest (void) +void symbol_scope_rep::update_nest () { auto t_parent = m_parent.lock (); @@ -370,7 +370,7 @@ return false; } -std::list symbol_scope::localfunctions (void) const +std::list symbol_scope::localfunctions () const { if (! m_rep) return std::list (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/symscope.h --- a/libinterp/corefcn/symscope.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/symscope.h Mon Jan 30 18:36:03 2023 +0100 @@ -83,9 +83,9 @@ symbol_scope_rep& operator = (const symbol_scope&) = delete; - ~symbol_scope_rep (void) = default; + ~symbol_scope_rep () = default; - std::size_t num_symbols (void) const { return m_symbols.size (); } + std::size_t num_symbols () const { return m_symbols.size (); } // Simply inserts symbol. No non-local searching. @@ -93,29 +93,29 @@ void insert_symbol_record (symbol_record& sr); - bool is_nested (void) const { return m_nesting_depth > 0; } + bool is_nested () const { return m_nesting_depth > 0; } - std::size_t nesting_depth (void) const { return m_nesting_depth; } + std::size_t nesting_depth () const { return m_nesting_depth; } void set_nesting_depth (std::size_t depth) { m_nesting_depth = depth; } - bool is_parent (void) const { return ! m_children.empty (); } + bool is_parent () const { return ! m_children.empty (); } - bool is_static (void) const { return m_is_static; } + bool is_static () const { return m_is_static; } - void mark_static (void) { m_is_static = true; } + void mark_static () { m_is_static = true; } - std::shared_ptr parent_scope_rep (void) const + std::shared_ptr parent_scope_rep () const { return m_parent.lock (); } - std::shared_ptr primary_parent_scope_rep (void) const + std::shared_ptr primary_parent_scope_rep () const { return m_primary_parent.lock (); } - std::shared_ptr dup (void) const + std::shared_ptr dup () const { std::shared_ptr new_sid = std::shared_ptr (new symbol_scope_rep (m_name)); @@ -204,32 +204,32 @@ octave_value find_subfunction (const std::string& name) const; - void lock_subfunctions (void) + void lock_subfunctions () { for (auto& nm_sf : m_subfunctions) nm_sf.second.lock (); } - void unlock_subfunctions (void) + void unlock_subfunctions () { for (auto& nm_sf : m_subfunctions) nm_sf.second.unlock (); } // Pairs of name, function objects. - std::map subfunctions (void) const + std::map subfunctions () const { return m_subfunctions; } - void erase_subfunctions (void) + void erase_subfunctions () { m_subfunctions.clear (); } void mark_subfunctions_in_scope_as_private (const std::string& class_name); - bool has_subfunctions (void) const + bool has_subfunctions () const { return ! m_subfunction_names.empty (); } @@ -239,26 +239,26 @@ m_subfunction_names = names; } - std::list subfunction_names (void) const + std::list subfunction_names () const { return m_subfunction_names; } - std::list localfunctions (void) const; + std::list localfunctions () const; - octave_value dump (void) const; + octave_value dump () const; - std::string name (void) const { return m_name; } + std::string name () const { return m_name; } void cache_name (const std::string& name) { m_name = name; } - std::string fcn_name (void) const { return m_fcn_name; } + std::string fcn_name () const { return m_fcn_name; } void cache_fcn_name (const std::string& name) { m_fcn_name = name; } - std::list parent_fcn_names (void) const; + std::list parent_fcn_names () const; - octave_user_code * user_code (void) const { return m_code; } + octave_user_code * user_code () const { return m_code; } void set_user_code (octave_user_code *code) { m_code = code; } @@ -271,15 +271,15 @@ m_fcn_file_name = name; } - std::string fcn_file_name (void) const { return m_fcn_file_name; } + std::string fcn_file_name () const { return m_fcn_file_name; } void cache_dir_name (const std::string& name); - std::string dir_name (void) const { return m_dir_name; } + std::string dir_name () const { return m_dir_name; } - void mark_primary_fcn_scope (void) { m_is_primary_fcn_scope = true; } + void mark_primary_fcn_scope () { m_is_primary_fcn_scope = true; } - bool is_primary_fcn_scope (void) const { return m_is_primary_fcn_scope; } + bool is_primary_fcn_scope () const { return m_is_primary_fcn_scope; } bool is_relative (const std::shared_ptr& scope) const; @@ -288,24 +288,24 @@ bool is_variable (const std::string& nm) const; - void update_nest (void); + void update_nest (); bool look_nonlocal (const std::string& name, std::size_t offset, symbol_record& result); - octave_value dump_symbols_map (void) const; + octave_value dump_symbols_map () const; - const std::map& symbols (void) const + const std::map& symbols () const { return m_symbols; } - std::map& symbols (void) + std::map& symbols () { return m_symbols; } - std::list symbol_list (void) const; + std::list symbol_list () const; private: @@ -390,13 +390,13 @@ symbol_scope& operator = (const symbol_scope&) = default; - ~symbol_scope (void) = default; + ~symbol_scope () = default; - bool is_valid (void) const { return bool (m_rep); } + bool is_valid () const { return bool (m_rep); } explicit operator bool () const { return bool (m_rep); } - std::size_t num_symbols (void) const + std::size_t num_symbols () const { return m_rep ? m_rep->num_symbols () : 0; } @@ -412,12 +412,12 @@ m_rep->insert_symbol_record (sr); } - bool is_nested (void) const + bool is_nested () const { return m_rep ? m_rep->is_nested () : false; } - bool is_parent (void) const + bool is_parent () const { return m_rep ? m_rep->is_parent () : false; } @@ -428,33 +428,33 @@ m_rep->set_nesting_depth (depth); } - std::size_t nesting_depth (void) const + std::size_t nesting_depth () const { return m_rep ? m_rep->nesting_depth () : 0; } - bool is_static (void) const + bool is_static () const { return m_rep ? m_rep->is_static () : false; } - void mark_static (void) + void mark_static () { if (m_rep) m_rep->mark_static (); } - std::shared_ptr parent_scope (void) const + std::shared_ptr parent_scope () const { return m_rep ? m_rep->parent_scope_rep () : nullptr; } - std::shared_ptr primary_parent_scope (void) const + std::shared_ptr primary_parent_scope () const { return m_rep ? m_rep->primary_parent_scope_rep () : nullptr; } - symbol_scope dup (void) const + symbol_scope dup () const { return symbol_scope (m_rep ? m_rep->dup () : nullptr); } @@ -513,26 +513,26 @@ return m_rep ? m_rep->find_subfunction (name) : octave_value (); } - void lock_subfunctions (void) + void lock_subfunctions () { if (m_rep) m_rep->lock_subfunctions (); } - void unlock_subfunctions (void) + void unlock_subfunctions () { if (m_rep) m_rep->unlock_subfunctions (); } - std::map subfunctions (void) const + std::map subfunctions () const { return (m_rep ? m_rep->subfunctions () : std::map ()); } - void erase_subfunctions (void) + void erase_subfunctions () { if (m_rep) m_rep->erase_subfunctions (); @@ -544,7 +544,7 @@ m_rep->mark_subfunctions_in_scope_as_private (class_name); } - bool has_subfunctions (void) const + bool has_subfunctions () const { return m_rep ? m_rep->has_subfunctions () : false; } @@ -555,20 +555,20 @@ m_rep->stash_subfunction_names (names); } - std::list subfunction_names (void) const + std::list subfunction_names () const { return m_rep ? m_rep->subfunction_names () : std::list (); } // List of function handle objects. - std::list localfunctions (void) const; + std::list localfunctions () const; - octave_value dump (void) const + octave_value dump () const { return m_rep ? m_rep->dump () : octave_value (); } - std::string name (void) const + std::string name () const { return m_rep ? m_rep->name () : ""; } @@ -579,7 +579,7 @@ m_rep->cache_name (name); } - std::string fcn_name (void) const + std::string fcn_name () const { return m_rep ? m_rep->fcn_name () : ""; } @@ -590,12 +590,12 @@ m_rep->cache_fcn_name (name); } - std::list parent_fcn_names (void) const + std::list parent_fcn_names () const { return m_rep ? m_rep->parent_fcn_names () : std::list (); } - octave_user_code * user_code (void) const + octave_user_code * user_code () const { return m_rep ? m_rep->user_code () : nullptr; } @@ -630,23 +630,23 @@ m_rep->cache_dir_name (name); } - std::string fcn_file_name (void) const + std::string fcn_file_name () const { return m_rep ? m_rep->fcn_file_name () : ""; } - std::string dir_name (void) const + std::string dir_name () const { return m_rep ? m_rep->dir_name () : ""; } - void mark_primary_fcn_scope (void) + void mark_primary_fcn_scope () { if (m_rep) m_rep->mark_primary_fcn_scope (); } - bool is_primary_fcn_scope (void) const + bool is_primary_fcn_scope () const { return m_rep ? m_rep->is_primary_fcn_scope () : false; } @@ -673,7 +673,7 @@ return m_rep ? m_rep->is_variable (nm) : false; } - void update_nest (void) + void update_nest () { if (m_rep) m_rep->update_nest (); @@ -685,7 +685,7 @@ return m_rep ? m_rep->look_nonlocal (name, offset, result) : false; } - std::shared_ptr get_rep (void) const + std::shared_ptr get_rep () const { return m_rep; } @@ -700,21 +700,21 @@ return a.m_rep != b.m_rep; } - const std::map& symbols (void) const + const std::map& symbols () const { static const std::map empty_map; return m_rep ? m_rep->symbols () : empty_map; } - std::map& symbols (void) + std::map& symbols () { static std::map empty_map; return m_rep ? m_rep->symbols () : empty_map; } - std::list symbol_list (void) const + std::list symbol_list () const { static const std::list empty_list; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/symtab.cc --- a/libinterp/corefcn/symtab.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/symtab.cc Mon Jan 30 18:36:03 2023 +0100 @@ -57,7 +57,7 @@ install_builtins (); } -symbol_scope symbol_table::current_scope (void) const +symbol_scope symbol_table::current_scope () const { tree_evaluator& tw = m_interpreter.get_evaluator (); @@ -495,7 +495,7 @@ } } -void symbol_table::clear_mex_functions (void) +void symbol_table::clear_mex_functions () { auto p = m_fcn_table.begin (); @@ -578,7 +578,7 @@ error ("install_built_in_dispatch: '%s' is undefined", name.c_str ()); } -std::list symbol_table::user_function_names (void) +std::list symbol_table::user_function_names () { std::list retval; @@ -594,7 +594,7 @@ return retval; } -std::list symbol_table::built_in_function_names (void) +std::list symbol_table::built_in_function_names () { std::list retval; @@ -612,7 +612,7 @@ return retval; } -std::list symbol_table::cmdline_function_names (void) +std::list symbol_table::cmdline_function_names () { std::list retval; @@ -650,7 +650,7 @@ return octave_value (info_map); } -octave_value symbol_table::dump (void) const +octave_value symbol_table::dump () const { std::map m = {{ "function_info", dump_fcn_table_map () }, @@ -691,7 +691,7 @@ return retval; } -void symbol_table::cleanup (void) +void symbol_table::cleanup () { clear_functions (); @@ -706,7 +706,7 @@ return p != m_fcn_table.end () ? &p->second : nullptr; } -octave_value symbol_table::dump_fcn_table_map (void) const +octave_value symbol_table::dump_fcn_table_map () const { if (m_fcn_table.empty ()) return octave_value (Matrix ()); @@ -741,8 +741,7 @@ return symtab.dump (); else { - std::string fname = args( - 0).xstring_value ("__dump_symtab_info__: argument must be a function name"); + std::string fname = args(0).xstring_value ("__dump_symtab_info__: argument must be a function name"); fcn_info *finfo = symtab.get_fcn_info (fname); @@ -762,8 +761,7 @@ if (args.length () != 1) print_usage (); - std::string name = args( - 0).xstring_value ("__get_cmdline_fcn_txt__: first argument must be function name"); + std::string name = args(0).xstring_value ("__get_cmdline_fcn_txt__: first argument must be function name"); symbol_table& symtab = interp.get_symbol_table (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/symtab.h --- a/libinterp/corefcn/symtab.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/symtab.h Mon Jan 30 18:36:03 2023 +0100 @@ -66,9 +66,9 @@ symbol_table& operator = (const symbol_table&) = delete; - ~symbol_table (void) = default; + ~symbol_table () = default; - symbol_scope current_scope (void) const; + symbol_scope current_scope () const; bool is_built_in_function_name (const std::string& name); @@ -155,7 +155,7 @@ // This clears oct and mex files, including autoloads. void clear_dld_function (const std::string& name); - void clear_mex_functions (void); + void clear_mex_functions (); bool set_class_relationship (const std::string& sup_class, const std::string& inf_class); @@ -168,20 +168,20 @@ void install_built_in_dispatch (const std::string& name, const std::string& klass); - std::list user_function_names (void); + std::list user_function_names (); - std::list built_in_function_names (void); + std::list built_in_function_names (); - std::list cmdline_function_names (void); + std::list cmdline_function_names (); - octave_value dump (void) const; + octave_value dump () const; void add_to_parent_map (const std::string& classname, const std::list& parent_list); std::list parent_classes (const std::string& dispatch_type); - void cleanup (void); + void cleanup (); fcn_info * get_fcn_info (const std::string& name); @@ -222,10 +222,10 @@ typedef std::map>::iterator parent_map_iterator; - octave_value dump_fcn_table_map (void) const; + octave_value dump_fcn_table_map () const; // This function is generated automatically by mk-builtins.pl. - void install_builtins (void); + void install_builtins (); }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/sysdep.cc --- a/libinterp/corefcn/sysdep.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/sysdep.cc Mon Jan 30 18:36:03 2023 +0100 @@ -108,7 +108,7 @@ #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) static void -BSD_init (void) +BSD_init () { # if defined (HAVE_FLOATINGPOINT_H) // Disable trapping on common exceptions. @@ -124,7 +124,7 @@ #if defined (__MINGW32__) || defined (_MSC_VER) static void -w32_set_octave_home (void) +w32_set_octave_home () { std::string bin_dir; @@ -171,7 +171,7 @@ } static void -w32_init (void) +w32_init () { w32_set_octave_home (); @@ -180,7 +180,7 @@ #endif -void set_application_id (void) +void set_application_id () { #if defined (__MINGW32__) || defined (_MSC_VER) @@ -363,7 +363,7 @@ #if defined (__MINGW32__) static void -MINGW_init (void) +MINGW_init () { w32_init (); } @@ -373,7 +373,7 @@ #if defined (_MSC_VER) static void -MSVC_init (void) +MSVC_init () { w32_init (); } @@ -506,7 +506,7 @@ #endif } -void sysdep_init (void) +void sysdep_init () { // Use a function from libgomp to force loading of OpenMP library. // Otherwise, a dynamically loaded library making use of OpenMP such @@ -524,7 +524,7 @@ #endif } -void sysdep_cleanup (void) +void sysdep_cleanup () { #if defined (OCTAVE_USE_WINDOWS_API) // Let us fail immediately without displaying any dialog. @@ -763,7 +763,7 @@ return c; } -std::string get_P_tmpdir (void) +std::string get_P_tmpdir () { #if defined (OCTAVE_USE_WINDOWS_API) diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/sysdep.h --- a/libinterp/corefcn/sysdep.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/sysdep.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,11 +37,11 @@ OCTAVE_BEGIN_NAMESPACE(octave) -extern OCTINTERP_API void sysdep_init (void); +extern OCTINTERP_API void sysdep_init (); -extern OCTINTERP_API void set_application_id (void); +extern OCTINTERP_API void set_application_id (); -extern OCTINTERP_API void sysdep_cleanup (void); +extern OCTINTERP_API void sysdep_cleanup (); extern OCTINTERP_API void raw_mode (bool, bool wait = true); @@ -51,7 +51,7 @@ extern OCTINTERP_API int kbhit (bool wait = true); -extern OCTINTERP_API std::string get_P_tmpdir (void); +extern OCTINTERP_API std::string get_P_tmpdir (); extern OCTINTERP_API bool same_file_internal (const std::string&, const std::string&); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/text-engine.cc --- a/libinterp/corefcn/text-engine.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/text-engine.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,7 +33,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) uint32_t -text_element_symbol::get_symbol_code (void) const +text_element_symbol::get_symbol_code () const { uint32_t code = invalid_code; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/text-engine.h --- a/libinterp/corefcn/text-engine.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/text-engine.h Mon Jan 30 18:36:03 2023 +0100 @@ -56,9 +56,9 @@ text_element { public: - text_element (void) { } + text_element () { } - virtual ~text_element (void) = default; + virtual ~text_element () = default; virtual void accept (text_processor& p) = 0; @@ -74,9 +74,9 @@ text_element_string (const std::string& s = "") : text_element (), m_str (s) { } - ~text_element_string (void) = default; + ~text_element_string () = default; - std::string string_value (void) const { return m_str; } + std::string string_value () const { return m_str; } void accept (text_processor& p); @@ -98,11 +98,11 @@ text_element_symbol (int sym) : text_element (), m_symbol (sym) { } - ~text_element_symbol (void) = default; + ~text_element_symbol () = default; - int get_symbol (void) const { return m_symbol; } + int get_symbol () const { return m_symbol; } - uint32_t get_symbol_code (void) const; + uint32_t get_symbol_code () const; void accept (text_processor& p); @@ -116,7 +116,7 @@ : public text_element, public base_list { public: - text_element_list (void) + text_element_list () : text_element (), base_list () { } text_element_list (text_element *e) @@ -125,7 +125,7 @@ push_back (e); } - ~text_element_list (void) + ~text_element_list () { while (! empty ()) { @@ -150,15 +150,15 @@ : text_element () { m_elem = new text_element_string (std::string (1, c)); } - ~text_element_subscript (void) + ~text_element_subscript () { delete m_elem; } void accept (text_processor& p); - text_element * get_element (void) { return m_elem; } + text_element * get_element () { return m_elem; } private: - text_element_subscript (void); + text_element_subscript (); //-------- @@ -178,15 +178,15 @@ : text_element () { m_elem = new text_element_string (std::string (1, c)); } - ~text_element_superscript (void) + ~text_element_superscript () { delete m_elem; } void accept (text_processor& p); - text_element * get_element (void) { return m_elem; } + text_element * get_element () { return m_elem; } private: - text_element_superscript (void); + text_element_superscript (); //-------- @@ -225,14 +225,14 @@ text_element_fontstyle (fontstyle st) : text_element (), m_style (st) { } - ~text_element_fontstyle (void) = default; + ~text_element_fontstyle () = default; - fontstyle get_fontstyle (void) const { return m_style; } + fontstyle get_fontstyle () const { return m_style; } void accept (text_processor& p); private: - text_element_fontstyle (void); + text_element_fontstyle (); //-------- @@ -248,14 +248,14 @@ text_element_fontname (const std::string& fname) : text_element (), m_name (fname) { } - ~text_element_fontname (void) = default; + ~text_element_fontname () = default; - const std::string& get_fontname (void) const { return m_name; } + const std::string& get_fontname () const { return m_name; } void accept (text_processor& p); private: - text_element_fontname (void); + text_element_fontname (); //-------- @@ -271,14 +271,14 @@ text_element_fontsize (double fsize) : text_element (), m_size (fsize) { } - ~text_element_fontsize (void) = default; + ~text_element_fontsize () = default; - double get_fontsize (void) const { return m_size; } + double get_fontsize () const { return m_size; } void accept (text_processor& p); private: - text_element_fontsize (void); + text_element_fontsize (); //-------- @@ -317,9 +317,9 @@ #undef ASSIGN_COLOR } - ~text_element_color (void) = default; + ~text_element_color () = default; - Matrix get_color (void) { return m_rgb; } + Matrix get_color () { return m_rgb; } void accept (text_processor& p); @@ -360,12 +360,12 @@ virtual void visit (text_element_color&) { } - virtual void reset (void) { } + virtual void reset () { } protected: - text_processor (void) { } + text_processor () { } - virtual ~text_processor (void) = default; + virtual ~text_processor () = default; }; #define TEXT_ELEMENT_ACCEPT(cls) \ @@ -391,9 +391,9 @@ text_parser { public: - text_parser (void) { } + text_parser () { } - virtual ~text_parser (void) = default; + virtual ~text_parser () = default; virtual text_element * parse (const std::string& s) = 0; @@ -407,9 +407,9 @@ text_parser_none : public text_parser { public: - text_parser_none (void) : text_parser () { } + text_parser_none () : text_parser () { } - ~text_parser_none (void) = default; + ~text_parser_none () = default; // FIXME: is it possible to use reference counting to manage the // memory for the object returned by the text parser? That would be @@ -427,26 +427,26 @@ text_parser_tex : public text_parser { public: - text_parser_tex (void) + text_parser_tex () : text_parser (), m_scanner (nullptr), m_buffer_state (nullptr), m_result (nullptr) { } - ~text_parser_tex (void) + ~text_parser_tex () { destroy_lexer (); } text_element * parse (const std::string& s); - void * get_scanner (void) { return m_scanner; } + void * get_scanner () { return m_scanner; } void set_parse_result (text_element *e) { m_result = e; } - text_element * get_parse_result (void) { return m_result; } + text_element * get_parse_result () { return m_result; } private: bool init_lexer (const std::string& s); - void destroy_lexer (void); + void destroy_lexer (); //-------- diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/text-renderer.cc --- a/libinterp/corefcn/text-renderer.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/text-renderer.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,19 +36,19 @@ OCTAVE_BEGIN_NAMESPACE(octave) -text_renderer::text_renderer (void) +text_renderer::text_renderer () : m_rep (make_ft_text_renderer ()), m_latex_rep (make_latex_text_renderer ()) { } -text_renderer::~text_renderer (void) +text_renderer::~text_renderer () { delete m_rep; delete m_latex_rep; } bool -text_renderer::ok (void) const +text_renderer::ok () const { static bool warned = false; @@ -96,7 +96,7 @@ } octave_map -text_renderer::get_system_fonts (void) +text_renderer::get_system_fonts () { octave_map retval; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/text-renderer.h --- a/libinterp/corefcn/text-renderer.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/text-renderer.h Mon Jan 30 18:36:03 2023 +0100 @@ -47,7 +47,7 @@ { public: - text_renderer (void); + text_renderer (); // No copying! @@ -55,9 +55,9 @@ text_renderer& operator = (const text_renderer&) = delete; - ~text_renderer (void); + ~text_renderer (); - bool ok (void) const; + bool ok () const; Matrix get_extent (text_element *elt, double rotation = 0.0); @@ -69,7 +69,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); @@ -83,7 +83,7 @@ { public: - font (void) + font () : m_name (), m_weight (), m_angle (), m_size (0) { } @@ -97,7 +97,7 @@ m_size (ft.m_size) { } - ~font (void) = default; + ~font () = default; font& operator = (const font& ft) { @@ -112,13 +112,13 @@ return *this; } - std::string get_name (void) const { return m_name; } + std::string get_name () const { return m_name; } - std::string get_weight (void) const { return m_weight; } + std::string get_weight () const { return m_weight; } - std::string get_angle (void) const { return m_angle; } + std::string get_angle () const { return m_angle; } - double get_size (void) const { return m_size; } + double get_size () const { return m_size; } protected: @@ -146,7 +146,7 @@ m_color (s.m_color), m_svg_element (s.m_svg_element) { } - ~string (void) = default; + ~string () = default; string& operator = (const string& s) { @@ -168,43 +168,43 @@ void set_string (const std::string& s) { m_str = s; } - std::string get_string (void) const { return m_str; } + std::string get_string () const { return m_str; } - std::string get_name (void) const { return m_fnt.get_name (); } + std::string get_name () const { return m_fnt.get_name (); } - std::string get_family (void) const { return m_family; } + std::string get_family () const { return m_family; } void set_family (const std::string& nm) { m_family = nm; } - std::string get_weight (void) const { return m_fnt.get_weight (); } + std::string get_weight () const { return m_fnt.get_weight (); } - std::string get_angle (void) const { return m_fnt.get_angle (); } + std::string get_angle () const { return m_fnt.get_angle (); } - double get_size (void) const { return m_fnt.get_size (); } + double get_size () const { return m_fnt.get_size (); } void set_x (const double x) { m_x = x; } - double get_x (void) const { return m_x; } + double get_x () const { return m_x; } void set_xdata (const std::vector& x) { m_xdata = x; } - std::vector get_xdata (void) const { return m_xdata; } + std::vector get_xdata () const { return m_xdata; } void set_y (const double y) { m_y = y; } - double get_y (void) const { return m_y; } + double get_y () const { return m_y; } void set_z (const double z) { m_z = z; } - double get_z (void) const { return m_z; } + double get_z () const { return m_z; } void set_code (const uint32_t code) { m_code = code; } - uint32_t get_code (void) const { return m_code; } + uint32_t get_code () const { return m_code; } void set_svg_element (const std::string& svg) { m_svg_element = svg; } - std::string get_svg_element (void) const { return m_svg_element; } + std::string get_svg_element () const { return m_svg_element; } void set_color (const uint8NDArray& c) { @@ -213,7 +213,7 @@ m_color(2) = static_cast (c(2)) / 255; } - Matrix get_color (void) const { return m_color; } + Matrix get_color () const { return m_color; } private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/time.cc --- a/libinterp/corefcn/time.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/time.cc Mon Jan 30 18:36:03 2023 +0100 @@ -267,8 +267,7 @@ if (args.length () != 1) print_usage (); - octave_scalar_map map = args( - 0).xscalar_map_value ("mktime: TM_STRUCT argument must be a structure"); + octave_scalar_map map = args(0).xscalar_map_value ("mktime: TM_STRUCT argument must be a structure"); sys::base_tm tm = extract_tm (map, "mktime"); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/toplev.cc --- a/libinterp/corefcn/toplev.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/toplev.cc Mon Jan 30 18:36:03 2023 +0100 @@ -158,7 +158,7 @@ // Combine alloc+get in one action. static void * -get_signal_mask (void) +get_signal_mask () { void *mask = octave_alloc_signal_mask (); @@ -540,7 +540,6 @@ { "QT_CPPFLAGS", build_env::QT_CPPFLAGS }, { "QT_LDFLAGS", build_env::QT_LDFLAGS }, { "QT_LIBS", build_env::QT_LIBS }, - { "QT_OPENGL_LIBS", build_env::QT_OPENGL_LIBS }, { "RANLIB", build_env::RANLIB }, { "RDYNAMIC_FLAG", build_env::RDYNAMIC_FLAG }, { "READLINE_LIBS", build_env::READLINE_LIBS }, @@ -614,8 +613,7 @@ if (nargin == 1) { - std::string arg = args( - 0).xstring_value ("__octave_config_info__: OPTION argument must be a string"); + std::string arg = args(0).xstring_value ("__octave_config_info__: OPTION argument must be a string"); octave_value info = find_config_info (config, arg); @@ -654,7 +652,7 @@ int debug_new_delete = 0; -typedef void (*vfp)(void); +typedef void (*vfp)(); extern vfp __new_handler; void * diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/url-handle-manager.cc --- a/libinterp/corefcn/url-handle-manager.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/url-handle-manager.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,14 +36,14 @@ OCTAVE_BEGIN_NAMESPACE(octave) static double -make_handle_fraction (void) +make_handle_fraction () { static double maxrand = RAND_MAX + 2.0; return (rand () + 1.0) / maxrand; } -url_handle url_handle_manager::get_handle (void) +url_handle url_handle_manager::get_handle () { url_handle retval; diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/url-handle-manager.h --- a/libinterp/corefcn/url-handle-manager.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/url-handle-manager.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,7 +48,7 @@ { public: - url_handle_manager (void) + url_handle_manager () : m_handle_map (), m_handle_free_list (), m_next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) { } @@ -56,9 +56,9 @@ url_handle_manager& operator = (const url_handle_manager&) = delete; - ~url_handle_manager (void) = default; + ~url_handle_manager () = default; - url_handle get_handle (void); + url_handle get_handle (); void free (const url_handle& h); @@ -110,7 +110,7 @@ return h; } - Matrix handle_list (void) + Matrix handle_list () { Matrix retval (1, m_handle_map.size ()); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/urlwrite.cc --- a/libinterp/corefcn/urlwrite.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/urlwrite.cc Mon Jan 30 18:36:03 2023 +0100 @@ -126,8 +126,7 @@ if (method != "get" && method != "post") error (R"(urlwrite: METHOD must be "get" or "post")"); - param = args( - 3).xcellstr_value ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings"); + param = args(3).xcellstr_value ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings"); if (param.numel () % 2 == 1) error ("urlwrite: number of elements in PARAM must be even"); @@ -238,8 +237,7 @@ if (method != "get" && method != "post") error (R"(urlread: METHOD must be "get" or "post")"); - param = args( - 2).xcellstr_value ("urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings"); + param = args(2).xcellstr_value ("urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings"); if (param.numel () % 2 == 1) error ("urlread: number of elements in PARAM must be even"); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/utils.cc --- a/libinterp/corefcn/utils.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/utils.cc Mon Jan 30 18:36:03 2023 +0100 @@ -573,8 +573,7 @@ if (nargin < 1 || nargin > 2) print_usage (); - string_vector names = args( - 0).xstring_vector_value ("file_in_loadpath: FILE argument must be a string"); + string_vector names = args(0).xstring_vector_value ("file_in_loadpath: FILE argument must be a string"); if (names.empty ()) error ("file_in_loadpath: FILE argument must not be empty"); @@ -585,8 +584,7 @@ return ovl (sys::env::make_absolute (lp.find_first_of (names))); else { - std::string opt = args( - 1).xstring_value ("file_in_loadpath: optional second argument must be a string"); + std::string opt = args(1).xstring_value ("file_in_loadpath: optional second argument must be a string"); if (opt != "all") error (R"(file_in_loadpath: "all" is only valid second argument)"); @@ -940,8 +938,7 @@ if (args.length () != 1) print_usage (); - std::string str = args( - 0).xstring_value ("do_string_escapes: STRING argument must be of type string"); + std::string str = args(0).xstring_value ("do_string_escapes: STRING argument must be of type string"); return ovl (do_string_escapes (str)); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/variables.cc Mon Jan 30 18:36:03 2023 +0100 @@ -60,7 +60,6 @@ #include "ov-class.h" #include "ov-usr-fcn.h" #include "pager.h" -#include "parse.h" #include "pt-eval.h" #include "syminfo.h" #include "symtab.h" @@ -558,7 +557,7 @@ } static octave::unwind_protect * -curr_fcn_unwind_protect_frame (void) +curr_fcn_unwind_protect_frame () { octave::tree_evaluator& tw = octave::__get_evaluator__ (); @@ -1430,7 +1429,7 @@ Vmissing_function_hook.clear (); // Call. - octave_value_list tmp = octave::feval (fcn_name, octave_value (name), 1); + octave_value_list tmp = interp.feval (fcn_name, octave_value (name), 1); if (tmp.length () == 1 && tmp(0).is_string ()) return tmp(0).string_value (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/variables.h --- a/libinterp/corefcn/variables.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/variables.h Mon Jan 30 18:36:03 2023 +0100 @@ -107,91 +107,6 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::symbol_exist' instead") -inline int -symbol_exist (const std::string& name, const std::string& type = "any") -{ - return octave::symbol_exist (name, type); -} - -OCTAVE_DEPRECATED (7, "use 'octave::unique_symbol_name' instead") -inline std::string -unique_symbol_name (const std::string& basename) -{ - return octave::unique_symbol_name (basename); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") -inline octave_value -set_internal_variable (bool& var, const octave_value_list& args, int nargout, - const char *nm) -{ - return octave::set_internal_variable (var, args, nargout, nm); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") -inline octave_value -set_internal_variable (char& var, const octave_value_list& args, int nargout, - const char *nm) -{ - return octave::set_internal_variable (var, args, nargout, nm); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") -inline octave_value -set_internal_variable (int& var, const octave_value_list& args, int nargout, - const char *nm, - int minval = std::numeric_limits::min (), - int maxval = std::numeric_limits::max ()) -{ - return octave::set_internal_variable (var, args, nargout, nm, minval, maxval); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") -inline octave_value -set_internal_variable (double& var, const octave_value_list& args, int nargout, - const char *nm, - double minval = -octave::numeric_limits::Inf (), - double maxval = octave::numeric_limits::Inf ()) -{ - return octave::set_internal_variable (var, args, nargout, nm, minval, maxval); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") -inline octave_value -set_internal_variable (std::string& var, const octave_value_list& args, - int nargout, const char *nm, bool empty_ok = true) -{ - return octave::set_internal_variable (var, args, nargout, nm, empty_ok); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") -inline octave_value -set_internal_variable (std::string& var, const octave_value_list& args, - int nargout, const char *nm, const char **choices) -{ - return octave::set_internal_variable (var, args, nargout, nm, choices); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") -inline octave_value -set_internal_variable (int& var, const octave_value_list& args, int nargout, - const char *nm, const char **choices) -{ - return octave::set_internal_variable (var, args, nargout, nm, choices); -} - -OCTAVE_DEPRECATED (7, "use 'octave::maybe_missing_function_hook' instead") -inline std::string -maybe_missing_function_hook (const std::string& name) -{ - return octave::maybe_missing_function_hook (name); -} - -#endif - // The following macros should also be considered obsolete. #define SET_INTERNAL_VARIABLE(NM) \ diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/xdiv.h --- a/libinterp/corefcn/xdiv.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/xdiv.h Mon Jan 30 18:36:03 2023 +0100 @@ -156,415 +156,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline Matrix -xdiv (const Matrix& a, const Matrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexMatrix -xdiv (const Matrix& a, const ComplexMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexMatrix -xdiv (const ComplexMatrix& a, const Matrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexMatrix -xdiv (const ComplexMatrix& a, const ComplexMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline Matrix -x_el_div (double a, const Matrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexMatrix -x_el_div (double a, const ComplexMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexMatrix -x_el_div (const Complex a, const Matrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexMatrix -x_el_div (const Complex a, const ComplexMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline NDArray -x_el_div (double a, const NDArray& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexNDArray -x_el_div (double a, const ComplexNDArray& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexNDArray -x_el_div (const Complex a, const NDArray& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline ComplexNDArray -x_el_div (const Complex a, const ComplexNDArray& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline Matrix -xleftdiv (const Matrix& a, const Matrix& b, - MatrixType& typ, blas_trans_type transt = blas_no_trans) -{ - return octave::xleftdiv (a, b, typ, transt); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexMatrix -xleftdiv (const Matrix& a, const ComplexMatrix& b, - MatrixType& typ, blas_trans_type transt = blas_no_trans) -{ - return octave::xleftdiv (a, b, typ, transt); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexMatrix -xleftdiv (const ComplexMatrix& a, const Matrix& b, - MatrixType& typ, blas_trans_type transt = blas_no_trans) -{ - return octave::xleftdiv (a, b, typ, transt); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexMatrix -xleftdiv (const ComplexMatrix& a, const ComplexMatrix& b, - MatrixType& typ, blas_trans_type transt = blas_no_trans) -{ - return octave::xleftdiv (a, b, typ, transt); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatMatrix -xdiv (const FloatMatrix& a, const FloatMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatComplexMatrix -xdiv (const FloatMatrix& a, const FloatComplexMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatComplexMatrix -xdiv (const FloatComplexMatrix& a, const FloatMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatComplexMatrix -xdiv (const FloatComplexMatrix& a, const FloatComplexMatrix& b, MatrixType& typ) -{ - return octave::xdiv (a, b, typ); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline FloatMatrix -x_el_div (float a, const FloatMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline FloatComplexMatrix -x_el_div (float a, const FloatComplexMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline FloatComplexMatrix -x_el_div (const FloatComplex a, const FloatMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline FloatComplexMatrix -x_el_div (const FloatComplex a, const FloatComplexMatrix& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline FloatNDArray -x_el_div (float a, const FloatNDArray& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline FloatComplexNDArray -x_el_div (float a, const FloatComplexNDArray& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline FloatComplexNDArray -x_el_div (const FloatComplex a, const FloatNDArray& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xdiv' instead") -inline FloatComplexNDArray -x_el_div (const FloatComplex a, const FloatComplexNDArray& b) -{ - return octave::elem_xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatMatrix -xleftdiv (const FloatMatrix& a, const FloatMatrix& b, - MatrixType& typ, blas_trans_type transt = blas_no_trans) -{ - return octave::xleftdiv (a, b, typ, transt); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatComplexMatrix -xleftdiv (const FloatMatrix& a, const FloatComplexMatrix& b, - MatrixType& typ, blas_trans_type transt = blas_no_trans) -{ - return octave::xleftdiv (a, b, typ, transt); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatComplexMatrix -xleftdiv (const FloatComplexMatrix& a, const FloatMatrix& b, - MatrixType& typ, blas_trans_type transt = blas_no_trans) -{ - return octave::xleftdiv (a, b, typ, transt); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatComplexMatrix -xleftdiv (const FloatComplexMatrix& a, const FloatComplexMatrix& b, - MatrixType& typ, blas_trans_type transt = blas_no_trans) -{ - return octave::xleftdiv (a, b, typ, transt); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline Matrix -xdiv (const Matrix& a, const DiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexMatrix -xdiv (const ComplexMatrix& a, const DiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexMatrix -xdiv (const ComplexMatrix& a, const ComplexDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline DiagMatrix -xdiv (const DiagMatrix& a, const DiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexDiagMatrix -xdiv (const ComplexDiagMatrix& a, const DiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline ComplexDiagMatrix -xdiv (const ComplexDiagMatrix& a, const ComplexDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatMatrix -xdiv (const FloatMatrix& a, const FloatDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatComplexMatrix -xdiv (const FloatComplexMatrix& a, const FloatDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatComplexMatrix -xdiv (const FloatMatrix& a, const FloatComplexDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatComplexMatrix -xdiv (const FloatComplexMatrix& a, const FloatComplexDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatDiagMatrix -xdiv (const FloatDiagMatrix& a, const FloatDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatComplexDiagMatrix -xdiv (const FloatComplexDiagMatrix& a, const FloatDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xdiv' instead") -inline FloatComplexDiagMatrix -xdiv (const FloatComplexDiagMatrix& a, const FloatComplexDiagMatrix& b) -{ - return octave::xdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline Matrix -xleftdiv (const DiagMatrix& a, const Matrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexMatrix -xleftdiv (const DiagMatrix& a, const ComplexMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexMatrix -xleftdiv (const ComplexDiagMatrix& a, const ComplexMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline DiagMatrix -xleftdiv (const DiagMatrix& a, const DiagMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexDiagMatrix -xleftdiv (const DiagMatrix& a, const ComplexDiagMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline ComplexDiagMatrix -xleftdiv (const ComplexDiagMatrix& a, const ComplexDiagMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatMatrix -xleftdiv (const FloatDiagMatrix& a, const FloatMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatComplexMatrix -xleftdiv (const FloatDiagMatrix& a, const FloatComplexMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatComplexMatrix -xleftdiv (const FloatComplexDiagMatrix& a, const FloatComplexMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatDiagMatrix -xleftdiv (const FloatDiagMatrix& a, const FloatDiagMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatComplexDiagMatrix -xleftdiv (const FloatDiagMatrix& a, const FloatComplexDiagMatrix& b) -{ - return octave::xleftdiv (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xleftdiv' instead") -inline FloatComplexDiagMatrix -xleftdiv (const FloatComplexDiagMatrix& a, const FloatComplexDiagMatrix& b) -{ - return octave::xleftdiv (a, b); -} - #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/xnorm.h --- a/libinterp/corefcn/xnorm.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/xnorm.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,36 +48,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline octave_value -xnorm (const octave_value& x, const octave_value& p) -{ - return octave::xnorm (x, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xcolnorms' instead") -inline octave_value -xcolnorms (const octave_value& x, const octave_value& p) -{ - return octave::xcolnorms (x, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xrownorms' instead") -inline octave_value -xrownorms (const octave_value& x, const octave_value& p) -{ - return octave::xrownorms (x, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xfrobnorm' instead") -inline octave_value -xfrobnorm (const octave_value& x) -{ - return octave::xfrobnorm (x); -} - #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/xpow.cc --- a/libinterp/corefcn/xpow.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/xpow.cc Mon Jan 30 18:36:03 2023 +0100 @@ -59,13 +59,13 @@ OCTAVE_BEGIN_NAMESPACE(octave) static void -err_failed_diagonalization (void) +err_failed_diagonalization () { error ("Failed to diagonalize matrix while calculating matrix exponential"); } static void -err_nonsquare_matrix (void) +err_nonsquare_matrix () { error ("for x^y, only square matrix arguments are permitted and one " \ "argument must be scalar. Use .^ for elementwise power."); diff -r 17d568574e1c -r 7860fcc69082 libinterp/corefcn/xpow.h --- a/libinterp/corefcn/xpow.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/corefcn/xpow.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,7 +44,6 @@ class ComplexNDArray; class FloatComplexNDArray; class octave_value; -class Range; OCTAVE_BEGIN_NAMESPACE(octave) @@ -209,589 +208,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (double a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (double a, const Matrix& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (double a, const Complex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (double a, const ComplexMatrix& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const Matrix& a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const Matrix& a, const Complex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const DiagMatrix& a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const DiagMatrix& a, const Complex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const PermMatrix& a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const Complex& a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const Complex& a, const Matrix& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const Complex& a, const Complex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const Complex& a, const ComplexMatrix& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const ComplexMatrix& a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const ComplexMatrix& a, const Complex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const ComplexDiagMatrix& a, double b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const ComplexDiagMatrix& a, const Complex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (double a, const Matrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (double a, const ComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (double a, const octave::range& r) -{ - return octave::elem_xpow (a, r); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Matrix& a, double b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Matrix& a, const Matrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Matrix& a, const Complex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Matrix& a, const ComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Complex& a, const Matrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Complex& a, const ComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Complex& a, const octave::range& r) -{ - return octave::elem_xpow (a, r); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const ComplexMatrix& a, double b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const ComplexMatrix& a, const Matrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const ComplexMatrix& a, const Complex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const ComplexMatrix& a, const ComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (double a, const NDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (double a, const ComplexNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const NDArray& a, double b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const NDArray& a, const NDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const NDArray& a, const Complex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const NDArray& a, const ComplexNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Complex& a, const NDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const Complex& a, const ComplexNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const ComplexNDArray& a, double b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const ComplexNDArray& a, const NDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const ComplexNDArray& a, const Complex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const ComplexNDArray& a, const ComplexNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (float a, float b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (float a, const FloatMatrix& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (float a, const FloatComplex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (float a, const FloatComplexMatrix& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatMatrix& a, float b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatMatrix& a, const FloatComplex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatDiagMatrix& a, float b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatDiagMatrix& a, const FloatComplex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatComplex& a, float b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatComplex& a, const FloatMatrix& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatComplex& a, const FloatComplex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatComplex& a, const FloatComplexMatrix& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatComplexMatrix& a, float b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatComplexMatrix& a, const FloatComplex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatComplexDiagMatrix& a, float b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xpow' instead") -inline octave_value -xpow (const FloatComplexDiagMatrix& a, const FloatComplex& b) -{ - return octave::xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (float a, const FloatMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (float a, const FloatComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatMatrix& a, float b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatMatrix& a, const FloatMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatMatrix& a, const FloatComplex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatMatrix& a, const FloatComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplex& a, const FloatMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplex& a, const FloatComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplexMatrix& a, float b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplexMatrix& a, const FloatMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplexMatrix& a, const FloatComplex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplexMatrix& a, const FloatComplexMatrix& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (float a, const FloatNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (float a, const FloatComplexNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatNDArray& a, float b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatNDArray& a, const FloatNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatNDArray& a, const FloatComplex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatNDArray& a, const FloatComplexNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplex& a, const FloatNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplex& a, const FloatComplexNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplexNDArray& a, float b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplexNDArray& a, const FloatNDArray& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplexNDArray& a, const FloatComplex& b) -{ - return octave::elem_xpow (a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::elem_xpow' instead") -inline octave_value -elem_xpow (const FloatComplexNDArray& a, const FloatComplexNDArray& b) -{ - return octave::elem_xpow (a, b); -} - #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/dldfcn/__init_fltk__.cc --- a/libinterp/dldfcn/__init_fltk__.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/dldfcn/__init_fltk__.cc Mon Jan 30 18:36:03 2023 +0100 @@ -102,7 +102,6 @@ #include "ov-fcn-handle.h" #include "ov.h" #include "ovl.h" -#include "parse.h" #include "variables.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -145,7 +144,7 @@ #endif } - ~OpenGL_fltk (void) = default; + ~OpenGL_fltk () = default; void zoom (bool z) { @@ -154,7 +153,7 @@ hide_overlay (); } - bool zoom (void) { return m_in_zoom; } + bool zoom () { return m_in_zoom; } void set_zoom_box (const Matrix& zb) { m_zoom_box = zb; } void print (const std::string& cmd, const std::string& term) @@ -164,7 +163,7 @@ octave::gl2ps_print (m_glfcns, gh_mgr.get_object (m_number), cmd, term); } - uint8NDArray get_pixels (void) + uint8NDArray get_pixels () { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -219,7 +218,7 @@ // (x1,y1,x2,y2) Matrix m_zoom_box; - void draw (void) + void draw () { #if defined (HAVE_OPENGL) @@ -247,7 +246,7 @@ #endif } - void overlay (void) + void overlay () { Matrix overlaycolor (3, 1); overlaycolor(0) = 0.45; @@ -308,7 +307,7 @@ : m_menubar (new Fl_Menu_Bar (xx, yy, ww, hh)) { } - int items_to_show (void) + int items_to_show () { //returns the number of visible menu items int len = m_menubar->size (); @@ -325,19 +324,19 @@ return n; } - void show (void) + void show () { m_menubar->show (); m_menubar->redraw (); } - void hide (void) + void hide () { m_menubar->hide (); m_menubar->redraw (); } - bool is_visible (void) + bool is_visible () { return m_menubar->visible (); } @@ -758,7 +757,7 @@ fltk_uimenu operator = (const fltk_uimenu&) = delete; - ~fltk_uimenu (void) + ~fltk_uimenu () { // FLTK is supposed to manage memory for widgets. } @@ -889,7 +888,7 @@ plot_window& operator = (const plot_window&) = delete; - ~plot_window (void) + ~plot_window () { this->hide (); Fl::check (); @@ -899,7 +898,7 @@ // FLTK is supposed to manage memory for widgets. } - double number (void) { return m_fp.get___myhandle__ ().value (); } + double number () { return m_fp.get___myhandle__ ().value (); } void renumber (double new_number) { @@ -920,13 +919,13 @@ return m_canvas->get_pixels (); } - void show_menubar (void) + void show_menubar () { m_uimenu->show (); update_toolbar_position (); } - void hide_menubar (void) + void hide_menubar () { m_uimenu->hide (); update_toolbar_position (); @@ -997,7 +996,7 @@ } } - void show_canvas (void) + void show_canvas () { if (! m_canvas->can_do ()) error ("unable to plot due to insufficient OpenGL support"); @@ -1008,7 +1007,7 @@ } } - void hide_canvas (void) + void hide_canvas () { m_canvas->hide (); } @@ -1066,12 +1065,12 @@ resize (bb(0), bb(1), bb(2), bb(3)); } - void mark_modified (void) + void mark_modified () { m_canvas->redraw (); } - void set_name (void) + void set_name () { m_window_label = m_fp.get_title (); label (m_window_label.c_str ()); @@ -1113,9 +1112,12 @@ // Window callback. static void window_close (Fl_Widget *, void *data) { + interpreter& interp = __get_interpreter__ (); + octave_value_list args; args(0) = static_cast (data)->number (); - octave::feval ("close", args); + + interp.feval ("close", args); } // Button callbacks. @@ -1166,25 +1168,32 @@ } } - void axis_auto (void) + void axis_auto () { octave_value_list args; if (m_fp.get_currentaxes ().ok ()) { + interpreter& interp = __get_interpreter__ (); + args(0) = m_fp.get_currentaxes ().as_octave_value (); args(1) = "auto"; - octave::feval ("axis", args); + + interp.feval ("axis", args); + mark_modified (); } } - void toggle_grid (void) + void toggle_grid () { + interpreter& interp = __get_interpreter__ (); + octave_value_list args; if (m_fp.get_currentaxes ().ok ()) args(0) = m_fp.get_currentaxes ().as_octave_value (); - octave::feval ("grid", args); + interp.feval ("grid", args); + mark_modified (); } @@ -1466,7 +1475,7 @@ m_fp.set_boundingbox (outerposition2position (bb), true, false); } - bool pan_enabled (void) + bool pan_enabled () { // Getting pan mode property: octave_value ov_pm = m_fp.get___pan_mode__ (); @@ -1476,7 +1485,7 @@ return pm.contents ("Enable").string_value () == "on"; } - std::string pan_mode (void) + std::string pan_mode () { // Getting pan mode property: octave_value ov_pm = m_fp.get___pan_mode__ (); @@ -1486,7 +1495,7 @@ return pm.contents ("Motion").string_value (); } - bool rotate_enabled (void) + bool rotate_enabled () { // Getting rotate mode property: octave_value ov_rm = m_fp.get___rotate_mode__ (); @@ -1871,7 +1880,7 @@ { private: - figure_manager (void) = default; + figure_manager () = default; public: @@ -1881,12 +1890,12 @@ figure_manager& operator = (const figure_manager&) = delete; - ~figure_manager (void) + ~figure_manager () { close_all (); } - static bool instance_ok (void) + static bool instance_ok () { bool retval = true; @@ -1896,7 +1905,7 @@ return retval; } - static void close_all (void) + static void close_all () { if (instance_ok ()) instance->do_close_all (); @@ -2030,7 +2039,7 @@ static std::string fltk_idx_header; - void do_close_all (void) + void do_close_all () { wm_iterator win; for (win = windows.begin (); win != windows.end (); win++) @@ -2271,9 +2280,9 @@ Fl::visual (FL_RGB); } - ~fltk_graphics_toolkit (void) = default; - - bool is_valid (void) const { return true; } + ~fltk_graphics_toolkit () = default; + + bool is_valid () const { return true; } bool initialize (const graphics_object& go) { @@ -2440,7 +2449,7 @@ } /* - double get_screen_resolution (void) const + double get_screen_resolution () const { // FLTK doesn't give this info. return 72.0; @@ -2450,7 +2459,7 @@ } */ - Matrix get_screen_size (void) const + Matrix get_screen_size () const { Matrix sz (1, 2, 0.0); sz(0) = Fl::w (); @@ -2458,7 +2467,7 @@ return sz; } - void close (void) + void close () { if (toolkit_loaded) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/dldfcn/__init_gnuplot__.cc --- a/libinterp/dldfcn/__init_gnuplot__.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/dldfcn/__init_gnuplot__.cc Mon Jan 30 18:36:03 2023 +0100 @@ -51,7 +51,6 @@ #include "interpreter.h" #include "ov.h" #include "ovl.h" -#include "parse.h" #include "utils.h" #include "variables.h" @@ -86,9 +85,9 @@ } } - ~gnuplot_graphics_toolkit (void) = default; + ~gnuplot_graphics_toolkit () = default; - bool is_valid (void) const { return true; } + bool is_valid () const { return true; } bool initialize (const graphics_object& go) { @@ -140,7 +139,7 @@ octave_value_list args; args(0) = go.get_handle ().as_octave_value (); - octave::feval ("__gnuplot_drawnow__", args); + m_interpreter.feval ("__gnuplot_drawnow__", args); } } @@ -154,7 +153,7 @@ args(2) = file; args(1) = term; args(0) = go.get_handle ().as_octave_value (); - octave::feval ("__gnuplot_drawnow__", args); + m_interpreter.feval ("__gnuplot_drawnow__", args); } Matrix get_canvas_size (const graphics_handle&) const @@ -163,13 +162,13 @@ return sz; } - double get_screen_resolution (void) const + double get_screen_resolution () const { return 72.0; } - Matrix get_screen_size (void) const + Matrix get_screen_size () const { return Matrix (1, 2, 0.0); } - void close (void) + void close () { if (m_interpreter.mislocked ("__init_gnuplot__")) m_interpreter.munlock ("__init_gnuplot__"); @@ -203,7 +202,7 @@ }; static bool -have_gnuplot_binary (void) +have_gnuplot_binary (interpreter& interp) { const std::string exeext = octave::build_env::EXEEXT; const std::string path = octave::sys::env::getenv ("PATH"); @@ -212,7 +211,7 @@ try { octave_value_list tmp - = octave::feval ("gnuplot_binary", octave_value_list ()); + = interp.feval ("gnuplot_binary", octave_value_list ()); if (tmp(0).is_string () && ! tmp(0).isempty ()) { @@ -237,8 +236,6 @@ } catch (const octave::execution_exception&) { - octave::interpreter& interp = octave::__get_interpreter__ (); - interp.recover_from_exception (); } @@ -253,7 +250,7 @@ Undocumented internal function. @end deftypefn */) { - if (! have_gnuplot_binary ()) + if (! have_gnuplot_binary (interp)) error ("__init_gnuplot__: the gnuplot program is not available, see 'gnuplot_binary'"); else if (! interp.mislocked ("__init_gnuplot__")) { @@ -268,13 +265,13 @@ return octave_value_list (); } -DEFUN_DLD (__have_gnuplot__, , , - doc: /* -*- texinfo -*- +DEFMETHOD_DLD (__have_gnuplot__, interp, , , + doc: /* -*- texinfo -*- @deftypefn {} {@var{gnuplot_available} =} __have_gnuplot__ () Undocumented internal function. @end deftypefn */) { - return ovl (have_gnuplot_binary ()); + return ovl (have_gnuplot_binary (interp)); } /* diff -r 17d568574e1c -r 7860fcc69082 libinterp/dldfcn/__ode15__.cc --- a/libinterp/dldfcn/__ode15__.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/dldfcn/__ode15__.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,11 +37,12 @@ #include "defun-dld.h" #include "error.h" #include "errwarn.h" +#include "interpreter-private.h" +#include "interpreter.h" #include "oct-map.h" #include "ov.h" #include "ovl.h" #include "pager.h" -#include "parse.h" #if defined (HAVE_SUNDIALS) @@ -168,7 +169,7 @@ SparseMatrix *dfdyp, realtype cj); //Default - IDA (void) + IDA () : m_t0 (0.0), m_y0 (), m_yp0 (), m_havejac (false), m_havejacfcn (false), m_havejacsparse (false), m_mem (nullptr), m_num (), m_ida_fcn (), m_ida_jac (), m_dfdy (nullptr), m_dfdyp (nullptr), m_spdfdy (nullptr), @@ -189,7 +190,7 @@ { } - ~IDA (void) + ~IDA () { IDAFree (&m_mem); SUNLinSolFree (m_sunLinearSolver); @@ -250,9 +251,9 @@ return *this; } - void set_userdata (void); + void set_userdata (); - void initialize (void); + void initialize (); static ColumnVector NVecToCol (N_Vector& v, octave_f77_int_type n); @@ -350,7 +351,7 @@ const octave_value& event_fcn, const octave_idx_type num_event_args); - void print_stat (void); + void print_stat (); private: @@ -571,7 +572,7 @@ } void -IDA::set_userdata (void) +IDA::set_userdata () { void *userdata = this; @@ -580,7 +581,7 @@ } void -IDA::initialize (void) +IDA::initialize () { m_num = to_f77_int (m_y0.numel ()); # if defined (HAVE_SUNDIALS_SUNCONTEXT) @@ -811,9 +812,11 @@ // cont is the number of steps reached by the solver // temp is the number of events registered + interpreter& interp = __get_interpreter__ (); + if (flag == "init") { - octave_value_list output = feval (event_fcn, args, 3); + octave_value_list output = interp.feval (event_fcn, args, 3); oldval = output(0).vector_value (); oldisterminal = output(1).vector_value (); olddir = output(2).vector_value (); @@ -821,7 +824,7 @@ else if (flag == "") { ColumnVector index (0); - octave_value_list output = feval (event_fcn, args, 3); + octave_value_list output = interp.feval (event_fcn, args, 3); ColumnVector val = output(0).vector_value (); ColumnVector isterminal = output(1).vector_value (); ColumnVector dir = output(2).vector_value (); @@ -994,6 +997,8 @@ else output(1) = yout; + interpreter& interp = __get_interpreter__ (); + if (flag == "init") { ColumnVector toutput (2); @@ -1001,19 +1006,19 @@ toutput(1) = tend; output(0) = toutput; - feval (output_fcn, output, 0); + interp.feval (output_fcn, output, 0); } else if (flag == "") { output(0) = tsol; - octave_value_list val = feval (output_fcn, output, 1); + octave_value_list val = interp.feval (output_fcn, output, 1); status = val(0).bool_value (); } else { // Cleanup plotter output(0) = tend; - feval (output_fcn, output, 0); + interp.feval (output_fcn, output, 0); } return status; @@ -1041,7 +1046,7 @@ } void -IDA::print_stat (void) +IDA::print_stat () { long int nsteps = 0, netfails = 0, nrevals = 0; @@ -1070,7 +1075,9 @@ try { - tmp = feval (ida_fc, ovl (t, x, xdot), 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (ida_fc, ovl (t, x, xdot), 1); } catch (execution_exception& ee) { @@ -1088,7 +1095,9 @@ try { - tmp = feval (ida_jc, ovl (t, x, xdot), 2); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (ida_jc, ovl (t, x, xdot), 2); } catch (execution_exception& ee) { @@ -1106,7 +1115,9 @@ try { - tmp = feval (ida_jc, ovl (t, x, xdot), 2); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (ida_jc, ovl (t, x, xdot), 2); } catch (execution_exception& ee) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/dldfcn/audiodevinfo.cc --- a/libinterp/dldfcn/audiodevinfo.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/dldfcn/audiodevinfo.cc Mon Jan 30 18:36:03 2023 +0100 @@ -44,11 +44,12 @@ #include "defun-dld.h" #include "error.h" #include "errwarn.h" +#include "interpreter-private.h" +#include "interpreter.h" #include "oct-map.h" #include "ov-int32.h" #include "ov.h" #include "ovl.h" -#include "parse.h" #if defined (HAVE_PORTAUDIO) # include @@ -521,55 +522,55 @@ class audioplayer : public octave_base_dld_value { public: - audioplayer (void); - ~audioplayer (void); + audioplayer (); + ~audioplayer (); // Overloaded base functions - double player_value (void) const { return 0; } + double player_value () const { return 0; } virtual double scalar_value (bool = false) const { return 0; } void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax) const; // Properties - bool is_constant (void) const { return true; } - bool is_defined (void) const { return true; } - bool print_as_scalar (void) const { return true; } - - void init (void); - void init_fn (void); + bool is_constant () const { return true; } + bool is_defined () const { return true; } + bool print_as_scalar () const { return true; } + + void init (); + void init_fn (); void set_y (const octave_value& y); void set_y (octave_function *fcn); void set_y (std::string fcn); - Matrix& get_y (void); - RowVector get_left (void) const; - RowVector get_right (void) const; + Matrix& get_y (); + RowVector get_left () const; + RowVector get_right () const; void set_fs (int fs); - int get_fs (void); + int get_fs (); void set_nbits (int nbits); - int get_nbits (void); + int get_nbits (); void set_id (int id); - int get_id (void); - int get_channels (void); - audio_type get_type (void); + int get_id (); + int get_channels (); + audio_type get_type (); void set_sample_number (unsigned int sample); - unsigned int get_sample_number (void); - unsigned int get_total_samples (void); + unsigned int get_sample_number (); + unsigned int get_total_samples (); void set_end_sample (unsigned int sample); - unsigned int get_end_sample (void); - void reset_end_sample (void); + unsigned int get_end_sample (); + void reset_end_sample (); void set_tag (const charMatrix& tag); - charMatrix get_tag (void); + charMatrix get_tag (); void set_userdata (const octave_value& userdata); - octave_value get_userdata (void); - PaStream * get_stream (void); - - void play (void); - void playblocking (void); - void pause (void); - void resume (void); - void stop (void); - bool isplaying (void); + octave_value get_userdata (); + PaStream * get_stream (); + + void play (); + void playblocking (); + void pause (); + void resume (); + void stop (); + bool isplaying (); octave_function *octave_callback_function; @@ -604,9 +605,11 @@ if (! player) error ("audioplayer callback function called without player"); + interpreter& interp = __get_interpreter__ (); + octave_value_list retval - = feval (player->octave_callback_function, - ovl (static_cast (frames)), 1); + = interp.feval (player->octave_callback_function, + ovl (static_cast (frames)), 1); if (retval.length () < 2) error ("audioplayer callback function failed"); @@ -873,14 +876,14 @@ return paContinue; } -audioplayer::audioplayer (void) +audioplayer::audioplayer () : octave_callback_function (nullptr), id (-1), fs (0), nbits (16), channels (0), sample_number (0), end_sample (-1), tag (""), y (), userdata (Matrix ()), left (), right (), stream (nullptr), output_parameters (), type () { } -audioplayer::~audioplayer (void) +audioplayer::~audioplayer () { if (isplaying ()) { @@ -904,7 +907,7 @@ } void -audioplayer::init_fn (void) +audioplayer::init_fn () { if (Pa_Initialize () != paNoError) error ("audioplayer: initialization error"); @@ -934,7 +937,7 @@ } void -audioplayer::init (void) +audioplayer::init () { // FIXME: Both of these variables are unused. // Should they be eliminated or is something not yet implemented? @@ -1012,19 +1015,19 @@ } Matrix& -audioplayer::get_y (void) +audioplayer::get_y () { return y; } RowVector -audioplayer::get_left (void) const +audioplayer::get_left () const { return left; } RowVector -audioplayer::get_right (void) const +audioplayer::get_right () const { return channels == 1 ? left : right; } @@ -1036,7 +1039,7 @@ } int -audioplayer::get_fs (void) +audioplayer::get_fs () { return fs; } @@ -1048,7 +1051,7 @@ } int -audioplayer::get_nbits (void) +audioplayer::get_nbits () { return nbits; } @@ -1060,19 +1063,19 @@ } int -audioplayer::get_id (void) +audioplayer::get_id () { return id; } int -audioplayer::get_channels (void) +audioplayer::get_channels () { return channels; } audio_type -audioplayer::get_type (void) +audioplayer::get_type () { return type; } @@ -1084,13 +1087,13 @@ } unsigned int -audioplayer::get_sample_number (void) +audioplayer::get_sample_number () { return sample_number; } unsigned int -audioplayer::get_total_samples (void) +audioplayer::get_total_samples () { return left.numel (); } @@ -1102,13 +1105,13 @@ } unsigned int -audioplayer::get_end_sample (void) +audioplayer::get_end_sample () { return end_sample; } void -audioplayer::reset_end_sample (void) +audioplayer::reset_end_sample () { set_end_sample (left.numel ()); } @@ -1120,7 +1123,7 @@ } charMatrix -audioplayer::get_tag (void) +audioplayer::get_tag () { return tag; } @@ -1132,13 +1135,13 @@ } octave_value -audioplayer::get_userdata (void) +audioplayer::get_userdata () { return userdata; } void -audioplayer::playblocking (void) +audioplayer::playblocking () { if (get_stream ()) stop (); @@ -1176,7 +1179,7 @@ } void -audioplayer::play (void) +audioplayer::play () { if (get_stream ()) stop (); @@ -1202,7 +1205,7 @@ } void -audioplayer::pause (void) +audioplayer::pause () { if (get_stream () == nullptr) return; @@ -1214,7 +1217,7 @@ } void -audioplayer::resume (void) +audioplayer::resume () { if (get_stream () == nullptr) return; @@ -1226,13 +1229,13 @@ } PaStream * -audioplayer::get_stream (void) +audioplayer::get_stream () { return stream; } void -audioplayer::stop (void) +audioplayer::stop () { if (get_stream () == nullptr) return; @@ -1255,7 +1258,7 @@ } bool -audioplayer::isplaying (void) +audioplayer::isplaying () { if (get_stream () == nullptr) return false; @@ -1271,53 +1274,53 @@ class audiorecorder : public octave_base_dld_value { public: - audiorecorder (void); - ~audiorecorder (void); + audiorecorder (); + ~audiorecorder (); // Overloaded base functions - double player_value (void) const { return 0; } + double player_value () const { return 0; } virtual double scalar_value (bool = false) const { return 0; } void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax) const; // Properties - bool is_constant (void) const { return true; } - bool is_defined (void) const { return true; } - bool print_as_scalar (void) const { return true; } - - void init (void); + bool is_constant () const { return true; } + bool is_defined () const { return true; } + bool print_as_scalar () const { return true; } + + void init (); void set_fs (int fs); - int get_fs (void); + int get_fs (); void set_nbits (int nbits); - int get_nbits (void); - PaSampleFormat get_sampleFormat (void); + int get_nbits (); + PaSampleFormat get_sampleFormat (); void set_id (int id); - int get_id (void); + int get_id (); void set_channels (int channels); - int get_channels (void); - audio_type get_type (void); + int get_channels (); + audio_type get_type (); void set_sample_number (unsigned int sample); - unsigned int get_sample_number (void); - unsigned int get_total_samples (void); + unsigned int get_sample_number (); + unsigned int get_total_samples (); void set_end_sample (unsigned int sample); - unsigned int get_end_sample (void); - void reset_end_sample (void); + unsigned int get_end_sample (); + void reset_end_sample (); void set_tag (const charMatrix& tag); - charMatrix get_tag (void); + charMatrix get_tag (); void set_userdata (const octave_value& userdata); - octave_value get_userdata (void); - PaStream * get_stream (void); - - octave_value getaudiodata (void); - audioplayer * getplayer (void); - bool isrecording (void); - audioplayer play (void); - void record (void); + octave_value get_userdata (); + PaStream * get_stream (); + + octave_value getaudiodata (); + audioplayer * getplayer (); + bool isrecording (); + audioplayer play (); + void record (); void recordblocking (float seconds); - void pause (void); - void resume (void); - void stop (void); + void pause (); + void resume (); + void stop (); void append (float sample_l, float sample_r); octave_function *octave_callback_function; @@ -1441,8 +1444,10 @@ } } + interpreter& interp = __get_interpreter__ (); + octave_value_list retval - = feval (recorder->octave_callback_function, ovl (sound), 1); + = interp.feval (recorder->octave_callback_function, ovl (sound), 1); return retval(0).int_value (); } @@ -1545,14 +1550,14 @@ return paContinue; } -audiorecorder::audiorecorder (void) +audiorecorder::audiorecorder () : octave_callback_function (nullptr), id (-1), fs (8000), nbits (8), channels (1), sample_number (0), end_sample (-1), tag (""), y (), userdata (Matrix ()), left (), right (), stream (nullptr), input_parameters (), type () { } -audiorecorder::~audiorecorder (void) +audiorecorder::~audiorecorder () { if (isrecording ()) { @@ -1576,7 +1581,7 @@ } void -audiorecorder::init (void) +audiorecorder::init () { if (Pa_Initialize () != paNoError) error ("audiorecorder: initialization error"); @@ -1618,7 +1623,7 @@ } int -audiorecorder::get_fs (void) +audiorecorder::get_fs () { return fs; } @@ -1630,13 +1635,13 @@ } int -audiorecorder::get_nbits (void) +audiorecorder::get_nbits () { return nbits; } PaSampleFormat -audiorecorder::get_sampleFormat (void) +audiorecorder::get_sampleFormat () { return input_parameters.sampleFormat; } @@ -1648,7 +1653,7 @@ } int -audiorecorder::get_id (void) +audiorecorder::get_id () { return id; } @@ -1663,13 +1668,13 @@ } int -audiorecorder::get_channels (void) +audiorecorder::get_channels () { return channels; } audio_type -audiorecorder::get_type (void) +audiorecorder::get_type () { return type; } @@ -1681,13 +1686,13 @@ } unsigned int -audiorecorder::get_sample_number (void) +audiorecorder::get_sample_number () { return sample_number; } unsigned int -audiorecorder::get_total_samples (void) +audiorecorder::get_total_samples () { return left.size (); } @@ -1699,13 +1704,13 @@ } unsigned int -audiorecorder::get_end_sample (void) +audiorecorder::get_end_sample () { return end_sample; } void -audiorecorder::reset_end_sample (void) +audiorecorder::reset_end_sample () { set_end_sample (left.size ()); } @@ -1717,7 +1722,7 @@ } charMatrix -audiorecorder::get_tag (void) +audiorecorder::get_tag () { return tag; } @@ -1729,13 +1734,13 @@ } octave_value -audiorecorder::get_userdata (void) +audiorecorder::get_userdata () { return userdata; } octave_value -audiorecorder::getaudiodata (void) +audiorecorder::getaudiodata () { // Must get size before entering loop as the value of left.size() may change // during loop with simultaneous recording and playback (bug #50674). @@ -1752,7 +1757,7 @@ } audioplayer * -audiorecorder::getplayer (void) +audiorecorder::getplayer () { audioplayer *player = new audioplayer (); @@ -1765,7 +1770,7 @@ } bool -audiorecorder::isrecording (void) +audiorecorder::isrecording () { if (get_stream () == nullptr) return false; @@ -1779,7 +1784,7 @@ } void -audiorecorder::record (void) +audiorecorder::record () { if (get_stream ()) stop (); @@ -1850,7 +1855,7 @@ } void -audiorecorder::pause (void) +audiorecorder::pause () { if (get_stream () == nullptr) return; @@ -1862,7 +1867,7 @@ } void -audiorecorder::resume (void) +audiorecorder::resume () { if (get_stream () == nullptr) return; @@ -1874,7 +1879,7 @@ } void -audiorecorder::stop (void) +audiorecorder::stop () { if (get_stream () == nullptr) return; @@ -1905,7 +1910,7 @@ } PaStream * -audiorecorder::get_stream (void) +audiorecorder::get_stream () { return stream; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/dldfcn/gzip.cc --- a/libinterp/dldfcn/gzip.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/dldfcn/gzip.cc Mon Jan 30 18:36:03 2023 +0100 @@ -98,7 +98,7 @@ { public: - CFile (void) = delete; + CFile () = delete; CFile (const std::string& path, const std::string& mode) : m_fp (sys::fopen (path, mode)) @@ -111,13 +111,13 @@ CFile& operator = (const CFile&) = delete; - ~CFile (void) + ~CFile () { if (m_fp) std::fclose (m_fp); } - void close (void) + void close () { if (std::fclose (m_fp)) throw std::runtime_error ("unable to close file"); @@ -150,7 +150,7 @@ { public: - zipper (void) = delete; + zipper () = delete; zipper (const std::string& source_path, const std::string& dest_path) : m_status (BZ_OK), m_source (source_path, "rb"), @@ -165,13 +165,13 @@ zipper& operator = (const zipper&) = delete; - ~zipper (void) + ~zipper () { if (m_bz != nullptr) BZ2_bzWriteClose (&m_status, m_bz, 1, nullptr, nullptr); } - void deflate (void) + void deflate () { const std::size_t buf_len = 8192; char buf[buf_len]; @@ -188,7 +188,7 @@ throw std::runtime_error ("failed to read from source file"); } - void close (void) + void close () { int abandon = (m_status == BZ_IO_ERROR) ? 1 : 0; BZ2_bzWriteClose (&m_status, m_bz, abandon, nullptr, nullptr); @@ -265,7 +265,7 @@ // Bytef is a typedef for unsigned char unsigned char *p; - uchar_array (void) = delete; + uchar_array () = delete; uchar_array (const std::string& str) { @@ -277,14 +277,14 @@ uchar_array& operator = (const uchar_array&) = delete; - ~uchar_array (void) { delete[] p; } + ~uchar_array () { delete[] p; } }; class gzip_header : public gz_header { public: - gzip_header (void) = delete; + gzip_header () = delete; gzip_header (const std::string& source_path) : m_basename (sys::env::base_pathname (source_path)) @@ -357,7 +357,7 @@ gzip_header& operator = (const gzip_header&) = delete; - ~gzip_header (void) = default; + ~gzip_header () = default; private: @@ -369,7 +369,7 @@ { public: - zipper (void) = delete; + zipper () = delete; zipper (const std::string& source_path, const std::string& dest_path) : m_source (source_path, "rb"), m_dest (dest_path, "wb"), @@ -384,14 +384,14 @@ zipper& operator = (const zipper&) = delete; - ~zipper (void) + ~zipper () { if (m_strm) deflateEnd (m_strm); delete m_strm; } - void deflate (void) + void deflate () { // int deflateInit2 (z_streamp m_strm, // int level, // compression level (default is 8) @@ -451,7 +451,7 @@ throw std::runtime_error ("failed to write file"); } - void close (void) + void close () { if (deflateEnd (m_strm) != Z_OK) throw std::runtime_error ("failed to close zlib stream"); diff -r 17d568574e1c -r 7860fcc69082 libinterp/liboctinterp-build-info.h --- a/libinterp/liboctinterp-build-info.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/liboctinterp-build-info.h Mon Jan 30 18:36:03 2023 +0100 @@ -30,6 +30,6 @@ #include -extern OCTINTERP_API std::string liboctinterp_hg_id (void); +extern OCTINTERP_API std::string liboctinterp_hg_id (); #endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/liboctinterp-build-info.in.cc --- a/libinterp/liboctinterp-build-info.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/liboctinterp-build-info.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,7 @@ #include "liboctinterp-build-info.h" std::string -liboctinterp_hg_id (void) +liboctinterp_hg_id () { return "%OCTAVE_HG_ID%"; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/mk-build-env-features.sh --- a/libinterp/mk-build-env-features.sh Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/mk-build-env-features.sh Mon Jan 30 18:36:03 2023 +0100 @@ -48,7 +48,7 @@ OCTAVE_BEGIN_NAMESPACE(build_env) octave_scalar_map - features (void) + features () { static bool initialized = false; diff -r 17d568574e1c -r 7860fcc69082 libinterp/mk-builtins.pl --- a/libinterp/mk-builtins.pl Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/mk-builtins.pl Mon Jan 30 18:36:03 2023 +0100 @@ -150,23 +150,6 @@ print "\nOCTAVE_END_NAMESPACE(octave)\n"; - print "\n#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)\n\n"; - - foreach $name (sort (@fcn_names)) - { - print "OCTAVE_DEPRECATED (7, \"use 'octave::$name' instead\") -inline octave_value_list -$name (const octave_value_list& args = octave_value_list (), int nargout = 0) -{ - return octave::$name (args, nargout); -} - -"; - } - - ## end OCTAVE_PROVIDE_DEPRECATED_SYMBOLS block - print "\n\n#endif\n"; - print "\n#endif\n"; } elsif ($make_source) @@ -314,7 +297,7 @@ print " void - symbol_table::install_builtins (void) + symbol_table::install_builtins () { "; diff -r 17d568574e1c -r 7860fcc69082 libinterp/module.mk --- a/libinterp/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -176,11 +176,6 @@ LIBINTERP_DEFUN_FILES += \ $(BUILT_IN_DEFUN_FILES) -## FIXME: The following two variables are deprecated and should be removed -## in Octave version 3.12. -DLL_CDEFS = @OCTINTERP_DLL_DEFS@ -DLL_CXXDEFS = @OCTINTERP_DLL_DEFS@ - ## Rules to build test files LIBINTERP_TST_FILES_SRC := $(shell $(SHELL) $(srcdir)/build-aux/find-files-with-tests.sh "$(srcdir)" $(ULT_DIST_SRC) $(DLDFCN_SRC)) diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-class.cc --- a/libinterp/octave-value/cdef-class.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-class.cc Mon Jan 30 18:36:03 2023 +0100 @@ -131,7 +131,7 @@ { public: - ctor_analyzer (void) = delete; + ctor_analyzer () = delete; ctor_analyzer (const std::string& ctor, const std::string& obj) : tree_walker (), m_who (ctor), m_obj_name (obj) { } @@ -140,7 +140,7 @@ ctor_analyzer& operator = (const ctor_analyzer&) = delete; - ~ctor_analyzer (void) = default; + ~ctor_analyzer () = default; void visit_statement (tree_statement& t) { @@ -163,7 +163,7 @@ t.expression ()->accept (*this); } - std::list get_constructor_list (void) const + std::list get_constructor_list () const { return m_ctor_list; } // NO-OP @@ -278,7 +278,7 @@ } void -cdef_class::cdef_class_rep::load_all_methods (void) +cdef_class::cdef_class_rep::load_all_methods () { // FIXME: re-scan class directory } @@ -515,7 +515,7 @@ } string_vector -cdef_class::cdef_class_rep::get_names (void) +cdef_class::cdef_class_rep::get_names () { std::set names; @@ -584,8 +584,7 @@ if (idx.front ().length () != 1) error ("invalid meta.class indexing"); - std::string nm = idx.front ()( - 0).xstring_value ("invalid meta.class indexing, expected a method or property name"); + std::string nm = idx.front ()(0).xstring_value ("invalid meta.class indexing, expected a method or property name"); cdef_method meth = find_method (nm); @@ -633,7 +632,7 @@ } void -cdef_class::cdef_class_rep::meta_release (void) +cdef_class::cdef_class_rep::meta_release () { cdef_manager& cdm = __get_cdef_manager__ (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-class.h --- a/libinterp/octave-value/cdef-class.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-class.h Mon Jan 30 18:36:03 2023 +0100 @@ -58,7 +58,7 @@ cdef_class_rep : public cdef_meta_object_rep { public: - cdef_class_rep (void) + cdef_class_rep () : cdef_meta_object_rep (), m_member_count (0), m_handle_class (false), m_meta (false) { } @@ -67,20 +67,20 @@ cdef_class_rep& operator = (const cdef_class_rep&) = delete; - ~cdef_class_rep (void) = default; + ~cdef_class_rep () = default; - cdef_object_rep * copy (void) const { return new cdef_class_rep (*this); } + cdef_object_rep * copy () const { return new cdef_class_rep (*this); } - bool is_class (void) const { return true; } + bool is_class () const { return true; } - std::string get_name (void) const + std::string get_name () const { return get ("Name").string_value (); } void set_name (const std::string& nm) { put ("Name", nm); } - bool is_abstract (void) const { return get ("Abstract").bool_value (); } + bool is_abstract () const { return get ("Abstract").bool_value (); } - bool is_sealed (void) const { return get ("Sealed").bool_value (); } + bool is_sealed () const { return get ("Sealed").bool_value (); } OCTINTERP_API cdef_method find_method (const std::string& nm, bool local = false); @@ -103,11 +103,11 @@ OCTINTERP_API std::map get_property_map (int mode); - OCTINTERP_API string_vector get_names (void); + OCTINTERP_API string_vector get_names (); void set_directory (const std::string& dir) { m_directory = dir; } - std::string get_directory (void) const { return m_directory; } + std::string get_directory () const { return m_directory; } OCTINTERP_API void delete_object (const cdef_object& obj); @@ -115,7 +115,7 @@ meta_subsref (const std::string& type, const std::list& idx, int nargout); - OCTINTERP_API void meta_release (void); + OCTINTERP_API void meta_release (); bool meta_accepts_postfix_index (char type) const { @@ -134,13 +134,13 @@ OCTINTERP_API void run_constructor (cdef_object& obj, const octave_value_list& args); - void mark_as_handle_class (void) { m_handle_class = true; } + void mark_as_handle_class () { m_handle_class = true; } - bool is_handle_class (void) const { return m_handle_class; } + bool is_handle_class () const { return m_handle_class; } - octave_idx_type static_count (void) const { return m_member_count; } + octave_idx_type static_count () const { return m_member_count; } - void destroy (void) + void destroy () { if (m_member_count) { @@ -155,21 +155,21 @@ delete this; } - void mark_as_meta_class (void) { m_meta = true; } + void mark_as_meta_class () { m_meta = true; } - bool is_meta_class (void) const { return m_meta; } + bool is_meta_class () const { return m_meta; } void doc_string (const std::string& txt) { m_doc_string = txt; } - std::string doc_string (void) const { return m_doc_string; } + std::string doc_string () const { return m_doc_string; } void file_name (const std::string& nm) { m_file_name = nm; } - std::string file_name (void) const { return m_file_name; } + std::string file_name () const { return m_file_name; } private: - OCTINTERP_API void load_all_methods (void); + OCTINTERP_API void load_all_methods (); OCTINTERP_API void find_names (std::set& names, bool all); @@ -181,7 +181,7 @@ find_methods (std::map& meths, bool only_inherited, bool include_ctor = false); - cdef_class wrap (void) + cdef_class wrap () { m_count++; return cdef_class (this); @@ -237,7 +237,7 @@ // Create an invalid class object. - cdef_class (void) : cdef_meta_object () { } + cdef_class () : cdef_meta_object () { } cdef_class (const std::string& nm, const std::list& superclasses) @@ -264,7 +264,7 @@ return *this; } - ~cdef_class (void) = default; + ~cdef_class () = default; OCTINTERP_API cdef_method find_method (const std::string& nm, bool local = false); @@ -303,25 +303,25 @@ return get_rep ()->get_property_map (mode); } - string_vector get_names (void) { return get_rep ()->get_names (); } + string_vector get_names () { return get_rep ()->get_names (); } - bool is_abstract (void) const { return get_rep ()->is_abstract (); } + bool is_abstract () const { return get_rep ()->is_abstract (); } - bool is_sealed (void) const { return get_rep ()->is_sealed (); } + bool is_sealed () const { return get_rep ()->is_sealed (); } void set_directory (const std::string& dir) { get_rep ()->set_directory (dir); } - std::string get_directory (void) const + std::string get_directory () const { return get_rep ()->get_directory (); } - std::string get_name (void) const { return get_rep ()->get_name (); } + std::string get_name () const { return get_rep ()->get_name (); } - bool is_builtin (void) const { return get_directory ().empty (); } + bool is_builtin () const { return get_directory ().empty (); } void delete_object (const cdef_object& obj) { @@ -359,7 +359,7 @@ OCTINTERP_API octave_value get_method_function (const std::string& nm); - octave_value get_constructor_function (void) + octave_value get_constructor_function () { return get_method_function (get_name ()); } @@ -384,27 +384,27 @@ get_rep ()->run_constructor (obj, args); } - void mark_as_handle_class (void) + void mark_as_handle_class () { get_rep ()->mark_as_handle_class (); } - bool is_handle_class (void) const + bool is_handle_class () const { return get_rep ()->is_handle_class (); } - void mark_as_meta_class (void) { get_rep ()->mark_as_meta_class (); } + void mark_as_meta_class () { get_rep ()->mark_as_meta_class (); } - bool is_meta_class (void) const { return get_rep ()->is_meta_class (); } + bool is_meta_class () const { return get_rep ()->is_meta_class (); } void doc_string (const std::string& txt) { get_rep ()->doc_string (txt); } - std::string doc_string (void) const { return get_rep ()->doc_string (); } + std::string doc_string () const { return get_rep ()->doc_string (); } void file_name (const std::string& nm) { get_rep ()->file_name (nm); } - std::string file_name (void) const { return get_rep ()->file_name (); } + std::string file_name () const { return get_rep ()->file_name (); } public: @@ -417,12 +417,12 @@ private: - cdef_class_rep * get_rep (void) + cdef_class_rep * get_rep () { return dynamic_cast (cdef_object::get_rep ()); } - const cdef_class_rep * get_rep (void) const + const cdef_class_rep * get_rep () const { return dynamic_cast (cdef_object::get_rep ()); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-manager.h --- a/libinterp/octave-value/cdef-manager.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-manager.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ cdef_manager& operator = (const cdef_manager&) = delete; - ~cdef_manager (void) = default; + ~cdef_manager () = default; OCTINTERP_API cdef_class find_class (const std::string& name, bool error_if_not_found = true, @@ -90,12 +90,12 @@ m_all_packages.erase (pkg.get_name ()); } - const cdef_class& meta_class (void) const { return m_meta_class; } - const cdef_class& meta_property (void) const { return m_meta_property; } - const cdef_class& meta_method (void) const { return m_meta_method; } - const cdef_class& meta_package (void) const { return m_meta_package; } + const cdef_class& meta_class () const { return m_meta_class; } + const cdef_class& meta_property () const { return m_meta_property; } + const cdef_class& meta_method () const { return m_meta_method; } + const cdef_class& meta_package () const { return m_meta_package; } - const cdef_package& meta (void) const { return m_meta; } + const cdef_package& meta () const { return m_meta; } OCTINTERP_API cdef_class make_class (const std::string& name, diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-method.cc --- a/libinterp/octave-value/cdef-method.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-method.cc Mon Jan 30 18:36:03 2023 +0100 @@ -68,7 +68,7 @@ } void -cdef_method::cdef_method_rep::check_method (void) +cdef_method::cdef_method_rep::check_method () { if (is_external ()) { @@ -134,7 +134,11 @@ check_method (); if (m_function.is_defined ()) - retval = feval (m_function, args, nargout); + { + interpreter& interp = __get_interpreter__ (); + + retval = interp.feval (m_function, args, nargout); + } return retval; } @@ -166,14 +170,16 @@ for (int i = 0; i < args.length (); i++) new_args(i+1) = args(i); - retval = feval (m_function, new_args, nargout); + interpreter& interp = __get_interpreter__ (); + + retval = interp.feval (m_function, new_args, nargout); } return retval; } bool -cdef_method::cdef_method_rep::is_constructor (void) const +cdef_method::cdef_method_rep::is_constructor () const { if (m_function.is_function()) return m_function.function_value ()->is_classdef_constructor (); @@ -190,7 +196,7 @@ } std::string -cdef_method::cdef_method_rep::get_doc_string (void) +cdef_method::cdef_method_rep::get_doc_string () { check_method (); @@ -200,7 +206,7 @@ } bool -cdef_method::cdef_method_rep::check_access (void) const +cdef_method::cdef_method_rep::check_access () const { cdef_class cls (to_cdef (get ("DefiningClass"))); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-method.h --- a/libinterp/octave-value/cdef-method.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-method.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,33 +52,33 @@ { public: - cdef_method_rep (void) + cdef_method_rep () : cdef_meta_object_rep (), m_function (), m_dispatch_type () { } cdef_method_rep& operator = (const cdef_method_rep& m) = delete; - ~cdef_method_rep (void) = default; + ~cdef_method_rep () = default; - cdef_object_rep * copy (void) const { return new cdef_method_rep(*this); } + cdef_object_rep * copy () const { return new cdef_method_rep(*this); } - bool is_method (void) const { return true; } + bool is_method () const { return true; } - std::string get_name (void) const { return get("Name").string_value (); } + std::string get_name () const { return get("Name").string_value (); } void set_name (const std::string& nm) { put ("Name", nm); } - bool is_static (void) const { return get("Static").bool_value (); } + bool is_static () const { return get("Static").bool_value (); } - octave_value get_function (void) const { return m_function; } + octave_value get_function () const { return m_function; } void set_function (const octave_value& fcn) { m_function = fcn; } - OCTINTERP_API std::string get_doc_string (void); + OCTINTERP_API std::string get_doc_string (); - OCTINTERP_API bool check_access (void) const; + OCTINTERP_API bool check_access () const; - bool is_external (void) const { return ! m_dispatch_type.empty (); } + bool is_external () const { return ! m_dispatch_type.empty (); } void mark_as_external (const std::string& dtype) { @@ -94,7 +94,7 @@ const octave_value_list& args, int nargout, bool do_check_access = true, const std::string& who = ""); - OCTINTERP_API bool is_constructor (void) const; + OCTINTERP_API bool is_constructor () const; OCTINTERP_API bool is_defined_in_class (const std::string& cname) const; @@ -114,9 +114,9 @@ m_dispatch_type (m.m_dispatch_type) { } - OCTINTERP_API void check_method (void); + OCTINTERP_API void check_method (); - cdef_method wrap (void) + cdef_method wrap () { m_count++; return cdef_method (this); @@ -132,7 +132,7 @@ public: - cdef_method (void) : cdef_meta_object () { } + cdef_method () : cdef_meta_object () { } cdef_method (const std::string& nm) : cdef_meta_object (new cdef_method_rep ()) @@ -158,7 +158,7 @@ return *this; } - ~cdef_method (void) = default; + ~cdef_method () = default; // normal invocation octave_value_list execute (const octave_value_list& args, int nargout, @@ -177,28 +177,28 @@ return get_rep ()->execute (obj, args, nargout, do_check_access, who); } - bool check_access (void) const { return get_rep ()->check_access (); } + bool check_access () const { return get_rep ()->check_access (); } - std::string get_name (void) const { return get_rep ()->get_name (); } + std::string get_name () const { return get_rep ()->get_name (); } - bool is_static (void) const { return get_rep ()->is_static (); } + bool is_static () const { return get_rep ()->is_static (); } void set_function (const octave_value& fcn) { get_rep ()->set_function (fcn); } - octave_value get_function (void) const + octave_value get_function () const { return get_rep ()->get_function (); } - std::string get_doc_string (void) + std::string get_doc_string () { return get_rep ()->get_doc_string (); } - bool is_constructor (void) const + bool is_constructor () const { return get_rep ()->is_constructor (); } @@ -208,7 +208,7 @@ return get_rep ()->is_defined_in_class (cname); } - bool is_external (void) const { return get_rep ()->is_external (); } + bool is_external () const { return get_rep ()->is_external (); } void mark_as_external (const std::string& dtype) { @@ -217,12 +217,12 @@ private: - cdef_method_rep * get_rep (void) + cdef_method_rep * get_rep () { return dynamic_cast (cdef_object::get_rep ()); } - const cdef_method_rep * get_rep (void) const + const cdef_method_rep * get_rep () const { return dynamic_cast (cdef_object::get_rep ()); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-object.cc --- a/libinterp/octave-value/cdef-object.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-object.cc Mon Jan 30 18:36:03 2023 +0100 @@ -111,19 +111,19 @@ } cdef_class -cdef_object_rep::get_class (void) const +cdef_object_rep::get_class () const { err_invalid_object ("get_class"); } std::string -cdef_object_rep::class_name (void) const +cdef_object_rep::class_name () const { return get_class ().get_name (); } string_vector -cdef_object_rep::map_keys (void) const +cdef_object_rep::map_keys () const { cdef_class cls = get_class (); @@ -134,7 +134,7 @@ } octave_map -cdef_object::map_value (void) const +cdef_object::map_value () const { octave_map retval; @@ -180,13 +180,13 @@ } cdef_class -cdef_object::get_class (void) const +cdef_object::get_class () const { return m_rep->get_class (); } cdef_class -cdef_object_base::get_class (void) const +cdef_object_base::get_class () const { return cdef_class (m_klass); } @@ -203,7 +203,7 @@ } cdef_object_rep * -cdef_object_base::make_array (void) const +cdef_object_base::make_array () const { cdef_object_rep *r = new cdef_object_array (); @@ -735,7 +735,7 @@ m_ctor_list.erase (cls); } -handle_cdef_object::~handle_cdef_object (void) +handle_cdef_object::~handle_cdef_object () { #if DEBUG_TRACE std::cerr << "deleting " << get_class ().get_name () @@ -743,7 +743,7 @@ #endif } -value_cdef_object::~value_cdef_object (void) +value_cdef_object::~value_cdef_object () { #if DEBUG_TRACE std::cerr << "deleting " << get_class ().get_name () diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-object.h --- a/libinterp/octave-value/cdef-object.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-object.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,48 +53,48 @@ friend class cdef_object; - cdef_object_rep (void) : m_count (1) { } + cdef_object_rep () : m_count (1) { } cdef_object_rep& operator = (const cdef_object_rep&) = delete; - virtual ~cdef_object_rep (void) = default; + virtual ~cdef_object_rep () = default; - virtual cdef_class get_class (void) const; + virtual cdef_class get_class () const; virtual void set_class (const cdef_class&) { err_invalid_object ("set_class"); } - virtual cdef_object_rep * clone (void) const + virtual cdef_object_rep * clone () const { err_invalid_object ("clone"); } - virtual cdef_object_rep * empty_clone (void) const + virtual cdef_object_rep * empty_clone () const { err_invalid_object ("empty_clone"); } - virtual cdef_object_rep * copy (void) const + virtual cdef_object_rep * copy () const { err_invalid_object ("copy"); } - virtual cdef_object_rep * make_array (void) const + virtual cdef_object_rep * make_array () const { err_invalid_object ("make_array"); } - virtual bool is_array (void) const { return false; } + virtual bool is_array () const { return false; } - virtual bool is_value_object (void) const { return false; } + virtual bool is_value_object () const { return false; } - virtual bool is_handle_object (void) const { return false; } + virtual bool is_handle_object () const { return false; } - virtual bool is_meta_object (void) const { return false; } + virtual bool is_meta_object () const { return false; } - virtual Array array_value (void) const + virtual Array array_value () const { err_invalid_object ("array_value"); } @@ -137,11 +137,11 @@ err_invalid_object ("subsasgn"); } - virtual string_vector map_keys (void) const; + virtual string_vector map_keys () const; - virtual bool is_valid (void) const { return false; } + virtual bool is_valid () const { return false; } - OCTINTERP_API std::string class_name (void) const; + OCTINTERP_API std::string class_name () const; virtual void mark_for_construction (const cdef_class&) { @@ -158,7 +158,7 @@ err_invalid_object ("is_partially_constructed_for"); } - virtual void mark_as_constructed (void) + virtual void mark_as_constructed () { err_invalid_object ("mark_as_constructed"); } @@ -168,18 +168,18 @@ err_invalid_object ("mark_as_constructed"); } - virtual bool is_constructed (void) const + virtual bool is_constructed () const { err_invalid_object ("is_constructed"); } - virtual octave_idx_type static_count (void) const { return 0; } + virtual octave_idx_type static_count () const { return 0; } - virtual void destroy (void) { delete this; } + virtual void destroy () { delete this; } OCTINTERP_API void release (const cdef_object& obj); - virtual dim_vector dims (void) const { return dim_vector (); } + virtual dim_vector dims () const { return dim_vector (); } protected: @@ -205,14 +205,14 @@ public: // FIXME: use a null object? - cdef_object (void) : m_rep (new cdef_object_rep ()) { } + cdef_object () : m_rep (new cdef_object_rep ()) { } cdef_object (const cdef_object& obj) : m_rep (obj.m_rep) { m_rep->m_count++; } cdef_object (cdef_object_rep *r) : m_rep (r) { } - virtual ~cdef_object (void) { m_rep->release (*this); } + virtual ~cdef_object () { m_rep->release (*this); } cdef_object& operator = (const cdef_object& obj) { @@ -227,37 +227,37 @@ return *this; } - OCTINTERP_API cdef_class get_class (void) const; + OCTINTERP_API cdef_class get_class () const; void set_class (const cdef_class& cls) { m_rep->set_class (cls); } - std::string class_name (void) const { return m_rep->class_name (); } + std::string class_name () const { return m_rep->class_name (); } - cdef_object clone (void) const { return cdef_object (m_rep->clone ()); } + cdef_object clone () const { return cdef_object (m_rep->clone ()); } - cdef_object empty_clone (void) const + cdef_object empty_clone () const { return cdef_object (m_rep->empty_clone ()); } - dim_vector dims (void) const { return m_rep->dims (); } + dim_vector dims () const { return m_rep->dims (); } - cdef_object make_array (void) const + cdef_object make_array () const { return cdef_object (m_rep->make_array ()); } - cdef_object copy (void) const { return cdef_object (m_rep->copy ()); } + cdef_object copy () const { return cdef_object (m_rep->copy ()); } - bool is_array (void) const { return m_rep->is_array (); } + bool is_array () const { return m_rep->is_array (); } - bool is_value_object (void) const { return m_rep->is_value_object (); } + bool is_value_object () const { return m_rep->is_value_object (); } - bool is_handle_object (void) const { return m_rep->is_handle_object (); } + bool is_handle_object () const { return m_rep->is_handle_object (); } - bool is_meta_object (void) const { return m_rep->is_meta_object (); } + bool is_meta_object () const { return m_rep->is_meta_object (); } - Array array_value (void) const + Array array_value () const { return m_rep->array_value (); } void put (const std::string& pname, const octave_value& val) @@ -303,20 +303,20 @@ return m_rep->subsasgn (type, idx, rhs); } - string_vector map_keys (void) const { return m_rep->map_keys (); } + string_vector map_keys () const { return m_rep->map_keys (); } - OCTINTERP_API octave_map map_value (void) const; + OCTINTERP_API octave_map map_value () const; - const cdef_object_rep * get_rep (void) const { return m_rep; } + const cdef_object_rep * get_rep () const { return m_rep; } - bool ok (void) const { return m_rep->is_valid (); } + bool ok () const { return m_rep->is_valid (); } void mark_for_construction (const cdef_class& cls) { m_rep->mark_for_construction (cls); } - bool is_constructed (void) const { return m_rep->is_constructed (); } + bool is_constructed () const { return m_rep->is_constructed (); } bool is_constructed_for (const cdef_class& cls) const { @@ -328,7 +328,7 @@ return m_rep->is_partially_constructed_for (cls); } - void mark_as_constructed (void) { m_rep->mark_as_constructed (); } + void mark_as_constructed () { m_rep->mark_as_constructed (); } void mark_as_constructed (const cdef_class& cls) { m_rep->mark_as_constructed (cls); } @@ -337,7 +337,7 @@ protected: - cdef_object_rep * get_rep (void) { return m_rep; } + cdef_object_rep * get_rep () { return m_rep; } void make_unique (int ignore_copies) { @@ -356,24 +356,24 @@ { public: - cdef_object_base (void) + cdef_object_base () : cdef_object_rep (), m_klass () { } cdef_object_base& operator = (const cdef_object_base&) = delete; - ~cdef_object_base (void) { } + ~cdef_object_base () { } - OCTINTERP_API cdef_class get_class (void) const; + OCTINTERP_API cdef_class get_class () const; OCTINTERP_API void set_class (const cdef_class& cls); - cdef_object_rep * empty_clone (void) const + cdef_object_rep * empty_clone () const { return new cdef_object_base (*this); } - OCTINTERP_API cdef_object_rep * make_array (void) const; + OCTINTERP_API cdef_object_rep * make_array () const; protected: @@ -394,7 +394,7 @@ { public: - cdef_object_array (void) : cdef_object_base () { } + cdef_object_array () : cdef_object_base () { } cdef_object_array (const Array& a) : cdef_object_base (), m_array (a) @@ -402,20 +402,20 @@ cdef_object_array& operator = (const cdef_object_array&) = delete; - ~cdef_object_array (void) = default; + ~cdef_object_array () = default; - cdef_object_rep * clone (void) const + cdef_object_rep * clone () const { return new cdef_object_array (*this); } - dim_vector dims (void) const { return m_array.dims (); } + dim_vector dims () const { return m_array.dims (); } - bool is_valid (void) const { return true; } + bool is_valid () const { return true; } - bool is_array (void) const { return true; } + bool is_array () const { return true; } - Array array_value (void) const { return m_array; } + Array array_value () const { return m_array; } OCTINTERP_API octave_value_list subsref (const std::string& type, const std::list& idx, @@ -446,7 +446,7 @@ Array m_array; - void fill_empty_values (void) { fill_empty_values (m_array); } + void fill_empty_values () { fill_empty_values (m_array); } OCTINTERP_API void fill_empty_values (Array& arr); @@ -462,13 +462,13 @@ { public: - cdef_object_scalar (void) : cdef_object_base () { } + cdef_object_scalar () : cdef_object_base () { } cdef_object_scalar& operator = (const cdef_object_scalar&) = delete; - ~cdef_object_scalar (void) = default; + ~cdef_object_scalar () = default; - dim_vector dims (void) const { return dim_vector (1, 1); } + dim_vector dims () const { return dim_vector (1, 1); } void break_closure_cycles (const std::shared_ptr& frame); @@ -521,11 +521,11 @@ OCTINTERP_API bool is_partially_constructed_for (const cdef_class& cls) const; - void mark_as_constructed (void) { m_ctor_list.clear (); } + void mark_as_constructed () { m_ctor_list.clear (); } OCTINTERP_API void mark_as_constructed (const cdef_class& cls); - bool is_constructed (void) const { return m_ctor_list.empty (); } + bool is_constructed () const { return m_ctor_list.empty (); } protected: @@ -549,27 +549,27 @@ { public: - handle_cdef_object (void) : cdef_object_scalar () { } + handle_cdef_object () : cdef_object_scalar () { } handle_cdef_object& operator = (const handle_cdef_object&) = delete; - OCTINTERP_API ~handle_cdef_object (void); + OCTINTERP_API ~handle_cdef_object (); - cdef_object_rep * clone (void) const + cdef_object_rep * clone () const { handle_cdef_object *obj = const_cast (this); obj->m_count++; return obj; } - cdef_object_rep * copy (void) const + cdef_object_rep * copy () const { return new handle_cdef_object (*this); } - bool is_valid (void) const { return true; } + bool is_valid () const { return true; } - bool is_handle_object (void) const { return true; } + bool is_handle_object () const { return true; } protected: @@ -585,22 +585,22 @@ { public: - value_cdef_object (void) : cdef_object_scalar () { } + value_cdef_object () : cdef_object_scalar () { } value_cdef_object& operator = (const value_cdef_object&) = delete; - OCTINTERP_API ~value_cdef_object (void); + OCTINTERP_API ~value_cdef_object (); - cdef_object_rep * clone (void) const + cdef_object_rep * clone () const { return new value_cdef_object (*this); } - cdef_object_rep * copy (void) const { return clone (); } + cdef_object_rep * copy () const { return clone (); } - bool is_valid (void) const { return true; } + bool is_valid () const { return true; } - bool is_value_object (void) const { return true; } + bool is_value_object () const { return true; } private: @@ -616,24 +616,24 @@ { public: - cdef_meta_object_rep (void) : handle_cdef_object () { } + cdef_meta_object_rep () : handle_cdef_object () { } cdef_meta_object_rep& operator = (const cdef_meta_object_rep&) = delete; - ~cdef_meta_object_rep (void) = default; + ~cdef_meta_object_rep () = default; - cdef_object_rep * copy (void) const + cdef_object_rep * copy () const { return new cdef_meta_object_rep (*this); } - bool is_meta_object (void) const { return true; } + bool is_meta_object () const { return true; } - virtual bool is_class (void) const { return false; } + virtual bool is_class () const { return false; } - virtual bool is_property (void) const { return false; } + virtual bool is_property () const { return false; } - virtual bool is_method (void) const { return false; } + virtual bool is_method () const { return false; } - virtual bool is_package (void) const { return false; } + virtual bool is_package () const { return false; } virtual octave_value_list meta_subsref (const std::string& /* type */, @@ -643,7 +643,7 @@ error ("subsref: invalid meta object"); } - virtual void meta_release (void) { } + virtual void meta_release () { } virtual bool meta_accepts_postfix_index (char /* type */) const { @@ -664,7 +664,7 @@ { public: - cdef_meta_object (void) : cdef_object () { } + cdef_meta_object () : cdef_object () { } // Object consistency is checked in sub-classes. cdef_meta_object (const cdef_meta_object& obj) : cdef_object (obj) { } @@ -675,15 +675,15 @@ cdef_meta_object& operator = (const cdef_object&) = delete; - ~cdef_meta_object (void) = default; + ~cdef_meta_object () = default; - bool is_class (void) const { return get_rep ()->is_class (); } + bool is_class () const { return get_rep ()->is_class (); } - bool is_property (void) const { return get_rep ()->is_property (); } + bool is_property () const { return get_rep ()->is_property (); } - bool is_method (void) const { return get_rep ()->is_method (); } + bool is_method () const { return get_rep ()->is_method (); } - bool is_package (void) const { return get_rep ()->is_package (); } + bool is_package () const { return get_rep ()->is_package (); } octave_value_list meta_subsref (const std::string& type, @@ -692,7 +692,7 @@ return get_rep ()->meta_subsref (type, idx, nargout); } - void meta_release (void) { get_rep ()->meta_release (); } + void meta_release () { get_rep ()->meta_release (); } bool meta_accepts_postfix_index (char type) const { @@ -701,12 +701,12 @@ private: - cdef_meta_object_rep * get_rep (void) + cdef_meta_object_rep * get_rep () { return dynamic_cast (cdef_object::get_rep ()); } - const cdef_meta_object_rep * get_rep (void) const + const cdef_meta_object_rep * get_rep () const { return dynamic_cast (cdef_object::get_rep ()); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-package.cc --- a/libinterp/octave-value/cdef-package.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-package.cc Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,6 @@ #include "ov-classdef.h" #include "ov-fcn-handle.h" #include "ov-usr-fcn.h" -#include "parse.h" #include "pt-assign.h" #include "pt-classdef.h" #include "pt-idx.h" @@ -92,19 +91,19 @@ } Cell -cdef_package::cdef_package_rep::get_classes (void) const +cdef_package::cdef_package_rep::get_classes () const { return map2Cell (m_class_map); } Cell -cdef_package::cdef_package_rep::get_functions (void) const +cdef_package::cdef_package_rep::get_functions () const { return map2Cell (m_function_map); } Cell -cdef_package::cdef_package_rep::get_packages (void) const +cdef_package::cdef_package_rep::get_packages () const { return map2Cell (m_package_map); } @@ -133,8 +132,7 @@ if (idx.front ().length () != 1) error ("invalid meta.package indexing"); - std::string nm = idx.front ()( - 0).xstring_value ("invalid meta.package indexing, expected a symbol name"); + std::string nm = idx.front ()(0).xstring_value ("invalid meta.package indexing, expected a symbol name"); #if DEBUG_TRACE std::cerr << "meta.package query: " << nm << std::endl; @@ -161,7 +159,9 @@ { octave_value_list tmp_args; - retval = feval (o, tmp_args, nargout); + interpreter& interp = __get_interpreter__ (); + + retval = interp.feval (o, tmp_args, nargout); } else retval(0) = o; @@ -186,7 +186,7 @@ } void -cdef_package::cdef_package_rep::meta_release (void) +cdef_package::cdef_package_rep::meta_release () { // FIXME: Do we really want to unregister the package, as it // could still be referenced by classes or sub-packages? diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-package.h --- a/libinterp/octave-value/cdef-package.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-package.h Mon Jan 30 18:36:03 2023 +0100 @@ -55,18 +55,18 @@ { public: - cdef_package_rep (void) : cdef_meta_object_rep (), m_member_count (0) { } + cdef_package_rep () : cdef_meta_object_rep (), m_member_count (0) { } cdef_package_rep& operator = (const cdef_package_rep&) = delete; - ~cdef_package_rep (void) = default; + ~cdef_package_rep () = default; - cdef_object_rep * copy (void) const + cdef_object_rep * copy () const { return new cdef_package_rep (*this); } - bool is_package (void) const { return true; } + bool is_package () const { return true; } - std::string get_name (void) const { return get("Name").string_value (); } + std::string get_name () const { return get("Name").string_value (); } void set_name (const std::string& nm) { put ("Name", nm); } @@ -79,15 +79,15 @@ OCTINTERP_API void install_package (const cdef_package& pack, const std::string& nm); - OCTINTERP_API Cell get_classes (void) const; + OCTINTERP_API Cell get_classes () const; - OCTINTERP_API Cell get_functions (void) const; + OCTINTERP_API Cell get_functions () const; - OCTINTERP_API Cell get_packages (void) const; + OCTINTERP_API Cell get_packages () const; - octave_idx_type static_count (void) const { return m_member_count; } + octave_idx_type static_count () const { return m_member_count; } - void destroy (void) + void destroy () { if (m_member_count) { @@ -106,7 +106,7 @@ meta_subsref (const std::string& type, const std::list& idx, int nargout); - OCTINTERP_API void meta_release (void); + OCTINTERP_API void meta_release (); bool meta_accepts_postfix_index (char type) const { @@ -141,7 +141,7 @@ m_package_map (p.m_package_map), m_member_count (p.m_member_count) { } - cdef_package wrap (void) + cdef_package wrap () { m_count++; return cdef_package (this); @@ -150,7 +150,7 @@ public: - cdef_package (void) : cdef_meta_object () { } + cdef_package () : cdef_meta_object () { } cdef_package (const std::string& nm) : cdef_meta_object (new cdef_package_rep ()) @@ -176,7 +176,7 @@ return *this; } - ~cdef_package (void) = default; + ~cdef_package () = default; void install_class (const cdef_class& cls, const std::string& nm) { @@ -193,22 +193,22 @@ get_rep ()->install_package (pack, nm); } - Cell get_classes (void) const + Cell get_classes () const { return get_rep ()->get_classes (); } - Cell get_functions (void) const + Cell get_functions () const { return get_rep ()->get_functions (); } - Cell get_packages (void) const + Cell get_packages () const { return get_rep ()->get_packages (); } - std::string get_name (void) const { return get_rep ()->get_name (); } + std::string get_name () const { return get_rep ()->get_name (); } octave_value find (const std::string& nm) { @@ -217,12 +217,12 @@ private: - cdef_package_rep * get_rep (void) + cdef_package_rep * get_rep () { return dynamic_cast (cdef_object::get_rep ()); } - const cdef_package_rep * get_rep (void) const + const cdef_package_rep * get_rep () const { return dynamic_cast (cdef_object::get_rep ()); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-property.cc --- a/libinterp/octave-value/cdef-property.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-property.cc Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,6 @@ #include "ov-classdef.h" #include "ov-fcn-handle.h" #include "ov-usr-fcn.h" -#include "parse.h" #include "pt-assign.h" #include "pt-classdef.h" #include "pt-eval.h" @@ -133,7 +132,9 @@ args(0) = to_ov (obj); - args = feval (get_fcn, args, 1); + interpreter& interp = __get_interpreter__ (); + + args = interp.feval (get_fcn, args, 1); retval = args(0); } @@ -207,11 +208,13 @@ args(0) = to_ov (obj); args(1) = val; + interpreter& interp = __get_interpreter__ (); + if (obj.is_handle_object ()) - feval (set_fcn, args, 0); + interp.feval (set_fcn, args, 0); else { - args = feval (set_fcn, args, 1); + args = interp.feval (set_fcn, args, 1); if (args.length () > 0 && args(0).is_defined ()) { @@ -230,7 +233,7 @@ } bool -cdef_property::cdef_property_rep::check_get_access (void) const +cdef_property::cdef_property_rep::check_get_access () const { cdef_class cls (to_cdef (get ("DefiningClass"))); @@ -240,7 +243,7 @@ } bool -cdef_property::cdef_property_rep::check_set_access (void) const +cdef_property::cdef_property_rep::check_set_access () const { cdef_class cls (to_cdef (get ("DefiningClass"))); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-property.h --- a/libinterp/octave-value/cdef-property.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-property.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,24 +53,24 @@ { public: - cdef_property_rep (void) : cdef_meta_object_rep () { } + cdef_property_rep () : cdef_meta_object_rep () { } cdef_property_rep& operator = (const cdef_property_rep& p) = delete; - ~cdef_property_rep (void) = default; + ~cdef_property_rep () = default; - cdef_object_rep * copy (void) const + cdef_object_rep * copy () const { return new cdef_property_rep (*this); } - bool is_property (void) const { return true; } + bool is_property () const { return true; } - std::string get_name (void) const { return get("Name").string_value (); } + std::string get_name () const { return get("Name").string_value (); } void set_name (const std::string& nm) { put ("Name", nm); } - bool is_constant (void) const { return get("Constant").bool_value (); } + bool is_constant () const { return get("Constant").bool_value (); } octave_value get_value (bool do_check_access = true, const std::string& who = "") const; @@ -83,9 +83,9 @@ bool do_check_access = true, const std::string& who = ""); - OCTINTERP_API bool check_get_access (void) const; + OCTINTERP_API bool check_get_access () const; - OCTINTERP_API bool check_set_access (void) const; + OCTINTERP_API bool check_set_access () const; private: cdef_property_rep (const cdef_property_rep& p) @@ -94,7 +94,7 @@ OCTINTERP_API bool is_recursive_set (const cdef_object& obj) const; - cdef_property wrap (void) + cdef_property wrap () { m_count++; return cdef_property (this); @@ -107,7 +107,7 @@ public: - cdef_property (void) : cdef_meta_object () { } + cdef_property () : cdef_meta_object () { } cdef_property (const std::string& nm) : cdef_meta_object (new cdef_property_rep ()) @@ -133,7 +133,7 @@ return *this; } - ~cdef_property (void) = default; + ~cdef_property () = default; octave_value get_value (const cdef_object& obj, bool do_check_access = true, const std::string& who = "") const @@ -154,28 +154,28 @@ get_rep ()->set_value (obj, val, do_check_access, who); } - bool check_get_access (void) const + bool check_get_access () const { return get_rep ()->check_get_access (); } - bool check_set_access (void) const + bool check_set_access () const { return get_rep ()->check_set_access (); } - std::string get_name (void) const { return get_rep ()->get_name (); } + std::string get_name () const { return get_rep ()->get_name (); } - bool is_constant (void) const { return get_rep ()->is_constant (); } + bool is_constant () const { return get_rep ()->is_constant (); } private: - cdef_property_rep * get_rep (void) + cdef_property_rep * get_rep () { return dynamic_cast (cdef_object::get_rep ()); } - const cdef_property_rep * get_rep (void) const + const cdef_property_rep * get_rep () const { return dynamic_cast (cdef_object::get_rep ()); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-utils.cc --- a/libinterp/octave-value/cdef-utils.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-utils.cc Mon Jan 30 18:36:03 2023 +0100 @@ -282,7 +282,7 @@ } cdef_class -get_class_context (void) +get_class_context () { std::string dummy_string; bool dummy_bool; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/cdef-utils.h --- a/libinterp/octave-value/cdef-utils.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/cdef-utils.h Mon Jan 30 18:36:03 2023 +0100 @@ -99,7 +99,7 @@ get_class_context (std::string& name, bool& in_constructor); extern OCTINTERP_API cdef_class -get_class_context (void); +get_class_context (); extern OCTINTERP_API bool check_access (const cdef_class& cls, const octave_value& acc, diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-diag.cc --- a/libinterp/octave-value/ov-base-diag.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-diag.cc Mon Jan 30 18:36:03 2023 +0100 @@ -279,7 +279,7 @@ // Return true if this matrix has all true elements (non-zero, not NA/NaN). template bool -octave_base_diag::is_true (void) const +octave_base_diag::is_true () const { if (dims ().numel () > 1) { @@ -473,7 +473,7 @@ template float_display_format -octave_base_diag::get_edit_display_format (void) const +octave_base_diag::get_edit_display_format () const { // FIXME return float_display_format (); @@ -551,7 +551,7 @@ template bool -octave_base_diag::print_as_scalar (void) const +octave_base_diag::print_as_scalar () const { dim_vector dv = dims (); @@ -657,7 +657,7 @@ template octave_value -octave_base_diag::to_dense (void) const +octave_base_diag::to_dense () const { if (! m_dense_cache.is_defined ()) m_dense_cache = MT (m_matrix); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-diag.h --- a/libinterp/octave-value/ov-base-diag.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-diag.h Mon Jan 30 18:36:03 2023 +0100 @@ -50,7 +50,7 @@ public: - octave_base_diag (void) + octave_base_diag () : octave_base_value (), m_matrix (), m_dense_cache () { } octave_base_diag (const DMT& m) @@ -60,13 +60,13 @@ octave_base_diag (const octave_base_diag& m) : octave_base_value (), m_matrix (m.m_matrix), m_dense_cache () { } - ~octave_base_diag (void) = default; + ~octave_base_diag () = default; - std::size_t byte_size (void) const { return m_matrix.byte_size (); } + std::size_t byte_size () const { return m_matrix.byte_size (); } - octave_value squeeze (void) const { return m_matrix; } + octave_value squeeze () const { return m_matrix; } - octave_value full_value (void) const { return to_dense (); } + octave_value full_value () const { return to_dense (); } // We don't need to override all three forms of subsref. The using // declaration will avoid warnings about partially-overloaded virtual @@ -87,9 +87,9 @@ subsasgn (const std::string& type, const std::list& idx, const octave_value& rhs); - dim_vector dims (void) const { return m_matrix.dims (); } + dim_vector dims () const { return m_matrix.dims (); } - octave_idx_type nnz (void) const { return diag ().nnz (); } + octave_idx_type nnz () const { return diag ().nnz (); } octave_value reshape (const dim_vector& new_dims) const { return to_dense ().reshape (new_dims); } @@ -110,7 +110,7 @@ octave_value all (int dim = 0) const { return MT (m_matrix).all (dim); } octave_value any (int dim = 0) const { return MT (m_matrix).any (dim); } - MatrixType matrix_type (void) const { return MatrixType::Diagonal; } + MatrixType matrix_type () const { return MatrixType::Diagonal; } MatrixType matrix_type (const MatrixType&) const { return matrix_type (); } @@ -136,17 +136,17 @@ sortmode is_sorted_rows (sortmode mode = UNSORTED) const { return to_dense ().is_sorted_rows (mode); } - bool is_matrix_type (void) const { return true; } + bool is_matrix_type () const { return true; } - bool isnumeric (void) const { return true; } + bool isnumeric () const { return true; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - OCTINTERP_API bool is_true (void) const; + OCTINTERP_API bool is_true () const; - bool is_diag_matrix (void) const { return true; } + bool is_diag_matrix () const { return true; } OCTINTERP_API double double_value (bool = false) const; @@ -190,28 +190,28 @@ sparse_complex_matrix_value (bool = false) const; int8NDArray - int8_array_value (void) const { return to_dense ().int8_array_value (); } + int8_array_value () const { return to_dense ().int8_array_value (); } int16NDArray - int16_array_value (void) const { return to_dense ().int16_array_value (); } + int16_array_value () const { return to_dense ().int16_array_value (); } int32NDArray - int32_array_value (void) const { return to_dense ().int32_array_value (); } + int32_array_value () const { return to_dense ().int32_array_value (); } int64NDArray - int64_array_value (void) const { return to_dense ().int64_array_value (); } + int64_array_value () const { return to_dense ().int64_array_value (); } uint8NDArray - uint8_array_value (void) const { return to_dense ().uint8_array_value (); } + uint8_array_value () const { return to_dense ().uint8_array_value (); } uint16NDArray - uint16_array_value (void) const { return to_dense ().uint16_array_value (); } + uint16_array_value () const { return to_dense ().uint16_array_value (); } uint32NDArray - uint32_array_value (void) const { return to_dense ().uint32_array_value (); } + uint32_array_value () const { return to_dense ().uint32_array_value (); } uint64NDArray - uint64_array_value (void) const { return to_dense ().uint64_array_value (); } + uint64_array_value () const { return to_dense ().uint64_array_value (); } OCTINTERP_API octave_value convert_to_str_internal (bool pad, bool force, char type) const; @@ -219,7 +219,7 @@ OCTINTERP_API void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - OCTINTERP_API float_display_format get_edit_display_format (void) const; + OCTINTERP_API float_display_format get_edit_display_format () const; OCTINTERP_API std::string edit_display (const float_display_format& fmt, @@ -236,7 +236,7 @@ OCTINTERP_API mxArray * as_mxArray (bool interleaved) const; - OCTINTERP_API bool print_as_scalar (void) const; + OCTINTERP_API bool print_as_scalar () const; OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -251,7 +251,7 @@ DMT m_matrix; - OCTINTERP_API octave_value to_dense (void) const; + OCTINTERP_API octave_value to_dense () const; virtual bool chk_valid_scalar (const octave_value&, typename DMT::element_type&) const = 0; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-int.cc --- a/libinterp/octave-value/ov-base-int.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-int.cc Mon Jan 30 18:36:03 2023 +0100 @@ -144,7 +144,7 @@ template octave_base_value * -octave_base_int_matrix::try_narrowing_conversion (void) +octave_base_int_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -205,70 +205,70 @@ template octave_value -octave_base_int_matrix::as_double (void) const +octave_base_int_matrix::as_double () const { return NDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_single (void) const +octave_base_int_matrix::as_single () const { return FloatNDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_int8 (void) const +octave_base_int_matrix::as_int8 () const { return int8NDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_int16 (void) const +octave_base_int_matrix::as_int16 () const { return int16NDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_int32 (void) const +octave_base_int_matrix::as_int32 () const { return int32NDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_int64 (void) const +octave_base_int_matrix::as_int64 () const { return int64NDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_uint8 (void) const +octave_base_int_matrix::as_uint8 () const { return uint8NDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_uint16 (void) const +octave_base_int_matrix::as_uint16 () const { return uint16NDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_uint32 (void) const +octave_base_int_matrix::as_uint32 () const { return uint32NDArray (this->m_matrix); } template octave_value -octave_base_int_matrix::as_uint64 (void) const +octave_base_int_matrix::as_uint64 () const { return uint64NDArray (this->m_matrix); } @@ -599,70 +599,70 @@ template octave_value -octave_base_int_scalar::as_double (void) const +octave_base_int_scalar::as_double () const { return static_cast (this->scalar); } template octave_value -octave_base_int_scalar::as_single (void) const +octave_base_int_scalar::as_single () const { return static_cast (this->scalar); } template octave_value -octave_base_int_scalar::as_int8 (void) const +octave_base_int_scalar::as_int8 () const { return octave_int8 (this->scalar); } template octave_value -octave_base_int_scalar::as_int16 (void) const +octave_base_int_scalar::as_int16 () const { return octave_int16 (this->scalar); } template octave_value -octave_base_int_scalar::as_int32 (void) const +octave_base_int_scalar::as_int32 () const { return octave_int32 (this->scalar); } template octave_value -octave_base_int_scalar::as_int64 (void) const +octave_base_int_scalar::as_int64 () const { return octave_int64 (this->scalar); } template octave_value -octave_base_int_scalar::as_uint8 (void) const +octave_base_int_scalar::as_uint8 () const { return octave_uint8 (this->scalar); } template octave_value -octave_base_int_scalar::as_uint16 (void) const +octave_base_int_scalar::as_uint16 () const { return octave_uint16 (this->scalar); } template octave_value -octave_base_int_scalar::as_uint32 (void) const +octave_base_int_scalar::as_uint32 () const { return octave_uint32 (this->scalar); } template octave_value -octave_base_int_scalar::as_uint64 (void) const +octave_base_int_scalar::as_uint64 () const { return octave_uint64 (this->scalar); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-int.h --- a/libinterp/octave-value/ov-base-int.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-int.h Mon Jan 30 18:36:03 2023 +0100 @@ -51,25 +51,25 @@ { public: - octave_base_int_matrix (void) : octave_base_matrix () { } + octave_base_int_matrix () : octave_base_matrix () { } octave_base_int_matrix (const T& nda) : octave_base_matrix (nda) { } - ~octave_base_int_matrix (void) = default; + ~octave_base_int_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_base_int_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_base_int_matrix (); } - OCTINTERP_API octave_base_value * try_narrowing_conversion (void); + OCTINTERP_API octave_base_value * try_narrowing_conversion (); - bool isreal (void) const { return true; } + bool isreal () const { return true; } - // void increment (void) { matrix += 1; } + // void increment () { matrix += 1; } - // void decrement (void) { matrix -= 1; } + // void decrement () { matrix -= 1; } OCTINTERP_API void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; @@ -77,18 +77,18 @@ OCTINTERP_API octave_value convert_to_str_internal (bool, bool, char type) const; - OCTINTERP_API octave_value as_double (void) const; - OCTINTERP_API octave_value as_single (void) const; + OCTINTERP_API octave_value as_double () const; + OCTINTERP_API octave_value as_single () const; - OCTINTERP_API octave_value as_int8 (void) const; - OCTINTERP_API octave_value as_int16 (void) const; - OCTINTERP_API octave_value as_int32 (void) const; - OCTINTERP_API octave_value as_int64 (void) const; + OCTINTERP_API octave_value as_int8 () const; + OCTINTERP_API octave_value as_int16 () const; + OCTINTERP_API octave_value as_int32 () const; + OCTINTERP_API octave_value as_int64 () const; - OCTINTERP_API octave_value as_uint8 (void) const; - OCTINTERP_API octave_value as_uint16 (void) const; - OCTINTERP_API octave_value as_uint32 (void) const; - OCTINTERP_API octave_value as_uint64 (void) const; + OCTINTERP_API octave_value as_uint8 () const; + OCTINTERP_API octave_value as_uint16 () const; + OCTINTERP_API octave_value as_uint32 () const; + OCTINTERP_API octave_value as_uint64 () const; OCTINTERP_API std::string edit_display (const float_display_format& fmt, @@ -123,42 +123,42 @@ { public: - octave_base_int_scalar (void) : octave_base_scalar () { } + octave_base_int_scalar () : octave_base_scalar () { } octave_base_int_scalar (const T& s) : octave_base_scalar (s) { } - ~octave_base_int_scalar (void) = default; + ~octave_base_int_scalar () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_base_int_scalar (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_base_int_scalar (); } - octave_base_value * try_narrowing_conversion (void) { return nullptr; } + octave_base_value * try_narrowing_conversion () { return nullptr; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_real_scalar (void) const { return true; } + bool is_real_scalar () const { return true; } - // void increment (void) { scalar += 1; } + // void increment () { scalar += 1; } - // void decrement (void) { scalar -= 1; } + // void decrement () { scalar -= 1; } OCTINTERP_API octave_value convert_to_str_internal (bool, bool, char type) const; - OCTINTERP_API octave_value as_double (void) const; - OCTINTERP_API octave_value as_single (void) const; + OCTINTERP_API octave_value as_double () const; + OCTINTERP_API octave_value as_single () const; - OCTINTERP_API octave_value as_int8 (void) const; - OCTINTERP_API octave_value as_int16 (void) const; - OCTINTERP_API octave_value as_int32 (void) const; - OCTINTERP_API octave_value as_int64 (void) const; + OCTINTERP_API octave_value as_int8 () const; + OCTINTERP_API octave_value as_int16 () const; + OCTINTERP_API octave_value as_int32 () const; + OCTINTERP_API octave_value as_int64 () const; - OCTINTERP_API octave_value as_uint8 (void) const; - OCTINTERP_API octave_value as_uint16 (void) const; - OCTINTERP_API octave_value as_uint32 (void) const; - OCTINTERP_API octave_value as_uint64 (void) const; + OCTINTERP_API octave_value as_uint8 () const; + OCTINTERP_API octave_value as_uint16 () const; + OCTINTERP_API octave_value as_uint32 () const; + OCTINTERP_API octave_value as_uint64 () const; OCTINTERP_API std::string edit_display (const float_display_format& fmt, diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-mat.cc --- a/libinterp/octave-value/ov-base-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -420,7 +420,7 @@ // Return true if this matrix has all true elements (non-zero, not NA/NaN). template bool -octave_base_matrix::is_true (void) const +octave_base_matrix::is_true () const { bool retval = false; dim_vector dv = m_matrix.dims (); @@ -446,7 +446,7 @@ template bool -octave_base_matrix::print_as_scalar (void) const +octave_base_matrix::print_as_scalar () const { dim_vector dv = dims (); @@ -523,7 +523,7 @@ template float_display_format -octave_base_matrix::get_edit_display_format (void) const +octave_base_matrix::get_edit_display_format () const { return make_format (m_matrix); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-mat.h --- a/libinterp/octave-value/ov-base-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ typedef MT object_type; - octave_base_matrix (void) + octave_base_matrix () : octave_base_value (), m_matrix (), m_typ (), m_idx_cache () { } octave_base_matrix (const MT& m, const MatrixType& t = MatrixType ()) @@ -71,15 +71,15 @@ : nullptr) { } - ~octave_base_matrix (void) { clear_cached_info (); } + ~octave_base_matrix () { clear_cached_info (); } - std::size_t byte_size (void) const { return m_matrix.byte_size (); } + std::size_t byte_size () const { return m_matrix.byte_size (); } - octave_value squeeze (void) const { return MT (m_matrix.squeeze ()); } + octave_value squeeze () const { return MT (m_matrix.squeeze ()); } - octave_value full_value (void) const { return m_matrix; } + octave_value full_value () const { return m_matrix; } - void maybe_economize (void) { m_matrix.maybe_economize (); } + void maybe_economize () { m_matrix.maybe_economize (); } // We don't need to override all three forms of subsref. The using // declaration will avoid warnings about partially-overloaded virtual @@ -114,13 +114,13 @@ OCTINTERP_API void delete_elements (const octave_value_list& idx); - dim_vector dims (void) const { return m_matrix.dims (); } + dim_vector dims () const { return m_matrix.dims (); } - octave_idx_type numel (void) const { return m_matrix.numel (); } + octave_idx_type numel () const { return m_matrix.numel (); } - int ndims (void) const { return m_matrix.ndims (); } + int ndims () const { return m_matrix.ndims (); } - octave_idx_type nnz (void) const { return m_matrix.nnz (); } + octave_idx_type nnz () const { return m_matrix.nnz (); } octave_value reshape (const dim_vector& new_dims) const { return MT (m_matrix.reshape (new_dims)); } @@ -133,7 +133,7 @@ octave_value all (int dim = 0) const { return m_matrix.all (dim); } octave_value any (int dim = 0) const { return m_matrix.any (dim); } - MatrixType matrix_type (void) const { return m_typ ? *m_typ : MatrixType (); } + MatrixType matrix_type () const { return m_typ ? *m_typ : MatrixType (); } MatrixType matrix_type (const MatrixType& _typ) const; octave_value diag (octave_idx_type k = 0) const @@ -157,17 +157,17 @@ sortmode is_sorted_rows (sortmode mode = UNSORTED) const { return m_matrix.is_sorted_rows (mode); } - bool is_matrix_type (void) const { return true; } + bool is_matrix_type () const { return true; } - bool isnumeric (void) const { return true; } + bool isnumeric () const { return true; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - OCTINTERP_API bool is_true (void) const; + OCTINTERP_API bool is_true () const; - OCTINTERP_API bool print_as_scalar (void) const; + OCTINTERP_API bool print_as_scalar () const; OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -176,19 +176,19 @@ OCTINTERP_API void short_disp (std::ostream& os) const; - OCTINTERP_API float_display_format get_edit_display_format (void) const; + OCTINTERP_API float_display_format get_edit_display_format () const; OCTINTERP_API std::string edit_display (const float_display_format& fmt, octave_idx_type i, octave_idx_type j) const; - MT& matrix_ref (void) + MT& matrix_ref () { clear_cached_info (); return m_matrix; } - const MT& matrix_ref (void) const + const MT& matrix_ref () const { return m_matrix; } @@ -201,7 +201,7 @@ // This function exists to support the MEX interface. // You should not use it anywhere else. - const void * mex_get_data (void) const { return m_matrix.data (); } + const void * mex_get_data () const { return m_matrix.data (); } protected: @@ -214,7 +214,7 @@ return idx; } - void clear_cached_info (void) const + void clear_cached_info () const { delete m_typ; m_typ = nullptr; delete m_idx_cache; m_idx_cache = nullptr; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-scalar.cc --- a/libinterp/octave-value/ov-base-scalar.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-scalar.cc Mon Jan 30 18:36:03 2023 +0100 @@ -107,7 +107,7 @@ template dim_vector -octave_base_scalar::dims (void) const +octave_base_scalar::dims () const { static dim_vector dv (1, 1); return dv; @@ -143,7 +143,7 @@ template bool -octave_base_scalar::is_true (void) const +octave_base_scalar::is_true () const { if (octave::math::isnan (scalar)) octave::err_nan_to_logical_conversion (); @@ -194,7 +194,7 @@ template float_display_format -octave_base_scalar::get_edit_display_format (void) const +octave_base_scalar::get_edit_display_format () const { return make_format (scalar); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-scalar.h --- a/libinterp/octave-value/ov-base-scalar.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-scalar.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ typedef ST scalar_type; - octave_base_scalar (void) + octave_base_scalar () : octave_base_value (), scalar () { } octave_base_scalar (const ST& s) @@ -61,11 +61,11 @@ octave_base_scalar (const octave_base_scalar& s) : octave_base_value (), scalar (s.scalar) { } - ~octave_base_scalar (void) = default; + ~octave_base_scalar () = default; - octave_value squeeze (void) const { return scalar; } + octave_value squeeze () const { return scalar; } - octave_value full_value (void) const { return scalar; } + octave_value full_value () const { return scalar; } // We don't need to override all three forms of subsref. The using // declaration will avoid warnings about partially-overloaded virtual @@ -83,23 +83,23 @@ subsasgn (const std::string& type, const std::list& idx, const octave_value& rhs); - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - OCTINTERP_API dim_vector dims (void) const; + OCTINTERP_API dim_vector dims () const; - octave_idx_type numel (void) const { return 1; } + octave_idx_type numel () const { return 1; } - int ndims (void) const { return 2; } + int ndims () const { return 2; } - octave_idx_type nnz (void) const { return (scalar != ST () ? 1 : 0); } + octave_idx_type nnz () const { return (scalar != ST () ? 1 : 0); } OCTINTERP_API octave_value permute (const Array&, bool = false) const; OCTINTERP_API octave_value reshape (const dim_vector& new_dims) const; - std::size_t byte_size (void) const { return sizeof (ST); } + std::size_t byte_size () const { return sizeof (ST); } octave_value all (int = 0) const { return (scalar != ST ()); } @@ -131,15 +131,15 @@ sortmode is_sorted_rows (sortmode mode = UNSORTED) const { return mode == UNSORTED ? ASCENDING : mode; } - MatrixType matrix_type (void) const { return MatrixType::Diagonal; } + MatrixType matrix_type () const { return MatrixType::Diagonal; } MatrixType matrix_type (const MatrixType&) const { return matrix_type (); } - bool is_scalar_type (void) const { return true; } + bool is_scalar_type () const { return true; } - bool isnumeric (void) const { return true; } + bool isnumeric () const { return true; } - OCTINTERP_API bool is_true (void) const; + OCTINTERP_API bool is_true () const; OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -151,7 +151,7 @@ OCTINTERP_API void short_disp (std::ostream& os) const; - OCTINTERP_API float_display_format get_edit_display_format (void) const; + OCTINTERP_API float_display_format get_edit_display_format () const; OCTINTERP_API std::string edit_display (const float_display_format& fmt, @@ -159,11 +159,11 @@ // This function exists to support the MEX interface. // You should not use it anywhere else. - const void * mex_get_data (void) const { return &scalar; } + const void * mex_get_data () const { return &scalar; } - const ST& scalar_ref (void) const { return scalar; } + const ST& scalar_ref () const { return scalar; } - ST& scalar_ref (void) { return scalar; } + ST& scalar_ref () { return scalar; } OCTINTERP_API octave_value fast_elem_extract (octave_idx_type n) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-sparse.cc --- a/libinterp/octave-value/ov-base-sparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-sparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -242,7 +242,7 @@ template bool -octave_base_sparse::is_true (void) const +octave_base_sparse::is_true () const { bool retval = false; dim_vector dv = matrix.dims (); @@ -272,7 +272,7 @@ template bool -octave_base_sparse::print_as_scalar (void) const +octave_base_sparse::print_as_scalar () const { dim_vector dv = dims (); @@ -379,7 +379,7 @@ template float_display_format -octave_base_sparse::get_edit_display_format (void) const +octave_base_sparse::get_edit_display_format () const { return float_display_format (); // return make_format (this->matrix); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base-sparse.h --- a/libinterp/octave-value/ov-base-sparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base-sparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ { public: - octave_base_sparse (void) + octave_base_sparse () : octave_base_value (), matrix (), typ (MatrixType ()) { } @@ -73,19 +73,19 @@ octave_base_sparse (const octave_base_sparse& a) : octave_base_value (), matrix (a.matrix), typ (a.typ) { } - ~octave_base_sparse (void) = default; + ~octave_base_sparse () = default; - octave_idx_type numel (void) const { return dims ().safe_numel (); } + octave_idx_type numel () const { return dims ().safe_numel (); } - octave_idx_type nnz (void) const { return matrix.nnz (); } + octave_idx_type nnz () const { return matrix.nnz (); } - octave_idx_type nzmax (void) const { return matrix.nzmax (); } + octave_idx_type nzmax () const { return matrix.nzmax (); } - std::size_t byte_size (void) const { return matrix.byte_size (); } + std::size_t byte_size () const { return matrix.byte_size (); } - octave_value squeeze (void) const { return matrix.squeeze (); } + octave_value squeeze () const { return matrix.squeeze (); } - octave_value full_value (void) const { return matrix.matrix_value (); } + octave_value full_value () const { return matrix.matrix_value (); } // We don't need to override all three forms of subsref. The using // declaration will avoid warnings about partially-overloaded virtual @@ -163,7 +163,7 @@ OCTINTERP_API void delete_elements (const octave_value_list& idx); - dim_vector dims (void) const { return matrix.dims (); } + dim_vector dims () const { return matrix.dims (); } OCTINTERP_API octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); @@ -196,23 +196,23 @@ sortmode issorted (sortmode mode = UNSORTED) const { return full_value ().issorted (mode); } - MatrixType matrix_type (void) const { return typ; } + MatrixType matrix_type () const { return typ; } MatrixType matrix_type (const MatrixType& _typ) const { MatrixType ret = typ; typ = _typ; return ret; } - bool is_matrix_type (void) const { return true; } + bool is_matrix_type () const { return true; } - bool isnumeric (void) const { return true; } + bool isnumeric () const { return true; } - bool issparse (void) const { return true; } + bool issparse () const { return true; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - OCTINTERP_API bool is_true (void) const; + OCTINTERP_API bool is_true () const; - OCTINTERP_API bool print_as_scalar (void) const; + OCTINTERP_API bool print_as_scalar () const; OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -226,7 +226,7 @@ OCTINTERP_API bool load_ascii (std::istream& is); - OCTINTERP_API float_display_format get_edit_display_format (void) const; + OCTINTERP_API float_display_format get_edit_display_format () const; OCTINTERP_API std::string edit_display (const float_display_format& fmt, @@ -234,11 +234,11 @@ // These functions exists to support the MEX interface. // You should not use them anywhere else. - const void * mex_get_data (void) const { return matrix.data (); } + const void * mex_get_data () const { return matrix.data (); } - const octave_idx_type * mex_get_ir (void) const { return matrix.ridx (); } + const octave_idx_type * mex_get_ir () const { return matrix.ridx (); } - const octave_idx_type * mex_get_jc (void) const { return matrix.cidx (); } + const octave_idx_type * mex_get_jc () const { return matrix.cidx (); } OCTINTERP_API octave_value fast_elem_extract (octave_idx_type n) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base.cc --- a/libinterp/octave-value/ov-base.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base.cc Mon Jan 30 18:36:03 2023 +0100 @@ -102,86 +102,86 @@ bool Vsparse_auto_mutate = false; octave_base_value * -octave_base_value::empty_clone (void) const +octave_base_value::empty_clone () const { return resize (dim_vector ()).clone (); } octave_value -octave_base_value::squeeze (void) const +octave_base_value::squeeze () const { std::string nm = type_name (); error ("squeeze: invalid operation for %s type", nm.c_str ()); } octave_value -octave_base_value::full_value (void) const +octave_base_value::full_value () const { err_wrong_type_arg ("full: invalid operation for %s type", type_name ()); } octave_value -octave_base_value::as_double (void) const +octave_base_value::as_double () const { err_invalid_conversion (type_name (), "double"); } octave_value -octave_base_value::as_single (void) const +octave_base_value::as_single () const { err_invalid_conversion (type_name (), "single"); } octave_value -octave_base_value::as_int8 (void) const +octave_base_value::as_int8 () const { err_invalid_conversion (type_name (), "int8"); } octave_value -octave_base_value::as_int16 (void) const +octave_base_value::as_int16 () const { err_invalid_conversion (type_name (), "int16"); } octave_value -octave_base_value::as_int32 (void) const +octave_base_value::as_int32 () const { err_invalid_conversion (type_name (), "int32"); } octave_value -octave_base_value::as_int64 (void) const +octave_base_value::as_int64 () const { err_invalid_conversion (type_name (), "int64"); } octave_value -octave_base_value::as_uint8 (void) const +octave_base_value::as_uint8 () const { err_invalid_conversion (type_name (), "uint8"); } octave_value -octave_base_value::as_uint16 (void) const +octave_base_value::as_uint16 () const { err_invalid_conversion (type_name (), "uint16"); } octave_value -octave_base_value::as_uint32 (void) const +octave_base_value::as_uint32 () const { err_invalid_conversion (type_name (), "uint32"); } octave_value -octave_base_value::as_uint64 (void) const +octave_base_value::as_uint64 () const { err_invalid_conversion (type_name (), "uint64"); } Matrix -octave_base_value::size (void) +octave_base_value::size () { const dim_vector dv = dims (); Matrix mdv (1, dv.ndims ()); @@ -313,19 +313,19 @@ } octave_idx_type -octave_base_value::nnz (void) const +octave_base_value::nnz () const { err_wrong_type_arg ("octave_base_value::nnz ()", type_name ()); } octave_idx_type -octave_base_value::nzmax (void) const +octave_base_value::nzmax () const { return numel (); } octave_idx_type -octave_base_value::nfields (void) const +octave_base_value::nfields () const { err_wrong_type_arg ("octave_base_value::nfields ()", type_name ()); } @@ -349,7 +349,7 @@ } MatrixType -octave_base_value::matrix_type (void) const +octave_base_value::matrix_type () const { err_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); } @@ -392,7 +392,7 @@ } void -octave_base_value::convert_to_row_or_column_vector (void) +octave_base_value::convert_to_row_or_column_vector () { err_wrong_type_arg ("octave_base_value::convert_to_row_or_column_vector ()", type_name ()); @@ -445,7 +445,7 @@ } float_display_format -octave_base_value::get_edit_display_format (void) const +octave_base_value::get_edit_display_format () const { return float_display_format (); } @@ -681,103 +681,103 @@ } PermMatrix -octave_base_value::perm_matrix_value (void) const +octave_base_value::perm_matrix_value () const { err_wrong_type_arg ("octave_base_value::perm_matrix_value()", type_name ()); } octave_int8 -octave_base_value::int8_scalar_value (void) const +octave_base_value::int8_scalar_value () const { err_wrong_type_arg ("octave_base_value::int8_scalar_value()", type_name ()); } octave_int16 -octave_base_value::int16_scalar_value (void) const +octave_base_value::int16_scalar_value () const { err_wrong_type_arg ("octave_base_value::int16_scalar_value()", type_name ()); } octave_int32 -octave_base_value::int32_scalar_value (void) const +octave_base_value::int32_scalar_value () const { err_wrong_type_arg ("octave_base_value::int32_scalar_value()", type_name ()); } octave_int64 -octave_base_value::int64_scalar_value (void) const +octave_base_value::int64_scalar_value () const { err_wrong_type_arg ("octave_base_value::int64_scalar_value()", type_name ()); } octave_uint8 -octave_base_value::uint8_scalar_value (void) const +octave_base_value::uint8_scalar_value () const { err_wrong_type_arg ("octave_base_value::uint8_scalar_value()", type_name ()); } octave_uint16 -octave_base_value::uint16_scalar_value (void) const +octave_base_value::uint16_scalar_value () const { err_wrong_type_arg ("octave_base_value::uint16_scalar_value()", type_name ()); } octave_uint32 -octave_base_value::uint32_scalar_value (void) const +octave_base_value::uint32_scalar_value () const { err_wrong_type_arg ("octave_base_value::uint32_scalar_value()", type_name ()); } octave_uint64 -octave_base_value::uint64_scalar_value (void) const +octave_base_value::uint64_scalar_value () const { err_wrong_type_arg ("octave_base_value::uint64_scalar_value()", type_name ()); } int8NDArray -octave_base_value::int8_array_value (void) const +octave_base_value::int8_array_value () const { err_wrong_type_arg ("octave_base_value::int8_array_value()", type_name ()); } int16NDArray -octave_base_value::int16_array_value (void) const +octave_base_value::int16_array_value () const { err_wrong_type_arg ("octave_base_value::int16_array_value()", type_name ()); } int32NDArray -octave_base_value::int32_array_value (void) const +octave_base_value::int32_array_value () const { err_wrong_type_arg ("octave_base_value::int32_array_value()", type_name ()); } int64NDArray -octave_base_value::int64_array_value (void) const +octave_base_value::int64_array_value () const { err_wrong_type_arg ("octave_base_value::int64_array_value()", type_name ()); } uint8NDArray -octave_base_value::uint8_array_value (void) const +octave_base_value::uint8_array_value () const { err_wrong_type_arg ("octave_base_value::uint8_array_value()", type_name ()); } uint16NDArray -octave_base_value::uint16_array_value (void) const +octave_base_value::uint16_array_value () const { err_wrong_type_arg ("octave_base_value::uint16_array_value()", type_name ()); } uint32NDArray -octave_base_value::uint32_array_value (void) const +octave_base_value::uint32_array_value () const { err_wrong_type_arg ("octave_base_value::uint32_array_value()", type_name ()); } uint64NDArray -octave_base_value::uint64_array_value (void) const +octave_base_value::uint64_array_value () const { err_wrong_type_arg ("octave_base_value::uint64_array_value()", type_name ()); } @@ -799,7 +799,7 @@ } std::string -octave_base_value::xstring_value (void) const +octave_base_value::xstring_value () const { wrong_type_arg_error (); @@ -807,13 +807,13 @@ } Array -octave_base_value::cellstr_value (void) const +octave_base_value::cellstr_value () const { err_wrong_type_arg ("octave_base_value::cellstr_value()", type_name ()); } octave::range -octave_base_value::range_value (void) const +octave_base_value::range_value () const { err_wrong_type_arg ("octave_base_value::range_value()", type_name ()); } @@ -823,55 +823,55 @@ #if 0 octave::range -octave_base_value::float_range_value (void) const +octave_base_value::float_range_value () const { err_wrong_type_arg ("octave_base_value::float_range_value()", type_name ()); } octave::range -octave_base_value::int8_range_value (void) const +octave_base_value::int8_range_value () const { err_wrong_type_arg ("octave_base_value::int8_range_value()", type_name ()); } octave::range -octave_base_value::int16_range_value (void) const +octave_base_value::int16_range_value () const { err_wrong_type_arg ("octave_base_value::int16_range_value()", type_name ()); } octave::range -octave_base_value::int32_range_value (void) const +octave_base_value::int32_range_value () const { err_wrong_type_arg ("octave_base_value::int32_range_value()", type_name ()); } octave::range -octave_base_value::int64_range_value (void) const +octave_base_value::int64_range_value () const { err_wrong_type_arg ("octave_base_value::int64_range_value()", type_name ()); } octave::range -octave_base_value::uint8_range_value (void) const +octave_base_value::uint8_range_value () const { err_wrong_type_arg ("octave_base_value::uint8_range_value()", type_name ()); } octave::range -octave_base_value::uint16_range_value (void) const +octave_base_value::uint16_range_value () const { err_wrong_type_arg ("octave_base_value::uint16_range_value()", type_name ()); } octave::range -octave_base_value::uint32_range_value (void) const +octave_base_value::uint32_range_value () const { err_wrong_type_arg ("octave_base_value::uint32_range_value()", type_name ()); } octave::range -octave_base_value::uint64_range_value (void) const +octave_base_value::uint64_range_value () const { err_wrong_type_arg ("octave_base_value::uint64_range_value()", type_name ()); } @@ -879,13 +879,13 @@ #endif octave_map -octave_base_value::map_value (void) const +octave_base_value::map_value () const { err_wrong_type_arg ("octave_base_value::map_value()", type_name ()); } octave_scalar_map -octave_base_value::scalar_map_value (void) const +octave_base_value::scalar_map_value () const { octave_map tmp = map_value (); @@ -896,7 +896,7 @@ } string_vector -octave_base_value::map_keys (void) const +octave_base_value::map_keys () const { err_wrong_type_arg ("octave_base_value::map_keys()", type_name ()); } @@ -908,20 +908,20 @@ } std::size_t -octave_base_value::nparents (void) const +octave_base_value::nparents () const { err_wrong_type_arg ("octave_base_value::nparents()", type_name ()); } std::list -octave_base_value::parent_class_name_list (void) const +octave_base_value::parent_class_name_list () const { err_wrong_type_arg ("octave_base_value::parent_class_name_list()", type_name ()); } string_vector -octave_base_value::parent_class_names (void) const +octave_base_value::parent_class_names () const { err_wrong_type_arg ("octave_base_value::parent_class_names()", type_name ()); } @@ -982,7 +982,7 @@ } octave_value_list -octave_base_value::list_value (void) const +octave_base_value::list_value () const { err_wrong_type_arg ("octave_base_value::list_value()", type_name ()); } @@ -1172,7 +1172,7 @@ } void -octave_base_value::wrong_type_arg_error (void) const +octave_base_value::wrong_type_arg_error () const { err_wrong_type_arg (type_name ()); } @@ -1184,19 +1184,19 @@ } void -octave_base_value::lock (void) +octave_base_value::lock () { err_wrong_type_arg ("octave_base_value::lock ()", type_name ()); } void -octave_base_value::unlock (void) +octave_base_value::unlock () { err_wrong_type_arg ("octave_base_value::unlock ()", type_name ()); } octave_value -octave_base_value::dump (void) const +octave_base_value::dump () const { std::map m = {{ "class", this->class_name () }, @@ -1395,7 +1395,7 @@ // For resetting print state. void -octave_base_value::reset (void) const +octave_base_value::reset () const { s_beginning_of_line = true; s_curr_print_indent_level = 0; @@ -1521,7 +1521,7 @@ } bool -called_from_builtin (void) +called_from_builtin () { octave::tree_evaluator& tw = octave::__get_evaluator__ (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-base.h --- a/libinterp/octave-value/ov-base.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-base.h Mon Jan 30 18:36:03 2023 +0100 @@ -55,7 +55,7 @@ // object is required to load a user-defined octave_value object, // maybe this function should be declared in a public header file? -extern OCTINTERP_API type_info& __get_type_info__ (void); +extern OCTINTERP_API type_info& __get_type_info__ (); // For now just preserve the old interface and don't mark it as deprecated. // This function is currently an internal, private function. Additional @@ -186,13 +186,13 @@ #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(VIRTUAL) \ public: \ - VIRTUAL int type_id (void) const { return t_id; } \ - VIRTUAL std::string type_name (void) const { return t_name; } \ - VIRTUAL std::string class_name (void) const { return c_name; } \ - static int static_type_id (void) { return t_id; } \ - static std::string static_type_name (void) { return t_name; } \ - static std::string static_class_name (void) { return c_name; } \ - static void register_type (void); \ + VIRTUAL int type_id () const { return t_id; } \ + VIRTUAL std::string type_name () const { return t_name; } \ + VIRTUAL std::string class_name () const { return c_name; } \ + static int static_type_id () { return t_id; } \ + static std::string static_type_name () { return t_name; } \ + static std::string static_class_name () { return c_name; } \ + static void register_type (); \ static void register_type (octave::type_info&); \ \ private: \ @@ -201,7 +201,7 @@ static const std::string c_name; #define DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS(cls, type) \ - template <> void cls::register_type (void); \ + template <> void cls::register_type (); \ template <> void cls::register_type (octave::type_info&); \ template <> int cls::t_id; \ template <> const std::string cls::t_name; \ @@ -211,7 +211,7 @@ tspec int t::t_id (-1); \ tspec const std::string t::t_name (n); \ tspec const std::string t::c_name (c); \ - tspec void t::register_type (void) \ + tspec void t::register_type () \ { \ octave::type_info& type_info = octave::__get_type_info__ (); \ \ @@ -248,12 +248,12 @@ type_conv_info (type_conv_fcn f = nullptr, int t = -1) : m_fcn (f), m_type_id (t) { } - operator type_conv_fcn (void) const { return m_fcn; } + operator type_conv_fcn () const { return m_fcn; } octave_base_value * operator () (const octave_base_value& v) const { return (*m_fcn) (v); } - int type_id (void) const { return m_type_id; } + int type_id () const { return m_type_id; } private: type_conv_fcn m_fcn; @@ -262,59 +262,59 @@ friend class octave_value; - octave_base_value (void) : count (1) { } + octave_base_value () : count (1) { } octave_base_value (const octave_base_value&) : count (1) { } - virtual ~octave_base_value (void) = default; + virtual ~octave_base_value () = default; // Unconditional clone. Always clones. virtual octave_base_value * - clone (void) const { return new octave_base_value (*this); } + clone () const { return new octave_base_value (*this); } // Empty clone. virtual octave_base_value * - empty_clone (void) const; + empty_clone () const; // Unique clone. Usually clones, but may be overridden to fake the // cloning when sharing copies is to be controlled from within an // instance (see octave_class). virtual octave_base_value * - unique_clone (void) { return clone (); } + unique_clone () { return clone (); } virtual void break_closure_cycles (const std::shared_ptr&) { } virtual type_conv_info - numeric_conversion_function (void) const + numeric_conversion_function () const { return type_conv_info (); } virtual type_conv_info - numeric_demotion_function (void) const + numeric_demotion_function () const { return type_conv_info (); } - virtual octave_value squeeze (void) const; + virtual octave_value squeeze () const; - virtual octave_value full_value (void) const; + virtual octave_value full_value () const; - virtual octave_value as_double (void) const; - virtual octave_value as_single (void) const; + virtual octave_value as_double () const; + virtual octave_value as_single () const; - virtual octave_value as_int8 (void) const; - virtual octave_value as_int16 (void) const; - virtual octave_value as_int32 (void) const; - virtual octave_value as_int64 (void) const; + virtual octave_value as_int8 () const; + virtual octave_value as_int16 () const; + virtual octave_value as_int32 () const; + virtual octave_value as_int64 () const; - virtual octave_value as_uint8 (void) const; - virtual octave_value as_uint16 (void) const; - virtual octave_value as_uint32 (void) const; - virtual octave_value as_uint64 (void) const; + virtual octave_value as_uint8 () const; + virtual octave_value as_uint16 () const; + virtual octave_value as_uint32 () const; + virtual octave_value as_uint64 () const; - virtual octave_base_value * try_narrowing_conversion (void) + virtual octave_base_value * try_narrowing_conversion () { return nullptr; } - virtual void maybe_economize (void) { } + virtual void maybe_economize () { } - virtual Matrix size (void); + virtual Matrix size (); virtual octave_idx_type xnumel (const octave_value_list&); @@ -351,34 +351,34 @@ virtual octave::idx_vector index_vector (bool require_integers = false) const; - virtual dim_vector dims (void) const { return dim_vector (); } + virtual dim_vector dims () const { return dim_vector (); } - octave_idx_type rows (void) const + octave_idx_type rows () const { const dim_vector dv = dims (); return dv(0); } - octave_idx_type columns (void) const + octave_idx_type columns () const { const dim_vector dv = dims (); return dv(1); } - virtual int ndims (void) const + virtual int ndims () const { return dims ().ndims (); } - virtual octave_idx_type numel (void) const { return dims ().numel (); } + virtual octave_idx_type numel () const { return dims ().numel (); } - virtual std::size_t byte_size (void) const { return 0; } + virtual std::size_t byte_size () const { return 0; } - virtual octave_idx_type nnz (void) const; + virtual octave_idx_type nnz () const; - virtual octave_idx_type nzmax (void) const; + virtual octave_idx_type nzmax () const; - virtual octave_idx_type nfields (void) const; + virtual octave_idx_type nfields () const; virtual octave_value reshape (const dim_vector&) const; @@ -386,143 +386,143 @@ virtual octave_value resize (const dim_vector&, bool fill = false) const; - virtual MatrixType matrix_type (void) const; + virtual MatrixType matrix_type () const; virtual MatrixType matrix_type (const MatrixType& typ) const; - virtual bool is_defined (void) const { return false; } + virtual bool is_defined () const { return false; } - virtual bool is_storable (void) const { return true; } + virtual bool is_storable () const { return true; } - virtual bool is_legacy_object (void) const { return false; } + virtual bool is_legacy_object () const { return false; } - bool isempty (void) const { return (dims ().any_zero ()); } + bool isempty () const { return (dims ().any_zero ()); } - bool is_zero_by_zero (void) const { return dims().zero_by_zero (); } + bool is_zero_by_zero () const { return dims().zero_by_zero (); } - virtual bool iscell (void) const { return false; } + virtual bool iscell () const { return false; } - virtual bool iscellstr (void) const { return false; } + virtual bool iscellstr () const { return false; } - virtual bool is_real_scalar (void) const { return false; } + virtual bool is_real_scalar () const { return false; } - virtual bool is_real_matrix (void) const { return false; } + virtual bool is_real_matrix () const { return false; } - virtual bool is_complex_scalar (void) const { return false; } + virtual bool is_complex_scalar () const { return false; } - virtual bool is_complex_matrix (void) const { return false; } + virtual bool is_complex_matrix () const { return false; } - virtual bool is_bool_scalar (void) const { return false; } + virtual bool is_bool_scalar () const { return false; } - virtual bool is_bool_matrix (void) const { return false; } + virtual bool is_bool_matrix () const { return false; } - virtual bool is_char_matrix (void) const { return false; } + virtual bool is_char_matrix () const { return false; } - virtual bool is_diag_matrix (void) const { return false; } + virtual bool is_diag_matrix () const { return false; } - virtual bool is_perm_matrix (void) const { return false; } + virtual bool is_perm_matrix () const { return false; } - virtual bool is_string (void) const { return false; } + virtual bool is_string () const { return false; } - virtual bool is_sq_string (void) const { return false; } + virtual bool is_sq_string () const { return false; } - virtual bool is_range (void) const { return false; } + virtual bool is_range () const { return false; } - virtual bool isstruct (void) const { return false; } + virtual bool isstruct () const { return false; } - virtual bool isobject (void) const { return false; } + virtual bool isobject () const { return false; } - virtual bool is_classdef_meta (void) const { return false; } + virtual bool is_classdef_meta () const { return false; } - virtual bool is_classdef_superclass_ref (void) const { return false; } + virtual bool is_classdef_superclass_ref () const { return false; } - virtual bool is_classdef_object (void) const { return false; } + virtual bool is_classdef_object () const { return false; } - virtual bool is_package (void) const { return false; } + virtual bool is_package () const { return false; } - virtual bool isjava (void) const { return false; } + virtual bool isjava () const { return false; } - virtual bool is_cs_list (void) const { return false; } + virtual bool is_cs_list () const { return false; } - virtual bool is_magic_colon (void) const { return false; } + virtual bool is_magic_colon () const { return false; } - virtual bool is_all_va_args (void) const { return false; } + virtual bool is_all_va_args () const { return false; } virtual octave_value all (int = 0) const; virtual octave_value any (int = 0) const; - virtual builtin_type_t builtin_type (void) const { return btyp_unknown; } + virtual builtin_type_t builtin_type () const { return btyp_unknown; } - virtual bool is_double_type (void) const { return false; } + virtual bool is_double_type () const { return false; } - virtual bool is_single_type (void) const { return false; } + virtual bool is_single_type () const { return false; } - virtual bool isfloat (void) const { return false; } + virtual bool isfloat () const { return false; } - virtual bool is_int8_type (void) const { return false; } + virtual bool is_int8_type () const { return false; } - virtual bool is_int16_type (void) const { return false; } + virtual bool is_int16_type () const { return false; } - virtual bool is_int32_type (void) const { return false; } + virtual bool is_int32_type () const { return false; } - virtual bool is_int64_type (void) const { return false; } + virtual bool is_int64_type () const { return false; } - virtual bool is_uint8_type (void) const { return false; } + virtual bool is_uint8_type () const { return false; } - virtual bool is_uint16_type (void) const { return false; } + virtual bool is_uint16_type () const { return false; } - virtual bool is_uint32_type (void) const { return false; } + virtual bool is_uint32_type () const { return false; } - virtual bool is_uint64_type (void) const { return false; } + virtual bool is_uint64_type () const { return false; } - virtual bool islogical (void) const { return false; } + virtual bool islogical () const { return false; } - virtual bool isinteger (void) const { return false; } + virtual bool isinteger () const { return false; } - virtual bool isreal (void) const { return false; } + virtual bool isreal () const { return false; } - virtual bool iscomplex (void) const { return false; } + virtual bool iscomplex () const { return false; } // Would be nice to get rid of the next four functions: - virtual bool is_scalar_type (void) const { return false; } + virtual bool is_scalar_type () const { return false; } - virtual bool is_matrix_type (void) const { return false; } + virtual bool is_matrix_type () const { return false; } - virtual bool isnumeric (void) const { return false; } + virtual bool isnumeric () const { return false; } - virtual bool issparse (void) const { return false; } + virtual bool issparse () const { return false; } - virtual bool is_true (void) const { return false; } + virtual bool is_true () const { return false; } - virtual bool is_magic_int (void) const { return false; } + virtual bool is_magic_int () const { return false; } - virtual bool isnull (void) const { return false; } + virtual bool isnull () const { return false; } - virtual bool is_constant (void) const { return false; } + virtual bool is_constant () const { return false; } - virtual bool is_function_handle (void) const { return false; } + virtual bool is_function_handle () const { return false; } - virtual bool is_anonymous_function (void) const { return false; } + virtual bool is_anonymous_function () const { return false; } - virtual bool is_inline_function (void) const { return false; } + virtual bool is_inline_function () const { return false; } - virtual bool is_function (void) const { return false; } + virtual bool is_function () const { return false; } - virtual bool is_user_script (void) const { return false; } + virtual bool is_user_script () const { return false; } - virtual bool is_user_function (void) const { return false; } + virtual bool is_user_function () const { return false; } - virtual bool is_user_code (void) const { return false; } + virtual bool is_user_code () const { return false; } - virtual bool is_builtin_function (void) const { return false; } + virtual bool is_builtin_function () const { return false; } - virtual bool is_dld_function (void) const { return false; } + virtual bool is_dld_function () const { return false; } - virtual bool is_mex_function (void) const { return false; } + virtual bool is_mex_function () const { return false; } - virtual void erase_subfunctions (void) { } + virtual void erase_subfunctions () { } virtual short int short_value (bool = false, bool = false) const; @@ -552,7 +552,7 @@ virtual float float_scalar_value (bool frc_str_conv = false) const { return float_value (frc_str_conv); } - virtual Cell cell_value (void) const; + virtual Cell cell_value () const; virtual Matrix matrix_value (bool = false) const; @@ -599,85 +599,85 @@ virtual FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const; - virtual PermMatrix perm_matrix_value (void) const; + virtual PermMatrix perm_matrix_value () const; - virtual octave_int8 int8_scalar_value (void) const; + virtual octave_int8 int8_scalar_value () const; - virtual octave_int16 int16_scalar_value (void) const; + virtual octave_int16 int16_scalar_value () const; - virtual octave_int32 int32_scalar_value (void) const; + virtual octave_int32 int32_scalar_value () const; - virtual octave_int64 int64_scalar_value (void) const; + virtual octave_int64 int64_scalar_value () const; - virtual octave_uint8 uint8_scalar_value (void) const; + virtual octave_uint8 uint8_scalar_value () const; - virtual octave_uint16 uint16_scalar_value (void) const; + virtual octave_uint16 uint16_scalar_value () const; - virtual octave_uint32 uint32_scalar_value (void) const; + virtual octave_uint32 uint32_scalar_value () const; - virtual octave_uint64 uint64_scalar_value (void) const; + virtual octave_uint64 uint64_scalar_value () const; - virtual int8NDArray int8_array_value (void) const; + virtual int8NDArray int8_array_value () const; - virtual int16NDArray int16_array_value (void) const; + virtual int16NDArray int16_array_value () const; - virtual int32NDArray int32_array_value (void) const; + virtual int32NDArray int32_array_value () const; - virtual int64NDArray int64_array_value (void) const; + virtual int64NDArray int64_array_value () const; - virtual uint8NDArray uint8_array_value (void) const; + virtual uint8NDArray uint8_array_value () const; - virtual uint16NDArray uint16_array_value (void) const; + virtual uint16NDArray uint16_array_value () const; - virtual uint32NDArray uint32_array_value (void) const; + virtual uint32NDArray uint32_array_value () const; - virtual uint64NDArray uint64_array_value (void) const; + virtual uint64NDArray uint64_array_value () const; virtual string_vector string_vector_value (bool pad = false) const; virtual std::string string_value (bool force = false) const; - virtual Array cellstr_value (void) const; + virtual Array cellstr_value () const; - virtual octave::range range_value (void) const; + virtual octave::range range_value () const; // For now, disable all but range. #if 0 - virtual octave::range float_range_value (void) const; + virtual octave::range float_range_value () const; - virtual octave::range int8_range_value (void) const; + virtual octave::range int8_range_value () const; - virtual octave::range int16_range_value (void) const; + virtual octave::range int16_range_value () const; - virtual octave::range int32_range_value (void) const; + virtual octave::range int32_range_value () const; - virtual octave::range int64_range_value (void) const; + virtual octave::range int64_range_value () const; - virtual octave::range uint8_range_value (void) const; + virtual octave::range uint8_range_value () const; - virtual octave::range uint16_range_value (void) const; + virtual octave::range uint16_range_value () const; - virtual octave::range uint32_range_value (void) const; + virtual octave::range uint32_range_value () const; - virtual octave::range uint64_range_value (void) const; + virtual octave::range uint64_range_value () const; #endif - virtual octave_map map_value (void) const; + virtual octave_map map_value () const; - virtual octave_scalar_map scalar_map_value (void) const; + virtual octave_scalar_map scalar_map_value () const; - virtual string_vector map_keys (void) const; + virtual string_vector map_keys () const; virtual bool isfield (const std::string&) const; - virtual std::size_t nparents (void) const; + virtual std::size_t nparents () const; - virtual std::list parent_class_name_list (void) const; + virtual std::list parent_class_name_list () const; - virtual string_vector parent_class_names (void) const; + virtual string_vector parent_class_names () const; virtual octave_base_value * find_parent_class (const std::string&) { return nullptr; } @@ -700,21 +700,21 @@ virtual octave_fcn_handle * fcn_handle_value (bool silent = false); - virtual octave_value_list list_value (void) const; + virtual octave_value_list list_value () const; virtual octave_value convert_to_str (bool pad = false, bool force = false, char type = '\'') const; virtual octave_value convert_to_str_internal (bool pad, bool force, char type) const; - virtual void convert_to_row_or_column_vector (void); + virtual void convert_to_row_or_column_vector (); // The following extractor functions don't perform any implicit type // conversions. virtual std::string xstring_value () const; - virtual bool print_as_scalar (void) const { return false; } + virtual bool print_as_scalar () const { return false; } virtual void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -730,7 +730,7 @@ virtual void short_disp (std::ostream& os) const { os << "..."; } - virtual float_display_format get_edit_display_format (void) const; + virtual float_display_format get_edit_display_format () const; virtual std::string edit_display (const float_display_format&, octave_idx_type, octave_idx_type) const @@ -758,11 +758,11 @@ oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const; - virtual const void * mex_get_data (void) const { return nullptr; } + virtual const void * mex_get_data () const { return nullptr; } - virtual const octave_idx_type * mex_get_ir (void) const { return nullptr; } + virtual const octave_idx_type * mex_get_ir () const { return nullptr; } - virtual const octave_idx_type * mex_get_jc (void) const { return nullptr; } + virtual const octave_idx_type * mex_get_jc () const { return nullptr; } virtual mxArray * as_mxArray (bool interleaved) const; @@ -783,15 +783,15 @@ virtual sortmode is_sorted_rows (sortmode mode = UNSORTED) const; - virtual void lock (void); + virtual void lock (); - virtual void unlock (void); + virtual void unlock (); - virtual bool islocked (void) const { return false; } + virtual bool islocked () const { return false; } - virtual void call_object_destructor (void) { } + virtual void call_object_destructor () { } - virtual octave_value dump (void) const; + virtual octave_value dump () const; // Standard mappers. Register new ones here. enum unary_mapper_t @@ -891,23 +891,23 @@ const std::list& idx, const octave_value& rhs); - void reset_indent_level (void) const + void reset_indent_level () const { s_curr_print_indent_level = 0; } - void increment_indent_level (void) const + void increment_indent_level () const { s_curr_print_indent_level += 2; } - void decrement_indent_level (void) const + void decrement_indent_level () const { s_curr_print_indent_level -= 2; } - int current_print_indent_level (void) const + int current_print_indent_level () const { return s_curr_print_indent_level; } OCTINTERP_API void indent (std::ostream& os) const; OCTINTERP_API void newline (std::ostream& os) const; - OCTINTERP_API void reset (void) const; + OCTINTERP_API void reset () const; // A reference count. // NOTE: the declaration is octave_idx_type because with 64-bit indexing, @@ -922,7 +922,7 @@ private: - OCTINTERP_API void wrong_type_arg_error (void) const; + OCTINTERP_API void wrong_type_arg_error () const; //-------- @@ -938,9 +938,9 @@ { public: - octave_base_dld_value (void) = default; + octave_base_dld_value () = default; - ~octave_base_dld_value (void) + ~octave_base_dld_value () { m_containing_dynamic_library.delete_later (); } @@ -965,6 +965,6 @@ // Tells whether some regular octave_value_base methods are being called from // within the "builtin" function. -extern OCTINTERP_API bool called_from_builtin (void); +extern OCTINTERP_API bool called_from_builtin (); #endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-bool-mat.cc --- a/libinterp/octave-value/ov-bool-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-bool-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -79,14 +79,14 @@ } octave_base_value::type_conv_info -octave_bool_matrix::numeric_conversion_function (void) const +octave_bool_matrix::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_matrix::static_type_id ()); } octave_base_value * -octave_bool_matrix::try_narrowing_conversion (void) +octave_bool_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -167,61 +167,61 @@ } octave_value -octave_bool_matrix::as_double (void) const +octave_bool_matrix::as_double () const { return NDArray (m_matrix); } octave_value -octave_bool_matrix::as_single (void) const +octave_bool_matrix::as_single () const { return FloatNDArray (m_matrix); } octave_value -octave_bool_matrix::as_int8 (void) const +octave_bool_matrix::as_int8 () const { return int8NDArray (m_matrix); } octave_value -octave_bool_matrix::as_int16 (void) const +octave_bool_matrix::as_int16 () const { return int16NDArray (m_matrix); } octave_value -octave_bool_matrix::as_int32 (void) const +octave_bool_matrix::as_int32 () const { return int32NDArray (m_matrix); } octave_value -octave_bool_matrix::as_int64 (void) const +octave_bool_matrix::as_int64 () const { return int64NDArray (m_matrix); } octave_value -octave_bool_matrix::as_uint8 (void) const +octave_bool_matrix::as_uint8 () const { return uint8NDArray (m_matrix); } octave_value -octave_bool_matrix::as_uint16 (void) const +octave_bool_matrix::as_uint16 () const { return uint16NDArray (m_matrix); } octave_value -octave_bool_matrix::as_uint32 (void) const +octave_bool_matrix::as_uint32 () const { return uint32NDArray (m_matrix); } octave_value -octave_bool_matrix::as_uint64 (void) const +octave_bool_matrix::as_uint64 () const { return uint64NDArray (m_matrix); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-bool-mat.h --- a/libinterp/octave-value/ov-bool-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-bool-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ { public: - octave_bool_matrix (void) + octave_bool_matrix () : octave_base_matrix () { } octave_bool_matrix (const boolNDArray& bnda) @@ -77,17 +77,17 @@ octave_bool_matrix (const octave_bool_matrix& bm) : octave_base_matrix (bm) { } - ~octave_bool_matrix (void) = default; + ~octave_bool_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_bool_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_bool_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); octave::idx_vector index_vector (bool /* require_integers */ = false) const { @@ -95,39 +95,39 @@ : set_idx_cache (octave::idx_vector (m_matrix)); } - builtin_type_t builtin_type (void) const { return btyp_bool; } + builtin_type_t builtin_type () const { return btyp_bool; } - bool is_bool_matrix (void) const { return true; } + bool is_bool_matrix () const { return true; } - bool islogical (void) const { return true; } + bool islogical () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool isnumeric (void) const { return false; } + bool isnumeric () const { return false; } int8NDArray - int8_array_value (void) const { return int8NDArray (m_matrix); } + int8_array_value () const { return int8NDArray (m_matrix); } int16NDArray - int16_array_value (void) const { return int16NDArray (m_matrix); } + int16_array_value () const { return int16NDArray (m_matrix); } int32NDArray - int32_array_value (void) const { return int32NDArray (m_matrix); } + int32_array_value () const { return int32NDArray (m_matrix); } int64NDArray - int64_array_value (void) const { return int64NDArray (m_matrix); } + int64_array_value () const { return int64NDArray (m_matrix); } uint8NDArray - uint8_array_value (void) const { return uint8NDArray (m_matrix); } + uint8_array_value () const { return uint8NDArray (m_matrix); } uint16NDArray - uint16_array_value (void) const { return uint16NDArray (m_matrix); } + uint16_array_value () const { return uint16NDArray (m_matrix); } uint32NDArray - uint32_array_value (void) const { return uint32NDArray (m_matrix); } + uint32_array_value () const { return uint32NDArray (m_matrix); } uint64NDArray - uint64_array_value (void) const { return uint64NDArray (m_matrix); } + uint64_array_value () const { return uint64NDArray (m_matrix); } double double_value (bool = false) const; @@ -194,21 +194,21 @@ octave_value convert_to_str_internal (bool pad, bool force, char type) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; // Use matrix_ref here to clear index cache. - void invert (void) { matrix_ref ().invert (); } + void invert () { matrix_ref ().invert (); } void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-bool-sparse.cc --- a/libinterp/octave-value/ov-bool-sparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-bool-sparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -67,7 +67,7 @@ } octave_base_value::type_conv_info -octave_sparse_bool_matrix::numeric_conversion_function (void) const +octave_sparse_bool_matrix::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_sparse_matrix::static_type_id ()); @@ -172,7 +172,7 @@ } octave_value -octave_sparse_bool_matrix::as_double (void) const +octave_sparse_bool_matrix::as_double () const { return SparseMatrix (this->matrix); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-bool-sparse.h --- a/libinterp/octave-value/ov-bool-sparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-bool-sparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ { public: - octave_sparse_bool_matrix (void) + octave_sparse_bool_matrix () : octave_base_sparse () { } octave_sparse_bool_matrix (const SparseBoolMatrix& bnda) @@ -75,14 +75,14 @@ octave_sparse_bool_matrix (const octave_sparse_bool_matrix& bm) : octave_base_sparse (bm) { } - ~octave_sparse_bool_matrix (void) = default; + ~octave_sparse_bool_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_sparse_bool_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_sparse_bool_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; // FIXME: Adapt idx_vector to allow sparse logical indexing without overflow! octave::idx_vector index_vector (bool /* require_integers */ = false) const @@ -90,15 +90,15 @@ return octave::idx_vector (matrix); } - builtin_type_t builtin_type (void) const { return btyp_bool; } + builtin_type_t builtin_type () const { return btyp_bool; } - bool is_bool_matrix (void) const { return true; } + bool is_bool_matrix () const { return true; } - bool islogical (void) const { return true; } + bool islogical () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool isnumeric (void) const { return false; } + bool isnumeric () const { return false; } double double_value (bool = false) const; @@ -130,7 +130,7 @@ octave_value convert_to_str_internal (bool pad, bool force, char type) const; - octave_value as_double (void) const; + octave_value as_double () const; bool save_binary (std::ostream& os, bool save_as_floats); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-bool.cc --- a/libinterp/octave-value/ov-bool.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-bool.cc Mon Jan 30 18:36:03 2023 +0100 @@ -69,7 +69,7 @@ } octave_base_value::type_conv_info -octave_bool::numeric_conversion_function (void) const +octave_bool::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_scalar::static_type_id ()); @@ -95,61 +95,61 @@ } octave_value -octave_bool::as_double (void) const +octave_bool::as_double () const { return static_cast (scalar); } octave_value -octave_bool::as_single (void) const +octave_bool::as_single () const { return static_cast (scalar); } octave_value -octave_bool::as_int8 (void) const +octave_bool::as_int8 () const { return octave_int8 (scalar); } octave_value -octave_bool::as_int16 (void) const +octave_bool::as_int16 () const { return octave_int16 (scalar); } octave_value -octave_bool::as_int32 (void) const +octave_bool::as_int32 () const { return octave_int32 (scalar); } octave_value -octave_bool::as_int64 (void) const +octave_bool::as_int64 () const { return octave_int64 (scalar); } octave_value -octave_bool::as_uint8 (void) const +octave_bool::as_uint8 () const { return octave_uint8 (scalar); } octave_value -octave_bool::as_uint16 (void) const +octave_bool::as_uint16 () const { return octave_uint16 (scalar); } octave_value -octave_bool::as_uint32 (void) const +octave_bool::as_uint32 () const { return octave_uint32 (scalar); } octave_value -octave_bool::as_uint64 (void) const +octave_bool::as_uint64 () const { return octave_uint64 (scalar); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-bool.h --- a/libinterp/octave-value/ov-bool.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-bool.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_bool (void) + octave_bool () : octave_base_scalar (false) { } octave_bool (bool b) @@ -63,13 +63,13 @@ octave_bool (const octave_bool& s) : octave_base_scalar (s) { } - ~octave_bool (void) = default; + ~octave_bool () = default; - octave_base_value * clone (void) const { return new octave_bool (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * clone () const { return new octave_bool (*this); } + octave_base_value * empty_clone () const { return new octave_bool_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); @@ -77,75 +77,75 @@ octave::idx_vector index_vector (bool /* require_integers */ = false) const { return octave::idx_vector (scalar); } - builtin_type_t builtin_type (void) const { return btyp_bool; } + builtin_type_t builtin_type () const { return btyp_bool; } - bool is_real_scalar (void) const { return true; } + bool is_real_scalar () const { return true; } - bool is_bool_scalar (void) const { return true; } + bool is_bool_scalar () const { return true; } - bool islogical (void) const { return true; } + bool islogical () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool isnumeric (void) const { return false; } + bool isnumeric () const { return false; } - bool is_true (void) const { return scalar; } + bool is_true () const { return scalar; } int8NDArray - int8_array_value (void) const + int8_array_value () const { return int8NDArray (dim_vector (1, 1), scalar); } int16NDArray - int16_array_value (void) const + int16_array_value () const { return int16NDArray (dim_vector (1, 1), scalar); } int32NDArray - int32_array_value (void) const + int32_array_value () const { return int32NDArray (dim_vector (1, 1), scalar); } int64NDArray - int64_array_value (void) const + int64_array_value () const { return int64NDArray (dim_vector (1, 1), scalar); } uint8NDArray - uint8_array_value (void) const + uint8_array_value () const { return uint8NDArray (dim_vector (1, 1), scalar); } uint16NDArray - uint16_array_value (void) const + uint16_array_value () const { return uint16NDArray (dim_vector (1, 1), scalar); } uint32NDArray - uint32_array_value (void) const + uint32_array_value () const { return uint32NDArray (dim_vector (1, 1), scalar); } uint64NDArray - uint64_array_value (void) const + uint64_array_value () const { return uint64NDArray (dim_vector (1, 1), scalar); } octave_int8 - int8_scalar_value (void) const { return octave_int8 (scalar); } + int8_scalar_value () const { return octave_int8 (scalar); } octave_int16 - int16_scalar_value (void) const { return octave_int16 (scalar); } + int16_scalar_value () const { return octave_int16 (scalar); } octave_int32 - int32_scalar_value (void) const { return octave_int32 (scalar); } + int32_scalar_value () const { return octave_int32 (scalar); } octave_int64 - int64_scalar_value (void) const { return octave_int64 (scalar); } + int64_scalar_value () const { return octave_int64 (scalar); } octave_uint8 - uint8_scalar_value (void) const { return octave_uint8 (scalar); } + uint8_scalar_value () const { return octave_uint8 (scalar); } octave_uint16 - uint16_scalar_value (void) const { return octave_uint16 (scalar); } + uint16_scalar_value () const { return octave_uint16 (scalar); } octave_uint32 - uint32_scalar_value (void) const { return octave_uint32 (scalar); } + uint32_scalar_value () const { return octave_uint32 (scalar); } octave_uint64 - uint64_scalar_value (void) const { return octave_uint64 (scalar); } + uint64_scalar_value () const { return octave_uint64 (scalar); } double double_value (bool = false) const { return scalar; } @@ -209,18 +209,18 @@ boolNDArray bool_array_value (bool = false) const { return boolNDArray (dim_vector (1, 1), scalar); } - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; octave_value resize (const dim_vector& dv, bool fill = false) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-builtin.cc --- a/libinterp/octave-value/ov-builtin.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-builtin.cc Mon Jan 30 18:36:03 2023 +0100 @@ -50,13 +50,13 @@ } octave_builtin::fcn -octave_builtin::function (void) const +octave_builtin::function () const { return m_fcn; } octave_builtin::meth -octave_builtin::method (void) const +octave_builtin::method () const { return m_meth; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-builtin.h --- a/libinterp/octave-value/ov-builtin.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-builtin.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ { public: - octave_builtin (void) + octave_builtin () : octave_function (), m_fcn (nullptr), m_meth (nullptr), m_file () { } @@ -88,21 +88,21 @@ octave_builtin& operator = (const octave_builtin& ob) = delete; - ~octave_builtin (void) = default; + ~octave_builtin () = default; - std::string src_file_name (void) const { return m_file; } + std::string src_file_name () const { return m_file; } octave_function * function_value (bool = false) { return this; } - bool is_builtin_function (void) const { return true; } + bool is_builtin_function () const { return true; } octave_value_list execute (octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list ()); - fcn function (void) const; + fcn function () const; - meth method (void) const; + meth method () const; void push_dispatch_class (const std::string& dispatch_type); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cell.cc --- a/libinterp/octave-value/ov-cell.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cell.cc Mon Jan 30 18:36:03 2023 +0100 @@ -428,7 +428,7 @@ } bool -octave_cell::iscellstr (void) const +octave_cell::iscellstr () const { bool retval; if (m_cellstr_cache.get ()) @@ -466,7 +466,7 @@ } std::size_t -octave_cell::byte_size (void) const +octave_cell::byte_size () const { std::size_t retval = 0; @@ -559,13 +559,13 @@ } bool -octave_cell::is_true (void) const +octave_cell::is_true () const { error ("invalid conversion from cell array to logical value"); } octave_value_list -octave_cell::list_value (void) const +octave_cell::list_value () const { return octave_value_list (m_matrix); } @@ -633,7 +633,7 @@ } Array -octave_cell::cellstr_value (void) const +octave_cell::cellstr_value () const { if (! iscellstr ()) error ("invalid conversion from cell array to array of strings"); @@ -645,7 +645,7 @@ } bool -octave_cell::print_as_scalar (void) const +octave_cell::print_as_scalar () const { return true; } @@ -995,7 +995,7 @@ } const void * -octave_cell::mex_get_data (void) const +octave_cell::mex_get_data () const { clear_cellstr_cache (); return m_matrix.data (); @@ -1336,8 +1336,7 @@ return ovl (args(0)); else { - string_vector s = args( - 0).xstring_vector_value ("cellstr: argument STRING must be a 2-D character array"); + string_vector s = args(0).xstring_vector_value ("cellstr: argument STRING must be a 2-D character array"); return ovl (s.isempty () ? Cell (octave_value ("")) : Cell (s, true)); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cell.h --- a/libinterp/octave-value/ov-cell.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cell.h Mon Jan 30 18:36:03 2023 +0100 @@ -51,7 +51,7 @@ { public: - octave_cell (void) + octave_cell () : octave_base_matrix (), m_cellstr_cache () { } octave_cell (const Cell& c) @@ -64,15 +64,15 @@ octave_cell (const octave_cell& c) : octave_base_matrix (c), m_cellstr_cache () { } - ~octave_cell (void) = default; + ~octave_cell () = default; - octave_base_value * clone (void) const { return new octave_cell (*this); } - octave_base_value * empty_clone (void) const { return new octave_cell (); } + octave_base_value * clone () const { return new octave_cell (*this); } + octave_base_value * empty_clone () const { return new octave_cell (); } void break_closure_cycles (const std::shared_ptr& frame); #if 0 - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); #endif octave_value subsref (const std::string& type, @@ -107,7 +107,7 @@ void delete_elements (const octave_value_list& idx); - std::size_t byte_size (void) const; + std::size_t byte_size () const; octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; @@ -120,36 +120,36 @@ sortmode is_sorted_rows (sortmode mode = UNSORTED) const; - bool is_matrix_type (void) const { return false; } + bool is_matrix_type () const { return false; } - bool isnumeric (void) const { return false; } + bool isnumeric () const { return false; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool iscell (void) const { return true; } + bool iscell () const { return true; } - builtin_type_t builtin_type (void) const { return btyp_cell; } + builtin_type_t builtin_type () const { return btyp_cell; } - bool iscellstr (void) const; + bool iscellstr () const; - bool is_true (void) const; + bool is_true () const; - Cell cell_value (void) const { return m_matrix; } + Cell cell_value () const { return m_matrix; } - octave_value_list list_value (void) const; + octave_value_list list_value () const; octave_value convert_to_str_internal (bool pad, bool, char type) const { return octave_value (string_vector_value (pad), type); } string_vector string_vector_value (bool pad = false) const; - Array cellstr_value (void) const; + Array cellstr_value () const; Array cellstr_value (const char *fmt, ...) const; - bool print_as_scalar (void) const; + bool print_as_scalar () const; void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -178,11 +178,11 @@ // This function exists to support the MEX interface. // You should not use it anywhere else. - const void * mex_get_data (void) const; + const void * mex_get_data () const; private: - void clear_cellstr_cache (void) const + void clear_cellstr_cache () const { m_cellstr_cache.reset (); } //-------- diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-ch-mat.cc --- a/libinterp/octave-value/ov-ch-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-ch-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -154,61 +154,61 @@ } octave_value -octave_char_matrix::as_double (void) const +octave_char_matrix::as_double () const { return NDArray (m_matrix); } octave_value -octave_char_matrix::as_single (void) const +octave_char_matrix::as_single () const { return FloatNDArray (m_matrix); } octave_value -octave_char_matrix::as_int8 (void) const +octave_char_matrix::as_int8 () const { return int8NDArray (m_matrix); } octave_value -octave_char_matrix::as_int16 (void) const +octave_char_matrix::as_int16 () const { return int16NDArray (m_matrix); } octave_value -octave_char_matrix::as_int32 (void) const +octave_char_matrix::as_int32 () const { return int32NDArray (m_matrix); } octave_value -octave_char_matrix::as_int64 (void) const +octave_char_matrix::as_int64 () const { return int64NDArray (m_matrix); } octave_value -octave_char_matrix::as_uint8 (void) const +octave_char_matrix::as_uint8 () const { return uint8NDArray (m_matrix); } octave_value -octave_char_matrix::as_uint16 (void) const +octave_char_matrix::as_uint16 () const { return uint16NDArray (m_matrix); } octave_value -octave_char_matrix::as_uint32 (void) const +octave_char_matrix::as_uint32 () const { return uint32NDArray (m_matrix); } octave_value -octave_char_matrix::as_uint64 (void) const +octave_char_matrix::as_uint64 () const { return uint64NDArray (m_matrix); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-ch-mat.h --- a/libinterp/octave-value/ov-ch-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-ch-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ { protected: - octave_char_matrix (void) + octave_char_matrix () : octave_base_matrix () { } octave_char_matrix (const charMatrix& chm) @@ -82,21 +82,21 @@ public: - ~octave_char_matrix (void) = default; + ~octave_char_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_char_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_char_matrix (); } octave::idx_vector index_vector (bool require_integers = false) const; - builtin_type_t builtin_type (void) const { return btyp_char; } + builtin_type_t builtin_type () const { return btyp_char; } - bool is_char_matrix (void) const { return true; } - bool is_real_matrix (void) const { return true; } + bool is_char_matrix () const { return true; } + bool is_real_matrix () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } double double_value (bool = false) const; @@ -148,18 +148,18 @@ octave_value convert_to_str_internal (bool, bool, char type) const { return octave_value (m_matrix, type); } - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-class.cc Mon Jan 30 18:36:03 2023 +0100 @@ -56,7 +56,6 @@ #include "ov-typeinfo.h" #include "ov-usr-fcn.h" #include "pager.h" -#include "parse.h" #include "pr-output.h" #include "unwind-prot.h" #include "variables.h" @@ -206,7 +205,7 @@ } octave_base_value * -octave_class::unique_clone (void) +octave_class::unique_clone () { if (count == m_obsolete_copies) { @@ -225,7 +224,7 @@ } std::string -octave_class::get_current_method_class (void) +octave_class::get_current_method_class () { std::string retval = class_name (); @@ -246,14 +245,14 @@ OCTAVE_NORETURN static void -err_invalid_index1 (void) +err_invalid_index1 () { error ("invalid index for class"); } OCTAVE_NORETURN static void -err_invalid_index_for_assignment (void) +err_invalid_index_for_assignment () { error ("invalid index for class assignment"); } @@ -305,14 +304,16 @@ } Matrix -octave_class::size (void) +octave_class::size () { if (in_class_method () || called_from_builtin ()) return octave_base_value::size (); Matrix retval (1, 2, 1.0); - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); octave_value meth = symtab.find_method ("size", class_name ()); @@ -321,7 +322,7 @@ count++; octave_value_list args (1, octave_value (this)); - octave_value_list lv = octave::feval (meth.function_value (), args, 1); + octave_value_list lv = interp.feval (meth.function_value (), args, 1); if (lv.length () <= 0 || ! lv(0).is_matrix_type () || ! lv(0).dims ().isvector ()) error ("@%s/size: invalid return value", class_name ().c_str ()); @@ -352,7 +353,9 @@ octave_idx_type retval = -1; const std::string cn = class_name (); - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); octave_value meth = symtab.find_method ("numel", cn); @@ -366,7 +369,7 @@ for (octave_idx_type i = 0; i < idx.length (); i++) args(i+1) = idx(i); - octave_value_list lv = octave::feval (meth.function_value (), args, 1); + octave_value_list lv = interp.feval (meth.function_value (), args, 1); if (lv.length () != 1 || ! lv(0).is_scalar_type ()) error ("@%s/numel: invalid return value", cn.c_str ()); @@ -447,7 +450,9 @@ } else { - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); octave_value meth = symtab.find_method ("subsref", class_name ()); @@ -479,7 +484,7 @@ true_nargout = xnumel (tmp); } - retval = octave::feval (meth.function_value (), args, true_nargout); + retval = interp.feval (meth.function_value (), args, true_nargout); // Since we're handling subsref, if the list has more than one // element, return it as a comma-separated list so that we can @@ -547,7 +552,9 @@ if (! (in_class_method () || called_from_builtin ())) { - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); octave_value meth = symtab.find_method ("subsasgn", class_name ()); @@ -589,10 +596,10 @@ octave::unwind_protect_var restore_var (m_obsolete_copies); m_obsolete_copies = 2; - tmp = octave::feval (meth.function_value (), args); + tmp = interp.feval (meth.function_value (), args); } else - tmp = octave::feval (meth.function_value (), args); + tmp = interp.feval (meth.function_value (), args); // FIXME: Should the subsasgn method be able to return // more than one value? @@ -823,7 +830,9 @@ octave::idx_vector octave_class::index_vector (bool require_integers) const { - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); octave_value meth = symtab.find_method ("subsindex", class_name ()); @@ -834,7 +843,7 @@ octave_value_list args; args(0) = octave_value (new octave_class (m_map, c_name, m_parent_list)); - octave_value_list tmp = octave::feval (meth.function_value (), args, 1); + octave_value_list tmp = interp.feval (meth.function_value (), args, 1); if (tmp(0).isobject ()) error ("subsindex function must return a valid index vector"); @@ -848,7 +857,7 @@ } std::size_t -octave_class::byte_size (void) const +octave_class::byte_size () const { // Neglect the size of the fieldnames. @@ -867,11 +876,13 @@ } bool -octave_class::is_true (void) const +octave_class::is_true () const { bool retval = false; - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); octave_value meth = symtab.find_method ("logical", class_name ()); @@ -879,7 +890,7 @@ { octave_value in = new octave_class (*this); - octave_value_list tmp = octave::feval (meth.function_value (), in, 1); + octave_value_list tmp = interp.feval (meth.function_value (), in, 1); retval = tmp(0).is_true (); } @@ -887,7 +898,7 @@ } string_vector -octave_class::map_keys (void) const +octave_class::map_keys () const { err_wrong_type_arg ("octave_class::map_keys()", type_name ()); } @@ -989,7 +1000,9 @@ { string_vector retval; - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); octave_value meth = symtab.find_method ("char", class_name ()); @@ -999,7 +1012,7 @@ octave_value_list args; args(0) = octave_value (new octave_class (m_map, c_name, m_parent_list)); - octave_value_list tmp = octave::feval (meth.function_value (), args, 1); + octave_value_list tmp = interp.feval (meth.function_value (), args, 1); if (tmp.length () >= 1) { @@ -1030,7 +1043,7 @@ // If we don't have one, we attempt to create one by calling the constructor // with no arguments. bool -octave_class::reconstruct_exemplar (void) +octave_class::reconstruct_exemplar () { bool retval = false; @@ -1076,7 +1089,7 @@ try { - result = octave::feval (ctor, ovl (), 1); + result = interp.feval (ctor, ovl (), 1); } catch (const octave::execution_exception&) { @@ -1096,7 +1109,7 @@ } void -octave_class::clear_exemplar_map (void) +octave_class::clear_exemplar_map () { exemplar_map.clear (); } @@ -1109,7 +1122,7 @@ // class structure here so the user's loadobj method has a chance // to do its magic. bool -octave_class::reconstruct_parents (void) +octave_class::reconstruct_parents () { bool retval = true; bool might_have_inheritance = false; @@ -1165,12 +1178,15 @@ os << "# classname: " << class_name () << "\n"; 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 (lp.find_method (class_name (), "saveobj") != "") { octave_value in = new octave_class (*this); - octave_value_list tmp = octave::feval ("saveobj", in, 1); + + octave_value_list tmp = interp.feval ("saveobj", in, 1); m = tmp(0).map_value (); } @@ -1223,8 +1239,7 @@ if (! is) break; - Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading class elements") : Cell ( - t2)); + Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2)); m.assign (nm, tcell); } @@ -1240,12 +1255,14 @@ if (! reconstruct_parents ()) warning ("load: unable to reconstruct object inheritance"); - octave::load_path& lp = octave::__get_load_path__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::load_path& lp = interp.get_load_path (); if (lp.find_method (classname, "loadobj") != "") { octave_value in = new octave_class (*this); - octave_value_list tmp = octave::feval ("loadobj", in, 1); + octave_value_list tmp = interp.feval ("loadobj", in, 1); m_map = tmp(0).map_value (); } @@ -1271,12 +1288,14 @@ 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 (lp.find_method (class_name (), "saveobj") != "") { octave_value in = new octave_class (*this); - octave_value_list tmp = octave::feval ("saveobj", in, 1); + octave_value_list tmp = interp.feval ("saveobj", in, 1); m = tmp(0).map_value (); } @@ -1348,8 +1367,7 @@ if (! is) break; - Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading class elements") : Cell ( - t2)); + Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2)); m.assign (nm, tcell); } @@ -1361,12 +1379,14 @@ if (! reconstruct_parents ()) warning ("load: unable to reconstruct object inheritance"); - octave::load_path& lp = octave::__get_load_path__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::load_path& lp = interp.get_load_path (); if (lp.find_method (c_name, "loadobj") != "") { octave_value in = new octave_class (*this); - octave_value_list tmp = octave::feval ("loadobj", in, 1); + octave_value_list tmp = interp.feval ("loadobj", in, 1); m_map = tmp(0).map_value (); } @@ -1400,7 +1420,9 @@ octave_map m; octave_map::iterator i; - octave::load_path& lp = octave::__get_load_path__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::load_path& lp = interp.get_load_path (); #if defined (HAVE_HDF5_18) group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT, @@ -1445,7 +1467,7 @@ if (lp.find_method (class_name (), "saveobj") != "") { octave_value in = new octave_class (*this); - octave_value_list tmp = octave::feval ("saveobj", in, 1); + octave_value_list tmp = interp.feval ("saveobj", in, 1); m = tmp(0).map_value (); } @@ -1597,8 +1619,7 @@ { octave_value t2 = dsub.tc; - Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading class elements") : Cell ( - t2)); + Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2)); m.assign (dsub.name, tcell); @@ -1611,12 +1632,14 @@ if (! reconstruct_parents ()) warning ("load: unable to reconstruct object inheritance"); - octave::load_path& lp = octave::__get_load_path__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::load_path& lp = interp.get_load_path (); if (lp.find_method (c_name, "loadobj") != "") { octave_value in = new octave_class (*this); - octave_value_list tmp = octave::feval ("loadobj", in, 1); + octave_value_list tmp = interp.feval ("loadobj", in, 1); m_map = tmp(0).map_value (); retval = true; @@ -1647,7 +1670,7 @@ } bool -octave_class::in_class_method (void) +octave_class::in_class_method () { octave::tree_evaluator& tw = octave::__get_evaluator__ (); @@ -1824,8 +1847,7 @@ octave_value obj = args(0); // not const because of find_parent_class () std::string obj_cls = obj.class_name (); - Array clsnames = args( - 1).xcellstr_value ("isa: CLASSNAME must be a string or cell array of strings"); + Array clsnames = args(1).xcellstr_value ("isa: CLASSNAME must be a string or cell array of strings"); boolNDArray matches (clsnames.dims (), false); @@ -2068,7 +2090,7 @@ octave_inline_fcn& operator = (const octave_inline_fcn& ob) = delete; - ~octave_inline_fcn (void) = default; + ~octave_inline_fcn () = default; // Override default call method because we ultimately use feval to // execute the inline function and that will push a stack frame. @@ -2093,7 +2115,7 @@ // to eliminate the octave_inline class below and replace the // octave_value::is_inline_function method with // -// bool octave_value::is_inline_function (void) const +// bool octave_value::is_inline_function () const // { // return class_name () == "inline"; // } @@ -2109,16 +2131,16 @@ octave_inline (const octave_inline&) = default; - ~octave_inline (void) = default; - - octave_base_value * clone (void) const { return new octave_inline (*this); } - - octave_base_value * empty_clone (void) const + ~octave_inline () = default; + + octave_base_value * clone () const { return new octave_inline (*this); } + + octave_base_value * empty_clone () const { return new octave_inline (octave_map (map_keys ())); } - bool is_inline_function (void) const { return true; } + bool is_inline_function () const { return true; } octave_function * function_value (bool) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-class.h --- a/libinterp/octave-value/ov-class.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-class.h Mon Jan 30 18:36:03 2023 +0100 @@ -55,7 +55,7 @@ { public: - octave_class (void) + octave_class () : octave_base_value (), m_map (), c_name (), m_parent_list (), m_obsolete_copies (0) { } @@ -78,13 +78,13 @@ : octave_base_value (s), m_map (s.m_map), c_name (s.c_name), m_parent_list (s.m_parent_list), m_obsolete_copies (0) { } - ~octave_class (void) = default; + ~octave_class () = default; - octave_base_value * clone (void) const { return new octave_class (*this); } + octave_base_value * clone () const { return new octave_class (*this); } - OCTINTERP_API octave_base_value * unique_clone (void); + OCTINTERP_API octave_base_value * unique_clone (); - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_class (octave_map (m_map.keys ()), c_name, m_parent_list); } @@ -93,7 +93,7 @@ OCTINTERP_API Cell dotref (const octave_value_list& idx); - OCTINTERP_API Matrix size (void); + OCTINTERP_API Matrix size (); OCTINTERP_API octave_idx_type xnumel (const octave_value_list&); @@ -131,21 +131,21 @@ OCTINTERP_API octave::idx_vector index_vector (bool require_integers = false) const; - dim_vector dims (void) const { return m_map.dims (); } + dim_vector dims () const { return m_map.dims (); } - OCTINTERP_API std::size_t byte_size (void) const; + OCTINTERP_API std::size_t byte_size () const; // This is the number of elements in each field. The total number // of elements is numel () * nfields (). - octave_idx_type numel (void) const + octave_idx_type numel () const { dim_vector dv = dims (); return dv.numel (); } - octave_idx_type nfields (void) const { return m_map.nfields (); } + octave_idx_type nfields () const { return m_map.nfields (); } - std::size_t nparents (void) const { return m_parent_list.size (); } + std::size_t nparents () const { return m_parent_list.size (); } octave_value reshape (const dim_vector& new_dims) const { @@ -161,22 +161,22 @@ return octave_value (new octave_class (retval)); } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool isstruct (void) const { return false; } + bool isstruct () const { return false; } - bool isobject (void) const { return true; } + bool isobject () const { return true; } - OCTINTERP_API bool is_true (void) const; + OCTINTERP_API bool is_true () const; - octave_map map_value (void) const { return m_map; } + octave_map map_value () const { return m_map; } - OCTINTERP_API string_vector map_keys (void) const; + OCTINTERP_API string_vector map_keys () const; - std::list parent_class_name_list (void) const + std::list parent_class_name_list () const { return m_parent_list; } - string_vector parent_class_names (void) const + string_vector parent_class_names () const { return string_vector (m_parent_list); } OCTINTERP_API octave_base_value * find_parent_class (const std::string&); @@ -192,11 +192,11 @@ OCTINTERP_API void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - OCTINTERP_API bool reconstruct_exemplar (void); + OCTINTERP_API bool reconstruct_exemplar (); - OCTINTERP_API static void clear_exemplar_map (void); + OCTINTERP_API static void clear_exemplar_map (); - OCTINTERP_API bool reconstruct_parents (void); + OCTINTERP_API bool reconstruct_parents (); OCTINTERP_API bool save_ascii (std::ostream& os); @@ -220,13 +220,13 @@ octave_map m_map; public: - int type_id (void) const { return t_id; } - std::string type_name (void) const { return t_name; } - std::string class_name (void) const { return c_name; } + int type_id () const { return t_id; } + std::string type_name () const { return t_name; } + std::string class_name () const { return c_name; } - static int static_type_id (void) { return t_id; } - static std::string static_type_name (void) { return t_name; } - static std::string static_class_name (void) { return ""; } + static int static_type_id () { return t_id; } + static std::string static_type_name () { return t_name; } + static std::string static_class_name () { return ""; } static OCTINTERP_API void register_type (octave::type_info&); private: @@ -236,8 +236,8 @@ std::string c_name; std::list m_parent_list; - OCTINTERP_API bool in_class_method (void); - OCTINTERP_API std::string get_current_method_class (void); + OCTINTERP_API bool in_class_method (); + OCTINTERP_API std::string get_current_method_class (); OCTINTERP_API octave_value subsasgn_common (const octave_value& obj, const std::string& type, @@ -253,7 +253,7 @@ { public: - exemplar_info (void) : m_field_names (), m_parent_class_names () { } + exemplar_info () : m_field_names (), m_parent_class_names () { } OCTINTERP_API exemplar_info (const octave_value& obj); @@ -271,13 +271,13 @@ return *this; } - octave_idx_type nfields (void) const { return m_field_names.numel (); } + octave_idx_type nfields () const { return m_field_names.numel (); } - std::size_t nparents (void) const { return m_parent_class_names.size (); } + std::size_t nparents () const { return m_parent_class_names.size (); } - string_vector fields (void) const { return m_field_names; } + string_vector fields () const { return m_field_names; } - std::list parents (void) const { return m_parent_class_names; } + std::list parents () const { return m_parent_class_names; } OCTINTERP_API bool compare (const octave_value& obj) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-classdef.cc --- a/libinterp/octave-value/ov-classdef.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-classdef.cc Mon Jan 30 18:36:03 2023 +0100 @@ -91,8 +91,29 @@ count++; args(0) = octave_value (this); + // Attempt to set up a proper value for nargout at least in the + // simple case where the cs-list-type expression - i.e., {} or + // ().x, is the leading one. + bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{' + || (type.length () > 1 && type[0] == '(' + && type[1] == '.')); + + if (maybe_cs_list_query) + { + // Set up a proper nargout for the subsref call by calling numel. + octave_value_list tmp; + if (type[0] != '.') tmp = idx.front (); + nargout = xnumel (tmp); + } + retval = meth.execute (args, nargout, true, "subsref"); + // Since we're handling subsref, if the list has more than one + // element, return it as a comma-separated list so that we can + // pass it to the evaluator + if (retval.length () > 1) + retval = octave_value (retval); + return retval; } } @@ -207,7 +228,7 @@ } Matrix -octave_classdef::size (void) +octave_classdef::size () { octave::cdef_class cls = m_object.get_class (); @@ -459,7 +480,7 @@ return ""; } -std::string octave_classdef_meta::file_name (void) const +std::string octave_classdef_meta::file_name () const { if (m_object.is_class ()) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-classdef.h --- a/libinterp/octave-value/ov-classdef.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-classdef.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,7 +48,7 @@ { public: - octave_classdef (void) + octave_classdef () : octave_base_value (), m_object () { } octave_classdef (const octave::cdef_object& obj) @@ -58,31 +58,31 @@ octave_classdef& operator = (const octave_classdef&) = delete; - ~octave_classdef (void) = default; + ~octave_classdef () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_classdef (m_object.clone ()); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_classdef (m_object.empty_clone ()); } octave_classdef * classdef_object_value (bool = false) { return this; } - octave::cdef_object get_object (void) const { return m_object; } + octave::cdef_object get_object () const { return m_object; } - octave::cdef_object& get_object_ref (void) { return m_object; } + octave::cdef_object& get_object_ref () { return m_object; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool isstruct (void) const { return false; } + bool isstruct () const { return false; } - bool isobject (void) const { return true; } + bool isobject () const { return true; } - bool is_classdef_object (void) const { return true; } + bool is_classdef_object () const { return true; } OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -120,15 +120,15 @@ const std::list& idx, const octave_value& rhs); - OCTINTERP_API Matrix size (void); + OCTINTERP_API Matrix size (); OCTINTERP_API octave_idx_type xnumel (const octave_value_list&); - string_vector map_keys (void) const { return m_object.map_keys (); } + string_vector map_keys () const { return m_object.map_keys (); } - octave_map map_value (void) const { return m_object.map_value (); } + octave_map map_value () const { return m_object.map_value (); } - dim_vector dims (void) const { return m_object.dims (); } + dim_vector dims () const { return m_object.dims (); } void set_property (octave_idx_type idx, const std::string& name, const octave_value& pval) @@ -149,13 +149,13 @@ public: - int type_id (void) const { return t_id; } - std::string type_name (void) const { return t_name; } - std::string class_name (void) const { return m_object.class_name (); } + int type_id () const { return t_id; } + std::string type_name () const { return t_name; } + std::string class_name () const { return m_object.class_name (); } - static int static_type_id (void) { return t_id; } - static std::string static_type_name (void) { return t_name; } - static std::string static_class_name (void) { return ""; } + static int static_type_id () { return t_id; } + static std::string static_type_name () { return t_name; } + static std::string static_class_name () { return ""; } static OCTINTERP_API void register_type (octave::type_info&); private: @@ -181,11 +181,11 @@ octave_classdef_meta& operator = (const octave_classdef_meta&) = delete; - ~octave_classdef_meta (void) { m_object.meta_release (); } + ~octave_classdef_meta () { m_object.meta_release (); } - bool is_classdef_meta (void) const { return true; } + bool is_classdef_meta () const { return true; } - bool is_package (void) const { return m_object.is_package(); } + bool is_package () const { return m_object.is_package(); } octave_function * function_value (bool = false) { return this; } @@ -232,7 +232,7 @@ OCTINTERP_API std::string doc_string (const std::string& meth_name) const; - OCTINTERP_API std::string file_name (void) const; + OCTINTERP_API std::string file_name () const; private: @@ -242,7 +242,7 @@ class octave_classdef_superclass_ref : public octave_function { public: - octave_classdef_superclass_ref (void) = delete; + octave_classdef_superclass_ref () = delete; octave_classdef_superclass_ref (const std::string& meth, const std::string& cls) @@ -253,9 +253,9 @@ octave_classdef_superclass_ref& operator = (const octave_classdef_superclass_ref&) = delete; - ~octave_classdef_superclass_ref (void) = default; + ~octave_classdef_superclass_ref () = default; - bool is_classdef_superclass_ref (void) const { return true; } + bool is_classdef_superclass_ref () const { return true; } octave_function * function_value (bool = false) { return this; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-colon.h --- a/libinterp/octave-value/ov-colon.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-colon.h Mon Jan 30 18:36:03 2023 +0100 @@ -49,27 +49,27 @@ { public: - octave_magic_colon (void) + octave_magic_colon () : octave_base_value () { } octave_magic_colon (const octave_magic_colon&) : octave_base_value () { } - ~octave_magic_colon (void) = default; + ~octave_magic_colon () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_magic_colon (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_magic_colon (); } octave::idx_vector index_vector (bool /* require_integers */ = false) const { return octave::idx_vector (':'); } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool is_magic_colon (void) const { return true; } + bool is_magic_colon () const { return true; } OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-complex.cc --- a/libinterp/octave-value/ov-complex.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-complex.cc Mon Jan 30 18:36:03 2023 +0100 @@ -80,16 +80,16 @@ update_message (); } - ~complex_index_exception (void) = default; + ~complex_index_exception () = default; - void update_message (void) + void update_message () { set_message (expression () + ": subscripts must be real (forgot to initialize i or j?)"); } // ID of error to throw. - const char * err_id (void) const + const char * err_id () const { return "Octave:invalid-index"; } @@ -106,7 +106,7 @@ } octave_base_value::type_conv_info -octave_complex::numeric_demotion_function (void) const +octave_complex::numeric_demotion_function () const { return octave_base_value::type_conv_info (default_numeric_demotion_function, @@ -114,7 +114,7 @@ } octave_base_value * -octave_complex::try_narrowing_conversion (void) +octave_complex::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -292,13 +292,13 @@ } octave_value -octave_complex::as_double (void) const +octave_complex::as_double () const { return scalar; } octave_value -octave_complex::as_single (void) const +octave_complex::as_single () const { return FloatComplex (scalar); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-complex.h --- a/libinterp/octave-value/ov-complex.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-complex.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_complex (void) + octave_complex () : octave_base_scalar () { } octave_complex (const Complex& c) @@ -63,20 +63,20 @@ octave_complex (const octave_complex& c) : octave_base_scalar (c) { } - ~octave_complex (void) = default; + ~octave_complex () = default; - octave_base_value * clone (void) const { return new octave_complex (*this); } + octave_base_value * clone () const { return new octave_complex (*this); } // We return an octave_complex_matrix object here instead of an // octave_complex object so that in expressions like A(2,2,2) = 2 // (for A previously undefined), A will be empty instead of a 1x1 // object. - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_complex_matrix (); } - type_conv_info numeric_demotion_function (void) const; + type_conv_info numeric_demotion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); @@ -91,15 +91,15 @@ || lo_ieee_isnan (scalar.imag ()))); } - builtin_type_t builtin_type (void) const { return btyp_complex; } + builtin_type_t builtin_type () const { return btyp_complex; } - bool is_complex_scalar (void) const { return true; } + bool is_complex_scalar () const { return true; } - bool iscomplex (void) const { return true; } + bool iscomplex () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } OCTINTERP_API double double_value (bool = false) const; @@ -162,8 +162,8 @@ return boolNDArray (dim_vector (1, 1), scalar != 0.0); } - OCTINTERP_API octave_value as_double (void) const; - OCTINTERP_API octave_value as_single (void) const; + OCTINTERP_API octave_value as_double () const; + OCTINTERP_API octave_value as_single () const; // We don't need to override both forms of the diag method. The using // declaration will avoid warnings about partially-overloaded virtual @@ -172,9 +172,9 @@ OCTINTERP_API octave_value diag (octave_idx_type m, octave_idx_type n) const; - void increment (void) { scalar += 1.0; } + void increment () { scalar += 1.0; } - void decrement (void) { scalar -= 1.0; } + void decrement () { scalar -= 1.0; } OCTINTERP_API bool save_ascii (std::ostream& os); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cs-list.h --- a/libinterp/octave-value/ov-cs-list.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cs-list.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,7 +48,7 @@ { public: - octave_cs_list (void) + octave_cs_list () : octave_base_value (), m_list () { } octave_cs_list (const octave_value_list& l) @@ -59,20 +59,20 @@ octave_cs_list (const octave_cs_list& l) : octave_base_value (), m_list (l.m_list) { } - ~octave_cs_list (void) = default; + ~octave_cs_list () = default; - octave_base_value * clone (void) const { return new octave_cs_list (*this); } - octave_base_value * empty_clone (void) const { return new octave_cs_list (); } + octave_base_value * clone () const { return new octave_cs_list (*this); } + octave_base_value * empty_clone () const { return new octave_cs_list (); } - dim_vector dims (void) const { return dim_vector (1, m_list.length ()); } + dim_vector dims () const { return dim_vector (1, m_list.length ()); } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool is_cs_list (void) const { return true; } + bool is_cs_list () const { return true; } - octave_value_list list_value (void) const { return m_list; } + octave_value_list list_value () const { return m_list; } // We don't need to override all three forms of subsref. The using // declaration will avoid warnings about partially-overloaded virtual diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cx-diag.cc --- a/libinterp/octave-value/ov-cx-diag.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cx-diag.cc Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ } octave_base_value::type_conv_info -octave_complex_diag_matrix::numeric_conversion_function (void) const +octave_complex_diag_matrix::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, @@ -71,7 +71,7 @@ } octave_base_value::type_conv_info -octave_complex_diag_matrix::numeric_demotion_function (void) const +octave_complex_diag_matrix::numeric_demotion_function () const { return octave_base_value::type_conv_info (default_numeric_demotion_function, @@ -79,7 +79,7 @@ } octave_base_value * -octave_complex_diag_matrix::try_narrowing_conversion (void) +octave_complex_diag_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -142,13 +142,13 @@ } octave_value -octave_complex_diag_matrix::as_double (void) const +octave_complex_diag_matrix::as_double () const { return m_matrix; } octave_value -octave_complex_diag_matrix::as_single (void) const +octave_complex_diag_matrix::as_single () const { return FloatComplexDiagMatrix (m_matrix); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cx-diag.h --- a/libinterp/octave-value/ov-cx-diag.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cx-diag.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,7 @@ { public: - octave_complex_diag_matrix (void) + octave_complex_diag_matrix () : octave_base_diag () { } octave_complex_diag_matrix (const ComplexDiagMatrix& m) @@ -50,28 +50,28 @@ octave_complex_diag_matrix (const octave_complex_diag_matrix& m) : octave_base_diag (m) { } - ~octave_complex_diag_matrix (void) = default; + ~octave_complex_diag_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_complex_diag_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_complex_diag_matrix (); } - OCTINTERP_API type_conv_info numeric_conversion_function (void) const; + OCTINTERP_API type_conv_info numeric_conversion_function () const; - OCTINTERP_API type_conv_info numeric_demotion_function (void) const; + OCTINTERP_API type_conv_info numeric_demotion_function () const; - OCTINTERP_API octave_base_value * try_narrowing_conversion (void); + OCTINTERP_API octave_base_value * try_narrowing_conversion (); - builtin_type_t builtin_type (void) const { return btyp_complex; } + builtin_type_t builtin_type () const { return btyp_complex; } - bool is_complex_matrix (void) const { return true; } + bool is_complex_matrix () const { return true; } - bool iscomplex (void) const { return true; } + bool iscomplex () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } OCTINTERP_API DiagMatrix diag_matrix_value (bool = false) const; @@ -83,8 +83,8 @@ OCTINTERP_API FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const; - OCTINTERP_API octave_value as_double (void) const; - OCTINTERP_API octave_value as_single (void) const; + OCTINTERP_API octave_value as_double () const; + OCTINTERP_API octave_value as_single () const; OCTINTERP_API bool save_binary (std::ostream& os, bool save_as_floats); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cx-mat.cc --- a/libinterp/octave-value/ov-cx-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cx-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -79,7 +79,7 @@ } octave_base_value::type_conv_info -octave_complex_matrix::numeric_demotion_function (void) const +octave_complex_matrix::numeric_demotion_function () const { return octave_base_value::type_conv_info (default_numeric_demotion_function, @@ -87,7 +87,7 @@ } octave_base_value * -octave_complex_matrix::try_narrowing_conversion (void) +octave_complex_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -281,13 +281,13 @@ } octave_value -octave_complex_matrix::as_double (void) const +octave_complex_matrix::as_double () const { return m_matrix; } octave_value -octave_complex_matrix::as_single (void) const +octave_complex_matrix::as_single () const { return FloatComplexNDArray (m_matrix); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cx-mat.h --- a/libinterp/octave-value/ov-cx-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cx-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_complex_matrix (void) + octave_complex_matrix () : octave_base_matrix () { } octave_complex_matrix (const ComplexNDArray& m) @@ -81,26 +81,26 @@ octave_complex_matrix (const octave_complex_matrix& cm) : octave_base_matrix (cm) { } - ~octave_complex_matrix (void) = default; + ~octave_complex_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_complex_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_complex_matrix (); } - type_conv_info numeric_demotion_function (void) const; + type_conv_info numeric_demotion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); - builtin_type_t builtin_type (void) const { return btyp_complex; } + builtin_type_t builtin_type () const { return btyp_complex; } - bool is_complex_matrix (void) const { return true; } + bool is_complex_matrix () const { return true; } - bool iscomplex (void) const { return true; } + bool iscomplex () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } double double_value (bool = false) const; @@ -138,18 +138,18 @@ SparseComplexMatrix sparse_complex_matrix_value (bool = false) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; octave_value diag (octave_idx_type k = 0) const; octave_value diag (octave_idx_type m, octave_idx_type n) const; - void increment (void) { m_matrix += Complex (1.0); } + void increment () { m_matrix += Complex (1.0); } - void decrement (void) { m_matrix -= Complex (1.0); } + void decrement () { m_matrix -= Complex (1.0); } - void changesign (void) { m_matrix.changesign (); } + void changesign () { m_matrix.changesign (); } bool save_ascii (std::ostream& os); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cx-sparse.cc --- a/libinterp/octave-value/ov-cx-sparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cx-sparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -58,7 +58,7 @@ "sparse complex matrix", "double"); octave_base_value * -octave_sparse_complex_matrix::try_narrowing_conversion (void) +octave_sparse_complex_matrix::try_narrowing_conversion () { return (matrix.all_elements_are_real () ? new octave_sparse_matrix (::real (matrix)) : nullptr); @@ -173,7 +173,7 @@ } octave_value -octave_sparse_complex_matrix::as_double (void) const +octave_sparse_complex_matrix::as_double () const { return this->matrix; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-cx-sparse.h --- a/libinterp/octave-value/ov-cx-sparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-cx-sparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ { public: - octave_sparse_complex_matrix (void) + octave_sparse_complex_matrix () : octave_base_sparse () { } octave_sparse_complex_matrix (const ComplexNDArray& m) @@ -86,24 +86,24 @@ octave_sparse_complex_matrix (const octave_sparse_complex_matrix& cm) : octave_base_sparse (cm) { } - ~octave_sparse_complex_matrix (void) = default; + ~octave_sparse_complex_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_sparse_complex_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_sparse_complex_matrix (); } - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); - builtin_type_t builtin_type (void) const { return btyp_complex; } + builtin_type_t builtin_type () const { return btyp_complex; } - bool is_complex_matrix (void) const { return true; } + bool is_complex_matrix () const { return true; } - bool iscomplex (void) const { return true; } + bool iscomplex () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } double double_value (bool = false) const; @@ -127,7 +127,7 @@ SparseBoolMatrix sparse_bool_matrix_value (bool warn = false) const; - octave_value as_double (void) const; + octave_value as_double () const; #if 0 int write (octave::stream& os, int block_size, diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-dld-fcn.cc --- a/libinterp/octave-value/ov-dld-fcn.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-dld-fcn.cc Mon Jan 30 18:36:03 2023 +0100 @@ -83,7 +83,7 @@ && oct_file_dir == file_name.substr (0, oct_file_dir.length ())); } -octave_dld_function::~octave_dld_function (void) +octave_dld_function::~octave_dld_function () { octave::dynamic_loader& dyn_loader = octave::__get_dynamic_loader__ (); @@ -91,13 +91,13 @@ } std::string -octave_dld_function::fcn_file_name (void) const +octave_dld_function::fcn_file_name () const { return m_sh_lib.file_name (); } octave::sys::time -octave_dld_function::time_parsed (void) const +octave_dld_function::time_parsed () const { return m_sh_lib.time_loaded (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-dld-fcn.h --- a/libinterp/octave-value/ov-dld-fcn.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-dld-fcn.h Mon Jan 30 18:36:03 2023 +0100 @@ -47,7 +47,7 @@ { public: - octave_dld_function (void) + octave_dld_function () : m_sh_lib (), m_time_checked (), m_system_fcn_file () { } @@ -67,22 +67,22 @@ octave_dld_function& operator = (const octave_dld_function& fcn) = delete; - ~octave_dld_function (void); + ~octave_dld_function (); void mark_fcn_file_up_to_date (const octave::sys::time& t) { m_time_checked = t; } - std::string fcn_file_name (void) const; + std::string fcn_file_name () const; - octave::sys::time time_parsed (void) const; + octave::sys::time time_parsed () const; - octave::sys::time time_checked (void) const { return m_time_checked; } + octave::sys::time time_checked () const { return m_time_checked; } - bool is_system_fcn_file (void) const { return m_system_fcn_file; } + bool is_system_fcn_file () const { return m_system_fcn_file; } - bool is_builtin_function (void) const { return false; } + bool is_builtin_function () const { return false; } - bool is_dld_function (void) const { return true; } + bool is_dld_function () const { return true; } static octave_dld_function * create (octave_builtin::fcn ff, const octave::dynamic_library& shl, @@ -94,7 +94,7 @@ const std::string& nm = "", const std::string& ds = ""); - octave::dynamic_library get_shlib (void) const + octave::dynamic_library get_shlib () const { return m_sh_lib; } private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-fcn-handle.cc --- a/libinterp/octave-value/ov-fcn-handle.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-fcn-handle.cc Mon Jan 30 18:36:03 2023 +0100 @@ -90,18 +90,18 @@ { public: - invalid_fcn_handle (void) : base_fcn_handle ("") { } + invalid_fcn_handle () : base_fcn_handle ("") { } invalid_fcn_handle (const invalid_fcn_handle&) = default; - ~invalid_fcn_handle (void) = default; - - invalid_fcn_handle * clone (void) const + ~invalid_fcn_handle () = default; + + invalid_fcn_handle * clone () const { return new invalid_fcn_handle (*this); } - std::string type (void) const { return ""; } + std::string type () const { return ""; } octave_value_list call (int nargout, const octave_value_list& args); }; @@ -120,16 +120,16 @@ internal_fcn_handle (const internal_fcn_handle&) = default; - ~internal_fcn_handle (void) = default; - - internal_fcn_handle * clone (void) const + ~internal_fcn_handle () = default; + + internal_fcn_handle * clone () const { return new internal_fcn_handle (*this); } - std::string type (void) const { return ""; } - - bool is_internal (void) const { return true; } + std::string type () const { return ""; } + + bool is_internal () const { return true; } octave_value_list call (int nargout, const octave_value_list& args); @@ -145,10 +145,10 @@ return m_fcn.user_function_value (); } - octave_value fcn_val (void) { return m_fcn; } + octave_value fcn_val () { return m_fcn; } // Should be const. - octave_scalar_map info (void); + octave_scalar_map info (); friend bool is_equal_to (const internal_fcn_handle& fh1, const internal_fcn_handle& fh2); @@ -185,16 +185,16 @@ simple_fcn_handle (const simple_fcn_handle&) = default; - ~simple_fcn_handle (void) = default; - - simple_fcn_handle * clone (void) const + ~simple_fcn_handle () = default; + + simple_fcn_handle * clone () const { return new simple_fcn_handle (*this); } - std::string type (void) const { return "simple"; } - - bool is_simple (void) const { return true; } + std::string type () const { return "simple"; } + + bool is_simple () const { return true; } octave_value_list call (int nargout, const octave_value_list& args); @@ -204,10 +204,10 @@ octave_user_function * user_function_value (bool); - octave_value fcn_val (void); + octave_value fcn_val (); // Should be const. - octave_scalar_map info (void); + octave_scalar_map info (); bool save_ascii (std::ostream& os); @@ -252,16 +252,16 @@ scoped_fcn_handle (const scoped_fcn_handle&) = default; - ~scoped_fcn_handle (void) = default; - - scoped_fcn_handle * clone (void) const + ~scoped_fcn_handle () = default; + + scoped_fcn_handle * clone () const { return new scoped_fcn_handle (*this); } - std::string type (void) const { return "scopedfunction"; } - - bool is_scoped (void) const { return true; } + std::string type () const { return "scopedfunction"; } + + bool is_scoped () const { return true; } octave_value_list call (int nargout, const octave_value_list& args); @@ -277,10 +277,10 @@ return m_fcn.user_function_value (); } - octave_value fcn_val (void) { return m_fcn; } + octave_value fcn_val () { return m_fcn; } // Should be const. - octave_scalar_map info (void); + octave_scalar_map info (); bool save_ascii (std::ostream& os); @@ -304,7 +304,7 @@ protected: - void find_function (void); + void find_function (); // The function we are handling. octave_value m_fcn; @@ -331,11 +331,11 @@ : base_fcn_handle (name), m_fcn (fcn) { } - std::string type (void) const { return "nested"; } + std::string type () const { return "nested"; } using base_fcn_handle::is_nested; - bool is_nested (void) const { return true; } + bool is_nested () const { return true; } // FIXME: These must go away. They don't do the right thing for // scoping or overloads. @@ -349,12 +349,12 @@ return m_fcn.user_function_value (); } - octave_value fcn_val (void) { return m_fcn; } - - virtual octave_value workspace (void) const = 0; + octave_value fcn_val () { return m_fcn; } + + virtual octave_value workspace () const = 0; // Should be const. - octave_scalar_map info (void); + octave_scalar_map info (); bool save_ascii (std::ostream& os); @@ -402,7 +402,7 @@ nested_fcn_handle (const nested_fcn_handle&) = default; - ~nested_fcn_handle (void) = default; + ~nested_fcn_handle () = default; using base_nested_fcn_handle::is_nested; @@ -411,21 +411,21 @@ return frame == m_stack_context; } - nested_fcn_handle * clone (void) const + nested_fcn_handle * clone () const { return new nested_fcn_handle (*this); } - octave_value make_weak_nested_handle (void) const; + octave_value make_weak_nested_handle () const; octave_value_list call (int nargout, const octave_value_list& args); - octave_value workspace (void) const; + octave_value workspace () const; friend bool is_equal_to (const nested_fcn_handle& fh1, const nested_fcn_handle& fh2); - std::shared_ptr stack_context (void) const + std::shared_ptr stack_context () const { return m_stack_context; } @@ -446,18 +446,18 @@ weak_nested_fcn_handle (const weak_nested_fcn_handle&) = default; - ~weak_nested_fcn_handle (void) = default; - - weak_nested_fcn_handle * clone (void) const + ~weak_nested_fcn_handle () = default; + + weak_nested_fcn_handle * clone () const { return new weak_nested_fcn_handle (*this); } - bool is_weak_nested (void) const { return true; } + bool is_weak_nested () const { return true; } octave_value_list call (int nargout, const octave_value_list& args); - octave_value workspace (void) const; + octave_value workspace () const; friend bool is_equal_to (const weak_nested_fcn_handle& fh1, const weak_nested_fcn_handle& fh2); @@ -497,16 +497,16 @@ class_simple_fcn_handle (const class_simple_fcn_handle&) = default; - ~class_simple_fcn_handle (void) = default; - - class_simple_fcn_handle * clone (void) const + ~class_simple_fcn_handle () = default; + + class_simple_fcn_handle * clone () const { return new class_simple_fcn_handle (*this); } - std::string type (void) const { return "classsimple"; } - - bool is_class_simple (void) const { return true; } + std::string type () const { return "classsimple"; } + + bool is_class_simple () const { return true; } octave_value_list call (int nargout, const octave_value_list& args); @@ -540,12 +540,12 @@ return m_fcn.user_function_value (); } - octave_value fcn_val (void) { return m_fcn; } + octave_value fcn_val () { return m_fcn; } // Should be const. - octave_scalar_map info (void); - - std::string dispatch_class (void) const { return m_dispatch_class; } + octave_scalar_map info (); + + std::string dispatch_class () const { return m_dispatch_class; } bool save_ascii (std::ostream& os); @@ -627,11 +627,11 @@ base_anonymous_fcn_handle (const base_anonymous_fcn_handle&) = default; - ~base_anonymous_fcn_handle (void) = default; - - std::string type (void) const { return "anonymous"; } - - bool is_anonymous (void) const { return true; } + ~base_anonymous_fcn_handle () = default; + + std::string type () const { return "anonymous"; } + + bool is_anonymous () const { return true; } // FIXME: These must go away. They don't do the right thing for // scoping or overloads. @@ -645,12 +645,12 @@ return m_fcn.user_function_value (); } - octave_value fcn_val (void) { return m_fcn; } - - virtual octave_value workspace (void) const = 0; + octave_value fcn_val () { return m_fcn; } + + virtual octave_value workspace () const = 0; // Should be const. - octave_scalar_map info (void); + octave_scalar_map info (); bool save_ascii (std::ostream& os); @@ -670,7 +670,7 @@ int current_print_indent_level) const; // Anonymous function handles are printed without a newline. - bool print_as_scalar (void) const { return false; } + bool print_as_scalar () const { return false; } bool parse (const std::string& fcn_text); @@ -704,23 +704,23 @@ anonymous_fcn_handle (const anonymous_fcn_handle&) = default; - ~anonymous_fcn_handle (void) = default; - - anonymous_fcn_handle * clone (void) const + ~anonymous_fcn_handle () = default; + + anonymous_fcn_handle * clone () const { return new anonymous_fcn_handle (*this); } - octave_value make_weak_anonymous_handle (void) const; + octave_value make_weak_anonymous_handle () const; octave_value_list call (int nargout, const octave_value_list& args); - octave_value workspace (void) const; + octave_value workspace () const; friend bool is_equal_to (const anonymous_fcn_handle& fh1, const anonymous_fcn_handle& fh2); - std::shared_ptr stack_context (void) const + std::shared_ptr stack_context () const { return m_stack_context; } @@ -743,18 +743,18 @@ weak_anonymous_fcn_handle (const weak_anonymous_fcn_handle&) = default; - ~weak_anonymous_fcn_handle (void) = default; - - weak_anonymous_fcn_handle * clone (void) const + ~weak_anonymous_fcn_handle () = default; + + weak_anonymous_fcn_handle * clone () const { return new weak_anonymous_fcn_handle (*this); } - bool is_weak_anonymous (void) const { return true; } + bool is_weak_anonymous () const { return true; } octave_value_list call (int nargout, const octave_value_list& args); - octave_value workspace (void) const; + octave_value workspace () const; friend bool is_equal_to (const weak_anonymous_fcn_handle& fh1, const weak_anonymous_fcn_handle& fh2); @@ -774,14 +774,14 @@ name.c_str ()); } -octave_value base_fcn_handle::make_weak_nested_handle (void) const +octave_value base_fcn_handle::make_weak_nested_handle () const { std::string type_str = type (); error ("invalid conversion from %s handle to weak nestead handle", type_str.c_str ()); } -octave_value base_fcn_handle::make_weak_anonymous_handle (void) const +octave_value base_fcn_handle::make_weak_anonymous_handle () const { std::string type_str = type (); error ("invalid conversion from %s handle to weak anonymous handle", @@ -921,7 +921,7 @@ return interp.feval (m_fcn, args, nargout); } -octave_scalar_map internal_fcn_handle::info (void) +octave_scalar_map internal_fcn_handle::info () { octave_scalar_map m; @@ -1166,7 +1166,7 @@ return m_fcn.is_defined () ? m_fcn.user_function_value () : nullptr; } -octave_value simple_fcn_handle::fcn_val (void) +octave_value simple_fcn_handle::fcn_val () { if (m_fcn.is_defined ()) return m_fcn; @@ -1182,7 +1182,7 @@ return m_fcn; } -octave_scalar_map simple_fcn_handle::info (void) +octave_scalar_map simple_fcn_handle::info () { octave_scalar_map m; @@ -1476,7 +1476,7 @@ return interp.feval (m_fcn, args, nargout); } -octave_scalar_map scoped_fcn_handle::info (void) +octave_scalar_map scoped_fcn_handle::info () { octave_scalar_map m; @@ -1631,7 +1631,7 @@ return false; } -void scoped_fcn_handle::find_function (void) +void scoped_fcn_handle::find_function () { // Since a scoped function is not visible by itself, try to load the // file named in m_file then find and define the scoped function. @@ -1688,7 +1688,7 @@ } } -octave_scalar_map base_nested_fcn_handle::info (void) +octave_scalar_map base_nested_fcn_handle::info () { octave_scalar_map m; @@ -1807,7 +1807,7 @@ current_print_indent_level); } -octave_value nested_fcn_handle::make_weak_nested_handle (void) const +octave_value nested_fcn_handle::make_weak_nested_handle () const { return octave_value (new octave_fcn_handle (new weak_nested_fcn_handle (*this))); @@ -1827,7 +1827,7 @@ return oct_usr_fcn->execute (tw, nargout, args); } -octave_value nested_fcn_handle::workspace (void) const +octave_value nested_fcn_handle::workspace () const { return m_stack_context->workspace (); } @@ -1857,7 +1857,7 @@ return oct_usr_fcn->execute (tw, nargout, args); } -octave_value weak_nested_fcn_handle::workspace (void) const +octave_value weak_nested_fcn_handle::workspace () const { std::shared_ptr frames = m_stack_context.lock (); @@ -1925,7 +1925,7 @@ return interp.feval (fcn_name (), args, nargout); } -octave_scalar_map class_simple_fcn_handle::info (void) +octave_scalar_map class_simple_fcn_handle::info () { octave_scalar_map m; @@ -2054,7 +2054,7 @@ const std::string base_anonymous_fcn_handle::anonymous ("@"); -octave_scalar_map base_anonymous_fcn_handle::info (void) +octave_scalar_map base_anonymous_fcn_handle::info () { octave_scalar_map m; @@ -2694,7 +2694,7 @@ m_stack_context->mark_closure_context (); } -octave_value anonymous_fcn_handle::make_weak_anonymous_handle (void) const +octave_value anonymous_fcn_handle::make_weak_anonymous_handle () const { return octave_value (new octave_fcn_handle (new weak_anonymous_fcn_handle (*this))); @@ -2714,7 +2714,7 @@ return oct_usr_fcn->execute (tw, nargout, args); } -octave_value anonymous_fcn_handle::workspace (void) const +octave_value anonymous_fcn_handle::workspace () const { octave_scalar_map local_vars_map; @@ -2768,7 +2768,7 @@ return oct_usr_fcn->execute (tw, nargout, args); } -octave_value weak_anonymous_fcn_handle::workspace (void) const +octave_value weak_anonymous_fcn_handle::workspace () const { octave_scalar_map local_vars_map; @@ -2813,7 +2813,7 @@ OCTAVE_END_NAMESPACE(octave) -octave_fcn_handle::octave_fcn_handle (void) +octave_fcn_handle::octave_fcn_handle () : octave_base_value (), m_rep (new octave::invalid_fcn_handle ()) { } @@ -2883,7 +2883,7 @@ } dim_vector -octave_fcn_handle::dims (void) const +octave_fcn_handle::dims () const { static dim_vector dv (1, 1); return dv; @@ -3459,8 +3459,7 @@ if (args.length () != 1) print_usage (); - octave_fcn_handle *fh = args( - 0).xfcn_handle_value ("functions: FCN_HANDLE argument must be a function handle object"); + octave_fcn_handle *fh = args(0).xfcn_handle_value ("functions: FCN_HANDLE argument must be a function handle object"); return ovl (fh->info ()); } @@ -3476,8 +3475,7 @@ if (args.length () != 1) print_usage (); - octave_fcn_handle *fh = args( - 0).xfcn_handle_value ("func2str: FCN_HANDLE argument must be a function handle object"); + octave_fcn_handle *fh = args(0).xfcn_handle_value ("func2str: FCN_HANDLE argument must be a function handle object"); if (! fh) error ("func2str: FCN_HANDLE must be a valid function handle"); @@ -3527,8 +3525,7 @@ if (nargin < 1 || nargin > 2) print_usage (); - std::string nm - = args(0).xstring_value ("str2func: FCN_NAME must be a string"); + std::string nm = args(0).xstring_value ("str2func: FCN_NAME must be a string"); if (nm.empty ()) error ("str2func: invalid function name"); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-fcn-handle.h --- a/libinterp/octave-value/ov-fcn-handle.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-fcn-handle.h Mon Jan 30 18:36:03 2023 +0100 @@ -58,40 +58,40 @@ base_fcn_handle (const base_fcn_handle&) = default; - virtual ~base_fcn_handle (void) = default; + virtual ~base_fcn_handle () = default; - virtual base_fcn_handle * clone (void) const = 0; + virtual base_fcn_handle * clone () const = 0; - virtual std::string type (void) const = 0; + virtual std::string type () const = 0; - virtual bool is_internal (void) const { return false; } + virtual bool is_internal () const { return false; } - virtual bool is_simple (void) const { return false; } + virtual bool is_simple () const { return false; } - virtual bool is_scoped (void) const { return false; } + virtual bool is_scoped () const { return false; } - virtual bool is_nested (void) const { return false; } + virtual bool is_nested () const { return false; } virtual bool is_nested (const std::shared_ptr&) const { return false; } - virtual bool is_weak_nested (void) const { return false; } + virtual bool is_weak_nested () const { return false; } - virtual bool is_class_simple (void) const { return false; } + virtual bool is_class_simple () const { return false; } - virtual bool is_anonymous (void) const { return false; } + virtual bool is_anonymous () const { return false; } - virtual bool is_weak_anonymous (void) const { return false; } + virtual bool is_weak_anonymous () const { return false; } - virtual octave_value make_weak_nested_handle (void) const; + virtual octave_value make_weak_nested_handle () const; - virtual octave_value make_weak_anonymous_handle (void) const; + virtual octave_value make_weak_anonymous_handle () const; - std::string fcn_name (void) const { return m_name; } + std::string fcn_name () const { return m_name; } - std::string file (void) const { return m_file; } + std::string file () const { return m_file; } octave_value_list subsref (const std::string& type, const std::list& idx, @@ -112,16 +112,16 @@ return nullptr; } - virtual octave_value fcn_val (void) { return octave_value (); } + virtual octave_value fcn_val () { return octave_value (); } - virtual octave_value workspace (void) const { return octave_value (); } + virtual octave_value workspace () const { return octave_value (); } // Should be const. - virtual octave_scalar_map info (void) { return octave_scalar_map (); } + virtual octave_scalar_map info () { return octave_scalar_map (); } virtual void set_dispatch_class (const std::string& /*class_name*/) { } - virtual std::string get_dispatch_class (void) const { return ""; } + virtual std::string get_dispatch_class () const { return ""; } octave_value convert_to_str_internal (bool pad, bool force, char type) const; @@ -146,7 +146,7 @@ { } // Function handles are printed without a newline by default. - virtual bool print_as_scalar (void) const { return true; } + virtual bool print_as_scalar () const { return true; } virtual bool set_fcn (const std::string& /*octaveroot*/, const std::string& /*fpath*/) @@ -182,7 +182,7 @@ // Creates an invalid function handle. Used to create generic // function handle objects when loading function handles. Further // dispatch happens in the octave_fcn_handle load/save functions. - octave_fcn_handle (void); + octave_fcn_handle (); // Create a handle to a built-in or internal function. octave_fcn_handle (const octave_value& fcn); @@ -225,14 +225,14 @@ octave_fcn_handle (const octave_fcn_handle& fh); - ~octave_fcn_handle (void) = default; + ~octave_fcn_handle () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_fcn_handle (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_fcn_handle (); } @@ -258,44 +258,44 @@ octave_value_list call (int nargout, const octave_value_list& args); - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - builtin_type_t builtin_type (void) const { return btyp_func_handle; } + builtin_type_t builtin_type () const { return btyp_func_handle; } - bool is_function_handle (void) const { return true; } + bool is_function_handle () const { return true; } - bool is_internal (void) const { return m_rep->is_internal (); } + bool is_internal () const { return m_rep->is_internal (); } - bool is_simple (void) const { return m_rep->is_simple (); } + bool is_simple () const { return m_rep->is_simple (); } - bool is_scoped (void) const { return m_rep->is_scoped (); } + bool is_scoped () const { return m_rep->is_scoped (); } - bool is_nested (void) const { return m_rep->is_nested (); } + bool is_nested () const { return m_rep->is_nested (); } bool is_nested (const std::shared_ptr& frame) const { return m_rep->is_nested (frame); } - bool is_weak_nested (void) const { return m_rep->is_weak_nested (); } + bool is_weak_nested () const { return m_rep->is_weak_nested (); } - bool is_class_simple (void) const { return m_rep->is_class_simple (); } + bool is_class_simple () const { return m_rep->is_class_simple (); } - bool is_anonymous (void) const { return m_rep->is_anonymous (); } + bool is_anonymous () const { return m_rep->is_anonymous (); } - bool is_weak_anonymous (void) const { return m_rep->is_weak_anonymous (); } + bool is_weak_anonymous () const { return m_rep->is_weak_anonymous (); } - octave_value make_weak_nested_handle (void) const + octave_value make_weak_nested_handle () const { return m_rep->make_weak_nested_handle (); } - octave_value make_weak_anonymous_handle (void) const + octave_value make_weak_anonymous_handle () const { return m_rep->make_weak_anonymous_handle (); } - dim_vector dims (void) const; + dim_vector dims () const; // FIXME: These must go away. They don't do the right thing for // scoping or overloads. @@ -311,24 +311,24 @@ octave_fcn_handle * fcn_handle_value (bool = false) { return this; } - octave_value fcn_val (void) { return m_rep->fcn_val (); } + octave_value fcn_val () { return m_rep->fcn_val (); } // FCN_NAME should be eliminated. - std::string fcn_name (void) const { return m_rep->fcn_name (); } + std::string fcn_name () const { return m_rep->fcn_name (); } - octave_value workspace (void) const + octave_value workspace () const { return m_rep->workspace (); } - octave_scalar_map info (void) { return m_rep->info (); } + octave_scalar_map info () { return m_rep->info (); } void set_dispatch_class (const std::string& class_name) { m_rep->set_dispatch_class (class_name); } - std::string get_dispatch_class (void) const + std::string get_dispatch_class () const { return m_rep->get_dispatch_class (); } @@ -356,7 +356,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; // Simple function handles are printed without a newline. - bool print_as_scalar (void) const { return m_rep->print_as_scalar (); } + bool print_as_scalar () const { return m_rep->print_as_scalar (); } friend bool is_equal_to (const octave_fcn_handle& fh1, const octave_fcn_handle& fh2); @@ -365,7 +365,7 @@ std::shared_ptr m_rep; - octave::base_fcn_handle * get_rep (void) const { return m_rep.get (); } + octave::base_fcn_handle * get_rep () const { return m_rep.get (); } DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-fcn.cc --- a/libinterp/octave-value/ov-fcn.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-fcn.cc Mon Jan 30 18:36:03 2023 +0100 @@ -35,13 +35,13 @@ #include "pt-eval.h" octave_base_value * -octave_function::clone (void) const +octave_function::clone () const { panic_impossible (); } octave_base_value * -octave_function::empty_clone (void) const +octave_function::empty_clone () const { panic_impossible (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-fcn.h --- a/libinterp/octave-value/ov-fcn.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-fcn.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_function (void) + octave_function () : m_relative (false), m_locked (false), m_private (false), m_dispatch_class (), m_package_name (), m_name (), m_dir_name (), m_doc () { } @@ -65,49 +65,49 @@ octave_function& operator = (const octave_function& f) = delete; - ~octave_function (void) = default; + ~octave_function () = default; - octave_base_value * clone (void) const; - octave_base_value * empty_clone (void) const; + octave_base_value * clone () const; + octave_base_value * empty_clone () const; - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_function (void) const { return true; } + bool is_function () const { return true; } - virtual bool is_system_fcn_file (void) const { return false; } + virtual bool is_system_fcn_file () const { return false; } - virtual std::string fcn_file_name (void) const { return ""; } + virtual std::string fcn_file_name () const { return ""; } - virtual std::string src_file_name (void) const { return ""; } + virtual std::string src_file_name () const { return ""; } // The name to show in the profiler (also used as map-key). - virtual std::string profiler_name (void) const { return name (); } + virtual std::string profiler_name () const { return name (); } - virtual std::string parent_fcn_name (void) const { return ""; } + virtual std::string parent_fcn_name () const { return ""; } - virtual octave::symbol_scope parent_fcn_scope (void) const + virtual octave::symbol_scope parent_fcn_scope () const { return octave::symbol_scope (); } - virtual std::list parent_fcn_names (void) const + virtual std::list parent_fcn_names () const { return std::list (); } virtual void mark_fcn_file_up_to_date (const octave::sys::time&) { } - virtual octave::symbol_scope scope (void) { return octave::symbol_scope (); } + virtual octave::symbol_scope scope () { return octave::symbol_scope (); } - virtual octave::sys::time time_parsed (void) const + virtual octave::sys::time time_parsed () const { return octave::sys::time (static_cast (0)); } - virtual octave::sys::time time_checked (void) const + virtual octave::sys::time time_checked () const { return octave::sys::time (static_cast (0)); } - virtual int call_depth (void) const { return 0; } + virtual int call_depth () const { return 0; } - virtual bool is_nested_function (void) const { return false; } + virtual bool is_nested_function () const { return false; } - virtual bool is_parent_function (void) const { return false; } + virtual bool is_parent_function () const { return false; } - virtual bool is_subfunction (void) const { return false; } + virtual bool is_subfunction () const { return false; } bool is_class_constructor (const std::string& cname = "") const { @@ -133,9 +133,9 @@ virtual bool is_classdef_method (const std::string& = "") const { return false; } - virtual bool takes_varargs (void) const { return false; } + virtual bool takes_varargs () const { return false; } - virtual bool takes_var_return (void) const { return false; } + virtual bool takes_var_return () const { return false; } // The next two functions are for dispatching to built-in // functions given built-in classes. @@ -147,11 +147,11 @@ void stash_dispatch_class (const std::string& nm) { m_dispatch_class = nm; } - std::string dispatch_class (void) const { return m_dispatch_class; } + std::string dispatch_class () const { return m_dispatch_class; } void stash_package_name (const std::string& pack) { m_package_name = pack; } - std::string package_name (void) const { return m_package_name; } + std::string package_name () const { return m_package_name; } virtual void mark_as_private_function (const std::string& cname = "") @@ -160,7 +160,7 @@ m_dispatch_class = cname; } - bool is_private_function (void) const { return m_private; } + bool is_private_function () const { return m_private; } bool is_private_function_of_class (const std::string& nm) const { return m_private && m_dispatch_class == nm; } @@ -169,45 +169,45 @@ is_anonymous_function_of_class (const std::string& = "") const { return false; } - std::string dir_name (void) const { return m_dir_name; } + std::string dir_name () const { return m_dir_name; } void stash_dir_name (const std::string& dir) { m_dir_name = dir; } - void lock (void) + void lock () { this->lock_subfunctions (); m_locked = true; } - void unlock (void) + void unlock () { this->unlock_subfunctions (); m_locked = false; } - bool islocked (void) const { return m_locked; } + bool islocked () const { return m_locked; } - virtual void lock_subfunctions (void) { } + virtual void lock_subfunctions () { } - virtual void unlock_subfunctions (void) { } + virtual void unlock_subfunctions () { } - virtual void maybe_relocate_end (void) { } + virtual void maybe_relocate_end () { } // Not valid until after the function is completely parsed. - virtual bool has_subfunctions (void) const { return false; } + virtual bool has_subfunctions () const { return false; } virtual void stash_subfunction_names (const std::list&) { } - virtual std::list subfunction_names (void) const + virtual std::list subfunction_names () const { return std::list (); } - void mark_relative (void) { m_relative = true; } + void mark_relative () { m_relative = true; } - bool is_relative (void) const { return m_relative; } + bool is_relative () const { return m_relative; } - std::string name (void) const { return m_name; } + std::string name () const { return m_name; } - std::string canonical_name (void) const + std::string canonical_name () const { if (m_package_name.empty ()) return m_name; @@ -220,7 +220,7 @@ virtual std::string doc_string (const std::string& /*meth_name*/ = "") const { return m_doc; } - virtual void unload (void) { } + virtual void unload () { } virtual void accept (octave::tree_walker&) { } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-float.cc --- a/libinterp/octave-value/ov-float.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-float.cc Mon Jan 30 18:36:03 2023 +0100 @@ -106,61 +106,61 @@ } octave_value -octave_float_scalar::as_double (void) const +octave_float_scalar::as_double () const { return static_cast (scalar); } octave_value -octave_float_scalar::as_single (void) const +octave_float_scalar::as_single () const { return scalar; } octave_value -octave_float_scalar::as_int8 (void) const +octave_float_scalar::as_int8 () const { return octave_int8 (scalar); } octave_value -octave_float_scalar::as_int16 (void) const +octave_float_scalar::as_int16 () const { return octave_int16 (scalar); } octave_value -octave_float_scalar::as_int32 (void) const +octave_float_scalar::as_int32 () const { return octave_int32 (scalar); } octave_value -octave_float_scalar::as_int64 (void) const +octave_float_scalar::as_int64 () const { return octave_int64 (scalar); } octave_value -octave_float_scalar::as_uint8 (void) const +octave_float_scalar::as_uint8 () const { return octave_uint8 (scalar); } octave_value -octave_float_scalar::as_uint16 (void) const +octave_float_scalar::as_uint16 () const { return octave_uint16 (scalar); } octave_value -octave_float_scalar::as_uint32 (void) const +octave_float_scalar::as_uint32 () const { return octave_uint32 (scalar); } octave_value -octave_float_scalar::as_uint64 (void) const +octave_float_scalar::as_uint64 () const { return octave_uint64 (scalar); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-float.h --- a/libinterp/octave-value/ov-float.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-float.h Mon Jan 30 18:36:03 2023 +0100 @@ -56,7 +56,7 @@ { public: - octave_float_scalar (void) + octave_float_scalar () : octave_base_scalar (0.0) { } octave_float_scalar (float d) @@ -65,15 +65,15 @@ octave_float_scalar (const octave_float_scalar& s) : octave_base_scalar (s) { } - ~octave_float_scalar (void) = default; + ~octave_float_scalar () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_float_scalar (*this); } // We return an octave_matrix here instead of an octave_float_scalar so // that in expressions like A(2,2,2) = 2 (for A previously // undefined), A will be empty instead of a 1x1 object. - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_float_matrix (); } octave_value do_index_op (const octave_value_list& idx, @@ -85,51 +85,51 @@ octave_value any (int = 0) const { return (scalar != 0 && ! lo_ieee_isnan (scalar)); } - builtin_type_t builtin_type (void) const { return btyp_float; } + builtin_type_t builtin_type () const { return btyp_float; } - bool is_real_scalar (void) const { return true; } + bool is_real_scalar () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_single_type (void) const { return true; } + bool is_single_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } int8NDArray - int8_array_value (void) const + int8_array_value () const { return int8NDArray (dim_vector (1, 1), scalar); } int16NDArray - int16_array_value (void) const + int16_array_value () const { return int16NDArray (dim_vector (1, 1), scalar); } int32NDArray - int32_array_value (void) const + int32_array_value () const { return int32NDArray (dim_vector (1, 1), scalar); } int64NDArray - int64_array_value (void) const + int64_array_value () const { return int64NDArray (dim_vector (1, 1), scalar); } uint8NDArray - uint8_array_value (void) const + uint8_array_value () const { return uint8NDArray (dim_vector (1, 1), scalar); } uint16NDArray - uint16_array_value (void) const + uint16_array_value () const { return uint16NDArray (dim_vector (1, 1), scalar); } uint32NDArray - uint32_array_value (void) const + uint32_array_value () const { return uint32NDArray (dim_vector (1, 1), scalar); } uint64NDArray - uint64_array_value (void) const + uint64_array_value () const { return uint64NDArray (dim_vector (1, 1), scalar); } #define DEFINE_INT_SCALAR_VALUE(TYPE) \ octave_ ## TYPE \ - TYPE ## _scalar_value (void) const \ + TYPE ## _scalar_value () const \ { \ return octave_ ## TYPE (scalar); \ } @@ -220,18 +220,18 @@ return boolNDArray (dim_vector (1, 1), scalar); } - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; // We don't need to override both forms of the diag method. The using // declaration will avoid warnings about partially-overloaded virtual @@ -242,9 +242,9 @@ octave_value convert_to_str_internal (bool pad, bool force, char type) const; - void increment (void) { ++scalar; } + void increment () { ++scalar; } - void decrement (void) { --scalar; } + void decrement () { --scalar; } bool save_ascii (std::ostream& os); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-complex.cc --- a/libinterp/octave-value/ov-flt-complex.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-complex.cc Mon Jan 30 18:36:03 2023 +0100 @@ -64,7 +64,7 @@ "float complex scalar", "single"); octave_base_value * -octave_float_complex::try_narrowing_conversion (void) +octave_float_complex::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -230,13 +230,13 @@ } octave_value -octave_float_complex::as_double (void) const +octave_float_complex::as_double () const { return Complex (scalar); } octave_value -octave_float_complex::as_single (void) const +octave_float_complex::as_single () const { return scalar; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-complex.h --- a/libinterp/octave-value/ov-flt-complex.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-complex.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_float_complex (void) + octave_float_complex () : octave_base_scalar () { } octave_float_complex (const FloatComplex& c) @@ -63,19 +63,19 @@ octave_float_complex (const octave_float_complex& c) : octave_base_scalar (c) { } - ~octave_float_complex (void) = default; + ~octave_float_complex () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_float_complex (*this); } // We return an octave_float_complex_matrix object here instead of an // octave_float_complex object so that in expressions like A(2,2,2) = 2 // (for A previously undefined), A will be empty instead of a 1x1 // object. - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_float_complex_matrix (); } - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); @@ -87,15 +87,15 @@ || lo_ieee_isnan (scalar.imag ()))); } - builtin_type_t builtin_type (void) const { return btyp_float_complex; } + builtin_type_t builtin_type () const { return btyp_float_complex; } - bool is_complex_scalar (void) const { return true; } + bool is_complex_scalar () const { return true; } - bool iscomplex (void) const { return true; } + bool iscomplex () const { return true; } - bool is_single_type (void) const { return true; } + bool is_single_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } double double_value (bool = false) const; @@ -155,8 +155,8 @@ return boolNDArray (dim_vector (1, 1), scalar != 1.0f); } - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; // We don't need to override both forms of the diag method. The using // declaration will avoid warnings about partially-overloaded virtual @@ -165,9 +165,9 @@ octave_value diag (octave_idx_type m, octave_idx_type n) const; - void increment (void) { scalar += 1.0; } + void increment () { scalar += 1.0; } - void decrement (void) { scalar -= 1.0; } + void decrement () { scalar -= 1.0; } bool save_ascii (std::ostream& os); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-cx-diag.cc --- a/libinterp/octave-value/ov-flt-cx-diag.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-cx-diag.cc Mon Jan 30 18:36:03 2023 +0100 @@ -52,14 +52,14 @@ } octave_base_value::type_conv_info -octave_float_complex_diag_matrix::numeric_conversion_function (void) const +octave_float_complex_diag_matrix::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_float_complex_matrix::static_type_id ()); } octave_base_value * -octave_float_complex_diag_matrix::try_narrowing_conversion (void) +octave_float_complex_diag_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -122,13 +122,13 @@ } octave_value -octave_float_complex_diag_matrix::as_double (void) const +octave_float_complex_diag_matrix::as_double () const { return ComplexDiagMatrix (m_matrix); } octave_value -octave_float_complex_diag_matrix::as_single (void) const +octave_float_complex_diag_matrix::as_single () const { return m_matrix; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-cx-diag.h --- a/libinterp/octave-value/ov-flt-cx-diag.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-cx-diag.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ { public: - octave_float_complex_diag_matrix (void) + octave_float_complex_diag_matrix () : octave_base_diag () { } octave_float_complex_diag_matrix (const FloatComplexDiagMatrix& m) @@ -51,26 +51,26 @@ octave_float_complex_diag_matrix (const octave_float_complex_diag_matrix& m) : octave_base_diag (m) { } - ~octave_float_complex_diag_matrix (void) = default; + ~octave_float_complex_diag_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_float_complex_diag_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_float_complex_diag_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); - builtin_type_t builtin_type (void) const { return btyp_float_complex; } + builtin_type_t builtin_type () const { return btyp_float_complex; } - bool is_complex_matrix (void) const { return true; } + bool is_complex_matrix () const { return true; } - bool iscomplex (void) const { return true; } + bool iscomplex () const { return true; } - bool is_single_type (void) const { return true; } + bool is_single_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } DiagMatrix diag_matrix_value (bool = false) const; @@ -80,8 +80,8 @@ FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; bool save_binary (std::ostream& os, bool save_as_floats); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-cx-mat.cc --- a/libinterp/octave-value/ov-flt-cx-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-cx-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -75,7 +75,7 @@ "float complex matrix", "single"); octave_base_value * -octave_float_complex_matrix::try_narrowing_conversion (void) +octave_float_complex_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -255,13 +255,13 @@ } octave_value -octave_float_complex_matrix::as_double (void) const +octave_float_complex_matrix::as_double () const { return ComplexNDArray (m_matrix); } octave_value -octave_float_complex_matrix::as_single (void) const +octave_float_complex_matrix::as_single () const { return m_matrix; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-cx-mat.h --- a/libinterp/octave-value/ov-flt-cx-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-cx-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_float_complex_matrix (void) + octave_float_complex_matrix () : octave_base_matrix () { } octave_float_complex_matrix (const FloatComplexNDArray& m) @@ -81,24 +81,24 @@ octave_float_complex_matrix (const octave_float_complex_matrix& cm) : octave_base_matrix (cm) { } - ~octave_float_complex_matrix (void) = default; + ~octave_float_complex_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_float_complex_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_float_complex_matrix (); } - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); - builtin_type_t builtin_type (void) const { return btyp_float_complex; } + builtin_type_t builtin_type () const { return btyp_float_complex; } - bool is_complex_matrix (void) const { return true; } + bool is_complex_matrix () const { return true; } - bool iscomplex (void) const { return true; } + bool iscomplex () const { return true; } - bool is_single_type (void) const { return true; } + bool is_single_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } double double_value (bool = false) const; @@ -134,18 +134,18 @@ SparseComplexMatrix sparse_complex_matrix_value (bool = false) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; octave_value diag (octave_idx_type k = 0) const; octave_value diag (octave_idx_type m, octave_idx_type n) const; - void increment (void) { m_matrix += FloatComplex (1.0); } + void increment () { m_matrix += FloatComplex (1.0); } - void decrement (void) { m_matrix -= FloatComplex (1.0); } + void decrement () { m_matrix -= FloatComplex (1.0); } - void changesign (void) { m_matrix.changesign (); } + void changesign () { m_matrix.changesign (); } bool save_ascii (std::ostream& os); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-re-diag.cc --- a/libinterp/octave-value/ov-flt-re-diag.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-re-diag.cc Mon Jan 30 18:36:03 2023 +0100 @@ -51,14 +51,14 @@ } octave_base_value::type_conv_info -octave_float_diag_matrix::numeric_conversion_function (void) const +octave_float_diag_matrix::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_float_matrix::static_type_id ()); } octave_base_value * -octave_float_diag_matrix::try_narrowing_conversion (void) +octave_float_diag_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -93,61 +93,61 @@ } octave_value -octave_float_diag_matrix::as_double (void) const +octave_float_diag_matrix::as_double () const { return DiagMatrix (m_matrix); } octave_value -octave_float_diag_matrix::as_single (void) const +octave_float_diag_matrix::as_single () const { return m_matrix; } octave_value -octave_float_diag_matrix::as_int8 (void) const +octave_float_diag_matrix::as_int8 () const { return int8_array_value (); } octave_value -octave_float_diag_matrix::as_int16 (void) const +octave_float_diag_matrix::as_int16 () const { return int16_array_value (); } octave_value -octave_float_diag_matrix::as_int32 (void) const +octave_float_diag_matrix::as_int32 () const { return int32_array_value (); } octave_value -octave_float_diag_matrix::as_int64 (void) const +octave_float_diag_matrix::as_int64 () const { return int64_array_value (); } octave_value -octave_float_diag_matrix::as_uint8 (void) const +octave_float_diag_matrix::as_uint8 () const { return uint8_array_value (); } octave_value -octave_float_diag_matrix::as_uint16 (void) const +octave_float_diag_matrix::as_uint16 () const { return uint16_array_value (); } octave_value -octave_float_diag_matrix::as_uint32 (void) const +octave_float_diag_matrix::as_uint32 () const { return uint32_array_value (); } octave_value -octave_float_diag_matrix::as_uint64 (void) const +octave_float_diag_matrix::as_uint64 () const { return uint64_array_value (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-re-diag.h --- a/libinterp/octave-value/ov-flt-re-diag.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-re-diag.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ { public: - octave_float_diag_matrix (void) + octave_float_diag_matrix () : octave_base_diag () { } octave_float_diag_matrix (const FloatDiagMatrix& m) @@ -51,26 +51,26 @@ octave_float_diag_matrix (const octave_float_diag_matrix& m) : octave_base_diag (m) { } - ~octave_float_diag_matrix (void) = default; + ~octave_float_diag_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_float_diag_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_float_diag_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); - builtin_type_t builtin_type (void) const { return btyp_float; } + builtin_type_t builtin_type () const { return btyp_float; } - bool is_real_matrix (void) const { return true; } + bool is_real_matrix () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_single_type (void) const { return true; } + bool is_single_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } DiagMatrix diag_matrix_value (bool = false) const; @@ -80,18 +80,18 @@ FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; bool save_binary (std::ostream& os, bool save_as_floats); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-re-mat.cc --- a/libinterp/octave-value/ov-flt-re-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-re-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -90,7 +90,7 @@ "single"); octave_base_value * -octave_float_matrix::try_narrowing_conversion (void) +octave_float_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -240,61 +240,61 @@ } octave_value -octave_float_matrix::as_double (void) const +octave_float_matrix::as_double () const { return NDArray (m_matrix); } octave_value -octave_float_matrix::as_single (void) const +octave_float_matrix::as_single () const { return FloatNDArray (m_matrix); } octave_value -octave_float_matrix::as_int8 (void) const +octave_float_matrix::as_int8 () const { return int8NDArray (m_matrix); } octave_value -octave_float_matrix::as_int16 (void) const +octave_float_matrix::as_int16 () const { return int16NDArray (m_matrix); } octave_value -octave_float_matrix::as_int32 (void) const +octave_float_matrix::as_int32 () const { return int32NDArray (m_matrix); } octave_value -octave_float_matrix::as_int64 (void) const +octave_float_matrix::as_int64 () const { return int64NDArray (m_matrix); } octave_value -octave_float_matrix::as_uint8 (void) const +octave_float_matrix::as_uint8 () const { return uint8NDArray (m_matrix); } octave_value -octave_float_matrix::as_uint16 (void) const +octave_float_matrix::as_uint16 () const { return uint16NDArray (m_matrix); } octave_value -octave_float_matrix::as_uint32 (void) const +octave_float_matrix::as_uint32 () const { return uint32NDArray (m_matrix); } octave_value -octave_float_matrix::as_uint64 (void) const +octave_float_matrix::as_uint64 () const { return uint64NDArray (m_matrix); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-flt-re-mat.h --- a/libinterp/octave-value/ov-flt-re-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-flt-re-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_float_matrix (void) + octave_float_matrix () : octave_base_matrix () { } octave_float_matrix (const FloatMatrix& m) @@ -81,14 +81,14 @@ octave_float_matrix (const octave_float_matrix& m) : octave_base_matrix (m) { } - ~octave_float_matrix (void) = default; + ~octave_float_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_float_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_float_matrix (); } - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); octave::idx_vector index_vector (bool /* require_integers */ = false) const { @@ -96,39 +96,39 @@ : set_idx_cache (octave::idx_vector (m_matrix)); } - builtin_type_t builtin_type (void) const { return btyp_float; } + builtin_type_t builtin_type () const { return btyp_float; } - bool is_real_matrix (void) const { return true; } + bool is_real_matrix () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_single_type (void) const { return true; } + bool is_single_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } int8NDArray - int8_array_value (void) const { return int8NDArray (m_matrix); } + int8_array_value () const { return int8NDArray (m_matrix); } int16NDArray - int16_array_value (void) const { return int16NDArray (m_matrix); } + int16_array_value () const { return int16NDArray (m_matrix); } int32NDArray - int32_array_value (void) const { return int32NDArray (m_matrix); } + int32_array_value () const { return int32NDArray (m_matrix); } int64NDArray - int64_array_value (void) const { return int64NDArray (m_matrix); } + int64_array_value () const { return int64NDArray (m_matrix); } uint8NDArray - uint8_array_value (void) const { return uint8NDArray (m_matrix); } + uint8_array_value () const { return uint8NDArray (m_matrix); } uint16NDArray - uint16_array_value (void) const { return uint16NDArray (m_matrix); } + uint16_array_value () const { return uint16NDArray (m_matrix); } uint32NDArray - uint32_array_value (void) const { return uint32NDArray (m_matrix); } + uint32_array_value () const { return uint32NDArray (m_matrix); } uint64NDArray - uint64_array_value (void) const { return uint64NDArray (m_matrix); } + uint64_array_value () const { return uint64NDArray (m_matrix); } double double_value (bool = false) const; @@ -168,29 +168,29 @@ SparseComplexMatrix sparse_complex_matrix_value (bool = false) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; octave_value diag (octave_idx_type k = 0) const; octave_value diag (octave_idx_type m, octave_idx_type n) const; // Use matrix_ref here to clear index cache. - void increment (void) { matrix_ref () += 1.0; } + void increment () { matrix_ref () += 1.0; } - void decrement (void) { matrix_ref () -= 1.0; } + void decrement () { matrix_ref () -= 1.0; } - void changesign (void) { matrix_ref ().changesign (); } + void changesign () { matrix_ref ().changesign (); } octave_value convert_to_str_internal (bool pad, bool force, char type) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-intx.h --- a/libinterp/octave-value/ov-intx.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-intx.h Mon Jan 30 18:36:03 2023 +0100 @@ -56,7 +56,7 @@ { public: - OCTAVE_VALUE_INT_MATRIX_T (void) + OCTAVE_VALUE_INT_MATRIX_T () : octave_base_int_matrix> () { } OCTAVE_VALUE_INT_MATRIX_T (const intNDArray& nda) @@ -66,45 +66,45 @@ : octave_base_int_matrix> (intNDArray (nda)) { } - ~OCTAVE_VALUE_INT_MATRIX_T (void) = default; + ~OCTAVE_VALUE_INT_MATRIX_T () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new OCTAVE_VALUE_INT_MATRIX_T (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new OCTAVE_VALUE_INT_MATRIX_T (); } - bool OCTAVE_TYPE_PREDICATE_FUNCTION (void) const { return true; } + bool OCTAVE_TYPE_PREDICATE_FUNCTION () const { return true; } - bool isinteger (void) const { return true; } + bool isinteger () const { return true; } - builtin_type_t builtin_type (void) const { return OCTAVE_INT_BTYP; } + builtin_type_t builtin_type () const { return OCTAVE_INT_BTYP; } public: int8NDArray - int8_array_value (void) const { return int8NDArray (m_matrix); } + int8_array_value () const { return int8NDArray (m_matrix); } int16NDArray - int16_array_value (void) const { return int16NDArray (m_matrix); } + int16_array_value () const { return int16NDArray (m_matrix); } int32NDArray - int32_array_value (void) const { return int32NDArray (m_matrix); } + int32_array_value () const { return int32NDArray (m_matrix); } int64NDArray - int64_array_value (void) const { return int64NDArray (m_matrix); } + int64_array_value () const { return int64NDArray (m_matrix); } uint8NDArray - uint8_array_value (void) const { return uint8NDArray (m_matrix); } + uint8_array_value () const { return uint8NDArray (m_matrix); } uint16NDArray - uint16_array_value (void) const { return uint16NDArray (m_matrix); } + uint16_array_value () const { return uint16NDArray (m_matrix); } uint32NDArray - uint32_array_value (void) const { return uint32NDArray (m_matrix); } + uint32_array_value () const { return uint32NDArray (m_matrix); } uint64NDArray - uint64_array_value (void) const { return uint64NDArray (m_matrix); } + uint64_array_value () const { return uint64NDArray (m_matrix); } double double_value (bool = false) const @@ -286,17 +286,17 @@ } // Use matrix_ref here to clear index cache. - void increment (void) + void increment () { matrix_ref () += OCTAVE_INT_T (1); } - void decrement (void) + void decrement () { matrix_ref () -= OCTAVE_INT_T (1); } - void changesign (void) + void changesign () { matrix_ref ().changesign (); } @@ -393,18 +393,18 @@ { public: - OCTAVE_VALUE_INT_SCALAR_T (void) + OCTAVE_VALUE_INT_SCALAR_T () : octave_base_int_scalar () { } OCTAVE_VALUE_INT_SCALAR_T (const OCTAVE_INT_T& nda) : octave_base_int_scalar (nda) { } - ~OCTAVE_VALUE_INT_SCALAR_T (void) = default; + ~OCTAVE_VALUE_INT_SCALAR_T () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new OCTAVE_VALUE_INT_SCALAR_T (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new OCTAVE_VALUE_INT_MATRIX_T (); } octave_value do_index_op (const octave_value_list& idx, @@ -427,68 +427,68 @@ return tmp.index_op (idx, resize_ok); } - bool OCTAVE_TYPE_PREDICATE_FUNCTION (void) const { return true; } + bool OCTAVE_TYPE_PREDICATE_FUNCTION () const { return true; } - bool isinteger (void) const { return true; } + bool isinteger () const { return true; } - builtin_type_t builtin_type (void) const { return OCTAVE_INT_BTYP; } + builtin_type_t builtin_type () const { return OCTAVE_INT_BTYP; } public: octave_int8 - int8_scalar_value (void) const { return octave_int8 (scalar); } + int8_scalar_value () const { return octave_int8 (scalar); } octave_int16 - int16_scalar_value (void) const { return octave_int16 (scalar); } + int16_scalar_value () const { return octave_int16 (scalar); } octave_int32 - int32_scalar_value (void) const { return octave_int32 (scalar); } + int32_scalar_value () const { return octave_int32 (scalar); } octave_int64 - int64_scalar_value (void) const { return octave_int64 (scalar); } + int64_scalar_value () const { return octave_int64 (scalar); } octave_uint8 - uint8_scalar_value (void) const { return octave_uint8 (scalar); } + uint8_scalar_value () const { return octave_uint8 (scalar); } octave_uint16 - uint16_scalar_value (void) const { return octave_uint16 (scalar); } + uint16_scalar_value () const { return octave_uint16 (scalar); } octave_uint32 - uint32_scalar_value (void) const { return octave_uint32 (scalar); } + uint32_scalar_value () const { return octave_uint32 (scalar); } octave_uint64 - uint64_scalar_value (void) const { return octave_uint64 (scalar); } + uint64_scalar_value () const { return octave_uint64 (scalar); } int8NDArray - int8_array_value (void) const + int8_array_value () const { return int8NDArray (dim_vector (1, 1), int8_scalar_value ()); } int16NDArray - int16_array_value (void) const + int16_array_value () const { return int16NDArray (dim_vector (1, 1), int16_scalar_value ()); } int32NDArray - int32_array_value (void) const + int32_array_value () const { return int32NDArray (dim_vector (1, 1), int32_scalar_value ()); } int64NDArray - int64_array_value (void) const + int64_array_value () const { return int64NDArray (dim_vector (1, 1), int64_scalar_value ()); } uint8NDArray - uint8_array_value (void) const + uint8_array_value () const { return uint8NDArray (dim_vector (1, 1), uint8_scalar_value ()); } uint16NDArray - uint16_array_value (void) const + uint16_array_value () const { return uint16NDArray (dim_vector (1, 1), uint16_scalar_value ()); } uint32NDArray - uint32_array_value (void) const + uint32_array_value () const { return uint32NDArray (dim_vector (1, 1), uint32_scalar_value ()); } uint64NDArray - uint64_array_value (void) const + uint64_array_value () const { return uint64NDArray (dim_vector (1, 1), uint64_scalar_value ()); } octave_value resize (const dim_vector& dv, bool fill = false) const @@ -611,12 +611,12 @@ return retval; } - void increment (void) + void increment () { scalar += OCTAVE_INT_T (1); } - void decrement (void) + void decrement () { scalar -= OCTAVE_INT_T (1); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-java.cc --- a/libinterp/octave-value/ov-java.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-java.cc Mon Jan 30 18:36:03 2023 +0100 @@ -63,7 +63,6 @@ #include "oct-process.h" #include "oct-shlib.h" #include "ov-java.h" -#include "parse.h" #include "variables.h" #if defined (HAVE_JAVA) @@ -230,7 +229,7 @@ { public: - JVMArgs (void) + JVMArgs () { m_vm_args.version = JNI_VERSION_1_6; m_vm_args.nOptions = 0; @@ -238,7 +237,7 @@ m_vm_args.ignoreUnrecognized = false; } - ~JVMArgs (void) + ~JVMArgs () { clean (); } @@ -276,7 +275,7 @@ private: - void clean (void) + void clean () { if (m_vm_args.options != nullptr) { @@ -290,7 +289,7 @@ } } - void update (void) + void update () { clean (); @@ -341,7 +340,7 @@ //! the options given by @c java.opts. static std::string -initial_java_dir (void) +initial_java_dir () { static std::string java_dir; @@ -420,7 +419,7 @@ //! @returns The initial classpath. static std::string -initial_class_path (void) +initial_class_path () { std::string java_dir = initial_java_dir (); @@ -668,7 +667,7 @@ //! @see #terminate_jvm() static void -initialize_jvm (void) +initialize_jvm () { // Most of the time JVM already exists and has been initialized. // Also it seems, as if jvm is set, the jvm is already attached. @@ -830,7 +829,7 @@ //! @see #initialize_jvm() static void -terminate_jvm (void) +terminate_jvm () { // There is nothing to do if jvm is not set (= nullptr). if (jvm) @@ -894,7 +893,7 @@ //! @returns A reference to jni, if #jvm is present, otherwise @c nullptr. static inline JNIEnv * -thread_jni_env (void) +thread_jni_env () { JNIEnv *env = nullptr; @@ -907,7 +906,7 @@ #endif bool -octave_java::is_java_string (void) const +octave_java::is_java_string () const { #if defined (HAVE_JAVA) @@ -1979,7 +1978,7 @@ //! @returns 0 in any case for good reason. static int -java_event_hook (void) +java_event_hook () { JNIEnv *current_env = thread_jni_env (); @@ -2006,7 +2005,7 @@ //! @c __java_get__, @c __java_set__, and @c __java2mat__. static void -initialize_java (void) +initialize_java () { if (! jvm) { @@ -2038,12 +2037,14 @@ int nargout = env->GetArrayLength (argout); int nargin = env->GetArrayLength (argin); - octave_value_list varargin, varargout; + octave_value_list varargin; for (int i = 0; i < nargin; i++) varargin(i) = box (env, env->GetObjectArrayElement (argin, i), nullptr); - varargout = octave::feval (fname, varargin, nargout); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave_value_list varargout = interp.feval (fname, varargin, nargout); jobjectArray_ref out_objs (env, argout), out_clss (env); out_objs.detach (); @@ -2074,10 +2075,12 @@ oct_args(i) = box (env, jobj, nullptr); } + octave::interpreter& interp = octave::__get_interpreter__ (); + if (val.is_function_handle ()) { octave_function *fcn = val.function_value (); - octave::feval (fcn, oct_args); + interp.feval (fcn, oct_args); } else if (val.iscell () && val.length () > 0 && (val.rows () == 1 || val.columns () == 1) @@ -2089,7 +2092,7 @@ for (int i=1; i"; } + static int static_type_id () { return t_id; } + static std::string static_type_name () { return t_name; } + static std::string static_class_name () { return ""; } static void register_type (octave::type_info&); private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-lazy-idx.cc --- a/libinterp/octave-value/ov-lazy-idx.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-lazy-idx.cc Mon Jan 30 18:36:03 2023 +0100 @@ -44,14 +44,14 @@ } octave_base_value::type_conv_info -octave_lazy_index::numeric_conversion_function (void) const +octave_lazy_index::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_matrix::static_type_id ()); } octave_base_value * -octave_lazy_index::try_narrowing_conversion (void) +octave_lazy_index::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -97,7 +97,7 @@ } octave_value -octave_lazy_index::squeeze (void) const +octave_lazy_index::squeeze () const { return octave::idx_vector (m_index.as_array ().squeeze (), m_index.extent (0)); @@ -161,61 +161,61 @@ } octave_value -octave_lazy_index::as_double (void) const +octave_lazy_index::as_double () const { return array_value (); } octave_value -octave_lazy_index::as_single (void) const +octave_lazy_index::as_single () const { return float_array_value (); } octave_value -octave_lazy_index::as_int8 (void) const +octave_lazy_index::as_int8 () const { return int8_array_value (); } octave_value -octave_lazy_index::as_int16 (void) const +octave_lazy_index::as_int16 () const { return int16_array_value (); } octave_value -octave_lazy_index::as_int32 (void) const +octave_lazy_index::as_int32 () const { return int32_array_value (); } octave_value -octave_lazy_index::as_int64 (void) const +octave_lazy_index::as_int64 () const { return int64_array_value (); } octave_value -octave_lazy_index::as_uint8 (void) const +octave_lazy_index::as_uint8 () const { return uint8_array_value (); } octave_value -octave_lazy_index::as_uint16 (void) const +octave_lazy_index::as_uint16 () const { return uint16_array_value (); } octave_value -octave_lazy_index::as_uint32 (void) const +octave_lazy_index::as_uint32 () const { return uint32_array_value (); } octave_value -octave_lazy_index::as_uint64 (void) const +octave_lazy_index::as_uint64 () const { return uint64_array_value (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-lazy-idx.h --- a/libinterp/octave-value/ov-lazy-idx.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-lazy-idx.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ { public: - octave_lazy_index (void) + octave_lazy_index () : octave_base_value (), m_index (), m_value () { } octave_lazy_index (const octave::idx_vector& idx) @@ -48,37 +48,37 @@ octave_lazy_index (const octave_lazy_index& i) : octave_base_value (), m_index (i.m_index), m_value (i.m_value) { } - ~octave_lazy_index (void) = default; + ~octave_lazy_index () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_lazy_index (*this); } - octave_base_value * empty_clone (void) const { return new octave_matrix (); } + octave_base_value * empty_clone () const { return new octave_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); octave_value fast_elem_extract (octave_idx_type n) const; - std::size_t byte_size (void) const + std::size_t byte_size () const { return numel () * sizeof (octave_idx_type); } - octave_value squeeze (void) const; + octave_value squeeze () const; - octave_value full_value (void) const { return make_value (); } + octave_value full_value () const { return make_value (); } octave::idx_vector index_vector (bool /* require_integers */ = false) const { return m_index; } - builtin_type_t builtin_type (void) const { return btyp_double; } + builtin_type_t builtin_type () const { return btyp_double; } - bool is_real_matrix (void) const { return true; } + bool is_real_matrix () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } // We don't need to override all three forms of subsref. The using // declaration will avoid warnings about partially-overloaded virtual @@ -97,11 +97,11 @@ bool resize_ok = false) { return make_value ().index_op (idx, resize_ok); } - dim_vector dims (void) const { return m_index.orig_dimensions (); } + dim_vector dims () const { return m_index.orig_dimensions (); } - octave_idx_type numel (void) const { return m_index.length (0); } + octave_idx_type numel () const { return m_index.length (0); } - octave_idx_type nnz (void) const { return numel (); } + octave_idx_type nnz () const { return numel (); } octave_value reshape (const dim_vector& new_dims) const; @@ -113,7 +113,7 @@ octave_value all (int dim = 0) const { return make_value ().all (dim); } octave_value any (int dim = 0) const { return make_value ().any (dim); } - MatrixType matrix_type (void) const { return make_value ().matrix_type (); } + MatrixType matrix_type () const { return make_value ().matrix_type (); } MatrixType matrix_type (const MatrixType& _typ) const { return make_value ().matrix_type (_typ); } @@ -128,18 +128,18 @@ sortmode is_sorted_rows (sortmode mode = UNSORTED) const; - bool is_matrix_type (void) const { return true; } + bool is_matrix_type () const { return true; } - bool isnumeric (void) const { return true; } + bool isnumeric () const { return true; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool is_true (void) const + bool is_true () const { return make_value ().is_true (); } - bool print_as_scalar (void) const + bool print_as_scalar () const { return make_value ().print_as_scalar (); } void print (std::ostream& os, bool pr_as_read_syntax = false) @@ -149,7 +149,7 @@ { make_value ().print_info (os, prefix); } #define FORWARD_VALUE_QUERY(TYPE, NAME) \ - TYPE NAME (void) const \ + TYPE NAME () const \ { \ return make_value ().NAME (); \ } @@ -202,18 +202,18 @@ return make_value ().convert_to_str_internal (pad, force, type); } - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const { @@ -238,7 +238,7 @@ // This function exists to support the MEX interface. // You should not use it anywhere else. - const void * mex_get_data (void) const + const void * mex_get_data () const { return make_value ().mex_get_data (); } @@ -255,7 +255,7 @@ private: - const octave_value& make_value (void) const + const octave_value& make_value () const { if (m_value.is_undefined ()) m_value = octave_value (m_index, false); @@ -263,7 +263,7 @@ return m_value; } - octave_value& make_value (void) + octave_value& make_value () { if (m_value.is_undefined ()) m_value = octave_value (m_index, false); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-legacy-range.cc --- a/libinterp/octave-value/ov-legacy-range.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-legacy-range.cc Mon Jan 30 18:36:03 2023 +0100 @@ -31,6 +31,7 @@ #include #include +#include "Range.h" #include "lo-ieee.h" #include "lo-utils.h" @@ -49,23 +50,326 @@ #include "ls-hdf5.h" #include "ls-utils.h" -#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif +class +Range +{ +public: + + Range () + : m_base (0), m_limit (0), m_inc (0), m_numel (0) + { } + + // Assume range is already properly constructed, so just copy internal + // values. However, we set LIMIT to the computed final value because + // that mimics the behavior of the other Range class constructors that + // reset limit to the computed final value. + + Range (const octave::range& r) + : m_base (r.base ()), m_limit (r.final_value ()), m_inc (r.increment ()), + m_numel (r.numel ()) + { } + + Range (const Range& r) = default; + + Range& operator = (const Range& r) = default; + + ~Range () = default; + + Range (double b, double l) + : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ()) + { + if (! octave::math::isinf (m_limit)) + m_limit = limit_internal (); + } + + Range (double b, double l, double i) + : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ()) + { + if (! octave::math::isinf (m_limit)) + m_limit = limit_internal (); + } + + // The range has a finite number of elements. + bool ok () const + { + return (octave::math::isfinite (m_limit) + && (m_numel >= 0 || m_numel == -2)); + } + + double base () const { return m_base; } + double limit () const { return m_limit; } + double increment () const { return m_inc; } + + octave_idx_type numel () const { return m_numel; } + + bool all_elements_are_ints () const; + + Matrix matrix_value () const; + + double min () const; + double max () const; + +private: + + double m_base; + double m_limit; + double m_inc; + + octave_idx_type m_numel; + + octave_idx_type numel_internal () const; + + double limit_internal () const; + + void init (); +}; + +bool +Range::all_elements_are_ints () const +{ + // If the base and increment are ints, the final value in the range will also + // be an integer, even if the limit is not. If there is one or fewer + // elements only the base needs to be an integer. + + return (! (octave::math::isnan (m_base) || octave::math::isnan (m_inc)) + && (octave::math::nint_big (m_base) == m_base || m_numel < 1) + && (octave::math::nint_big (m_inc) == m_inc || m_numel <= 1)); +} + +Matrix +Range::matrix_value () const +{ + Matrix retval (1, m_numel); + + if (m_numel > 0) + { + // The first element must always be *exactly* the base. + // E.g, -0 would otherwise become +0 in the loop (-0 + 0*increment). + retval(0) = m_base; + + double b = m_base; + double increment = m_inc; + for (octave_idx_type i = 1; i < m_numel - 1; i++) + retval.xelem (i) = b + i * increment; + + retval.xelem (m_numel - 1) = m_limit; + } + + return retval; +} + +// NOTE: max and min only return useful values if numel > 0. +// do_minmax_body() in max.cc avoids calling Range::min/max if numel == 0. + +double +Range::min () const +{ + double retval = 0.0; + if (m_numel > 0) + { + if (m_inc > 0) + retval = m_base; + else + { + retval = m_base + (m_numel - 1) * m_inc; + + // Require '<=' test. See note in max (). + if (retval <= m_limit) + retval = m_limit; + } + + } + return retval; +} + +double +Range::max () const +{ + double retval = 0.0; + if (m_numel > 0) + { + if (m_inc > 0) + { + retval = m_base + (m_numel - 1) * m_inc; + + // On some machines (x86 with extended precision floating point + // arithmetic, for example) it is possible that we can overshoot the + // limit by approximately the machine precision even though we were + // very careful in our calculation of the number of elements. + // Therefore, we clip the result to the limit if it overshoots. + // The test also includes equality (>= m_limit) to have expressions + // such as -5:1:-0 result in a -0 endpoint. + if (retval >= m_limit) + retval = m_limit; + } + else + retval = m_base; + } + return retval; +} + +// C See Knuth, Art Of Computer Programming, Vol. 1, Problem 1.2.4-5. +// C +// C===Tolerant FLOOR function. +// C +// C X - is given as a Double Precision argument to be operated on. +// C It is assumed that X is represented with M mantissa bits. +// C CT - is given as a Comparison Tolerance such that +// C 0.LT.CT.LE.3-SQRT(5)/2. If the relative difference between +// C X and A whole number is less than CT, then TFLOOR is +// C returned as this whole number. By treating the +// C floating-point numbers as a finite ordered set note that +// C the heuristic EPS=2.**(-(M-1)) and CT=3*EPS causes +// C arguments of TFLOOR/TCEIL to be treated as whole numbers +// C if they are exactly whole numbers or are immediately +// C adjacent to whole number representations. Since EPS, the +// C "distance" between floating-point numbers on the unit +// C interval, and M, the number of bits in X'S mantissa, exist +// C on every floating-point computer, TFLOOR/TCEIL are +// C consistently definable on every floating-point computer. +// C +// C For more information see the following references: +// C (1) P. E. Hagerty, "More On Fuzzy Floor And Ceiling," APL QUOTE +// C QUAD 8(4):20-24, June 1978. Note that TFLOOR=FL5. +// C (2) L. M. Breed, "Definitions For Fuzzy Floor And Ceiling", APL +// C QUOTE QUAD 8(3):16-23, March 1978. This paper cites FL1 through +// C FL5, the history of five years of evolutionary development of +// C FL5 - the seven lines of code below - by open collaboration +// C and corroboration of the mathematical-computing community. +// C +// C Penn State University Center for Academic Computing +// C H. D. Knoble - August, 1978. + +static inline double +tfloor (double x, double ct) +{ +// C---------FLOOR(X) is the largest integer algebraically less than +// C or equal to X; that is, the unfuzzy FLOOR function. + +// DINT (X) = X - DMOD (X, 1.0); +// FLOOR (X) = DINT (X) - DMOD (2.0 + DSIGN (1.0, X), 3.0); + +// C---------Hagerty's FL5 function follows... + + double q = 1.0; + + if (x < 0.0) + q = 1.0 - ct; + + double rmax = q / (2.0 - ct); + + double t1 = 1.0 + std::floor (x); + t1 = (ct / q) * (t1 < 0.0 ? -t1 : t1); + t1 = (rmax < t1 ? rmax : t1); + t1 = (ct > t1 ? ct : t1); + t1 = std::floor (x + t1); + + if (x <= 0.0 || (t1 - x) < rmax) + return t1; + else + return t1 - 1.0; +} + +static inline bool +teq (double u, double v, + double ct = 3.0 * std::numeric_limits::epsilon ()) +{ + double tu = std::abs (u); + double tv = std::abs (v); + + return std::abs (u - v) < ((tu > tv ? tu : tv) * ct); +} + +octave_idx_type +Range::numel_internal () const +{ + octave_idx_type retval = -1; + + if (! octave::math::isfinite (m_base) || ! octave::math::isfinite (m_inc) + || octave::math::isnan (m_limit)) + retval = -2; + else if (octave::math::isinf (m_limit) + && ((m_inc > 0 && m_limit > 0) + || (m_inc < 0 && m_limit < 0))) + retval = std::numeric_limits::max () - 1; + else if (m_inc == 0 + || (m_limit > m_base && m_inc < 0) + || (m_limit < m_base && m_inc > 0)) + { + retval = 0; + } + else + { + double ct = 3.0 * std::numeric_limits::epsilon (); + + double tmp = tfloor ((m_limit - m_base + m_inc) / m_inc, ct); + + octave_idx_type n_elt = (tmp > 0.0 + ? static_cast (tmp) : 0); + + // If the final element that we would compute for the range is equal to + // the limit of the range, or is an adjacent floating point number, + // accept it. Otherwise, try a range with one fewer element. If that + // fails, try again with one more element. + // + // I'm not sure this is very good, but it seems to work better than just + // using tfloor as above. For example, without it, the expression + // 1.8:0.05:1.9 fails to produce the expected result of [1.8, 1.85, 1.9]. + + if (! teq (m_base + (n_elt - 1) * m_inc, m_limit)) + { + if (teq (m_base + (n_elt - 2) * m_inc, m_limit)) + n_elt--; + else if (teq (m_base + n_elt * m_inc, m_limit)) + n_elt++; + } + + retval = ((n_elt < std::numeric_limits::max ()) + ? n_elt : -1); + } + + return retval; +} + +double +Range::limit_internal () const +{ + double new_limit = m_inc > 0 ? max () : min (); + + // If result must be an integer then force the new_limit to be one. + if (all_elements_are_ints ()) + new_limit = std::round (new_limit); + + return new_limit; +} + +void +Range::init () +{ + m_numel = numel_internal (); + + if (! octave::math::isinf (m_limit)) + m_limit = limit_internal (); +} DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_legacy_range, "range", "double"); -octave_legacy_range::octave_legacy_range (void) - : octave_base_value (), range () { } +octave_legacy_range::octave_legacy_range () + : octave_base_value (), m_range (new Range ()) { } octave_legacy_range::octave_legacy_range (const Range& r) - : octave_base_value (), range (r) + : octave_base_value (), m_range (new Range (r)) { - if (range.numel () < 0 && range.numel () != -2) + if (m_range->numel () < 0 && m_range->numel () != -2) error ("invalid range"); } +octave_legacy_range::octave_legacy_range (const octave_legacy_range& r) + : octave_base_value (r), m_range () +{ + m_range.reset (new Range (*(r.m_range))); +} + static octave_base_value * default_numeric_conversion_function (const octave_base_value& a) { @@ -75,21 +379,21 @@ } octave_base_value::type_conv_info -octave_legacy_range::numeric_conversion_function (void) const +octave_legacy_range::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, - octave_matrix::static_type_id ()); + octave_matrix::static_type_id ()); } octave_base_value * -octave_legacy_range::try_narrowing_conversion (void) +octave_legacy_range::try_narrowing_conversion () { octave_base_value *retval = nullptr; - switch (range.numel ()) + switch (m_range->numel ()) { case 1: - retval = new octave_scalar (range.base ()); + retval = new octave_scalar (m_range->base ()); break; case 0: @@ -97,17 +401,17 @@ break; case -2: - retval = new octave_matrix (range.matrix_value ()); + retval = new octave_matrix (m_range->matrix_value ()); break; default: { - if (range.increment () == 0) - retval = new octave_matrix (range.matrix_value ()); + if (m_range->increment () == 0) + retval = new octave_matrix (m_range->matrix_value ()); else retval = new octave_range - (octave::range (range.base (), range.increment (), - range.limit (), range.numel ())); + (octave::range (m_range->base (), m_range->increment (), + m_range->limit (), m_range->numel ())); } break; } @@ -145,9 +449,9 @@ error ("load: failed to load range constant"); if (inc != 0) - range = Range (base, limit, inc); + m_range.reset (new Range (base, limit, inc)); else - range = Range (base, inc, static_cast (limit)); + m_range.reset (new Range (base, inc, static_cast (limit))); return true; } @@ -173,9 +477,9 @@ if (swap) swap_bytes<8> (&inc); if (inc != 0) - range = Range (bas, lim, inc); + m_range.reset (new Range (bas, lim, inc)); else - range = Range (bas, inc, static_cast (lim)); + m_range.reset (new Range (bas, inc, static_cast (lim))); return true; } @@ -245,14 +549,14 @@ octave_idx_type nel; if (hdf5_get_scalar_attr (data_hid, H5T_NATIVE_IDX, "OCTAVE_RANGE_NELEM", &nel)) - range = Range (rangevals[0], rangevals[2], nel); + m_range.reset (new Range (rangevals[0], rangevals[2], nel)); else { if (rangevals[2] != 0) - range = Range (rangevals[0], rangevals[1], rangevals[2]); + m_range.reset (new Range (rangevals[0], rangevals[1], rangevals[2])); else - range = Range (rangevals[0], rangevals[2], - static_cast (rangevals[1])); + m_range.reset (new Range (rangevals[0], rangevals[2], + static_cast (rangevals[1]))); } } @@ -269,7 +573,3 @@ return retval; } - -#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) -# pragma GCC diagnostic pop -#endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-legacy-range.h --- a/libinterp/octave-value/ov-legacy-range.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-legacy-range.h Mon Jan 30 18:36:03 2023 +0100 @@ -31,10 +31,9 @@ #include #include +#include #include -#include "Range.h" - #include "lo-mappers.h" #include "lo-utils.h" #include "mx-base.h" @@ -45,6 +44,8 @@ #include "ov-re-mat.h" #include "ov-typeinfo.h" +class Range; + class octave_value_list; // Legacy Range values. @@ -61,19 +62,19 @@ { public: - octave_legacy_range (void); + octave_legacy_range (); octave_legacy_range (const Range& r); - octave_legacy_range (const octave_legacy_range& r) = default; + octave_legacy_range (const octave_legacy_range& r); // No assignment. octave_legacy_range& operator = (const octave_legacy_range&) = delete; - ~octave_legacy_range (void) { } + ~octave_legacy_range () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_legacy_range (*this); } @@ -81,17 +82,17 @@ // A range is really just a special kind of real matrix object. In // the places where we need to call empty_clone, it makes more sense // to create an empty matrix (0x0) instead of an empty range (1x0). - octave_base_value * empty_clone (void) const { return new octave_matrix (); } + octave_base_value * empty_clone () const { return new octave_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_legacy_object (void) const { return true; } + bool is_legacy_object () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } bool load_ascii (std::istream& is); @@ -102,7 +103,7 @@ private: - Range range; + std::unique_ptr m_range; DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-magic-int.cc --- a/libinterp/octave-value/ov-magic-int.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-magic-int.cc Mon Jan 30 18:36:03 2023 +0100 @@ -104,70 +104,70 @@ template octave_value -octave_base_magic_int::as_double (void) const +octave_base_magic_int::as_double () const { return static_cast (scalar_ref ()); } template octave_value -octave_base_magic_int::as_single (void) const +octave_base_magic_int::as_single () const { return static_cast (scalar_ref ()); } template octave_value -octave_base_magic_int::as_int8 (void) const +octave_base_magic_int::as_int8 () const { return octave_int8 (scalar_ref ()); } template octave_value -octave_base_magic_int::as_int16 (void) const +octave_base_magic_int::as_int16 () const { return octave_int16 (scalar_ref ()); } template octave_value -octave_base_magic_int::as_int32 (void) const +octave_base_magic_int::as_int32 () const { return octave_int32 (scalar_ref ()); } template octave_value -octave_base_magic_int::as_int64 (void) const +octave_base_magic_int::as_int64 () const { return octave_int64 (scalar_ref ()); } template octave_value -octave_base_magic_int::as_uint8 (void) const +octave_base_magic_int::as_uint8 () const { return octave_uint8 (scalar_ref ()); } template octave_value -octave_base_magic_int::as_uint16 (void) const +octave_base_magic_int::as_uint16 () const { return octave_uint16 (scalar_ref ()); } template octave_value -octave_base_magic_int::as_uint32 (void) const +octave_base_magic_int::as_uint32 () const { return octave_uint32 (scalar_ref ()); } template octave_value -octave_base_magic_int::as_uint64 (void) const +octave_base_magic_int::as_uint64 () const { return octave_uint64 (scalar_ref ()); } @@ -306,7 +306,7 @@ "double"); octave_base_value::type_conv_info -octave_magic_uint::numeric_conversion_function (void) const +octave_magic_uint::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conv_fcn, octave_scalar::static_type_id ()); @@ -316,7 +316,7 @@ "double"); octave_base_value::type_conv_info -octave_magic_int::numeric_conversion_function (void) const +octave_magic_int::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conv_fcn, octave_scalar::static_type_id ()); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-magic-int.h --- a/libinterp/octave-value/ov-magic-int.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-magic-int.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,26 +52,26 @@ { public: - octave_base_magic_int (void) + octave_base_magic_int () : octave_base_scalar (0) { } octave_base_magic_int (const T& val) : octave_base_scalar (val) { } - ~octave_base_magic_int (void) = default; + ~octave_base_magic_int () = default; // We return an octave_matrix here instead of an octave_scalar so // that in expressions like A(2,2,2) = 2 (for A previously // undefined), A will be empty instead of a 1x1 object. - octave_base_value * empty_clone (void) const { return new octave_matrix (); } + octave_base_value * empty_clone () const { return new octave_matrix (); } // Although SCALAR is a protected member of the base class, it is not // directly visible here without the explicit octave_base_slalar:: // qualification. Why not? - const T& scalar_ref (void) const { return octave_base_scalar::scalar; } + const T& scalar_ref () const { return octave_base_scalar::scalar; } - T& scalar_ref (void) { return octave_base_scalar::scalar; } + T& scalar_ref () { return octave_base_scalar::scalar; } octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); @@ -80,66 +80,66 @@ octave_value any (int = 0) const { return scalar_ref () != T (0); } - builtin_type_t builtin_type (void) const { return btyp_double; } + builtin_type_t builtin_type () const { return btyp_double; } - bool is_storable (void) const { return false; } + bool is_storable () const { return false; } - bool is_magic_int (void) const { return true; } + bool is_magic_int () const { return true; } - bool is_real_scalar (void) const { return true; } + bool is_real_scalar () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } - int8NDArray int8_array_value (void) const + int8NDArray int8_array_value () const { return int8NDArray (dim_vector (1, 1), double_value ()); } - int16NDArray int16_array_value (void) const + int16NDArray int16_array_value () const { return int16NDArray (dim_vector (1, 1), double_value ()); } - int32NDArray int32_array_value (void) const + int32NDArray int32_array_value () const { return int32NDArray (dim_vector (1, 1), double_value ()); } - int64NDArray int64_array_value (void) const + int64NDArray int64_array_value () const { return int64NDArray (dim_vector (1, 1), double_value ()); } - uint8NDArray uint8_array_value (void) const + uint8NDArray uint8_array_value () const { return uint8NDArray (dim_vector (1, 1), double_value ()); } - uint16NDArray uint16_array_value (void) const + uint16NDArray uint16_array_value () const { return uint16NDArray (dim_vector (1, 1), double_value ()); } - uint32NDArray uint32_array_value (void) const + uint32NDArray uint32_array_value () const { return uint32NDArray (dim_vector (1, 1), double_value ()); } - uint64NDArray uint64_array_value (void) const + uint64NDArray uint64_array_value () const { return uint64NDArray (dim_vector (1, 1), double_value ()); } - octave_int8 int8_scalar_value (void) const + octave_int8 int8_scalar_value () const { return octave_int8 (double_value ()); } - octave_int16 int16_scalar_value (void) const + octave_int16 int16_scalar_value () const { return octave_int16 (double_value ()); } - octave_int32 int32_scalar_value (void) const + octave_int32 int32_scalar_value () const { return octave_int32 (double_value ()); } - octave_int64 int64_scalar_value (void) const + octave_int64 int64_scalar_value () const { return octave_int64 (double_value ()); } - octave_uint8 uint8_scalar_value (void) const + octave_uint8 uint8_scalar_value () const { return octave_uint8 (double_value ()); } - octave_uint16 uint16_scalar_value (void) const + octave_uint16 uint16_scalar_value () const { return octave_uint16 (double_value ()); } - octave_uint32 uint32_scalar_value (void) const + octave_uint32 uint32_scalar_value () const { return octave_uint32 (double_value ()); } - octave_uint64 uint64_scalar_value (void) const + octave_uint64 uint64_scalar_value () const { return octave_uint64 (double_value ()); } double double_value (bool = false) const @@ -221,18 +221,18 @@ return boolNDArray (dim_vector (1, 1), double_value ()); } - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; // We don't need to override both forms of the diag method. The using // declaration will avoid warnings about partially-overloaded virtual @@ -243,9 +243,9 @@ octave_value convert_to_str_internal (bool pad, bool force, char type) const; - void increment (void) { scalar_ref () += T (1); } + void increment () { scalar_ref () += T (1); } - void decrement (void) { scalar_ref () -= T (1); } + void decrement () { scalar_ref () -= T (1); } bool save_ascii (std::ostream& os); @@ -279,20 +279,20 @@ { public: - octave_magic_uint (void) + octave_magic_uint () : octave_base_magic_int (0) { } octave_magic_uint (const octave_uint64& val) : octave_base_magic_int (val) { } - ~octave_magic_uint (void) = default; + ~octave_magic_uint () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_magic_uint (*this); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; private: @@ -305,20 +305,20 @@ { public: - octave_magic_int (void) + octave_magic_int () : octave_base_magic_int (0) { } octave_magic_int (const octave_int64& val) : octave_base_magic_int (val) { } - ~octave_magic_int (void) = default; + ~octave_magic_int () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_magic_int (*this); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-mex-fcn.cc --- a/libinterp/octave-value/ov-mex-fcn.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-mex-fcn.cc Mon Jan 30 18:36:03 2023 +0100 @@ -68,7 +68,7 @@ && oct_file_dir == file_name.substr (0, oct_file_dir.length ())); } -octave_mex_function::~octave_mex_function (void) +octave_mex_function::~octave_mex_function () { if (m_exit_fcn_ptr) (*m_exit_fcn_ptr) (); @@ -79,13 +79,13 @@ } std::string -octave_mex_function::fcn_file_name (void) const +octave_mex_function::fcn_file_name () const { return m_sh_lib.file_name (); } octave::sys::time -octave_mex_function::time_parsed (void) const +octave_mex_function::time_parsed () const { return m_sh_lib.time_loaded (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-mex-fcn.h --- a/libinterp/octave-value/ov-mex-fcn.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-mex-fcn.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ { public: - octave_mex_function (void) + octave_mex_function () : m_mex_fcn_ptr (nullptr), m_exit_fcn_ptr (nullptr), m_sh_lib (), m_time_checked (), m_interleaved (false), m_is_fmex (false), m_is_system_fcn_file (false) @@ -68,7 +68,7 @@ octave_mex_function& operator = (const octave_mex_function& fcn) = delete; - ~octave_mex_function (void); + ~octave_mex_function (); octave_function * function_value (bool = false) { return this; } @@ -79,37 +79,37 @@ m_time_checked = t; } - std::string fcn_file_name (void) const; + std::string fcn_file_name () const; - octave::sys::time time_parsed (void) const; + octave::sys::time time_parsed () const; - octave::sys::time time_checked (void) const { return m_time_checked; } + octave::sys::time time_checked () const { return m_time_checked; } - bool is_system_fcn_file (void) const { return m_is_system_fcn_file; } + bool is_system_fcn_file () const { return m_is_system_fcn_file; } - bool is_builtin_function (void) const { return false; } + bool is_builtin_function () const { return false; } - bool is_mex_function (void) const { return true; } + bool is_mex_function () const { return true; } - bool use_interleaved_complex (void) const { return m_interleaved; } + bool use_interleaved_complex () const { return m_interleaved; } octave_value_list execute (octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list ()); - void atexit (void (*fcn) (void)) { m_exit_fcn_ptr = fcn; } + void atexit (void (*fcn) ()) { m_exit_fcn_ptr = fcn; } - octave::dynamic_library get_shlib (void) const { return m_sh_lib; } + octave::dynamic_library get_shlib () const { return m_sh_lib; } - void * mex_fcn_ptr (void) const { return m_mex_fcn_ptr; } + void * mex_fcn_ptr () const { return m_mex_fcn_ptr; } - bool is_fmex (void) const { return m_is_fmex; } + bool is_fmex () const { return m_is_fmex; } private: void *m_mex_fcn_ptr; - void (*m_exit_fcn_ptr) (void); + void (*m_exit_fcn_ptr) (); octave::dynamic_library m_sh_lib; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-null-mat.cc --- a/libinterp/octave-value/ov-null-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-null-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -46,7 +46,7 @@ } octave_base_value::type_conv_info -octave_null_matrix::numeric_conversion_function (void) const +octave_null_matrix::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_null_matrix_numeric_conversion_function, @@ -67,7 +67,7 @@ } octave_base_value::type_conv_info -octave_null_str::numeric_conversion_function (void) const +octave_null_str::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_null_str_numeric_conversion_function, @@ -89,7 +89,7 @@ } octave_base_value::type_conv_info -octave_null_sq_str::numeric_conversion_function (void) const +octave_null_sq_str::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_null_sq_str_numeric_conversion_function, diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-null-mat.h --- a/libinterp/octave-value/ov-null-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-null-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,15 +45,15 @@ OCTINTERP_API octave_null_matrix : public octave_matrix { - octave_null_matrix (void) : octave_matrix () { } + octave_null_matrix () : octave_matrix () { } public: static const octave_value instance; - bool isnull (void) const { return true; } + bool isnull () const { return true; } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; private: @@ -66,17 +66,17 @@ OCTINTERP_API octave_null_str : public octave_char_matrix_str { - octave_null_str (void) : octave_char_matrix_str () { } + octave_null_str () : octave_char_matrix_str () { } public: static const octave_value instance; - bool is_storable (void) const { return false; } + bool is_storable () const { return false; } - bool isnull (void) const { return true; } + bool isnull () const { return true; } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; private: @@ -89,17 +89,17 @@ OCTINTERP_API octave_null_sq_str : public octave_char_matrix_sq_str { - octave_null_sq_str (void) : octave_char_matrix_sq_str () { } + octave_null_sq_str () : octave_char_matrix_sq_str () { } public: static const octave_value instance; - bool is_storable (void) const { return false; } + bool is_storable () const { return false; } - bool isnull (void) const { return true; } + bool isnull () const { return true; } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-oncleanup.cc --- a/libinterp/octave-value/ov-oncleanup.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-oncleanup.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,7 +33,6 @@ #include "ov-oncleanup.h" #include "ov-fcn.h" #include "ov-usr-fcn.h" -#include "parse.h" #include "pt-misc.h" DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_oncleanup, "onCleanup", @@ -66,13 +65,13 @@ } } -octave_oncleanup::~octave_oncleanup (void) +octave_oncleanup::~octave_oncleanup () { call_object_destructor (); } octave_scalar_map -octave_oncleanup::scalar_map_value (void) const +octave_oncleanup::scalar_map_value () const { octave_scalar_map retval; retval.setfield ("task", m_fcn); @@ -146,7 +145,7 @@ } void -octave_oncleanup::call_object_destructor (void) +octave_oncleanup::call_object_destructor () { if (m_fcn.is_undefined ()) return; @@ -171,7 +170,7 @@ try { // Run the actual code. - octave::feval (the_fcn); + interp.feval (the_fcn); } catch (const octave::interrupt_exception&) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-oncleanup.h --- a/libinterp/octave-value/ov-oncleanup.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-oncleanup.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,11 +39,11 @@ { public: - octave_oncleanup (void) = default; + octave_oncleanup () = default; octave_oncleanup (const octave_value& m_fcn); - octave_base_value * clone (void) const + octave_base_value * clone () const { if (m_fcn.is_defined ()) error ("onCleanup: internal error: cloning nonempty object"); @@ -51,22 +51,22 @@ return empty_clone (); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_oncleanup (); } - ~octave_oncleanup (void); + ~octave_oncleanup (); - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool isobject (void) const { return true; } // do we want this? + bool isobject () const { return true; } // do we want this? - octave_map map_value (void) const { return scalar_map_value (); } + octave_map map_value () const { return scalar_map_value (); } - octave_scalar_map scalar_map_value (void) const; + octave_scalar_map scalar_map_value () const; - dim_vector dims (void) const + dim_vector dims () const { static dim_vector dv (1, 1); return dv; @@ -89,7 +89,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - void call_object_destructor (void); + void call_object_destructor (); private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-perm.cc --- a/libinterp/octave-value/ov-perm.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-perm.cc Mon Jan 30 18:36:03 2023 +0100 @@ -137,7 +137,7 @@ // Return true if this matrix has all true elements (non-zero, not NaN/NA). // A permutation cannot have NaN/NA. bool -octave_perm_matrix::is_true (void) const +octave_perm_matrix::is_true () const { if (dims ().numel () > 1) { @@ -254,67 +254,67 @@ } octave_value -octave_perm_matrix::as_double (void) const +octave_perm_matrix::as_double () const { return m_matrix; } octave_value -octave_perm_matrix::as_single (void) const +octave_perm_matrix::as_single () const { return float_array_value (); } octave_value -octave_perm_matrix::as_int8 (void) const +octave_perm_matrix::as_int8 () const { return int8_array_value (); } octave_value -octave_perm_matrix::as_int16 (void) const +octave_perm_matrix::as_int16 () const { return int16_array_value (); } octave_value -octave_perm_matrix::as_int32 (void) const +octave_perm_matrix::as_int32 () const { return int32_array_value (); } octave_value -octave_perm_matrix::as_int64 (void) const +octave_perm_matrix::as_int64 () const { return int64_array_value (); } octave_value -octave_perm_matrix::as_uint8 (void) const +octave_perm_matrix::as_uint8 () const { return uint8_array_value (); } octave_value -octave_perm_matrix::as_uint16 (void) const +octave_perm_matrix::as_uint16 () const { return uint16_array_value (); } octave_value -octave_perm_matrix::as_uint32 (void) const +octave_perm_matrix::as_uint32 () const { return uint32_array_value (); } octave_value -octave_perm_matrix::as_uint64 (void) const +octave_perm_matrix::as_uint64 () const { return uint64_array_value (); } float_display_format -octave_perm_matrix::get_edit_display_format (void) const +octave_perm_matrix::get_edit_display_format () const { return float_display_format (float_format (1, 0, 0)); } @@ -440,7 +440,7 @@ } bool -octave_perm_matrix::print_as_scalar (void) const +octave_perm_matrix::print_as_scalar () const { dim_vector dv = dims (); @@ -470,7 +470,7 @@ } octave_value -octave_perm_matrix::to_dense (void) const +octave_perm_matrix::to_dense () const { if (! m_dense_cache.is_defined ()) m_dense_cache = Matrix (m_matrix); @@ -490,7 +490,7 @@ } octave_base_value::type_conv_info -octave_perm_matrix::numeric_conversion_function (void) const +octave_perm_matrix::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_matrix::static_type_id ()); @@ -552,7 +552,7 @@ } octave_base_value * -octave_perm_matrix::try_narrowing_conversion (void) +octave_perm_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-perm.h --- a/libinterp/octave-value/ov-perm.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-perm.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,24 +40,24 @@ octave_perm_matrix : public octave_base_value { public: - octave_perm_matrix (void) : m_matrix (), m_dense_cache () { } + octave_perm_matrix () : m_matrix (), m_dense_cache () { } octave_perm_matrix (const PermMatrix& p) : m_matrix (p), m_dense_cache () { } - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_perm_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_perm_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); - std::size_t byte_size (void) const { return m_matrix.byte_size (); } + std::size_t byte_size () const { return m_matrix.byte_size (); } - octave_value squeeze (void) const { return m_matrix; } + octave_value squeeze () const { return m_matrix; } - octave_value full_value (void) const { return to_dense (); } + octave_value full_value () const { return to_dense (); } // We don't need to override all three forms of subsref. The using // declaration will avoid warnings about partially-overloaded virtual @@ -74,9 +74,9 @@ octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); - dim_vector dims (void) const { return m_matrix.dims (); } + dim_vector dims () const { return m_matrix.dims (); } - octave_idx_type nnz (void) const { return m_matrix.rows (); } + octave_idx_type nnz () const { return m_matrix.rows (); } octave_value reshape (const dim_vector& new_dims) const { return to_dense ().reshape (new_dims); } @@ -90,7 +90,7 @@ octave_value all (int dim = 0) const { return to_dense ().all (dim); } octave_value any (int dim = 0) const { return to_dense ().any (dim); } - MatrixType matrix_type (void) const { return MatrixType::Permuted_Diagonal; } + MatrixType matrix_type () const { return MatrixType::Permuted_Diagonal; } MatrixType matrix_type (const MatrixType&) const { return matrix_type (); } @@ -117,27 +117,27 @@ sortmode is_sorted_rows (sortmode mode = UNSORTED) const { return to_dense ().is_sorted_rows (mode); } - builtin_type_t builtin_type (void) const { return btyp_double; } + builtin_type_t builtin_type () const { return btyp_double; } - bool is_perm_matrix (void) const { return true; } + bool is_perm_matrix () const { return true; } - bool is_matrix_type (void) const { return true; } + bool is_matrix_type () const { return true; } - bool isnumeric (void) const { return true; } + bool isnumeric () const { return true; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool is_real_matrix (void) const { return true; } + bool is_real_matrix () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } - bool is_true (void) const; + bool is_true () const; double double_value (bool = false) const; @@ -148,7 +148,7 @@ octave::idx_vector index_vector (bool require_integers = false) const; - PermMatrix perm_matrix_value (void) const + PermMatrix perm_matrix_value () const { return m_matrix; } Matrix matrix_value (bool = false) const; @@ -182,47 +182,47 @@ SparseComplexMatrix sparse_complex_matrix_value (bool = false) const; int8NDArray - int8_array_value (void) const { return to_dense ().int8_array_value (); } + int8_array_value () const { return to_dense ().int8_array_value (); } int16NDArray - int16_array_value (void) const { return to_dense ().int16_array_value (); } + int16_array_value () const { return to_dense ().int16_array_value (); } int32NDArray - int32_array_value (void) const { return to_dense ().int32_array_value (); } + int32_array_value () const { return to_dense ().int32_array_value (); } int64NDArray - int64_array_value (void) const { return to_dense ().int64_array_value (); } + int64_array_value () const { return to_dense ().int64_array_value (); } uint8NDArray - uint8_array_value (void) const { return to_dense ().uint8_array_value (); } + uint8_array_value () const { return to_dense ().uint8_array_value (); } uint16NDArray - uint16_array_value (void) const { return to_dense ().uint16_array_value (); } + uint16_array_value () const { return to_dense ().uint16_array_value (); } uint32NDArray - uint32_array_value (void) const { return to_dense ().uint32_array_value (); } + uint32_array_value () const { return to_dense ().uint32_array_value (); } uint64NDArray - uint64_array_value (void) const { return to_dense ().uint64_array_value (); } + uint64_array_value () const { return to_dense ().uint64_array_value (); } octave_value convert_to_str_internal (bool pad, bool force, char type) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - float_display_format get_edit_display_format (void) const; + float_display_format get_edit_display_format () const; std::string edit_display (const float_display_format& fmt, octave_idx_type i, octave_idx_type j) const; @@ -242,7 +242,7 @@ mxArray * as_mxArray (bool interleaved) const; - bool print_as_scalar (void) const; + bool print_as_scalar () const; void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -259,7 +259,7 @@ PermMatrix m_matrix; - virtual octave_value to_dense (void) const; + virtual octave_value to_dense () const; mutable octave_value m_dense_cache; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-range.cc --- a/libinterp/octave-value/ov-range.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-range.cc Mon Jan 30 18:36:03 2023 +0100 @@ -191,7 +191,7 @@ template octave_base_value::type_conv_info -ov_range::numeric_conversion_function (void) const +ov_range::numeric_conversion_function () const { typedef typename octave_value_range_traits::matrix_type ov_mx_type; @@ -201,7 +201,7 @@ template octave_base_value * -ov_range::try_narrowing_conversion (void) +ov_range::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -414,7 +414,7 @@ template octave::range -ov_range::range_value (void) const +ov_range::range_value () const { err_wrong_type_arg ("ov_range::range_value()", type_name ()); } @@ -425,63 +425,63 @@ template octave::range -ov_range::float_range_value (void) const +ov_range::float_range_value () const { err_wrong_type_arg ("ov_range::float_range_value ()", type_name ()); } template octave::range -ov_range::int8_range_value (void) const +ov_range::int8_range_value () const { err_wrong_type_arg ("ov_range::int8_range_value ()", type_name ()); } template octave::range -ov_range::int16_range_value (void) const +ov_range::int16_range_value () const { err_wrong_type_arg ("ov_range::int16_range_value ()", type_name ()); } template octave::range -ov_range::int32_range_value (void) const +ov_range::int32_range_value () const { err_wrong_type_arg ("ov_range::int32_range_value ()", type_name ()); } template octave::range -ov_range::int64_range_value (void) const +ov_range::int64_range_value () const { err_wrong_type_arg ("ov_range::int64_range_value ()", type_name ()); } template octave::range -ov_range::uint8_range_value (void) const +ov_range::uint8_range_value () const { err_wrong_type_arg ("ov_range::uint8_range_value ()", type_name ()); } template octave::range -ov_range::uint16_range_value (void) const +ov_range::uint16_range_value () const { err_wrong_type_arg ("ov_range::uint16_range_value ()", type_name ()); } template octave::range -ov_range::uint32_range_value (void) const +ov_range::uint32_range_value () const { err_wrong_type_arg ("ov_range::uint32_range_value ()", type_name ()); } template octave::range -ov_range::uint64_range_value (void) const +ov_range::uint64_range_value () const { err_wrong_type_arg ("ov_range::uint64_range_value ()", type_name ()); } @@ -500,70 +500,70 @@ template octave_value -ov_range::as_double (void) const +ov_range::as_double () const { return NDArray (raw_array_value ()); } template octave_value -ov_range::as_single (void) const +ov_range::as_single () const { return FloatMatrix (raw_array_value ()); } template octave_value -ov_range::as_int8 (void) const +ov_range::as_int8 () const { return int8NDArray (raw_array_value ()); } template octave_value -ov_range::as_int16 (void) const +ov_range::as_int16 () const { return int16NDArray (raw_array_value ()); } template octave_value -ov_range::as_int32 (void) const +ov_range::as_int32 () const { return int32NDArray (raw_array_value ()); } template octave_value -ov_range::as_int64 (void) const +ov_range::as_int64 () const { return int64NDArray (raw_array_value ()); } template octave_value -ov_range::as_uint8 (void) const +ov_range::as_uint8 () const { return uint8NDArray (raw_array_value ()); } template octave_value -ov_range::as_uint16 (void) const +ov_range::as_uint16 () const { return uint16NDArray (raw_array_value ()); } template octave_value -ov_range::as_uint32 (void) const +ov_range::as_uint32 () const { return uint32NDArray (raw_array_value ()); } template octave_value -ov_range::as_uint64 (void) const +ov_range::as_uint64 () const { return uint64NDArray (raw_array_value ()); } @@ -655,7 +655,7 @@ template float_display_format -ov_range::get_edit_display_format (void) const +ov_range::get_edit_display_format () const { return make_format (m_range); } @@ -1428,7 +1428,7 @@ template <> octave::range -ov_range::range_value (void) const +ov_range::range_value () const { return m_range; } @@ -1439,63 +1439,63 @@ template <> octave::range -ov_range::float_range_value (void) const +ov_range::float_range_value () const { return m_range; } template <> octave::range -ov_range::int8_range_value (void) const +ov_range::int8_range_value () const { return m_range; } template <> octave::range -ov_range::int16_range_value (void) const +ov_range::int16_range_value () const { return m_range; } template <> octave::range -ov_range::int32_range_value (void) const +ov_range::int32_range_value () const { return m_range; } template <> octave::range -ov_range::int64_range_value (void) const +ov_range::int64_range_value () const { return m_range; } template <> octave::range -ov_range::uint8_range_value (void) const +ov_range::uint8_range_value () const { return m_range; } template <> octave::range -ov_range::uint16_range_value (void) const +ov_range::uint16_range_value () const { return m_range; } template <> octave::range -ov_range::uint32_range_value (void) const +ov_range::uint32_range_value () const { return m_range; } template <> octave::range -ov_range::uint64_range_value (void) const +ov_range::uint64_range_value () const { return m_range; } @@ -1520,7 +1520,7 @@ template <> octave_idx_type -ov_range::nnz (void) const +ov_range::nnz () const { return m_range.nnz (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-range.h --- a/libinterp/octave-value/ov-range.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-range.h Mon Jan 30 18:36:03 2023 +0100 @@ -60,7 +60,7 @@ { public: - ov_range (void) + ov_range () : octave_base_value (), m_range (), m_idx_cache () { } ov_range (const octave::range& r) @@ -85,9 +85,9 @@ // No assignment. ov_range& operator = (const ov_range&) = delete; - ~ov_range (void) { clear_cached_info (); } + ~ov_range () { clear_cached_info (); } - octave_base_value * clone (void) const + octave_base_value * clone () const { return new ov_range (*this); } @@ -96,16 +96,16 @@ // the places where we need to call empty_clone, it makes more sense // to create an empty matrix (0x0) instead of an empty range (1x0). - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new typename octave_value_range_traits::matrix_type (); } - OCTINTERP_API type_conv_info numeric_conversion_function (void) const; + OCTINTERP_API type_conv_info numeric_conversion_function () const; - OCTINTERP_API octave_base_value * try_narrowing_conversion (void); + OCTINTERP_API octave_base_value * try_narrowing_conversion (); - builtin_type_t builtin_type (void) const { return class_to_btyp::btyp; } + builtin_type_t builtin_type () const { return class_to_btyp::btyp; } // We don't need to override all three forms of subsref. The using // declaration will avoid warnings about partially-overloaded virtual @@ -124,15 +124,15 @@ OCTINTERP_API octave::idx_vector index_vector (bool require_integers = false) const; - dim_vector dims (void) const + dim_vector dims () const { octave_idx_type n = numel (); return dim_vector (n > 0, n); } - octave_idx_type numel (void) const { return m_range.numel (); } + octave_idx_type numel () const { return m_range.numel (); } - octave_idx_type nnz (void) const + octave_idx_type nnz () const { // FIXME: this is a potential waste of memory. @@ -143,7 +143,7 @@ OCTINTERP_API octave_value resize (const dim_vector& dv, bool fill = false) const; - std::size_t byte_size (void) const { return 3 * sizeof (T); } + std::size_t byte_size () const { return 3 * sizeof (T); } octave_value reshape (const dim_vector& new_dims) const { @@ -155,53 +155,53 @@ return raw_array_value ().permute (vec, inv); } - octave_value squeeze (void) const { return m_range; } + octave_value squeeze () const { return m_range; } - octave_value full_value (void) const { return raw_array_value (); } + octave_value full_value () const { return raw_array_value (); } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_storable (void) const { return m_range.is_storable (); } + bool is_storable () const { return m_range.is_storable (); } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool is_range (void) const { return true; } + bool is_range () const { return true; } - bool is_double_type (void) const { return builtin_type () == btyp_double; } + bool is_double_type () const { return builtin_type () == btyp_double; } - bool is_single_type (void) const { return builtin_type () == btyp_float; } + bool is_single_type () const { return builtin_type () == btyp_float; } - bool isfloat (void) const { return btyp_isfloat (builtin_type ()); } + bool isfloat () const { return btyp_isfloat (builtin_type ()); } - bool is_int8_type (void) const { return builtin_type () == btyp_int8; } + bool is_int8_type () const { return builtin_type () == btyp_int8; } - bool is_int16_type (void) const { return builtin_type () == btyp_int16; } + bool is_int16_type () const { return builtin_type () == btyp_int16; } - bool is_int32_type (void) const { return builtin_type () == btyp_int32; } + bool is_int32_type () const { return builtin_type () == btyp_int32; } - bool is_int64_type (void) const { return builtin_type () == btyp_int64; } + bool is_int64_type () const { return builtin_type () == btyp_int64; } - bool is_uint8_type (void) const { return builtin_type () == btyp_uint8; } + bool is_uint8_type () const { return builtin_type () == btyp_uint8; } - bool is_uint16_type (void) const { return builtin_type () == btyp_uint16; } + bool is_uint16_type () const { return builtin_type () == btyp_uint16; } - bool is_uint32_type (void) const { return builtin_type () == btyp_uint32; } + bool is_uint32_type () const { return builtin_type () == btyp_uint32; } - bool is_uint64_type (void) const { return builtin_type () == btyp_uint64; } + bool is_uint64_type () const { return builtin_type () == btyp_uint64; } - bool isinteger (void) const + bool isinteger () const { return btyp_isinteger (builtin_type ()); } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool isnumeric (void) const + bool isnumeric () const { return btyp_isnumeric (builtin_type ()); } - bool is_true (void) const { return nnz () == numel (); } + bool is_true () const { return nnz () == numel (); } octave_value all (int dim = 0) const { @@ -268,7 +268,7 @@ return (mode == UNSORTED) ? ASCENDING : mode; } - Array raw_array_value (void) const { return m_range.array_value (); } + Array raw_array_value () const { return m_range.array_value (); } OCTINTERP_API double double_value (bool = false) const; @@ -310,42 +310,42 @@ // functions to avoid the intermediate conversion to a matrix // object. - int8NDArray int8_array_value (void) const + int8NDArray int8_array_value () const { return raw_array_value (); } - int16NDArray int16_array_value (void) const + int16NDArray int16_array_value () const { return raw_array_value (); } - int32NDArray int32_array_value (void) const + int32NDArray int32_array_value () const { return raw_array_value (); } - int64NDArray int64_array_value (void) const + int64NDArray int64_array_value () const { return raw_array_value (); } - uint8NDArray uint8_array_value (void) const + uint8NDArray uint8_array_value () const { return raw_array_value (); } - uint16NDArray uint16_array_value (void) const + uint16NDArray uint16_array_value () const { return raw_array_value (); } - uint32NDArray uint32_array_value (void) const + uint32NDArray uint32_array_value () const { return raw_array_value (); } - uint64NDArray uint64_array_value (void) const + uint64NDArray uint64_array_value () const { return raw_array_value (); } @@ -386,47 +386,47 @@ return raw_array_value (); } - OCTINTERP_API octave::range range_value (void) const; + OCTINTERP_API octave::range range_value () const; // For now, disable all but ov_range. #if 0 - OCTINTERP_API octave::range float_range_value (void) const; + OCTINTERP_API octave::range float_range_value () const; - OCTINTERP_API octave::range int8_range_value (void) const; + OCTINTERP_API octave::range int8_range_value () const; - OCTINTERP_API octave::range int16_range_value (void) const; + OCTINTERP_API octave::range int16_range_value () const; - OCTINTERP_API octave::range int32_range_value (void) const; + OCTINTERP_API octave::range int32_range_value () const; - OCTINTERP_API octave::range int64_range_value (void) const; + OCTINTERP_API octave::range int64_range_value () const; - OCTINTERP_API octave::range uint8_range_value (void) const; + OCTINTERP_API octave::range uint8_range_value () const; - OCTINTERP_API octave::range uint16_range_value (void) const; + OCTINTERP_API octave::range uint16_range_value () const; - OCTINTERP_API octave::range uint32_range_value (void) const; + OCTINTERP_API octave::range uint32_range_value () const; - OCTINTERP_API octave::range uint64_range_value (void) const; + OCTINTERP_API octave::range uint64_range_value () const; #endif OCTINTERP_API octave_value convert_to_str_internal (bool pad, bool force, char type) const; - OCTINTERP_API octave_value as_double (void) const; - OCTINTERP_API octave_value as_single (void) const; + OCTINTERP_API octave_value as_double () const; + OCTINTERP_API octave_value as_single () const; - OCTINTERP_API octave_value as_int8 (void) const; - OCTINTERP_API octave_value as_int16 (void) const; - OCTINTERP_API octave_value as_int32 (void) const; - OCTINTERP_API octave_value as_int64 (void) const; + OCTINTERP_API octave_value as_int8 () const; + OCTINTERP_API octave_value as_int16 () const; + OCTINTERP_API octave_value as_int32 () const; + OCTINTERP_API octave_value as_int64 () const; - OCTINTERP_API octave_value as_uint8 (void) const; - OCTINTERP_API octave_value as_uint16 (void) const; - OCTINTERP_API octave_value as_uint32 (void) const; - OCTINTERP_API octave_value as_uint64 (void) const; + OCTINTERP_API octave_value as_uint8 () const; + OCTINTERP_API octave_value as_uint16 () const; + OCTINTERP_API octave_value as_uint32 () const; + OCTINTERP_API octave_value as_uint64 () const; OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -438,7 +438,7 @@ OCTINTERP_API void short_disp (std::ostream& os) const; - OCTINTERP_API float_display_format get_edit_display_format (void) const; + OCTINTERP_API float_display_format get_edit_display_format () const; OCTINTERP_API std::string edit_display (const float_display_format& fmt, @@ -490,7 +490,7 @@ return idx; } - void clear_cached_info (void) const + void clear_cached_info () const { delete m_idx_cache; m_idx_cache = nullptr; } @@ -524,7 +524,7 @@ template <> OCTINTERP_API octave::range -ov_range::range_value (void) const; +ov_range::range_value () const; // For now, disable all but ov_range. @@ -532,39 +532,39 @@ template <> OCTINTERP_API octave::range -ov_range::float_range_value (void) const; +ov_range::float_range_value () const; template <> OCTINTERP_API octave::range -ov_range::int8_range_value (void) const; +ov_range::int8_range_value () const; template <> OCTINTERP_API octave::range -ov_range::int16_range_value (void) const; +ov_range::int16_range_value () const; template <> OCTINTERP_API octave::range -ov_range::int32_range_value (void) const; +ov_range::int32_range_value () const; template <> OCTINTERP_API octave::range -ov_range::int64_range_value (void) const; +ov_range::int64_range_value () const; template <> OCTINTERP_API octave::range -ov_range::uint8_range_value (void) const; +ov_range::uint8_range_value () const; template <> OCTINTERP_API octave::range -ov_range::uint16_range_value (void) const; +ov_range::uint16_range_value () const; template <> OCTINTERP_API octave::range -ov_range::uint32_range_value (void) const; +ov_range::uint32_range_value () const; template <> OCTINTERP_API octave::range -ov_range::uint64_range_value (void) const; +ov_range::uint64_range_value () const; #endif @@ -577,7 +577,7 @@ template <> OCTINTERP_API octave_idx_type -ov_range::nnz (void) const; +ov_range::nnz () const; // The following specialization is also historical baggage. For double // ranges, we can produce special double-valued diagnoal matrix objects diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-re-diag.cc --- a/libinterp/octave-value/ov-re-diag.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-re-diag.cc Mon Jan 30 18:36:03 2023 +0100 @@ -51,7 +51,7 @@ } octave_base_value::type_conv_info -octave_diag_matrix::numeric_conversion_function (void) const +octave_diag_matrix::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_matrix::static_type_id ()); @@ -66,7 +66,7 @@ } octave_base_value::type_conv_info -octave_diag_matrix::numeric_demotion_function (void) const +octave_diag_matrix::numeric_demotion_function () const { return octave_base_value::type_conv_info (default_numeric_demotion_function, @@ -74,7 +74,7 @@ } octave_base_value * -octave_diag_matrix::try_narrowing_conversion (void) +octave_diag_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -161,61 +161,61 @@ } octave_value -octave_diag_matrix::as_double (void) const +octave_diag_matrix::as_double () const { return m_matrix; } octave_value -octave_diag_matrix::as_single (void) const +octave_diag_matrix::as_single () const { return FloatDiagMatrix (m_matrix); } octave_value -octave_diag_matrix::as_int8 (void) const +octave_diag_matrix::as_int8 () const { return int8_array_value (); } octave_value -octave_diag_matrix::as_int16 (void) const +octave_diag_matrix::as_int16 () const { return int16_array_value (); } octave_value -octave_diag_matrix::as_int32 (void) const +octave_diag_matrix::as_int32 () const { return int32_array_value (); } octave_value -octave_diag_matrix::as_int64 (void) const +octave_diag_matrix::as_int64 () const { return int64_array_value (); } octave_value -octave_diag_matrix::as_uint8 (void) const +octave_diag_matrix::as_uint8 () const { return uint8_array_value (); } octave_value -octave_diag_matrix::as_uint16 (void) const +octave_diag_matrix::as_uint16 () const { return uint16_array_value (); } octave_value -octave_diag_matrix::as_uint32 (void) const +octave_diag_matrix::as_uint32 () const { return uint32_array_value (); } octave_value -octave_diag_matrix::as_uint64 (void) const +octave_diag_matrix::as_uint64 () const { return uint64_array_value (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-re-diag.h --- a/libinterp/octave-value/ov-re-diag.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-re-diag.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ { public: - octave_diag_matrix (void) + octave_diag_matrix () : octave_base_diag () { } octave_diag_matrix (const DiagMatrix& m) @@ -51,31 +51,31 @@ octave_diag_matrix (const octave_diag_matrix& m) : octave_base_diag (m) { } - ~octave_diag_matrix (void) = default; + ~octave_diag_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_diag_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_diag_matrix (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; - type_conv_info numeric_demotion_function (void) const; + type_conv_info numeric_demotion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); - builtin_type_t builtin_type (void) const { return btyp_double; } + builtin_type_t builtin_type () const { return btyp_double; } - bool is_real_matrix (void) const { return true; } + bool is_real_matrix () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } DiagMatrix diag_matrix_value (bool = false) const; @@ -85,18 +85,18 @@ FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; bool save_binary (std::ostream& os, bool save_as_floats); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-re-mat.cc --- a/libinterp/octave-value/ov-re-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-re-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -98,7 +98,7 @@ } octave_base_value::type_conv_info -octave_matrix::numeric_demotion_function (void) const +octave_matrix::numeric_demotion_function () const { return octave_base_value::type_conv_info (default_numeric_demotion_function, @@ -106,7 +106,7 @@ } octave_base_value * -octave_matrix::try_narrowing_conversion (void) +octave_matrix::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -250,61 +250,61 @@ } octave_value -octave_matrix::as_double (void) const +octave_matrix::as_double () const { return NDArray (m_matrix); } octave_value -octave_matrix::as_single (void) const +octave_matrix::as_single () const { return FloatNDArray (m_matrix); } octave_value -octave_matrix::as_int8 (void) const +octave_matrix::as_int8 () const { return int8NDArray (m_matrix); } octave_value -octave_matrix::as_int16 (void) const +octave_matrix::as_int16 () const { return int16NDArray (m_matrix); } octave_value -octave_matrix::as_int32 (void) const +octave_matrix::as_int32 () const { return int32NDArray (m_matrix); } octave_value -octave_matrix::as_int64 (void) const +octave_matrix::as_int64 () const { return int64NDArray (m_matrix); } octave_value -octave_matrix::as_uint8 (void) const +octave_matrix::as_uint8 () const { return uint8NDArray (m_matrix); } octave_value -octave_matrix::as_uint16 (void) const +octave_matrix::as_uint16 () const { return uint16NDArray (m_matrix); } octave_value -octave_matrix::as_uint32 (void) const +octave_matrix::as_uint32 () const { return uint32NDArray (m_matrix); } octave_value -octave_matrix::as_uint64 (void) const +octave_matrix::as_uint64 () const { return uint64NDArray (m_matrix); } @@ -350,7 +350,7 @@ } octave_value -octave_matrix::squeeze (void) const +octave_matrix::squeeze () const { if (m_idx_cache) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-re-mat.h --- a/libinterp/octave-value/ov-re-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-re-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_matrix (void) + octave_matrix () : octave_base_matrix () { } octave_matrix (const Matrix& m) @@ -96,14 +96,14 @@ set_idx_cache (cache); } - ~octave_matrix (void) = default; + ~octave_matrix () = default; - octave_base_value * clone (void) const { return new octave_matrix (*this); } - octave_base_value * empty_clone (void) const { return new octave_matrix (); } + octave_base_value * clone () const { return new octave_matrix (*this); } + octave_base_value * empty_clone () const { return new octave_matrix (); } - type_conv_info numeric_demotion_function (void) const; + type_conv_info numeric_demotion_function () const; - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); octave::idx_vector index_vector (bool /* require_integers */ = false) const { @@ -111,39 +111,39 @@ : set_idx_cache (octave::idx_vector (m_matrix)); } - builtin_type_t builtin_type (void) const { return btyp_double; } + builtin_type_t builtin_type () const { return btyp_double; } - bool is_real_matrix (void) const { return true; } + bool is_real_matrix () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } int8NDArray - int8_array_value (void) const { return int8NDArray (m_matrix); } + int8_array_value () const { return int8NDArray (m_matrix); } int16NDArray - int16_array_value (void) const { return int16NDArray (m_matrix); } + int16_array_value () const { return int16NDArray (m_matrix); } int32NDArray - int32_array_value (void) const { return int32NDArray (m_matrix); } + int32_array_value () const { return int32NDArray (m_matrix); } int64NDArray - int64_array_value (void) const { return int64NDArray (m_matrix); } + int64_array_value () const { return int64NDArray (m_matrix); } uint8NDArray - uint8_array_value (void) const { return uint8NDArray (m_matrix); } + uint8_array_value () const { return uint8NDArray (m_matrix); } uint16NDArray - uint16_array_value (void) const { return uint16NDArray (m_matrix); } + uint16_array_value () const { return uint16NDArray (m_matrix); } uint32NDArray - uint32_array_value (void) const { return uint32NDArray (m_matrix); } + uint32_array_value () const { return uint32NDArray (m_matrix); } uint64NDArray - uint64_array_value (void) const { return uint64NDArray (m_matrix); } + uint64_array_value () const { return uint64NDArray (m_matrix); } double double_value (bool = false) const; @@ -180,18 +180,18 @@ SparseComplexMatrix sparse_complex_matrix_value (bool = false) const; - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; octave_value diag (octave_idx_type k = 0) const; @@ -199,7 +199,7 @@ octave_value reshape (const dim_vector& new_dims) const; - octave_value squeeze (void) const; + octave_value squeeze () const; octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; octave_value sort (Array& sidx, octave_idx_type dim = 0, @@ -212,11 +212,11 @@ sortmode is_sorted_rows (sortmode mode = UNSORTED) const; // Use matrix_ref here to clear index cache. - void increment (void) { matrix_ref () += 1.0; } + void increment () { matrix_ref () += 1.0; } - void decrement (void) { matrix_ref () -= 1.0; } + void decrement () { matrix_ref () -= 1.0; } - void changesign (void) { matrix_ref ().changesign (); } + void changesign () { matrix_ref ().changesign (); } octave_value convert_to_str_internal (bool pad, bool force, char type) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-re-sparse.cc --- a/libinterp/octave-value/ov-re-sparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-re-sparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -214,7 +214,7 @@ } octave_value -octave_sparse_matrix::as_double (void) const +octave_sparse_matrix::as_double () const { return this->matrix; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-re-sparse.h --- a/libinterp/octave-value/ov-re-sparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-re-sparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_sparse_matrix (void) + octave_sparse_matrix () : octave_base_sparse () { } octave_sparse_matrix (const Matrix& m) @@ -84,24 +84,24 @@ octave_sparse_matrix (const octave_sparse_matrix& m) : octave_base_sparse (m) { } - ~octave_sparse_matrix (void) = default; + ~octave_sparse_matrix () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_sparse_matrix (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_sparse_matrix (); } octave::idx_vector index_vector (bool require_integers = false) const; - builtin_type_t builtin_type (void) const { return btyp_double; } + builtin_type_t builtin_type () const { return btyp_double; } - bool is_real_matrix (void) const { return true; } + bool is_real_matrix () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } double double_value (bool = false) const; @@ -132,7 +132,7 @@ octave_value convert_to_str_internal (bool pad, bool force, char type) const; - octave_value as_double (void) const; + octave_value as_double () const; #if 0 int write (octave::stream& os, int block_size, diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-scalar.cc --- a/libinterp/octave-value/ov-scalar.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-scalar.cc Mon Jan 30 18:36:03 2023 +0100 @@ -76,7 +76,7 @@ } octave_base_value::type_conv_info -octave_scalar::numeric_demotion_function (void) const +octave_scalar::numeric_demotion_function () const { return octave_base_value::type_conv_info (default_numeric_demotion_function, @@ -125,61 +125,61 @@ } octave_value -octave_scalar::as_double (void) const +octave_scalar::as_double () const { return scalar; } octave_value -octave_scalar::as_single (void) const +octave_scalar::as_single () const { return static_cast (scalar); } octave_value -octave_scalar::as_int8 (void) const +octave_scalar::as_int8 () const { return octave_int8 (scalar); } octave_value -octave_scalar::as_int16 (void) const +octave_scalar::as_int16 () const { return octave_int16 (scalar); } octave_value -octave_scalar::as_int32 (void) const +octave_scalar::as_int32 () const { return octave_int32 (scalar); } octave_value -octave_scalar::as_int64 (void) const +octave_scalar::as_int64 () const { return octave_int64 (scalar); } octave_value -octave_scalar::as_uint8 (void) const +octave_scalar::as_uint8 () const { return octave_uint8 (scalar); } octave_value -octave_scalar::as_uint16 (void) const +octave_scalar::as_uint16 () const { return octave_uint16 (scalar); } octave_value -octave_scalar::as_uint32 (void) const +octave_scalar::as_uint32 () const { return octave_uint32 (scalar); } octave_value -octave_scalar::as_uint64 (void) const +octave_scalar::as_uint64 () const { return octave_uint64 (scalar); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-scalar.h --- a/libinterp/octave-value/ov-scalar.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-scalar.h Mon Jan 30 18:36:03 2023 +0100 @@ -55,7 +55,7 @@ { public: - octave_scalar (void) + octave_scalar () : octave_base_scalar (0.0) { } octave_scalar (double d) @@ -64,19 +64,19 @@ octave_scalar (const octave_scalar& s) : octave_base_scalar (s) { } - ~octave_scalar (void) = default; + ~octave_scalar () = default; - octave_base_value * clone (void) const { return new octave_scalar (*this); } + octave_base_value * clone () const { return new octave_scalar (*this); } // We return an octave_matrix here instead of an octave_scalar so // that in expressions like A(2,2,2) = 2 (for A previously // undefined), A will be empty instead of a 1x1 object. - octave_base_value * empty_clone (void) const { return new octave_matrix (); } + octave_base_value * empty_clone () const { return new octave_matrix (); } octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); - type_conv_info numeric_demotion_function (void) const; + type_conv_info numeric_demotion_function () const; octave::idx_vector index_vector (bool /* require_integers */ = false) const { return octave::idx_vector (scalar); } @@ -84,51 +84,51 @@ octave_value any (int = 0) const { return (scalar != 0 && ! lo_ieee_isnan (scalar)); } - builtin_type_t builtin_type (void) const { return btyp_double; } + builtin_type_t builtin_type () const { return btyp_double; } - bool is_real_scalar (void) const { return true; } + bool is_real_scalar () const { return true; } - bool isreal (void) const { return true; } + bool isreal () const { return true; } - bool is_double_type (void) const { return true; } + bool is_double_type () const { return true; } - bool isfloat (void) const { return true; } + bool isfloat () const { return true; } int8NDArray - int8_array_value (void) const + int8_array_value () const { return int8NDArray (dim_vector (1, 1), scalar); } int16NDArray - int16_array_value (void) const + int16_array_value () const { return int16NDArray (dim_vector (1, 1), scalar); } int32NDArray - int32_array_value (void) const + int32_array_value () const { return int32NDArray (dim_vector (1, 1), scalar); } int64NDArray - int64_array_value (void) const + int64_array_value () const { return int64NDArray (dim_vector (1, 1), scalar); } uint8NDArray - uint8_array_value (void) const + uint8_array_value () const { return uint8NDArray (dim_vector (1, 1), scalar); } uint16NDArray - uint16_array_value (void) const + uint16_array_value () const { return uint16NDArray (dim_vector (1, 1), scalar); } uint32NDArray - uint32_array_value (void) const + uint32_array_value () const { return uint32NDArray (dim_vector (1, 1), scalar); } uint64NDArray - uint64_array_value (void) const + uint64_array_value () const { return uint64NDArray (dim_vector (1, 1), scalar); } #define DEFINE_INT_SCALAR_VALUE(TYPE) \ octave_ ## TYPE \ - TYPE ## _scalar_value (void) const \ + TYPE ## _scalar_value () const \ { \ return octave_ ## TYPE (scalar); \ } @@ -223,18 +223,18 @@ return boolNDArray (dim_vector (1, 1), scalar); } - octave_value as_double (void) const; - octave_value as_single (void) const; + octave_value as_double () const; + octave_value as_single () const; - octave_value as_int8 (void) const; - octave_value as_int16 (void) const; - octave_value as_int32 (void) const; - octave_value as_int64 (void) const; + octave_value as_int8 () const; + octave_value as_int16 () const; + octave_value as_int32 () const; + octave_value as_int64 () const; - octave_value as_uint8 (void) const; - octave_value as_uint16 (void) const; - octave_value as_uint32 (void) const; - octave_value as_uint64 (void) const; + octave_value as_uint8 () const; + octave_value as_uint16 () const; + octave_value as_uint32 () const; + octave_value as_uint64 () const; // We don't need to override both forms of the diag method. The using // declaration will avoid warnings about partially-overloaded virtual @@ -245,9 +245,9 @@ octave_value convert_to_str_internal (bool pad, bool force, char type) const; - void increment (void) { ++scalar; } + void increment () { ++scalar; } - void decrement (void) { --scalar; } + void decrement () { --scalar; } bool save_ascii (std::ostream& os); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-str-mat.cc --- a/libinterp/octave-value/ov-str-mat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-str-mat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -80,7 +80,7 @@ } octave_base_value::type_conv_info -octave_char_matrix_str::numeric_conversion_function (void) const +octave_char_matrix_str::numeric_conversion_function () const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_matrix::static_type_id ()); @@ -252,7 +252,7 @@ */ Array -octave_char_matrix_str::cellstr_value (void) const +octave_char_matrix_str::cellstr_value () const { Array retval; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-str-mat.h --- a/libinterp/octave-value/ov-str-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-str-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ { public: - octave_char_matrix_str (void) + octave_char_matrix_str () : octave_char_matrix () { } octave_char_matrix_str (const charMatrix& chm) @@ -84,20 +84,20 @@ octave_char_matrix_str (const octave_char_matrix_str& chms) : octave_char_matrix (chms) { } - ~octave_char_matrix_str (void) = default; + ~octave_char_matrix_str () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_char_matrix_str (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_char_matrix_str (); } - type_conv_info numeric_conversion_function (void) const; + type_conv_info numeric_conversion_function () const; octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false) { return do_index_op_internal (idx, resize_ok); } - octave_value squeeze (void) const + octave_value squeeze () const { return octave_value (charNDArray (m_matrix.squeeze ())); } octave_value reshape (const dim_vector& new_dims) const @@ -116,9 +116,9 @@ octave_value diag (octave_idx_type k = 0) const { return octave_value (m_matrix.diag (k)); } - bool is_string (void) const { return true; } + bool is_string () const { return true; } - bool isnumeric (void) const { return false; } + bool isnumeric () const { return false; } double double_value (bool = false) const; @@ -136,9 +136,9 @@ std::string string_value (bool force = false) const; - std::string xstring_value (void) const { return string_value (); } + std::string xstring_value () const { return string_value (); } - Array cellstr_value (void) const; + Array cellstr_value () const; octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { return octave_value (m_matrix.sort (dim, mode)); } @@ -147,7 +147,7 @@ sortmode mode = ASCENDING) const { return octave_value (m_matrix.sort (sidx, dim, mode)); } - bool print_as_scalar (void) const { return (rows () <= 1); } + bool print_as_scalar () const { return (rows () <= 1); } void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; @@ -191,7 +191,7 @@ { public: - octave_char_matrix_sq_str (void) + octave_char_matrix_sq_str () : octave_char_matrix_str () { } octave_char_matrix_sq_str (const charMatrix& chm) @@ -221,14 +221,14 @@ octave_char_matrix_sq_str (const octave_char_matrix_sq_str& chms) : octave_char_matrix_str (chms) { } - ~octave_char_matrix_sq_str (void) = default; + ~octave_char_matrix_sq_str () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_char_matrix_sq_str (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_char_matrix_sq_str (); } - octave_value squeeze (void) const + octave_value squeeze () const { return octave_value (charNDArray (m_matrix.squeeze ()), '\''); } octave_value reshape (const dim_vector& new_dims) const @@ -252,7 +252,7 @@ octave_value diag (octave_idx_type k = 0) const { return octave_value (m_matrix.diag (k), '\''); } - bool is_sq_string (void) const { return true; } + bool is_sq_string () const { return true; } octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false) diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-struct.cc Mon Jan 30 18:36:03 2023 +0100 @@ -76,7 +76,7 @@ } octave_base_value * -octave_struct::try_narrowing_conversion (void) +octave_struct::try_narrowing_conversion () { octave_base_value *retval = nullptr; @@ -109,7 +109,7 @@ } static void -err_invalid_index_for_assignment (void) +err_invalid_index_for_assignment () { error ("invalid index for structure array assignment"); } @@ -571,7 +571,7 @@ } std::size_t -octave_struct::byte_size (void) const +octave_struct::byte_size () const { // Neglect the size of the fieldnames. @@ -1292,7 +1292,7 @@ } std::size_t -octave_scalar_struct::byte_size (void) const +octave_scalar_struct::byte_size () const { // Neglect the size of the fieldnames. @@ -1694,7 +1694,7 @@ } octave_value -octave_scalar_struct::to_array (void) +octave_scalar_struct::to_array () { return new octave_struct (octave_map (m_map)); } @@ -1794,8 +1794,7 @@ { if (nargin == 2) { - Array cstr = args( - 1).xcellstr_value ("struct: second argument should be a cell array of field names"); + Array cstr = args(1).xcellstr_value ("struct: second argument should be a cell array of field names"); return ovl (octave_map (args(0).dims (), cstr)); } @@ -2020,7 +2019,7 @@ OCTAVE_NORETURN static void -invalid_cell2struct_fields_error (void) +invalid_cell2struct_fields_error () { error ("cell2struct: FIELDS must be a cell array of strings or a scalar string"); } @@ -2091,8 +2090,7 @@ if (nargin < 2 || nargin > 3) print_usage (); - const Cell vals - = args(0).xcell_value ("cell2struct: argument CELL must be of type cell"); + const Cell vals = args(0).xcell_value ("cell2struct: argument CELL must be of type cell"); const Array fields = get_cell2struct_fields (args(1)); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-struct.h --- a/libinterp/octave-value/ov-struct.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-struct.h Mon Jan 30 18:36:03 2023 +0100 @@ -50,7 +50,7 @@ { public: - octave_struct (void) + octave_struct () : octave_base_value (), m_map () { } octave_struct (const octave_map& m) @@ -59,14 +59,14 @@ octave_struct (const octave_struct& s) : octave_base_value (), m_map (s.m_map) { } - ~octave_struct (void) = default; + ~octave_struct () = default; - octave_base_value * clone (void) const { return new octave_struct (*this); } - octave_base_value * empty_clone (void) const { return new octave_struct (); } + octave_base_value * clone () const { return new octave_struct (*this); } + octave_base_value * empty_clone () const { return new octave_struct (); } void break_closure_cycles (const std::shared_ptr& frame); - octave_base_value * try_narrowing_conversion (void); + octave_base_value * try_narrowing_conversion (); Cell dotref (const octave_value_list& idx, bool auto_add = false); @@ -91,7 +91,7 @@ const std::list& idx, const octave_value& rhs); - octave_value squeeze (void) const { return m_map.squeeze (); } + octave_value squeeze () const { return m_map.squeeze (); } octave_value permute (const Array& vec, bool inv = false) const { return m_map.permute (vec, inv); } @@ -99,18 +99,18 @@ octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); - dim_vector dims (void) const { return m_map.dims (); } + dim_vector dims () const { return m_map.dims (); } - std::size_t byte_size (void) const; + std::size_t byte_size () const; // This is the number of elements in each field. The total number // of elements is numel () * nfields (). - octave_idx_type numel (void) const + octave_idx_type numel () const { return m_map.numel (); } - octave_idx_type nfields (void) const { return m_map.nfields (); } + octave_idx_type nfields () const { return m_map.nfields (); } octave_value reshape (const dim_vector& new_dims) const { return m_map.reshape (new_dims); } @@ -118,17 +118,17 @@ octave_value resize (const dim_vector& dv, bool fill = false) const { octave_map tmap = m_map; tmap.resize (dv, fill); return tmap; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool isstruct (void) const { return true; } + bool isstruct () const { return true; } - builtin_type_t builtin_type (void) const { return btyp_struct; } + builtin_type_t builtin_type () const { return btyp_struct; } - octave_map map_value (void) const { return m_map; } + octave_map map_value () const { return m_map; } - string_vector map_keys (void) const { return m_map.fieldnames (); } + string_vector map_keys () const { return m_map.fieldnames (); } bool isfield (const std::string& field_name) const { return m_map.isfield (field_name); } @@ -178,7 +178,7 @@ { public: - octave_scalar_struct (void) + octave_scalar_struct () : octave_base_value (), m_map () { } octave_scalar_struct (const octave_scalar_map& m) @@ -190,11 +190,11 @@ octave_scalar_struct (const octave_scalar_struct& s) : octave_base_value (), m_map (s.m_map) { } - ~octave_scalar_struct (void) = default; + ~octave_scalar_struct () = default; - octave_base_value * clone (void) const + octave_base_value * clone () const { return new octave_scalar_struct (*this); } - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return new octave_scalar_struct (); } void break_closure_cycles (const std::shared_ptr& frame); @@ -218,7 +218,7 @@ const std::list& idx, const octave_value& rhs); - octave_value squeeze (void) const { return m_map; } + octave_value squeeze () const { return m_map; } octave_value permute (const Array& vec, bool inv = false) const { return octave_map (m_map).permute (vec, inv); } @@ -226,18 +226,18 @@ octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); - dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } + dim_vector dims () const { static dim_vector dv (1, 1); return dv; } - std::size_t byte_size (void) const; + std::size_t byte_size () const; // This is the number of elements in each field. The total number // of elements is numel () * nfields (). - octave_idx_type numel (void) const + octave_idx_type numel () const { return 1; } - octave_idx_type nfields (void) const { return m_map.nfields (); } + octave_idx_type nfields () const { return m_map.nfields (); } octave_value reshape (const dim_vector& new_dims) const { return octave_map (m_map).reshape (new_dims); } @@ -245,19 +245,19 @@ octave_value resize (const dim_vector& dv, bool fill = false) const { octave_map tmap = m_map; tmap.resize (dv, fill); return tmap; } - bool is_defined (void) const { return true; } + bool is_defined () const { return true; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool isstruct (void) const { return true; } + bool isstruct () const { return true; } - builtin_type_t builtin_type (void) const { return btyp_struct; } + builtin_type_t builtin_type () const { return btyp_struct; } - octave_map map_value (void) const { return m_map; } + octave_map map_value () const { return m_map; } - octave_scalar_map scalar_map_value (void) const { return m_map; } + octave_scalar_map scalar_map_value () const { return m_map; } - string_vector map_keys (void) const { return m_map.fieldnames (); } + string_vector map_keys () const { return m_map.fieldnames (); } bool isfield (const std::string& field_name) const { return m_map.isfield (field_name); } @@ -295,7 +295,7 @@ private: - octave_value to_array (void); + octave_value to_array (); DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-typeinfo.cc --- a/libinterp/octave-value/ov-typeinfo.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-typeinfo.cc Mon Jan 30 18:36:03 2023 +0100 @@ -581,7 +581,7 @@ } string_vector -type_info::installed_type_names (void) const +type_info::installed_type_names () const { string_vector retval (m_num_types); @@ -592,7 +592,7 @@ } octave_scalar_map -type_info::unary_ops_map (void) const +type_info::unary_ops_map () const { octave_scalar_map retval; @@ -617,7 +617,7 @@ } octave_scalar_map -type_info::non_const_unary_ops_map (void) const +type_info::non_const_unary_ops_map () const { octave_scalar_map retval; @@ -642,7 +642,7 @@ } octave_scalar_map -type_info::binary_ops_map (void) const +type_info::binary_ops_map () const { octave_scalar_map retval; @@ -668,7 +668,7 @@ } octave_scalar_map -type_info::compound_binary_ops_map (void) const +type_info::compound_binary_ops_map () const { octave_scalar_map retval; @@ -695,7 +695,7 @@ } octave_scalar_map -type_info::assign_ops_map (void) const +type_info::assign_ops_map () const { octave_scalar_map retval; @@ -721,7 +721,7 @@ } octave_scalar_map -type_info::assignany_ops_map (void) const +type_info::assignany_ops_map () const { octave_scalar_map retval; @@ -746,7 +746,7 @@ } octave_scalar_map -type_info::installed_type_info (void) const +type_info::installed_type_info () const { octave_scalar_map retval; @@ -875,14 +875,14 @@ return type_info.lookup_widening_op (t, t_result); } -string_vector installed_type_names (void) +string_vector installed_type_names () { octave::type_info& type_info = octave::__get_type_info__ (); return type_info.installed_type_names (); } -octave_scalar_map installed_type_info (void) +octave_scalar_map installed_type_info () { octave::type_info& type_info = octave::__get_type_info__ (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-typeinfo.h --- a/libinterp/octave-value/ov-typeinfo.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-typeinfo.h Mon Jan 30 18:36:03 2023 +0100 @@ -75,7 +75,7 @@ type_info& operator = (const type_info&) = delete; - ~type_info (void) = default; + ~type_info () = default; // It is intentional that there is no install_type function. @@ -219,21 +219,21 @@ octave_base_value::type_conv_fcn lookup_widening_op (int, int); - string_vector installed_type_names (void) const; + string_vector installed_type_names () const; - octave_scalar_map installed_type_info (void) const; + octave_scalar_map installed_type_info () const; - octave_scalar_map unary_ops_map (void) const; + octave_scalar_map unary_ops_map () const; - octave_scalar_map non_const_unary_ops_map (void) const; + octave_scalar_map non_const_unary_ops_map () const; - octave_scalar_map binary_ops_map (void) const; + octave_scalar_map binary_ops_map () const; - octave_scalar_map compound_binary_ops_map (void) const; + octave_scalar_map compound_binary_ops_map () const; - octave_scalar_map assign_ops_map (void) const; + octave_scalar_map assign_ops_map () const; - octave_scalar_map assignany_ops_map (void) const; + octave_scalar_map assignany_ops_map () const; private: @@ -328,9 +328,9 @@ extern OCTINTERP_API octave_base_value::type_conv_fcn lookup_widening_op (int t, int t_result); -extern OCTINTERP_API string_vector installed_type_names (void); +extern OCTINTERP_API string_vector installed_type_names (); -extern OCTINTERP_API octave_scalar_map installed_type_info (void); +extern OCTINTERP_API octave_scalar_map installed_type_info (); OCTAVE_END_NAMESPACE(octave_value_typeinfo) diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-usr-fcn.cc --- a/libinterp/octave-value/ov-usr-fcn.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-usr-fcn.cc Mon Jan 30 18:36:03 2023 +0100 @@ -64,7 +64,7 @@ // Whether to optimize subsasgn method calls. static bool Voptimize_subsasgn_calls = true; -octave_user_code::~octave_user_code (void) +octave_user_code::~octave_user_code () { // This function is no longer valid, so remove the pointer to it from // the corresponding scope. @@ -85,7 +85,7 @@ } void -octave_user_code::get_file_info (void) +octave_user_code::get_file_info () { m_file_info = new octave::file_info (m_file_name); @@ -128,13 +128,13 @@ } std::map -octave_user_code::subfunctions (void) const +octave_user_code::subfunctions () const { return std::map (); } octave_value -octave_user_code::dump (void) const +octave_user_code::dump () const { std::map m = {{ "scope_info", m_scope ? m_scope.dump () : "0x0" }, @@ -153,7 +153,7 @@ "user-defined script", "user-defined script"); -octave_user_script::octave_user_script (void) +octave_user_script::octave_user_script () : octave_user_code () { } @@ -228,7 +228,7 @@ m_cmd_list->mark_as_function_body (); } -octave_user_function::~octave_user_function (void) +octave_user_function::~octave_user_function () { delete m_param_list; delete m_ret_list; @@ -253,7 +253,7 @@ // information (yet). void -octave_user_function::maybe_relocate_end_internal (void) +octave_user_function::maybe_relocate_end_internal () { if (m_cmd_list && ! m_cmd_list->empty ()) { @@ -289,7 +289,7 @@ } void -octave_user_function::maybe_relocate_end (void) +octave_user_function::maybe_relocate_end () { std::map fcns = subfunctions (); @@ -314,7 +314,7 @@ } std::string -octave_user_function::profiler_name (void) const +octave_user_function::profiler_name () const { std::ostringstream result; @@ -337,7 +337,7 @@ } void -octave_user_function::mark_as_system_fcn_file (void) +octave_user_function::mark_as_system_fcn_file () { if (! m_file_name.empty ()) { @@ -367,19 +367,19 @@ } void -octave_user_function::erase_subfunctions (void) +octave_user_function::erase_subfunctions () { m_scope.erase_subfunctions (); } bool -octave_user_function::takes_varargs (void) const +octave_user_function::takes_varargs () const { return (m_param_list && m_param_list->takes_varargs ()); } bool -octave_user_function::takes_var_return (void) const +octave_user_function::takes_var_return () const { return (m_ret_list && m_ret_list->takes_varargs ()); } @@ -393,19 +393,19 @@ } void -octave_user_function::lock_subfunctions (void) +octave_user_function::lock_subfunctions () { m_scope.lock_subfunctions (); } void -octave_user_function::unlock_subfunctions (void) +octave_user_function::unlock_subfunctions () { m_scope.unlock_subfunctions (); } std::map -octave_user_function::subfunctions (void) const +octave_user_function::subfunctions () const { return m_scope.subfunctions (); } @@ -442,7 +442,7 @@ } bool -octave_user_function::has_subfunctions (void) const +octave_user_function::has_subfunctions () const { return m_scope.has_subfunctions (); } @@ -454,7 +454,7 @@ } std::list -octave_user_function::subfunction_names (void) const +octave_user_function::subfunction_names () const { return m_scope.subfunction_names (); } @@ -502,7 +502,7 @@ } octave::tree_expression * -octave_user_function::special_expr (void) +octave_user_function::special_expr () { panic_unless (is_special_expr ()); panic_if (m_cmd_list->length () != 1); @@ -512,7 +512,7 @@ } bool -octave_user_function::subsasgn_optimization_ok (void) +octave_user_function::subsasgn_optimization_ok () { bool retval = false; if (Voptimize_subsasgn_calls @@ -529,7 +529,7 @@ } std::string -octave_user_function::ctor_type_str (void) const +octave_user_function::ctor_type_str () const { std::string retval; @@ -556,7 +556,7 @@ } std::string -octave_user_function::method_type_str (void) const +octave_user_function::method_type_str () const { std::string retval; @@ -583,7 +583,7 @@ } octave_value -octave_user_function::dump (void) const +octave_user_function::dump () const { std::map m = {{ "user_code", octave_user_code::dump () }, @@ -621,7 +621,7 @@ } void -octave_user_function::restore_warning_states (void) +octave_user_function::restore_warning_states () { octave::interpreter& interp = octave::__get_interpreter__ (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov-usr-fcn.h --- a/libinterp/octave-value/ov-usr-fcn.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov-usr-fcn.h Mon Jan 30 18:36:03 2023 +0100 @@ -79,9 +79,9 @@ octave_user_code& operator = (const octave_user_code& f) = delete; - ~octave_user_code (void); + ~octave_user_code (); - bool is_user_code (void) const { return true; } + bool is_user_code () const { return true; } std::string get_code_line (std::size_t line); @@ -91,7 +91,7 @@ void cache_function_text (const std::string& text, const octave::sys::time& timestamp); - octave::symbol_scope scope (void) { return m_scope; } + octave::symbol_scope scope () { return m_scope; } void stash_fcn_file_name (const std::string& nm) { m_file_name = nm; } @@ -104,26 +104,26 @@ mark_fcn_file_up_to_date (t); } - std::string fcn_file_name (void) const { return m_file_name; } + std::string fcn_file_name () const { return m_file_name; } - octave::sys::time time_parsed (void) const { return m_t_parsed; } + octave::sys::time time_parsed () const { return m_t_parsed; } - octave::sys::time time_checked (void) const { return m_t_checked; } + octave::sys::time time_checked () const { return m_t_checked; } virtual octave_value find_subfunction (const std::string&) const { return octave_value (); } - virtual std::map subfunctions (void) const; + virtual std::map subfunctions () const; - octave::tree_statement_list * body (void) { return m_cmd_list; } + octave::tree_statement_list * body () { return m_cmd_list; } - octave_value dump (void) const; + octave_value dump () const; protected: - void get_file_info (void); + void get_file_info (); // Our symbol table scope. octave::symbol_scope m_scope; @@ -153,7 +153,7 @@ { public: - octave_user_script (void); + octave_user_script (); octave_user_script (const std::string& fnm, const std::string& nm, const octave::symbol_scope& scope = octave::symbol_scope (), @@ -170,7 +170,7 @@ octave_user_script& operator = (const octave_user_script& f) = delete; - ~octave_user_script (void) = default; + ~octave_user_script () = default; octave_function * function_value (bool = false) { return this; } @@ -181,7 +181,7 @@ // Scripts and user functions are both considered "scripts" because // they are written in Octave's scripting language. - bool is_user_script (void) const { return true; } + bool is_user_script () const { return true; } // We must overload the call method so that we call the proper // push_stack_frame method, which is overloaded for pointers to @@ -221,7 +221,7 @@ octave_user_function& operator = (const octave_user_function& fcn) = delete; - ~octave_user_function (void); + ~octave_user_function (); octave_function * function_value (bool = false) { return this; } @@ -239,8 +239,8 @@ m_location_column = col; } - int beginning_line (void) const { return m_location_line; } - int beginning_column (void) const { return m_location_column; } + int beginning_line () const { return m_location_line; } + int beginning_column () const { return m_location_column; } void stash_fcn_end_location (int line, int col) { @@ -248,10 +248,10 @@ m_end_location_column = col; } - int ending_line (void) const { return m_end_location_line; } - int ending_column (void) const { return m_end_location_column; } + int ending_line () const { return m_end_location_line; } + int ending_column () const { return m_end_location_column; } - void maybe_relocate_end (void); + void maybe_relocate_end (); void stash_parent_fcn_scope (const octave::symbol_scope& ps); @@ -259,68 +259,68 @@ void stash_trailing_comment (octave::comment_list *tc) { m_trail_comm = tc; } - std::string profiler_name (void) const; + std::string profiler_name () const; - std::string parent_fcn_name (void) const + std::string parent_fcn_name () const { octave::symbol_scope pscope = parent_fcn_scope (); return pscope.fcn_name (); } - octave::symbol_scope parent_fcn_scope (void) const + octave::symbol_scope parent_fcn_scope () const { return m_scope.parent_scope (); } - std::list parent_fcn_names (void) const + std::list parent_fcn_names () const { return m_scope.parent_fcn_names (); } - void mark_as_system_fcn_file (void); + void mark_as_system_fcn_file (); - bool is_system_fcn_file (void) const { return m_system_fcn_file; } + bool is_system_fcn_file () const { return m_system_fcn_file; } - bool is_user_function (void) const { return true; } + bool is_user_function () const { return true; } - void erase_subfunctions (void); + void erase_subfunctions (); - bool takes_varargs (void) const; + bool takes_varargs () const; - bool takes_var_return (void) const; + bool takes_var_return () const; void mark_as_private_function (const std::string& cname = ""); - void lock_subfunctions (void); + void lock_subfunctions (); - void unlock_subfunctions (void); + void unlock_subfunctions (); - std::map subfunctions (void) const; + std::map subfunctions () const; octave_value find_subfunction (const std::string& subfuns) const; - bool has_subfunctions (void) const; + bool has_subfunctions () const; void stash_subfunction_names (const std::list& names); - std::list subfunction_names (void) const; + std::list subfunction_names () const; octave_value_list all_va_args (const octave_value_list& args); void stash_function_name (const std::string& s) { m_name = s; } - void mark_as_subfunction (void) { m_subfunction = true; } + void mark_as_subfunction () { m_subfunction = true; } - bool is_subfunction (void) const { return m_subfunction; } + bool is_subfunction () const { return m_subfunction; } - void mark_as_inline_function (void) { m_inline_function = true; } + void mark_as_inline_function () { m_inline_function = true; } - bool is_inline_function (void) const { return m_inline_function; } + bool is_inline_function () const { return m_inline_function; } - void mark_as_anonymous_function (void) { m_anonymous_function = true; } + void mark_as_anonymous_function () { m_anonymous_function = true; } - bool is_anonymous_function (void) const { return m_anonymous_function; } + bool is_anonymous_function () const { return m_anonymous_function; } bool is_anonymous_function_of_class (const std::string& cname = "") const @@ -335,18 +335,18 @@ // If we are a special expression, then the function body consists of exactly // one expression. The expression's result is the return value of the // function. - bool is_special_expr (void) const + bool is_special_expr () const { return is_inline_function () || is_anonymous_function (); } - void mark_as_nested_function (void) { m_nested_function = true; } + void mark_as_nested_function () { m_nested_function = true; } - bool is_nested_function (void) const { return m_nested_function; } + bool is_nested_function () const { return m_nested_function; } - bool is_parent_function (void) const { return m_scope.is_parent (); } + bool is_parent_function () const { return m_scope.is_parent (); } - void mark_as_legacy_constructor (void) { m_class_constructor = legacy; } + void mark_as_legacy_constructor () { m_class_constructor = legacy; } bool is_legacy_constructor (const std::string& cname = "") const { @@ -354,7 +354,7 @@ ? (cname.empty () ? true : cname == dispatch_class ()) : false); } - void mark_as_classdef_constructor (void) { m_class_constructor = classdef; } + void mark_as_classdef_constructor () { m_class_constructor = classdef; } bool is_classdef_constructor (const std::string& cname = "") const { @@ -362,7 +362,7 @@ ? (cname.empty () ? true : cname == dispatch_class ()) : false); } - void mark_as_legacy_method (void) { m_class_method = legacy; } + void mark_as_legacy_method () { m_class_method = legacy; } bool is_legacy_method (const std::string& cname = "") const { @@ -370,7 +370,7 @@ ? (cname.empty () ? true : cname == dispatch_class ()) : false); } - void mark_as_classdef_method (void) { m_class_method = classdef; } + void mark_as_classdef_method () { m_class_method = classdef; } bool is_classdef_method (const std::string& cname = "") const { @@ -391,23 +391,23 @@ execute (octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list ()); - octave::tree_parameter_list * parameter_list (void) { return m_param_list; } + octave::tree_parameter_list * parameter_list () { return m_param_list; } - octave::tree_parameter_list * return_list (void) { return m_ret_list; } + octave::tree_parameter_list * return_list () { return m_ret_list; } - octave::comment_list * leading_comment (void) { return m_lead_comm; } + octave::comment_list * leading_comment () { return m_lead_comm; } - octave::comment_list * trailing_comment (void) { return m_trail_comm; } + octave::comment_list * trailing_comment () { return m_trail_comm; } // If is_special_expr is true, retrieve the sigular expression that forms the // body. May be null (even if is_special_expr is true). - octave::tree_expression * special_expr (void); + octave::tree_expression * special_expr (); - bool subsasgn_optimization_ok (void); + bool subsasgn_optimization_ok (); void accept (octave::tree_walker& tw); - octave_value dump (void) const; + octave_value dump () const; private: @@ -418,8 +418,8 @@ classdef }; - std::string ctor_type_str (void) const; - std::string method_type_str (void) const; + std::string ctor_type_str () const; + std::string method_type_str () const; // List of arguments for this function. These are local variables. octave::tree_parameter_list *m_param_list; @@ -466,7 +466,7 @@ // Enum describing whether this function is a method for a class. class_method_type m_class_method; - void maybe_relocate_end_internal (void); + void maybe_relocate_end_internal (); void print_code_function_header (const std::string& prefix); @@ -475,7 +475,7 @@ // XXX FIXME (public) public: - void restore_warning_states (void); + void restore_warning_states (); DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov.cc --- a/libinterp/octave-value/ov.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov.cc Mon Jan 30 18:36:03 2023 +0100 @@ -118,7 +118,7 @@ // Octave's value type. octave_base_value * -octave_value::nil_rep (void) +octave_value::nil_rep () { static octave_base_value nr; return &nr; @@ -1073,36 +1073,6 @@ maybe_mutate (); } -// Remove when public constructor that uses this function is removed. -octave_base_value * -octave_value::make_range_rep_deprecated (double base, double inc, double limit) -{ -#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - - return dynamic_cast - (new octave_legacy_range (Range (base, inc, limit))); - -#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) -# pragma GCC diagnostic pop -#endif -} - -// Remove when public constructor that uses this function is removed. -octave_base_value * -octave_value::make_range_rep_deprecated (const Range& r, bool force_range) -{ - if (! force_range && ! r.ok ()) - error ("invalid range"); - - if ((force_range || Voptimize_range)) - return dynamic_cast (new octave_legacy_range (r)); - else - return dynamic_cast (new octave_matrix (r.matrix_value ())); -} - octave_value::octave_value (const octave::range& r, bool force_range) : m_rep (force_range || Voptimize_range ? dynamic_cast (new ov_range (r)) @@ -1201,8 +1171,8 @@ : m_rep (force_range || optimize_range ? dynamic_cast (new octave_char_range (r, type)) : dynamic_cast (type == '"' - ? new octave_char_matrix_dq_str (r.array_value ()) - : new octave_char_matrix_sq_str (r.array_value ()))) + ? new octave_char_matrix_dq_str (r.array_value ()) + : new octave_char_matrix_sq_str (r.array_value ()))) #else : m_rep (type == '"' ? new octave_char_matrix_dq_str (r.array_value ()) @@ -1256,7 +1226,7 @@ } octave_base_value * -octave_value::clone (void) const +octave_value::clone () const { return m_rep->clone (); } @@ -1289,7 +1259,7 @@ } void -octave_value::maybe_mutate (void) +octave_value::maybe_mutate () { octave_base_value *tmp = m_rep->try_narrowing_conversion (); @@ -1724,7 +1694,7 @@ // unresolved const issues that prevent that solution from working. std::string -octave_value::get_dims_str (void) const +octave_value::get_dims_str () const { octave_value tmp = *this; @@ -1739,7 +1709,7 @@ } octave_idx_type -octave_value::length (void) const +octave_value::length () const { octave_idx_type retval = 0; @@ -1803,19 +1773,19 @@ } Cell -octave_value::cell_value (void) const +octave_value::cell_value () const { return m_rep->cell_value (); } octave_map -octave_value::map_value (void) const +octave_value::map_value () const { return m_rep->map_value (); } octave_scalar_map -octave_value::scalar_map_value (void) const +octave_value::scalar_map_value () const { return m_rep->scalar_map_value (); } @@ -1857,7 +1827,7 @@ } octave_value_list -octave_value::list_value (void) const +octave_value::list_value () const { return m_rep->list_value (); } @@ -1891,10 +1861,10 @@ ComplexColumnVector octave_value::complex_column_vector_value (bool force_string_conv, - bool frc_vec_conv) const + bool frc_vec_conv) const { return ComplexColumnVector (complex_vector_value (force_string_conv, - frc_vec_conv)); + frc_vec_conv)); } RowVector @@ -1910,7 +1880,7 @@ bool frc_vec_conv) const { return ComplexRowVector (complex_vector_value (force_string_conv, - frc_vec_conv)); + frc_vec_conv)); } Array @@ -1920,8 +1890,8 @@ Array retval = array_value (force_string_conv); return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "real vector")); + force_vector_conversion, + type_name (), "real vector")); } template @@ -1989,8 +1959,8 @@ } return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "integer vector")); + force_vector_conversion, + type_name (), "integer vector")); } template @@ -2008,8 +1978,8 @@ Array octave_value::octave_idx_type_vector_value (bool require_int, - bool force_string_conv, - bool force_vector_conversion) const + bool force_string_conv, + bool force_vector_conversion) const { Array retval; @@ -2059,8 +2029,8 @@ } return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "integer vector")); + force_vector_conversion, + type_name (), "integer vector")); } Array @@ -2070,25 +2040,25 @@ Array retval = complex_array_value (force_string_conv); return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "complex vector")); + force_vector_conversion, + type_name (), "complex vector")); } FloatColumnVector octave_value::float_column_vector_value (bool force_string_conv, - bool frc_vec_conv) const + bool frc_vec_conv) const { return FloatColumnVector (float_vector_value (force_string_conv, - frc_vec_conv)); + frc_vec_conv)); } FloatComplexColumnVector octave_value::float_complex_column_vector_value (bool force_string_conv, - bool frc_vec_conv) const + bool frc_vec_conv) const { return FloatComplexColumnVector (float_complex_vector_value (force_string_conv, - frc_vec_conv)); + frc_vec_conv)); } FloatRowVector @@ -2096,15 +2066,15 @@ bool frc_vec_conv) const { return FloatRowVector (float_vector_value (force_string_conv, - frc_vec_conv)); + frc_vec_conv)); } FloatComplexRowVector octave_value::float_complex_row_vector_value (bool force_string_conv, - bool frc_vec_conv) const + bool frc_vec_conv) const { return FloatComplexRowVector (float_complex_vector_value (force_string_conv, - frc_vec_conv)); + frc_vec_conv)); } Array @@ -2114,19 +2084,19 @@ Array retval = float_array_value (force_string_conv); return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "real vector")); + force_vector_conversion, + type_name (), "real vector")); } Array octave_value::float_complex_vector_value (bool force_string_conv, - bool force_vector_conversion) const + bool force_vector_conversion) const { Array retval = float_complex_array_value (force_string_conv); return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "complex vector")); + force_vector_conversion, + type_name (), "complex vector")); } // NAME can't always be "x ## FCN" because some of the original @@ -2214,8 +2184,7 @@ XVALUE_EXTRACTOR (DiagMatrix, xdiag_matrix_value, diag_matrix_value) XVALUE_EXTRACTOR (FloatDiagMatrix, xfloat_diag_matrix_value, float_diag_matrix_value) XVALUE_EXTRACTOR (ComplexDiagMatrix, xcomplex_diag_matrix_value, complex_diag_matrix_value) -XVALUE_EXTRACTOR (FloatComplexDiagMatrix, xfloat_complex_diag_matrix_value, - float_complex_diag_matrix_value) +XVALUE_EXTRACTOR (FloatComplexDiagMatrix, xfloat_complex_diag_matrix_value, float_complex_diag_matrix_value) XVALUE_EXTRACTOR (PermMatrix, xperm_matrix_value, perm_matrix_value) @@ -2273,16 +2242,13 @@ XVALUE_EXTRACTOR (ComplexRowVector, xcomplex_row_vector_value, complex_row_vector_value) XVALUE_EXTRACTOR (FloatColumnVector, xfloat_column_vector_value, float_column_vector_value) -XVALUE_EXTRACTOR (FloatComplexColumnVector, xfloat_complex_column_vector_value, - float_complex_column_vector_value) +XVALUE_EXTRACTOR (FloatComplexColumnVector, xfloat_complex_column_vector_value, float_complex_column_vector_value) XVALUE_EXTRACTOR (FloatRowVector, xfloat_row_vector_value, float_row_vector_value) -XVALUE_EXTRACTOR (FloatComplexRowVector, xfloat_complex_row_vector_value, - float_complex_row_vector_value) +XVALUE_EXTRACTOR (FloatComplexRowVector, xfloat_complex_row_vector_value, float_complex_row_vector_value) XVALUE_EXTRACTOR (Array, xint_vector_value, int_vector_value) -XVALUE_EXTRACTOR (Array, xoctave_idx_type_vector_value, - octave_idx_type_vector_value) +XVALUE_EXTRACTOR (Array, xoctave_idx_type_vector_value, octave_idx_type_vector_value) XVALUE_EXTRACTOR (Array, xvector_value, vector_value) XVALUE_EXTRACTOR (Array, xcomplex_vector_value, complex_vector_value) @@ -2301,7 +2267,7 @@ #undef XVALUE_EXTRACTOR octave_value -octave_value::storable_value (void) const +octave_value::storable_value () const { octave_value retval = *this; if (isnull ()) @@ -2317,7 +2283,7 @@ } void -octave_value::make_storable_value (void) +octave_value::make_storable_value () { if (isnull ()) { @@ -2340,7 +2306,7 @@ } float_display_format -octave_value::get_edit_display_format (void) const +octave_value::get_edit_display_format () const { return m_rep->get_edit_display_format (); } @@ -2520,7 +2486,7 @@ if (! tmp) err_unary_op_conversion_failed - (octave_value::unary_op_as_string (op), type_name ()); + (octave_value::unary_op_as_string (op), type_name ()); octave_base_value *old_rep = m_rep; m_rep = tmp; @@ -2692,950 +2658,950 @@ OCTAVE_BEGIN_NAMESPACE(octave) -OCTAVE_NORETURN static void -err_binary_op (const std::string& on, const std::string& tn1, - const std::string& tn2) -{ - error ("binary operator '%s' not implemented for '%s' by '%s' operations", - on.c_str (), tn1.c_str (), tn2.c_str ()); -} - -OCTAVE_NORETURN static void -err_binary_op_conv (const std::string& on) -{ - error ("type conversion failed for binary operator '%s'", on.c_str ()); -} - -octave_value -binary_op (type_info& ti, octave_value::binary_op op, - const octave_value& v1, const octave_value& v2) -{ - octave_value retval; - - int t1 = v1.type_id (); - int t2 = v2.type_id (); - - if (t1 == octave_class::static_type_id () - || t2 == octave_class::static_type_id () - || t1 == octave_classdef::static_type_id () - || t2 == octave_classdef::static_type_id ()) - { - type_info::binary_class_op_fcn f = ti.lookup_binary_class_op (op); - - if (! f) - err_binary_op (octave_value::binary_op_as_string (op), - v1.class_name (), v2.class_name ()); - - retval = f (v1, v2); - } - else - { - // FIXME: we need to handle overloading operators for built-in - // classes (double, char, int8, etc.) - - type_info::binary_op_fcn f - = ti.lookup_binary_op (op, t1, t2); - - if (f) - retval = f (v1.get_rep (), v2.get_rep ()); - else - { - octave_value tv1; - octave_base_value::type_conv_info cf1 - = v1.numeric_conversion_function (); - - octave_value tv2; - octave_base_value::type_conv_info cf2 - = v2.numeric_conversion_function (); - - // Try biased (one-sided) conversions first. - if (cf2.type_id () >= 0 - && ti.lookup_binary_op (op, t1, cf2.type_id ())) - cf1 = nullptr; - else if (cf1.type_id () >= 0 - && ti.lookup_binary_op (op, cf1.type_id (), t2)) - cf2 = nullptr; - - if (cf1) - { - octave_base_value *tmp = cf1 (v1.get_rep ()); - - if (! tmp) - err_binary_op_conv (octave_value::binary_op_as_string (op)); - - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - else - tv1 = v1; - - if (cf2) - { - octave_base_value *tmp = cf2 (v2.get_rep ()); - - if (! tmp) - err_binary_op_conv (octave_value::binary_op_as_string (op)); - - tv2 = octave_value (tmp); - t2 = tv2.type_id (); - } - else - tv2 = v2; - - if (cf1 || cf2) - { - retval = binary_op (op, tv1, tv2); - } - else - { - //demote double -> single and try again - cf1 = tv1.numeric_demotion_function (); - - cf2 = tv2.numeric_demotion_function (); - - // Try biased (one-sided) conversions first. - if (cf2.type_id () >= 0 - && ti.lookup_binary_op (op, t1, cf2.type_id ())) - cf1 = nullptr; - else if (cf1.type_id () >= 0 - && ti.lookup_binary_op (op, cf1.type_id (), t2)) - cf2 = nullptr; - - if (cf1) - { - octave_base_value *tmp = cf1 (tv1.get_rep ()); - - if (! tmp) - err_binary_op_conv (octave_value::binary_op_as_string (op)); - - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - - if (cf2) - { - octave_base_value *tmp = cf2 (tv2.get_rep ()); - - if (! tmp) - err_binary_op_conv (octave_value::binary_op_as_string (op)); - - tv2 = octave_value (tmp); - t2 = tv2.type_id (); - } - - if (! cf1 && ! cf2) - err_binary_op (octave_value::binary_op_as_string (op), - v1.type_name (), v2.type_name ()); - - f = ti.lookup_binary_op (op, t1, t2); - - if (! f) - err_binary_op (octave_value::binary_op_as_string (op), - v1.type_name (), v2.type_name ()); - - retval = f (tv1.get_rep (), tv2.get_rep ()); - } - } - } - - return retval; -} - -octave_value -binary_op (octave_value::binary_op op, const octave_value& v1, - const octave_value& v2) -{ - type_info& ti = __get_type_info__ (); - - return binary_op (ti, op, v1, v2); -} - -static octave_value -decompose_binary_op (type_info& ti, octave_value::compound_binary_op op, - const octave_value& v1, const octave_value& v2) -{ - switch (op) - { - case octave_value::op_trans_mul: - return binary_op (octave_value::op_mul, - unary_op (octave_value::op_transpose, v1), v2); - - case octave_value::op_mul_trans: - return binary_op (ti, octave_value::op_mul, - v1, unary_op (octave_value::op_transpose, v2)); - - case octave_value::op_herm_mul: - return binary_op (ti, octave_value::op_mul, - unary_op (octave_value::op_hermitian, v1), v2); - - case octave_value::op_mul_herm: - return binary_op (ti, octave_value::op_mul, - v1, unary_op (octave_value::op_hermitian, v2)); - - case octave_value::op_trans_ldiv: - return binary_op (ti, octave_value::op_ldiv, - unary_op (octave_value::op_transpose, v1), v2); - - case octave_value::op_herm_ldiv: - return binary_op (ti, octave_value::op_ldiv, - unary_op (octave_value::op_hermitian, v1), v2); - - case octave_value::op_el_not_and: - return binary_op (ti, octave_value::op_el_and, - unary_op (octave_value::op_not, v1), v2); - - case octave_value::op_el_not_or: - return binary_op (ti, octave_value::op_el_or, - unary_op (octave_value::op_not, v1), v2); - - case octave_value::op_el_and_not: - return binary_op (ti, octave_value::op_el_and, - v1, unary_op (octave_value::op_not, v2)); - - case octave_value::op_el_or_not: - return binary_op (ti, octave_value::op_el_or, - v1, unary_op (octave_value::op_not, v2)); - - default: - error ("invalid compound operator"); - } -} - -octave_value -binary_op (type_info& ti, octave_value::compound_binary_op op, - const octave_value& v1, const octave_value& v2) -{ - octave_value retval; - - int t1 = v1.type_id (); - int t2 = v2.type_id (); - - if (t1 == octave_class::static_type_id () - || t2 == octave_class::static_type_id () - || t1 == octave_classdef::static_type_id () - || t2 == octave_classdef::static_type_id ()) - { - type_info::binary_class_op_fcn f = ti.lookup_binary_class_op (op); - - if (f) + OCTAVE_NORETURN static void + err_binary_op (const std::string& on, const std::string& tn1, + const std::string& tn2) + { + error ("binary operator '%s' not implemented for '%s' by '%s' operations", + on.c_str (), tn1.c_str (), tn2.c_str ()); + } + + OCTAVE_NORETURN static void + err_binary_op_conv (const std::string& on) + { + error ("type conversion failed for binary operator '%s'", on.c_str ()); + } + + octave_value + binary_op (type_info& ti, octave_value::binary_op op, + const octave_value& v1, const octave_value& v2) + { + octave_value retval; + + int t1 = v1.type_id (); + int t2 = v2.type_id (); + + if (t1 == octave_class::static_type_id () + || t2 == octave_class::static_type_id () + || t1 == octave_classdef::static_type_id () + || t2 == octave_classdef::static_type_id ()) + { + type_info::binary_class_op_fcn f = ti.lookup_binary_class_op (op); + + if (! f) + err_binary_op (octave_value::binary_op_as_string (op), + v1.class_name (), v2.class_name ()); + retval = f (v1, v2); - else - retval = decompose_binary_op (ti, op, v1, v2); - } - else - { - type_info::binary_op_fcn f = ti.lookup_binary_op (op, t1, t2); - - if (f) - retval = f (v1.get_rep (), v2.get_rep ()); - else - retval = decompose_binary_op (ti, op, v1, v2); - } - - return retval; -} - -octave_value -binary_op (octave_value::compound_binary_op op, - const octave_value& v1, const octave_value& v2) -{ - type_info& ti = __get_type_info__ (); - - return binary_op (ti, op, v1, v2); -} - -OCTAVE_NORETURN static void -err_cat_op (const std::string& tn1, const std::string& tn2) -{ - error ("concatenation operator not implemented for '%s' by '%s' operations", - tn1.c_str (), tn2.c_str ()); -} - -OCTAVE_NORETURN static void -err_cat_op_conv (void) -{ - error ("type conversion failed for concatenation operator"); -} - -octave_value -cat_op (type_info& ti, const octave_value& v1, - const octave_value& v2, const Array& ra_idx) -{ - octave_value retval; - - // Can't rapid return for concatenation with an empty object here as - // something like cat(1,[],single([]) must return the correct type. - - int t1 = v1.type_id (); - int t2 = v2.type_id (); - - type_info::cat_op_fcn f = ti.lookup_cat_op (t1, t2); - - if (f) - retval = f (v1.get_rep (), v2.get_rep (), ra_idx); - else - { - octave_value tv1; - octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); - - octave_value tv2; - octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); - - // Try biased (one-sided) conversions first. - if (cf2.type_id () >= 0 && ti.lookup_cat_op (t1, cf2.type_id ())) - cf1 = nullptr; - else if (cf1.type_id () >= 0 && ti.lookup_cat_op (cf1.type_id (), t2)) - cf2 = nullptr; - - if (cf1) - { - octave_base_value *tmp = cf1 (v1.get_rep ()); - - if (! tmp) - err_cat_op_conv (); - - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - else - tv1 = v1; - - if (cf2) - { - octave_base_value *tmp = cf2 (v2.get_rep ()); - - if (! tmp) - err_cat_op_conv (); - - tv2 = octave_value (tmp); - t2 = tv2.type_id (); - } - else - tv2 = v2; - - if (! cf1 && ! cf2) - err_cat_op (v1.type_name (), v2.type_name ()); - - retval = cat_op (ti, tv1, tv2, ra_idx); - } - - return retval; -} - -octave_value -cat_op (const octave_value& v1, const octave_value& v2, - const Array& ra_idx) -{ - type_info& ti = __get_type_info__ (); - - return cat_op (ti, v1, v2, ra_idx); -} - -// Unless the colon operator is used with a class or classdef object, -// then all arguments must be the same type or mixed with double -// values. - -static builtin_type_t -get_colon_op_type (builtin_type_t op1_type, builtin_type_t op2_type) -{ - if (op1_type == op2_type) - return op1_type; - - if (op1_type == btyp_double) - return op2_type; - - if (op2_type == btyp_double) - return op1_type; - - return btyp_unknown; -} - -static builtin_type_t -get_colon_op_type (const octave_value& base, const octave_value& increment, + } + else + { + // FIXME: we need to handle overloading operators for built-in + // classes (double, char, int8, etc.) + + type_info::binary_op_fcn f + = ti.lookup_binary_op (op, t1, t2); + + if (f) + retval = f (v1.get_rep (), v2.get_rep ()); + else + { + octave_value tv1; + octave_base_value::type_conv_info cf1 + = v1.numeric_conversion_function (); + + octave_value tv2; + octave_base_value::type_conv_info cf2 + = v2.numeric_conversion_function (); + + // Try biased (one-sided) conversions first. + if (cf2.type_id () >= 0 + && ti.lookup_binary_op (op, t1, cf2.type_id ())) + cf1 = nullptr; + else if (cf1.type_id () >= 0 + && ti.lookup_binary_op (op, cf1.type_id (), t2)) + cf2 = nullptr; + + if (cf1) + { + octave_base_value *tmp = cf1 (v1.get_rep ()); + + if (! tmp) + err_binary_op_conv (octave_value::binary_op_as_string (op)); + + tv1 = octave_value (tmp); + t1 = tv1.type_id (); + } + else + tv1 = v1; + + if (cf2) + { + octave_base_value *tmp = cf2 (v2.get_rep ()); + + if (! tmp) + err_binary_op_conv (octave_value::binary_op_as_string (op)); + + tv2 = octave_value (tmp); + t2 = tv2.type_id (); + } + else + tv2 = v2; + + if (cf1 || cf2) + { + retval = binary_op (op, tv1, tv2); + } + else + { + //demote double -> single and try again + cf1 = tv1.numeric_demotion_function (); + + cf2 = tv2.numeric_demotion_function (); + + // Try biased (one-sided) conversions first. + if (cf2.type_id () >= 0 + && ti.lookup_binary_op (op, t1, cf2.type_id ())) + cf1 = nullptr; + else if (cf1.type_id () >= 0 + && ti.lookup_binary_op (op, cf1.type_id (), t2)) + cf2 = nullptr; + + if (cf1) + { + octave_base_value *tmp = cf1 (tv1.get_rep ()); + + if (! tmp) + err_binary_op_conv (octave_value::binary_op_as_string (op)); + + tv1 = octave_value (tmp); + t1 = tv1.type_id (); + } + + if (cf2) + { + octave_base_value *tmp = cf2 (tv2.get_rep ()); + + if (! tmp) + err_binary_op_conv (octave_value::binary_op_as_string (op)); + + tv2 = octave_value (tmp); + t2 = tv2.type_id (); + } + + if (! cf1 && ! cf2) + err_binary_op (octave_value::binary_op_as_string (op), + v1.type_name (), v2.type_name ()); + + f = ti.lookup_binary_op (op, t1, t2); + + if (! f) + err_binary_op (octave_value::binary_op_as_string (op), + v1.type_name (), v2.type_name ()); + + retval = f (tv1.get_rep (), tv2.get_rep ()); + } + } + } + + return retval; + } + + octave_value + binary_op (octave_value::binary_op op, const octave_value& v1, + const octave_value& v2) + { + type_info& ti = __get_type_info__ (); + + return binary_op (ti, op, v1, v2); + } + + static octave_value + decompose_binary_op (type_info& ti, octave_value::compound_binary_op op, + const octave_value& v1, const octave_value& v2) + { + switch (op) + { + case octave_value::op_trans_mul: + return binary_op (octave_value::op_mul, + unary_op (octave_value::op_transpose, v1), v2); + + case octave_value::op_mul_trans: + return binary_op (ti, octave_value::op_mul, + v1, unary_op (octave_value::op_transpose, v2)); + + case octave_value::op_herm_mul: + return binary_op (ti, octave_value::op_mul, + unary_op (octave_value::op_hermitian, v1), v2); + + case octave_value::op_mul_herm: + return binary_op (ti, octave_value::op_mul, + v1, unary_op (octave_value::op_hermitian, v2)); + + case octave_value::op_trans_ldiv: + return binary_op (ti, octave_value::op_ldiv, + unary_op (octave_value::op_transpose, v1), v2); + + case octave_value::op_herm_ldiv: + return binary_op (ti, octave_value::op_ldiv, + unary_op (octave_value::op_hermitian, v1), v2); + + case octave_value::op_el_not_and: + return binary_op (ti, octave_value::op_el_and, + unary_op (octave_value::op_not, v1), v2); + + case octave_value::op_el_not_or: + return binary_op (ti, octave_value::op_el_or, + unary_op (octave_value::op_not, v1), v2); + + case octave_value::op_el_and_not: + return binary_op (ti, octave_value::op_el_and, + v1, unary_op (octave_value::op_not, v2)); + + case octave_value::op_el_or_not: + return binary_op (ti, octave_value::op_el_or, + v1, unary_op (octave_value::op_not, v2)); + + default: + error ("invalid compound operator"); + } + } + + octave_value + binary_op (type_info& ti, octave_value::compound_binary_op op, + const octave_value& v1, const octave_value& v2) + { + octave_value retval; + + int t1 = v1.type_id (); + int t2 = v2.type_id (); + + if (t1 == octave_class::static_type_id () + || t2 == octave_class::static_type_id () + || t1 == octave_classdef::static_type_id () + || t2 == octave_classdef::static_type_id ()) + { + type_info::binary_class_op_fcn f = ti.lookup_binary_class_op (op); + + if (f) + retval = f (v1, v2); + else + retval = decompose_binary_op (ti, op, v1, v2); + } + else + { + type_info::binary_op_fcn f = ti.lookup_binary_op (op, t1, t2); + + if (f) + retval = f (v1.get_rep (), v2.get_rep ()); + else + retval = decompose_binary_op (ti, op, v1, v2); + } + + return retval; + } + + octave_value + binary_op (octave_value::compound_binary_op op, + const octave_value& v1, const octave_value& v2) + { + type_info& ti = __get_type_info__ (); + + return binary_op (ti, op, v1, v2); + } + + OCTAVE_NORETURN static void + err_cat_op (const std::string& tn1, const std::string& tn2) + { + error ("concatenation operator not implemented for '%s' by '%s' operations", + tn1.c_str (), tn2.c_str ()); + } + + OCTAVE_NORETURN static void + err_cat_op_conv () + { + error ("type conversion failed for concatenation operator"); + } + + octave_value + cat_op (type_info& ti, const octave_value& v1, + const octave_value& v2, const Array& ra_idx) + { + octave_value retval; + + // Can't rapid return for concatenation with an empty object here as + // something like cat(1,[],single([]) must return the correct type. + + int t1 = v1.type_id (); + int t2 = v2.type_id (); + + type_info::cat_op_fcn f = ti.lookup_cat_op (t1, t2); + + if (f) + retval = f (v1.get_rep (), v2.get_rep (), ra_idx); + else + { + octave_value tv1; + octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); + + octave_value tv2; + octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); + + // Try biased (one-sided) conversions first. + if (cf2.type_id () >= 0 && ti.lookup_cat_op (t1, cf2.type_id ())) + cf1 = nullptr; + else if (cf1.type_id () >= 0 && ti.lookup_cat_op (cf1.type_id (), t2)) + cf2 = nullptr; + + if (cf1) + { + octave_base_value *tmp = cf1 (v1.get_rep ()); + + if (! tmp) + err_cat_op_conv (); + + tv1 = octave_value (tmp); + t1 = tv1.type_id (); + } + else + tv1 = v1; + + if (cf2) + { + octave_base_value *tmp = cf2 (v2.get_rep ()); + + if (! tmp) + err_cat_op_conv (); + + tv2 = octave_value (tmp); + t2 = tv2.type_id (); + } + else + tv2 = v2; + + if (! cf1 && ! cf2) + err_cat_op (v1.type_name (), v2.type_name ()); + + retval = cat_op (ti, tv1, tv2, ra_idx); + } + + return retval; + } + + octave_value + cat_op (const octave_value& v1, const octave_value& v2, + const Array& ra_idx) + { + type_info& ti = __get_type_info__ (); + + return cat_op (ti, v1, v2, ra_idx); + } + + // Unless the colon operator is used with a class or classdef object, + // then all arguments must be the same type or mixed with double + // values. + + static builtin_type_t + get_colon_op_type (builtin_type_t op1_type, builtin_type_t op2_type) + { + if (op1_type == op2_type) + return op1_type; + + if (op1_type == btyp_double) + return op2_type; + + if (op2_type == btyp_double) + return op1_type; + + return btyp_unknown; + } + + static builtin_type_t + get_colon_op_type (const octave_value& base, const octave_value& increment, + const octave_value& limit) + { + builtin_type_t typ + = get_colon_op_type (base.builtin_type (), increment.builtin_type ()); + + if (typ == btyp_unknown) + return typ; + + return get_colon_op_type (typ, limit.builtin_type ()); + } + + // This check depends on the type of VAL either being the expected + // integer type or a double value. + + template + static void + check_colon_operand (const octave_value& val, const char *op_str) + { + if (! val.is_double_type ()) + return; + + double dval = val.double_value (); + double intpart; + static const double out_of_range_top + = static_cast (std::numeric_limits::max ()) + + 1.; + + if (dval >= out_of_range_top + || dval < std::numeric_limits::min () + || std::modf (dval, &intpart) != 0.0) + error ("colon operator %s invalid (not an integer or out of range for given integer type)", op_str); + } + + // Return the difference between two unsigned integers as an unsigned + // integer of the same type. + + template ::value + && std::is_unsigned::value), + bool>::type = true> + UT + integer_difference (UT a, UT b) + { + return a > b ? a - b : b - a; + } + + // Return the difference between two signed integers as an unsigned + // integer corresponding to the signed type. + + template ::type, + typename std::enable_if<(std::is_integral::value + && std::is_signed::value), + bool>::type = true> + UT + integer_difference (ST a, ST b) + { + // Map to unsigned. + // Idea from https://stackoverflow.com/questions/10589559 + + static const UT offset + = UT (0) - static_cast (std::numeric_limits::min ()); + + UT au = static_cast (a) + offset; + UT bu = static_cast (b) + offset; + + return integer_difference (au, bu); + } + + // Number of elements in an integer range taking care to avoid + // overflow. Base and limit are of the same type. If they are + // unsigned, then increment is also of the same type. If they are + // signed, then the type of increment is the unsigned type + // corresponding to T. Assumes that the base and limit values are + // consistent with the sign of the original increment (not an empty + // range) so we can calculate numel with the absolute value of the + // increment and the absolute difference between the base and limit + // values. + + template ::type, + typename std::enable_if::value, + bool>::type = true> + octave_idx_type + range_numel_aux (T base, UT unsigned_increment, T limit) + { + // Adding one to DIFF/INCREMENT may overflow, so check whether it is + // out of range before adding. + + UT nel_m1 = integer_difference (limit, base) / unsigned_increment; + + // FIXME: fix error message. + if (nel_m1 > std::numeric_limits::max () - 1) + error ("too many elements for range!"); + + return static_cast (nel_m1) + 1; + } + + // Convert signed range increment to unsigned. + + template ::type, + typename std::enable_if<(std::is_integral::value + && std::is_signed::value), + bool>::type = true> + UT + range_increment (ST increment) + { + return (increment < 0 + ? UT (0) - static_cast (increment) + : static_cast (increment)); + } + + // "Convert" unsigned range increment to unsigned. A no-op, but + // needed to provide a consistent interface for other template + // functions. + + template ::type, + typename std::enable_if<(std::is_integral::value + && std::is_unsigned::value), + bool>::type = true> + UT + range_increment (UT increment) + { + return increment; + } + + // Convert double range increment to unsigned. Enable by return type. + + template ::type> + typename std::enable_if<(std::is_integral::value + && std::is_unsigned::value), UT>::type + range_increment (double increment) + { + double abs_increment = std::abs (increment); + + return static_cast (abs_increment); + } + + // Number of elements in an integer range base:increment:limit. Base, + // increment, and limit are of the same signed type. + + template ::value + && std::is_signed::value), + bool>::type = true> + octave_idx_type + range_numel (ST base, ST increment, ST limit) + { + typedef typename std::make_unsigned::type UT; + + if (increment == 0 + || (increment > 0 && base > limit) + || (increment < 0 && base < limit)) + return 0; + + UT unsigned_increment = range_increment (increment); + + return range_numel_aux (base, unsigned_increment, limit); + } + + // Number of elements in an integer range base:increment:limit. Base, + // increment, and limit are unsigned and of the same type. + + template ::value + && std::is_unsigned::value), + bool>::type = true> + octave_idx_type + range_numel (UT base, UT increment, UT limit) + { + // Unsigned, INCREMENT is always >= 0. + if (increment == 0 || base > limit) + return 0; + + return range_numel_aux (base, increment, limit); + } + + // Number of elements in an integer range base:increment:limit. Base + // and limit are of the same type and increment is a double value. + + template ::type, + typename std::enable_if::value, + bool>::type = true> + octave_idx_type + range_numel (T base, double increment, T limit) + { + double intpart; + if (math::isnan (increment) || std::modf (increment, &intpart) != 0.0) + error ("colon operator increment invalid (not an integer)"); + + if (increment == 0 + || (increment > 0 && base > limit) + || (increment < 0 && base < limit)) + return 0; + + static const double out_of_range_top + = static_cast (std::numeric_limits::max ()) + 1.; + + double abs_increment = std::abs (increment); + + // Technically, this condition should be + // `abs_increment > std::numeric_limits::max ()`. + // But intmax('uint64') is not representable exactly as floating point + // number. Instead, it "rounds" up by 1 to 2^64. To account for + // this, use the following expression which works for all unsigned + // integer types. + if (abs_increment >= out_of_range_top) + return 1; + + UT unsigned_increment = range_increment (increment); + + return range_numel_aux (base, unsigned_increment, limit); + } + + // Make a range from integer values. Increment may be integer or double. + + template ::value + && std::is_arithmetic::value), + bool>::type = true> + octave_value + make_int_range (T base, IT increment, T limit) + { + octave_idx_type nel = range_numel (base, increment, limit); + + // For now, we create arrays instead of range for all types + // except double. + + Array> result (dim_vector (1, nel)); + + if (nel > 0) + { + typedef typename std::make_unsigned::type UT; + + UT unsigned_increment = range_increment (increment); + + T val = base; + result.xelem (0) = val; + + if (limit > base) + { + for (octave_idx_type i = 1; i < nel; i++) + { + val += unsigned_increment; + result.xelem (i) = val; + } + } + else + { + for (octave_idx_type i = 1; i < nel; i++) + { + val -= unsigned_increment; + result.xelem (i) = val; + } + } + } + + return octave_value (result); + } + + // Make a range from floating point values. + + // FIXME: Try again to define memory efficient range classes for + // integer and floating point values? Maybe with the templates + // defined in this file we could do that in a reasonable way? + // Regardless of that, it might be good to provide special treatment + // of colon expressions in FOR loops so that we can eliminate the + // "is_for_cmd_expr / force_range" flag from the parser and the + // octave_value constructors for range objects. + + // NOTE: We define this function separately for float and double so + // that we can avoid having to instantiate ov_range. We DO + // instantiate range but only so we can take advantage of the + // range class to generate the corresponding array of float values + // and not have to duplicate that code here. + + template ::value, + bool>::type = true> + octave_value + make_float_range (T base, T increment, T limit, bool is_for_cmd_expr) + { + if (math::isnan (base) + || math::isnan (increment) + || math::isnan (limit)) + return octave_value (numeric_limits::NaN ()); + + if (increment == 0 + || (increment > 0 && base > limit) + || (increment < 0 && base < limit)) + return octave_value (Array (dim_vector (1, 0))); + + // At this point, we know that the base and limit values are + // consistent with the sign of the increment (not an empty range). + + range r (base, increment, limit); + + if (! is_for_cmd_expr && ! r.is_storable ()) + error ("range with infinite number of elements cannot be stored"); + + return octave_value (r, is_for_cmd_expr); + } + + template ::value, + bool>::type = true> + octave_value + make_float_range (T base, T increment, T limit, bool is_for_cmd_expr) + { + if (math::isnan (base) + || math::isnan (increment) + || math::isnan (limit)) + return octave_value (numeric_limits::NaN ()); + + if (increment == 0 + || (increment > 0 && base > limit) + || (increment < 0 && base < limit)) + return octave_value (Array (dim_vector (1, 0))); + + // At this point, we know that the base and limit values are + // consistent with the sign of the increment (not an empty range). + + range r (base, increment, limit); + + if (! is_for_cmd_expr && ! r.is_storable ()) + error ("range with infinite number of elements cannot be stored"); + + return octave_value (r.array_value ()); + } + + template ::value + || std::is_same::value + || std::is_same::value + || std::is_same::value + || std::is_same::value + || std::is_same::value + || std::is_same::value + || std::is_same::value), + bool>::type = true> + octave_value + make_int_range (const octave_value& base, const octave_value& increment, + const octave_value& limit) + { + if (base.isempty () || increment.isempty () || limit.isempty ()) + return octave_value (Array (dim_vector (1, 0))); + + check_colon_operand (base, "lower bound"); + check_colon_operand (limit, "upper bound"); + + typename T::val_type base_val = octave_value_extract (base).value (); + typename T::val_type limit_val = octave_value_extract (limit).value (); + + if (increment.is_double_type ()) + { + double increment_val = increment.double_value (); + + return make_int_range (base_val, increment_val, limit_val); + } + + check_colon_operand (increment, "increment"); + + typename T::val_type increment_val + = octave_value_extract (increment).value (); + + return make_int_range (base_val, increment_val, limit_val); + } + + template ::value, + bool>::type = true> + octave_value + make_float_range (const octave_value& base, const octave_value& increment, + const octave_value& limit, bool is_for_cmd_expr) + { + if (base.isempty () || increment.isempty () || limit.isempty ()) + return octave_value (Array (dim_vector (1, 0))); + + T base_val = octave_value_extract (base); + T increment_val = octave_value_extract (increment); + T limit_val = octave_value_extract (limit); + + return make_float_range (base_val, increment_val, limit_val, + is_for_cmd_expr); + } + + + octave_value + make_char_range (const octave_value& base, const octave_value& increment, const octave_value& limit) -{ - builtin_type_t typ - = get_colon_op_type (base.builtin_type (), increment.builtin_type ()); - - if (typ == btyp_unknown) - return typ; - - return get_colon_op_type (typ, limit.builtin_type ()); -} - -// This check depends on the type of VAL either being the expected -// integer type or a double value. - -template -static void -check_colon_operand (const octave_value& val, const char *op_str) -{ - if (! val.is_double_type ()) - return; - - double dval = val.double_value (); - double intpart; - static const double out_of_range_top - = static_cast (std::numeric_limits::max ()) - + 1.; - - if (dval >= out_of_range_top - || dval < std::numeric_limits::min () - || std::modf (dval, &intpart) != 0.0) - error ("colon operator %s invalid (not an integer or out of range for given integer type)", op_str); -} - -// Return the difference between two unsigned integers as an unsigned -// integer of the same type. - -template ::value - && std::is_unsigned::value), - bool>::type = true> -UT -integer_difference (UT a, UT b) -{ - return a > b ? a - b : b - a; -} - -// Return the difference between two signed integers as an unsigned -// integer corresponding to the signed type. - -template ::type, - typename std::enable_if<(std::is_integral::value - && std::is_signed::value), - bool>::type = true> -UT -integer_difference (ST a, ST b) -{ - // Map to unsigned. - // Idea from https://stackoverflow.com/questions/10589559 - - static const UT offset - = UT (0) - static_cast (std::numeric_limits::min ()); - - UT au = static_cast (a) + offset; - UT bu = static_cast (b) + offset; - - return integer_difference (au, bu); -} - -// Number of elements in an integer range taking care to avoid -// overflow. Base and limit are of the same type. If they are -// unsigned, then increment is also of the same type. If they are -// signed, then the type of increment is the unsigned type -// corresponding to T. Assumes that the base and limit values are -// consistent with the sign of the original increment (not an empty -// range) so we can calculate numel with the absolute value of the -// increment and the absolute difference between the base and limit -// values. - -template ::type, - typename std::enable_if::value, - bool>::type = true> -octave_idx_type -range_numel_aux (T base, UT unsigned_increment, T limit) -{ - // Adding one to DIFF/INCREMENT may overflow, so check whether it is - // out of range before adding. - - UT nel_m1 = integer_difference (limit, base) / unsigned_increment; - - // FIXME: fix error message. - if (nel_m1 > std::numeric_limits::max () - 1) - error ("too many elements for range!"); - - return static_cast (nel_m1) + 1; -} - -// Convert signed range increment to unsigned. - -template ::type, - typename std::enable_if<(std::is_integral::value - && std::is_signed::value), - bool>::type = true> -UT -range_increment (ST increment) -{ - return (increment < 0 - ? UT (0) - static_cast (increment) - : static_cast (increment)); -} - -// "Convert" unsigned range increment to unsigned. A no-op, but -// needed to provide a consistent interface for other template -// functions. - -template ::type, - typename std::enable_if<(std::is_integral::value - && std::is_unsigned::value), - bool>::type = true> -UT -range_increment (UT increment) -{ - return increment; -} - -// Convert double range increment to unsigned. Enable by return type. - -template ::type> -typename std::enable_if<(std::is_integral::value - && std::is_unsigned::value), UT>::type -range_increment (double increment) -{ - double abs_increment = std::abs (increment); - - return static_cast (abs_increment); -} - -// Number of elements in an integer range base:increment:limit. Base, -// increment, and limit are of the same signed type. - -template ::value - && std::is_signed::value), - bool>::type = true> -octave_idx_type -range_numel (ST base, ST increment, ST limit) -{ - typedef typename std::make_unsigned::type UT; - - if (increment == 0 - || (increment > 0 && base > limit) - || (increment < 0 && base < limit)) - return 0; - - UT unsigned_increment = range_increment (increment); - - return range_numel_aux (base, unsigned_increment, limit); -} - -// Number of elements in an integer range base:increment:limit. Base, -// increment, and limit are unsigned and of the same type. - -template ::value - && std::is_unsigned::value), - bool>::type = true> -octave_idx_type -range_numel (UT base, UT increment, UT limit) -{ - // Unsigned, INCREMENT is always >= 0. - if (increment == 0 || base > limit) - return 0; - - return range_numel_aux (base, increment, limit); -} - -// Number of elements in an integer range base:increment:limit. Base -// and limit are of the same type and increment is a double value. - -template ::type, - typename std::enable_if::value, - bool>::type = true> -octave_idx_type -range_numel (T base, double increment, T limit) -{ - double intpart; - if (math::isnan (increment) || std::modf (increment, &intpart) != 0.0) - error ("colon operator increment invalid (not an integer)"); - - if (increment == 0 - || (increment > 0 && base > limit) - || (increment < 0 && base < limit)) - return 0; - - static const double out_of_range_top - = static_cast (std::numeric_limits::max ()) + 1.; - - double abs_increment = std::abs (increment); - - // Technically, this condition should be - // `abs_increment > std::numeric_limits::max ()`. - // But intmax('uint64') is not representable exactly as floating point - // number. Instead, it "rounds" up by 1 to 2^64. To account for - // this, use the following expression which works for all unsigned - // integer types. - if (abs_increment >= out_of_range_top) - return 1; - - UT unsigned_increment = range_increment (increment); - - return range_numel_aux (base, unsigned_increment, limit); -} - -// Make a range from integer values. Increment may be integer or double. - -template ::value - && std::is_arithmetic::value), - bool>::type = true> -octave_value -make_int_range (T base, IT increment, T limit) -{ - octave_idx_type nel = range_numel (base, increment, limit); - - // For now, we create arrays instead of range for all types - // except double. - - Array> result (dim_vector (1, nel)); - - if (nel > 0) - { - typedef typename std::make_unsigned::type UT; - - UT unsigned_increment = range_increment (increment); - - T val = base; - result.xelem (0) = val; - - if (limit > base) - { - for (octave_idx_type i = 1; i < nel; i++) - { - val += unsigned_increment; - result.xelem (i) = val; - } - } - else - { - for (octave_idx_type i = 1; i < nel; i++) - { - val -= unsigned_increment; - result.xelem (i) = val; - } - } - } - - return octave_value (result); -} - -// Make a range from floating point values. - -// FIXME: Try again to define memory efficient range classes for -// integer and floating point values? Maybe with the templates -// defined in this file we could do that in a reasonable way? -// Regardless of that, it might be good to provide special treatment -// of colon expressions in FOR loops so that we can eliminate the -// "is_for_cmd_expr / force_range" flag from the parser and the -// octave_value constructors for range objects. - -// NOTE: We define this function separately for float and double so -// that we can avoid having to instantiate ov_range. We DO -// instantiate range but only so we can take advantage of the -// range class to generate the corresponding array of float values -// and not have to duplicate that code here. - -template ::value, - bool>::type = true> -octave_value -make_float_range (T base, T increment, T limit, bool is_for_cmd_expr) -{ - if (math::isnan (base) - || math::isnan (increment) - || math::isnan (limit)) - return octave_value (numeric_limits::NaN ()); - - if (increment == 0 - || (increment > 0 && base > limit) - || (increment < 0 && base < limit)) - return octave_value (Array (dim_vector (1, 0))); - - // At this point, we know that the base and limit values are - // consistent with the sign of the increment (not an empty range). - - range r (base, increment, limit); - - if (! is_for_cmd_expr && ! r.is_storable ()) - error ("range with infinite number of elements cannot be stored"); - - return octave_value (r, is_for_cmd_expr); -} - -template ::value, - bool>::type = true> -octave_value -make_float_range (T base, T increment, T limit, bool is_for_cmd_expr) -{ - if (math::isnan (base) - || math::isnan (increment) - || math::isnan (limit)) - return octave_value (numeric_limits::NaN ()); - - if (increment == 0 - || (increment > 0 && base > limit) - || (increment < 0 && base < limit)) - return octave_value (Array (dim_vector (1, 0))); - - // At this point, we know that the base and limit values are - // consistent with the sign of the increment (not an empty range). - - range r (base, increment, limit); - - if (! is_for_cmd_expr && ! r.is_storable ()) - error ("range with infinite number of elements cannot be stored"); - - return octave_value (r.array_value ()); -} - -template ::value - || std::is_same::value - || std::is_same::value - || std::is_same::value - || std::is_same::value - || std::is_same::value - || std::is_same::value - || std::is_same::value), - bool>::type = true> -octave_value -make_int_range (const octave_value& base, const octave_value& increment, - const octave_value& limit) -{ - if (base.isempty () || increment.isempty () || limit.isempty ()) - return octave_value (Array (dim_vector (1, 0))); - - check_colon_operand (base, "lower bound"); - check_colon_operand (limit, "upper bound"); - - typename T::val_type base_val = octave_value_extract (base).value (); - typename T::val_type limit_val = octave_value_extract (limit).value (); - - if (increment.is_double_type ()) - { - double increment_val = increment.double_value (); - - return make_int_range (base_val, increment_val, limit_val); - } - - check_colon_operand (increment, "increment"); - - typename T::val_type increment_val - = octave_value_extract (increment).value (); - - return make_int_range (base_val, increment_val, limit_val); -} - -template ::value, - bool>::type = true> -octave_value -make_float_range (const octave_value& base, const octave_value& increment, - const octave_value& limit, bool is_for_cmd_expr) -{ - if (base.isempty () || increment.isempty () || limit.isempty ()) - return octave_value (Array (dim_vector (1, 0))); - - T base_val = octave_value_extract (base); - T increment_val = octave_value_extract (increment); - T limit_val = octave_value_extract (limit); - - return make_float_range (base_val, increment_val, limit_val, - is_for_cmd_expr); -} - - -octave_value -make_char_range (const octave_value& base, const octave_value& increment, - const octave_value& limit) -{ - octave_value retval; - - bool dq_str = (base.is_dq_string () || increment.is_dq_string () - || limit.is_dq_string ()); - - char type = dq_str ? '"' : '\''; - - if (base.isempty () || increment.isempty () || limit.isempty ()) - retval = octave_value ("", type); - else - { - Matrix mtx_base = base.matrix_value (true); - Matrix mtx_increment = increment.matrix_value (true); - Matrix mtx_limit = limit.matrix_value (true); - - range tmp (mtx_base(0), mtx_increment(0), mtx_limit(0)); - - retval = octave_value (tmp); - } - - return retval.convert_to_str (false, true, type); -} - -octave_value -colon_op (const octave_value& base, const octave_value& increment_arg, - const octave_value& limit, bool is_for_cmd_expr) -{ - if (base.isobject () || increment_arg.isobject () || limit.isobject ()) - { - octave_value_list tmp1; - - if (increment_arg.is_defined ()) - { - tmp1(2) = limit; - tmp1(1) = increment_arg; - tmp1(0) = base; - } - else - { - tmp1(1) = limit; - tmp1(0) = base; - } - - interpreter& interp = __get_interpreter__ (); - - symbol_table& symtab = interp.get_symbol_table (); - - octave_value fcn = symtab.find_function ("colon", tmp1); - - if (fcn.is_defined ()) - { - octave_value_list tmp2 = interp.feval (fcn, tmp1, 1); - - return tmp2(0); - } - } - - octave_value increment - = increment_arg.is_defined () ? increment_arg : octave_value (1.0); - - if (base.numel () > 1 || limit.numel () > 1 || increment.numel () > 1) - warning_with_id ("Octave:colon-nonscalar-argument", - "colon arguments should be scalars"); - - if (base.iscomplex () || limit.iscomplex () || increment.iscomplex ()) - warning_with_id ("Octave:colon-complex-argument", - "imaginary part of complex colon arguments is ignored"); - - // FIXME: is there a better way to do this job, maybe using type traits? - - builtin_type_t type_id = get_colon_op_type (base, increment, limit); - - // For compatibility with Matlab, don't allow the range used in - // a FOR loop expression to be converted to a Matrix. - - // For now, these functions create arrays instead of range for - // all types except double. - - switch (type_id) - { - case btyp_double: - case btyp_complex: - return make_float_range (base, increment, limit, is_for_cmd_expr); - - case btyp_float: - case btyp_float_complex: - return make_float_range (base, increment, limit, is_for_cmd_expr); - - case btyp_int8: - return make_int_range (base, increment, limit); - - case btyp_int16: - return make_int_range (base, increment, limit); - - case btyp_int32: - return make_int_range (base, increment, limit); - - case btyp_int64: - return make_int_range (base, increment, limit); - - case btyp_uint8: - return make_int_range (base, increment, limit); - - case btyp_uint16: - return make_int_range (base, increment, limit); - - case btyp_uint32: - return make_int_range (base, increment, limit); - - case btyp_uint64: - return make_int_range (base, increment, limit); - - case btyp_char: - return make_char_range (base, increment, limit); - - case btyp_unknown: - error ("incompatible types found in range expression"); - - default: - error ("invalid types found in range expression"); - } - - return octave_value (); -} - -OCTAVE_NORETURN static void -err_unary_op_conv (const std::string& on) -{ - error ("type conversion failed for unary operator '%s'", on.c_str ()); -} - -octave_value -unary_op (type_info& ti, octave_value::unary_op op, - const octave_value& v) -{ - octave_value retval; - - int t = v.type_id (); - - if (t == octave_class::static_type_id () - || t == octave_classdef::static_type_id ()) - { - type_info::unary_class_op_fcn f = ti.lookup_unary_class_op (op); - - if (! f) - err_unary_op (octave_value::unary_op_as_string (op), v.class_name ()); - - retval = f (v); - } - else - { - // FIXME: we need to handle overloading operators for built-in - // classes (double, char, int8, etc.) - - type_info::unary_op_fcn f = ti.lookup_unary_op (op, t); - - if (f) - retval = f (v.get_rep ()); - else - { - octave_value tv; - octave_base_value::type_conv_fcn cf - = v.numeric_conversion_function (); - - if (! cf) - err_unary_op (octave_value::unary_op_as_string (op), - v.type_name ()); - - octave_base_value *tmp = cf (v.get_rep ()); - - if (! tmp) - err_unary_op_conv (octave_value::unary_op_as_string (op)); - - tv = octave_value (tmp); - retval = unary_op (op, tv); - } - } - - return retval; -} - -octave_value -unary_op (octave_value::unary_op op, const octave_value& v) -{ - type_info& ti = __get_type_info__ (); - - return unary_op (ti, op, v); -} + { + octave_value retval; + + bool dq_str = (base.is_dq_string () || increment.is_dq_string () + || limit.is_dq_string ()); + + char type = dq_str ? '"' : '\''; + + if (base.isempty () || increment.isempty () || limit.isempty ()) + retval = octave_value ("", type); + else + { + Matrix mtx_base = base.matrix_value (true); + Matrix mtx_increment = increment.matrix_value (true); + Matrix mtx_limit = limit.matrix_value (true); + + range tmp (mtx_base(0), mtx_increment(0), mtx_limit(0)); + + retval = octave_value (tmp); + } + + return retval.convert_to_str (false, true, type); + } + + octave_value + colon_op (const octave_value& base, const octave_value& increment_arg, + const octave_value& limit, bool is_for_cmd_expr) + { + if (base.isobject () || increment_arg.isobject () || limit.isobject ()) + { + octave_value_list tmp1; + + if (increment_arg.is_defined ()) + { + tmp1(2) = limit; + tmp1(1) = increment_arg; + tmp1(0) = base; + } + else + { + tmp1(1) = limit; + tmp1(0) = base; + } + + interpreter& interp = __get_interpreter__ (); + + symbol_table& symtab = interp.get_symbol_table (); + + octave_value fcn = symtab.find_function ("colon", tmp1); + + if (fcn.is_defined ()) + { + octave_value_list tmp2 = interp.feval (fcn, tmp1, 1); + + return tmp2(0); + } + } + + octave_value increment + = increment_arg.is_defined () ? increment_arg : octave_value (1.0); + + if (base.numel () > 1 || limit.numel () > 1 || increment.numel () > 1) + warning_with_id ("Octave:colon-nonscalar-argument", + "colon arguments should be scalars"); + + if (base.iscomplex () || limit.iscomplex () || increment.iscomplex ()) + warning_with_id ("Octave:colon-complex-argument", + "imaginary part of complex colon arguments is ignored"); + + // FIXME: is there a better way to do this job, maybe using type traits? + + builtin_type_t type_id = get_colon_op_type (base, increment, limit); + + // For compatibility with Matlab, don't allow the range used in + // a FOR loop expression to be converted to a Matrix. + + // For now, these functions create arrays instead of range for + // all types except double. + + switch (type_id) + { + case btyp_double: + case btyp_complex: + return make_float_range (base, increment, limit, is_for_cmd_expr); + + case btyp_float: + case btyp_float_complex: + return make_float_range (base, increment, limit, is_for_cmd_expr); + + case btyp_int8: + return make_int_range (base, increment, limit); + + case btyp_int16: + return make_int_range (base, increment, limit); + + case btyp_int32: + return make_int_range (base, increment, limit); + + case btyp_int64: + return make_int_range (base, increment, limit); + + case btyp_uint8: + return make_int_range (base, increment, limit); + + case btyp_uint16: + return make_int_range (base, increment, limit); + + case btyp_uint32: + return make_int_range (base, increment, limit); + + case btyp_uint64: + return make_int_range (base, increment, limit); + + case btyp_char: + return make_char_range (base, increment, limit); + + case btyp_unknown: + error ("incompatible types found in range expression"); + + default: + error ("invalid types found in range expression"); + } + + return octave_value (); + } + + OCTAVE_NORETURN static void + err_unary_op_conv (const std::string& on) + { + error ("type conversion failed for unary operator '%s'", on.c_str ()); + } + + octave_value + unary_op (type_info& ti, octave_value::unary_op op, + const octave_value& v) + { + octave_value retval; + + int t = v.type_id (); + + if (t == octave_class::static_type_id () + || t == octave_classdef::static_type_id ()) + { + type_info::unary_class_op_fcn f = ti.lookup_unary_class_op (op); + + if (! f) + err_unary_op (octave_value::unary_op_as_string (op), v.class_name ()); + + retval = f (v); + } + else + { + // FIXME: we need to handle overloading operators for built-in + // classes (double, char, int8, etc.) + + type_info::unary_op_fcn f = ti.lookup_unary_op (op, t); + + if (f) + retval = f (v.get_rep ()); + else + { + octave_value tv; + octave_base_value::type_conv_fcn cf + = v.numeric_conversion_function (); + + if (! cf) + err_unary_op (octave_value::unary_op_as_string (op), + v.type_name ()); + + octave_base_value *tmp = cf (v.get_rep ()); + + if (! tmp) + err_unary_op_conv (octave_value::unary_op_as_string (op)); + + tv = octave_value (tmp); + retval = unary_op (op, tv); + } + } + + return retval; + } + + octave_value + unary_op (octave_value::unary_op op, const octave_value& v) + { + type_info& ti = __get_type_info__ (); + + return unary_op (ti, op, v); + } OCTAVE_END_NAMESPACE(octave) @@ -3748,8 +3714,7 @@ std::string& type_string, std::list& idx) { - const octave_map m = - arg.xmap_value ("%s: second argument must be a structure with fields 'type' and 'subs'", name); + const octave_map m = arg.xmap_value ("%s: second argument must be a structure with fields 'type' and 'subs'", name); if (m.nfields () != 2 || ! m.contains ("type") || ! m.contains ("subs")) error ("%s: second argument must be a structure with fields 'type' and 'subs'", diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ov.h --- a/libinterp/octave-value/ov.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ov.h Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,6 @@ #include #include -#include "Range.h" #include "data-conv.h" #include "idx-vector.h" #include "mach-info.h" @@ -167,7 +166,7 @@ enum magic_colon { magic_colon_t }; - octave_value (void) + octave_value () : m_rep (nil_rep ()) { m_rep->count++; @@ -288,34 +287,6 @@ OCTINTERP_API octave_value (const Array& cellstr); OCTINTERP_API octave_value (const octave::idx_vector& idx, bool lazy = true); -private: - - // Remove when public constructors that use this function are removed. - static OCTINTERP_API octave_base_value * - make_range_rep_deprecated (double base, double inc, double limit); - - // Remove when public constructors that use this function are removed. - static OCTINTERP_API octave_base_value * - make_range_rep_deprecated (const Range& r, bool force_range); - -public: - -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "use 'octave_value (range&)' instead") - octave_value (double base, double limit, double inc) - : m_rep (make_range_rep_deprecated (base, inc, limit)) - { - maybe_mutate (); - } - - OCTAVE_DEPRECATED (7, "use 'octave_value (range&)' instead") - octave_value (const Range& r, bool force_range = false) - : m_rep (make_range_rep_deprecated (r, force_range)) - { - maybe_mutate (); - } -#endif - OCTINTERP_API octave_value (const octave::range& r, bool force_range = false); @@ -386,14 +357,14 @@ // This should only be called for derived types. - OCTINTERP_API octave_base_value * clone (void) const; + OCTINTERP_API octave_base_value * clone () const; - octave_base_value * empty_clone (void) const + octave_base_value * empty_clone () const { return m_rep->empty_clone (); } // Delete the representation of this constant if the count drops to zero. - ~octave_value (void) + ~octave_value () { // Because we define a move constructor and a move assignment // operator, rep may be a nullptr here. We should only need to @@ -403,7 +374,7 @@ delete m_rep; } - void make_unique (void) + void make_unique () { if (m_rep->count > 1) { @@ -472,43 +443,43 @@ return *this; } - octave_idx_type get_count (void) const { return m_rep->count; } + octave_idx_type get_count () const { return m_rep->count; } - octave_base_value::type_conv_info numeric_conversion_function (void) const + octave_base_value::type_conv_info numeric_conversion_function () const { return m_rep->numeric_conversion_function (); } - octave_base_value::type_conv_info numeric_demotion_function (void) const + octave_base_value::type_conv_info numeric_demotion_function () const { return m_rep->numeric_demotion_function (); } - OCTINTERP_API void maybe_mutate (void); + OCTINTERP_API void maybe_mutate (); - octave_value squeeze (void) const + octave_value squeeze () const { return m_rep->squeeze (); } // The result of full(). - octave_value full_value (void) const + octave_value full_value () const { return m_rep->full_value (); } // Type conversions. - octave_value as_double (void) const { return m_rep->as_double (); } - octave_value as_single (void) const { return m_rep->as_single (); } + octave_value as_double () const { return m_rep->as_double (); } + octave_value as_single () const { return m_rep->as_single (); } - octave_value as_int8 (void) const { return m_rep->as_int8 (); } - octave_value as_int16 (void) const { return m_rep->as_int16 (); } - octave_value as_int32 (void) const { return m_rep->as_int32 (); } - octave_value as_int64 (void) const { return m_rep->as_int64 (); } + octave_value as_int8 () const { return m_rep->as_int8 (); } + octave_value as_int16 () const { return m_rep->as_int16 (); } + octave_value as_int32 () const { return m_rep->as_int32 (); } + octave_value as_int64 () const { return m_rep->as_int64 (); } - octave_value as_uint8 (void) const { return m_rep->as_uint8 (); } - octave_value as_uint16 (void) const { return m_rep->as_uint16 (); } - octave_value as_uint32 (void) const { return m_rep->as_uint32 (); } - octave_value as_uint64 (void) const { return m_rep->as_uint64 (); } + octave_value as_uint8 () const { return m_rep->as_uint8 (); } + octave_value as_uint16 () const { return m_rep->as_uint16 (); } + octave_value as_uint32 () const { return m_rep->as_uint32 (); } + octave_value as_uint64 () const { return m_rep->as_uint64 (); } - octave_base_value * try_narrowing_conversion (void) + octave_base_value * try_narrowing_conversion () { return m_rep->try_narrowing_conversion (); } // Close to dims (), but can be overloaded for classes. - Matrix size (void) + Matrix size () { return m_rep->size (); } // FIXME: should this function be deprecated and removed? It supports @@ -552,15 +523,6 @@ return m_rep->do_index_op (idx, resize_ok); } -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "use 'octave_value::index_op' instead") - octave_value do_index_op (const octave_value_list& idx, - bool resize_ok = false) - { - return index_op (idx, resize_ok); - } -#endif - OCTINTERP_API octave_value subsasgn (const std::string& type, const std::list& idx, const octave_value& rhs); @@ -583,35 +545,35 @@ // Size. - dim_vector dims (void) const { return m_rep->dims (); } + dim_vector dims () const { return m_rep->dims (); } - OCTINTERP_API std::string get_dims_str (void) const; + OCTINTERP_API std::string get_dims_str () const; - octave_idx_type rows (void) const { return m_rep->rows (); } + octave_idx_type rows () const { return m_rep->rows (); } - octave_idx_type columns (void) const { return m_rep->columns (); } + octave_idx_type columns () const { return m_rep->columns (); } - OCTINTERP_API octave_idx_type length (void) const; + OCTINTERP_API octave_idx_type length () const; - int ndims (void) const { return m_rep->ndims (); } + int ndims () const { return m_rep->ndims (); } - bool all_zero_dims (void) const { return dims ().all_zero (); } + bool all_zero_dims () const { return dims ().all_zero (); } // Are the dimensions of this constant zero by zero? - bool is_zero_by_zero (void) const + bool is_zero_by_zero () const { return (ndims () == 2 && rows () == 0 && columns () == 0); } - octave_idx_type numel (void) const + octave_idx_type numel () const { return m_rep->numel (); } - std::size_t byte_size (void) const + std::size_t byte_size () const { return m_rep->byte_size (); } - octave_idx_type nnz (void) const { return m_rep->nnz (); } + octave_idx_type nnz () const { return m_rep->nnz (); } - octave_idx_type nzmax (void) const { return m_rep->nzmax (); } + octave_idx_type nzmax () const { return m_rep->nzmax (); } - octave_idx_type nfields (void) const { return m_rep->nfields (); } + octave_idx_type nfields () const { return m_rep->nfields (); } octave_value reshape (const dim_vector& dv) const { return m_rep->reshape (dv); } @@ -625,7 +587,7 @@ octave_value resize (const dim_vector& dv, bool fill = false) const { return m_rep->resize (dv, fill);} - MatrixType matrix_type (void) const + MatrixType matrix_type () const { return m_rep->matrix_type (); } MatrixType matrix_type (const MatrixType& typ) const @@ -634,94 +596,94 @@ // Does this constant have a type? Both of these are provided since it is // sometimes more natural to write is_undefined() instead of ! is_defined(). - bool is_defined (void) const + bool is_defined () const { return m_rep->is_defined (); } - bool is_undefined (void) const + bool is_undefined () const { return ! is_defined (); } - bool is_legacy_object (void) const + bool is_legacy_object () const { return m_rep->is_legacy_object (); } - bool isempty (void) const + bool isempty () const { return m_rep->isempty (); } - bool iscell (void) const + bool iscell () const { return m_rep->iscell (); } - bool iscellstr (void) const + bool iscellstr () const { return m_rep->iscellstr (); } - bool is_real_scalar (void) const + bool is_real_scalar () const { return m_rep->is_real_scalar (); } - bool is_real_matrix (void) const + bool is_real_matrix () const { return m_rep->is_real_matrix (); } - bool is_complex_scalar (void) const + bool is_complex_scalar () const { return m_rep->is_complex_scalar (); } - bool is_complex_matrix (void) const + bool is_complex_matrix () const { return m_rep->is_complex_matrix (); } - bool is_bool_scalar (void) const + bool is_bool_scalar () const { return m_rep->is_bool_scalar (); } - bool is_bool_matrix (void) const + bool is_bool_matrix () const { return m_rep->is_bool_matrix (); } - bool is_char_matrix (void) const + bool is_char_matrix () const { return m_rep->is_char_matrix (); } - bool is_diag_matrix (void) const + bool is_diag_matrix () const { return m_rep->is_diag_matrix (); } - bool is_perm_matrix (void) const + bool is_perm_matrix () const { return m_rep->is_perm_matrix (); } - bool is_string (void) const + bool is_string () const { return m_rep->is_string (); } - bool is_sq_string (void) const + bool is_sq_string () const { return m_rep->is_sq_string (); } - bool is_dq_string (void) const + bool is_dq_string () const { return m_rep->is_string () && ! m_rep->is_sq_string (); } - bool is_range (void) const + bool is_range () const { return m_rep->is_range (); } - bool isstruct (void) const + bool isstruct () const { return m_rep->isstruct (); } - bool is_classdef_meta (void) const + bool is_classdef_meta () const { return m_rep->is_classdef_meta (); } - bool is_classdef_object (void) const + bool is_classdef_object () const { return m_rep->is_classdef_object (); } - bool is_classdef_superclass_ref (void) const + bool is_classdef_superclass_ref () const { return m_rep->is_classdef_superclass_ref (); } - bool is_package (void) const + bool is_package () const { return m_rep->is_package (); } - bool isobject (void) const + bool isobject () const { return m_rep->isobject (); } - bool isjava (void) const + bool isjava () const { return m_rep->isjava (); } - bool is_cs_list (void) const + bool is_cs_list () const { return m_rep->is_cs_list (); } - bool is_magic_colon (void) const + bool is_magic_colon () const { return m_rep->is_magic_colon (); } - bool is_magic_int (void) const + bool is_magic_int () const { return m_rep->is_magic_int (); } - bool isnull (void) const + bool isnull () const { return m_rep->isnull (); } // Are any or all of the elements in this constant nonzero? @@ -732,119 +694,119 @@ octave_value any (int dim = 0) const { return m_rep->any (dim); } - builtin_type_t builtin_type (void) const + builtin_type_t builtin_type () const { return m_rep->builtin_type (); } // Floating point types. - bool is_double_type (void) const + bool is_double_type () const { return m_rep->is_double_type (); } - bool is_single_type (void) const + bool is_single_type () const { return m_rep->is_single_type (); } - bool isfloat (void) const + bool isfloat () const { return m_rep->isfloat (); } // Integer types. - bool is_int8_type (void) const + bool is_int8_type () const { return m_rep->is_int8_type (); } - bool is_int16_type (void) const + bool is_int16_type () const { return m_rep->is_int16_type (); } - bool is_int32_type (void) const + bool is_int32_type () const { return m_rep->is_int32_type (); } - bool is_int64_type (void) const + bool is_int64_type () const { return m_rep->is_int64_type (); } - bool is_uint8_type (void) const + bool is_uint8_type () const { return m_rep->is_uint8_type (); } - bool is_uint16_type (void) const + bool is_uint16_type () const { return m_rep->is_uint16_type (); } - bool is_uint32_type (void) const + bool is_uint32_type () const { return m_rep->is_uint32_type (); } - bool is_uint64_type (void) const + bool is_uint64_type () const { return m_rep->is_uint64_type (); } - bool isinteger (void) const + bool isinteger () const { return m_rep->isinteger (); } // Other type stuff. - bool islogical (void) const + bool islogical () const { return m_rep->islogical (); } - bool isreal (void) const + bool isreal () const { return m_rep->isreal (); } - bool iscomplex (void) const + bool iscomplex () const { return m_rep->iscomplex (); } - bool is_scalar_type (void) const + bool is_scalar_type () const { return m_rep->is_scalar_type (); } - bool is_matrix_type (void) const + bool is_matrix_type () const { return m_rep->is_matrix_type (); } - bool isnumeric (void) const + bool isnumeric () const { return m_rep->isnumeric (); } - bool issparse (void) const + bool issparse () const { return m_rep->issparse (); } // Does this constant correspond to a truth value? - bool is_true (void) const + bool is_true () const { return m_rep->is_true (); } // Do two constants match (in a switch statement)? bool is_equal (const octave_value&) const; - bool is_constant (void) const + bool is_constant () const { return m_rep->is_constant (); } - bool is_function_handle (void) const + bool is_function_handle () const { return m_rep->is_function_handle (); } - bool is_anonymous_function (void) const + bool is_anonymous_function () const { return m_rep->is_anonymous_function (); } - bool is_inline_function (void) const + bool is_inline_function () const { return m_rep->is_inline_function (); } - bool is_function (void) const + bool is_function () const { return m_rep->is_function (); } - bool is_user_script (void) const + bool is_user_script () const { return m_rep->is_user_script (); } - bool is_user_function (void) const + bool is_user_function () const { return m_rep->is_user_function (); } - bool is_user_code (void) const + bool is_user_code () const { return m_rep->is_user_code (); } - bool is_builtin_function (void) const + bool is_builtin_function () const { return m_rep->is_builtin_function (); } - bool is_dld_function (void) const + bool is_dld_function () const { return m_rep->is_dld_function (); } - bool is_mex_function (void) const + bool is_mex_function () const { return m_rep->is_mex_function (); } - void erase_subfunctions (void) { m_rep->erase_subfunctions (); } + void erase_subfunctions () { m_rep->erase_subfunctions (); } // Values. - octave_value eval (void) { return *this; } + octave_value eval () { return *this; } short int short_value (bool req_int = false, bool frc_str_conv = false) const @@ -965,55 +927,55 @@ float_complex_diag_matrix_value (bool force = false) const { return m_rep->float_complex_diag_matrix_value (force); } - PermMatrix perm_matrix_value (void) const + PermMatrix perm_matrix_value () const { return m_rep->perm_matrix_value (); } - octave_int8 int8_scalar_value (void) const + octave_int8 int8_scalar_value () const { return m_rep->int8_scalar_value (); } - octave_int16 int16_scalar_value (void) const + octave_int16 int16_scalar_value () const { return m_rep->int16_scalar_value (); } - octave_int32 int32_scalar_value (void) const + octave_int32 int32_scalar_value () const { return m_rep->int32_scalar_value (); } - octave_int64 int64_scalar_value (void) const + octave_int64 int64_scalar_value () const { return m_rep->int64_scalar_value (); } - octave_uint8 uint8_scalar_value (void) const + octave_uint8 uint8_scalar_value () const { return m_rep->uint8_scalar_value (); } - octave_uint16 uint16_scalar_value (void) const + octave_uint16 uint16_scalar_value () const { return m_rep->uint16_scalar_value (); } - octave_uint32 uint32_scalar_value (void) const + octave_uint32 uint32_scalar_value () const { return m_rep->uint32_scalar_value (); } - octave_uint64 uint64_scalar_value (void) const + octave_uint64 uint64_scalar_value () const { return m_rep->uint64_scalar_value (); } - int8NDArray int8_array_value (void) const + int8NDArray int8_array_value () const { return m_rep->int8_array_value (); } - int16NDArray int16_array_value (void) const + int16NDArray int16_array_value () const { return m_rep->int16_array_value (); } - int32NDArray int32_array_value (void) const + int32NDArray int32_array_value () const { return m_rep->int32_array_value (); } - int64NDArray int64_array_value (void) const + int64NDArray int64_array_value () const { return m_rep->int64_array_value (); } - uint8NDArray uint8_array_value (void) const + uint8NDArray uint8_array_value () const { return m_rep->uint8_array_value (); } - uint16NDArray uint16_array_value (void) const + uint16NDArray uint16_array_value () const { return m_rep->uint16_array_value (); } - uint32NDArray uint32_array_value (void) const + uint32NDArray uint32_array_value () const { return m_rep->uint32_array_value (); } - uint64NDArray uint64_array_value (void) const + uint64NDArray uint64_array_value () const { return m_rep->uint64_array_value (); } std::string string_value (bool force = false) const @@ -1022,64 +984,64 @@ string_vector string_vector_value (bool pad = false) const { return m_rep->string_vector_value (pad); } - Cell cell_value (void) const; + Cell cell_value () const; - Array cellstr_value (void) const + Array cellstr_value () const { return m_rep->cellstr_value (); } - octave::range range_value (void) const + octave::range range_value () const { return m_rep->range_value (); } // For now, disable all but range. #if 0 - octave::range float_range_value (void) const + octave::range float_range_value () const { return m_rep->float_range_value (); } - octave::range int8_range_value (void) const + octave::range int8_range_value () const { return m_rep->int8_range_value (); } - octave::range int16_range_value (void) const + octave::range int16_range_value () const { return m_rep->int16_range_value (); } - octave::range int32_range_value (void) const + octave::range int32_range_value () const { return m_rep->int32_range_value (); } - octave::range int64_range_value (void) const + octave::range int64_range_value () const { return m_rep->int64_range_value (); } - octave::range uint8_range_value (void) const + octave::range uint8_range_value () const { return m_rep->uint8_range_value (); } - octave::range uint16_range_value (void) const + octave::range uint16_range_value () const { return m_rep->uint16_range_value (); } - octave::range uint32_range_value (void) const + octave::range uint32_range_value () const { return m_rep->uint32_range_value (); } - octave::range uint64_range_value (void) const + octave::range uint64_range_value () const { return m_rep->uint64_range_value (); } #endif - OCTINTERP_API octave_map map_value (void) const; + OCTINTERP_API octave_map map_value () const; - OCTINTERP_API octave_scalar_map scalar_map_value (void) const; + OCTINTERP_API octave_scalar_map scalar_map_value () const; - string_vector map_keys (void) const + string_vector map_keys () const { return m_rep->map_keys (); } bool isfield (const std::string& field_name) const { return m_rep->isfield (field_name); } - std::size_t nparents (void) const + std::size_t nparents () const { return m_rep->nparents (); } - std::list parent_class_name_list (void) const + std::list parent_class_name_list () const { return m_rep->parent_class_name_list (); } - string_vector parent_class_names (void) const + string_vector parent_class_names () const { return m_rep->parent_class_names (); } octave_base_value * @@ -1106,7 +1068,7 @@ OCTINTERP_API octave_fcn_handle * fcn_handle_value (bool silent = false) const; - OCTINTERP_API octave_value_list list_value (void) const; + OCTINTERP_API octave_value_list list_value () const; OCTINTERP_API ColumnVector column_vector_value (bool frc_str_conv = false, @@ -1393,19 +1355,19 @@ // Possibly economize a lazy-indexed value. - void maybe_economize (void) + void maybe_economize () { m_rep->maybe_economize (); } // The following two hook conversions are called on any octave_value prior to // storing it to a "permanent" location, like a named variable, a cell or a // struct component, or a return value of a function. - OCTINTERP_API octave_value storable_value (void) const; + OCTINTERP_API octave_value storable_value () const; // Ditto, but in place, i.e., equivalent to *this = this->storable_value (), // but possibly more efficient. - OCTINTERP_API void make_storable_value (void); + OCTINTERP_API void make_storable_value (); // FIXME: These should probably be private. // Conversions. If a user of this class wants a certain kind of constant, @@ -1419,10 +1381,10 @@ convert_to_str_internal (bool pad, bool force, char type) const { return m_rep->convert_to_str_internal (pad, force, type); } - void convert_to_row_or_column_vector (void) + void convert_to_row_or_column_vector () { m_rep->convert_to_row_or_column_vector (); } - bool print_as_scalar (void) const + bool print_as_scalar () const { return m_rep->print_as_scalar (); } void print (std::ostream& os, bool pr_as_read_syntax = false) @@ -1439,7 +1401,7 @@ void short_disp (std::ostream& os) const { m_rep->short_disp (os); } - OCTINTERP_API float_display_format get_edit_display_format (void) const; + OCTINTERP_API float_display_format get_edit_display_format () const; std::string edit_display (const float_display_format& fmt, octave_idx_type i, octave_idx_type j) const @@ -1447,11 +1409,11 @@ return m_rep->edit_display (fmt, i, j); } - int type_id (void) const { return m_rep->type_id (); } + int type_id () const { return m_rep->type_id (); } - std::string type_name (void) const { return m_rep->type_name (); } + std::string type_name () const { return m_rep->type_name (); } - std::string class_name (void) const { return m_rep->class_name (); } + std::string class_name () const { return m_rep->class_name (); } // Unary operations that are member functions. There are also some // non-member functions for unary and binary operations declared @@ -1459,28 +1421,11 @@ OCTINTERP_API octave_value& non_const_unary_op (unary_op op); -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "use 'octave_value::non_const_unary_op' instead") - octave_value& do_non_const_unary_op (unary_op op) - { - return non_const_unary_op (op); - } -#endif - OCTINTERP_API octave_value& non_const_unary_op (unary_op op, const std::string& type, const std::list& idx); -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "use 'octave_value::non_const_unary_op' instead") - octave_value& do_non_const_unary_op (unary_op op, const std::string& type, - const std::list& idx) - { - return non_const_unary_op (op, type, idx); - } -#endif - - const octave_base_value& get_rep (void) const { return *m_rep; } + const octave_base_value& get_rep () const { return *m_rep; } bool is_copy_of (const octave_value& val) const { return m_rep == val.m_rep; } @@ -1508,7 +1453,7 @@ oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const; - octave_base_value * internal_rep (void) const { return m_rep; } + octave_base_value * internal_rep () const { return m_rep; } // These functions exist to support the MEX interface. // You should not use them anywhere else. @@ -1517,13 +1462,13 @@ mex_get_data (mxClassID class_id = mxUNKNOWN_CLASS, mxComplexity complexity = mxREAL) const; - const octave_idx_type * mex_get_ir (void) const + const octave_idx_type * mex_get_ir () const { return m_rep->mex_get_ir (); } const octave_idx_type * - mex_get_jc (void) const + mex_get_jc () const { return m_rep->mex_get_jc (); } @@ -1552,18 +1497,18 @@ sortmode is_sorted_rows (sortmode mode = UNSORTED) const { return m_rep->is_sorted_rows (mode); } - void lock (void) { m_rep->lock (); } + void lock () { m_rep->lock (); } - void unlock (void) { m_rep->unlock (); } + void unlock () { m_rep->unlock (); } - bool islocked (void) const { return m_rep->islocked (); } + bool islocked () const { return m_rep->islocked (); } - void call_object_destructor (void) { return m_rep->call_object_destructor (); } + void call_object_destructor () { return m_rep->call_object_destructor (); } - octave_value dump (void) const { return m_rep->dump (); } + octave_value dump () const { return m_rep->dump (); } #define MAPPER_FORWARD(F) \ - octave_value F (void) const \ + octave_value F () const \ { \ return m_rep->map (octave_base_value::umap_ ## F); \ } @@ -1670,7 +1615,7 @@ private: - static OCTINTERP_API octave_base_value * nil_rep (void); + static OCTINTERP_API octave_base_value * nil_rep (); OCTINTERP_API assign_op unary_op_to_assign_op (unary_op op); @@ -1736,87 +1681,6 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "use 'octave::unary_op' instead") -inline octave_value -do_unary_op (octave::type_info& ti, octave_value::unary_op op, - const octave_value& a) -{ - return octave::unary_op (ti, op, a); -} - -OCTAVE_DEPRECATED (7, "use 'octave::unary_op' instead") -inline octave_value -do_unary_op (octave_value::unary_op op, const octave_value& a) -{ - return octave::unary_op (op, a); -} - -OCTAVE_DEPRECATED (7, "use 'octave::binary_op' instead") -inline octave_value -do_binary_op (octave::type_info& ti, octave_value::binary_op op, - const octave_value& a, const octave_value& b) -{ - return octave::binary_op (ti, op, a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::binary_op' instead") -inline octave_value -do_binary_op (octave::type_info& ti, octave_value::compound_binary_op op, - const octave_value& a, const octave_value& b) -{ - return octave::binary_op (ti, op, a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::binary_op' instead") -inline octave_value -do_binary_op (octave_value::binary_op op, const octave_value& a, - const octave_value& b) -{ - return octave::binary_op (op, a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::binary_op' instead") -inline octave_value -do_binary_op (octave_value::compound_binary_op op, const octave_value& a, - const octave_value& b) -{ - return octave::binary_op (op, a, b); -} - -OCTAVE_DEPRECATED (7, "use 'octave::cat_op' instead") -inline octave_value -do_cat_op (octave::type_info& ti, const octave_value& a, - const octave_value& b, const Array& ra_idx) -{ - return octave::cat_op (ti, a, b, ra_idx); -} - -OCTAVE_DEPRECATED (7, "use 'octave::cat_op' instead") -inline octave_value -do_cat_op (const octave_value& a, const octave_value& b, - const Array& ra_idx) -{ - return octave::cat_op (a, b, ra_idx); -} - -OCTAVE_DEPRECATED (7, "use 'octave::colon_op' instead") -inline octave_value -do_colon_op (const octave_value& base, const octave_value& increment, - const octave_value& limit, bool is_for_cmd_expr = false) -{ - return octave::colon_op (base, increment, limit, is_for_cmd_expr); -} - -OCTAVE_DEPRECATED (7, "use 'octave::colon_op' instead") -inline octave_value -do_colon_op (const octave_value& base, const octave_value& limit, - bool is_for_cmd_expr = false) -{ - return octave::colon_op (base, limit, is_for_cmd_expr); -} -#endif - #define OV_UNOP_FN(name) \ inline octave_value \ name (const octave_value& a) \ diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ovl.cc --- a/libinterp/octave-value/ovl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ovl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -121,7 +121,7 @@ } octave_value_list& -octave_value_list::reverse (void) +octave_value_list::reverse () { octave_idx_type n = length (); @@ -173,7 +173,7 @@ } bool -octave_value_list::all_strings_p (void) const +octave_value_list::all_strings_p () const { octave_idx_type n = length (); @@ -185,7 +185,7 @@ } bool -octave_value_list::all_scalars (void) const +octave_value_list::all_scalars () const { octave_idx_type n = length (); @@ -200,7 +200,7 @@ } bool -octave_value_list::any_cell (void) const +octave_value_list::any_cell () const { octave_idx_type n = length (); @@ -212,7 +212,7 @@ } bool -octave_value_list::has_magic_colon (void) const +octave_value_list::has_magic_colon () const { octave_idx_type n = length (); @@ -274,7 +274,7 @@ } void -octave_value_list::make_storable_values (void) +octave_value_list::make_storable_values () { octave_idx_type len = length (); const std::vector& cdata = m_data; diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave-value/ovl.h --- a/libinterp/octave-value/ovl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave-value/ovl.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,7 +44,7 @@ { public: - octave_value_list (void) = default; + octave_value_list () = default; explicit octave_value_list (octave_idx_type n) : m_data (n), m_names () { } @@ -81,13 +81,13 @@ octave_value_list (const std::list&); octave_value_list (const std::list&); - ~octave_value_list (void) = default; + ~octave_value_list () = default; octave_value_list& operator = (const octave_value_list& obj) = default; octave_value_list& operator = (octave_value_list&& obj) = default; - Array array_value (void) const + Array array_value () const { Array retval; @@ -102,7 +102,7 @@ return retval; } - Cell cell_value (void) const { return array_value (); } + Cell cell_value () const { return array_value (); } // Assignment will resize on range errors. @@ -110,9 +110,9 @@ const octave_value& operator () (octave_idx_type n) const { return elem (n); } - octave_idx_type length (void) const { return m_data.size (); } + octave_idx_type length () const { return m_data.size (); } - bool empty (void) const { return length () == 0; } + bool empty () const { return length () == 0; } void resize (octave_idx_type n, const octave_value& rfv = octave_value ()) { @@ -125,7 +125,7 @@ octave_value_list& append (const octave_value_list& lst); - octave_value_list& reverse (void); + octave_value_list& reverse (); octave_value_list slice (octave_idx_type offset, octave_idx_type len, bool tags = false) const @@ -152,25 +152,25 @@ splice (octave_idx_type offset, octave_idx_type len, const octave_value_list& lst = octave_value_list ()) const; - bool all_strings_p (void) const; + bool all_strings_p () const; - bool all_scalars (void) const; + bool all_scalars () const; - bool any_cell (void) const; + bool any_cell () const; - bool has_magic_colon (void) const; + bool has_magic_colon () const; string_vector make_argv (const std::string& = "") const; void stash_name_tags (const string_vector& nm) { m_names = nm; } - string_vector name_tags (void) const { return m_names; } + string_vector name_tags () const { return m_names; } - void make_storable_values (void); + void make_storable_values (); octave_value& xelem (octave_idx_type i) { return m_data[i]; } - void clear (void) { m_data.clear (); } + void clear () { m_data.clear (); } private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave.cc --- a/libinterp/octave.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave.cc Mon Jan 30 18:36:03 2023 +0100 @@ -56,7 +56,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -cmdline_options::cmdline_options (void) +cmdline_options::cmdline_options () { m_all_args.resize (1); m_all_args[0] = ""; @@ -239,7 +239,7 @@ argc-octave_optind_wrapper ()); } -octave_value cmdline_options::as_octave_value (void) const +octave_value cmdline_options::as_octave_value () const { octave_scalar_map m; @@ -295,7 +295,7 @@ // an explicit definition of the destructor here is much simpler than // including the full declaration of interpreter in the // octave.h header file. -application::~application (void) { } +application::~application () { } void application::set_program_names (const std::string& pname) @@ -324,25 +324,25 @@ } } -bool application::forced_interactive (void) +bool application::forced_interactive () { return s_instance ? s_instance->m_options.forced_interactive () : false; } // Provided for convenience. Will be removed once we eliminate the // old terminal widget. -bool application::experimental_terminal_widget (void) const +bool application::experimental_terminal_widget () const { return (s_instance ? s_instance->m_options.experimental_terminal_widget () : false); } -bool application::interpreter_initialized (void) +bool application::interpreter_initialized () { return m_interpreter ? m_interpreter->initialized () : false; } -interpreter& application::create_interpreter (void) +interpreter& application::create_interpreter () { if (! m_interpreter) m_interpreter = std::unique_ptr (new interpreter (this)); @@ -350,23 +350,23 @@ return *m_interpreter; } -void application::initialize_interpreter (void) +void application::initialize_interpreter () { if (m_interpreter) m_interpreter->initialize (); } -int application::execute_interpreter (void) +int application::execute_interpreter () { return m_interpreter ? m_interpreter->execute () : -1; } -void application::delete_interpreter (void) +void application::delete_interpreter () { m_interpreter.reset (); } -void application::init (void) +void application::init () { if (s_instance) throw std::runtime_error @@ -420,7 +420,7 @@ sysdep_init (); } -int cli_application::execute (void) +int cli_application::execute () { interpreter& interp = create_interpreter (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/octave.h --- a/libinterp/octave.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/octave.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,7 +44,7 @@ { public: - cmdline_options (void); + cmdline_options (); cmdline_options (int argc, char **argv); @@ -52,41 +52,41 @@ cmdline_options& operator = (const cmdline_options&) = default; - int sys_argc (void) const { return m_all_args.numel (); } - char ** sys_argv (void) const { return m_all_args.c_str_vec (); } + int sys_argc () const { return m_all_args.numel (); } + char ** sys_argv () const { return m_all_args.c_str_vec (); } - bool echo_commands (void) const { return m_echo_commands; } + bool echo_commands () const { return m_echo_commands; } - bool experimental_terminal_widget (void) const + bool experimental_terminal_widget () const { return m_experimental_terminal_widget; } - bool forced_interactive (void) const { return m_forced_interactive; } - bool forced_line_editing (void) const { return m_forced_line_editing; } - bool gui (void) const { return m_gui; } - bool inhibit_startup_message (void) const + bool forced_interactive () const { return m_forced_interactive; } + bool forced_line_editing () const { return m_forced_line_editing; } + bool gui () const { return m_gui; } + bool inhibit_startup_message () const { return m_inhibit_startup_message; } - bool line_editing (void) const { return m_line_editing; } + bool line_editing () const { return m_line_editing; } - bool no_window_system (void) const { return m_no_window_system; } - bool persist (void) const { return m_persist; } - bool read_history_file (void) const { return m_read_history_file; } - bool read_init_files (void) const { return m_read_init_files; } - bool read_site_files (void) const { return m_read_site_files; } - bool server (void) const { return m_server; } - bool set_initial_path (void) const { return m_set_initial_path; } - bool traditional (void) const { return m_traditional; } - bool verbose_flag (void) const { return m_verbose_flag; } - std::string code_to_eval (void) const { return m_code_to_eval; } - std::list command_line_path (void) const + bool no_window_system () const { return m_no_window_system; } + bool persist () const { return m_persist; } + bool read_history_file () const { return m_read_history_file; } + bool read_init_files () const { return m_read_init_files; } + bool read_site_files () const { return m_read_site_files; } + bool server () const { return m_server; } + bool set_initial_path () const { return m_set_initial_path; } + bool traditional () const { return m_traditional; } + bool verbose_flag () const { return m_verbose_flag; } + std::string code_to_eval () const { return m_code_to_eval; } + std::list command_line_path () const { return m_command_line_path; } - std::string docstrings_file (void) const { return m_docstrings_file; } - std::string doc_cache_file (void) const { return m_doc_cache_file; } - std::string exec_path (void) const { return m_exec_path; } - std::string image_path (void) const { return m_image_path; } - std::string info_file (void) const { return m_info_file; } - std::string info_program (void) const { return m_info_program; } - std::string texi_macros_file (void) const {return m_texi_macros_file; } - string_vector all_args (void) const { return m_all_args; } - string_vector remaining_args (void) const { return m_remaining_args; } + std::string docstrings_file () const { return m_docstrings_file; } + std::string doc_cache_file () const { return m_doc_cache_file; } + std::string exec_path () const { return m_exec_path; } + std::string image_path () const { return m_image_path; } + std::string info_file () const { return m_info_file; } + std::string info_program () const { return m_info_program; } + std::string texi_macros_file () const {return m_texi_macros_file; } + string_vector all_args () const { return m_all_args; } + string_vector remaining_args () const { return m_remaining_args; } void echo_commands (bool arg) { m_echo_commands = arg; } @@ -120,7 +120,7 @@ void all_args (const string_vector& arg) { m_all_args = arg; } void remaining_args (const string_vector& arg) { m_remaining_args = arg; } - octave_value as_octave_value (void) const; + octave_value as_octave_value () const; private: @@ -255,36 +255,36 @@ application& operator = (const application&) = delete; - virtual ~application (void); + virtual ~application (); - int sys_argc (void) const { return m_options.sys_argc (); } - char ** sys_argv (void) const { return m_options.sys_argv (); } + int sys_argc () const { return m_options.sys_argc (); } + char ** sys_argv () const { return m_options.sys_argv (); } void set_program_names (const std::string& pname); void intern_argv (const string_vector& args); - cmdline_options options (void) const { return m_options; } + cmdline_options options () const { return m_options; } - bool have_eval_option_code (void) const { return m_have_eval_option_code; } + bool have_eval_option_code () const { return m_have_eval_option_code; } - bool have_script_file (void) const { return m_have_script_file; } + bool have_script_file () const { return m_have_script_file; } - bool is_octave_program (void) const { return m_is_octave_program; } + bool is_octave_program () const { return m_is_octave_program; } - bool interpreter_initialized (void); + bool interpreter_initialized (); - virtual interpreter& create_interpreter (void); + virtual interpreter& create_interpreter (); - virtual void initialize_interpreter (void); + virtual void initialize_interpreter (); - virtual int execute_interpreter (void); + virtual int execute_interpreter (); - virtual void delete_interpreter (void); + virtual void delete_interpreter (); - virtual int execute (void) = 0; + virtual int execute () = 0; - virtual bool gui_running (void) const { return false; } + virtual bool gui_running () const { return false; } virtual void gui_running (bool) { } void program_invocation_name (const std::string& nm) @@ -296,40 +296,40 @@ // Provided for convenience. Will be removed once we eliminate the // old terminal widget. - bool experimental_terminal_widget (void) const; + bool experimental_terminal_widget () const; - static application * app (void) { return s_instance; } + static application * app () { return s_instance; } - static std::string program_invocation_name (void) + static std::string program_invocation_name () { return s_instance ? s_instance->m_program_invocation_name : ""; } - static std::string program_name (void) + static std::string program_name () { return s_instance ? s_instance->m_program_name : ""; } - static string_vector argv (void) + static string_vector argv () { return s_instance ? s_instance->m_argv : string_vector (); } - static bool is_gui_running (void) + static bool is_gui_running () { return s_instance ? s_instance->gui_running () : false; } // Convenience functions. - static bool forced_interactive (void); + static bool forced_interactive (); private: // The application instance; There should be only one. static application *s_instance; - void init (void); + void init (); protected: @@ -380,9 +380,9 @@ cli_application& operator = (const cli_application&) = delete; - ~cli_application (void) = default; + ~cli_application () = default; - int execute (void); + int execute (); }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/operators/op-class.cc --- a/libinterp/operators/op-class.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/operators/op-class.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,6 +34,7 @@ #include "errwarn.h" #include "interpreter-private.h" +#include "interpreter.h" #include "load-path.h" #include "ovl.h" #include "ov.h" @@ -41,7 +42,6 @@ #include "ov-typeinfo.h" #include "ops.h" #include "symtab.h" -#include "parse.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -55,15 +55,17 @@ { std::string class_name = a.class_name (); - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); octave_value meth = symtab.find_method (opname, class_name); if (meth.is_defined ()) { // Call overloaded unary class operator. - octave_value_list tmp = octave::feval (meth.function_value (), - ovl (a), 1); + octave_value_list tmp + = interp.feval (meth.function_value (), ovl (a), 1); // Return first element if present. if (tmp.length () > 0) @@ -140,7 +142,9 @@ oct_binop_default (const octave_value& a1, const octave_value& a2, const std::string& opname) { - octave::symbol_table& symtab = octave::__get_symbol_table__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::symbol_table& symtab = interp.get_symbol_table (); // Dispatch to first (leftmost) operand by default. std::string dispatch_type = a1.class_name (); @@ -157,8 +161,8 @@ error ("%s method not defined for %s class", opname.c_str (), dispatch_type.c_str ()); - octave_value_list tmp = octave::feval (meth.function_value (), - ovl (a1, a2), 1); + octave_value_list tmp + = interp.feval (meth.function_value (), ovl (a1, a2), 1); if (tmp.length () > 0) return tmp(0); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/anon-fcn-validator.h --- a/libinterp/parse-tree/anon-fcn-validator.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/anon-fcn-validator.h Mon Jan 30 18:36:03 2023 +0100 @@ -51,7 +51,7 @@ anon_fcn_validator& operator = (const anon_fcn_validator&) = delete; - ~anon_fcn_validator (void) = default; + ~anon_fcn_validator () = default; void visit_postfix_expression (tree_postfix_expression&); @@ -61,12 +61,12 @@ void visit_simple_assignment (tree_simple_assignment&); - bool ok (void) const { return m_ok; } + bool ok () const { return m_ok; } - int line (void) const { return m_line; } - int column (void) const { return m_column; } + int line () const { return m_line; } + int column () const { return m_column; } - std::string message (void) const { return m_message; } + std::string message () const { return m_message; } private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/bp-table.cc --- a/libinterp/parse-tree/bp-table.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/bp-table.cc Mon Jan 30 18:36:03 2023 +0100 @@ -96,12 +96,12 @@ m_ok = true; } - std::string file (void) const { return m_file; } - std::string dir (void) const { return m_fcn; } - std::string fcn (void) const { return m_fcn; } - std::string class_name (void) const { return m_class_name; } + std::string file () const { return m_file; } + std::string dir () const { return m_fcn; } + std::string fcn () const { return m_fcn; } + std::string class_name () const { return m_class_name; } - bool ok (void) const { return m_ok; } + bool ok () const { return m_ok; } private: @@ -114,7 +114,7 @@ // Clear all reasons to stop, other than breakpoints. -void bp_table::dbclear_all_signals (void) +void bp_table::dbclear_all_signals () { interpreter& interp = m_evaluator.get_interpreter (); error_system& es = interp.get_error_system (); @@ -941,7 +941,7 @@ return remove_all_breakpoints_from_function (info.fcn (), silent); } -void bp_table::remove_all_breakpoints (void) +void bp_table::remove_all_breakpoints () { // Odd loop structure required because delete will invalidate // m_bp_set iterators. diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/bp-table.h --- a/libinterp/parse-tree/bp-table.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/bp-table.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,217 +39,172 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class tree_evaluator; - -struct bp_type -{ -public: - bp_type (int l, const std::string& c) : line (l), cond (c) { } - - //-------- + class tree_evaluator; - int line; - std::string cond; -}; + struct bp_type + { + public: + bp_type (int l, const std::string& c) : line (l), cond (c) { } -// Interface to breakpoints. -class OCTINTERP_API bp_table -{ -public: + //-------- - bp_table (tree_evaluator& tw) - : m_evaluator (tw), m_bp_set (), m_errors_that_stop (), - m_caught_that_stop (), m_warnings_that_stop () - { } - - ~bp_table (void) = default; - - // Set of breakpoint lines. - typedef std::set bp_lines; + int line; + std::string cond; + }; - typedef bp_lines::const_iterator const_bp_lines_iterator; - typedef bp_lines::iterator bp_lines_iterator; - - typedef std::map fname_line_map; - - typedef fname_line_map::const_iterator const_fname_line_map_iterator; - typedef fname_line_map::iterator fname_line_map_iterator; - - typedef std::map > fname_bp_map; - typedef fname_bp_map::const_iterator const_fname_bp_map_iterator; - typedef fname_bp_map::iterator fname_bp_map_iterator; + // Interface to breakpoints. + class OCTINTERP_API bp_table + { + public: -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "use 'bp_table::add_breakpoints_in_function' instead") - int add_breakpoint (const std::string& fname = "", - const std::string& class_name = "", - int line = 1, - const std::string& condition = "") - { - return add_breakpoint_in_function (fname, class_name, line, condition); - } + bp_table (tree_evaluator& tw) + : m_evaluator (tw), m_bp_set (), m_errors_that_stop (), + m_caught_that_stop (), m_warnings_that_stop () + { } - OCTAVE_DEPRECATED (7, "use 'bp_table::add_breakpoints_in_function' instead") - bp_lines add_breakpoint (const std::string& fname = "", - const std::string& class_name = "", - const bp_lines& lines = bp_lines (), - const std::string& condition = "") - { - return add_breakpoints_in_function (fname, class_name, lines, condition); - } -#endif + ~bp_table () = default; + + // Set of breakpoint lines. + typedef std::set bp_lines; + + typedef bp_lines::const_iterator const_bp_lines_iterator; + typedef bp_lines::iterator bp_lines_iterator; - // Add a breakpoint at the nearest executable line in a function. - int add_breakpoint_in_function (const std::string& fname = "", - const std::string& class_name = "", - int line = 1, - const std::string& condition = ""); + typedef std::map fname_line_map; + + typedef fname_line_map::const_iterator const_fname_line_map_iterator; + typedef fname_line_map::iterator fname_line_map_iterator; - // Add a set of breakpoints at the nearest executable lines in a - // function. - bp_lines add_breakpoints_in_function (const std::string& fname = "", - const std::string& class_name = "", - const bp_lines& lines = bp_lines (), - const std::string& condition = ""); + typedef std::map > fname_bp_map; + typedef fname_bp_map::const_iterator const_fname_bp_map_iterator; + typedef fname_bp_map::iterator fname_bp_map_iterator; - // Add a breakpoint at the nearest executable line in a file. - int add_breakpoint_in_file (const std::string& file = "", - int line = 1, - const std::string& condition = ""); - - // Add a set of breakpoints at the nearest executable lines in a - // file. - bp_lines add_breakpoints_in_file (const std::string& file = "", - const bp_lines& lines = bp_lines (), + // Add a breakpoint at the nearest executable line in a function. + int add_breakpoint_in_function (const std::string& fname = "", + const std::string& class_name = "", + int line = 1, const std::string& condition = ""); -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "use 'bp_table::remove_breakpoint_from_function' instead") - int remove_breakpoint (const std::string& fname = "", - int line = 1) - { - return remove_breakpoint_from_function (fname, line); - } + // Add a set of breakpoints at the nearest executable lines in a + // function. + bp_lines add_breakpoints_in_function (const std::string& fname = "", + const std::string& class_name = "", + const bp_lines& lines = bp_lines (), + const std::string& condition = ""); - OCTAVE_DEPRECATED (7, "use 'bp_table::remove_breakpoints_from_function' instead") - int remove_breakpoint (const std::string& fname = "", - const bp_lines& lines = bp_lines ()) - { - return remove_breakpoints_from_function (fname, lines); - } -#endif + // Add a breakpoint at the nearest executable line in a file. + int add_breakpoint_in_file (const std::string& file = "", + int line = 1, + const std::string& condition = ""); + + // Add a set of breakpoints at the nearest executable lines in a + // file. + bp_lines add_breakpoints_in_file (const std::string& file = "", + const bp_lines& lines = bp_lines (), + const std::string& condition = ""); - // Remove a breakpoint from the given line in file. - int remove_breakpoint_from_function (const std::string& fname = "", - int line = 1); + // Remove a breakpoint from the given line in file. + int remove_breakpoint_from_function (const std::string& fname = "", + int line = 1); - // Remove a set of breakpoints from the given lines in file. - int remove_breakpoints_from_function (const std::string& fname = "", - const bp_lines& lines = bp_lines ()); + // Remove a set of breakpoints from the given lines in file. + int remove_breakpoints_from_function (const std::string& fname = "", + const bp_lines& lines = bp_lines ()); - // Remove all the breakpoints in a specified function. - bp_lines remove_all_breakpoints_from_function (const std::string& fname, - bool silent = false); + // Remove all the breakpoints in a specified function. + bp_lines remove_all_breakpoints_from_function (const std::string& fname, + bool silent = false); - // Remove a breakpoint from the given line in file. - int remove_breakpoint_from_file (const std::string& file = "", - int line = 1); + // Remove a breakpoint from the given line in file. + int remove_breakpoint_from_file (const std::string& file = "", + int line = 1); - // Remove a set of breakpoints from the given lines in file. - int remove_breakpoints_from_file (const std::string& file = "", - const bp_lines& lines = bp_lines ()); + // Remove a set of breakpoints from the given lines in file. + int remove_breakpoints_from_file (const std::string& file = "", + const bp_lines& lines = bp_lines ()); -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "use 'bp_table::remove_all_breakpoints_from_function' instead") - bp_lines remove_all_breakpoints_in_file (const std::string& fname, - bool silent = false) - { - return remove_all_breakpoints_from_function (fname, silent); - } -#endif + // Remove all the breakpoints from a file. + bp_lines remove_all_breakpoints_from_file (const std::string& file, + bool silent = false); + + // Remove all the breakpoints registered with octave. + void remove_all_breakpoints (); - // Remove all the breakpoints from a file. - bp_lines remove_all_breakpoints_from_file (const std::string& file, - bool silent = false); + // Return all breakpoints. Each element of the map is a vector + // containing the breakpoints corresponding to a given function name. + fname_bp_map get_breakpoint_list (const octave_value_list& fname_list); + + bool have_breakpoints () { return (! m_bp_set.empty ()); } - // Remove all the breakpoints registered with octave. - void remove_all_breakpoints (void); - - // Return all breakpoints. Each element of the map is a vector - // containing the breakpoints corresponding to a given function name. - fname_bp_map get_breakpoint_list (const octave_value_list& fname_list); - - bool have_breakpoints (void) { return (! m_bp_set.empty ()); } + // Should we enter debugging for this particular error identifier? + bool debug_on_err (const std::string& id) + { + return (m_errors_that_stop.empty () || m_errors_that_stop.count (id)); + } - // Should we enter debugging for this particular error identifier? - bool debug_on_err (const std::string& id) - { - return (m_errors_that_stop.empty () || m_errors_that_stop.count (id)); - } + // Should we enter debugging for this particular identifier in a try/catch? + bool debug_on_caught (const std::string& id) + { + return (m_caught_that_stop.empty () || m_caught_that_stop.count (id)); + } - // Should we enter debugging for this particular identifier in a try/catch? - bool debug_on_caught (const std::string& id) - { - return (m_caught_that_stop.empty () || m_caught_that_stop.count (id)); - } + // Should we enter debugging for this particular warning identifier? + bool debug_on_warn (const std::string& id) + { + return (m_warnings_that_stop.empty () || m_warnings_that_stop.count (id)); + } - // Should we enter debugging for this particular warning identifier? - bool debug_on_warn (const std::string& id) - { - return (m_warnings_that_stop.empty () || m_warnings_that_stop.count (id)); - } + octave_map stop_on_err_warn_status (bool to_screen); + + void dbstop_process_map_args (const octave_map& mv); - octave_map stop_on_err_warn_status (bool to_screen); + void dbclear_all_signals (); - void dbstop_process_map_args (const octave_map& mv); + bool condition_valid (const std::string& cond); - void dbclear_all_signals (void); - - bool condition_valid (const std::string& cond); + void parse_dbfunction_params (const char *who, + const octave_value_list& args, + std::string& fcn_name, + std::string& class_name, + bp_table::bp_lines& lines, + std::string& cond); - void parse_dbfunction_params (const char *who, - const octave_value_list& args, - std::string& fcn_name, - std::string& class_name, - bp_table::bp_lines& lines, - std::string& cond); + private: + + typedef std::set::const_iterator const_bp_set_iterator; + typedef std::set::iterator bp_set_iterator; -private: - - typedef std::set::const_iterator const_bp_set_iterator; - typedef std::set::iterator bp_set_iterator; + tree_evaluator& m_evaluator; - tree_evaluator& m_evaluator; - - // Set of function (.m file) names containing at least one breakpoint. - std::set m_bp_set; + // Set of function (.m file) names containing at least one breakpoint. + std::set m_bp_set; - // Set of error and warning message IDs that cause us to stop - // *if* Vdebug_on_error / Vdebug_on_caught / Vdebug_on_warning is set. - // Empty means stop on any error / caught error / warning. - std::set m_errors_that_stop; - std::set m_caught_that_stop; - std::set m_warnings_that_stop; + // Set of error and warning message IDs that cause us to stop + // *if* Vdebug_on_error / Vdebug_on_caught / Vdebug_on_warning is set. + // Empty means stop on any error / caught error / warning. + std::set m_errors_that_stop; + std::set m_caught_that_stop; + std::set m_warnings_that_stop; - void set_stop_flag (const char *who, const std::string& condition, - bool on_off); + void set_stop_flag (const char *who, const std::string& condition, + bool on_off); - void process_id_list (const char *who, const std::string& condition, - const octave_value_list& args, - int nargin, int& pos, bool on_off, - std::set& id_list); + void process_id_list (const char *who, const std::string& condition, + const octave_value_list& args, + int nargin, int& pos, bool on_off, + std::set& id_list); - bool add_breakpoint_1 (octave_user_code *fcn, const std::string& fname, - const bp_lines& line, const std::string& condition, - bp_lines& retval); + bool add_breakpoint_1 (octave_user_code *fcn, const std::string& fname, + const bp_lines& line, const std::string& condition, + bp_lines& retval); - int remove_breakpoint_1 (octave_user_code *fcn, const std::string&, - const bp_lines& lines); + int remove_breakpoint_1 (octave_user_code *fcn, const std::string&, + const bp_lines& lines); - bp_lines remove_all_breakpoints_in_file_1 (octave_user_code *fcn, - const std::string& fname); -}; + bp_lines remove_all_breakpoints_in_file_1 (octave_user_code *fcn, + const std::string& fname); + }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/comment-list.cc --- a/libinterp/parse-tree/comment-list.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/comment-list.cc Mon Jan 30 18:36:03 2023 +0100 @@ -35,7 +35,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) comment_list * -comment_list::dup (void) const +comment_list::dup () const { comment_list *new_cl = new comment_list (); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/comment-list.h --- a/libinterp/parse-tree/comment-list.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/comment-list.h Mon Jan 30 18:36:03 2023 +0100 @@ -34,9 +34,9 @@ OCTAVE_BEGIN_NAMESPACE(octave) -extern std::string get_comment_text (void); +extern std::string get_comment_text (); -extern char * get_comment_text_c_str (void); +extern char * get_comment_text_c_str (); extern void save_comment_text (const std::string& text); @@ -72,17 +72,17 @@ return *this; } - std::string text (void) const { return m_text; } + std::string text () const { return m_text; } - comment_type type (void) const { return m_type; } + comment_type type () const { return m_type; } - bool is_block (void) const { return m_type == block; } - bool is_full_line (void) const { return m_type == full_line; } - bool is_end_of_line (void) const { return m_type == end_of_line; } - bool is_doc_string (void) const { return m_type == doc_string; } - bool is_copyright (void) const { return m_type == copyright; } + bool is_block () const { return m_type == block; } + bool is_full_line () const { return m_type == full_line; } + bool is_end_of_line () const { return m_type == end_of_line; } + bool is_doc_string () const { return m_type == doc_string; } + bool is_copyright () const { return m_type == copyright; } - ~comment_elt (void) = default; + ~comment_elt () = default; private: @@ -98,7 +98,7 @@ { public: - comment_list (void) { } + comment_list () { } void append (const comment_elt& elt) { base_list::append (elt); } @@ -107,7 +107,7 @@ comment_elt::comment_type t = comment_elt::unknown) { append (comment_elt (s, t)); } - comment_list * dup (void) const; + comment_list * dup () const; }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/filepos.h --- a/libinterp/parse-tree/filepos.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/filepos.h Mon Jan 30 18:36:03 2023 +0100 @@ -34,7 +34,7 @@ { public: - filepos (void) : m_line (0), m_column (0) { } + filepos () : m_line (0), m_column (0) { } filepos (int l, int c) : m_line (l), m_column (c) { } @@ -42,15 +42,15 @@ filepos& operator = (const filepos&) = default; - ~filepos (void) = default; + ~filepos () = default; operator bool () { return m_line > 0 && m_column > 0; } void line (int l) { m_line = l; } void column (int c) { m_column = c; } - int line (void) const { return m_line; } - int column (void) const { return m_column; } + int line () const { return m_line; } + int column () const { return m_column; } void increment_line (int val = 1) { m_line += val; } void increment_column (int val = 1) { m_column += val; } @@ -58,7 +58,7 @@ void decrement_line (int val = 1) { m_line -= val; } void decrement_column (int val = 1) { m_column -= val; } - void next_line (void) + void next_line () { m_line++; m_column = 1; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/lex.h --- a/libinterp/parse-tree/lex.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/lex.h Mon Jan 30 18:36:03 2023 +0100 @@ -62,23 +62,23 @@ symbol_table_context (interpreter& interp) : m_interpreter (interp), m_frame_stack () { } - ~symbol_table_context (void) { clear (); } + ~symbol_table_context () { clear (); } - void clear (void); + void clear (); - bool empty (void) const { return m_frame_stack.empty (); } + bool empty () const { return m_frame_stack.empty (); } - std::size_t size (void) const { return m_frame_stack.size (); } + std::size_t size () const { return m_frame_stack.size (); } - void pop (void); + void pop (); void push (const symbol_scope& scope) { m_frame_stack.push_front (scope); } - symbol_scope curr_scope (void) const; - symbol_scope parent_scope (void) const; + symbol_scope curr_scope () const; + symbol_scope parent_scope () const; private: @@ -103,7 +103,7 @@ public: - bbp_nesting_level (void) : m_context () { } + bbp_nesting_level () : m_context () { } bbp_nesting_level (const bbp_nesting_level& nl) : m_context (nl.m_context) @@ -117,54 +117,54 @@ return *this; } - ~bbp_nesting_level (void) = default; + ~bbp_nesting_level () = default; // Alias for clear function. - void reset (void) { clear (); } + void reset () { clear (); } - void bracket (void) { m_context.push (BRACKET); } + void bracket () { m_context.push (BRACKET); } - bool is_bracket (void) + bool is_bracket () { return ! m_context.empty () && m_context.top () == BRACKET; } - void brace (void) { m_context.push (BRACE); } + void brace () { m_context.push (BRACE); } - bool is_brace (void) + bool is_brace () { return ! m_context.empty () && m_context.top () == BRACE; } - void paren (void) { m_context.push (PAREN); } + void paren () { m_context.push (PAREN); } - bool is_paren (void) + bool is_paren () { return ! m_context.empty () && m_context.top () == PAREN; } - void anon_fcn_body (void) { m_context.push (ANON_FCN_BODY); } + void anon_fcn_body () { m_context.push (ANON_FCN_BODY); } - bool is_anon_fcn_body (void) + bool is_anon_fcn_body () { return ! m_context.empty () && m_context.top () == ANON_FCN_BODY; } - bool is_bracket_or_brace (void) + bool is_bracket_or_brace () { return (! m_context.empty () && (m_context.top () == BRACKET || m_context.top () == BRACE)); } - bool none (void) { return m_context.empty (); } + bool none () { return m_context.empty (); } - void remove (void) + void remove () { if (! m_context.empty ()) m_context.pop (); } - void clear (void) + void clear () { while (! m_context.empty ()) m_context.pop (); @@ -191,7 +191,7 @@ // elements that it stores. Another reason is that it makes it // easier to change the implementation later if needed. - token_cache (void) : m_buffer () { } + token_cache () : m_buffer () { } // No copying! @@ -199,14 +199,14 @@ token_cache& operator = (const token_cache&) = delete; - ~token_cache (void) { clear (); } + ~token_cache () { clear (); } void push (token *tok) { m_buffer.push_front (tok); } - void pop (void) + void pop () { if (! empty ()) { @@ -227,32 +227,32 @@ } // Most recently pushed. - token * front (void) + token * front () { return empty () ? nullptr : m_buffer.front (); } - const token * front (void) const + const token * front () const { return empty () ? nullptr : m_buffer.front (); } - token * back (void) + token * back () { return empty () ? nullptr : m_buffer.back (); } - const token * back (void) const + const token * back () const { return empty () ? nullptr : m_buffer.back (); } // Number of elements currently in the buffer. - std::size_t size (void) const { return m_buffer.size (); } + std::size_t size () const { return m_buffer.size (); } - bool empty (void) const { return m_buffer.empty (); } + bool empty () const { return m_buffer.empty (); } - void clear (void) + void clear () { while (! empty ()) pop (); @@ -326,25 +326,25 @@ lexical_feedback& operator = (const lexical_feedback&) = delete; - ~lexical_feedback (void); + ~lexical_feedback (); - void init (void); + void init (); - void reset (void); + void reset (); - int previous_token_value (void) const; + int previous_token_value () const; bool previous_token_value_is (int tok_val) const; - void mark_previous_token_trailing_space (void); + void mark_previous_token_trailing_space (); - bool space_follows_previous_token (void) const; + bool space_follows_previous_token () const; - bool previous_token_is_binop (void) const; + bool previous_token_is_binop () const; - bool previous_token_is_keyword (void) const; + bool previous_token_is_keyword () const; - bool previous_token_may_be_command (void) const; + bool previous_token_may_be_command () const; void mark_as_variable (const std::string& nm); void mark_as_variables (const std::list& lst); @@ -539,7 +539,7 @@ { public: - input_buffer (void) + input_buffer () : m_buffer (), m_offset (0), m_chars_left (0), m_eof (false) { } @@ -548,9 +548,9 @@ // Copy at most max_size characters to buf. int copy_chunk (char *buf, std::size_t max_size, bool by_lines = false); - bool empty (void) const { return m_chars_left == 0; } + bool empty () const { return m_chars_left == 0; } - bool at_eof (void) const { return m_eof; } + bool at_eof () const { return m_eof; } private: @@ -567,9 +567,9 @@ { public: - comment_buffer (void) : m_comment_list (nullptr) { } + comment_buffer () : m_comment_list (nullptr) { } - ~comment_buffer (void) { delete m_comment_list; } + ~comment_buffer () { delete m_comment_list; } void append (const std::string& s, comment_elt::comment_type t) { @@ -581,7 +581,7 @@ // Caller is expected to delete the returned value. - comment_list * get_comment (void) + comment_list * get_comment () { comment_list *retval = m_comment_list; @@ -590,7 +590,7 @@ return retval; } - void reset (void) + void reset () { delete m_comment_list; @@ -615,31 +615,31 @@ base_lexer& operator = (const base_lexer&) = delete; - virtual ~base_lexer (void); + virtual ~base_lexer (); - void init (void); + void init (); - virtual bool is_push_lexer (void) const { return false; } + virtual bool is_push_lexer () const { return false; } - virtual void reset (void); + virtual void reset (); - void prep_for_file (void); + void prep_for_file (); void begin_string (int state); virtual int fill_flex_buffer (char *buf, unsigned int max_size) = 0; - bool at_end_of_buffer (void) const { return m_input_buf.empty (); } + bool at_end_of_buffer () const { return m_input_buf.empty (); } - bool at_end_of_file (void) const { return m_input_buf.at_eof (); } + bool at_end_of_file () const { return m_input_buf.at_eof (); } - int handle_end_of_input (void); + int handle_end_of_input (); - char * flex_yytext (void); + char * flex_yytext (); - int flex_yyleng (void); + int flex_yyleng (); - int text_yyinput (void); + int text_yyinput (); void xunput (char c, char *buf); @@ -647,37 +647,37 @@ void update_token_positions (int tok_len); - bool looking_at_space (void); + bool looking_at_space (); - bool inside_any_object_index (void); + bool inside_any_object_index (); int make_keyword_token (const std::string& s); bool fq_identifier_contains_keyword (const std::string& s); - bool whitespace_is_significant (void); + bool whitespace_is_significant (); // We only provide specializations with base equal to 2, 10, or 16. template - int handle_number (void); + int handle_number (); - void handle_continuation (void); + void handle_continuation (); void finish_comment (comment_elt::comment_type typ); - comment_list * get_comment (void) { return m_comment_buf.get_comment (); } + comment_list * get_comment () { return m_comment_buf.get_comment (); } int handle_close_bracket (int bracket_type); - bool looks_like_command_arg (void); + bool looks_like_command_arg (); - int handle_superclass_identifier (void); + int handle_superclass_identifier (); - int handle_meta_identifier (void); + int handle_meta_identifier (); - int handle_fq_identifier (void); + int handle_fq_identifier (); - int handle_identifier (void); + int handle_identifier (); void maybe_warn_separator_insert (char sep); @@ -685,31 +685,27 @@ void maybe_warn_language_extension_comment (char c); - void warn_language_extension_continuation (void); + void warn_language_extension_continuation (); void warn_language_extension_operator (const std::string& op); void warn_deprecated_syntax (const std::string& msg); - void warn_deprecated_operator (const std::string& deprecated_op, - const std::string& recommended_op, - const std::string& version); - void push_token (token *); - token * current_token (void); + token * current_token (); - std::size_t pending_token_count (void) const; + std::size_t pending_token_count () const; void display_token (int tok); void fatal_error (const char *msg); - bool debug_flag (void) const; + bool debug_flag () const; - bool display_tokens (void) const; + bool display_tokens () const; - void increment_token_count (void); + void increment_token_count (); void lexer_debug (const char *pattern); @@ -722,31 +718,31 @@ // Object that collects comment text. comment_buffer m_comment_buf; - virtual std::string input_source (void) const { return "unknown"; } + virtual std::string input_source () const { return "unknown"; } - 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; } - bool input_from_tmp_history_file (void); + bool input_from_tmp_history_file (); void push_start_state (int state); - void pop_start_state (void); + void pop_start_state (); - void clear_start_state (void); + void clear_start_state (); - int start_state (void) const { return start_state_stack.top (); } + int start_state () const { return start_state_stack.top (); } - void display_start_state (void) const; + void display_start_state () const; bool maybe_unput_comma_before_unary_op (int tok); int handle_op (int tok, bool bos = false, bool compat = true); - int finish_command_arg (void); + int finish_command_arg (); int handle_token (int tok, token *tok_val = nullptr); @@ -790,29 +786,29 @@ lexer& operator = (const lexer&) = delete; - void reset (void) + void reset () { m_initial_input = true; base_lexer::reset (); } - std::string input_source (void) const + std::string input_source () const { return m_reader.input_source (); } - bool input_from_terminal (void) const + bool input_from_terminal () const { return m_reader.input_from_terminal (); } - bool input_from_file (void) const + bool input_from_file () const { return m_reader.input_from_file (); } - bool input_from_eval_string (void) const + bool input_from_eval_string () const { return m_reader.input_from_eval_string (); } @@ -868,11 +864,11 @@ push_lexer& operator = (const push_lexer&) = delete; - bool is_push_lexer (void) const { return true; } + bool is_push_lexer () const { return true; } void append_input (const std::string& input, bool eof); - std::string input_source (void) const { return "push buffer"; } + std::string input_source () const { return "push buffer"; } int fill_flex_buffer (char *buf, unsigned int max_size); }; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/lex.ll Mon Jan 30 18:36:03 2023 +0100 @@ -183,28 +183,6 @@ } \ while (0) -#define CMD_OR_DEPRECATED_OP(PATTERN, REPLACEMENT, VERSION, TOK) \ - do \ - { \ - curr_lexer->lexer_debug (PATTERN); \ - \ - if (curr_lexer->looks_like_command_arg ()) \ - { \ - yyless (0); \ - curr_lexer->push_start_state (COMMAND_START); \ - } \ - else \ - { \ - curr_lexer->warn_deprecated_operator (PATTERN, REPLACEMENT, \ - #VERSION); \ - /* set COMPAT to true here to avoid warning about \ - compatibility since we've already warned about the \ - operator being deprecated. */ \ - return curr_lexer->handle_op (TOK, false, true); \ - } \ - } \ - while (0) - #define CMD_OR_UNARY_OP(PATTERN, TOK, COMPAT) \ do \ { \ @@ -1088,28 +1066,6 @@ curr_lexer->m_string_text += '\v'; } -(\.\.\.){S}*{NL} { - curr_lexer->lexer_debug ("(\\.\\.\\.){S}*{NL}"); - - /* FIXME: Remove support for '...' continuation in Octave 9 */ - static const char *msg = "'...' continuations in double-quoted character strings were deprecated in version 7 and will not be allowed in a future version of Octave; please use '\\' instead"; - - curr_lexer->warn_deprecated_syntax (msg); - - HANDLE_STRING_CONTINUATION; - } - -\\{S}+{NL} { - curr_lexer->lexer_debug ("\\\\{S}+{NL}"); - - /* FIXME: Remove support for WS after line continuation in Octave 9 */ - static const char *msg = "whitespace after continuation markers in double-quoted character strings were deprecated in version 7 and will not be allowed in a future version of Octave"; - - curr_lexer->warn_deprecated_syntax (msg); - - HANDLE_STRING_CONTINUATION; - } - \\{NL} { curr_lexer->lexer_debug ("\\\\{NL}"); @@ -1302,17 +1258,6 @@ // Deprecated C preprocessor style continuation markers. %} -\\{S}*{NL} | -\\{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL} { - curr_lexer->lexer_debug ("\\\\{S}*{NL}|\\\\{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL}"); - - /* FIXME: Remove support for '\\' line continuation in Octave 9 */ - static const char *msg = "using continuation marker \\ outside of double quoted strings was deprecated in version 7 and will be removed from a future version of Octave, use ... instead"; - - curr_lexer->warn_deprecated_syntax (msg); - - curr_lexer->handle_continuation (); - } %{ // End of file. @@ -1644,13 +1589,10 @@ %} ":" { CMD_OR_OP (":", ':', true); } -".+" { CMD_OR_DEPRECATED_OP (".+", "+", 7, '+'); } -".-" { CMD_OR_DEPRECATED_OP (".-", "-", 7, '-'); } ".*" { CMD_OR_OP (".*", EMUL, true); } "./" { CMD_OR_OP ("./", EDIV, true); } ".\\" { CMD_OR_OP (".\\", ELEFTDIV, true); } ".^" { CMD_OR_OP (".^", EPOW, true); } -".**" { CMD_OR_DEPRECATED_OP (".**", ".^", 7, EPOW); } "<=" { CMD_OR_OP ("<=", EXPR_LE, true); } "==" { CMD_OR_OP ("==", EXPR_EQ, true); } "!=" { CMD_OR_OP ("!=", EXPR_NE, false); } @@ -1680,7 +1622,6 @@ } "^" { CMD_OR_OP ("^", POW, true); } -"**" { CMD_OR_DEPRECATED_OP ("**", "^", 7, POW); } "&&" { CMD_OR_OP ("&&", EXPR_AND_AND, true); } "||" { CMD_OR_OP ("||", EXPR_OR_OR, true); } @@ -1817,15 +1758,11 @@ "*=" { CMD_OR_OP ("*=", MUL_EQ, false); } "/=" { CMD_OR_OP ("/=", DIV_EQ, false); } "\\=" { CMD_OR_OP ("\\=", LEFTDIV_EQ, false); } -".+=" { CMD_OR_DEPRECATED_OP (".+=", "+=", 7, ADD_EQ); } -".-=" { CMD_OR_DEPRECATED_OP (".-=", "-=", 7, SUB_EQ); } ".*=" { CMD_OR_OP (".*=", EMUL_EQ, false); } "./=" { CMD_OR_OP ("./=", EDIV_EQ, false); } ".\\=" { CMD_OR_OP (".\\=", ELEFTDIV_EQ, false); } "^=" { CMD_OR_OP ("^=", POW_EQ, false); } -"**=" { CMD_OR_DEPRECATED_OP ("**=", "^=", 7, POW_EQ); } ".^=" { CMD_OR_OP (".^=", EPOW_EQ, false); } -".**=" { CMD_OR_DEPRECATED_OP (".**=", ".^=", 7, EPOW_EQ); } "&=" { CMD_OR_OP ("&=", AND_EQ, false); } "|=" { CMD_OR_OP ("|=", OR_EQ, false); } @@ -2177,14 +2114,14 @@ */ void - lexical_feedback::symbol_table_context::clear (void) + lexical_feedback::symbol_table_context::clear () { while (! m_frame_stack.empty ()) m_frame_stack.pop_front (); } void - lexical_feedback::symbol_table_context::pop (void) + lexical_feedback::symbol_table_context::pop () { if (empty ()) panic_impossible (); @@ -2193,7 +2130,7 @@ } symbol_scope - lexical_feedback::symbol_table_context::curr_scope (void) const + lexical_feedback::symbol_table_context::curr_scope () const { if (empty ()) return m_interpreter.get_current_scope (); @@ -2202,7 +2139,7 @@ } symbol_scope - lexical_feedback::symbol_table_context::parent_scope (void) const + lexical_feedback::symbol_table_context::parent_scope () const { std::size_t sz = size (); @@ -2211,13 +2148,13 @@ : (sz == 1 ? m_frame_stack[0] : symbol_scope ())); } - lexical_feedback::~lexical_feedback (void) + lexical_feedback::~lexical_feedback () { m_tokens.clear (); } void - lexical_feedback::init (void) + lexical_feedback::init () { // The closest paren, brace, or bracket nesting is not an object // index. @@ -2225,7 +2162,7 @@ } void - lexical_feedback::reset (void) + lexical_feedback::reset () { m_end_of_input = false; m_allow_command_syntax = true; @@ -2285,7 +2222,7 @@ } int - lexical_feedback::previous_token_value (void) const + lexical_feedback::previous_token_value () const { const token *tok = m_tokens.front (); return tok ? tok->token_value () : 0; @@ -2299,7 +2236,7 @@ } void - lexical_feedback::mark_previous_token_trailing_space (void) + lexical_feedback::mark_previous_token_trailing_space () { token *tok = m_tokens.front (); if (tok && ! previous_token_value_is ('\n')) @@ -2307,14 +2244,14 @@ } bool - lexical_feedback::space_follows_previous_token (void) const + lexical_feedback::space_follows_previous_token () const { const token *tok = m_tokens.front (); return tok ? tok->space_follows_token () : false; } bool - lexical_feedback::previous_token_is_binop (void) const + lexical_feedback::previous_token_is_binop () const { int tok = previous_token_value (); @@ -2334,7 +2271,7 @@ } bool - lexical_feedback::previous_token_is_keyword (void) const + lexical_feedback::previous_token_is_keyword () const { const token *tok = m_tokens.front (); return tok ? tok->iskeyword () : false; @@ -2359,7 +2296,7 @@ } bool - lexical_feedback::previous_token_may_be_command (void) const + lexical_feedback::previous_token_may_be_command () const { if (! m_allow_command_syntax) return false; @@ -2455,13 +2392,13 @@ return len; } - base_lexer::~base_lexer (void) + base_lexer::~base_lexer () { yylex_destroy (m_scanner); } void - base_lexer::init (void) + base_lexer::init () { yylex_init (&m_scanner); @@ -2482,7 +2419,7 @@ struct yyguts_t *yyg = static_cast (m_scanner) void - base_lexer::reset (void) + base_lexer::reset () { // Start off on the right foot. clear_start_state (); @@ -2505,7 +2442,7 @@ } void - base_lexer::prep_for_file (void) + base_lexer::prep_for_file () { m_reading_script_file = true; @@ -2521,7 +2458,7 @@ } int - base_lexer::handle_end_of_input (void) + base_lexer::handle_end_of_input () { lexer_debug ("<>"); @@ -2546,19 +2483,19 @@ } char * - base_lexer::flex_yytext (void) + base_lexer::flex_yytext () { return yyget_text (m_scanner); } int - base_lexer::flex_yyleng (void) + base_lexer::flex_yyleng () { return yyget_leng (m_scanner); } int - base_lexer::text_yyinput (void) + base_lexer::text_yyinput () { int c = yyinput (m_scanner); @@ -2629,7 +2566,7 @@ } bool - base_lexer::looking_at_space (void) + base_lexer::looking_at_space () { int c = text_yyinput (); xunput (c); @@ -2637,7 +2574,7 @@ } bool - base_lexer::inside_any_object_index (void) + base_lexer::inside_any_object_index () { bool retval = false; @@ -2964,7 +2901,7 @@ } bool - base_lexer::whitespace_is_significant (void) + base_lexer::whitespace_is_significant () { return (m_nesting_level.is_bracket () || (m_nesting_level.is_brace () @@ -3035,7 +2972,7 @@ template <> int - base_lexer::handle_number<2> (void) + base_lexer::handle_number<2> () { // Skip 0[bB] prefix. std::string yytxt (flex_yytext () + 2); @@ -3121,14 +3058,14 @@ } static uint64_t - flintmax (void) + flintmax () { return (static_cast (1) << std::numeric_limits::digits); } template <> int - base_lexer::handle_number<10> (void) + base_lexer::handle_number<10> () { bool imag = false; bool digits_only = true; @@ -3243,7 +3180,7 @@ template <> int - base_lexer::handle_number<16> (void) + base_lexer::handle_number<16> () { // Skip 0[xX] prefix. std::string yytxt (flex_yytext () + 2); @@ -3319,7 +3256,7 @@ } void - base_lexer::handle_continuation (void) + base_lexer::handle_continuation () { char *yytxt = flex_yytext (); int yylng = flex_yyleng (); @@ -3422,7 +3359,7 @@ } bool - base_lexer::looks_like_command_arg (void) + base_lexer::looks_like_command_arg () { if (! m_allow_command_syntax) return false; @@ -3435,7 +3372,7 @@ } int - base_lexer::handle_superclass_identifier (void) + base_lexer::handle_superclass_identifier () { update_token_positions (flex_yyleng ()); @@ -3469,7 +3406,7 @@ } int - base_lexer::handle_meta_identifier (void) + base_lexer::handle_meta_identifier () { std::string txt = flex_yytext (); @@ -3500,7 +3437,7 @@ } int - base_lexer::handle_fq_identifier (void) + base_lexer::handle_fq_identifier () { std::string txt = flex_yytext (); @@ -3534,7 +3471,7 @@ // should be ignored. int - base_lexer::handle_identifier (void) + base_lexer::handle_identifier () { update_token_positions (flex_yyleng ()); @@ -3640,7 +3577,7 @@ } void - base_lexer::warn_language_extension_continuation (void) + base_lexer::warn_language_extension_continuation () { warn_language_extension ("\\ used as line continuation marker"); } @@ -3667,16 +3604,6 @@ } void - base_lexer::warn_deprecated_operator (const std::string& deprecated_op, - const std::string& recommended_op, - const std::string& version) - { - std::string msg = "the '" + deprecated_op + "' operator was deprecated in version " + version + " and will not be allowed in a future version of Octave; please use '" + recommended_op + "' instead"; - - warn_deprecated_syntax (msg); - } - - void base_lexer::push_token (token *tok) { YYSTYPE *lval = yyget_lval (m_scanner); @@ -3685,14 +3612,14 @@ } token * - base_lexer::current_token (void) + base_lexer::current_token () { YYSTYPE *lval = yyget_lval (m_scanner); return lval->tok_val; } std::size_t - base_lexer::pending_token_count (void) const + base_lexer::pending_token_count () const { return m_tokens.size (); } @@ -3832,21 +3759,21 @@ } bool - base_lexer::debug_flag (void) const + base_lexer::debug_flag () const { settings& stgs = m_interpreter.get_settings (); return stgs.lexer_debug_flag (); } bool - base_lexer::display_tokens (void) const + base_lexer::display_tokens () const { settings& stgs = m_interpreter.get_settings (); return stgs.display_tokens (); } void - base_lexer::increment_token_count (void) + base_lexer::increment_token_count () { settings& stgs = m_interpreter.get_settings (); stgs.increment_token_count (); @@ -3869,7 +3796,7 @@ } bool - base_lexer::input_from_tmp_history_file (void) + base_lexer::input_from_tmp_history_file () { history_system& history_sys = m_interpreter.get_history_system (); @@ -3887,7 +3814,7 @@ } void - base_lexer::pop_start_state (void) + base_lexer::pop_start_state () { OCTAVE_YYG; @@ -3897,7 +3824,7 @@ } void - base_lexer::clear_start_state (void) + base_lexer::clear_start_state () { while (! start_state_stack.empty ()) start_state_stack.pop (); @@ -3906,7 +3833,7 @@ } void - base_lexer::display_start_state (void) const + base_lexer::display_start_state () const { std::cerr << "S: "; @@ -4017,7 +3944,7 @@ // function call. int - base_lexer::finish_command_arg (void) + base_lexer::finish_command_arg () { int tok = SQ_STRING; @@ -4083,10 +4010,8 @@ if (m_input_buf.empty ()) { - input_system& input_sys = m_interpreter.get_input_system (); - std::string ps - = m_initial_input ? input_sys.PS1 () : input_sys.PS2 (); + = m_initial_input ? m_interpreter.PS1 () : m_interpreter.PS2 (); std::string prompt = command_editor::decode_prompt_string (ps); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/oct-lvalue.cc --- a/libinterp/parse-tree/oct-lvalue.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/oct-lvalue.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,12 +37,12 @@ OCTAVE_BEGIN_NAMESPACE(octave) -bool octave_lvalue::is_defined (void) const +bool octave_lvalue::is_defined () const { return ! is_black_hole () && m_frame->is_defined (m_sym); } -bool octave_lvalue::is_undefined (void) const +bool octave_lvalue::is_undefined () const { return ! is_defined (); } @@ -59,7 +59,7 @@ m_frame->assign (op, m_sym, m_type, m_idx, rhs); } -octave_idx_type octave_lvalue::numel (void) const +octave_idx_type octave_lvalue::numel () const { // Return 1 if there is no index because without an index there // should be no way to have a cs-list here. Cs-lists may be passed @@ -178,7 +178,7 @@ m_idx = i; } -bool octave_lvalue::index_is_empty (void) const +bool octave_lvalue::index_is_empty () const { bool retval = false; @@ -192,7 +192,7 @@ return retval; } -bool octave_lvalue::index_is_colon (void) const +bool octave_lvalue::index_is_colon () const { bool retval = false; @@ -212,7 +212,7 @@ m_frame->non_const_unary_op (op, m_sym, m_type, m_idx); } -octave_value octave_lvalue::value (void) const +octave_value octave_lvalue::value () const { return (is_black_hole () ? octave_value () : m_frame->value (m_sym, m_type, m_idx)); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/oct-lvalue.h --- a/libinterp/parse-tree/oct-lvalue.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/oct-lvalue.h Mon Jan 30 18:36:03 2023 +0100 @@ -50,46 +50,38 @@ octave_lvalue& operator = (const octave_lvalue&) = delete; - ~octave_lvalue (void) = default; + ~octave_lvalue () = default; - bool is_black_hole (void) const { return m_black_hole; } + bool is_black_hole () const { return m_black_hole; } - void mark_black_hole (void) { m_black_hole = true; } + void mark_black_hole () { m_black_hole = true; } - bool is_defined (void) const; + bool is_defined () const; - bool is_undefined (void) const; + bool is_undefined () const; - bool isstruct (void) const { return value().isstruct (); } + bool isstruct () const { return value().isstruct (); } void define (const octave_value& v); void assign (octave_value::assign_op, const octave_value&); - octave_idx_type numel (void) const; + octave_idx_type numel () const; void set_index (const std::string& t, const std::list& i); - void clear_index (void) { m_type = ""; m_idx.clear (); } + void clear_index () { m_type = ""; m_idx.clear (); } - std::string index_type (void) const { return m_type; } + std::string index_type () const { return m_type; } - bool index_is_empty (void) const; + bool index_is_empty () const; - bool index_is_colon (void) const; + bool index_is_colon () const; void unary_op (octave_value::unary_op op); -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "use 'octave_lvalue::unary_op' instead") - void do_unary_op (octave_value::unary_op op) - { - return unary_op (op); - } -#endif - - octave_value value (void) const; + octave_value value () const; private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/oct-parse.yy --- a/libinterp/parse-tree/oct-parse.yy Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/oct-parse.yy Mon Jan 30 18:36:03 2023 +0100 @@ -2425,18 +2425,18 @@ parse_exception& operator = (const parse_exception&) = default; - ~parse_exception (void) = default; - - std::string message (void) const { return m_message; } + ~parse_exception () = default; + + std::string message () const { return m_message; } // Provided for std::exception interface. - const char * what (void) const noexcept { return m_message.c_str (); } - - std::string fcn_name (void) const { return m_fcn_name; } - std::string file_name (void) const { return m_file_name; } - - int line (void) const { return m_line; } - int column (void) const { return m_column; } + const char * what () const noexcept { return m_message.c_str (); } + + std::string fcn_name () const { return m_fcn_name; } + std::string file_name () const { return m_file_name; } + + int line () const { return m_line; } + int column () const { return m_column; } // virtual void display (std::ostream& os) const; @@ -2454,7 +2454,7 @@ { public: - parse_tree_validator (void) + parse_tree_validator () : m_scope (), m_error_list () { } @@ -2462,13 +2462,13 @@ parse_tree_validator& operator = (const parse_tree_validator&) = delete; - ~parse_tree_validator (void) = default; - - symbol_scope get_scope (void) const { return m_scope; } - - bool ok (void) const { return m_error_list.empty (); } - - std::list error_list (void) const + ~parse_tree_validator () = default; + + symbol_scope get_scope () const { return m_scope; } + + bool ok () const { return m_error_list.empty (); } + + std::list error_list () const { return m_error_list; } @@ -2542,7 +2542,7 @@ } std::size_t - base_parser::parent_scope_info::size (void) const + base_parser::parent_scope_info::size () const { return m_info.size (); } @@ -2560,7 +2560,7 @@ } void - base_parser::parent_scope_info::pop (void) + base_parser::parent_scope_info::pop () { m_info.pop_back (); } @@ -2616,18 +2616,18 @@ } symbol_scope - base_parser::parent_scope_info::parent_scope (void) const + base_parser::parent_scope_info::parent_scope () const { return size () > 1 ? m_info[size()-2].first : symbol_scope (); } std::string - base_parser::parent_scope_info::parent_name (void) const + base_parser::parent_scope_info::parent_name () const { return m_info[size()-2].second; } - void base_parser::parent_scope_info::clear (void) + void base_parser::parent_scope_info::clear () { m_info.clear (); m_all_names.clear (); @@ -2643,7 +2643,7 @@ m_stmt_list (), m_lexer (lxr), m_parser_state (yypstate_new ()) { } - base_parser::~base_parser (void) + base_parser::~base_parser () { delete &m_lexer; @@ -2659,7 +2659,7 @@ } void - base_parser::reset (void) + base_parser::reset () { m_endfunction_found = false; m_autoloading = false; @@ -2801,7 +2801,7 @@ } bool - base_parser::push_fcn_symtab (void) + base_parser::push_fcn_symtab () { m_curr_fcn_depth++; @@ -2893,7 +2893,7 @@ } tree_black_hole * - base_parser::make_black_hole (void) + base_parser::make_black_hole () { return new tree_black_hole (); } @@ -3006,7 +3006,7 @@ if (base->is_constant () && limit->is_constant () && (! incr || incr->is_constant ())) { - interpreter& interp = __get_interpreter__ (); + interpreter& interp = m_lexer.m_interpreter; try { @@ -4306,7 +4306,7 @@ } void - base_parser::recover_from_parsing_function (void) + base_parser::recover_from_parsing_function () { m_lexer.m_symtab_context.pop (); @@ -4884,7 +4884,9 @@ if (local_fcns) { - symbol_table& symtab = __get_symbol_table__ (); + interpreter& interp = m_lexer.m_interpreter; + + symbol_table& symtab = interp.get_symbol_table (); for (tree_statement *elt : *local_fcns) { @@ -5174,7 +5176,9 @@ if (e->is_constant ()) { - tree_evaluator& tw = __get_evaluator__ (); + interpreter& interp = m_lexer.m_interpreter; + + tree_evaluator& tw = interp.get_evaluator (); octave_value ov = e->evaluate (tw); @@ -5237,7 +5241,7 @@ if (array_list->all_elements_are_constant ()) { - interpreter& interp = __get_interpreter__ (); + interpreter& interp = m_lexer.m_interpreter; try { @@ -5494,7 +5498,7 @@ } void - base_parser::disallow_command_syntax (void) + base_parser::disallow_command_syntax () { m_lexer.m_allow_command_syntax = false; } @@ -5615,7 +5619,7 @@ } int - parser::run (void) + parser::run () { int status = -1; @@ -5732,17 +5736,15 @@ } int - push_parser::run (void) + push_parser::run () { if (! m_reader) error ("push_parser::run requires valid input_reader"); int exit_status = 0; - input_system& input_sys = m_interpreter.get_input_system (); - std::string prompt - = command_editor::decode_prompt_string (input_sys.PS1 ()); + = command_editor::decode_prompt_string (m_interpreter.PS1 ()); do { @@ -5764,7 +5766,7 @@ exit_status = run (input_line, false); - prompt = command_editor::decode_prompt_string (input_sys.PS2 ()); + prompt = command_editor::decode_prompt_string (m_interpreter.PS2 ()); } while (exit_status < 0); @@ -5806,7 +5808,7 @@ return octave_value (); } - unwind_action act ([=] (void) { ::fclose (ffile); }); + unwind_action act ([=] () { ::fclose (ffile); }); // get the encoding for this folder input_system& input_sys = interp.get_input_system (); @@ -5900,7 +5902,7 @@ // Check script or function for semantic errors. bool - base_parser::validate_primary_fcn (void) + base_parser::validate_primary_fcn () { octave_user_code *code = m_primary_fcn.user_code_value (); @@ -6412,16 +6414,6 @@ return retval; } - void - cleanup_statement_list (tree_statement_list **lst) - { - if (*lst) - { - delete *lst; - *lst = nullptr; - } - } - DEFMETHOD (eval, interp, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {} eval (@var{try}) @@ -6648,7 +6640,7 @@ // the eval, then the message is stored in the exception object and we // will display it later, after the buffers have been restored. - unwind_action act ([=] (void) + unwind_action act ([=] () { octave_stdout.rdbuf (old_out_buf); std::cerr.rdbuf (old_err_buf); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/parse.h --- a/libinterp/parse-tree/parse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/parse.h Mon Jan 30 18:36:03 2023 +0100 @@ -122,7 +122,7 @@ typedef std::deque::reverse_iterator reverse_iterator; typedef std::deque::const_reverse_iterator const_reverse_iterator; - parent_scope_info (void) = delete; + parent_scope_info () = delete; parent_scope_info (base_parser& parser) : m_parser (parser), m_info (), m_all_names () @@ -134,25 +134,25 @@ parent_scope_info& operator = (const parent_scope_info&) = delete; - ~parent_scope_info (void) = default; + ~parent_scope_info () = default; - OCTINTERP_API std::size_t size (void) const; + OCTINTERP_API std::size_t size () const; OCTINTERP_API void push (const value_type& elt); OCTINTERP_API void push (const symbol_scope& id); - OCTINTERP_API void pop (void); + OCTINTERP_API void pop (); OCTINTERP_API bool name_ok (const std::string& name); OCTINTERP_API bool name_current_scope (const std::string& name); - OCTINTERP_API symbol_scope parent_scope (void) const; + OCTINTERP_API symbol_scope parent_scope () const; - OCTINTERP_API std::string parent_name (void) const; + OCTINTERP_API std::string parent_name () const; - OCTINTERP_API void clear (void); + OCTINTERP_API void clear (); private: @@ -171,27 +171,27 @@ base_parser& operator = (const base_parser&) = delete; - virtual ~base_parser (void); + virtual ~base_parser (); - base_lexer& get_lexer (void) const { return m_lexer; } + base_lexer& get_lexer () const { return m_lexer; } - bool at_end_of_input (void) const { return m_lexer.m_end_of_input; } + bool at_end_of_input () const { return m_lexer.m_end_of_input; } - OCTINTERP_API void reset (void); + OCTINTERP_API void reset (); void classdef_object (const std::shared_ptr& obj) { m_classdef_object = obj; } - std::shared_ptr classdef_object (void) const + std::shared_ptr classdef_object () const { return m_classdef_object; } OCTINTERP_API void statement_list (std::shared_ptr& lst); - std::shared_ptr statement_list (void) const + std::shared_ptr statement_list () const { return m_stmt_list; } @@ -201,7 +201,7 @@ m_parsing_subfunctions = flag; } - bool parsing_subfunctions (void) const + bool parsing_subfunctions () const { return m_parsing_subfunctions; } @@ -211,12 +211,12 @@ m_parsing_local_functions = flag; } - bool parsing_local_functions (void) const + bool parsing_local_functions () const { return m_parsing_local_functions; } - int curr_fcn_depth (void) const + int curr_fcn_depth () const { return m_curr_fcn_depth; } @@ -226,7 +226,7 @@ m_endfunction_found = flag; } - bool endfunction_found (void) const + bool endfunction_found () const { return m_endfunction_found; } @@ -239,12 +239,12 @@ OCTINTERP_API bool end_token_ok (token *tok, token::end_tok_type expected); // Handle pushing symbol table for new function scope. - OCTINTERP_API bool push_fcn_symtab (void); + OCTINTERP_API bool push_fcn_symtab (); // Build a constant. OCTINTERP_API tree_constant * make_constant (token *tok_val); - OCTINTERP_API tree_black_hole * make_black_hole (void); + OCTINTERP_API tree_black_hole * make_black_hole (); OCTINTERP_API tree_matrix * make_matrix (tree_argument_list *row); @@ -458,7 +458,7 @@ // Reset state after parsing function. OCTINTERP_API void - recover_from_parsing_function (void); + recover_from_parsing_function (); OCTINTERP_API tree_classdef * make_classdef (token *tok_val, tree_classdef_attribute_list *a, @@ -701,7 +701,7 @@ // Don't allow parsing command syntax. If the parser/lexer is // reset, this setting is also reset to the default (allow command // syntax). - OCTINTERP_API void disallow_command_syntax (void); + OCTINTERP_API void disallow_command_syntax (); // Generic error messages. OCTINTERP_API void bison_error (const std::string& s); @@ -723,11 +723,11 @@ // use a separate run method and completely separate input from // lexical analysis and parsing. - virtual int run (void) = 0; + virtual int run () = 0; // Check primary script or function generated by the parser for // semantic errors. - OCTINTERP_API bool validate_primary_fcn (void); + OCTINTERP_API bool validate_primary_fcn (); OCTINTERP_API bool finish_input (tree_statement_list *lst, bool at_eof = false); @@ -859,9 +859,9 @@ parser& operator = (const parser&) = delete; - ~parser (void) = default; + ~parser () = default; - OCTINTERP_API int run (void); + OCTINTERP_API int run (); }; class push_parser : public base_parser @@ -887,13 +887,13 @@ push_parser& operator = (const push_parser&) = delete; - ~push_parser (void) = default; + ~push_parser () = default; // Use the push parser in the same way as the pull parser. The // parser arranges for input through the M_READER object. See, for // example, interpreter::main_loop. - OCTINTERP_API int run (void); + OCTINTERP_API int run (); // Parse INPUT. M_READER is not used. The user is responsible for // collecting input. @@ -950,9 +950,6 @@ extern OCTINTERP_API octave_value_list feval (const octave_value_list& args, int nargout = 0); -extern OCTINTERP_API void -cleanup_statement_list (tree_statement_list **lst); - OCTAVE_END_NAMESPACE(octave) #endif diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/profiler.cc --- a/libinterp/parse-tree/profiler.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/profiler.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -profiler::stats::stats (void) +profiler::stats::stats () : m_time (0.0), m_calls (0), m_recursive (false), m_parents (), m_children () { } @@ -172,13 +172,13 @@ return retval; } -profiler::profiler (void) +profiler::profiler () : m_known_functions (), m_fcn_index (), m_enabled (false), m_call_tree (new tree_node (nullptr, 0)), m_active_fcn (nullptr), m_last_time (-1.0) { } -profiler::~profiler (void) +profiler::~profiler () { delete m_call_tree; } @@ -253,7 +253,7 @@ } void -profiler::reset (void) +profiler::reset () { if (enabled ()) error ("profile: can't reset active profiler"); @@ -272,7 +272,7 @@ } octave_value -profiler::get_flat (void) const +profiler::get_flat () const { octave_value retval; @@ -334,7 +334,7 @@ } octave_value -profiler::get_hierarchical (void) const +profiler::get_hierarchical () const { octave_value retval; @@ -360,7 +360,7 @@ } double -profiler::query_time (void) const +profiler::query_time () const { sys::time now; @@ -372,7 +372,7 @@ } void -profiler::add_current_time (void) +profiler::add_current_time () { if (m_active_fcn) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/profiler.h --- a/libinterp/parse-tree/profiler.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/profiler.h Mon Jan 30 18:36:03 2023 +0100 @@ -82,14 +82,14 @@ enter& operator = (const enter&) = delete; - ~enter (void) + ~enter () { if (m_enabled) m_profiler.exit_function (m_fcn); } }; - profiler (void); + profiler (); // No copying! @@ -97,15 +97,15 @@ profiler& operator = (const profiler&) = delete; - virtual ~profiler (void); + virtual ~profiler (); - bool enabled (void) const { return m_enabled; } + bool enabled () const { return m_enabled; } void set_active (bool); - void reset (void); + void reset (); - octave_value get_flat (void) const; - octave_value get_hierarchical (void) const; + octave_value get_flat () const; + octave_value get_hierarchical () const; private: @@ -115,7 +115,7 @@ struct stats { public: - stats (void); + stats (); typedef std::set function_set; @@ -143,7 +143,7 @@ tree_node (tree_node *, octave_idx_type); - virtual ~tree_node (void); + virtual ~tree_node (); // No copying! @@ -212,12 +212,12 @@ // This is not static because in the future, maybe we want a flag // in the profiler or something to choose between cputime, wall-time, // user-time, system-time, ... - double query_time (void) const; + double query_time () const; // Add the time elapsed since last_time to the function we're currently in. // This is called from two different positions, thus it is useful to have // it as a separate function. - void add_current_time (void); + void add_current_time (); }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-anon-scopes.h --- a/libinterp/parse-tree/pt-anon-scopes.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-anon-scopes.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,7 @@ { public: - tree_anon_scopes (void) = delete; + tree_anon_scopes () = delete; tree_anon_scopes (tree_anon_fcn_handle& anon_fh); @@ -51,11 +51,11 @@ tree_anon_scopes& operator = (const tree_anon_scopes&) = delete; - ~tree_anon_scopes (void) = default; + ~tree_anon_scopes () = default; - std::set fcn_parameters (void) const { return m_params; } + std::set fcn_parameters () const { return m_params; } - std::set free_variables (void) const { return m_vars; } + std::set free_variables () const { return m_vars; } // The following methods, though public, don't belong to the // intended user interface of this class. diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-arg-list.cc --- a/libinterp/parse-tree/pt-arg-list.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-arg-list.cc Mon Jan 30 18:36:03 2023 +0100 @@ -43,7 +43,7 @@ // Argument lists. -tree_argument_list::~tree_argument_list (void) +tree_argument_list::~tree_argument_list () { while (! empty ()) { @@ -66,7 +66,7 @@ } bool -tree_argument_list::all_elements_are_constant (void) const +tree_argument_list::all_elements_are_constant () const { for (const tree_expression *elt : *this) { @@ -78,7 +78,7 @@ } bool -tree_argument_list::is_valid_lvalue_list (void) const +tree_argument_list::is_valid_lvalue_list () const { bool retval = true; @@ -98,7 +98,7 @@ } string_vector -tree_argument_list::get_arg_names (void) const +tree_argument_list::get_arg_names () const { int len = length (); @@ -113,7 +113,7 @@ } std::list -tree_argument_list::variable_names (void) const +tree_argument_list::variable_names () const { std::list retval; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-arg-list.h --- a/libinterp/parse-tree/pt-arg-list.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-arg-list.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ typedef tree_expression *element_type; - tree_argument_list (void) + tree_argument_list () : m_list_includes_magic_tilde (false), m_simple_assign_lhs (false) { } @@ -67,19 +67,19 @@ tree_argument_list& operator = (const tree_argument_list&) = delete; - ~tree_argument_list (void); + ~tree_argument_list (); - bool has_magic_tilde (void) const + bool has_magic_tilde () const { return m_list_includes_magic_tilde; } - bool includes_magic_tilde (void) const + bool includes_magic_tilde () const { return m_list_includes_magic_tilde; } - tree_expression * remove_front (void) + tree_expression * remove_front () { auto p = begin (); tree_expression *retval = *p; @@ -89,17 +89,17 @@ void append (const element_type& s); - void mark_as_simple_assign_lhs (void) { m_simple_assign_lhs = true; } + void mark_as_simple_assign_lhs () { m_simple_assign_lhs = true; } - bool is_simple_assign_lhs (void) { return m_simple_assign_lhs; } + bool is_simple_assign_lhs () { return m_simple_assign_lhs; } - bool all_elements_are_constant (void) const; + bool all_elements_are_constant () const; - bool is_valid_lvalue_list (void) const; + bool is_valid_lvalue_list () const; - string_vector get_arg_names (void) const; + string_vector get_arg_names () const; - std::list variable_names (void) const; + std::list variable_names () const; tree_argument_list * dup (symbol_scope& scope) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-args-block.cc --- a/libinterp/parse-tree/pt-args-block.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-args-block.cc Mon Jan 30 18:36:03 2023 +0100 @@ -31,7 +31,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -tree_args_block_validation_list::~tree_args_block_validation_list (void) +tree_args_block_validation_list::~tree_args_block_validation_list () { while (! empty ()) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-args-block.h --- a/libinterp/parse-tree/pt-args-block.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-args-block.h Mon Jan 30 18:36:03 2023 +0100 @@ -55,12 +55,12 @@ tree_arg_size_spec& operator = (const tree_arg_size_spec&) = delete; - ~tree_arg_size_spec (void) + ~tree_arg_size_spec () { delete m_size_args; } - tree_argument_list * size_args (void) { return m_size_args; } + tree_argument_list * size_args () { return m_size_args; } void accept (tree_walker& tw) { @@ -86,12 +86,12 @@ tree_arg_validation_fcns& operator = (const tree_arg_validation_fcns&) = delete; - ~tree_arg_validation_fcns (void) + ~tree_arg_validation_fcns () { delete m_fcn_args; } - tree_argument_list * fcn_args (void) { return m_fcn_args; } + tree_argument_list * fcn_args () { return m_fcn_args; } void accept (tree_walker& tw) { @@ -122,7 +122,7 @@ tree_arg_validation& operator = (const tree_arg_validation&) = delete; - ~tree_arg_validation (void) + ~tree_arg_validation () { delete m_arg_name; delete m_size_spec; @@ -136,17 +136,17 @@ m_arg_name = name; } - tree_expression * identifier_expression (void) { return m_arg_name; } + tree_expression * identifier_expression () { return m_arg_name; } - tree_arg_size_spec * size_spec (void) { return m_size_spec; } + tree_arg_size_spec * size_spec () { return m_size_spec; } - tree_identifier * class_name (void) { return m_class_name; } + tree_identifier * class_name () { return m_class_name; } tree_arg_validation_fcns * - validation_fcns (void) { return m_validation_fcns; } + validation_fcns () { return m_validation_fcns; } tree_expression * - initializer_expression (void) { return m_default_value; } + initializer_expression () { return m_default_value; } void accept (tree_walker& tw) { @@ -169,7 +169,7 @@ { public: - tree_args_block_validation_list (void) { } + tree_args_block_validation_list () { } tree_args_block_validation_list (tree_arg_validation *a) { append (a); } @@ -183,7 +183,7 @@ tree_args_block_validation_list& operator = (const tree_args_block_validation_list&) = delete; - ~tree_args_block_validation_list (void); + ~tree_args_block_validation_list (); void accept (tree_walker& tw) { @@ -208,12 +208,12 @@ tree_args_block_attribute_list& operator = (const tree_args_block_attribute_list&) = delete; - ~tree_args_block_attribute_list (void) + ~tree_args_block_attribute_list () { delete m_attr; } - tree_identifier * attribute (void) { return m_attr; } + tree_identifier * attribute () { return m_attr; } void accept (tree_walker& tw) { @@ -245,7 +245,7 @@ tree_arguments_block& operator = (const tree_arguments_block&) = delete; - ~tree_arguments_block (void) + ~tree_arguments_block () { delete m_attr_list; delete m_validation_list; @@ -254,19 +254,19 @@ delete m_trail_comm; } - tree_args_block_attribute_list * attribute_list (void) + tree_args_block_attribute_list * attribute_list () { return m_attr_list; } - tree_args_block_validation_list * validation_list (void) + tree_args_block_validation_list * validation_list () { return m_validation_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-array-list.cc --- a/libinterp/parse-tree/pt-array-list.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-array-list.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,7 +34,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -tree_array_list::~tree_array_list (void) +tree_array_list::~tree_array_list () { while (! empty ()) { @@ -45,7 +45,7 @@ } bool -tree_array_list::all_elements_are_constant (void) const +tree_array_list::all_elements_are_constant () const { for (const tree_argument_list *elt : *this) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-array-list.h --- a/libinterp/parse-tree/pt-array-list.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-array-list.h Mon Jan 30 18:36:03 2023 +0100 @@ -64,9 +64,9 @@ tree_array_list& operator = (const tree_array_list&) = delete; - ~tree_array_list (void); + ~tree_array_list (); - bool all_elements_are_constant (void) const; + bool all_elements_are_constant () const; // 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 diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-assign.cc --- a/libinterp/parse-tree/pt-assign.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-assign.cc Mon Jan 30 18:36:03 2023 +0100 @@ -30,9 +30,9 @@ #include #include "error.h" +#include "interpreter.h" #include "oct-lvalue.h" #include "ov.h" -#include "parse.h" #include "pt-arg-list.h" #include "pt-assign.h" @@ -48,7 +48,7 @@ m_ans_assign (), m_etype (t) { } -tree_simple_assignment::~tree_simple_assignment (void) +tree_simple_assignment::~tree_simple_assignment () { if (! m_preserve) delete m_lhs; @@ -57,7 +57,7 @@ } std::string -tree_simple_assignment::oper (void) const +tree_simple_assignment::oper () const { return octave_value::assign_op_as_string (m_etype); } @@ -134,7 +134,10 @@ octave_value_list args = ovl (lhs_val); args.stash_name_tags (string_vector (m_lhs->name ())); - feval ("display", args); + + interpreter& interp = tw.get_interpreter (); + + interp.feval ("display", args); } } catch (index_exception& ie) @@ -156,7 +159,7 @@ : tree_expression (l, c), m_lhs (lst), m_rhs (r), m_preserve (plhs) { } -tree_multi_assignment::~tree_multi_assignment (void) +tree_multi_assignment::~tree_multi_assignment () { if (! m_preserve) delete m_lhs; @@ -165,7 +168,7 @@ } std::string -tree_multi_assignment::oper (void) const +tree_multi_assignment::oper () const { return octave_value::assign_op_as_string (op_type ()); } @@ -339,7 +342,10 @@ octave_value_list args = ovl (lhs_val); args.stash_name_tags (string_vector (lhs_elt->name ())); - feval ("display", args); + + interpreter& interp = tw.get_interpreter (); + + interp.feval ("display", args); } } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-assign.h --- a/libinterp/parse-tree/pt-assign.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-assign.h Mon Jan 30 18:36:03 2023 +0100 @@ -66,17 +66,17 @@ tree_simple_assignment& operator = (const tree_simple_assignment&) = delete; - ~tree_simple_assignment (void); + ~tree_simple_assignment (); - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } - bool is_assignment_expression (void) const { return true; } + bool is_assignment_expression () const { return true; } - std::string oper (void) const; + std::string oper () const; - tree_expression * left_hand_side (void) { return m_lhs; } + tree_expression * left_hand_side () { return m_lhs; } - tree_expression * right_hand_side (void) { return m_rhs; } + tree_expression * right_hand_side () { return m_rhs; } tree_expression * dup (symbol_scope& scope) const; @@ -92,7 +92,7 @@ tw.visit_simple_assignment (*this); } - octave_value::assign_op op_type (void) const { return m_etype; } + octave_value::assign_op op_type () const { return m_etype; } private: @@ -137,17 +137,17 @@ tree_multi_assignment& operator = (const tree_multi_assignment&) = delete; - ~tree_multi_assignment (void); + ~tree_multi_assignment (); - bool is_assignment_expression (void) const { return true; } + bool is_assignment_expression () const { return true; } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } - std::string oper (void) const; + std::string oper () const; - tree_argument_list * left_hand_side (void) { return m_lhs; } + tree_argument_list * left_hand_side () { return m_lhs; } - tree_expression * right_hand_side (void) { return m_rhs; } + tree_expression * right_hand_side () { return m_rhs; } tree_expression * dup (symbol_scope& scope) const; @@ -165,7 +165,7 @@ tw.visit_multi_assignment (*this); } - octave_value::assign_op op_type (void) const + octave_value::assign_op op_type () const { return octave_value::op_asn_eq; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-binop.cc --- a/libinterp/parse-tree/pt-binop.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-binop.cc Mon Jan 30 18:36:03 2023 +0100 @@ -48,7 +48,7 @@ } std::string -tree_binary_expression::oper (void) const +tree_binary_expression::oper () const { return octave_value::binary_op_as_string (m_etype); } @@ -164,7 +164,7 @@ // Boolean expressions. std::string -tree_boolean_expression::oper (void) const +tree_boolean_expression::oper () const { std::string retval = ""; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-binop.h --- a/libinterp/parse-tree/pt-binop.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-binop.h Mon Jan 30 18:36:03 2023 +0100 @@ -68,7 +68,7 @@ tree_binary_expression& operator = (const tree_binary_expression&) = delete; - ~tree_binary_expression (void) + ~tree_binary_expression () { if (! m_preserve_operands) { @@ -77,18 +77,18 @@ } } - void preserve_operands (void) { m_preserve_operands = true; } + void preserve_operands () { m_preserve_operands = true; } - bool is_binary_expression (void) const { return true; } + bool is_binary_expression () const { return true; } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } - std::string oper (void) const; + std::string oper () const; - octave_value::binary_op op_type (void) const { return m_etype; } + octave_value::binary_op op_type () const { return m_etype; } - tree_expression * lhs (void) { return m_lhs; } - tree_expression * rhs (void) { return m_rhs; } + tree_expression * lhs () { return m_lhs; } + tree_expression * rhs () { return m_rhs; } void lhs (tree_expression *expr) { m_lhs = expr; } void rhs (tree_expression *expr) { m_rhs = expr; } @@ -107,7 +107,7 @@ tw.visit_binary_expression (*this); } - std::string profiler_name (void) const { return "binary " + oper (); } + std::string profiler_name () const { return "binary " + oper (); } void matlab_style_short_circuit_warning (const char *op); @@ -146,7 +146,7 @@ tree_braindead_shortcircuit_binary_expression& operator = (const tree_braindead_shortcircuit_binary_expression&) = delete; - ~tree_braindead_shortcircuit_binary_expression (void) = default; + ~tree_braindead_shortcircuit_binary_expression () = default; tree_expression * dup (symbol_scope& scope) const; @@ -181,15 +181,15 @@ tree_boolean_expression& operator = (const tree_boolean_expression&) = delete; - ~tree_boolean_expression (void) = default; + ~tree_boolean_expression () = default; - bool is_boolean_expression (void) const { return true; } + bool is_boolean_expression () const { return true; } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } - std::string oper (void) const; + std::string oper () const; - type op_type (void) const { return m_etype; } + type op_type () const { return m_etype; } tree_expression * dup (symbol_scope& scope) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-bp.h --- a/libinterp/parse-tree/pt-bp.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-bp.h Mon Jan 30 18:36:03 2023 +0100 @@ -56,9 +56,9 @@ tree_breakpoint& operator = (const tree_breakpoint&) = delete; - ~tree_breakpoint (void) = default; + ~tree_breakpoint () = default; - bool success (void) const { return m_found; } + bool success () const { return m_found; } void visit_argument_list (tree_argument_list&); @@ -147,11 +147,11 @@ void visit_unwind_protect_command (tree_unwind_protect_command&); - octave_value_list get_list (void) { return m_bp_list; } + octave_value_list get_list () { return m_bp_list; } - octave_value_list get_cond_list (void) { return m_bp_cond_list; } + octave_value_list get_cond_list () { return m_bp_cond_list; } - int get_line (void) { return m_found ? m_line : 0; } + int get_line () { return m_found ? m_line : 0; } private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-cbinop.h --- a/libinterp/parse-tree/pt-cbinop.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-cbinop.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,12 +54,12 @@ m_etype (ct) { } - octave_value::compound_binary_op cop_type (void) const { return m_etype; } + octave_value::compound_binary_op cop_type () const { return m_etype; } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } - tree_expression * clhs (void) { return m_lhs; } - tree_expression * crhs (void) { return m_rhs; } + tree_expression * clhs () { return m_lhs; } + tree_expression * crhs () { return m_rhs; } octave_value evaluate (tree_evaluator&, int nargout = 1); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-cell.h --- a/libinterp/parse-tree/pt-cell.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-cell.h Mon Jan 30 18:36:03 2023 +0100 @@ -57,11 +57,11 @@ tree_cell& operator = (const tree_cell&) = delete; - ~tree_cell (void) = default; + ~tree_cell () = default; - bool iscell (void) const { return true; } + bool iscell () const { return true; } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } tree_expression * dup (symbol_scope& scope) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-check.h --- a/libinterp/parse-tree/pt-check.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-check.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ { public: - tree_checker (void) + tree_checker () : m_do_lvalue_check (false), m_file_name () { } // No copying! @@ -51,7 +51,7 @@ tree_checker& operator = (const tree_checker&) = delete; - ~tree_checker (void) = default; + ~tree_checker () = default; void visit_argument_list (tree_argument_list&); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-classdef.cc --- a/libinterp/parse-tree/pt-classdef.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-classdef.cc Mon Jan 30 18:36:03 2023 +0100 @@ -95,7 +95,7 @@ // Classdef attribute_list -tree_classdef_attribute_list::~tree_classdef_attribute_list (void) +tree_classdef_attribute_list::~tree_classdef_attribute_list () { while (! empty ()) { @@ -109,7 +109,7 @@ // Classdef superclass_list -tree_classdef_superclass_list::~tree_classdef_superclass_list (void) +tree_classdef_superclass_list::~tree_classdef_superclass_list () { while (! empty ()) { @@ -143,26 +143,26 @@ m_doc_string (check_for_doc_string (m_comments)) { } -tree_classdef_property::~tree_classdef_property (void) +tree_classdef_property::~tree_classdef_property () { delete m_av; } -tree_identifier *tree_classdef_property::ident (void) +tree_identifier *tree_classdef_property::ident () { tree_expression *id_expr = m_av->identifier_expression (); return dynamic_cast (id_expr); } -tree_expression *tree_classdef_property::expression (void) +tree_expression *tree_classdef_property::expression () { return m_av->initializer_expression (); } // Classdef property_list -tree_classdef_property_list::~tree_classdef_property_list (void) +tree_classdef_property_list::~tree_classdef_property_list () { while (! empty ()) { @@ -188,7 +188,7 @@ // Classdef events_list -tree_classdef_events_list::~tree_classdef_events_list (void) +tree_classdef_events_list::~tree_classdef_events_list () { while (! empty ()) { @@ -211,7 +211,7 @@ // Classdef enum_list -tree_classdef_enum_list::~tree_classdef_enum_list (void) +tree_classdef_enum_list::~tree_classdef_enum_list () { while (! empty ()) { @@ -225,7 +225,7 @@ // Classdef body -tree_classdef_body::tree_classdef_body (void) +tree_classdef_body::tree_classdef_body () : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst () { } @@ -257,7 +257,7 @@ append (enb); } -tree_classdef_body::~tree_classdef_body (void) +tree_classdef_body::~tree_classdef_body () { while (! m_properties_lst.empty ()) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-classdef.h --- a/libinterp/parse-tree/pt-classdef.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-classdef.h Mon Jan 30 18:36:03 2023 +0100 @@ -50,7 +50,7 @@ { public: - tree_superclass_ref (void) = delete; + tree_superclass_ref () = delete; tree_superclass_ref (const std::string& meth, const std::string& cls, int l = -1, int c = -1) @@ -63,12 +63,12 @@ tree_superclass_ref& operator = (const tree_superclass_ref&) = delete; - std::string method_name (void) const + std::string method_name () const { return m_method_name; } - std::string class_name (void) const { return m_class_name; } + std::string class_name () const { return m_class_name; } tree_superclass_ref * dup (symbol_scope& scope) const; @@ -101,7 +101,7 @@ { public: - tree_metaclass_query (void) = delete; + tree_metaclass_query () = delete; tree_metaclass_query (const std::string& cls, int l = -1, int c = -1) : tree_expression (l, c), m_class_name (cls) @@ -113,7 +113,7 @@ tree_metaclass_query& operator = (const tree_metaclass_query&) = delete; - std::string class_name (void) const { return m_class_name; } + std::string class_name () const { return m_class_name; } tree_metaclass_query * dup (symbol_scope& scope) const; @@ -153,17 +153,17 @@ tree_classdef_attribute& operator = (const tree_classdef_attribute&) = delete; - ~tree_classdef_attribute (void) + ~tree_classdef_attribute () { delete m_id; delete m_expr; } - tree_identifier * ident (void) { return m_id; } + tree_identifier * ident () { return m_id; } - tree_expression * expression (void) { return m_expr; } + tree_expression * expression () { return m_expr; } - bool negate (void) { return m_neg; } + bool negate () { return m_neg; } void accept (tree_walker& tw) { @@ -181,7 +181,7 @@ { public: - tree_classdef_attribute_list (void) { } + tree_classdef_attribute_list () { } tree_classdef_attribute_list (tree_classdef_attribute *a) { append (a); } @@ -196,7 +196,7 @@ tree_classdef_attribute_list& operator = (const tree_classdef_attribute_list&) = delete; - ~tree_classdef_attribute_list (void); + ~tree_classdef_attribute_list (); void accept (tree_walker& tw) { @@ -219,9 +219,9 @@ tree_classdef_superclass& operator = (const tree_classdef_superclass&) = delete; - ~tree_classdef_superclass (void) = default; + ~tree_classdef_superclass () = default; - std::string class_name (void) { return m_cls_name; } + std::string class_name () { return m_cls_name; } void accept (tree_walker& tw) { @@ -238,7 +238,7 @@ { public: - tree_classdef_superclass_list (void) { } + tree_classdef_superclass_list () { } tree_classdef_superclass_list (tree_classdef_superclass *sc) { @@ -256,7 +256,7 @@ tree_classdef_superclass_list& operator = (const tree_classdef_superclass_list&) = delete; - ~tree_classdef_superclass_list (void); + ~tree_classdef_superclass_list (); void accept (tree_walker& tw) { @@ -282,7 +282,7 @@ tree_classdef_element& operator = (const tree_classdef_element&) = delete; - ~tree_classdef_element (void) + ~tree_classdef_element () { delete m_attr_list; delete m_elt_list; @@ -290,13 +290,13 @@ delete m_trail_comm; } - tree_classdef_attribute_list * attribute_list (void) { return m_attr_list; } + tree_classdef_attribute_list * attribute_list () { return m_attr_list; } - T * element_list (void) { return m_elt_list; } + T * element_list () { return m_elt_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker&) { } @@ -328,19 +328,19 @@ tree_classdef_property& operator = (const tree_classdef_property&) = delete; - ~tree_classdef_property (void); + ~tree_classdef_property (); - tree_identifier * ident (void); + tree_identifier * ident (); - tree_expression * expression (void); + tree_expression * expression (); - comment_list * comments (void) const { return m_comments; } + comment_list * comments () const { return m_comments; } void doc_string (const std::string& txt) { m_doc_string = txt; } - std::string doc_string (void) const { return m_doc_string; } + std::string doc_string () const { return m_doc_string; } - bool have_doc_string (void) const { return ! m_doc_string.empty (); } + bool have_doc_string () const { return ! m_doc_string.empty (); } void accept (tree_walker& tw) { @@ -358,7 +358,7 @@ { public: - tree_classdef_property_list (void) { } + tree_classdef_property_list () { } tree_classdef_property_list (tree_classdef_property *p) { append (p); } @@ -372,7 +372,7 @@ tree_classdef_property_list& operator = (const tree_classdef_property_list&) = delete; - ~tree_classdef_property_list (void); + ~tree_classdef_property_list (); void accept (tree_walker& tw) { @@ -399,7 +399,7 @@ tree_classdef_properties_block& operator = (const tree_classdef_properties_block&) = delete; - ~tree_classdef_properties_block (void) = default; + ~tree_classdef_properties_block () = default; void accept (tree_walker& tw) { @@ -411,7 +411,7 @@ { public: - tree_classdef_methods_list (void) { } + tree_classdef_methods_list () { } tree_classdef_methods_list (const octave_value& f) { append (f); } @@ -425,7 +425,7 @@ tree_classdef_methods_list& operator = (const tree_classdef_methods_list&) = delete; - ~tree_classdef_methods_list (void) = default; + ~tree_classdef_methods_list () = default; void accept (tree_walker& tw) { @@ -452,7 +452,7 @@ tree_classdef_methods_block& operator = (const tree_classdef_methods_block&) = delete; - ~tree_classdef_methods_block (void) = default; + ~tree_classdef_methods_block () = default; void accept (tree_walker& tw) { @@ -473,20 +473,20 @@ tree_classdef_event& operator = (const tree_classdef_event&) = delete; - ~tree_classdef_event (void) + ~tree_classdef_event () { delete m_id; } - tree_identifier * ident (void) { return m_id; } + tree_identifier * ident () { return m_id; } - comment_list * comments (void) const { return m_comments; } + comment_list * comments () const { return m_comments; } void doc_string (const std::string& txt) { m_doc_string = txt; } - std::string doc_string (void) const { return m_doc_string; } + std::string doc_string () const { return m_doc_string; } - bool have_doc_string (void) const { return ! m_doc_string.empty (); } + bool have_doc_string () const { return ! m_doc_string.empty (); } void accept (tree_walker& tw) { @@ -504,7 +504,7 @@ { public: - tree_classdef_events_list (void) { } + tree_classdef_events_list () { } tree_classdef_events_list (tree_classdef_event *e) { append (e); } @@ -519,7 +519,7 @@ tree_classdef_events_list& operator = (const tree_classdef_events_list&) = delete; - ~tree_classdef_events_list (void); + ~tree_classdef_events_list (); void accept (tree_walker& tw) { @@ -546,7 +546,7 @@ tree_classdef_events_block& operator = (const tree_classdef_events_block&) = delete; - ~tree_classdef_events_block (void) = default; + ~tree_classdef_events_block () = default; void accept (tree_walker& tw) { @@ -567,23 +567,23 @@ tree_classdef_enum& operator = (const tree_classdef_enum&) = delete; - ~tree_classdef_enum (void) + ~tree_classdef_enum () { delete m_id; delete m_expr; } - tree_identifier * ident (void) { return m_id; } + tree_identifier * ident () { return m_id; } - tree_expression * expression (void) { return m_expr; } + tree_expression * expression () { return m_expr; } - comment_list * comments (void) const { return m_comments; } + comment_list * comments () const { return m_comments; } void doc_string (const std::string& txt) { m_doc_string = txt; } - std::string doc_string (void) const { return m_doc_string; } + std::string doc_string () const { return m_doc_string; } - bool have_doc_string (void) const { return ! m_doc_string.empty (); } + bool have_doc_string () const { return ! m_doc_string.empty (); } void accept (tree_walker& tw) { @@ -602,7 +602,7 @@ { public: - tree_classdef_enum_list (void) { } + tree_classdef_enum_list () { } tree_classdef_enum_list (tree_classdef_enum *e) { append (e); } @@ -616,7 +616,7 @@ tree_classdef_enum_list& operator = (const tree_classdef_enum_list&) = delete; - ~tree_classdef_enum_list (void); + ~tree_classdef_enum_list (); void accept (tree_walker& tw) { @@ -643,7 +643,7 @@ tree_classdef_enum_block& operator = (const tree_classdef_enum_block&) = delete; - ~tree_classdef_enum_block (void) = default; + ~tree_classdef_enum_block () = default; void accept (tree_walker& tw) { @@ -673,7 +673,7 @@ typedef std::list::const_iterator enum_list_const_iterator; - tree_classdef_body (void); + tree_classdef_body (); tree_classdef_body (tree_classdef_properties_block *pb); @@ -689,7 +689,7 @@ tree_classdef_body& operator = (const tree_classdef_body&) = delete; - ~tree_classdef_body (void); + ~tree_classdef_body (); void append (tree_classdef_properties_block *pb) { @@ -711,31 +711,31 @@ m_enum_lst.push_back (enb); } - std::list properties_list (void) + std::list properties_list () { return m_properties_lst; } - std::list methods_list (void) + std::list methods_list () { return m_methods_lst; } - std::list events_list (void) + std::list events_list () { return m_events_lst; } - std::list enum_list (void) + std::list enum_list () { return m_enum_lst; } void doc_string (const std::string& txt) { m_doc_string = txt; } - std::string doc_string (void) const { return m_doc_string; } + std::string doc_string () const { return m_doc_string; } - bool have_doc_string (void) const { return ! m_doc_string.empty (); } + bool have_doc_string () const { return ! m_doc_string.empty (); } void accept (tree_walker& tw) { @@ -780,7 +780,7 @@ tree_classdef& operator = (const tree_classdef&) = delete; - ~tree_classdef (void) + ~tree_classdef () { delete m_attr_list; delete m_id; @@ -790,29 +790,29 @@ delete m_trail_comm; } - symbol_scope scope (void) { return m_scope; } + symbol_scope scope () { return m_scope; } tree_classdef_attribute_list * - attribute_list (void) { return m_attr_list; } + attribute_list () { return m_attr_list; } - tree_identifier * ident (void) { return m_id; } + tree_identifier * ident () { return m_id; } tree_classdef_superclass_list * - superclass_list (void) { return m_supclass_list; } + superclass_list () { return m_supclass_list; } - tree_classdef_body * body (void) { return m_element_list; } + tree_classdef_body * body () { return m_element_list; } - comment_list * leading_comment (void) { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * leading_comment () { return m_lead_comm; } + comment_list * trailing_comment () { return m_trail_comm; } - std::string package_name (void) const { return m_pack_name; } + std::string package_name () const { return m_pack_name; } - std::string file_name (void) const { return m_file_name; } + std::string file_name () const { return m_file_name; } octave_value make_meta_class (interpreter& interp, bool is_at_folder = false); - std::string doc_string (void) const + std::string doc_string () const { return m_element_list ? m_element_list->doc_string () : ""; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-cmd.h --- a/libinterp/parse-tree/pt-cmd.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-cmd.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ tree_command& operator = (const tree_command&) = delete; - virtual ~tree_command (void) = default; + virtual ~tree_command () = default; }; // No-op. @@ -71,21 +71,21 @@ tree_no_op_command& operator = (const tree_no_op_command&) = delete; - ~tree_no_op_command (void) = default; + ~tree_no_op_command () = default; void accept (tree_walker& tw) { tw.visit_no_op_command (*this); } - bool is_end_of_fcn_or_script (void) const + bool is_end_of_fcn_or_script () const { return (m_orig_cmd == "endfunction" || m_orig_cmd == "endscript"); } - bool is_end_of_file (void) const { return m_eof; } + bool is_end_of_file () const { return m_eof; } - std::string original_command (void) { return m_orig_cmd; } + std::string original_command () { return m_orig_cmd; } private: @@ -109,14 +109,14 @@ tree_function_def& operator = (const tree_function_def&) = delete; - ~tree_function_def (void) = default; + ~tree_function_def () = default; void accept (tree_walker& tw) { tw.visit_function_def (*this); } - octave_value function (void) { return m_fcn; } + octave_value function () { return m_fcn; } private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-colon.h --- a/libinterp/parse-tree/pt-colon.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-colon.h Mon Jan 30 18:36:03 2023 +0100 @@ -66,7 +66,7 @@ tree_colon_expression& operator = (const tree_colon_expression&) = delete; - ~tree_colon_expression (void) + ~tree_colon_expression () { if (! m_save_base) delete m_base; @@ -75,21 +75,21 @@ delete m_increment; } - void preserve_base (void) { m_save_base = true; } + void preserve_base () { m_save_base = true; } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } void eval_error (const std::string& s) const; - tree_expression * base (void) { return m_base; } + tree_expression * base () { return m_base; } - tree_expression * limit (void) { return m_limit; } + tree_expression * limit () { return m_limit; } - tree_expression * increment (void) { return m_increment; } + tree_expression * increment () { return m_increment; } tree_expression * dup (symbol_scope& scope) const; - bool is_colon_expression (void) const { return true; } + bool is_colon_expression () const { return true; } octave_value evaluate (tree_evaluator&, int nargout = 1); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-const.h --- a/libinterp/parse-tree/pt-const.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-const.h Mon Jan 30 18:36:03 2023 +0100 @@ -67,13 +67,13 @@ tree_constant& operator = (const tree_constant&) = delete; - ~tree_constant (void) = default; + ~tree_constant () = default; // Type. It would be nice to eliminate the need for this. - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - void maybe_mutate (void) { m_value.maybe_mutate (); } + void maybe_mutate () { m_value.maybe_mutate (); } void print (std::ostream& os, bool pr_as_read_syntax = false, bool pr_orig_txt = true); @@ -81,9 +81,9 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false, bool pr_orig_txt = true); - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } - octave_value value (void) { return m_value; } + octave_value value () { return m_value; } tree_expression * dup (symbol_scope& scope) const; @@ -97,7 +97,7 @@ void stash_original_text (const std::string& s) { m_orig_text = s; } - std::string original_text (void) const { return m_orig_text; } + std::string original_text () const { return m_orig_text; } octave_value evaluate (tree_evaluator&, int nargout = 1) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-decl.cc --- a/libinterp/parse-tree/pt-decl.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-decl.cc Mon Jan 30 18:36:03 2023 +0100 @@ -51,7 +51,7 @@ error ("tree_decl_elt: invalid ID"); } -tree_decl_elt::~tree_decl_elt (void) +tree_decl_elt::~tree_decl_elt () { delete m_id; delete m_expr; @@ -84,7 +84,7 @@ } } -tree_decl_command::~tree_decl_command (void) +tree_decl_command::~tree_decl_command () { delete m_init_list; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-decl.h --- a/libinterp/parse-tree/pt-decl.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-decl.h Mon Jan 30 18:36:03 2023 +0100 @@ -65,31 +65,31 @@ tree_decl_elt& operator = (const tree_decl_elt&) = delete; - ~tree_decl_elt (void); + ~tree_decl_elt (); - void mark_as_formal_parameter (void) + void mark_as_formal_parameter () { m_id->mark_as_formal_parameter (); } - bool lvalue_ok (void) { return m_id->lvalue_ok (); } + bool lvalue_ok () { return m_id->lvalue_ok (); } octave_lvalue lvalue (tree_evaluator& tw) { return m_id->lvalue (tw); } - void mark_global (void) { type = global; } - bool is_global (void) const { return type == global; } + void mark_global () { type = global; } + bool is_global () const { return type == global; } - void mark_persistent (void) { type = persistent; } - bool is_persistent (void) const { return type == persistent; } + void mark_persistent () { type = persistent; } + bool is_persistent () const { return type == persistent; } - tree_identifier * ident (void) { return m_id; } + tree_identifier * ident () { return m_id; } - std::string name (void) const { return m_id->name (); } + std::string name () const { return m_id->name (); } - tree_expression * expression (void) { return m_expr; } + tree_expression * expression () { return m_expr; } tree_decl_elt * dup (symbol_scope& scope) const; @@ -113,7 +113,7 @@ { public: - tree_decl_init_list (void) { } + tree_decl_init_list () { } tree_decl_init_list (tree_decl_elt *t) { append (t); } @@ -123,7 +123,7 @@ tree_decl_init_list& operator = (const tree_decl_init_list&) = delete; - ~tree_decl_init_list (void) + ~tree_decl_init_list () { while (! empty ()) { @@ -133,19 +133,19 @@ } } - void mark_global (void) + void mark_global () { for (tree_decl_elt *elt : *this) elt->mark_global (); } - void mark_persistent (void) + void mark_persistent () { for (tree_decl_elt *elt : *this) elt->mark_persistent (); } - std::list variable_names (void) const + std::list variable_names () const { std::list retval; @@ -184,23 +184,23 @@ tree_decl_command& operator = (const tree_decl_command&) = delete; - ~tree_decl_command (void); + ~tree_decl_command (); - void mark_global (void) + void mark_global () { if (m_init_list) m_init_list->mark_global (); } - void mark_persistent (void) + void mark_persistent () { if (m_init_list) m_init_list->mark_persistent (); } - tree_decl_init_list * initializer_list (void) { return m_init_list; } + tree_decl_init_list * initializer_list () { return m_init_list; } - std::string name (void) const { return m_cmd_name; } + std::string name () const { return m_cmd_name; } void accept (tree_walker& tw) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-eval.cc --- a/libinterp/parse-tree/pt-eval.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-eval.cc Mon Jan 30 18:36:03 2023 +0100 @@ -75,616 +75,855 @@ OCTAVE_BEGIN_NAMESPACE(octave) -// Normal evaluator. - -class quit_debug_exception -{ -public: - - quit_debug_exception (bool all = false) : m_all (all) { } - - quit_debug_exception (const quit_debug_exception&) = default; - - quit_debug_exception& operator = (const quit_debug_exception&) = default; - - ~quit_debug_exception (void) = default; - - bool all (void) const { return m_all; } - -private: - - bool m_all; -}; - -class debugger -{ -public: - - enum execution_mode - { - EX_NORMAL = 0, - EX_CONTINUE = 1, - EX_QUIT = 2, - EX_QUIT_ALL = 3 + // Normal evaluator. + + class quit_debug_exception + { + public: + + quit_debug_exception (bool all = false) : m_all (all) { } + + quit_debug_exception (const quit_debug_exception&) = default; + + quit_debug_exception& operator = (const quit_debug_exception&) = default; + + ~quit_debug_exception () = default; + + bool all () const { return m_all; } + + private: + + bool m_all; }; - debugger (interpreter& interp, std::size_t level) - : m_interpreter (interp), m_level (level), - m_execution_mode (EX_NORMAL), m_in_debug_repl (false) - { } - - int server_loop (void); - - void repl (const std::string& prompt = "debug> "); - - bool in_debug_repl (void) const { return m_in_debug_repl; } - - void dbcont (void) { m_execution_mode = EX_CONTINUE; } - - void dbquit (bool all = false) - { - if (all) - m_execution_mode = EX_QUIT_ALL; - else - m_execution_mode = EX_QUIT; - } - - bool quitting_debugger (void) const; - -private: - - interpreter& m_interpreter; - - std::size_t m_level; - execution_mode m_execution_mode; - bool m_in_debug_repl; -}; - -// FIXME: Could the debugger server_loop and repl functions be merged -// with the corresponding tree_evaluator functions or do they need to -// remain separate? They perform nearly the same functions. - -int debugger::server_loop (void) -{ - // Process events from the event queue. - - tree_evaluator& tw = m_interpreter.get_evaluator (); - - void (tree_evaluator::*server_mode_fptr) (bool) - = &tree_evaluator::server_mode; - unwind_action act (server_mode_fptr, &tw, true); - - int exit_status = 0; - - do - { - if (m_execution_mode == EX_CONTINUE || tw.dbstep_flag ()) - break; - - if (quitting_debugger ()) - break; - - try - { - // FIXME: Should we call octave_quit in the octave::sleep - // and/or command_editor::run_event_hooks functions? - - octave_quit (); - - // FIXME: Running the event queue should be decoupled from - // the command_editor. - - // FIXME: Is it OK to use command_editor::run_event_hooks - // here? It may run more than one queued function per call, - // and it seems that the checks at the top of the loop - // probably need to be done after each individual event - // function is executed. For now, maybe the simplest thing - // would be to pass a predicate function (lambda expression) - // to the command_editor::run_event_hooks and have it check - // that and break out of the eval loop(s) if the condition - // is met? - - // FIXME: We should also use a condition variable to manage - // the execution of entries in the queue and eliminate the - // need for the busy-wait loop. - - command_editor::run_event_hooks (); - - release_unreferenced_dynamic_libraries (); - - sleep (0.1); - } - catch (const interrupt_exception&) - { - octave_interrupt_state = 1; - m_interpreter.recover_from_exception (); - - // Required newline when the user does Ctrl+C at the prompt. - if (m_interpreter.interactive ()) - octave_stdout << "\n"; - } - catch (const index_exception& e) - { - m_interpreter.recover_from_exception (); - - std::cerr << "error: unhandled index exception: " - << e.message () << " -- trying to return to prompt" - << std::endl; - } - catch (const execution_exception& ee) - { - error_system& es = m_interpreter.get_error_system (); - - es.save_exception (ee); - es.display_exception (ee); - - if (m_interpreter.interactive ()) - { - m_interpreter.recover_from_exception (); - } - else - { - // We should exit with a nonzero status. - exit_status = 1; - break; - } - } - catch (const quit_debug_exception& qde) - { - if (qde.all ()) - throw; - - // Continue in this debug level. - } - catch (const std::bad_alloc&) - { - m_interpreter.recover_from_exception (); - - std::cerr << "error: out of memory -- trying to return to prompt" - << std::endl; - } - } - while (exit_status == 0); - - if (exit_status == EOF) - { - if (m_interpreter.interactive ()) - octave_stdout << "\n"; - - exit_status = 0; - } - - return exit_status; -} - -void debugger::repl (const std::string& prompt_arg) -{ - unwind_protect frame; - - frame.protect_var (m_in_debug_repl); - frame.protect_var (m_execution_mode); - - m_in_debug_repl = true; - - tree_evaluator& tw = m_interpreter.get_evaluator (); - - bool silent = tw.quiet_breakpoint_flag (false); - - frame.add (&tree_evaluator::restore_frame, &tw, - tw.current_call_stack_frame_number ()); - - tw.goto_frame (tw.debug_frame ()); - - octave_user_code *caller = tw.current_user_code (); - std::string fcn_file_nm, fcn_nm; - - if (caller) - { - fcn_file_nm = caller->fcn_file_name (); - fcn_nm = fcn_file_nm.empty () ? caller->name () : fcn_file_nm; - } - - int curr_debug_line = tw.current_line (); - - std::ostringstream buf; - - input_system& input_sys = m_interpreter.get_input_system (); - - event_manager& evmgr = m_interpreter.get_event_manager (); - - if (! fcn_nm.empty ()) - { - if (input_sys.gud_mode ()) - { - static char ctrl_z = 'Z' & 0x1f; - - buf << ctrl_z << ctrl_z << fcn_nm << ':' << curr_debug_line; - } - else - { - // FIXME: we should come up with a clean way to detect - // that we are stopped on the no-op command that marks the - // end of a function or script. - - if (! silent) - { - std::shared_ptr frm = tw.current_user_frame (); - - frm->display_stopped_in_message (buf); - } - - evmgr.enter_debugger_event (fcn_nm, fcn_file_nm, curr_debug_line); - - evmgr.set_workspace (); - - frame.add (&event_manager::execute_in_debugger_event, &evmgr, - fcn_nm, curr_debug_line); - - if (! silent) - { - std::string line_buf; - - if (caller) - line_buf = caller->get_code_line (curr_debug_line); - - if (! line_buf.empty ()) - buf << curr_debug_line << ": " << line_buf; - } - } - } - - if (silent) - command_editor::erase_empty_line (true); - - std::string stopped_in_msg = buf.str (); - - if (m_interpreter.server_mode ()) - { - if (! stopped_in_msg.empty ()) - octave_stdout << stopped_in_msg << std::endl; - - evmgr.push_event_queue (); - - frame.add (&event_manager::pop_event_queue, &evmgr); - - frame.add (&tree_evaluator::set_parser, &tw, tw.get_parser ()); - - std::shared_ptr - debug_parser (new push_parser (m_interpreter)); - - tw.set_parser (debug_parser); - - server_loop (); - } - else + class debugger + { + public: + + enum execution_mode + { + EX_NORMAL = 0, + EX_CONTINUE = 1, + EX_QUIT = 2, + EX_QUIT_ALL = 3 + }; + + debugger (interpreter& interp, std::size_t level) + : m_interpreter (interp), m_level (level), + m_execution_mode (EX_NORMAL), m_in_debug_repl (false) + { } + + int server_loop (); + + void repl (const std::string& prompt = "debug> "); + + bool in_debug_repl () const { return m_in_debug_repl; } + + void dbcont () { m_execution_mode = EX_CONTINUE; } + + void dbquit (bool all = false) { - if (! stopped_in_msg.empty ()) - std::cerr << stopped_in_msg << std::endl; - - std::string tmp_prompt = prompt_arg; - if (m_level > 0) - tmp_prompt = "[" + std::to_string (m_level) + "]" + prompt_arg; - - frame.add (&input_system::set_PS1, &input_sys, input_sys.PS1 ()); - input_sys.PS1 (tmp_prompt); - - if (! m_interpreter.interactive ()) - { - void (interpreter::*interactive_fptr) (bool) - = &interpreter::interactive; - frame.add (interactive_fptr, &m_interpreter, - m_interpreter.interactive ()); - - m_interpreter.interactive (true); - - // FIXME: should debugging be possible in an embedded - // interpreter? - - application *app = application::app (); - - if (app) - { - void (application::*forced_interactive_fptr) (bool) - = &application::forced_interactive; - frame.add (forced_interactive_fptr, app, - app->forced_interactive ()); - - app->forced_interactive (true); - } - } - -#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER) - - input_reader reader (m_interpreter); - - push_parser debug_parser (m_interpreter); - -#else - - parser debug_parser (m_interpreter); - -#endif - - error_system& es = m_interpreter.get_error_system (); - - while (m_in_debug_repl) - { - if (m_execution_mode == EX_CONTINUE || tw.dbstep_flag ()) - break; - - if (quitting_debugger ()) - break; - - try - { - debug_parser.reset (); - -#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER) - - int retval = 0; - - std::string prompt - = command_editor::decode_prompt_string (tmp_prompt); - - do - { - bool eof = false; - std::string input_line = reader.get_input (prompt, eof); - - if (eof) - { - retval = EOF; - break; - } - - retval = debug_parser.run (input_line, false); - - prompt = command_editor::decode_prompt_string (input_sys.PS2 ()); - } - while (retval < 0); - -#else - - int retval = debug_parser.run (); - -#endif - if (command_editor::interrupt (false)) - { - // Break regardless of m_execution_mode value. - - quitting_debugger (); - - break; - } - else - { - if (retval == 0) - { - std::shared_ptr stmt_list - = debug_parser.statement_list (); - - if (stmt_list) - stmt_list->accept (tw); - - if (octave_completion_matches_called) - octave_completion_matches_called = false; - - // FIXME: the following statement is here because - // the last command may have been a dbup, dbdown, or - // dbstep command that changed the current debug - // frame. If so, we need to reset the current frame - // for the call stack. But is this right way to do - // this job? What if the statement list was - // something like "dbup; dbstack"? Will the call to - // dbstack use the right frame? If not, how can we - // fix this problem? - tw.goto_frame (tw.debug_frame ()); - } - - octave_quit (); - } - } - catch (const execution_exception& ee) - { - es.save_exception (ee); - es.display_exception (ee); - - // Ignore errors when in debugging mode; - m_interpreter.recover_from_exception (); - } - catch (const quit_debug_exception& qde) - { - if (qde.all ()) - throw; - - // Continue in this debug level. - } - } - } -} - -bool debugger::quitting_debugger (void) const -{ - if (m_execution_mode == EX_QUIT) - { - // If there is no enclosing debug level or the top-level - // repl is not active, handle dbquit the same as dbcont. - - if (m_level > 0 || m_interpreter.server_mode () - || m_interpreter.in_top_level_repl ()) - throw quit_debug_exception (); + if (all) + m_execution_mode = EX_QUIT_ALL; else - return true; + m_execution_mode = EX_QUIT; } - if (m_execution_mode == EX_QUIT_ALL) - { - // If the top-level repl is not active, handle "dbquit all" - // the same as dbcont. - - if (m_interpreter.server_mode () || m_interpreter.in_top_level_repl ()) - throw quit_debug_exception (true); - else - return true; - } - - return false; -} - -bool tree_evaluator::at_top_level (void) const -{ - return m_call_stack.at_top_level (); -} - -std::string -tree_evaluator::mfilename (const std::string& opt) const -{ - std::string fname; - - octave_user_code *fcn = m_call_stack.current_user_code (); - - if (fcn) - { - fname = fcn->fcn_file_name (); - - if (fname.empty ()) - fname = fcn->name (); - } - - if (opt == "fullpathext") - return fname; - - std::size_t dpos = fname.rfind (sys::file_ops::dir_sep_char ()); - std::size_t epos = fname.rfind ('.'); - - if (epos <= dpos+1) - epos = std::string::npos; - - if (epos != std::string::npos) - fname = fname.substr (0, epos); - - if (opt == "fullpath") - return fname; - - if (dpos != std::string::npos) - fname = fname.substr (dpos+1); - - return fname; -} - -void tree_evaluator::parse_and_execute (const std::string& input, - bool& incomplete_parse) -{ - incomplete_parse = false; - - unwind_protect_var upv (m_in_top_level_repl, true); - - if (at_top_level ()) - { - dbstep_flag (0); - reset_debug_state (); - } - - // FIXME: OK to do this job here, or should it be in the functions - // that do the actual prompting? - - // Update the time stamp for the "prompt" so that automatically - // finding modified files based on file modification times will - // work. In the future, we may do something completely different to - // check for changes to files but for now, we rely on the prompt - // time stamp to limit the checks for file modification times. - - Vlast_prompt_time.stamp (); - - bool eof = false; - - event_manager& evmgr = m_interpreter.get_event_manager (); - - if (command_history::add (input)) - evmgr.append_history (input); - - m_exit_status = m_parser->run (input, eof); - - if (m_exit_status == 0) - { - std::shared_ptr - stmt_list = m_parser->statement_list (); - - if (stmt_list) - { - command_editor::increment_current_command_number (); - - eval (stmt_list, m_interpreter.interactive ()); - - evmgr.set_workspace (); - } - else if (m_parser->at_end_of_input ()) - m_exit_status = EOF; - } - else - incomplete_parse = true; - - // FIXME: Should we be checking m_exit_status or incomplete_parse or - // both here? Could EOF have a value other than -1, and is there - // possible confusion between that state and the parser returning -1? - - if (m_exit_status == -1) - m_exit_status = 0; - else - m_parser->reset (); - - evmgr.pre_input_event (); -} - -void tree_evaluator::get_line_and_eval (void) -{ - std::mutex mtx; - std::unique_lock lock (mtx); - std::condition_variable cv; - bool incomplete_parse = false; - bool evaluation_pending = false; - bool exiting = false; - - input_system& input_sys = m_interpreter.get_input_system (); - event_manager& evmgr = m_interpreter.get_event_manager (); - - while (true) - { - // FIXME: Detect EOF? Use readline? If - // so, then we need to disable idle event loop hook function - // execution. - - std::string ps = incomplete_parse ? input_sys.PS2 () : input_sys.PS1 (); - - std::cout << command_editor::decode_prompt_string (ps); - - std::string input; - std::getline (std::cin, input); - - if (input.empty ()) - continue; - - incomplete_parse = false; - evaluation_pending = true; - exiting = false; - - evmgr.post_event - ([&] (interpreter& interp) + bool quitting_debugger () const; + + private: + + interpreter& m_interpreter; + + std::size_t m_level; + execution_mode m_execution_mode; + bool m_in_debug_repl; + }; + + // FIXME: Could the debugger server_loop and repl functions be merged + // with the corresponding tree_evaluator functions or do they need to + // remain separate? They perform nearly the same functions. + + int debugger::server_loop () + { + // Process events from the event queue. + + tree_evaluator& tw = m_interpreter.get_evaluator (); + + void (tree_evaluator::*server_mode_fptr) (bool) + = &tree_evaluator::server_mode; + unwind_action act (server_mode_fptr, &tw, true); + + int exit_status = 0; + + do { - // INTERPRETER THREAD - - std::lock_guard local_lock (mtx); + if (m_execution_mode == EX_CONTINUE || tw.dbstep_flag ()) + break; + + if (quitting_debugger ()) + break; try { - interp.parse_and_execute (input, incomplete_parse); + // FIXME: Should we call octave_quit in the octave::sleep + // and/or command_editor::run_event_hooks functions? + + octave_quit (); + + // FIXME: Running the event queue should be decoupled from + // the command_editor. + + // FIXME: Is it OK to use command_editor::run_event_hooks + // here? It may run more than one queued function per call, + // and it seems that the checks at the top of the loop + // probably need to be done after each individual event + // function is executed. For now, maybe the simplest thing + // would be to pass a predicate function (lambda expression) + // to the command_editor::run_event_hooks and have it check + // that and break out of the eval loop(s) if the condition + // is met? + + // FIXME: We should also use a condition variable to manage + // the execution of entries in the queue and eliminate the + // need for the busy-wait loop. + + command_editor::run_event_hooks (); + + release_unreferenced_dynamic_libraries (); + + sleep (0.1); + } + catch (const interrupt_exception&) + { + octave_interrupt_state = 1; + m_interpreter.recover_from_exception (); + + // Required newline when the user does Ctrl+C at the prompt. + if (m_interpreter.interactive ()) + octave_stdout << "\n"; + } + catch (const index_exception& e) + { + m_interpreter.recover_from_exception (); + + std::cerr << "error: unhandled index exception: " + << e.message () << " -- trying to return to prompt" + << std::endl; + } + catch (const execution_exception& ee) + { + error_system& es = m_interpreter.get_error_system (); + + es.save_exception (ee); + es.display_exception (ee); + + if (m_interpreter.interactive ()) + { + m_interpreter.recover_from_exception (); + } + else + { + // We should exit with a nonzero status. + exit_status = 1; + break; + } + } + catch (const quit_debug_exception& qde) + { + if (qde.all ()) + throw; + + // Continue in this debug level. + } + catch (const std::bad_alloc&) + { + m_interpreter.recover_from_exception (); + + std::cerr << "error: out of memory -- trying to return to prompt" + << std::endl; } - catch (const exit_exception&) + } + while (exit_status == 0); + + if (exit_status == EOF) + { + if (m_interpreter.interactive ()) + octave_stdout << "\n"; + + exit_status = 0; + } + + return exit_status; + } + + void debugger::repl (const std::string& prompt_arg) + { + unwind_protect frame; + + frame.protect_var (m_in_debug_repl); + frame.protect_var (m_execution_mode); + + m_in_debug_repl = true; + + tree_evaluator& tw = m_interpreter.get_evaluator (); + + bool silent = tw.quiet_breakpoint_flag (false); + + frame.add (&tree_evaluator::restore_frame, &tw, + tw.current_call_stack_frame_number ()); + + tw.goto_frame (tw.debug_frame ()); + + octave_user_code *caller = tw.current_user_code (); + std::string fcn_file_nm, fcn_nm; + + if (caller) + { + fcn_file_nm = caller->fcn_file_name (); + fcn_nm = fcn_file_nm.empty () ? caller->name () : fcn_file_nm; + } + + int curr_debug_line = tw.current_line (); + + std::ostringstream buf; + + input_system& input_sys = m_interpreter.get_input_system (); + + event_manager& evmgr = m_interpreter.get_event_manager (); + + if (! fcn_nm.empty ()) + { + if (input_sys.gud_mode ()) + { + static char ctrl_z = 'Z' & 0x1f; + + buf << ctrl_z << ctrl_z << fcn_nm << ':' << curr_debug_line; + } + else + { + // FIXME: we should come up with a clean way to detect + // that we are stopped on the no-op command that marks the + // end of a function or script. + + if (! silent) + { + std::shared_ptr frm = tw.current_user_frame (); + + frm->display_stopped_in_message (buf); + } + + evmgr.enter_debugger_event (fcn_nm, fcn_file_nm, curr_debug_line); + + evmgr.set_workspace (); + + frame.add (&event_manager::execute_in_debugger_event, &evmgr, + fcn_nm, curr_debug_line); + + if (! silent) + { + std::string line_buf; + + if (caller) + line_buf = caller->get_code_line (curr_debug_line); + + if (! line_buf.empty ()) + buf << curr_debug_line << ": " << line_buf; + } + } + } + + if (silent) + command_editor::erase_empty_line (true); + + std::string stopped_in_msg = buf.str (); + + if (m_interpreter.server_mode ()) + { + if (! stopped_in_msg.empty ()) + octave_stdout << stopped_in_msg << std::endl; + + evmgr.push_event_queue (); + + frame.add (&event_manager::pop_event_queue, &evmgr); + + frame.add (&tree_evaluator::set_parser, &tw, tw.get_parser ()); + + std::shared_ptr + debug_parser (new push_parser (m_interpreter)); + + tw.set_parser (debug_parser); + + server_loop (); + } + else + { + if (! stopped_in_msg.empty ()) + std::cerr << stopped_in_msg << std::endl; + + std::string tmp_prompt = prompt_arg; + if (m_level > 0) + tmp_prompt = "[" + std::to_string (m_level) + "]" + prompt_arg; + + frame.add (&interpreter::set_PS1, &m_interpreter, m_interpreter.PS1 ()); + m_interpreter.PS1 (tmp_prompt); + + if (! m_interpreter.interactive ()) + { + void (interpreter::*interactive_fptr) (bool) + = &interpreter::interactive; + frame.add (interactive_fptr, &m_interpreter, + m_interpreter.interactive ()); + + m_interpreter.interactive (true); + + // FIXME: should debugging be possible in an embedded + // interpreter? + + application *app = application::app (); + + if (app) + { + void (application::*forced_interactive_fptr) (bool) + = &application::forced_interactive; + frame.add (forced_interactive_fptr, app, + app->forced_interactive ()); + + app->forced_interactive (true); + } + } + +#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER) + + input_reader reader (m_interpreter); + + push_parser debug_parser (m_interpreter); + +#else + + parser debug_parser (m_interpreter); + +#endif + + error_system& es = m_interpreter.get_error_system (); + + while (m_in_debug_repl) { - evaluation_pending = false; - exiting = true; - cv.notify_all (); - throw; + if (m_execution_mode == EX_CONTINUE || tw.dbstep_flag ()) + break; + + if (quitting_debugger ()) + break; + + try + { + debug_parser.reset (); + +#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER) + + int retval = 0; + + std::string prompt + = command_editor::decode_prompt_string (tmp_prompt); + + do + { + bool eof = false; + std::string input_line = reader.get_input (prompt, eof); + + if (eof) + { + retval = EOF; + break; + } + + retval = debug_parser.run (input_line, false); + + prompt = command_editor::decode_prompt_string (m_interpreter.PS2 ()); + } + while (retval < 0); + +#else + + int retval = debug_parser.run (); + +#endif + if (command_editor::interrupt (false)) + { + // Break regardless of m_execution_mode value. + + quitting_debugger (); + + break; + } + else + { + if (retval == 0) + { + std::shared_ptr stmt_list + = debug_parser.statement_list (); + + if (stmt_list) + stmt_list->accept (tw); + + if (octave_completion_matches_called) + octave_completion_matches_called = false; + + // FIXME: the following statement is here because + // the last command may have been a dbup, dbdown, or + // dbstep command that changed the current debug + // frame. If so, we need to reset the current frame + // for the call stack. But is this right way to do + // this job? What if the statement list was + // something like "dbup; dbstack"? Will the call to + // dbstack use the right frame? If not, how can we + // fix this problem? + tw.goto_frame (tw.debug_frame ()); + } + + octave_quit (); + } + } + catch (const execution_exception& ee) + { + es.save_exception (ee); + es.display_exception (ee); + + // Ignore errors when in debugging mode; + m_interpreter.recover_from_exception (); + } + catch (const quit_debug_exception& qde) + { + if (qde.all ()) + throw; + + // Continue in this debug level. + } + } + } + } + + bool debugger::quitting_debugger () const + { + if (m_execution_mode == EX_QUIT) + { + // If there is no enclosing debug level or the top-level + // repl is not active, handle dbquit the same as dbcont. + + if (m_level > 0 || m_interpreter.server_mode () + || m_interpreter.in_top_level_repl ()) + throw quit_debug_exception (); + else + return true; + } + + if (m_execution_mode == EX_QUIT_ALL) + { + // If the top-level repl is not active, handle "dbquit all" + // the same as dbcont. + + if (m_interpreter.server_mode () || m_interpreter.in_top_level_repl ()) + throw quit_debug_exception (true); + else + return true; + } + + return false; + } + + bool tree_evaluator::at_top_level () const + { + return m_call_stack.at_top_level (); + } + + std::string + tree_evaluator::mfilename (const std::string& opt) const + { + std::string fname; + + octave_user_code *fcn = m_call_stack.current_user_code (); + + if (fcn) + { + fname = fcn->fcn_file_name (); + + if (fname.empty ()) + fname = fcn->name (); + } + + if (opt == "fullpathext") + return fname; + + std::size_t dpos = fname.rfind (sys::file_ops::dir_sep_char ()); + std::size_t epos = fname.rfind ('.'); + + if (epos <= dpos+1) + epos = std::string::npos; + + if (epos != std::string::npos) + fname = fname.substr (0, epos); + + if (opt == "fullpath") + return fname; + + if (dpos != std::string::npos) + fname = fname.substr (dpos+1); + + return fname; + } + + void tree_evaluator::parse_and_execute (const std::string& input, + bool& incomplete_parse) + { + incomplete_parse = false; + + unwind_protect_var upv (m_in_top_level_repl, true); + + if (at_top_level ()) + { + dbstep_flag (0); + reset_debug_state (); + } + + // FIXME: OK to do this job here, or should it be in the functions + // that do the actual prompting? + + // Update the time stamp for the "prompt" so that automatically + // finding modified files based on file modification times will + // work. In the future, we may do something completely different to + // check for changes to files but for now, we rely on the prompt + // time stamp to limit the checks for file modification times. + + Vlast_prompt_time.stamp (); + + bool eof = false; + + event_manager& evmgr = m_interpreter.get_event_manager (); + + if (command_history::add (input)) + evmgr.append_history (input); + + m_exit_status = m_parser->run (input, eof); + + if (m_exit_status == 0) + { + std::shared_ptr + stmt_list = m_parser->statement_list (); + + if (stmt_list) + { + command_editor::increment_current_command_number (); + + eval (stmt_list, m_interpreter.interactive ()); + + evmgr.set_workspace (); + } + else if (m_parser->at_end_of_input ()) + m_exit_status = EOF; + } + else + incomplete_parse = true; + + // FIXME: Should we be checking m_exit_status or incomplete_parse or + // both here? Could EOF have a value other than -1, and is there + // possible confusion between that state and the parser returning -1? + + if (m_exit_status == -1) + m_exit_status = 0; + else + m_parser->reset (); + + evmgr.pre_input_event (); + } + + void tree_evaluator::get_line_and_eval () + { + std::mutex mtx; + std::unique_lock lock (mtx); + std::condition_variable cv; + bool incomplete_parse = false; + bool evaluation_pending = false; + bool exiting = false; + + event_manager& evmgr = m_interpreter.get_event_manager (); + + while (true) + { + // FIXME: Detect EOF? Use readline? If + // so, then we need to disable idle event loop hook function + // execution. + + std::string ps + = incomplete_parse ? m_interpreter.PS2 () : m_interpreter.PS1 (); + + std::cout << command_editor::decode_prompt_string (ps); + + std::string input; + std::getline (std::cin, input); + + if (input.empty ()) + continue; + + incomplete_parse = false; + evaluation_pending = true; + exiting = false; + + evmgr.post_event + ([&] (interpreter& interp) + { + // INTERPRETER THREAD + + std::lock_guard local_lock (mtx); + + try + { + interp.parse_and_execute (input, incomplete_parse); + } + catch (const exit_exception&) + { + evaluation_pending = false; + exiting = true; + cv.notify_all (); + throw; + } + catch (const execution_exception& ee) + { + error_system& es = m_interpreter.get_error_system (); + + es.save_exception (ee); + es.display_exception (ee); + + if (m_interpreter.interactive ()) + { + m_interpreter.recover_from_exception (); + m_parser->reset (); + evaluation_pending = false; + cv.notify_all (); + } + else + { + evaluation_pending = false; + cv.notify_all (); + throw exit_exception (1); + } + } + catch (...) + { + evaluation_pending = false; + cv.notify_all (); + throw; + } + + evaluation_pending = false; + cv.notify_all (); + }); + + // Wait until evaluation is finished before prompting for input + // again. + + cv.wait (lock, [&] { return ! evaluation_pending; }); + + if (exiting) + break; + } + } + + int tree_evaluator::repl () + { + // The big loop. Read, Eval, Print, Loop. Normally user + // interaction at the command line in a terminal session, but we may + // also end up here when reading from a pipe or when stdin is + // connected to a file by the magic of input redirection. + + int exit_status = 0; + + // FIXME: should this choice be a command-line option? Note that we + // intend that the push parser interface only be used for + // interactive sessions. + +#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER) + static bool use_command_line_push_parser = true; +#else + static bool use_command_line_push_parser = false; +#endif + + // The following logic is written as it is to allow easy transition + // to setting USE_COMMAND_LINE_PUSH_PARSER at run time and to + // simplify the logic of the main loop below by using the same + // base_parser::run interface for both push and pull parsers. + + std::shared_ptr repl_parser; + + if (m_interpreter.interactive ()) + { + if (use_command_line_push_parser) + { + push_parser *pp + = new push_parser (m_interpreter, + new input_reader (m_interpreter)); + + repl_parser = std::shared_ptr (pp); + } + else + { + parser *pp = new parser (new lexer (m_interpreter)); + repl_parser = std::shared_ptr (pp); + } + } + else + { + parser *pp = new parser (new lexer (stdin, m_interpreter)); + repl_parser = std::shared_ptr (pp); + } + + do + { + try + { + unwind_protect_var upv (m_in_top_level_repl, true); + + repl_parser->reset (); + + if (at_top_level ()) + { + dbstep_flag (0); + reset_debug_state (); + } + + exit_status = repl_parser->run (); + + if (exit_status == 0) + { + std::shared_ptr + stmt_list = repl_parser->statement_list (); + + if (stmt_list) + { + command_editor::increment_current_command_number (); + + eval (stmt_list, m_interpreter.interactive ()); + } + else if (repl_parser->at_end_of_input ()) + { + exit_status = EOF; + break; + } + } + } + catch (const interrupt_exception&) + { + m_interpreter.recover_from_exception (); + + // Required newline when the user does Ctrl+C at the prompt. + if (m_interpreter.interactive ()) + octave_stdout << "\n"; + } + catch (const index_exception& ie) + { + m_interpreter.recover_from_exception (); + + std::cerr << "error: unhandled index exception: " + << ie.message () << " -- trying to return to prompt" + << std::endl; + } + catch (const execution_exception& ee) + { + error_system& es = m_interpreter.get_error_system (); + + es.save_exception (ee); + es.display_exception (ee); + + if (m_interpreter.interactive ()) + m_interpreter.recover_from_exception (); + else + { + // We should exit with a nonzero status. + exit_status = 1; + break; + } + } + catch (const quit_debug_exception&) + { + m_interpreter.recover_from_exception (); + + // FIXME: Does anything else need to happen here? + } + catch (const std::bad_alloc&) + { + m_interpreter.recover_from_exception (); + + std::cerr << "error: out of memory -- trying to return to prompt" + << std::endl; + } + } + while (exit_status == 0); + + if (exit_status == EOF) + { + if (m_interpreter.interactive ()) + octave_stdout << "\n"; + + exit_status = 0; + } + + return exit_status; + } + + int tree_evaluator::server_loop () + { + // Process events from the event queue. + + unwind_protect_var upv1 (m_server_mode, true); + + m_exit_status = 0; + + std::shared_ptr parser (new push_parser (m_interpreter)); + unwind_protect_var> upv2 (m_parser, parser); + + // FIXME: We are currently resetting the parser after every call to + // recover_from_exception. This action should probably be handled + // in a more consistent way, but resetting the parser in every call + // to interpreter::recover_from_exception appears to cause + // segfaults in the test suite. + + do + { + try + { + // FIXME: Should we call octave_quit in the octave::sleep + // and/or command_editor::run_event_hooks functions? + + octave_quit (); + + // FIXME: Running the event queue should be decoupled from + // the command_editor. We should also use a condition + // variable to manage the execution of entries in the queue + // and eliminate the need for the busy-wait loop. + + command_editor::run_event_hooks (); + + release_unreferenced_dynamic_libraries (); + + sleep (0.1); + } + catch (const interrupt_exception&) + { + octave_interrupt_state = 1; + m_interpreter.recover_from_exception (); + m_parser->reset (); + + // Required newline when the user does Ctrl+C at the prompt. + if (m_interpreter.interactive ()) + octave_stdout << "\n"; + } + catch (const index_exception& e) + { + m_interpreter.recover_from_exception (); + m_parser->reset (); + + std::cerr << "error: unhandled index exception: " + << e.message () << " -- trying to return to prompt" + << std::endl; } catch (const execution_exception& ee) { @@ -697,1133 +936,874 @@ { m_interpreter.recover_from_exception (); m_parser->reset (); - evaluation_pending = false; - cv.notify_all (); } else { - evaluation_pending = false; - cv.notify_all (); - throw exit_exception (1); + // We should exit with a nonzero status. + m_exit_status = 1; + break; } } - catch (...) + catch (const quit_debug_exception&) { - evaluation_pending = false; - cv.notify_all (); - throw; - } - - evaluation_pending = false; - cv.notify_all (); - }); - - // Wait until evaluation is finished before prompting for input - // again. - - cv.wait (lock, [&] { return ! evaluation_pending; }); - - if (exiting) - break; - } -} - -int tree_evaluator::repl (void) -{ - // The big loop. Read, Eval, Print, Loop. Normally user - // interaction at the command line in a terminal session, but we may - // also end up here when reading from a pipe or when stdin is - // connected to a file by the magic of input redirection. - - int exit_status = 0; - - // FIXME: should this choice be a command-line option? Note that we - // intend that the push parser interface only be used for - // interactive sessions. - -#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER) - static bool use_command_line_push_parser = true; -#else - static bool use_command_line_push_parser = false; -#endif - - // The following logic is written as it is to allow easy transition - // to setting USE_COMMAND_LINE_PUSH_PARSER at run time and to - // simplify the logic of the main loop below by using the same - // base_parser::run interface for both push and pull parsers. - - std::shared_ptr repl_parser; - - if (m_interpreter.interactive ()) - { - if (use_command_line_push_parser) - { - push_parser *pp - = new push_parser (m_interpreter, - new input_reader (m_interpreter)); - - repl_parser = std::shared_ptr (pp); - } - else - { - parser *pp = new parser (new lexer (m_interpreter)); - repl_parser = std::shared_ptr (pp); - } - } - else - { - parser *pp = new parser (new lexer (stdin, m_interpreter)); - repl_parser = std::shared_ptr (pp); - } - - do - { - try - { - unwind_protect_var upv (m_in_top_level_repl, true); - - repl_parser->reset (); - - if (at_top_level ()) - { - dbstep_flag (0); - reset_debug_state (); - } - - exit_status = repl_parser->run (); - - if (exit_status == 0) - { - std::shared_ptr - stmt_list = repl_parser->statement_list (); - - if (stmt_list) - { - command_editor::increment_current_command_number (); - - eval (stmt_list, m_interpreter.interactive ()); - } - else if (repl_parser->at_end_of_input ()) - { - exit_status = EOF; - break; - } - } - } - catch (const interrupt_exception&) - { - m_interpreter.recover_from_exception (); - - // Required newline when the user does Ctrl+C at the prompt. - if (m_interpreter.interactive ()) - octave_stdout << "\n"; - } - catch (const index_exception& ie) - { - m_interpreter.recover_from_exception (); - - std::cerr << "error: unhandled index exception: " - << ie.message () << " -- trying to return to prompt" - << std::endl; - } - catch (const execution_exception& ee) - { - error_system& es = m_interpreter.get_error_system (); - - es.save_exception (ee); - es.display_exception (ee); - - if (m_interpreter.interactive ()) + octave_interrupt_state = 1; m_interpreter.recover_from_exception (); - else - { - // We should exit with a nonzero status. - exit_status = 1; - break; - } - } - catch (const quit_debug_exception&) - { - m_interpreter.recover_from_exception (); - - // FIXME: Does anything else need to happen here? - } - catch (const std::bad_alloc&) - { - m_interpreter.recover_from_exception (); - - std::cerr << "error: out of memory -- trying to return to prompt" - << std::endl; - } - } - while (exit_status == 0); - - if (exit_status == EOF) - { - if (m_interpreter.interactive ()) - octave_stdout << "\n"; - - exit_status = 0; - } - - return exit_status; -} - -int tree_evaluator::server_loop (void) -{ - // Process events from the event queue. - - unwind_protect_var upv1 (m_server_mode, true); - - m_exit_status = 0; - - std::shared_ptr parser (new push_parser (m_interpreter)); - unwind_protect_var> upv2 (m_parser, parser); - - // FIXME: We are currently resetting the parser after every call to - // recover_from_exception. This action should probably be handled - // in a more consistent way, but resetting the parser in every call - // to interpreter::recover_from_exception appears to cause - // segfaults in the test suite. - - do - { - try - { - // FIXME: Should we call octave_quit in the octave::sleep - // and/or command_editor::run_event_hooks functions? - - octave_quit (); - - // FIXME: Running the event queue should be decoupled from - // the command_editor. We should also use a condition - // variable to manage the execution of entries in the queue - // and eliminate the need for the busy-wait loop. - - command_editor::run_event_hooks (); - - release_unreferenced_dynamic_libraries (); - - sleep (0.1); - } - catch (const interrupt_exception&) - { - octave_interrupt_state = 1; - m_interpreter.recover_from_exception (); - m_parser->reset (); - - // Required newline when the user does Ctrl+C at the prompt. - if (m_interpreter.interactive ()) - octave_stdout << "\n"; - } - catch (const index_exception& e) - { - m_interpreter.recover_from_exception (); - m_parser->reset (); - - std::cerr << "error: unhandled index exception: " - << e.message () << " -- trying to return to prompt" - << std::endl; - } - catch (const execution_exception& ee) - { - error_system& es = m_interpreter.get_error_system (); - - es.save_exception (ee); - es.display_exception (ee); - - if (m_interpreter.interactive ()) - { - m_interpreter.recover_from_exception (); - m_parser->reset (); - } - else - { - // We should exit with a nonzero status. - m_exit_status = 1; - break; - } - } - catch (const quit_debug_exception&) - { - octave_interrupt_state = 1; - m_interpreter.recover_from_exception (); - m_parser->reset (); - } - catch (const exit_exception& xe) - { - m_exit_status = xe.exit_status (); - break; - } - catch (const std::bad_alloc&) - { - m_interpreter.recover_from_exception (); - m_parser->reset (); - - std::cerr << "error: out of memory -- trying to return to prompt" - << std::endl; - } - } - while (m_exit_status == 0); - - if (m_exit_status == EOF) - { - if (m_interpreter.interactive ()) - octave_stdout << "\n"; - - m_exit_status = 0; - } - - return m_exit_status; -} - -void tree_evaluator::eval (std::shared_ptr& stmt_list, - bool interactive) -{ - try - { - stmt_list->accept (*this); - - octave_quit (); - - if (! interactive) - { - bool quit = (m_returning || m_breaking); - - if (m_returning) - m_returning = 0; - - if (m_breaking) - m_breaking--; - - if (quit) - return; - } - - if (octave_completion_matches_called) - octave_completion_matches_called = false; - } - catch (const quit_debug_exception&) - { - m_interpreter.recover_from_exception (); - } -} - -octave_value_list -tree_evaluator::eval_string (const std::string& eval_str, bool silent, - int& parse_status, int nargout) -{ - octave_value_list retval; - - parser eval_parser (eval_str, m_interpreter); - - do - { - eval_parser.reset (); - - // If we are looking at - // - // val = eval ("code"); - // - // then don't allow code to be parsed as a command. - - if (nargout > 0) - eval_parser.disallow_command_syntax (); - - parse_status = eval_parser.run (); - - if (parse_status == 0) - { - std::shared_ptr stmt_list - = eval_parser.statement_list (); - - if (stmt_list) - { - tree_statement *stmt = nullptr; - - if (stmt_list->length () == 1 - && (stmt = stmt_list->front ()) - && stmt->is_expression ()) - { - tree_expression *expr = stmt->expression (); - - if (silent) - expr->set_print_flag (false); - - retval = expr->evaluate_n (*this, nargout); - - bool do_bind_ans = false; - - if (expr->is_identifier ()) - do_bind_ans = ! is_variable (expr); - else - do_bind_ans = ! expr->is_assignment_expression (); - - if (do_bind_ans && ! retval.empty ()) - bind_ans (retval(0), expr->print_result ()); - - if (nargout == 0) - retval = octave_value_list (); - } - else if (nargout == 0) - stmt_list->accept (*this); - else - error ("eval: invalid use of statement list"); - - if (returning () || breaking () || continuing ()) - break; - } - else if (eval_parser.at_end_of_input ()) + m_parser->reset (); + } + catch (const exit_exception& xe) + { + m_exit_status = xe.exit_status (); break; - } - } - while (parse_status == 0); - - return retval; -} - -octave_value tree_evaluator::eval_string (const std::string& eval_str, - bool silent, int& parse_status) -{ - octave_value retval; - - octave_value_list tmp = eval_string (eval_str, silent, parse_status, 1); - - if (! tmp.empty ()) - retval = tmp(0); - - return retval; -} - -octave_value_list tree_evaluator::eval_string (const octave_value& arg, - bool silent, int& parse_status, - int nargout) -{ - std::string s = arg.xstring_value ("eval: expecting string argument"); - - return eval_string (s, silent, parse_status, nargout); -} - -octave_value_list tree_evaluator::eval (const std::string& try_code, - int nargout) -{ - int parse_status = 0; - - return eval_string (try_code, nargout > 0, parse_status, nargout); -} - -octave_value_list tree_evaluator::eval (const std::string& try_code, - const std::string& catch_code, - int nargout) -{ - octave_value_list retval; - - error_system& es = m_interpreter.get_error_system (); - - int parse_status = 0; - - bool execution_error = false; - - octave_value_list tmp; - - try - { - tmp = eval_string (try_code, nargout > 0, parse_status, nargout); - } - catch (const execution_exception& ee) - { - es.save_exception (ee); - m_interpreter.recover_from_exception (); - - execution_error = true; - } - - if (parse_status != 0 || execution_error) - { - tmp = eval_string (catch_code, nargout > 0, parse_status, nargout); - - retval = (nargout > 0) ? tmp : octave_value_list (); - } - else - { - if (nargout > 0) - retval = tmp; - - // FIXME: we should really be rethrowing whatever - // exception occurred, not just throwing an - // execution exception. - if (execution_error) - throw execution_exception (); - } - - return retval; -} - -octave_value_list tree_evaluator::evalin (const std::string& context, - const std::string& try_code, - int nargout) -{ - unwind_action act ([=] (std::size_t frm) - { - m_call_stack.restore_frame (frm); - }, m_call_stack.current_frame ()); - - if (context == "caller") - m_call_stack.goto_caller_frame (); - else if (context == "base") - m_call_stack.goto_base_frame (); - else - error (R"(evalin: CONTEXT must be "caller" or "base")"); - - int parse_status = 0; - - return eval_string (try_code, nargout > 0, parse_status, nargout); -} - -octave_value_list tree_evaluator::evalin (const std::string& context, - const std::string& try_code, - const std::string& catch_code, - int nargout) -{ - octave_value_list retval; - - unwind_action act1 ([=] (std::size_t frm) - { - m_call_stack.restore_frame (frm); - }, m_call_stack.current_frame ()); - - if (context == "caller") - m_call_stack.goto_caller_frame (); - else if (context == "base") - m_call_stack.goto_base_frame (); - else - error (R"(evalin: CONTEXT must be "caller" or "base")"); - - error_system& es = m_interpreter.get_error_system (); - - int parse_status = 0; - - bool execution_error = false; - - octave_value_list tmp; - - try - { - tmp = eval_string (try_code, nargout > 0, parse_status, nargout); - } - catch (const execution_exception& ee) - { - es.save_exception (ee); - m_interpreter.recover_from_exception (); - - execution_error = true; - } - - if (parse_status != 0 || execution_error) - { - tmp = eval_string (catch_code, nargout > 0, parse_status, nargout); - - retval = (nargout > 0) ? tmp : octave_value_list (); - } - else - { - if (nargout > 0) - retval = tmp; - - // FIXME: we should really be rethrowing whatever - // exception occurred, not just throwing an - // execution exception. - if (execution_error) - throw execution_exception (); - } - - return retval; -} - -void -tree_evaluator::visit_anon_fcn_handle (tree_anon_fcn_handle&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_argument_list (tree_argument_list&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_arguments_block (tree_arguments_block&) -{ - warning ("function arguments validation blocks are not supported; INCORRECT RESULTS ARE POSSIBLE"); -} - -void -tree_evaluator::visit_args_block_attribute_list (tree_args_block_attribute_list&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_args_block_validation_list (tree_args_block_validation_list&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_arg_validation (tree_arg_validation&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_arg_size_spec (tree_arg_size_spec&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_arg_validation_fcns (tree_arg_validation_fcns&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_binary_expression (tree_binary_expression&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_boolean_expression (tree_boolean_expression&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_compound_binary_expression (tree_compound_binary_expression&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_break_command (tree_break_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - if (m_in_loop_command) - m_breaking = 1; - else - error ("break must appear in a loop in the same file as loop command"); -} - -void -tree_evaluator::visit_colon_expression (tree_colon_expression&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_continue_command (tree_continue_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - if (m_in_loop_command) - m_continuing = 1; -} - -bool -tree_evaluator::statement_printing_enabled (void) -{ - return ! (m_silent_functions && (m_statement_context == SC_FUNCTION - || m_statement_context == SC_SCRIPT)); -} - -void -tree_evaluator::reset_debug_state (void) -{ - m_debug_mode = (m_bp_table.have_breakpoints () - || m_dbstep_flag != 0 - || m_break_on_next_stmt - || in_debug_repl ()); -} - -void -tree_evaluator::reset_debug_state (bool mode) -{ - m_debug_mode = mode; -} - -void -tree_evaluator::enter_debugger (const std::string& prompt) -{ - unwind_protect frame; - - frame.add (command_history::ignore_entries, - command_history::ignoring_entries ()); - - command_history::ignore_entries (false); - - frame.add (&call_stack::restore_frame, &m_call_stack, - m_call_stack.current_frame ()); - - // Don't allow errors or warnings at the debug prompt to push us - // into deeper levels of debugging. - - error_system& es = m_interpreter.get_error_system (); - - frame.add (&error_system::set_debug_on_error, &es, es.debug_on_error ()); - - frame.add (&error_system::set_debug_on_warning, &es, - es.debug_on_warning ()); - - es.debug_on_error (false); - es.debug_on_warning (false); - - // Go up to the nearest user code frame. - - m_debug_frame = m_call_stack.dbupdown (0); - - // FIXME: probably we just want to print one line, not the - // entire statement, which might span many lines... - // - // tree_print_code tpc (octave_stdout); - // stmt.accept (tpc); - - debugger *dbgr = new debugger (m_interpreter, m_debugger_stack.size ()); - - m_debugger_stack.push (dbgr); - - frame.add ([=] (void) - { - delete m_debugger_stack.top (); - m_debugger_stack.pop (); - reset_debug_state (); - }); - - dbgr->repl (prompt); -} - -void -tree_evaluator::keyboard (const std::string& prompt) -{ - enter_debugger (prompt); -} - -void -tree_evaluator::dbupdown (int n, bool verbose) -{ - m_debug_frame = m_call_stack.dbupdown (n, verbose); -} - -Matrix -tree_evaluator::ignored_fcn_outputs (void) const -{ - Matrix retval; - - const std::list *lvalues = m_lvalue_list; - - if (! lvalues) + } + catch (const std::bad_alloc&) + { + m_interpreter.recover_from_exception (); + m_parser->reset (); + + std::cerr << "error: out of memory -- trying to return to prompt" + << std::endl; + } + } + while (m_exit_status == 0); + + if (m_exit_status == EOF) + { + if (m_interpreter.interactive ()) + octave_stdout << "\n"; + + m_exit_status = 0; + } + + return m_exit_status; + } + + void tree_evaluator::eval (std::shared_ptr& stmt_list, + bool interactive) + { + try + { + stmt_list->accept (*this); + + octave_quit (); + + if (! interactive) + { + bool quit = (m_returning || m_breaking); + + if (m_returning) + m_returning = 0; + + if (m_breaking) + m_breaking--; + + if (quit) + return; + } + + if (octave_completion_matches_called) + octave_completion_matches_called = false; + } + catch (const quit_debug_exception&) + { + m_interpreter.recover_from_exception (); + } + } + + octave_value_list + tree_evaluator::eval_string (const std::string& eval_str, bool silent, + int& parse_status, int nargout) + { + octave_value_list retval; + + parser eval_parser (eval_str, m_interpreter); + + do + { + eval_parser.reset (); + + // If we are looking at + // + // val = eval ("code"); + // + // then don't allow code to be parsed as a command. + + if (nargout > 0) + eval_parser.disallow_command_syntax (); + + parse_status = eval_parser.run (); + + if (parse_status == 0) + { + std::shared_ptr stmt_list + = eval_parser.statement_list (); + + if (stmt_list) + { + tree_statement *stmt = nullptr; + + if (stmt_list->length () == 1 + && (stmt = stmt_list->front ()) + && stmt->is_expression ()) + { + tree_expression *expr = stmt->expression (); + + if (silent) + expr->set_print_flag (false); + + retval = expr->evaluate_n (*this, nargout); + + bool do_bind_ans = false; + + if (expr->is_identifier ()) + do_bind_ans = ! is_variable (expr); + else + do_bind_ans = ! expr->is_assignment_expression (); + + if (do_bind_ans && ! retval.empty ()) + bind_ans (retval(0), expr->print_result ()); + + if (nargout == 0) + retval = octave_value_list (); + } + else if (nargout == 0) + stmt_list->accept (*this); + else + error ("eval: invalid use of statement list"); + + if (returning () || breaking () || continuing ()) + break; + } + else if (eval_parser.at_end_of_input ()) + break; + } + } + while (parse_status == 0); + + return retval; + } + + octave_value tree_evaluator::eval_string (const std::string& eval_str, + bool silent, int& parse_status) + { + octave_value retval; + + octave_value_list tmp = eval_string (eval_str, silent, parse_status, 1); + + if (! tmp.empty ()) + retval = tmp(0); + + return retval; + } + + octave_value_list tree_evaluator::eval_string (const octave_value& arg, + bool silent, int& parse_status, + int nargout) + { + std::string s = arg.xstring_value ("eval: expecting string argument"); + + return eval_string (s, silent, parse_status, nargout); + } + + octave_value_list tree_evaluator::eval (const std::string& try_code, + int nargout) + { + int parse_status = 0; + + return eval_string (try_code, nargout > 0, parse_status, nargout); + } + + octave_value_list tree_evaluator::eval (const std::string& try_code, + const std::string& catch_code, + int nargout) + { + octave_value_list retval; + + error_system& es = m_interpreter.get_error_system (); + + int parse_status = 0; + + bool execution_error = false; + + octave_value_list tmp; + + try + { + tmp = eval_string (try_code, nargout > 0, parse_status, nargout); + } + catch (const execution_exception& ee) + { + es.save_exception (ee); + m_interpreter.recover_from_exception (); + + execution_error = true; + } + + if (parse_status != 0 || execution_error) + { + tmp = eval_string (catch_code, nargout > 0, parse_status, nargout); + + retval = (nargout > 0) ? tmp : octave_value_list (); + } + else + { + if (nargout > 0) + retval = tmp; + + // FIXME: we should really be rethrowing whatever + // exception occurred, not just throwing an + // execution exception. + if (execution_error) + throw execution_exception (); + } + + return retval; + } + + octave_value_list tree_evaluator::evalin (const std::string& context, + const std::string& try_code, + int nargout) + { + unwind_action act ([=] (std::size_t frm) + { + m_call_stack.restore_frame (frm); + }, m_call_stack.current_frame ()); + + if (context == "caller") + m_call_stack.goto_caller_frame (); + else if (context == "base") + m_call_stack.goto_base_frame (); + else + error (R"(evalin: CONTEXT must be "caller" or "base")"); + + int parse_status = 0; + + return eval_string (try_code, nargout > 0, parse_status, nargout); + } + + octave_value_list tree_evaluator::evalin (const std::string& context, + const std::string& try_code, + const std::string& catch_code, + int nargout) + { + octave_value_list retval; + + unwind_action act1 ([=] (std::size_t frm) + { + m_call_stack.restore_frame (frm); + }, m_call_stack.current_frame ()); + + if (context == "caller") + m_call_stack.goto_caller_frame (); + else if (context == "base") + m_call_stack.goto_base_frame (); + else + error (R"(evalin: CONTEXT must be "caller" or "base")"); + + error_system& es = m_interpreter.get_error_system (); + + int parse_status = 0; + + bool execution_error = false; + + octave_value_list tmp; + + try + { + tmp = eval_string (try_code, nargout > 0, parse_status, nargout); + } + catch (const execution_exception& ee) + { + es.save_exception (ee); + m_interpreter.recover_from_exception (); + + execution_error = true; + } + + if (parse_status != 0 || execution_error) + { + tmp = eval_string (catch_code, nargout > 0, parse_status, nargout); + + retval = (nargout > 0) ? tmp : octave_value_list (); + } + else + { + if (nargout > 0) + retval = tmp; + + // FIXME: we should really be rethrowing whatever + // exception occurred, not just throwing an + // execution exception. + if (execution_error) + throw execution_exception (); + } + return retval; - - octave_idx_type nbh = 0; - - for (const auto& lval : *lvalues) - nbh += lval.is_black_hole (); - - if (nbh > 0) - { - retval.resize (1, nbh); - - octave_idx_type k = 0; - octave_idx_type l = 0; - - for (const auto& lval : *lvalues) - { - if (lval.is_black_hole ()) - retval(l++) = k+1; - - k += lval.numel (); - } - } - - return retval; -} - -// If NAME is an operator (like "+", "-", ...), convert it to the -// corresponding function name ("plus", "minus", ...). - -static std::string -get_operator_function_name (const std::string& name) -{ - // Bow to the god of compatibility. - - // FIXME: it seems ugly to put this here, but there is no single - // function in the parser that converts from the operator name to - // the corresponding function name. At least try to do it without N - // string compares. - - // FIXME: .+, .-, **, and .** are deprecated but still need to be - // handled here until they are removed. - - std::size_t len = name.length (); - - if (len == 3 && name == ".**") - // deprecated - return "power"; - else if (len == 2) - { - if (name[0] == '.') - { - switch (name[1]) - { - case '\'': - return "transpose"; - - case '+': - // deprecated - return "plus"; - - case '-': - // deprecated - return "minus"; - - case '*': - return "times"; - - case '/': - return "rdivide"; - - case '^': - return "power"; - - case '\\': - return "ldivide"; - - default: - break; - } - } - else if (name[1] == '=') - { - switch (name[0]) - { - case '<': - return "le"; - - case '=': - return "eq"; - - case '>': - return "ge"; - - case '~': - case '!': - return "ne"; - - default: - break; - } - } - else if (name == "**") - // deprecated - return "mpower"; - } - else if (len == 1) - { - switch (name[0]) - { - case '~': - case '!': - return "not"; - - case '\'': - return "ctranspose"; - - case '+': - return "plus"; - - case '-': - return "minus"; - - case '*': - return "mtimes"; - - case '/': - return "mrdivide"; - - case '^': - return "mpower"; - - case '\\': - return "mldivide"; - - case '<': - return "lt"; - - case '>': - return "gt"; - - case '&': - return "and"; - - case '|': - return "or"; - - default: - break; - } - } - - return name; -} - -// Creates a function handle that takes into account the context, -// finding local, nested, private, or sub functions. - -octave_value -tree_evaluator::make_fcn_handle (const std::string& name) -{ - octave_value retval; - - // The str2func function can create a function handle with the name - // of an operator (for example, "+"). If so, it is converted to the - // name of the corresponding function ("+" -> "plus") and we create - // a simple function handle using that name. - - std::string fcn_name = get_operator_function_name (name); - - // If FCN_NAME is different from NAME, then NAME is an operator. As - // of version 2020a, Matlab apparently uses the function name - // corresponding to the operator to search for private and local - // functions in the current scope but not(!) nested functions. - - bool name_is_operator = fcn_name != name; - - std::size_t pos = fcn_name.find ('.'); - - if (pos != std::string::npos) - { - // Recognize (some of? which ones?) the following cases - // and create something other than a simple function handle? - // Should we just be checking for the last two when the first - // element of the dot-separated list is an object? If so, then - // should this syntax be limited to a dot-separated list with - // exactly two elements? - // - // object . method - // object . static-method - // - // Code to do that duplicates some of simple_fcn_handle::call. - - // Only accept expressions that contain one '.' separator. - - // FIXME: The logic here is a bit complicated. Is there a good - // way to simplify it? - - std::string meth_nm = fcn_name.substr (pos+1); - - if (meth_nm.find ('.') == std::string::npos) - { - std::string obj_nm = fcn_name.substr (0, pos); - - // If obj_nm is an object in the current scope with a - // method named meth_nm, create a classsimple handle. - - octave_value object = varval (obj_nm); - - if (object.is_defined () && object.is_classdef_object ()) - { - octave_classdef *cdef = object.classdef_object_value (); - - if (cdef) - { - std::string class_nm = cdef->class_name (); - - cdef_object cdef_obj = cdef->get_object (); - - cdef_class cls = cdef_obj.get_class (); - - cdef_method meth = cls.find_method (meth_nm); - - if (meth.ok ()) - { - // If the method we found is static, create a - // new function name from the class name and - // method name and create a simple function - // handle below. Otherwise, create a class - // simple function handle. - - if (meth.is_static ()) - fcn_name = class_nm + '.' + meth_nm; - else - { - octave_value meth_fcn = meth.get_function (); - - octave_fcn_handle *fh - = new octave_fcn_handle (object, meth_fcn, - class_nm, meth_nm); - - return octave_value (fh); - } - } - } - } - } - - // We didn't match anything above, so create handle to SIMPLE - // package function or static class method. Function resolution - // is performed when the handle is used. - - return octave_value (new octave_fcn_handle (fcn_name)); - } - - // If the function name refers to a sub/local/private function or a - // class method/constructor, create scoped function handle that is - // bound to that function. Use the same precedence list as - // fcn_info::find but limit search to the following types of - // functions: - // - // nested functions (and subfunctions) - // local functions in the current file - // private function - // class method - // - // For anything else we create a simple function handle that will be - // resolved dynamically in the scope where it is evaluated. - - symbol_scope curr_scope = get_current_scope (); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - if (curr_scope) - { - octave_value ov_fcn - = symtab.find_scoped_function (fcn_name, curr_scope); - - // If name is operator, we are in Fstr2func, so skip the stack - // frame for that function. - - bool skip_first = name_is_operator; - octave_function *curr_fcn = current_function (skip_first); - - if (ov_fcn.is_defined ()) - { - octave_function *fcn = ov_fcn.function_value (); - - if (fcn->is_nested_function ()) - { - if (! name_is_operator) - { - // Get current stack frame and return handle to nested - // function. - - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - // If we are creating a handle to the current - // function or a handle to a sibling function (i.e., - // not a child of the current function), then use - // the calling stack frame as the context instead of - // the current stack frame. - - // FIXME: Do we need both checks here or is it - // sufficient to check that the parent of curr_fcn - // is the same as the parent of fcn? Is there any - // case where curr_fcn could be nullptr, or does - // that indicate an internal error of some kind? - - if (curr_fcn - && (fcn_name == curr_fcn->name () - || fcn->parent_fcn_name () == curr_fcn->parent_fcn_name ())) - frame = frame->access_link (); - - octave_fcn_handle *fh - = new octave_fcn_handle (ov_fcn, fcn_name, frame); - - return octave_value (fh); - } - } - else if (fcn->is_subfunction () - /* || fcn->is_localfunction () */ - || fcn->is_private_function ()) - { - // Create handle to SCOPED function (sub/local function - // or private function). - - std::list parentage = fcn->parent_fcn_names (); - - octave_fcn_handle *fh - = new octave_fcn_handle (ov_fcn, fcn_name, parentage); - - return octave_value (fh); - } - } - - if (curr_fcn && (curr_fcn->is_class_method () - || curr_fcn->is_class_constructor ())) - { - std::string dispatch_class = curr_fcn->dispatch_class (); - - octave_value ov_meth - = symtab.find_method (fcn_name, dispatch_class); - - if (ov_meth.is_defined ()) - { - octave_function *fcn = ov_meth.function_value (); - - // FIXME: do we need to check that it is a method of - // dispatch_class, or is it sufficient to just check - // that it is a method? - - if (fcn->is_class_method ()) - { - // Create CLASSSIMPLE handle to method but don't - // bind to the method. Lookup will be done later. - - octave_fcn_handle *fh - = new octave_fcn_handle (dispatch_class, fcn_name); - - return octave_value (fh); - } - } - } - } - - octave_value ov_fcn = symtab.find_user_function (fcn_name); - - // Create handle to SIMPLE function. If the function is not found - // now, then we will look for it again when the handle is used. - - return octave_value (new octave_fcn_handle (ov_fcn, fcn_name)); -} + } + + void + tree_evaluator::visit_anon_fcn_handle (tree_anon_fcn_handle&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_argument_list (tree_argument_list&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_arguments_block (tree_arguments_block&) + { + warning ("function arguments validation blocks are not supported; INCORRECT RESULTS ARE POSSIBLE"); + } + + void + tree_evaluator::visit_args_block_attribute_list (tree_args_block_attribute_list&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_args_block_validation_list (tree_args_block_validation_list&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_arg_validation (tree_arg_validation&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_arg_size_spec (tree_arg_size_spec&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_arg_validation_fcns (tree_arg_validation_fcns&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_binary_expression (tree_binary_expression&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_boolean_expression (tree_boolean_expression&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_compound_binary_expression (tree_compound_binary_expression&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_break_command (tree_break_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + if (m_in_loop_command) + m_breaking = 1; + else + error ("break must appear in a loop in the same file as loop command"); + } + + void + tree_evaluator::visit_colon_expression (tree_colon_expression&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_continue_command (tree_continue_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + if (m_in_loop_command) + m_continuing = 1; + } + + bool + tree_evaluator::statement_printing_enabled () + { + return ! (m_silent_functions && (m_statement_context == SC_FUNCTION + || m_statement_context == SC_SCRIPT)); + } + + void + tree_evaluator::reset_debug_state () + { + m_debug_mode = (m_bp_table.have_breakpoints () + || m_dbstep_flag != 0 + || m_break_on_next_stmt + || in_debug_repl ()); + } + + void + tree_evaluator::reset_debug_state (bool mode) + { + m_debug_mode = mode; + } + + void + tree_evaluator::enter_debugger (const std::string& prompt) + { + unwind_protect frame; + + frame.add (command_history::ignore_entries, + command_history::ignoring_entries ()); + + command_history::ignore_entries (false); + + frame.add (&call_stack::restore_frame, &m_call_stack, + m_call_stack.current_frame ()); + + // Don't allow errors or warnings at the debug prompt to push us + // into deeper levels of debugging. + + error_system& es = m_interpreter.get_error_system (); + + frame.add (&error_system::set_debug_on_error, &es, es.debug_on_error ()); + + frame.add (&error_system::set_debug_on_warning, &es, + es.debug_on_warning ()); + + es.debug_on_error (false); + es.debug_on_warning (false); + + // Go up to the nearest user code frame. + + m_debug_frame = m_call_stack.dbupdown (0); + + // FIXME: probably we just want to print one line, not the + // entire statement, which might span many lines... + // + // tree_print_code tpc (octave_stdout); + // stmt.accept (tpc); + + debugger *dbgr = new debugger (m_interpreter, m_debugger_stack.size ()); + + m_debugger_stack.push (dbgr); + + frame.add ([=] () + { + delete m_debugger_stack.top (); + m_debugger_stack.pop (); + reset_debug_state (); + }); + + dbgr->repl (prompt); + } + + void + tree_evaluator::keyboard (const std::string& prompt) + { + enter_debugger (prompt); + } + + void + tree_evaluator::dbupdown (int n, bool verbose) + { + m_debug_frame = m_call_stack.dbupdown (n, verbose); + } + + Matrix + tree_evaluator::ignored_fcn_outputs () const + { + Matrix retval; + + const std::list *lvalues = m_lvalue_list; + + if (! lvalues) + return retval; + + octave_idx_type nbh = 0; + + for (const auto& lval : *lvalues) + nbh += lval.is_black_hole (); + + if (nbh > 0) + { + retval.resize (1, nbh); + + octave_idx_type k = 0; + octave_idx_type l = 0; + + for (const auto& lval : *lvalues) + { + if (lval.is_black_hole ()) + retval(l++) = k+1; + + k += lval.numel (); + } + } + + return retval; + } + + // If NAME is an operator (like "+", "-", ...), convert it to the + // corresponding function name ("plus", "minus", ...). + + static std::string + get_operator_function_name (const std::string& name) + { + // Bow to the god of compatibility. + + // FIXME: it seems ugly to put this here, but there is no single + // function in the parser that converts from the operator name to + // the corresponding function name. At least try to do it without N + // string compares. + + std::size_t len = name.length (); + + if (len == 2) + { + if (name[0] == '.') + { + switch (name[1]) + { + case '\'': + return "transpose"; + + case '*': + return "times"; + + case '/': + return "rdivide"; + + case '^': + return "power"; + + case '\\': + return "ldivide"; + + default: + break; + } + } + else if (name[1] == '=') + { + switch (name[0]) + { + case '<': + return "le"; + + case '=': + return "eq"; + + case '>': + return "ge"; + + case '~': + case '!': + return "ne"; + + default: + break; + } + } + } + else if (len == 1) + { + switch (name[0]) + { + case '~': + case '!': + return "not"; + + case '\'': + return "ctranspose"; + + case '+': + return "plus"; + + case '-': + return "minus"; + + case '*': + return "mtimes"; + + case '/': + return "mrdivide"; + + case '^': + return "mpower"; + + case '\\': + return "mldivide"; + + case '<': + return "lt"; + + case '>': + return "gt"; + + case '&': + return "and"; + + case '|': + return "or"; + + default: + break; + } + } + + return name; + } + + // Creates a function handle that takes into account the context, + // finding local, nested, private, or sub functions. + + octave_value + tree_evaluator::make_fcn_handle (const std::string& name) + { + octave_value retval; + + // The str2func function can create a function handle with the name + // of an operator (for example, "+"). If so, it is converted to the + // name of the corresponding function ("+" -> "plus") and we create + // a simple function handle using that name. + + std::string fcn_name = get_operator_function_name (name); + + // If FCN_NAME is different from NAME, then NAME is an operator. As + // of version 2020a, Matlab apparently uses the function name + // corresponding to the operator to search for private and local + // functions in the current scope but not(!) nested functions. + + bool name_is_operator = fcn_name != name; + + std::size_t pos = fcn_name.find ('.'); + + if (pos != std::string::npos) + { + // Recognize (some of? which ones?) the following cases + // and create something other than a simple function handle? + // Should we just be checking for the last two when the first + // element of the dot-separated list is an object? If so, then + // should this syntax be limited to a dot-separated list with + // exactly two elements? + // + // object . method + // object . static-method + // + // Code to do that duplicates some of simple_fcn_handle::call. + + // Only accept expressions that contain one '.' separator. + + // FIXME: The logic here is a bit complicated. Is there a good + // way to simplify it? + + std::string meth_nm = fcn_name.substr (pos+1); + + if (meth_nm.find ('.') == std::string::npos) + { + std::string obj_nm = fcn_name.substr (0, pos); + + // If obj_nm is an object in the current scope with a + // method named meth_nm, create a classsimple handle. + + octave_value object = varval (obj_nm); + + if (object.is_defined () && object.is_classdef_object ()) + { + octave_classdef *cdef = object.classdef_object_value (); + + if (cdef) + { + std::string class_nm = cdef->class_name (); + + cdef_object cdef_obj = cdef->get_object (); + + cdef_class cls = cdef_obj.get_class (); + + cdef_method meth = cls.find_method (meth_nm); + + if (meth.ok ()) + { + // If the method we found is static, create a + // new function name from the class name and + // method name and create a simple function + // handle below. Otherwise, create a class + // simple function handle. + + if (meth.is_static ()) + fcn_name = class_nm + '.' + meth_nm; + else + { + octave_value meth_fcn = meth.get_function (); + + octave_fcn_handle *fh + = new octave_fcn_handle (object, meth_fcn, + class_nm, meth_nm); + + return octave_value (fh); + } + } + } + } + } + + // We didn't match anything above, so create handle to SIMPLE + // package function or static class method. Function resolution + // is performed when the handle is used. + + return octave_value (new octave_fcn_handle (fcn_name)); + } + + // If the function name refers to a sub/local/private function or a + // class method/constructor, create scoped function handle that is + // bound to that function. Use the same precedence list as + // fcn_info::find but limit search to the following types of + // functions: + // + // nested functions (and subfunctions) + // local functions in the current file + // private function + // class method + // + // For anything else we create a simple function handle that will be + // resolved dynamically in the scope where it is evaluated. + + symbol_scope curr_scope = get_current_scope (); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + if (curr_scope) + { + octave_value ov_fcn + = symtab.find_scoped_function (fcn_name, curr_scope); + + // If name is operator, we are in Fstr2func, so skip the stack + // frame for that function. + + bool skip_first = name_is_operator; + octave_function *curr_fcn = current_function (skip_first); + + if (ov_fcn.is_defined ()) + { + octave_function *fcn = ov_fcn.function_value (); + + if (fcn->is_nested_function ()) + { + if (! name_is_operator) + { + // Get current stack frame and return handle to nested + // function. + + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + // If we are creating a handle to the current + // function or a handle to a sibling function (i.e., + // not a child of the current function), then use + // the calling stack frame as the context instead of + // the current stack frame. + + // FIXME: Do we need both checks here or is it + // sufficient to check that the parent of curr_fcn + // is the same as the parent of fcn? Is there any + // case where curr_fcn could be nullptr, or does + // that indicate an internal error of some kind? + + if (curr_fcn + && (fcn_name == curr_fcn->name () + || fcn->parent_fcn_name () == curr_fcn->parent_fcn_name ())) + frame = frame->access_link (); + + octave_fcn_handle *fh + = new octave_fcn_handle (ov_fcn, fcn_name, frame); + + return octave_value (fh); + } + } + else if (fcn->is_subfunction () + /* || fcn->is_localfunction () */ + || fcn->is_private_function ()) + { + // Create handle to SCOPED function (sub/local function + // or private function). + + std::list parentage = fcn->parent_fcn_names (); + + octave_fcn_handle *fh + = new octave_fcn_handle (ov_fcn, fcn_name, parentage); + + return octave_value (fh); + } + } + + if (curr_fcn && (curr_fcn->is_class_method () + || curr_fcn->is_class_constructor ())) + { + std::string dispatch_class = curr_fcn->dispatch_class (); + + octave_value ov_meth + = symtab.find_method (fcn_name, dispatch_class); + + if (ov_meth.is_defined ()) + { + octave_function *fcn = ov_meth.function_value (); + + // FIXME: do we need to check that it is a method of + // dispatch_class, or is it sufficient to just check + // that it is a method? + + if (fcn->is_class_method ()) + { + // Create CLASSSIMPLE handle to method but don't + // bind to the method. Lookup will be done later. + + octave_fcn_handle *fh + = new octave_fcn_handle (dispatch_class, fcn_name); + + return octave_value (fh); + } + } + } + } + + octave_value ov_fcn = symtab.find_user_function (fcn_name); + + // Create handle to SIMPLE function. If the function is not found + // now, then we will look for it again when the handle is used. + + return octave_value (new octave_fcn_handle (ov_fcn, fcn_name)); + } /* %!test -%! x = {".**", "power"; -%! ".'", "transpose"; -%! ".+", "plus"; -%! ".-", "minus"; +%! x = {".'", "transpose"; %! ".*", "times"; %! "./", "rdivide"; %! ".^", "power"; @@ -1833,7 +1813,6 @@ %! ">=", "ge"; %! "!=", "ne"; %! "~=", "ne"; -%! "**", "mpower"; %! "~", "not"; %! "!", "not"; %! "\'", "ctranspose"; @@ -1852,401 +1831,401 @@ %! endfor */ -octave_value -tree_evaluator::evaluate (tree_decl_elt *elt) -{ - // Do not allow functions to return null values. - - tree_identifier *id = elt->ident (); - - return id ? id->evaluate (*this).storable_value () : octave_value (); -} - -bool -tree_evaluator::is_variable (const std::string& name) const -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - return frame->is_variable (name); -} - -bool -tree_evaluator::is_local_variable (const std::string& name) const -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - return frame->is_local_variable (name); -} - -bool -tree_evaluator::is_variable (const tree_expression *expr) const -{ - if (expr->is_identifier ()) - { - const tree_identifier *id - = dynamic_cast (expr); - - if (id->is_black_hole ()) - return false; - - return is_variable (id->symbol ()); - } - - return false; -} - -bool -tree_evaluator::is_defined (const tree_expression *expr) const -{ - if (expr->is_identifier ()) - { - const tree_identifier *id - = dynamic_cast (expr); - - return is_defined (id->symbol ()); - } - - return false; -} - -bool -tree_evaluator::is_variable (const symbol_record& sym) const -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - return frame->is_variable (sym); -} - -bool -tree_evaluator::is_defined (const symbol_record& sym) const -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - return frame->is_defined (sym); -} - -bool tree_evaluator::is_global (const std::string& name) const -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - return frame->is_global (name); -} - -octave_value -tree_evaluator::varval (const symbol_record& sym) const -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - return frame->varval (sym); -} - -octave_value -tree_evaluator::varval (const std::string& name) const -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - return frame->varval (name); -} - -void tree_evaluator::install_variable (const std::string& name, - const octave_value& value, - bool global) -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - return frame->install_variable (name, value, global); -} - -octave_value -tree_evaluator::global_varval (const std::string& name) const -{ - return m_call_stack.global_varval (name); -} - -octave_value& -tree_evaluator::global_varref (const std::string& name) -{ - return m_call_stack.global_varref (name); -} - -void -tree_evaluator::global_assign (const std::string& name, - const octave_value& val) -{ - m_call_stack.global_varref (name) = val; -} - -octave_value -tree_evaluator::top_level_varval (const std::string& name) const -{ - return m_call_stack.get_top_level_value (name); -} - -void -tree_evaluator::top_level_assign (const std::string& name, - const octave_value& val) -{ - m_call_stack.set_top_level_value (name, val); -} - -void -tree_evaluator::assign (const std::string& name, const octave_value& val) -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - frame->assign (name, val); -} - -void -tree_evaluator::assignin (const std::string& context, - const std::string& name, const octave_value& val) -{ - // FIXME: Can this be done without an unwind-protect frame, simply - // by getting a reference to the caller or base stack frame and - // calling assign on that? - - unwind_action act ([=] (std::size_t frm) - { - m_call_stack.restore_frame (frm); - }, m_call_stack.current_frame ()); - - if (context == "caller") - m_call_stack.goto_caller_frame (); - else if (context == "base") - m_call_stack.goto_base_frame (); - else - error (R"(assignin: CONTEXT must be "caller" or "base")"); - - if (valid_identifier (name)) - { - // Put the check here so that we don't slow down assignments - // generally. Any that go through Octave's parser should have - // already been checked. - - if (iskeyword (name)) - error ("assignin: invalid assignment to keyword '%s'", - name.c_str ()); - - assign (name, val); - } - else - error ("assignin: invalid variable name '%s'", name.c_str ()); -} - -void -tree_evaluator::source_file (const std::string& file_name, - const std::string& context, - bool verbose, bool require_file) -{ - // Map from absolute name of script file to recursion level. We - // use a map instead of simply placing a limit on recursion in the - // source_file function so that two mutually recursive scripts - // written as - // - // foo1.m: - // ------ - // foo2 - // - // foo2.m: - // ------ - // foo1 - // - // and called with - // - // foo1 - // - // (for example) will behave the same if they are written as - // - // foo1.m: - // ------ - // source ("foo2.m") - // - // foo2.m: - // ------ - // source ("foo1.m") - // - // and called with - // - // source ("foo1.m") - // - // (for example). - - static std::map source_call_depth; - - std::string file_full_name - = sys::file_ops::tilde_expand (file_name); - - std::size_t pos - = file_full_name.find_last_of (sys::file_ops::dir_sep_str ()); - - std::string dir_name = file_full_name.substr (0, pos); - - file_full_name = sys::env::make_absolute (file_full_name); - - unwind_protect frame; - - if (source_call_depth.find (file_full_name) == source_call_depth.end ()) - source_call_depth[file_full_name] = -1; - - frame.protect_var (source_call_depth[file_full_name]); - - source_call_depth[file_full_name]++; - - if (source_call_depth[file_full_name] >= max_recursion_depth ()) - error ("max_recursion_depth exceeded"); - - if (! context.empty ()) - { - frame.add (&call_stack::restore_frame, &m_call_stack, - m_call_stack.current_frame ()); - - if (context == "caller") - m_call_stack.goto_caller_frame (); - else if (context == "base") - m_call_stack.goto_base_frame (); - else - error (R"(source: CONTEXT must be "caller" or "base")"); - } - - // Find symbol name that would be in symbol_table, if it were loaded. - std::size_t dir_end - = file_name.find_last_of (sys::file_ops::dir_sep_chars ()); - dir_end = (dir_end == std::string::npos) ? 0 : dir_end + 1; - - std::size_t extension = file_name.find_last_of ('.'); - if (extension == std::string::npos) - extension = file_name.length (); - - std::string symbol = file_name.substr (dir_end, extension - dir_end); - std::string full_name = sys::canonicalize_file_name (file_name); - - // Check if this file is already loaded (or in the path) - symbol_table& symtab = m_interpreter.get_symbol_table (); - octave_value ov_code = symtab.fcn_table_find (symbol); - - // For compatibility with Matlab, accept both scripts and - // functions. - - if (ov_code.is_user_code ()) - { - octave_user_code *code = ov_code.user_code_value (); - - if (! code - || (sys::canonicalize_file_name (code->fcn_file_name ()) - != full_name)) - { - // Wrong file, so load it below. - ov_code = octave_value (); - } - } - else - { - // Not a script, so load it below. - ov_code = octave_value (); - } - - // If no symbol of this name, or the symbol is for a different - // file, load. - - if (ov_code.is_undefined ()) - { - try - { - ov_code = parse_fcn_file (m_interpreter, file_full_name, - file_name, dir_name, "", "", - require_file, true, false, false); - } - catch (execution_exception& ee) - { - error (ee, "source: error sourcing file '%s'", - file_full_name.c_str ()); - } - } - - // Return or error if we don't have a valid script or function. - - if (ov_code.is_undefined ()) - return; - - if (! ov_code.is_user_code ()) - error ("source: %s is not a script", full_name.c_str ()); - - if (verbose) - { - octave_stdout << "executing commands from " << full_name << " ... "; - octave_stdout.flush (); - } - - octave_user_code *code = ov_code.user_code_value (); - - code->call (*this, 0, octave_value_list ()); - - if (verbose) - octave_stdout << "done." << std::endl; -} - -void -tree_evaluator::set_auto_fcn_var (stack_frame::auto_var_type avt, - const octave_value& val) -{ - m_call_stack.set_auto_fcn_var (avt, val); -} - -octave_value -tree_evaluator::get_auto_fcn_var (stack_frame::auto_var_type avt) const -{ - return m_call_stack.get_auto_fcn_var (avt); -} - -void -tree_evaluator::define_parameter_list_from_arg_vector -(tree_parameter_list *param_list, const octave_value_list& args) -{ - if (! param_list || param_list->varargs_only ()) - return; - - int i = -1; - - for (tree_decl_elt *elt : *param_list) - { - i++; - - octave_lvalue ref = elt->lvalue (*this); - - if (i < args.length ()) - { - if (args(i).is_defined () && args(i).is_magic_colon ()) - { - if (! eval_decl_elt (elt)) - error ("no default value for argument %d", i+1); - } - else - ref.define (args(i)); - } - else - eval_decl_elt (elt); - } -} - -void -tree_evaluator::undefine_parameter_list (tree_parameter_list *param_list) -{ - for (tree_decl_elt *elt : *param_list) - { - octave_lvalue ref = elt->lvalue (*this); - - ref.assign (octave_value::op_asn_eq, octave_value ()); - } -} + octave_value + tree_evaluator::evaluate (tree_decl_elt *elt) + { + // Do not allow functions to return null values. + + tree_identifier *id = elt->ident (); + + return id ? id->evaluate (*this).storable_value () : octave_value (); + } + + bool + tree_evaluator::is_variable (const std::string& name) const + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + return frame->is_variable (name); + } + + bool + tree_evaluator::is_local_variable (const std::string& name) const + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + return frame->is_local_variable (name); + } + + bool + tree_evaluator::is_variable (const tree_expression *expr) const + { + if (expr->is_identifier ()) + { + const tree_identifier *id + = dynamic_cast (expr); + + if (id->is_black_hole ()) + return false; + + return is_variable (id->symbol ()); + } + + return false; + } + + bool + tree_evaluator::is_defined (const tree_expression *expr) const + { + if (expr->is_identifier ()) + { + const tree_identifier *id + = dynamic_cast (expr); + + return is_defined (id->symbol ()); + } + + return false; + } + + bool + tree_evaluator::is_variable (const symbol_record& sym) const + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + return frame->is_variable (sym); + } + + bool + tree_evaluator::is_defined (const symbol_record& sym) const + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + return frame->is_defined (sym); + } + + bool tree_evaluator::is_global (const std::string& name) const + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + return frame->is_global (name); + } + + octave_value + tree_evaluator::varval (const symbol_record& sym) const + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + return frame->varval (sym); + } + + octave_value + tree_evaluator::varval (const std::string& name) const + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + return frame->varval (name); + } + + void tree_evaluator::install_variable (const std::string& name, + const octave_value& value, + bool global) + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + return frame->install_variable (name, value, global); + } + + octave_value + tree_evaluator::global_varval (const std::string& name) const + { + return m_call_stack.global_varval (name); + } + + octave_value& + tree_evaluator::global_varref (const std::string& name) + { + return m_call_stack.global_varref (name); + } + + void + tree_evaluator::global_assign (const std::string& name, + const octave_value& val) + { + m_call_stack.global_varref (name) = val; + } + + octave_value + tree_evaluator::top_level_varval (const std::string& name) const + { + return m_call_stack.get_top_level_value (name); + } + + void + tree_evaluator::top_level_assign (const std::string& name, + const octave_value& val) + { + m_call_stack.set_top_level_value (name, val); + } + + void + tree_evaluator::assign (const std::string& name, const octave_value& val) + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + frame->assign (name, val); + } + + void + tree_evaluator::assignin (const std::string& context, + const std::string& name, const octave_value& val) + { + // FIXME: Can this be done without an unwind-protect frame, simply + // by getting a reference to the caller or base stack frame and + // calling assign on that? + + unwind_action act ([=] (std::size_t frm) + { + m_call_stack.restore_frame (frm); + }, m_call_stack.current_frame ()); + + if (context == "caller") + m_call_stack.goto_caller_frame (); + else if (context == "base") + m_call_stack.goto_base_frame (); + else + error (R"(assignin: CONTEXT must be "caller" or "base")"); + + if (valid_identifier (name)) + { + // Put the check here so that we don't slow down assignments + // generally. Any that go through Octave's parser should have + // already been checked. + + if (iskeyword (name)) + error ("assignin: invalid assignment to keyword '%s'", + name.c_str ()); + + assign (name, val); + } + else + error ("assignin: invalid variable name '%s'", name.c_str ()); + } + + void + tree_evaluator::source_file (const std::string& file_name, + const std::string& context, + bool verbose, bool require_file) + { + // Map from absolute name of script file to recursion level. We + // use a map instead of simply placing a limit on recursion in the + // source_file function so that two mutually recursive scripts + // written as + // + // foo1.m: + // ------ + // foo2 + // + // foo2.m: + // ------ + // foo1 + // + // and called with + // + // foo1 + // + // (for example) will behave the same if they are written as + // + // foo1.m: + // ------ + // source ("foo2.m") + // + // foo2.m: + // ------ + // source ("foo1.m") + // + // and called with + // + // source ("foo1.m") + // + // (for example). + + static std::map source_call_depth; + + std::string file_full_name + = sys::file_ops::tilde_expand (file_name); + + std::size_t pos + = file_full_name.find_last_of (sys::file_ops::dir_sep_str ()); + + std::string dir_name = file_full_name.substr (0, pos); + + file_full_name = sys::env::make_absolute (file_full_name); + + unwind_protect frame; + + if (source_call_depth.find (file_full_name) == source_call_depth.end ()) + source_call_depth[file_full_name] = -1; + + frame.protect_var (source_call_depth[file_full_name]); + + source_call_depth[file_full_name]++; + + if (source_call_depth[file_full_name] >= max_recursion_depth ()) + error ("max_recursion_depth exceeded"); + + if (! context.empty ()) + { + frame.add (&call_stack::restore_frame, &m_call_stack, + m_call_stack.current_frame ()); + + if (context == "caller") + m_call_stack.goto_caller_frame (); + else if (context == "base") + m_call_stack.goto_base_frame (); + else + error (R"(source: CONTEXT must be "caller" or "base")"); + } + + // Find symbol name that would be in symbol_table, if it were loaded. + std::size_t dir_end + = file_name.find_last_of (sys::file_ops::dir_sep_chars ()); + dir_end = (dir_end == std::string::npos) ? 0 : dir_end + 1; + + std::size_t extension = file_name.find_last_of ('.'); + if (extension == std::string::npos) + extension = file_name.length (); + + std::string symbol = file_name.substr (dir_end, extension - dir_end); + std::string full_name = sys::canonicalize_file_name (file_name); + + // Check if this file is already loaded (or in the path) + symbol_table& symtab = m_interpreter.get_symbol_table (); + octave_value ov_code = symtab.fcn_table_find (symbol); + + // For compatibility with Matlab, accept both scripts and + // functions. + + if (ov_code.is_user_code ()) + { + octave_user_code *code = ov_code.user_code_value (); + + if (! code + || (sys::canonicalize_file_name (code->fcn_file_name ()) + != full_name)) + { + // Wrong file, so load it below. + ov_code = octave_value (); + } + } + else + { + // Not a script, so load it below. + ov_code = octave_value (); + } + + // If no symbol of this name, or the symbol is for a different + // file, load. + + if (ov_code.is_undefined ()) + { + try + { + ov_code = parse_fcn_file (m_interpreter, file_full_name, + file_name, dir_name, "", "", + require_file, true, false, false); + } + catch (execution_exception& ee) + { + error (ee, "source: error sourcing file '%s'", + file_full_name.c_str ()); + } + } + + // Return or error if we don't have a valid script or function. + + if (ov_code.is_undefined ()) + return; + + if (! ov_code.is_user_code ()) + error ("source: %s is not a script", full_name.c_str ()); + + if (verbose) + { + octave_stdout << "executing commands from " << full_name << " ... "; + octave_stdout.flush (); + } + + octave_user_code *code = ov_code.user_code_value (); + + code->call (*this, 0, octave_value_list ()); + + if (verbose) + octave_stdout << "done." << std::endl; + } + + void + tree_evaluator::set_auto_fcn_var (stack_frame::auto_var_type avt, + const octave_value& val) + { + m_call_stack.set_auto_fcn_var (avt, val); + } + + octave_value + tree_evaluator::get_auto_fcn_var (stack_frame::auto_var_type avt) const + { + return m_call_stack.get_auto_fcn_var (avt); + } + + void + tree_evaluator::define_parameter_list_from_arg_vector + (tree_parameter_list *param_list, const octave_value_list& args) + { + if (! param_list || param_list->varargs_only ()) + return; + + int i = -1; + + for (tree_decl_elt *elt : *param_list) + { + i++; + + octave_lvalue ref = elt->lvalue (*this); + + if (i < args.length ()) + { + if (args(i).is_defined () && args(i).is_magic_colon ()) + { + if (! eval_decl_elt (elt)) + error ("no default value for argument %d", i+1); + } + else + ref.define (args(i)); + } + else + eval_decl_elt (elt); + } + } + + void + tree_evaluator::undefine_parameter_list (tree_parameter_list *param_list) + { + for (tree_decl_elt *elt : *param_list) + { + octave_lvalue ref = elt->lvalue (*this); + + ref.assign (octave_value::op_asn_eq, octave_value ()); + } + } // END is documented in op-kw-docs. DEFMETHOD (end, interp, args, , @@ -2292,2989 +2271,2988 @@ %! assert (x(minus (minus (end, 1), 1)), 8); */ -octave_value_list -tree_evaluator::convert_to_const_vector (tree_argument_list *args) -{ - std::list arg_vals; - - for (auto elt : *args) - { - // FIXME: is it possible for elt to be invalid? - - if (! elt) + octave_value_list + tree_evaluator::convert_to_const_vector (tree_argument_list *args) + { + std::list arg_vals; + + for (auto elt : *args) + { + // FIXME: is it possible for elt to be invalid? + + if (! elt) + break; + + octave_value tmp = elt->evaluate (*this); + + if (tmp.is_cs_list ()) + { + octave_value_list tmp_ovl = tmp.list_value (); + + for (octave_idx_type i = 0; i < tmp_ovl.length (); i++) + arg_vals.push_back (tmp_ovl(i)); + } + else if (tmp.is_defined ()) + arg_vals.push_back (tmp); + } + + return octave_value_list (arg_vals); + } + + octave_value_list + tree_evaluator::convert_return_list_to_const_vector + (tree_parameter_list *ret_list, int nargout, const Matrix& ignored_outputs, + const Cell& varargout) + { + octave_idx_type vlen = varargout.numel (); + int len = ret_list->length (); + + // Special case. Will do a shallow copy. + if (len == 0) + return varargout; + else + { + int i = 0; + int k = 0; + int num_ignored = ignored_outputs.numel (); + int ignored = num_ignored > 0 ? ignored_outputs(k) - 1 : -1; + + if (nargout <= len) + { + int nout = nargout > 0 ? nargout : 1; + octave_value_list retval (nout); + + for (tree_decl_elt *elt : *ret_list) + { + if (nargout == 0 && ! is_defined (elt->ident ())) + break; + + if (ignored >= 0 && i == ignored) + { + i++; + k++; + ignored = k < num_ignored ? ignored_outputs(k) - 1 : -1; + } + else + retval(i++) = evaluate (elt); + + if (i == nout) + break; + } + + return retval; + } + else + { + octave_value_list retval (len + vlen); + + for (tree_decl_elt *elt : *ret_list) + { + if (ignored >= 0 && i == ignored) + { + i++; + k++; + ignored = k < num_ignored ? ignored_outputs(k) - 1 : -1; + } + else + retval(i++) = evaluate (elt); + } + + for (octave_idx_type j = 0; j < vlen; j++) + retval(i++) = varargout(j); + + return retval; + } + } + } + + bool + tree_evaluator::eval_decl_elt (tree_decl_elt *elt) + { + bool retval = false; + + tree_identifier *id = elt->ident (); + tree_expression *expr = elt->expression (); + + if (id && expr) + { + octave_lvalue ult = id->lvalue (*this); + + octave_value init_val = expr->evaluate (*this); + + ult.assign (octave_value::op_asn_eq, init_val); + + retval = true; + } + + return retval; + } + + bool + tree_evaluator::switch_case_label_matches (tree_switch_case *expr, + const octave_value& val) + { + tree_expression *label = expr->case_label (); + + octave_value label_value = label->evaluate (*this); + + if (label_value.is_defined ()) + { + if (label_value.iscell ()) + { + Cell cell (label_value.cell_value ()); + + for (octave_idx_type i = 0; i < cell.rows (); i++) + { + for (octave_idx_type j = 0; j < cell.columns (); j++) + { + bool match = val.is_equal (cell(i,j)); + + if (match) + return true; + } + } + } + else + return val.is_equal (label_value); + } + + return false; + } + + void tree_evaluator::push_stack_frame (const symbol_scope& scope) + { + m_call_stack.push (scope); + } + + void tree_evaluator::push_stack_frame (octave_user_function *fcn, + const std::shared_ptr& closure_frames) + { + m_call_stack.push (fcn, closure_frames); + } + + void tree_evaluator::push_stack_frame (octave_user_function *fcn, + const stack_frame::local_vars_map& local_vars, + const std::shared_ptr& closure_frames) + { + m_call_stack.push (fcn, local_vars, closure_frames); + } + + void tree_evaluator::push_stack_frame (octave_user_script *script) + { + m_call_stack.push (script); + } + + void tree_evaluator::push_stack_frame (octave_function *fcn) + { + m_call_stack.push (fcn); + } + + void tree_evaluator::pop_stack_frame () + { + m_call_stack.pop (); + } + + int tree_evaluator::current_line () const + { + return m_call_stack.current_line (); + } + + int tree_evaluator::current_column () const + { + return m_call_stack.current_column (); + } + + int tree_evaluator::debug_user_code_line () const + { + return m_call_stack.debug_user_code_line (); + } + + int tree_evaluator::debug_user_code_column () const + { + return m_call_stack.debug_user_code_column (); + } + + void tree_evaluator::debug_where (std::ostream& os) const + { + std::shared_ptr frm = m_call_stack.current_user_frame (); + + frm->display_stopped_in_message (os); + } + + octave_user_code * tree_evaluator::current_user_code () const + { + return m_call_stack.current_user_code (); + } + + unwind_protect * tree_evaluator::curr_fcn_unwind_protect_frame () + { + return m_call_stack.curr_fcn_unwind_protect_frame (); + } + + octave_user_code * tree_evaluator::debug_user_code () const + { + return m_call_stack.debug_user_code (); + } + + octave_function * tree_evaluator::current_function (bool skip_first) const + { + return m_call_stack.current_function (skip_first); + } + + octave_function * tree_evaluator::caller_function () const + { + return m_call_stack.current_function (true); + } + + bool tree_evaluator::goto_frame (std::size_t n, bool verbose) + { + return m_call_stack.goto_frame (n, verbose); + } + + void tree_evaluator::goto_caller_frame () + { + m_call_stack.goto_caller_frame (); + } + + void tree_evaluator::goto_base_frame () + { + m_call_stack.goto_base_frame (); + } + + void tree_evaluator::restore_frame (std::size_t n) + { + return m_call_stack.restore_frame (n); + } + + std::string tree_evaluator::get_dispatch_class () const + { + return m_call_stack.get_dispatch_class (); + } + + void tree_evaluator::set_dispatch_class (const std::string& class_name) + { + m_call_stack.set_dispatch_class (class_name); + } + + bool + tree_evaluator::is_class_method_executing (std::string& dclass) const + { + return m_call_stack.is_class_method_executing (dclass); + } + + bool + tree_evaluator::is_class_constructor_executing (std::string& dclass) const + { + return m_call_stack.is_class_constructor_executing (dclass); + } + + std::list> + tree_evaluator::backtrace_frames (octave_idx_type& curr_user_frame) const + { + return m_call_stack.backtrace_frames (curr_user_frame); + } + + std::list> + tree_evaluator::backtrace_frames () const + { + return m_call_stack.backtrace_frames (); + } + + std::list + tree_evaluator::backtrace_info (octave_idx_type& curr_user_frame, + bool print_subfn) const + { + return m_call_stack.backtrace_info (curr_user_frame, print_subfn); + } + + std::list tree_evaluator::backtrace_info () const + { + return m_call_stack.backtrace_info (); + } + + octave_map + tree_evaluator::backtrace (octave_idx_type& curr_user_frame, + bool print_subfn) const + { + return m_call_stack.backtrace (curr_user_frame, print_subfn); + } + + octave_map tree_evaluator::backtrace () const + { + return m_call_stack.backtrace (); + } + + octave_map tree_evaluator::empty_backtrace () const + { + return m_call_stack.empty_backtrace (); + } + + std::string tree_evaluator::backtrace_message () const + { + std::list frames = backtrace_info (); + + std::ostringstream buf; + + for (const auto& frm : frames) + { + buf << " " << frm.fcn_name (); + + int line = frm.line (); + + if (line > 0) + { + buf << " at line " << line; + + int column = frm.column (); + + if (column > 0) + buf << " column " << column; + + buf << "\n"; + } + } + + return buf.str (); + } + + void tree_evaluator::push_dummy_scope (const std::string& name) + { + symbol_scope dummy_scope (name + "$dummy"); + + m_call_stack.push (dummy_scope); + } + + void tree_evaluator::pop_scope () + { + m_call_stack.pop (); + } + + symbol_scope tree_evaluator::get_top_scope () const + { + return m_call_stack.top_scope (); + } + + symbol_scope tree_evaluator::get_current_scope () const + { + return m_call_stack.current_scope (); + } + + void tree_evaluator::mlock (bool skip_first) const + { + octave_function *fcn = m_call_stack.current_function (skip_first); + + if (! fcn) + error ("mlock: invalid use outside a function"); + + if (fcn->is_builtin_function ()) + { + warning ("mlock: locking built-in function has no effect"); + return; + } + + fcn->lock (); + } + + void tree_evaluator::munlock (bool skip_first) const + { + octave_function *fcn = m_call_stack.current_function (skip_first); + + if (! fcn) + error ("munlock: invalid use outside a function"); + + if (fcn->is_builtin_function ()) + { + warning ("munlock: unlocking built-in function has no effect"); + return; + } + + fcn->unlock (); + } + + bool tree_evaluator::mislocked (bool skip_first) const + { + octave_function *fcn = m_call_stack.current_function (skip_first); + + if (! fcn) + error ("mislocked: invalid use outside a function"); + + return fcn->islocked (); + } + + octave_value + tree_evaluator::max_stack_depth (const octave_value_list& args, int nargout) + { + return m_call_stack.max_stack_depth (args, nargout); + } + + void tree_evaluator::display_call_stack () const + { + m_call_stack.display (); + } + + octave_value tree_evaluator::find (const std::string& name) + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + octave_value val = frame->varval (name); + + if (val.is_defined ()) + return val; + + // Subfunction. I think it only makes sense to check for + // subfunctions if we are currently executing a function defined + // from a .m file. + + octave_value fcn = frame->find_subfunction (name); + + if (fcn.is_defined ()) + return fcn; + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + return symtab.fcn_table_find (name, ovl ()); + } + + void tree_evaluator::clear_objects () + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + frame->clear_objects (); + } + + void tree_evaluator::clear_variable (const std::string& name) + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + frame->clear_variable (name); + } + + void tree_evaluator::clear_variable_pattern (const std::string& pattern) + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + frame->clear_variable_pattern (pattern); + } + + void tree_evaluator::clear_variable_regexp (const std::string& pattern) + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + frame->clear_variable_regexp (pattern); + } + + void tree_evaluator::clear_variables () + { + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + frame->clear_variables (); + } + + void tree_evaluator::clear_global_variable (const std::string& name) + { + m_call_stack.clear_global_variable (name); + } + + void + tree_evaluator::clear_global_variable_pattern (const std::string& pattern) + { + m_call_stack.clear_global_variable_pattern (pattern); + } + + void tree_evaluator::clear_global_variable_regexp(const std::string& pattern) + { + m_call_stack.clear_global_variable_regexp (pattern); + } + + void tree_evaluator::clear_global_variables () + { + m_call_stack.clear_global_variables (); + } + + void tree_evaluator::clear_all (bool force) + { + // FIXME: should this also clear objects? + + clear_variables (); + clear_global_variables (); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + symtab.clear_functions (force); + } + + void tree_evaluator::clear_symbol (const std::string& name) + { + // FIXME: are we supposed to do both here? + + clear_variable (name); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + symtab.clear_function (name); + } + + void tree_evaluator::clear_symbol_pattern (const std::string& pattern) + { + // FIXME: are we supposed to do both here? + + clear_variable_pattern (pattern); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + symtab.clear_function_pattern (pattern); + } + + void tree_evaluator::clear_symbol_regexp (const std::string& pattern) + { + // FIXME: are we supposed to do both here? + + clear_variable_regexp (pattern); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + symtab.clear_function_regexp (pattern); + } + + std::list tree_evaluator::global_variable_names () const + { + return m_call_stack.global_variable_names (); + } + + std::list tree_evaluator::top_level_variable_names () const + { + return m_call_stack.top_level_variable_names (); + } + + std::list tree_evaluator::variable_names () const + { + return m_call_stack.variable_names (); + } + + // Return a pointer to the user-defined function FNAME. If FNAME is empty, + // search backward for the first user-defined function in the + // current call stack. + + octave_user_code * + tree_evaluator::get_user_code (const std::string& fname, + const std::string& class_name) + { + octave_user_code *user_code = nullptr; + + if (fname.empty ()) + user_code = m_call_stack.debug_user_code (); + else + { + std::string name = fname; + + if (sys::file_ops::dir_sep_char () != '/' && name[0] == '@') + { + auto beg = name.begin () + 2; // never have @/method + auto end = name.end () - 1; // never have trailing '/' + std::replace (beg, end, '/', sys::file_ops::dir_sep_char ()); + } + + std::size_t name_len = name.length (); + + if (name_len > 2 && name.substr (name_len-2) == ".m") + name = name.substr (0, name_len-2); + + if (name.empty ()) + return nullptr; + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + octave_value fcn; + std::size_t p2 = std::string::npos; + + if (name[0] == '@') + { + std::size_t p1 = name.find (sys::file_ops::dir_sep_char (), 1); + + if (p1 == std::string::npos) + return nullptr; + + std::string dispatch_type = name.substr (1, p1-1); + + p2 = name.find ('>', p1); + + std::string method = name.substr (p1+1, p2-1); + + fcn = symtab.find_method (method, dispatch_type); + } + else if (! class_name.empty ()) + { + cdef_manager& cdm = m_interpreter.get_cdef_manager (); + + fcn = cdm.find_method (class_name, name); + + // If there is no classdef method, then try legacy classes. + if (fcn.is_undefined ()) + fcn = symtab.find_method (name, class_name); + } + else + { + p2 = name.find ('>'); + + std::string main_fcn = name.substr (0, p2); + + fcn = symtab.find_function (main_fcn); + } + + // List of function names sub1>sub2>... + std::string subfuns; + + if (p2 != std::string::npos) + subfuns = name.substr (p2+1); + + if (fcn.is_defined () && fcn.is_user_code ()) + user_code = fcn.user_code_value (); + + if (! user_code || subfuns.empty ()) + return user_code; + + fcn = user_code->find_subfunction (subfuns); + + if (fcn.is_undefined ()) + return nullptr; + + user_code = fcn.user_code_value (); + } + + return user_code; + } + + std::string + tree_evaluator::current_function_name (bool skip_first) const + { + octave_function *curfcn = m_call_stack.current_function (skip_first); + + if (curfcn) + return curfcn->name (); + + return ""; + } + + bool + tree_evaluator::in_user_code () const + { + return m_call_stack.current_user_code () != nullptr; + } + + void + tree_evaluator::visit_decl_command (tree_decl_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + // FIXME: tree_decl_init_list is not derived from tree, so should it + // really have an accept method? + + tree_decl_init_list *init_list = cmd.initializer_list (); + + if (init_list) + init_list->accept (*this); + } + + void + tree_evaluator::visit_decl_elt (tree_decl_elt& elt) + { + tree_identifier *id = elt.ident (); + + if (id) + { + if (elt.is_global ()) + m_call_stack.make_global (id->symbol ()); + else if (elt.is_persistent ()) + m_call_stack.make_persistent (id->symbol ()); + else + error ("declaration list element not global or persistent"); + + octave_lvalue ult = id->lvalue (*this); + + if (ult.is_undefined ()) + { + tree_expression *expr = elt.expression (); + + octave_value init_val; + + if (expr) + init_val = expr->evaluate (*this); + else + init_val = Matrix (); + + ult.assign (octave_value::op_asn_eq, init_val); + } + } + } + + template + void + tree_evaluator::execute_range_loop (const range& rng, int line, + octave_lvalue& ult, + tree_statement_list *loop_body) + { + octave_idx_type steps = rng.numel (); + + if (math::isinf (rng.limit ())) + warning_with_id ("Octave:infinite-loop", + "FOR loop limit is infinite, will stop after %" + OCTAVE_IDX_TYPE_FORMAT " steps", steps); + + for (octave_idx_type i = 0; i < steps; i++) + { + if (m_echo_state) + m_echo_file_pos = line; + + octave_value val (rng.elem (i)); + + ult.assign (octave_value::op_asn_eq, val); + + if (loop_body) + loop_body->accept (*this); + + if (quit_loop_now ()) + break; + } + } + + void + tree_evaluator::visit_simple_for_command (tree_simple_for_command& cmd) + { + int line = cmd.line (); + if (line < 0) + line = 1; + + if (m_echo_state) + { + echo_code (line); + line++; + } + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + // FIXME: need to handle PARFOR loops here using cmd.in_parallel () + // and cmd.maxproc_expr (); + + unwind_protect_var upv (m_in_loop_command, true); + + tree_expression *expr = cmd.control_expr (); + + octave_value rhs = expr->evaluate (*this); + + if (rhs.is_undefined ()) + return; + + tree_expression *lhs = cmd.left_hand_side (); + + octave_lvalue ult = lhs->lvalue (*this); + + tree_statement_list *loop_body = cmd.body (); + + if (rhs.is_range ()) + { + // FIXME: is there a better way to dispatch here? + + if (rhs.is_double_type ()) + { + execute_range_loop (rhs.range_value (), line, ult, loop_body); + return; + } + + // For now, disable all but range. + +#if 0 + if (rhs.is_int64_type ()) + { + execute_range_loop (rhs.int64_range_value (), line, ult, loop_body); + return; + } + + if (rhs.is_uint64_type ()) + { + execute_range_loop (rhs.uint64_range_value (), line, ult, loop_body); + return; + } + + if (rhs.is_int32_type ()) + { + execute_range_loop (rhs.int32_range_value (), line, ult, loop_body); + return; + } + + if (rhs.is_uint32_type ()) + { + execute_range_loop (rhs.uint32_range_value (), line, ult, loop_body); + return; + } + + if (rhs.is_int16_type ()) + { + execute_range_loop (rhs.int16_range_value (), line, ult, loop_body); + return; + } + + if (rhs.is_uint16_type ()) + { + execute_range_loop (rhs.uint16_range_value (), line, ult, loop_body); + return; + } + + if (rhs.is_int8_type ()) + { + execute_range_loop (rhs.int8_range_value (), line, ult, loop_body); + return; + } + + if (rhs.is_uint8_type ()) + { + execute_range_loop (rhs.uint8_range_value (), line, ult, loop_body); + return; + } + + if (rhs.is_single_type ()) + { + execute_range_loop (rhs.float_range_value (), line, ult, loop_body); + return; + } +#endif + } + + if (rhs.is_scalar_type ()) + { + if (m_echo_state) + m_echo_file_pos = line; + + ult.assign (octave_value::op_asn_eq, rhs); + + if (loop_body) + loop_body->accept (*this); + + // Maybe decrement break and continue states. + quit_loop_now (); + + return; + } + + // Also handle any range types not explicitly handled above, though + // not as efficiently as the specialized code above. + + if (rhs.is_range () || rhs.is_matrix_type () || rhs.iscell () + || rhs.is_string () || rhs.isstruct ()) + { + // A matrix or cell is reshaped to 2 dimensions and iterated by + // columns. + + dim_vector dv = rhs.dims ().redim (2); + + octave_idx_type nrows = dv(0); + octave_idx_type steps = dv(1); + + octave_value arg = rhs; + if (rhs.ndims () > 2) + arg = arg.reshape (dv); + + if (nrows > 0 && steps > 0) + { + octave_value_list idx; + octave_idx_type iidx; + + // for row vectors, use single index to speed things up. + if (nrows == 1) + { + idx.resize (1); + iidx = 0; + } + else + { + idx.resize (2); + idx(0) = octave_value::magic_colon_t; + iidx = 1; + } + + for (octave_idx_type i = 1; i <= steps; i++) + { + if (m_echo_state) + m_echo_file_pos = line; + + // index_op expects one-based indices. + idx(iidx) = i; + octave_value val = arg.index_op (idx); + + ult.assign (octave_value::op_asn_eq, val); + + if (loop_body) + loop_body->accept (*this); + + if (quit_loop_now ()) + break; + } + } + else + { + // Handle empty cases, while still assigning to loop var. + ult.assign (octave_value::op_asn_eq, arg); + } + + return; + } + + error ("invalid type in for loop expression near line %d, column %d", + cmd.line (), cmd.column ()); + } + + void + tree_evaluator::visit_complex_for_command (tree_complex_for_command& cmd) + { + int line = cmd.line (); + if (line < 0) + line = 1; + + if (m_echo_state) + { + echo_code (line); + line++; + } + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + unwind_protect_var upv (m_in_loop_command, true); + + tree_expression *expr = cmd.control_expr (); + + octave_value rhs = expr->evaluate (*this); + + if (rhs.is_undefined ()) + return; + + if (! rhs.isstruct ()) + error ("in statement 'for [X, Y] = VAL', VAL must be a structure"); + + // Cycle through structure elements. First element of id_list + // is set to value and the second is set to the name of the + // structure element. + + tree_argument_list *lhs = cmd.left_hand_side (); + + auto p = lhs->begin (); + + tree_expression *elt = *p++; + + octave_lvalue val_ref = elt->lvalue (*this); + + elt = *p; + + octave_lvalue key_ref = elt->lvalue (*this); + + const octave_map tmp_val = rhs.map_value (); + + tree_statement_list *loop_body = cmd.body (); + + string_vector keys = tmp_val.keys (); + + octave_idx_type nel = keys.numel (); + + for (octave_idx_type i = 0; i < nel; i++) + { + if (m_echo_state) + m_echo_file_pos = line; + + std::string key = keys[i]; + + const Cell val_lst = tmp_val.contents (key); + + octave_idx_type n = val_lst.numel (); + + octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst); + + val_ref.assign (octave_value::op_asn_eq, val); + key_ref.assign (octave_value::op_asn_eq, key); + + if (loop_body) + loop_body->accept (*this); + + if (quit_loop_now ()) + break; + } + } + + void tree_evaluator::visit_spmd_command (tree_spmd_command& cmd) + { + // For now, we just execute the commands serially. + + tree_statement_list *body = cmd.body (); + + if (body) + body->accept (*this); + } + + octave_value + tree_evaluator::evaluate_anon_fcn_handle (tree_anon_fcn_handle& afh) + { + // FIXME: should CMD_LIST be limited to a single expression? + // I think that is what Matlab does. + + symbol_scope new_scope; + symbol_scope scope = afh.scope (); + if (scope) + new_scope = scope.dup (); + + tree_parameter_list *param_list = afh.parameter_list (); + tree_parameter_list *param_list_dup + = param_list ? param_list->dup (new_scope) : nullptr; + + tree_parameter_list *ret_list = nullptr; + + tree_statement_list *stmt_list = nullptr; + + symbol_scope parent_scope = get_current_scope (); + + new_scope.set_parent (parent_scope); + new_scope.set_primary_parent (parent_scope); + + tree_expression *expr = afh.expression (); + if (expr) + { + tree_expression *expr_dup = expr->dup (new_scope); + tree_statement *stmt = new tree_statement (expr_dup, nullptr); + stmt_list = new tree_statement_list (stmt); + } + + tree_anon_scopes anon_fcn_ctx (afh); + + std::set free_vars = anon_fcn_ctx.free_variables (); + + stack_frame::local_vars_map local_vars; + + std::shared_ptr frame + = m_call_stack.get_current_stack_frame (); + + for (auto& name : free_vars) + { + octave_value val = frame->varval (name); + + if (val.is_defined ()) + local_vars[name] = val; + } + + octave_user_function *af + = new octave_user_function (new_scope, param_list_dup, ret_list, + stmt_list); + + octave_function *curr_fcn = m_call_stack.current_function (); + + bool is_nested = false; + + if (curr_fcn) + { + // FIXME: maybe it would be better to just stash curr_fcn + // instead of individual bits of info about it? + + // An anonymous function defined inside another nested function + // or parent of a nested function also behaves like a nested + // function. + + if (curr_fcn->is_parent_function () || curr_fcn->is_nested_function ()) + { + is_nested = true; + af->mark_as_nested_function (); + new_scope.set_nesting_depth (parent_scope.nesting_depth () + 1); + } + + af->stash_dir_name (curr_fcn->dir_name ()); + + new_scope.cache_fcn_file_name (curr_fcn->fcn_file_name ()); + new_scope.cache_dir_name (curr_fcn->dir_name ()); + + // The following is needed so that class method dispatch works + // properly for anonymous functions that wrap class methods. + + if (curr_fcn->is_class_method () || curr_fcn->is_class_constructor ()) + af->stash_dispatch_class (curr_fcn->dispatch_class ()); + + af->stash_fcn_file_name (curr_fcn->fcn_file_name ()); + } + + af->mark_as_anonymous_function (); + + octave_value ov_fcn (af); + + return (is_nested + ? octave_value (new octave_fcn_handle (ov_fcn, local_vars, frame)) + : octave_value (new octave_fcn_handle (ov_fcn, local_vars))); + } + + octave_value_list + tree_evaluator::execute_builtin_function (octave_builtin& builtin_function, + int nargout, + const octave_value_list& args) + { + octave_value_list retval; + + if (args.has_magic_colon ()) + error ("invalid use of colon in function argument list"); + + profiler::enter block (m_profiler, builtin_function); + + octave_builtin::fcn fcn = builtin_function.function (); + + if (fcn) + retval = (*fcn) (args, nargout); + else + { + octave_builtin::meth meth = builtin_function.method (); + + retval = (*meth) (m_interpreter, args, nargout); + } + + // Do not allow null values to be returned from functions. + // FIXME: perhaps true builtins should be allowed? + + retval.make_storable_values (); + + // Fix the case of a single undefined value. + // This happens when a compiled function uses + // + // octave_value retval; + // + // instead of + // + // octave_value_list retval; + // + // the idiom is very common, so we solve that here. + + if (retval.length () == 1 && retval.xelem (0).is_undefined ()) + retval.clear (); + + return retval; + } + + octave_value_list + tree_evaluator::execute_mex_function (octave_mex_function& mex_function, + int nargout, + const octave_value_list& args) + { + octave_value_list retval; + + if (args.has_magic_colon ()) + error ("invalid use of colon in function argument list"); + + profiler::enter block (m_profiler, mex_function); + + retval = call_mex (mex_function, args, nargout); + + return retval; + } + + octave_value_list + tree_evaluator::execute_user_script (octave_user_script& user_script, + int nargout, + const octave_value_list& args) + { + octave_value_list retval; + + std::string file_name = user_script.fcn_file_name (); + + if (args.length () != 0 || nargout != 0) + error ("invalid call to script %s", file_name.c_str ()); + + tree_statement_list *cmd_list = user_script.body (); + + if (! cmd_list) + return retval; + + // FIXME: Maybe this check belongs in the places where we push a new + // stack frame? Or in the call_stack push method itself? + + if (m_call_stack.size () >= static_cast (m_max_recursion_depth)) + error ("max_recursion_depth exceeded"); + + unwind_protect_var upv (m_statement_context, SC_SCRIPT); + + profiler::enter block (m_profiler, user_script); + + if (echo ()) + push_echo_state (tree_evaluator::ECHO_SCRIPTS, file_name); + + // FIXME: Should we be using tree_evaluator::eval here? + + cmd_list->accept (*this); + + if (m_returning) + m_returning = 0; + + if (m_breaking) + m_breaking--; + + return retval; + } + + void + tree_evaluator::visit_octave_user_script (octave_user_script&) + { + // ?? + panic_impossible (); + } + + octave_value_list + tree_evaluator::execute_user_function (octave_user_function& user_function, + int nargout, + const octave_value_list& xargs) + { + octave_value_list retval; + + // If this function is a classdef constructor, extract the first input + // argument, which must be the partially constructed object instance. + + octave_value_list args (xargs); + octave_value_list ret_args; + + int nargin = args.length (); + + if (user_function.is_classdef_constructor ()) + { + if (nargin > 0) + { + ret_args = args.slice (0, 1, true); + --nargin; + args = args.slice (1, nargin, true); + } + else + panic_impossible (); + } + + // FIXME: this probably shouldn't be a double-precision matrix. + Matrix ignored_outputs = ignored_fcn_outputs (); + + tree_parameter_list *param_list = user_function.parameter_list (); + + bool takes_varargs = false; + int max_inputs = 0; + + if (param_list) + { + takes_varargs = param_list->takes_varargs (); + max_inputs = param_list->length (); + } + + if (! takes_varargs && nargin > max_inputs) + { + std::string name = user_function.name (); + + if (name.empty ()) + name = "@"; + + error_with_id ("Octave:invalid-fun-call", + "%s: function called with too many inputs", + name.c_str ()); + } + + define_parameter_list_from_arg_vector (param_list, args); + + tree_parameter_list *ret_list = user_function.return_list (); + + if (ret_list && ! ret_list->takes_varargs ()) + { + int max_outputs = ret_list->length (); + + if (nargout > max_outputs) + { + std::string name = user_function.name (); + + error_with_id ("Octave:invalid-fun-call", + "%s: function called with too many outputs", + name.c_str ()); + } + } + + bind_auto_fcn_vars (xargs.name_tags (), ignored_outputs, nargin, + nargout, user_function.takes_varargs (), + user_function.all_va_args (args)); + + // For classdef constructor, pre-populate the output arguments + // with the pre-initialized object instance, extracted above. + + if (user_function.is_classdef_constructor ()) + { + if (! ret_list) + error ("%s: invalid classdef constructor, no output argument defined", + user_function.dispatch_class ().c_str ()); + + define_parameter_list_from_arg_vector (ret_list, ret_args); + } + + // FIXME: Maybe this check belongs in the places where we push a + // new stack frame? Or in the call_stack push method itself? + + if (m_call_stack.size () >= static_cast (m_max_recursion_depth)) + error ("max_recursion_depth exceeded"); + + unwind_action act2 ([&user_function] () { + user_function.restore_warning_states (); + }); + + // Evaluate the commands that make up the function. + + unwind_protect_var upv (m_statement_context, SC_FUNCTION); + + tree_statement_list *cmd_list = user_function.body (); + + if (cmd_list) + { + profiler::enter + block (m_profiler, user_function); + + if (echo ()) + push_echo_state (tree_evaluator::ECHO_FUNCTIONS, + user_function.fcn_file_name ()); + + if (user_function.is_special_expr ()) + { + panic_if (cmd_list->length () != 1); + + tree_statement *stmt = cmd_list->front (); + + tree_expression *expr = stmt->expression (); + + if (expr) + { + m_call_stack.set_location (stmt->line (), stmt->column ()); + + retval = expr->evaluate_n (*this, nargout); + } + } + else + cmd_list->accept (*this); + + if (m_returning) + m_returning = 0; + + if (m_breaking) + m_breaking--; + } + + // Copy return values out. + + if (ret_list && ! user_function.is_special_expr ()) + { + Cell varargout; + + if (ret_list->takes_varargs ()) + { + octave_value varargout_varval = varval ("varargout"); + + if (varargout_varval.is_defined ()) + varargout = varargout_varval.xcell_value ("varargout must be a cell array object"); + } + + retval = convert_return_list_to_const_vector (ret_list, nargout, + ignored_outputs, + varargout); + } + + return retval; + } + + void + tree_evaluator::visit_octave_user_function (octave_user_function&) + { + // ?? + panic_impossible (); + } + + void + tree_evaluator::visit_octave_user_function_header (octave_user_function&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_octave_user_function_trailer (octave_user_function&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_function_def (tree_function_def& cmd) + { + octave_value fcn = cmd.function (); + + octave_function *f = fcn.function_value (); + + if (f) + { + std::string nm = f->name (); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + symtab.install_cmdline_function (nm, fcn); + + // Make sure that any variable with the same name as the new + // function is cleared. + + assign (nm); + } + } + + void + tree_evaluator::visit_identifier (tree_identifier&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_if_clause (tree_if_clause&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_if_command (tree_if_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + // FIXME: tree_if_command_list is not derived from tree, so should it + // really have an accept method? + + tree_if_command_list *lst = cmd.cmd_list (); + + if (lst) + lst->accept (*this); + } + + void + tree_evaluator::visit_if_command_list (tree_if_command_list& lst) + { + for (tree_if_clause *tic : lst) + { + tree_expression *expr = tic->condition (); + + if (! (in_debug_repl () + && m_call_stack.current_frame () == m_debug_frame)) + m_call_stack.set_location (tic->line (), tic->column ()); + + if (m_debug_mode && ! tic->is_else_clause ()) + do_breakpoint (tic->is_active_breakpoint (*this)); + + if (tic->is_else_clause () || is_logically_true (expr, "if")) + { + tree_statement_list *stmt_lst = tic->commands (); + + if (stmt_lst) + stmt_lst->accept (*this); + + break; + } + } + } + + void + tree_evaluator::visit_index_expression (tree_index_expression&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_matrix (tree_matrix&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_cell (tree_cell&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_multi_assignment (tree_multi_assignment&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_no_op_command (tree_no_op_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + if (m_debug_mode && cmd.is_end_of_fcn_or_script ()) + do_breakpoint (cmd.is_active_breakpoint (*this), true); + } + + void + tree_evaluator::visit_constant (tree_constant&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_fcn_handle (tree_fcn_handle&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_parameter_list (tree_parameter_list&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_postfix_expression (tree_postfix_expression&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_prefix_expression (tree_prefix_expression&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_return_command (tree_return_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + // Act like dbcont. + + if (in_debug_repl () && m_call_stack.current_frame () == m_debug_frame) + dbcont (); + else if (m_statement_context == SC_FUNCTION + || m_statement_context == SC_SCRIPT + || m_in_loop_command) + m_returning = 1; + } + + void + tree_evaluator::visit_simple_assignment (tree_simple_assignment&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_statement (tree_statement& stmt) + { + tree_command *cmd = stmt.command (); + tree_expression *expr = stmt.expression (); + + if (cmd || expr) + { + if (! (in_debug_repl () + && m_call_stack.current_frame () == m_debug_frame)) + m_call_stack.set_location (stmt.line (), stmt.column ()); + + try + { + if (cmd) + { + unwind_protect_var *> + upv (m_lvalue_list, nullptr); + + cmd->accept (*this); + } + else + { + if (m_echo_state) + { + int line = stmt.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + if (m_debug_mode) + do_breakpoint (expr->is_active_breakpoint (*this)); + + // FIXME: maybe all of this should be packaged in + // one virtual function that returns a flag saying whether + // or not the expression will take care of binding ans and + // printing the result. + + // FIXME: it seems that we should just have to + // evaluate the expression and that should take care of + // everything, binding ans as necessary? + + octave_value tmp_result = expr->evaluate (*this, 0); + + if (tmp_result.is_defined ()) + { + bool do_bind_ans = false; + + if (expr->is_identifier ()) + do_bind_ans = ! is_variable (expr); + else + do_bind_ans = ! expr->is_assignment_expression (); + + if (do_bind_ans) + bind_ans (tmp_result, expr->print_result () + && statement_printing_enabled ()); + } + } + } + catch (const std::bad_alloc&) + { + // FIXME: We want to use error_with_id here so that give users + // control over this error message but error_with_id will + // require some memory allocations. Is there anything we can + // do to make those more likely to succeed? + + error_with_id ("Octave:bad-alloc", + "out of memory or dimension too large for Octave's index type"); + } + catch (const interrupt_exception&) + { + // If we are debugging, then continue with next statement. + // Otherwise, jump out of here. + + if (m_debug_mode) + m_interpreter.recover_from_exception (); + else + throw; + } + catch (const execution_exception& ee) + { + error_system& es = m_interpreter.get_error_system (); + + if ((m_interpreter.interactive () + || application::forced_interactive ()) + && ((es.debug_on_error () + && m_bp_table.debug_on_err (es.last_error_id ())) + || (es.debug_on_caught () + && m_bp_table.debug_on_caught (es.last_error_id ()))) + && in_user_code ()) + { + es.save_exception (ee); + es.display_exception (ee); + + enter_debugger (); + + // It doesn't make sense to continue execution after an + // error occurs so force the debugger to quit all debug + // levels and return the the top prompt. + + throw quit_debug_exception (true); + } + else + throw; + } + } + } + + void + tree_evaluator::visit_statement_list (tree_statement_list& lst) + { + // FIXME: commented out along with else clause below. + // static octave_value_list empty_list; + + auto p = lst.begin (); + + if (p != lst.end ()) + { + while (true) + { + tree_statement *elt = *p++; + + if (! elt) + error ("invalid statement found in statement list!"); + + octave_quit (); + + elt->accept (*this); + + if (m_breaking || m_continuing) + break; + + if (m_returning) + break; + + if (p == lst.end ()) + break; + else + { + // Clear previous values before next statement is + // evaluated so that we aren't holding an extra + // reference to a value that may be used next. For + // example, in code like this: + // + // X = rand (N); # refcount for X should be 1 + // # after this statement + // + // X(idx) = val; # no extra copy of X should be + // # needed, but we will be faked + // # out if retval is not cleared + // # between statements here + + // result_values = empty_list; + } + } + } + } + + void + tree_evaluator::visit_switch_case (tree_switch_case&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_switch_case_list (tree_switch_case_list&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_switch_command (tree_switch_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + tree_expression *expr = cmd.switch_value (); + + if (! expr) + error ("missing value in switch command near line %d, column %d", + cmd.line (), cmd.column ()); + + octave_value val = expr->evaluate (*this); + + tree_switch_case_list *lst = cmd.case_list (); + + if (lst) + { + for (tree_switch_case *t : *lst) + { + if (t->is_default_case () || switch_case_label_matches (t, val)) + { + tree_statement_list *stmt_lst = t->commands (); + + if (stmt_lst) + stmt_lst->accept (*this); + + break; + } + } + } + } + + void + tree_evaluator::visit_try_catch_command (tree_try_catch_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + bool execution_error = false; + octave_scalar_map err_map; + + tree_statement_list *try_code = cmd.body (); + + if (try_code) + { + // unwind frame before catch block + + unwind_protect frame; + + interpreter_try (frame); + + // The catch code is *not* added to unwind_protect stack; it + // doesn't need to be run on interrupts. + + try + { + try_code->accept (*this); + } + catch (const execution_exception& ee) + { + execution_error = true; + + error_system& es = m_interpreter.get_error_system (); + + es.save_exception (ee); + + err_map.assign ("message", es.last_error_message ()); + err_map.assign ("identifier", es.last_error_id ()); + err_map.assign ("stack", es.last_error_stack ()); + + m_interpreter.recover_from_exception (); + } + + // Actions attached to unwind_protect frame will run here, prior + // to executing the catch block. + } + + if (execution_error) + { + tree_statement_list *catch_code = cmd.cleanup (); + + if (catch_code) + { + tree_identifier *expr_id = cmd.identifier (); + + if (expr_id) + { + octave_lvalue ult = expr_id->lvalue (*this); + + ult.assign (octave_value::op_asn_eq, err_map); + } + + // perform actual "catch" block + catch_code->accept (*this); + } + } + } + + void + tree_evaluator::do_unwind_protect_cleanup_code (tree_statement_list *list) + { + unwind_protect frame; + + frame.protect_var (octave_interrupt_state); + octave_interrupt_state = 0; + + // We want to preserve the last location info for possible + // backtracking. + + frame.add (&call_stack::set_line, &m_call_stack, + m_call_stack.current_line ()); + + frame.add (&call_stack::set_column, &m_call_stack, + m_call_stack.current_column ()); + + // Similarly, if we have seen a return or break statement, allow all + // the cleanup code to run before returning or handling the break. + // We don't have to worry about continue statements because they can + // only occur in loops. + + frame.protect_var (m_returning); + m_returning = 0; + + frame.protect_var (m_breaking); + m_breaking = 0; + + try + { + if (list) + list->accept (*this); + } + catch (const execution_exception& ee) + { + error_system& es = m_interpreter.get_error_system (); + + es.save_exception (ee); + m_interpreter.recover_from_exception (); + + if (m_breaking || m_returning) + frame.discard (2); + else + frame.run (2); + + frame.discard (2); + + throw; + } + + // The unwind_protects are popped off the stack in the reverse of + // the order they are pushed on. + + // FIXME: these statements say that if we see a break or + // return statement in the cleanup block, that we want to use the + // new value of the breaking or returning flag instead of restoring + // the previous value. Is that the right thing to do? I think so. + // Consider the case of + // + // function foo () + // unwind_protect + // fprintf (stderr, "1: this should always be executed\n"); + // break; + // fprintf (stderr, "1: this should never be executed\n"); + // unwind_protect_cleanup + // fprintf (stderr, "2: this should always be executed\n"); + // return; + // fprintf (stderr, "2: this should never be executed\n"); + // end_unwind_protect + // endfunction + // + // If we reset the value of the breaking flag, both the returning + // flag and the breaking flag will be set, and we shouldn't have + // both. So, use the most recent one. If there is no return or + // break in the cleanup block, the values should be reset to + // whatever they were when the cleanup block was entered. + + if (m_breaking || m_returning) + frame.discard (2); + else + frame.run (2); + } + + void + tree_evaluator::visit_unwind_protect_command (tree_unwind_protect_command& cmd) + { + if (m_echo_state) + { + int line = cmd.line (); + if (line < 0) + line = 1; + echo_code (line); + m_echo_file_pos = line + 1; + } + + tree_statement_list *cleanup_code = cmd.cleanup (); + + tree_statement_list *unwind_protect_code = cmd.body (); + + if (unwind_protect_code) + { + try + { + unwind_protect_code->accept (*this); + } + catch (const execution_exception& ee) + { + error_system& es = m_interpreter.get_error_system (); + + // FIXME: Maybe we should be able to temporarily set the + // interpreter's exception handling state to something "safe" + // while the cleanup block runs instead of just resetting it + // here? + es.save_exception (ee); + m_interpreter.recover_from_exception (); + + // Run the cleanup code on exceptions, so that it is run even + // in case of interrupt or out-of-memory. + do_unwind_protect_cleanup_code (cleanup_code); + + // If an error occurs inside the cleanup code, a new + // exception will be thrown instead of the original. + throw; + } + catch (const interrupt_exception&) + { + // The comments above apply here as well. + m_interpreter.recover_from_exception (); + do_unwind_protect_cleanup_code (cleanup_code); + throw; + } + + // Also execute the unwind_protect_cleanump code if the + // unwind_protect block runs without error. + do_unwind_protect_cleanup_code (cleanup_code); + } + } + + void + tree_evaluator::visit_while_command (tree_while_command& cmd) + { + int line = cmd.line (); + if (line < 0) + line = 1; + + if (m_echo_state) + { + echo_code (line); + line++; + } + + unwind_protect_var upv (m_in_loop_command, true); + + tree_expression *expr = cmd.condition (); + + if (! expr) + panic_impossible (); + + for (;;) + { + if (m_echo_state) + m_echo_file_pos = line; + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + if (is_logically_true (expr, "while")) + { + tree_statement_list *loop_body = cmd.body (); + + if (loop_body) + loop_body->accept (*this); + + if (quit_loop_now ()) + break; + } + else + break; + } + } + + void + tree_evaluator::visit_do_until_command (tree_do_until_command& cmd) + { + int line = cmd.line (); + if (line < 0) + line = 1; + + if (m_echo_state) + { + echo_code (line); + line++; + } + + unwind_protect_var upv (m_in_loop_command, true); + + tree_expression *expr = cmd.condition (); + + if (! expr) + panic_impossible (); + + for (;;) + { + if (m_echo_state) + m_echo_file_pos = line; + + tree_statement_list *loop_body = cmd.body (); + + if (loop_body) + loop_body->accept (*this); + + if (quit_loop_now ()) + break; + + if (m_debug_mode) + do_breakpoint (cmd.is_active_breakpoint (*this)); + + if (is_logically_true (expr, "do-until")) + break; + } + } + + void + tree_evaluator::visit_superclass_ref (tree_superclass_ref&) + { + panic_impossible (); + } + + void + tree_evaluator::visit_metaclass_query (tree_metaclass_query&) + { + panic_impossible (); + } + + void tree_evaluator::bind_ans (const octave_value& val, bool print) + { + static std::string ans = "ans"; + + if (val.is_defined ()) + { + if (val.is_cs_list ()) + { + octave_value_list lst = val.list_value (); + + for (octave_idx_type i = 0; i < lst.length (); i++) + bind_ans (lst(i), print); + } + else + { + // FIXME: Maybe assign could also return the assigned value, + // just for convenience? + + assign (ans, val); + + if (print) + { + // Use varval instead of displaying VAL directly so that + // we get the right type and value for things like + // magic_int values that may mutate when stored. + + octave_value_list args = ovl (varval (ans)); + args.stash_name_tags (string_vector (ans)); + m_interpreter.feval ("display", args); + } + } + } + } + + void + tree_evaluator::do_breakpoint (tree_statement& stmt) + { + do_breakpoint (stmt.is_active_breakpoint (*this), + stmt.is_end_of_fcn_or_script ()); + } + + void + tree_evaluator::do_breakpoint (bool is_breakpoint, + bool is_end_of_fcn_or_script) + { + bool break_on_this_statement = false; + + if (is_breakpoint) + break_on_this_statement = true; + else if (m_dbstep_flag > 0) + { + if (m_call_stack.current_frame () == m_debug_frame) + { + if (m_dbstep_flag == 1 || is_end_of_fcn_or_script) + { + // We get here if we are doing a "dbstep" or a "dbstep N" and + // the count has reached 1 so that we must stop and return to + // debug prompt. Alternatively, "dbstep N" has been used but + // the end of the frame has been reached so we stop at the last + // line and return to prompt. + + break_on_this_statement = true; + } + else + { + // Executing "dbstep N". Decrease N by one and continue. + + m_dbstep_flag--; + } + + } + else if (m_dbstep_flag == 1 + && m_call_stack.current_frame () < m_debug_frame) + { + // We stepped out from the end of a function. + + m_debug_frame = m_call_stack.current_frame (); + + break_on_this_statement = true; + } + } + else if (m_dbstep_flag == -1) + { + // We get here if we are doing a "dbstep in". + + break_on_this_statement = true; + + m_debug_frame = m_call_stack.current_frame (); + } + else if (m_dbstep_flag == -2) + { + // We get here if we are doing a "dbstep out". Check for end of + // function and whether the current frame is the same as the + // cached value because we want to step out from the frame where + // "dbstep out" was evaluated, not from any functions called from + // that frame. + + if (is_end_of_fcn_or_script + && m_call_stack.current_frame () == m_debug_frame) + m_dbstep_flag = -1; + } + + if (! break_on_this_statement) + break_on_this_statement = m_break_on_next_stmt; + + m_break_on_next_stmt = false; + + if (break_on_this_statement) + { + m_dbstep_flag = 0; + + enter_debugger (); + } + } + + bool + tree_evaluator::is_logically_true (tree_expression *expr, + const char *warn_for) + { + bool expr_value = false; + + m_call_stack.set_location (expr->line (), expr->column ()); + + octave_value t1 = expr->evaluate (*this); + + if (t1.is_defined ()) + return t1.is_true (); + else + error ("%s: undefined value used in conditional expression", warn_for); + + return expr_value; + } + + octave_value + tree_evaluator::max_recursion_depth (const octave_value_list& args, + int nargout) + { + return set_internal_variable (m_max_recursion_depth, args, nargout, + "max_recursion_depth", 0); + } + + symbol_info_list + tree_evaluator::glob_symbol_info (const std::string& pattern) const + { + return m_call_stack.glob_symbol_info (pattern); + } + + symbol_info_list + tree_evaluator::regexp_symbol_info (const std::string& pattern) const + { + return m_call_stack.regexp_symbol_info (pattern); + } + + symbol_info_list + tree_evaluator::get_symbol_info () + { + return m_call_stack.get_symbol_info (); + } + + symbol_info_list + tree_evaluator::top_scope_symbol_info () const + { + return m_call_stack.top_scope_symbol_info (); + } + + octave_map tree_evaluator::get_autoload_map () const + { + Cell fcn_names (dim_vector (m_autoload_map.size (), 1)); + Cell file_names (dim_vector (m_autoload_map.size (), 1)); + + octave_idx_type i = 0; + for (const auto& fcn_fname : m_autoload_map) + { + fcn_names(i) = fcn_fname.first; + file_names(i) = fcn_fname.second; + + i++; + } + + octave_map m; + + m.assign ("function", fcn_names); + m.assign ("file", file_names); + + return m; + } + + std::string tree_evaluator::lookup_autoload (const std::string& nm) const + { + std::string retval; + + auto p = m_autoload_map.find (nm); + + if (p != m_autoload_map.end ()) + { + load_path& lp = m_interpreter.get_load_path (); + + retval = lp.find_file (p->second); + } + + return retval; + } + + std::list tree_evaluator::autoloaded_functions () const + { + std::list names; + + for (const auto& fcn_fname : m_autoload_map) + names.push_back (fcn_fname.first); + + return names; + } + + std::list + tree_evaluator::reverse_lookup_autoload (const std::string& nm) const + { + std::list names; + + for (const auto& fcn_fname : m_autoload_map) + if (nm == fcn_fname.second) + names.push_back (fcn_fname.first); + + return names; + } + + void tree_evaluator::add_autoload (const std::string& fcn, + const std::string& nm) + { + std::string file_name = check_autoload_file (nm); + + m_autoload_map[fcn] = file_name; + } + + void tree_evaluator::remove_autoload (const std::string& fcn, + const std::string& nm) + { + check_autoload_file (nm); + + // Remove function from symbol table and autoload map. + symbol_table& symtab = m_interpreter.get_symbol_table (); + + symtab.clear_dld_function (fcn); + + m_autoload_map.erase (fcn); + } + + octave_value + tree_evaluator::whos_line_format (const octave_value_list& args, int nargout) + { + return set_internal_variable (m_whos_line_format, args, nargout, + "whos_line_format"); + } + + octave_value + tree_evaluator::silent_functions (const octave_value_list& args, int nargout) + { + return set_internal_variable (m_silent_functions, args, nargout, + "silent_functions"); + } + + octave_value + tree_evaluator::string_fill_char (const octave_value_list& args, int nargout) + { + return set_internal_variable (m_string_fill_char, args, nargout, + "string_fill_char"); + } + + // Final step of processing an indexing error. Add the name of the + // variable being indexed, if any, then issue an error. (Will this also + // be needed by pt-lvalue, which calls subsref?) + + void tree_evaluator::final_index_error (index_exception& ie, + const tree_expression *expr) + { + std::string extra_message; + + if (is_variable (expr)) + { + std::string var = expr->name (); + + ie.set_var (var); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + octave_value fcn = symtab.find_function (var); + + if (fcn.is_function ()) + { + octave_function *fp = fcn.function_value (); + + if (fp && fp->name () == var) + extra_message + = " (note: variable '" + var + "' shadows function)"; + } + } + + std::string msg = ie.message () + extra_message; + + error_with_id (ie.err_id (), "%s", msg.c_str ()); + } + + octave_value + tree_evaluator::do_who (int argc, const string_vector& argv, + bool return_list, bool verbose) + { + return m_call_stack.do_who (argc, argv, return_list, verbose); + } + + octave_value_list + tree_evaluator::make_value_list (tree_argument_list *args, + const string_vector& arg_nm) + { + octave_value_list retval; + + if (args) + { + unwind_protect_var *> + upv (m_lvalue_list, nullptr); + + int len = args->length (); + + unwind_protect_var upv2 (m_index_position); + unwind_protect_var upv3 (m_num_indices); + + m_num_indices = len; + + std::list arg_vals; + + int k = 0; + + for (auto elt : *args) + { + // FIXME: is it possible for elt to be invalid? + + if (! elt) + break; + + m_index_position = k++; + + octave_value tmp = elt->evaluate (*this); + + if (tmp.is_cs_list ()) + { + octave_value_list tmp_ovl = tmp.list_value (); + + for (octave_idx_type i = 0; i < tmp_ovl.length (); i++) + arg_vals.push_back (tmp_ovl(i)); + } + else if (tmp.is_defined ()) + arg_vals.push_back (tmp); + } + + retval = octave_value_list (arg_vals); + } + + octave_idx_type n = retval.length (); + + if (n > 0) + retval.stash_name_tags (arg_nm); + + return retval; + } + + std::list + tree_evaluator::make_lvalue_list (tree_argument_list *lhs) + { + std::list retval; + + for (tree_expression *elt : *lhs) + retval.push_back (elt->lvalue (*this)); + + return retval; + } + + void + tree_evaluator::push_echo_state (int type, const std::string& file_name, + int pos) + { + unwind_protect *frame = m_call_stack.curr_fcn_unwind_protect_frame (); + + if (frame) + { + push_echo_state_cleanup (*frame); + + set_echo_state (type, file_name, pos); + } + } + + void + tree_evaluator::set_echo_state (int type, const std::string& file_name, + int pos) + { + m_echo_state = echo_this_file (file_name, type); + m_echo_file_name = file_name; + m_echo_file_pos = pos; + } + + void + tree_evaluator::uwp_set_echo_state (bool state, const std::string& file_name, + int pos) + { + m_echo_state = state; + m_echo_file_name = file_name; + m_echo_file_pos = pos; + } + + void + tree_evaluator::maybe_set_echo_state () + { + octave_function *caller = caller_function (); + + if (caller && caller->is_user_code ()) + { + octave_user_code *fcn = dynamic_cast (caller); + + int type = fcn->is_user_function () ? ECHO_FUNCTIONS : ECHO_SCRIPTS; + + std::string file_name = fcn->fcn_file_name (); + + // We want the line where "echo" was called, not the line number + // stored in the stack frame that was created for the echo + // function (that will always be -1). + + int pos = m_call_stack.current_user_code_line (); + + if (pos < 0) + pos = 1; + + set_echo_state (type, file_name, pos); + } + } + + void + tree_evaluator::push_echo_state_cleanup (unwind_protect& frame) + { + frame.add (&tree_evaluator::uwp_set_echo_state, this, + m_echo_state, m_echo_file_name, m_echo_file_pos); + } + + bool tree_evaluator::maybe_push_echo_state_cleanup () + { + // This function is expected to be called from ECHO, which would be + // the top of the call stack. If the caller of ECHO is a + // user-defined function or script, then set up unwind-protect + // elements to restore echo state. + + unwind_protect *frame = m_call_stack.curr_fcn_unwind_protect_frame (); + + if (frame) + { + push_echo_state_cleanup (*frame); + return true; + } + + return false; + } + + + octave_value + tree_evaluator::echo (const octave_value_list& args, int) + { + bool cleanup_pushed = maybe_push_echo_state_cleanup (); + + string_vector argv = args.make_argv (); + + switch (args.length ()) + { + case 0: + if ((m_echo & ECHO_SCRIPTS) || (m_echo & ECHO_FUNCTIONS)) + { + m_echo = ECHO_OFF; + m_echo_files.clear (); + } + else + m_echo = ECHO_SCRIPTS; break; - octave_value tmp = elt->evaluate (*this); - - if (tmp.is_cs_list ()) + case 1: { - octave_value_list tmp_ovl = tmp.list_value (); - - for (octave_idx_type i = 0; i < tmp_ovl.length (); i++) - arg_vals.push_back (tmp_ovl(i)); - } - else if (tmp.is_defined ()) - arg_vals.push_back (tmp); - } - - return octave_value_list (arg_vals); -} - -octave_value_list -tree_evaluator::convert_return_list_to_const_vector -(tree_parameter_list *ret_list, int nargout, const Matrix& ignored_outputs, - const Cell& varargout) -{ - octave_idx_type vlen = varargout.numel (); - int len = ret_list->length (); - - // Special case. Will do a shallow copy. - if (len == 0) - return varargout; - else - { - int i = 0; - int k = 0; - int num_ignored = ignored_outputs.numel (); - int ignored = num_ignored > 0 ? ignored_outputs(k) - 1 : -1; - - if (nargout <= len) - { - int nout = nargout > 0 ? nargout : 1; - octave_value_list retval (nout); - - for (tree_decl_elt *elt : *ret_list) + std::string arg0 = argv[0]; + + if (arg0 == "on") + m_echo = ECHO_SCRIPTS; + else if (arg0 == "off") + m_echo = ECHO_OFF; + else { - if (nargout == 0 && ! is_defined (elt->ident ())) - break; - - if (ignored >= 0 && i == ignored) + std::string file = fcn_file_in_path (arg0); + file = sys::env::make_absolute (file); + + if (file.empty ()) + error ("echo: no such file %s", arg0.c_str ()); + + if (m_echo & ECHO_ALL) { - i++; - k++; - ignored = k < num_ignored ? ignored_outputs(k) - 1 : -1; + // Echo is enabled for all functions, so turn it off + // for this one. + + m_echo_files[file] = false; } else - retval(i++) = evaluate (elt); - - if (i == nout) - break; - } - - return retval; - } - else - { - octave_value_list retval (len + vlen); - - for (tree_decl_elt *elt : *ret_list) - { - if (ignored >= 0 && i == ignored) { - i++; - k++; - ignored = k < num_ignored ? ignored_outputs(k) - 1 : -1; - } - else - retval(i++) = evaluate (elt); - } - - for (octave_idx_type j = 0; j < vlen; j++) - retval(i++) = varargout(j); - - return retval; - } - } -} - -bool -tree_evaluator::eval_decl_elt (tree_decl_elt *elt) -{ - bool retval = false; - - tree_identifier *id = elt->ident (); - tree_expression *expr = elt->expression (); - - if (id && expr) - { - octave_lvalue ult = id->lvalue (*this); - - octave_value init_val = expr->evaluate (*this); - - ult.assign (octave_value::op_asn_eq, init_val); - - retval = true; - } - - return retval; -} - -bool -tree_evaluator::switch_case_label_matches (tree_switch_case *expr, - const octave_value& val) -{ - tree_expression *label = expr->case_label (); - - octave_value label_value = label->evaluate (*this); - - if (label_value.is_defined ()) - { - if (label_value.iscell ()) - { - Cell cell (label_value.cell_value ()); - - for (octave_idx_type i = 0; i < cell.rows (); i++) - { - for (octave_idx_type j = 0; j < cell.columns (); j++) - { - bool match = val.is_equal (cell(i, j)); - - if (match) - return true; + // Echo may be enabled for specific functions. + + auto p = m_echo_files.find (file); + + if (p == m_echo_files.end ()) + { + // Not this one, so enable it. + + m_echo |= ECHO_FUNCTIONS; + m_echo_files[file] = true; + } + else + { + // This one is already in the list. Flip the + // status for it. + + p->second = ! p->second; + } } } } - else - return val.is_equal (label_value); - } - - return false; -} - -void tree_evaluator::push_stack_frame (const symbol_scope& scope) -{ - m_call_stack.push (scope); -} - -void tree_evaluator::push_stack_frame (octave_user_function *fcn, - const std::shared_ptr& closure_frames) -{ - m_call_stack.push (fcn, closure_frames); -} - -void tree_evaluator::push_stack_frame (octave_user_function *fcn, - const stack_frame::local_vars_map& local_vars, - const std::shared_ptr& closure_frames) -{ - m_call_stack.push (fcn, local_vars, closure_frames); -} - -void tree_evaluator::push_stack_frame (octave_user_script *script) -{ - m_call_stack.push (script); -} - -void tree_evaluator::push_stack_frame (octave_function *fcn) -{ - m_call_stack.push (fcn); -} - -void tree_evaluator::pop_stack_frame (void) -{ - m_call_stack.pop (); -} - -int tree_evaluator::current_line (void) const -{ - return m_call_stack.current_line (); -} - -int tree_evaluator::current_column (void) const -{ - return m_call_stack.current_column (); -} - -int tree_evaluator::debug_user_code_line (void) const -{ - return m_call_stack.debug_user_code_line (); -} - -int tree_evaluator::debug_user_code_column (void) const -{ - return m_call_stack.debug_user_code_column (); -} - -void tree_evaluator::debug_where (std::ostream& os) const -{ - std::shared_ptr frm = m_call_stack.current_user_frame (); - - frm->display_stopped_in_message (os); -} - -octave_user_code *tree_evaluator::current_user_code (void) const -{ - return m_call_stack.current_user_code (); -} - -unwind_protect *tree_evaluator::curr_fcn_unwind_protect_frame (void) -{ - return m_call_stack.curr_fcn_unwind_protect_frame (); -} - -octave_user_code *tree_evaluator::debug_user_code (void) const -{ - return m_call_stack.debug_user_code (); -} - -octave_function *tree_evaluator::current_function (bool skip_first) const -{ - return m_call_stack.current_function (skip_first); -} - -octave_function *tree_evaluator::caller_function (void) const -{ - return m_call_stack.current_function (true); -} - -bool tree_evaluator::goto_frame (std::size_t n, bool verbose) -{ - return m_call_stack.goto_frame (n, verbose); -} - -void tree_evaluator::goto_caller_frame (void) -{ - m_call_stack.goto_caller_frame (); -} - -void tree_evaluator::goto_base_frame (void) -{ - m_call_stack.goto_base_frame (); -} - -void tree_evaluator::restore_frame (std::size_t n) -{ - return m_call_stack.restore_frame (n); -} - -std::string tree_evaluator::get_dispatch_class (void) const -{ - return m_call_stack.get_dispatch_class (); -} - -void tree_evaluator::set_dispatch_class (const std::string& class_name) -{ - m_call_stack.set_dispatch_class (class_name); -} - -bool -tree_evaluator::is_class_method_executing (std::string& dclass) const -{ - return m_call_stack.is_class_method_executing (dclass); -} - -bool -tree_evaluator::is_class_constructor_executing (std::string& dclass) const -{ - return m_call_stack.is_class_constructor_executing (dclass); -} - -std::list> - tree_evaluator::backtrace_frames (octave_idx_type& curr_user_frame) const -{ - return m_call_stack.backtrace_frames (curr_user_frame); -} - -std::list> - tree_evaluator::backtrace_frames (void) const -{ - return m_call_stack.backtrace_frames (); -} - -std::list -tree_evaluator::backtrace_info (octave_idx_type& curr_user_frame, - bool print_subfn) const -{ - return m_call_stack.backtrace_info (curr_user_frame, print_subfn); -} - -std::list tree_evaluator::backtrace_info (void) const -{ - return m_call_stack.backtrace_info (); -} - -octave_map -tree_evaluator::backtrace (octave_idx_type& curr_user_frame, - bool print_subfn) const -{ - return m_call_stack.backtrace (curr_user_frame, print_subfn); -} - -octave_map tree_evaluator::backtrace (void) const -{ - return m_call_stack.backtrace (); -} - -octave_map tree_evaluator::empty_backtrace (void) const -{ - return m_call_stack.empty_backtrace (); -} - -std::string tree_evaluator::backtrace_message (void) const -{ - std::list frames = backtrace_info (); - - std::ostringstream buf; - - for (const auto& frm : frames) - { - buf << " " << frm.fcn_name (); - - int line = frm.line (); - - if (line > 0) + break; + + case 2: { - buf << " at line " << line; - - int column = frm.column (); - - if (column > 0) - buf << " column " << column; - - buf << "\n"; - } - } - - return buf.str (); -} - -void tree_evaluator::push_dummy_scope (const std::string& name) -{ - symbol_scope dummy_scope (name + "$dummy"); - - m_call_stack.push (dummy_scope); -} - -void tree_evaluator::pop_scope (void) -{ - m_call_stack.pop (); -} - -symbol_scope tree_evaluator::get_top_scope (void) const -{ - return m_call_stack.top_scope (); -} - -symbol_scope tree_evaluator::get_current_scope (void) const -{ - return m_call_stack.current_scope (); -} - -void tree_evaluator::mlock (bool skip_first) const -{ - octave_function *fcn = m_call_stack.current_function (skip_first); - - if (! fcn) - error ("mlock: invalid use outside a function"); - - if (fcn->is_builtin_function ()) - { - warning ("mlock: locking built-in function has no effect"); - return; - } - - fcn->lock (); -} - -void tree_evaluator::munlock (bool skip_first) const -{ - octave_function *fcn = m_call_stack.current_function (skip_first); - - if (! fcn) - error ("munlock: invalid use outside a function"); - - if (fcn->is_builtin_function ()) - { - warning ("munlock: unlocking built-in function has no effect"); - return; - } - - fcn->unlock (); -} - -bool tree_evaluator::mislocked (bool skip_first) const -{ - octave_function *fcn = m_call_stack.current_function (skip_first); - - if (! fcn) - error ("mislocked: invalid use outside a function"); - - return fcn->islocked (); -} - -octave_value -tree_evaluator::max_stack_depth (const octave_value_list& args, int nargout) -{ - return m_call_stack.max_stack_depth (args, nargout); -} - -void tree_evaluator::display_call_stack (void) const -{ - m_call_stack.display (); -} - -octave_value tree_evaluator::find (const std::string& name) -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - octave_value val = frame->varval (name); - - if (val.is_defined ()) - return val; - - // Subfunction. I think it only makes sense to check for - // subfunctions if we are currently executing a function defined - // from a .m file. - - octave_value fcn = frame->find_subfunction (name); - - if (fcn.is_defined ()) - return fcn; - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - return symtab.fcn_table_find (name, ovl ()); -} - -void tree_evaluator::clear_objects (void) -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - frame->clear_objects (); -} - -void tree_evaluator::clear_variable (const std::string& name) -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - frame->clear_variable (name); -} - -void tree_evaluator::clear_variable_pattern (const std::string& pattern) -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - frame->clear_variable_pattern (pattern); -} - -void tree_evaluator::clear_variable_regexp (const std::string& pattern) -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - frame->clear_variable_regexp (pattern); -} - -void tree_evaluator::clear_variables (void) -{ - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - frame->clear_variables (); -} - -void tree_evaluator::clear_global_variable (const std::string& name) -{ - m_call_stack.clear_global_variable (name); -} - -void -tree_evaluator::clear_global_variable_pattern (const std::string& pattern) -{ - m_call_stack.clear_global_variable_pattern (pattern); -} - -void tree_evaluator::clear_global_variable_regexp(const std::string& pattern) -{ - m_call_stack.clear_global_variable_regexp (pattern); -} - -void tree_evaluator::clear_global_variables (void) -{ - m_call_stack.clear_global_variables (); -} - -void tree_evaluator::clear_all (bool force) -{ - // FIXME: should this also clear objects? - - clear_variables (); - clear_global_variables (); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - symtab.clear_functions (force); -} - -void tree_evaluator::clear_symbol (const std::string& name) -{ - // FIXME: are we supposed to do both here? - - clear_variable (name); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - symtab.clear_function (name); -} - -void tree_evaluator::clear_symbol_pattern (const std::string& pattern) -{ - // FIXME: are we supposed to do both here? - - clear_variable_pattern (pattern); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - symtab.clear_function_pattern (pattern); -} - -void tree_evaluator::clear_symbol_regexp (const std::string& pattern) -{ - // FIXME: are we supposed to do both here? - - clear_variable_regexp (pattern); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - symtab.clear_function_regexp (pattern); -} - -std::list tree_evaluator::global_variable_names (void) const -{ - return m_call_stack.global_variable_names (); -} - -std::list tree_evaluator::top_level_variable_names (void) const -{ - return m_call_stack.top_level_variable_names (); -} - -std::list tree_evaluator::variable_names (void) const -{ - return m_call_stack.variable_names (); -} - -// Return a pointer to the user-defined function FNAME. If FNAME is empty, -// search backward for the first user-defined function in the -// current call stack. - -octave_user_code * -tree_evaluator::get_user_code (const std::string& fname, - const std::string& class_name) -{ - octave_user_code *user_code = nullptr; - - if (fname.empty ()) - user_code = m_call_stack.debug_user_code (); - else - { - std::string name = fname; - - if (sys::file_ops::dir_sep_char () != '/' && name[0] == '@') - { - auto beg = name.begin () + 2; // never have @/method - auto end = name.end () - 1; // never have trailing '/' - std::replace (beg, end, '/', sys::file_ops::dir_sep_char ()); - } - - std::size_t name_len = name.length (); - - if (name_len > 2 && name.substr (name_len-2) == ".m") - name = name.substr (0, name_len-2); - - if (name.empty ()) - return nullptr; - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - octave_value fcn; - std::size_t p2 = std::string::npos; - - if (name[0] == '@') - { - std::size_t p1 = name.find (sys::file_ops::dir_sep_char (), 1); - - if (p1 == std::string::npos) - return nullptr; - - std::string dispatch_type = name.substr (1, p1-1); - - p2 = name.find ('>', p1); - - std::string method = name.substr (p1+1, p2-1); - - fcn = symtab.find_method (method, dispatch_type); - } - else if (! class_name.empty ()) - { - cdef_manager& cdm = m_interpreter.get_cdef_manager (); - - fcn = cdm.find_method (class_name, name); - - // If there is no classdef method, then try legacy classes. - if (fcn.is_undefined ()) - fcn = symtab.find_method (name, class_name); - } - else - { - p2 = name.find ('>'); - - std::string main_fcn = name.substr (0, p2); - - fcn = symtab.find_function (main_fcn); - } - - // List of function names sub1>sub2>... - std::string subfuns; - - if (p2 != std::string::npos) - subfuns = name.substr (p2+1); - - if (fcn.is_defined () && fcn.is_user_code ()) - user_code = fcn.user_code_value (); - - if (! user_code || subfuns.empty ()) - return user_code; - - fcn = user_code->find_subfunction (subfuns); - - if (fcn.is_undefined ()) - return nullptr; - - user_code = fcn.user_code_value (); - } - - return user_code; -} - -std::string -tree_evaluator::current_function_name (bool skip_first) const -{ - octave_function *curfcn = m_call_stack.current_function (skip_first); - - if (curfcn) - return curfcn->name (); - - return ""; -} - -bool -tree_evaluator::in_user_code (void) const -{ - return m_call_stack.current_user_code () != nullptr; -} - -void -tree_evaluator::visit_decl_command (tree_decl_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - // FIXME: tree_decl_init_list is not derived from tree, so should it - // really have an accept method? - - tree_decl_init_list *init_list = cmd.initializer_list (); - - if (init_list) - init_list->accept (*this); -} - -void -tree_evaluator::visit_decl_elt (tree_decl_elt& elt) -{ - tree_identifier *id = elt.ident (); - - if (id) - { - if (elt.is_global ()) - m_call_stack.make_global (id->symbol ()); - else if (elt.is_persistent ()) - m_call_stack.make_persistent (id->symbol ()); - else - error ("declaration list element not global or persistent"); - - octave_lvalue ult = id->lvalue (*this); - - if (ult.is_undefined ()) - { - tree_expression *expr = elt.expression (); - - octave_value init_val; - - if (expr) - init_val = expr->evaluate (*this); - else - init_val = Matrix (); - - ult.assign (octave_value::op_asn_eq, init_val); - } - } -} - -template -void -tree_evaluator::execute_range_loop (const range& rng, int line, - octave_lvalue& ult, - tree_statement_list *loop_body) -{ - octave_idx_type steps = rng.numel (); - - if (math::isinf (rng.limit ())) - warning_with_id ("Octave:infinite-loop", - "FOR loop limit is infinite, will stop after %" - OCTAVE_IDX_TYPE_FORMAT " steps", steps); - - for (octave_idx_type i = 0; i < steps; i++) - { - if (m_echo_state) - m_echo_file_pos = line; - - octave_value val (rng.elem (i)); - - ult.assign (octave_value::op_asn_eq, val); - - if (loop_body) - loop_body->accept (*this); - - if (quit_loop_now ()) - break; - } -} - -void -tree_evaluator::visit_simple_for_command (tree_simple_for_command& cmd) -{ - int line = cmd.line (); - if (line < 0) - line = 1; - - if (m_echo_state) - { - echo_code (line); - line++; - } - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - // FIXME: need to handle PARFOR loops here using cmd.in_parallel () - // and cmd.maxproc_expr (); - - unwind_protect_var upv (m_in_loop_command, true); - - tree_expression *expr = cmd.control_expr (); - - octave_value rhs = expr->evaluate (*this); - - if (rhs.is_undefined ()) - return; - - tree_expression *lhs = cmd.left_hand_side (); - - octave_lvalue ult = lhs->lvalue (*this); - - tree_statement_list *loop_body = cmd.body (); - - if (rhs.is_range ()) - { - // FIXME: is there a better way to dispatch here? - - if (rhs.is_double_type ()) - { - execute_range_loop (rhs.range_value (), line, ult, loop_body); - return; - } - - // For now, disable all but range. - -#if 0 - if (rhs.is_int64_type ()) - { - execute_range_loop (rhs.int64_range_value (), line, ult, loop_body); - return; - } - - if (rhs.is_uint64_type ()) - { - execute_range_loop (rhs.uint64_range_value (), line, ult, loop_body); - return; - } - - if (rhs.is_int32_type ()) - { - execute_range_loop (rhs.int32_range_value (), line, ult, loop_body); - return; - } - - if (rhs.is_uint32_type ()) - { - execute_range_loop (rhs.uint32_range_value (), line, ult, loop_body); - return; - } - - if (rhs.is_int16_type ()) - { - execute_range_loop (rhs.int16_range_value (), line, ult, loop_body); - return; - } - - if (rhs.is_uint16_type ()) - { - execute_range_loop (rhs.uint16_range_value (), line, ult, loop_body); - return; - } - - if (rhs.is_int8_type ()) - { - execute_range_loop (rhs.int8_range_value (), line, ult, loop_body); - return; - } - - if (rhs.is_uint8_type ()) - { - execute_range_loop (rhs.uint8_range_value (), line, ult, loop_body); - return; - } - - if (rhs.is_single_type ()) - { - execute_range_loop (rhs.float_range_value (), line, ult, loop_body); - return; - } -#endif - } - - if (rhs.is_scalar_type ()) - { - if (m_echo_state) - m_echo_file_pos = line; - - ult.assign (octave_value::op_asn_eq, rhs); - - if (loop_body) - loop_body->accept (*this); - - // Maybe decrement break and continue states. - quit_loop_now (); - - return; - } - - // Also handle any range types not explicitly handled above, though - // not as efficiently as the specialized code above. - - if (rhs.is_range () || rhs.is_matrix_type () || rhs.iscell () - || rhs.is_string () || rhs.isstruct ()) - { - // A matrix or cell is reshaped to 2 dimensions and iterated by - // columns. - - dim_vector dv = rhs.dims ().redim (2); - - octave_idx_type nrows = dv(0); - octave_idx_type steps = dv(1); - - octave_value arg = rhs; - if (rhs.ndims () > 2) - arg = arg.reshape (dv); - - if (nrows > 0 && steps > 0) - { - octave_value_list idx; - octave_idx_type iidx; - - // for row vectors, use single index to speed things up. - if (nrows == 1) + std::string arg0 = argv[0]; + std::string arg1 = argv[1]; + + if (arg1 == "on" || arg1 == "off") + std::swap (arg0, arg1); + + if (arg0 == "on") { - idx.resize (1); - iidx = 0; + if (arg1 == "all") + { + m_echo = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_ALL); + m_echo_files.clear (); + } + else + { + std::string file = fcn_file_in_path (arg1); + file = sys::env::make_absolute (file); + + if (file.empty ()) + error ("echo: no such file %s", arg1.c_str ()); + + m_echo |= ECHO_FUNCTIONS; + m_echo_files[file] = true; + } + } + else if (arg0 == "off") + { + if (arg1 == "all") + { + m_echo = ECHO_OFF; + m_echo_files.clear (); + } + else + { + std::string file = fcn_file_in_path (arg1); + file = sys::env::make_absolute (file); + + if (file.empty ()) + error ("echo: no such file %s", arg1.c_str ()); + + m_echo_files[file] = false; + } } else - { - idx.resize (2); - idx(0) = octave_value::magic_colon_t; - iidx = 1; - } - - for (octave_idx_type i = 1; i <= steps; i++) - { - if (m_echo_state) - m_echo_file_pos = line; - - // index_op expects one-based indices. - idx(iidx) = i; - octave_value val = arg.index_op (idx); - - ult.assign (octave_value::op_asn_eq, val); - - if (loop_body) - loop_body->accept (*this); - - if (quit_loop_now ()) - break; - } - } - else - { - // Handle empty cases, while still assigning to loop var. - ult.assign (octave_value::op_asn_eq, arg); - } - - return; - } - - error ("invalid type in for loop expression near line %d, column %d", - cmd.line (), cmd.column ()); -} - -void -tree_evaluator::visit_complex_for_command (tree_complex_for_command& cmd) -{ - int line = cmd.line (); - if (line < 0) - line = 1; - - if (m_echo_state) - { - echo_code (line); - line++; - } - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - unwind_protect_var upv (m_in_loop_command, true); - - tree_expression *expr = cmd.control_expr (); - - octave_value rhs = expr->evaluate (*this); - - if (rhs.is_undefined ()) - return; - - if (! rhs.isstruct ()) - error ("in statement 'for [X, Y] = VAL', VAL must be a structure"); - - // Cycle through structure elements. First element of id_list - // is set to value and the second is set to the name of the - // structure element. - - tree_argument_list *lhs = cmd.left_hand_side (); - - auto p = lhs->begin (); - - tree_expression *elt = *p++; - - octave_lvalue val_ref = elt->lvalue (*this); - - elt = *p; - - octave_lvalue key_ref = elt->lvalue (*this); - - const octave_map tmp_val = rhs.map_value (); - - tree_statement_list *loop_body = cmd.body (); - - string_vector keys = tmp_val.keys (); - - octave_idx_type nel = keys.numel (); - - for (octave_idx_type i = 0; i < nel; i++) - { - if (m_echo_state) - m_echo_file_pos = line; - - std::string key = keys[i]; - - const Cell val_lst = tmp_val.contents (key); - - octave_idx_type n = val_lst.numel (); - - octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst); - - val_ref.assign (octave_value::op_asn_eq, val); - key_ref.assign (octave_value::op_asn_eq, key); - - if (loop_body) - loop_body->accept (*this); - - if (quit_loop_now ()) - break; - } -} - -void tree_evaluator::visit_spmd_command (tree_spmd_command& cmd) -{ - // For now, we just execute the commands serially. - - tree_statement_list *body = cmd.body (); - - if (body) - body->accept (*this); -} - -octave_value -tree_evaluator::evaluate_anon_fcn_handle (tree_anon_fcn_handle& afh) -{ - // FIXME: should CMD_LIST be limited to a single expression? - // I think that is what Matlab does. - - symbol_scope new_scope; - symbol_scope scope = afh.scope (); - if (scope) - new_scope = scope.dup (); - - tree_parameter_list *param_list = afh.parameter_list (); - tree_parameter_list *param_list_dup - = param_list ? param_list->dup (new_scope) : nullptr; - - tree_parameter_list *ret_list = nullptr; - - tree_statement_list *stmt_list = nullptr; - - symbol_scope parent_scope = get_current_scope (); - - new_scope.set_parent (parent_scope); - new_scope.set_primary_parent (parent_scope); - - tree_expression *expr = afh.expression (); - if (expr) - { - tree_expression *expr_dup = expr->dup (new_scope); - tree_statement *stmt = new tree_statement (expr_dup, nullptr); - stmt_list = new tree_statement_list (stmt); - } - - tree_anon_scopes anon_fcn_ctx (afh); - - std::set free_vars = anon_fcn_ctx.free_variables (); - - stack_frame::local_vars_map local_vars; - - std::shared_ptr frame - = m_call_stack.get_current_stack_frame (); - - for (auto& name : free_vars) - { - octave_value val = frame->varval (name); - - if (val.is_defined ()) - local_vars[name] = val; - } - - octave_user_function *af - = new octave_user_function (new_scope, param_list_dup, ret_list, - stmt_list); - - octave_function *curr_fcn = m_call_stack.current_function (); - - bool is_nested = false; - - if (curr_fcn) - { - // FIXME: maybe it would be better to just stash curr_fcn - // instead of individual bits of info about it? - - // An anonymous function defined inside another nested function - // or parent of a nested function also behaves like a nested - // function. - - if (curr_fcn->is_parent_function () || curr_fcn->is_nested_function ()) - { - is_nested = true; - af->mark_as_nested_function (); - new_scope.set_nesting_depth (parent_scope.nesting_depth () + 1); - } - - af->stash_dir_name (curr_fcn->dir_name ()); - - new_scope.cache_fcn_file_name (curr_fcn->fcn_file_name ()); - new_scope.cache_dir_name (curr_fcn->dir_name ()); - - // The following is needed so that class method dispatch works - // properly for anonymous functions that wrap class methods. - - if (curr_fcn->is_class_method () || curr_fcn->is_class_constructor ()) - af->stash_dispatch_class (curr_fcn->dispatch_class ()); - - af->stash_fcn_file_name (curr_fcn->fcn_file_name ()); - } - - af->mark_as_anonymous_function (); - - octave_value ov_fcn (af); - - return (is_nested - ? octave_value (new octave_fcn_handle (ov_fcn, local_vars, frame)) - : octave_value (new octave_fcn_handle (ov_fcn, local_vars))); -} - -octave_value_list -tree_evaluator::execute_builtin_function (octave_builtin& builtin_function, - int nargout, - const octave_value_list& args) -{ - octave_value_list retval; - - if (args.has_magic_colon ()) - error ("invalid use of colon in function argument list"); - - profiler::enter block (m_profiler, builtin_function); - - octave_builtin::fcn fcn = builtin_function.function (); - - if (fcn) - retval = (*fcn) (args, nargout); - else - { - octave_builtin::meth meth = builtin_function.method (); - - retval = (*meth) (m_interpreter, args, nargout); - } - - // Do not allow null values to be returned from functions. - // FIXME: perhaps true builtins should be allowed? - - retval.make_storable_values (); - - // Fix the case of a single undefined value. - // This happens when a compiled function uses - // - // octave_value retval; - // - // instead of - // - // octave_value_list retval; - // - // the idiom is very common, so we solve that here. - - if (retval.length () == 1 && retval.xelem (0).is_undefined ()) - retval.clear (); - - return retval; -} - -octave_value_list -tree_evaluator::execute_mex_function (octave_mex_function& mex_function, - int nargout, - const octave_value_list& args) -{ - octave_value_list retval; - - if (args.has_magic_colon ()) - error ("invalid use of colon in function argument list"); - - profiler::enter block (m_profiler, mex_function); - - retval = call_mex (mex_function, args, nargout); - - return retval; -} - -octave_value_list -tree_evaluator::execute_user_script (octave_user_script& user_script, - int nargout, - const octave_value_list& args) -{ - octave_value_list retval; - - std::string file_name = user_script.fcn_file_name (); - - if (args.length () != 0 || nargout != 0) - error ("invalid call to script %s", file_name.c_str ()); - - tree_statement_list *cmd_list = user_script.body (); - - if (! cmd_list) - return retval; - - // FIXME: Maybe this check belongs in the places where we push a new - // stack frame? Or in the call_stack push method itself? - - if (m_call_stack.size () >= static_cast (m_max_recursion_depth)) - error ("max_recursion_depth exceeded"); - - unwind_protect_var upv (m_statement_context, SC_SCRIPT); - - profiler::enter block (m_profiler, user_script); - - if (echo ()) - push_echo_state (tree_evaluator::ECHO_SCRIPTS, file_name); - - // FIXME: Should we be using tree_evaluator::eval here? - - cmd_list->accept (*this); - - if (m_returning) - m_returning = 0; - - if (m_breaking) - m_breaking--; - - return retval; -} - -void -tree_evaluator::visit_octave_user_script (octave_user_script&) -{ - // ?? - panic_impossible (); -} - -octave_value_list -tree_evaluator::execute_user_function (octave_user_function& user_function, - int nargout, - const octave_value_list& xargs) -{ - octave_value_list retval; - - // If this function is a classdef constructor, extract the first input - // argument, which must be the partially constructed object instance. - - octave_value_list args (xargs); - octave_value_list ret_args; - - int nargin = args.length (); - - if (user_function.is_classdef_constructor ()) - { - if (nargin > 0) - { - ret_args = args.slice (0, 1, true); - --nargin; - args = args.slice (1, nargin, true); - } - else - panic_impossible (); - } - - // FIXME: this probably shouldn't be a double-precision matrix. - Matrix ignored_outputs = ignored_fcn_outputs (); - - tree_parameter_list *param_list = user_function.parameter_list (); - - bool takes_varargs = false; - int max_inputs = 0; - - if (param_list) - { - takes_varargs = param_list->takes_varargs (); - max_inputs = param_list->length (); - } - - if (! takes_varargs && nargin > max_inputs) - { - std::string name = user_function.name (); - - if (name.empty ()) - name = "@"; - - error_with_id ("Octave:invalid-fun-call", - "%s: function called with too many inputs", - name.c_str ()); - } - - define_parameter_list_from_arg_vector (param_list, args); - - tree_parameter_list *ret_list = user_function.return_list (); - - if (ret_list && ! ret_list->takes_varargs ()) - { - int max_outputs = ret_list->length (); - - if (nargout > max_outputs) - { - std::string name = user_function.name (); - - error_with_id ("Octave:invalid-fun-call", - "%s: function called with too many outputs", - name.c_str ()); - } - } - - bind_auto_fcn_vars (xargs.name_tags (), ignored_outputs, nargin, - nargout, user_function.takes_varargs (), - user_function.all_va_args (args)); - - // For classdef constructor, pre-populate the output arguments - // with the pre-initialized object instance, extracted above. - - if (user_function.is_classdef_constructor ()) - { - if (! ret_list) - error ("%s: invalid classdef constructor, no output argument defined", - user_function.dispatch_class ().c_str ()); - - define_parameter_list_from_arg_vector (ret_list, ret_args); - } - - // FIXME: Maybe this check belongs in the places where we push a - // new stack frame? Or in the call_stack push method itself? - - if (m_call_stack.size () >= static_cast (m_max_recursion_depth)) - error ("max_recursion_depth exceeded"); - - unwind_action act2 ([&user_function] () - { - user_function.restore_warning_states (); - }); - - // Evaluate the commands that make up the function. - - unwind_protect_var upv (m_statement_context, SC_FUNCTION); - - tree_statement_list *cmd_list = user_function.body (); - - if (cmd_list) - { - profiler::enter - block (m_profiler, user_function); - - if (echo ()) - push_echo_state (tree_evaluator::ECHO_FUNCTIONS, - user_function.fcn_file_name ()); - - if (user_function.is_special_expr ()) - { - panic_if (cmd_list->length () != 1); - - tree_statement *stmt = cmd_list->front (); - - tree_expression *expr = stmt->expression (); - - if (expr) - { - m_call_stack.set_location (stmt->line (), stmt->column ()); - - retval = expr->evaluate_n (*this, nargout); - } - } - else - cmd_list->accept (*this); - - if (m_returning) - m_returning = 0; - - if (m_breaking) - m_breaking--; - } - - // Copy return values out. - - if (ret_list && ! user_function.is_special_expr ()) - { - Cell varargout; - - if (ret_list->takes_varargs ()) - { - octave_value varargout_varval = varval ("varargout"); - - if (varargout_varval.is_defined ()) - varargout = varargout_varval.xcell_value ("varargout must be a cell array object"); - } - - retval = convert_return_list_to_const_vector (ret_list, nargout, - ignored_outputs, - varargout); - } - - return retval; -} - -void -tree_evaluator::visit_octave_user_function (octave_user_function&) -{ - // ?? - panic_impossible (); -} - -void -tree_evaluator::visit_octave_user_function_header (octave_user_function&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_octave_user_function_trailer (octave_user_function&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_function_def (tree_function_def& cmd) -{ - octave_value fcn = cmd.function (); - - octave_function *f = fcn.function_value (); - - if (f) - { - std::string nm = f->name (); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - symtab.install_cmdline_function (nm, fcn); - - // Make sure that any variable with the same name as the new - // function is cleared. - - assign (nm); - } -} - -void -tree_evaluator::visit_identifier (tree_identifier&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_if_clause (tree_if_clause&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_if_command (tree_if_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - // FIXME: tree_if_command_list is not derived from tree, so should it - // really have an accept method? - - tree_if_command_list *lst = cmd.cmd_list (); - - if (lst) - lst->accept (*this); -} - -void -tree_evaluator::visit_if_command_list (tree_if_command_list& lst) -{ - for (tree_if_clause *tic : lst) - { - tree_expression *expr = tic->condition (); - - if (! (in_debug_repl () - && m_call_stack.current_frame () == m_debug_frame)) - m_call_stack.set_location (tic->line (), tic->column ()); - - if (m_debug_mode && ! tic->is_else_clause ()) - do_breakpoint (tic->is_active_breakpoint (*this)); - - if (tic->is_else_clause () || is_logically_true (expr, "if")) - { - tree_statement_list *stmt_lst = tic->commands (); - - if (stmt_lst) - stmt_lst->accept (*this); - - break; - } - } -} - -void -tree_evaluator::visit_index_expression (tree_index_expression&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_matrix (tree_matrix&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_cell (tree_cell&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_multi_assignment (tree_multi_assignment&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_no_op_command (tree_no_op_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - if (m_debug_mode && cmd.is_end_of_fcn_or_script ()) - do_breakpoint (cmd.is_active_breakpoint (*this), true); -} - -void -tree_evaluator::visit_constant (tree_constant&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_fcn_handle (tree_fcn_handle&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_parameter_list (tree_parameter_list&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_postfix_expression (tree_postfix_expression&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_prefix_expression (tree_prefix_expression&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_return_command (tree_return_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - // Act like dbcont. - - if (in_debug_repl () && m_call_stack.current_frame () == m_debug_frame) - dbcont (); - else if (m_statement_context == SC_FUNCTION - || m_statement_context == SC_SCRIPT - || m_in_loop_command) - m_returning = 1; -} - -void -tree_evaluator::visit_simple_assignment (tree_simple_assignment&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_statement (tree_statement& stmt) -{ - tree_command *cmd = stmt.command (); - tree_expression *expr = stmt.expression (); - - if (cmd || expr) - { - if (! (in_debug_repl () - && m_call_stack.current_frame () == m_debug_frame)) - m_call_stack.set_location (stmt.line (), stmt.column ()); - - try - { - if (cmd) - { - unwind_protect_var *> - upv (m_lvalue_list, nullptr); - - cmd->accept (*this); - } - else - { - if (m_echo_state) - { - int line = stmt.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - if (m_debug_mode) - do_breakpoint (expr->is_active_breakpoint (*this)); - - // FIXME: maybe all of this should be packaged in - // one virtual function that returns a flag saying whether - // or not the expression will take care of binding ans and - // printing the result. - - // FIXME: it seems that we should just have to - // evaluate the expression and that should take care of - // everything, binding ans as necessary? - - octave_value tmp_result = expr->evaluate (*this, 0); - - if (tmp_result.is_defined ()) - { - bool do_bind_ans = false; - - if (expr->is_identifier ()) - do_bind_ans = ! is_variable (expr); - else - do_bind_ans = ! expr->is_assignment_expression (); - - if (do_bind_ans) - bind_ans (tmp_result, expr->print_result () - && statement_printing_enabled ()); - } - } - } - catch (const std::bad_alloc&) - { - // FIXME: We want to use error_with_id here so that give users - // control over this error message but error_with_id will - // require some memory allocations. Is there anything we can - // do to make those more likely to succeed? - - error_with_id ("Octave:bad-alloc", - "out of memory or dimension too large for Octave's index type"); - } - catch (const interrupt_exception&) - { - // If we are debugging, then continue with next statement. - // Otherwise, jump out of here. - - if (m_debug_mode) - m_interpreter.recover_from_exception (); - else - throw; - } - catch (const execution_exception& ee) - { - error_system& es = m_interpreter.get_error_system (); - - if ((m_interpreter.interactive () - || application::forced_interactive ()) - && ((es.debug_on_error () - && m_bp_table.debug_on_err (es.last_error_id ())) - || (es.debug_on_caught () - && m_bp_table.debug_on_caught (es.last_error_id ()))) - && in_user_code ()) - { - es.save_exception (ee); - es.display_exception (ee); - - enter_debugger (); - - // It doesn't make sense to continue execution after an - // error occurs so force the debugger to quit all debug - // levels and return the the top prompt. - - throw quit_debug_exception (true); - } - else - throw; - } - } -} - -void -tree_evaluator::visit_statement_list (tree_statement_list& lst) -{ - // FIXME: commented out along with else clause below. - // static octave_value_list empty_list; - - auto p = lst.begin (); - - if (p != lst.end ()) - { - while (true) - { - tree_statement *elt = *p++; - - if (! elt) - error ("invalid statement found in statement list!"); - - octave_quit (); - - elt->accept (*this); - - if (m_breaking || m_continuing) - break; - - if (m_returning) - break; - - if (p == lst.end ()) - break; - else - { - // Clear previous values before next statement is - // evaluated so that we aren't holding an extra - // reference to a value that may be used next. For - // example, in code like this: - // - // X = rand (N); # refcount for X should be 1 - // # after this statement - // - // X(idx) = val; # no extra copy of X should be - // # needed, but we will be faked - // # out if retval is not cleared - // # between statements here - - // result_values = empty_list; - } + print_usage (); } - } -} - -void -tree_evaluator::visit_switch_case (tree_switch_case&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_switch_case_list (tree_switch_case_list&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_switch_command (tree_switch_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - tree_expression *expr = cmd.switch_value (); - - if (! expr) - error ("missing value in switch command near line %d, column %d", - cmd.line (), cmd.column ()); - - octave_value val = expr->evaluate (*this); - - tree_switch_case_list *lst = cmd.case_list (); - - if (lst) - { - for (tree_switch_case *t : *lst) - { - if (t->is_default_case () || switch_case_label_matches (t, val)) - { - tree_statement_list *stmt_lst = t->commands (); - - if (stmt_lst) - stmt_lst->accept (*this); - - break; - } - } - } -} - -void -tree_evaluator::visit_try_catch_command (tree_try_catch_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - bool execution_error = false; - octave_scalar_map err_map; - - tree_statement_list *try_code = cmd.body (); - - if (try_code) - { - // unwind frame before catch block - - unwind_protect frame; - - interpreter_try (frame); - - // The catch code is *not* added to unwind_protect stack; it - // doesn't need to be run on interrupts. - - try - { - try_code->accept (*this); - } - catch (const execution_exception& ee) - { - execution_error = true; - - error_system& es = m_interpreter.get_error_system (); - - es.save_exception (ee); - - err_map.assign ("message", es.last_error_message ()); - err_map.assign ("identifier", es.last_error_id ()); - err_map.assign ("stack", es.last_error_stack ()); - - m_interpreter.recover_from_exception (); - } - - // Actions attached to unwind_protect frame will run here, prior - // to executing the catch block. - } - - if (execution_error) - { - tree_statement_list *catch_code = cmd.cleanup (); - - if (catch_code) - { - tree_identifier *expr_id = cmd.identifier (); - - if (expr_id) - { - octave_lvalue ult = expr_id->lvalue (*this); - - ult.assign (octave_value::op_asn_eq, err_map); - } - - // perform actual "catch" block - catch_code->accept (*this); - } - } -} - -void -tree_evaluator::do_unwind_protect_cleanup_code (tree_statement_list *list) -{ - unwind_protect frame; - - frame.protect_var (octave_interrupt_state); - octave_interrupt_state = 0; - - // We want to preserve the last location info for possible - // backtracking. - - frame.add (&call_stack::set_line, &m_call_stack, - m_call_stack.current_line ()); - - frame.add (&call_stack::set_column, &m_call_stack, - m_call_stack.current_column ()); - - // Similarly, if we have seen a return or break statement, allow all - // the cleanup code to run before returning or handling the break. - // We don't have to worry about continue statements because they can - // only occur in loops. - - frame.protect_var (m_returning); - m_returning = 0; - - frame.protect_var (m_breaking); - m_breaking = 0; - - try - { - if (list) - list->accept (*this); - } - catch (const execution_exception& ee) - { - error_system& es = m_interpreter.get_error_system (); - - es.save_exception (ee); - m_interpreter.recover_from_exception (); - - if (m_breaking || m_returning) - frame.discard (2); - else - frame.run (2); - - frame.discard (2); - - throw; - } - - // The unwind_protects are popped off the stack in the reverse of - // the order they are pushed on. - - // FIXME: these statements say that if we see a break or - // return statement in the cleanup block, that we want to use the - // new value of the breaking or returning flag instead of restoring - // the previous value. Is that the right thing to do? I think so. - // Consider the case of - // - // function foo () - // unwind_protect - // fprintf (stderr, "1: this should always be executed\n"); - // break; - // fprintf (stderr, "1: this should never be executed\n"); - // unwind_protect_cleanup - // fprintf (stderr, "2: this should always be executed\n"); - // return; - // fprintf (stderr, "2: this should never be executed\n"); - // end_unwind_protect - // endfunction - // - // If we reset the value of the breaking flag, both the returning - // flag and the breaking flag will be set, and we shouldn't have - // both. So, use the most recent one. If there is no return or - // break in the cleanup block, the values should be reset to - // whatever they were when the cleanup block was entered. - - if (m_breaking || m_returning) - frame.discard (2); - else - frame.run (2); -} - -void -tree_evaluator::visit_unwind_protect_command (tree_unwind_protect_command& cmd) -{ - if (m_echo_state) - { - int line = cmd.line (); - if (line < 0) - line = 1; - echo_code (line); - m_echo_file_pos = line + 1; - } - - tree_statement_list *cleanup_code = cmd.cleanup (); - - tree_statement_list *unwind_protect_code = cmd.body (); - - if (unwind_protect_code) - { - try - { - unwind_protect_code->accept (*this); - } - catch (const execution_exception& ee) - { - error_system& es = m_interpreter.get_error_system (); - - // FIXME: Maybe we should be able to temporarily set the - // interpreter's exception handling state to something "safe" - // while the cleanup block runs instead of just resetting it - // here? - es.save_exception (ee); - m_interpreter.recover_from_exception (); - - // Run the cleanup code on exceptions, so that it is run even - // in case of interrupt or out-of-memory. - do_unwind_protect_cleanup_code (cleanup_code); - - // If an error occurs inside the cleanup code, a new - // exception will be thrown instead of the original. - throw; - } - catch (const interrupt_exception&) - { - // The comments above apply here as well. - m_interpreter.recover_from_exception (); - do_unwind_protect_cleanup_code (cleanup_code); - throw; - } - - // Also execute the unwind_protect_cleanump code if the - // unwind_protect block runs without error. - do_unwind_protect_cleanup_code (cleanup_code); - } -} - -void -tree_evaluator::visit_while_command (tree_while_command& cmd) -{ - int line = cmd.line (); - if (line < 0) - line = 1; - - if (m_echo_state) - { - echo_code (line); - line++; - } - - unwind_protect_var upv (m_in_loop_command, true); - - tree_expression *expr = cmd.condition (); - - if (! expr) - panic_impossible (); - - for (;;) - { - if (m_echo_state) - m_echo_file_pos = line; - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - if (is_logically_true (expr, "while")) - { - tree_statement_list *loop_body = cmd.body (); - - if (loop_body) - loop_body->accept (*this); - - if (quit_loop_now ()) - break; - } - else break; - } -} - -void -tree_evaluator::visit_do_until_command (tree_do_until_command& cmd) -{ - int line = cmd.line (); - if (line < 0) - line = 1; - - if (m_echo_state) - { - echo_code (line); - line++; - } - - unwind_protect_var upv (m_in_loop_command, true); - - tree_expression *expr = cmd.condition (); - - if (! expr) - panic_impossible (); - - for (;;) - { - if (m_echo_state) - m_echo_file_pos = line; - - tree_statement_list *loop_body = cmd.body (); - - if (loop_body) - loop_body->accept (*this); - - if (quit_loop_now ()) - break; - - if (m_debug_mode) - do_breakpoint (cmd.is_active_breakpoint (*this)); - - if (is_logically_true (expr, "do-until")) + + default: + print_usage (); break; - } -} - -void -tree_evaluator::visit_superclass_ref (tree_superclass_ref&) -{ - panic_impossible (); -} - -void -tree_evaluator::visit_metaclass_query (tree_metaclass_query&) -{ - panic_impossible (); -} - -void tree_evaluator::bind_ans (const octave_value& val, bool print) -{ - static std::string ans = "ans"; - - if (val.is_defined ()) - { - if (val.is_cs_list ()) - { - octave_value_list lst = val.list_value (); - - for (octave_idx_type i = 0; i < lst.length (); i++) - bind_ans (lst(i), print); - } - else - { - // FIXME: Maybe assign could also return the assigned value, - // just for convenience? - - assign (ans, val); - - if (print) - { - // Use varval instead of displaying VAL directly so that - // we get the right type and value for things like - // magic_int values that may mutate when stored. - - octave_value_list args = ovl (varval (ans)); - args.stash_name_tags (string_vector (ans)); - feval ("display", args); - } - } - } -} - -void -tree_evaluator::do_breakpoint (tree_statement& stmt) -{ - do_breakpoint (stmt.is_active_breakpoint (*this), - stmt.is_end_of_fcn_or_script ()); -} - -void -tree_evaluator::do_breakpoint (bool is_breakpoint, - bool is_end_of_fcn_or_script) -{ - bool break_on_this_statement = false; - - if (is_breakpoint) - break_on_this_statement = true; - else if (m_dbstep_flag > 0) - { - if (m_call_stack.current_frame () == m_debug_frame) - { - if (m_dbstep_flag == 1 || is_end_of_fcn_or_script) - { - // We get here if we are doing a "dbstep" or a "dbstep N" and - // the count has reached 1 so that we must stop and return to - // debug prompt. Alternatively, "dbstep N" has been used but - // the end of the frame has been reached so we stop at the last - // line and return to prompt. - - break_on_this_statement = true; - } - else - { - // Executing "dbstep N". Decrease N by one and continue. - - m_dbstep_flag--; - } - - } - else if (m_dbstep_flag == 1 - && m_call_stack.current_frame () < m_debug_frame) - { - // We stepped out from the end of a function. - - m_debug_frame = m_call_stack.current_frame (); - - break_on_this_statement = true; - } - } - else if (m_dbstep_flag == -1) - { - // We get here if we are doing a "dbstep in". - - break_on_this_statement = true; - - m_debug_frame = m_call_stack.current_frame (); - } - else if (m_dbstep_flag == -2) - { - // We get here if we are doing a "dbstep out". Check for end of - // function and whether the current frame is the same as the - // cached value because we want to step out from the frame where - // "dbstep out" was evaluated, not from any functions called from - // that frame. - - if (is_end_of_fcn_or_script - && m_call_stack.current_frame () == m_debug_frame) - m_dbstep_flag = -1; - } - - if (! break_on_this_statement) - break_on_this_statement = m_break_on_next_stmt; - - m_break_on_next_stmt = false; - - if (break_on_this_statement) - { - m_dbstep_flag = 0; - - enter_debugger (); - } -} - -bool -tree_evaluator::is_logically_true (tree_expression *expr, - const char *warn_for) -{ - bool expr_value = false; - - m_call_stack.set_location (expr->line (), expr->column ()); - - octave_value t1 = expr->evaluate (*this); - - if (t1.is_defined ()) - return t1.is_true (); - else - error ("%s: undefined value used in conditional expression", warn_for); - - return expr_value; -} - -octave_value -tree_evaluator::max_recursion_depth (const octave_value_list& args, - int nargout) -{ - return set_internal_variable (m_max_recursion_depth, args, nargout, - "max_recursion_depth", 0); -} - -symbol_info_list -tree_evaluator::glob_symbol_info (const std::string& pattern) const -{ - return m_call_stack.glob_symbol_info (pattern); -} - -symbol_info_list -tree_evaluator::regexp_symbol_info (const std::string& pattern) const -{ - return m_call_stack.regexp_symbol_info (pattern); -} - -symbol_info_list -tree_evaluator::get_symbol_info (void) -{ - return m_call_stack.get_symbol_info (); -} - -symbol_info_list -tree_evaluator::top_scope_symbol_info (void) const -{ - return m_call_stack.top_scope_symbol_info (); -} - -octave_map tree_evaluator::get_autoload_map (void) const -{ - Cell fcn_names (dim_vector (m_autoload_map.size (), 1)); - Cell file_names (dim_vector (m_autoload_map.size (), 1)); - - octave_idx_type i = 0; - for (const auto& fcn_fname : m_autoload_map) - { - fcn_names(i) = fcn_fname.first; - file_names(i) = fcn_fname.second; - - i++; - } - - octave_map m; - - m.assign ("function", fcn_names); - m.assign ("file", file_names); - - return m; -} - -std::string tree_evaluator::lookup_autoload (const std::string& nm) const -{ - std::string retval; - - auto p = m_autoload_map.find (nm); - - if (p != m_autoload_map.end ()) - { - load_path& lp = m_interpreter.get_load_path (); - - retval = lp.find_file (p->second); - } - - return retval; -} - -std::list tree_evaluator::autoloaded_functions (void) const -{ - std::list names; - - for (const auto& fcn_fname : m_autoload_map) - names.push_back (fcn_fname.first); - - return names; -} - -std::list -tree_evaluator::reverse_lookup_autoload (const std::string& nm) const -{ - std::list names; - - for (const auto& fcn_fname : m_autoload_map) - if (nm == fcn_fname.second) - names.push_back (fcn_fname.first); - - return names; -} - -void tree_evaluator::add_autoload (const std::string& fcn, - const std::string& nm) -{ - std::string file_name = check_autoload_file (nm); - - m_autoload_map[fcn] = file_name; -} - -void tree_evaluator::remove_autoload (const std::string& fcn, - const std::string& nm) -{ - check_autoload_file (nm); - - // Remove function from symbol table and autoload map. - symbol_table& symtab = m_interpreter.get_symbol_table (); - - symtab.clear_dld_function (fcn); - - m_autoload_map.erase (fcn); -} - -octave_value -tree_evaluator::whos_line_format (const octave_value_list& args, int nargout) -{ - return set_internal_variable (m_whos_line_format, args, nargout, - "whos_line_format"); -} - -octave_value -tree_evaluator::silent_functions (const octave_value_list& args, int nargout) -{ - return set_internal_variable (m_silent_functions, args, nargout, - "silent_functions"); -} - -octave_value -tree_evaluator::string_fill_char (const octave_value_list& args, int nargout) -{ - return set_internal_variable (m_string_fill_char, args, nargout, - "string_fill_char"); -} - -// Final step of processing an indexing error. Add the name of the -// variable being indexed, if any, then issue an error. (Will this also -// be needed by pt-lvalue, which calls subsref?) - -void tree_evaluator::final_index_error (index_exception& ie, - const tree_expression *expr) -{ - std::string extra_message; - - if (is_variable (expr)) - { - std::string var = expr->name (); - - ie.set_var (var); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - octave_value fcn = symtab.find_function (var); - - if (fcn.is_function ()) - { - octave_function *fp = fcn.function_value (); - - if (fp && fp->name () == var) - extra_message - = " (note: variable '" + var + "' shadows function)"; - } - } - - std::string msg = ie.message () + extra_message; - - error_with_id (ie.err_id (), "%s", msg.c_str ()); -} - -octave_value -tree_evaluator::do_who (int argc, const string_vector& argv, - bool return_list, bool verbose) -{ - return m_call_stack.do_who (argc, argv, return_list, verbose); -} - -octave_value_list -tree_evaluator::make_value_list (tree_argument_list *args, - const string_vector& arg_nm) -{ - octave_value_list retval; - - if (args) - { - unwind_protect_var *> - upv (m_lvalue_list, nullptr); - - int len = args->length (); - - unwind_protect_var upv2 (m_index_position); - unwind_protect_var upv3 (m_num_indices); - - m_num_indices = len; - - std::list arg_vals; - - int k = 0; - - for (auto elt : *args) - { - // FIXME: is it possible for elt to be invalid? - - if (! elt) - break; - - m_index_position = k++; - - octave_value tmp = elt->evaluate (*this); - - if (tmp.is_cs_list ()) - { - octave_value_list tmp_ovl = tmp.list_value (); - - for (octave_idx_type i = 0; i < tmp_ovl.length (); i++) - arg_vals.push_back (tmp_ovl(i)); - } - else if (tmp.is_defined ()) - arg_vals.push_back (tmp); - } - - retval = octave_value_list (arg_vals); - } - - octave_idx_type n = retval.length (); - - if (n > 0) - retval.stash_name_tags (arg_nm); - - return retval; -} - -std::list -tree_evaluator::make_lvalue_list (tree_argument_list *lhs) -{ - std::list retval; - - for (tree_expression *elt : *lhs) - retval.push_back (elt->lvalue (*this)); - - return retval; -} - -void -tree_evaluator::push_echo_state (int type, const std::string& file_name, - int pos) -{ - unwind_protect *frame = m_call_stack.curr_fcn_unwind_protect_frame (); - - if (frame) - { - push_echo_state_cleanup (*frame); - - set_echo_state (type, file_name, pos); - } -} - -void -tree_evaluator::set_echo_state (int type, const std::string& file_name, - int pos) -{ - m_echo_state = echo_this_file (file_name, type); - m_echo_file_name = file_name; - m_echo_file_pos = pos; -} - -void -tree_evaluator::uwp_set_echo_state (bool state, const std::string& file_name, - int pos) -{ - m_echo_state = state; - m_echo_file_name = file_name; - m_echo_file_pos = pos; -} - -void -tree_evaluator::maybe_set_echo_state (void) -{ - octave_function *caller = caller_function (); - - if (caller && caller->is_user_code ()) - { - octave_user_code *fcn = dynamic_cast (caller); - - int type = fcn->is_user_function () ? ECHO_FUNCTIONS : ECHO_SCRIPTS; - - std::string file_name = fcn->fcn_file_name (); - - // We want the line where "echo" was called, not the line number - // stored in the stack frame that was created for the echo - // function (that will always be -1). - - int pos = m_call_stack.current_user_code_line (); - - if (pos < 0) - pos = 1; - - set_echo_state (type, file_name, pos); - } -} - -void -tree_evaluator::push_echo_state_cleanup (unwind_protect& frame) -{ - frame.add (&tree_evaluator::uwp_set_echo_state, this, - m_echo_state, m_echo_file_name, m_echo_file_pos); -} - -bool tree_evaluator::maybe_push_echo_state_cleanup (void) -{ - // This function is expected to be called from ECHO, which would be - // the top of the call stack. If the caller of ECHO is a - // user-defined function or script, then set up unwind-protect - // elements to restore echo state. - - unwind_protect *frame = m_call_stack.curr_fcn_unwind_protect_frame (); - - if (frame) - { - push_echo_state_cleanup (*frame); - return true; - } - - return false; -} - - -octave_value -tree_evaluator::echo (const octave_value_list& args, int) -{ - bool cleanup_pushed = maybe_push_echo_state_cleanup (); - - string_vector argv = args.make_argv (); - - switch (args.length ()) - { - case 0: - if ((m_echo & ECHO_SCRIPTS) || (m_echo & ECHO_FUNCTIONS)) - { - m_echo = ECHO_OFF; - m_echo_files.clear (); - } - else - m_echo = ECHO_SCRIPTS; - break; - - case 1: + } + + if (cleanup_pushed) + maybe_set_echo_state (); + + return octave_value (); + } + + bool tree_evaluator::in_debug_repl () const + { + return (m_debugger_stack.empty () + ? false : m_debugger_stack.top()->in_debug_repl ()); + } + + void tree_evaluator::dbcont () + { + if (! m_debugger_stack.empty ()) + m_debugger_stack.top()->dbcont (); + } + + void tree_evaluator::dbquit (bool all) + { + if (! m_debugger_stack.empty ()) + m_debugger_stack.top()->dbquit (all); + } + + static octave_value end_value (const octave_value& value, + octave_idx_type index_position, + octave_idx_type num_indices) + { + dim_vector dv = value.dims (); + int ndims = dv.ndims (); + + if (num_indices < ndims) { - std::string arg0 = argv[0]; - - if (arg0 == "on") - m_echo = ECHO_SCRIPTS; - else if (arg0 == "off") - m_echo = ECHO_OFF; + for (int i = num_indices; i < ndims; i++) + dv(num_indices-1) *= dv(i); + + if (num_indices == 1) + { + ndims = 2; + dv.resize (ndims); + dv(1) = 1; + } else { - std::string file = fcn_file_in_path (arg0); - file = sys::env::make_absolute (file); - - if (file.empty ()) - error ("echo: no such file %s", arg0.c_str ()); - - if (m_echo & ECHO_ALL) - { - // Echo is enabled for all functions, so turn it off - // for this one. - - m_echo_files[file] = false; - } - else + ndims = num_indices; + dv.resize (ndims); + } + } + + return (index_position < ndims + ? octave_value (dv(index_position)) : octave_value (1.0)); + } + + octave_value_list + tree_evaluator::evaluate_end_expression (const octave_value_list& args) + { + int nargin = args.length (); + + if (nargin != 0 && nargin != 3) + print_usage (); + + if (nargin == 3) + { + octave_idx_type index_position + = args(1).xidx_type_value ("end: K must be integer value"); + + if (index_position < 1) + error ("end: K must be greater than zero"); + + octave_idx_type num_indices + = args(2).xidx_type_value ("end: N must be integer value"); + + if (num_indices < 1) + error ("end: N must be greater than zero"); + + return end_value (args(0), index_position-1, num_indices); + } + + // If m_indexed_object is undefined, then this use of 'end' is + // either appearing in a function call argument list or in an + // attempt to index an undefined symbol. There seems to be no + // reasonable way to provide a better error message. So just fail + // with an invalid use message. See bug #58830. + + if (m_indexed_object.is_undefined ()) + error ("invalid use of 'end': may only be used to index existing value"); + + octave_value expr_result; + + if (m_index_list.empty ()) + expr_result = m_indexed_object; + else + { + try + { + // When evaluating "end" with no arguments, we should have + // been called from the built-in Fend function that appears + // in the context of an argument list. Fend will be + // evaluated in its own stack frame. But we need to + // evaluate the partial expression that the special "end" + // token applies to in the calling stack frame. + + unwind_action act ([=] (std::size_t frm) + { + m_call_stack.restore_frame (frm); + }, m_call_stack.current_frame ()); + + std::size_t n = m_call_stack.find_current_user_frame (); + m_call_stack.goto_frame (n); + + // End is only valid inside argument lists used for + // indexing. The dispatch class is set by the function that + // evaluates the argument list. + + // Silently ignore extra output values. + + octave_value_list tmp + = m_indexed_object.subsref (m_index_type, m_index_list, 1); + + expr_result = tmp.length () ? tmp(0) : octave_value (); + + if (expr_result.is_cs_list ()) + err_indexed_cs_list (); + } + catch (const index_exception&) + { + error ("error evaluating partial expression for END"); + } + } + + if (expr_result.isobject ()) + { + // FIXME: is there a better way to lookup and execute a method + // that handles all the details like setting the dispatch class + // appropriately? + + std::string dispatch_class = expr_result.class_name (); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + octave_value meth = symtab.find_method ("end", dispatch_class); + + if (meth.is_defined ()) + return m_interpreter.feval + (meth, ovl (expr_result, m_index_position+1, m_num_indices), 1); + } + + return end_value (expr_result, m_index_position, m_num_indices); + } + + octave_value + tree_evaluator::PS4 (const octave_value_list& args, int nargout) + { + return set_internal_variable (m_PS4, args, nargout, "PS4"); + } + + bool tree_evaluator::echo_this_file (const std::string& file, int type) const + { + if ((type & m_echo) == ECHO_SCRIPTS) + { + // Asking about scripts and echo is enabled for them. + return true; + } + + if ((type & m_echo) == ECHO_FUNCTIONS) + { + // Asking about functions and echo is enabled for functions. + // Now, which ones? + + auto p = m_echo_files.find (file); + + if (m_echo & ECHO_ALL) + { + // Return true ulness echo was turned off for a specific + // file. + + return (p == m_echo_files.end () || p->second); + } + else + { + // Return true if echo is specifically enabled for this file. + + return p != m_echo_files.end () && p->second; + } + } + + return false; + } + + void tree_evaluator::echo_code (int line) + { + std::string prefix = command_editor::decode_prompt_string (m_PS4); + + octave_function *curr_fcn = m_call_stack.current_function (); + + if (curr_fcn && curr_fcn->is_user_code ()) + { + octave_user_code *code = dynamic_cast (curr_fcn); + + int num_lines = line - m_echo_file_pos + 1; + + std::deque lines + = code->get_code_lines (m_echo_file_pos, num_lines); + + for (auto& elt : lines) + octave_stdout << prefix << elt << std::endl; + } + } + + // Decide if it's time to quit a for or while loop. + bool tree_evaluator::quit_loop_now () + { + octave_quit (); + + // Maybe handle 'continue N' someday... + + if (m_continuing) + m_continuing--; + + bool quit = (m_returning || m_breaking || m_continuing); + + if (m_breaking) + m_breaking--; + + return quit; + } + + void tree_evaluator::bind_auto_fcn_vars (const string_vector& arg_names, + const Matrix& ignored_outputs, + int nargin, int nargout, + bool takes_varargs, + const octave_value_list& va_args) + { + set_auto_fcn_var (stack_frame::ARG_NAMES, Cell (arg_names)); + set_auto_fcn_var (stack_frame::IGNORED, ignored_outputs); + set_auto_fcn_var (stack_frame::NARGIN, nargin); + set_auto_fcn_var (stack_frame::NARGOUT, nargout); + set_auto_fcn_var (stack_frame::SAVED_WARNING_STATES, octave_value ()); + + if (takes_varargs) + assign ("varargin", va_args.cell_value ()); + } + + std::string + tree_evaluator::check_autoload_file (const std::string& nm) const + { + if (sys::env::absolute_pathname (nm)) + return nm; + + std::string full_name = nm; + + octave_user_code *fcn = m_call_stack.current_user_code (); + + bool found = false; + + if (fcn) + { + std::string fname = fcn->fcn_file_name (); + + if (! fname.empty ()) + { + fname = sys::env::make_absolute (fname); + fname = fname.substr (0, fname.find_last_of (sys::file_ops::dir_sep_str ()) + 1); + + sys::file_stat fs (fname + nm); + + if (fs.exists ()) { - // Echo may be enabled for specific functions. - - auto p = m_echo_files.find (file); - - if (p == m_echo_files.end ()) - { - // Not this one, so enable it. - - m_echo |= ECHO_FUNCTIONS; - m_echo_files[file] = true; - } - else - { - // This one is already in the list. Flip the - // status for it. - - p->second = ! p->second; - } + full_name = fname + nm; + found = true; } } } - break; - - case 2: - { - std::string arg0 = argv[0]; - std::string arg1 = argv[1]; - - if (arg1 == "on" || arg1 == "off") - std::swap (arg0, arg1); - - if (arg0 == "on") - { - if (arg1 == "all") - { - m_echo = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_ALL); - m_echo_files.clear (); - } - else - { - std::string file = fcn_file_in_path (arg1); - file = sys::env::make_absolute (file); - - if (file.empty ()) - error ("echo: no such file %s", arg1.c_str ()); - - m_echo |= ECHO_FUNCTIONS; - m_echo_files[file] = true; - } - } - else if (arg0 == "off") - { - if (arg1 == "all") - { - m_echo = ECHO_OFF; - m_echo_files.clear (); - } - else - { - std::string file = fcn_file_in_path (arg1); - file = sys::env::make_absolute (file); - - if (file.empty ()) - error ("echo: no such file %s", arg1.c_str ()); - - m_echo_files[file] = false; - } - } - else - print_usage (); - } - break; - - default: - print_usage (); - break; - } - - if (cleanup_pushed) - maybe_set_echo_state (); - - return octave_value (); -} - -bool tree_evaluator::in_debug_repl (void) const -{ - return (m_debugger_stack.empty () - ? false : m_debugger_stack.top()->in_debug_repl ()); -} - -void tree_evaluator::dbcont (void) -{ - if (! m_debugger_stack.empty ()) - m_debugger_stack.top()->dbcont (); -} - -void tree_evaluator::dbquit (bool all) -{ - if (! m_debugger_stack.empty ()) - m_debugger_stack.top()->dbquit (all); -} - -static octave_value end_value (const octave_value& value, - octave_idx_type index_position, - octave_idx_type num_indices) -{ - dim_vector dv = value.dims (); - int ndims = dv.ndims (); - - if (num_indices < ndims) - { - for (int i = num_indices; i < ndims; i++) - dv(num_indices-1) *= dv(i); - - if (num_indices == 1) - { - ndims = 2; - dv.resize (ndims); - dv(1) = 1; - } - else - { - ndims = num_indices; - dv.resize (ndims); - } - } - - return (index_position < ndims - ? octave_value (dv(index_position)) : octave_value (1.0)); -} - -octave_value_list -tree_evaluator::evaluate_end_expression (const octave_value_list& args) -{ - int nargin = args.length (); - - if (nargin != 0 && nargin != 3) - print_usage (); - - if (nargin == 3) - { - octave_idx_type index_position - = args(1).xidx_type_value ("end: K must be integer value"); - - if (index_position < 1) - error ("end: K must be greater than zero"); - - octave_idx_type num_indices - = args(2).xidx_type_value ("end: N must be integer value"); - - if (num_indices < 1) - error ("end: N must be greater than zero"); - - return end_value (args(0), index_position-1, num_indices); - } - - // If m_indexed_object is undefined, then this use of 'end' is - // either appearing in a function call argument list or in an - // attempt to index an undefined symbol. There seems to be no - // reasonable way to provide a better error message. So just fail - // with an invalid use message. See bug #58830. - - if (m_indexed_object.is_undefined ()) - error ("invalid use of 'end': may only be used to index existing value"); - - octave_value expr_result; - - if (m_index_list.empty ()) - expr_result = m_indexed_object; - else - { - try - { - // When evaluating "end" with no arguments, we should have - // been called from the built-in Fend function that appears - // in the context of an argument list. Fend will be - // evaluated in its own stack frame. But we need to - // evaluate the partial expression that the special "end" - // token applies to in the calling stack frame. - - unwind_action act ([=] (std::size_t frm) - { - m_call_stack.restore_frame (frm); - }, m_call_stack.current_frame ()); - - std::size_t n = m_call_stack.find_current_user_frame (); - m_call_stack.goto_frame (n); - - // End is only valid inside argument lists used for - // indexing. The dispatch class is set by the function that - // evaluates the argument list. - - // Silently ignore extra output values. - - octave_value_list tmp - = m_indexed_object.subsref (m_index_type, m_index_list, 1); - - expr_result = tmp.length () ? tmp(0) : octave_value (); - - if (expr_result.is_cs_list ()) - err_indexed_cs_list (); - } - catch (const index_exception&) - { - error ("error evaluating partial expression for END"); - } - } - - if (expr_result.isobject ()) - { - // FIXME: is there a better way to lookup and execute a method - // that handles all the details like setting the dispatch class - // appropriately? - - std::string dispatch_class = expr_result.class_name (); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - octave_value meth = symtab.find_method ("end", dispatch_class); - - if (meth.is_defined ()) - return m_interpreter.feval - (meth, ovl (expr_result, m_index_position+1, m_num_indices), 1); - } - - return end_value (expr_result, m_index_position, m_num_indices); -} - -octave_value -tree_evaluator::PS4 (const octave_value_list& args, int nargout) -{ - return set_internal_variable (m_PS4, args, nargout, "PS4"); -} - -bool tree_evaluator::echo_this_file (const std::string& file, int type) const -{ - if ((type & m_echo) == ECHO_SCRIPTS) - { - // Asking about scripts and echo is enabled for them. - return true; - } - - if ((type & m_echo) == ECHO_FUNCTIONS) - { - // Asking about functions and echo is enabled for functions. - // Now, which ones? - - auto p = m_echo_files.find (file); - - if (m_echo & ECHO_ALL) - { - // Return true ulness echo was turned off for a specific - // file. - - return (p == m_echo_files.end () || p->second); - } - else - { - // Return true if echo is specifically enabled for this file. - - return p != m_echo_files.end () && p->second; - } - } - - return false; -} - -void tree_evaluator::echo_code (int line) -{ - std::string prefix = command_editor::decode_prompt_string (m_PS4); - - octave_function *curr_fcn = m_call_stack.current_function (); - - if (curr_fcn && curr_fcn->is_user_code ()) - { - octave_user_code *code = dynamic_cast (curr_fcn); - - int num_lines = line - m_echo_file_pos + 1; - - std::deque lines - = code->get_code_lines (m_echo_file_pos, num_lines); - - for (auto& elt : lines) - octave_stdout << prefix << elt << std::endl; - } -} - -// Decide if it's time to quit a for or while loop. -bool tree_evaluator::quit_loop_now (void) -{ - octave_quit (); - - // Maybe handle 'continue N' someday... - - if (m_continuing) - m_continuing--; - - bool quit = (m_returning || m_breaking || m_continuing); - - if (m_breaking) - m_breaking--; - - return quit; -} - -void tree_evaluator::bind_auto_fcn_vars (const string_vector& arg_names, - const Matrix& ignored_outputs, - int nargin, int nargout, - bool takes_varargs, - const octave_value_list& va_args) -{ - set_auto_fcn_var (stack_frame::ARG_NAMES, Cell (arg_names)); - set_auto_fcn_var (stack_frame::IGNORED, ignored_outputs); - set_auto_fcn_var (stack_frame::NARGIN, nargin); - set_auto_fcn_var (stack_frame::NARGOUT, nargout); - set_auto_fcn_var (stack_frame::SAVED_WARNING_STATES, octave_value ()); - - if (takes_varargs) - assign ("varargin", va_args.cell_value ()); -} - -std::string -tree_evaluator::check_autoload_file (const std::string& nm) const -{ - if (sys::env::absolute_pathname (nm)) - return nm; - - std::string full_name = nm; - - octave_user_code *fcn = m_call_stack.current_user_code (); - - bool found = false; - - if (fcn) - { - std::string fname = fcn->fcn_file_name (); - - if (! fname.empty ()) - { - fname = sys::env::make_absolute (fname); - fname = fname.substr (0, fname.find_last_of (sys::file_ops::dir_sep_str ()) + 1); - - sys::file_stat fs (fname + nm); - - if (fs.exists ()) - { - full_name = fname + nm; - found = true; - } - } - } - - if (! found) - warning_with_id ("Octave:autoload-relative-file-name", - "autoload: '%s' is not an absolute filename", - nm.c_str ()); - - return full_name; -} + + if (! found) + warning_with_id ("Octave:autoload-relative-file-name", + "autoload: '%s' is not an absolute filename", + nm.c_str ()); + + return full_name; + } DEFMETHOD (max_recursion_depth, interp, args, nargout, doc: /* -*- texinfo -*- @@ -5492,9 +5470,7 @@ @seealso{echo, PS1, PS2} @end deftypefn */) { - tree_evaluator& tw = interp.get_evaluator (); - - return tw.PS4 (args, nargout); + return interp.PS4 (args, nargout); } DEFMETHOD (echo, interp, args, nargout, diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-eval.h --- a/libinterp/parse-tree/pt-eval.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-eval.h Mon Jan 30 18:36:03 2023 +0100 @@ -81,44 +81,44 @@ { public: - value_stack (void) = default; + value_stack () = default; value_stack (const value_stack&) = default; value_stack& operator = (const value_stack&) = default; - ~value_stack (void) = default; + ~value_stack () = default; void push (const T& val) { m_stack.push (val); } - void pop (void) + void pop () { m_stack.pop (); } - T val_pop (void) + T val_pop () { T retval = m_stack.top (); m_stack.pop (); return retval; } - T top (void) const + T top () const { return m_stack.top (); } - std::size_t size (void) const + std::size_t size () const { return m_stack.size (); } - bool empty (void) const + bool empty () const { return m_stack.empty (); } - void clear (void) + void clear () { while (! m_stack.empty ()) m_stack.pop (); @@ -154,9 +154,9 @@ tree_evaluator& operator = (const tree_evaluator&) = delete; - ~tree_evaluator (void) = default; + ~tree_evaluator () = default; - std::shared_ptr get_parser (void) + std::shared_ptr get_parser () { return m_parser; } @@ -166,7 +166,7 @@ m_parser = parser; } - bool at_top_level (void) const; + bool at_top_level () const; std::string mfilename (const std::string& opt = "") const; @@ -176,15 +176,15 @@ void parse_and_execute (const std::string& input, bool& incomplete_parse); - void get_line_and_eval (void); + void get_line_and_eval (); - int repl (void); + int repl (); - bool in_top_level_repl (void) const { return m_in_top_level_repl; } + bool in_top_level_repl () const { return m_in_top_level_repl; } - int server_loop (void); + int server_loop (); - bool server_mode (void) const { return m_server_mode; } + bool server_mode () const { return m_server_mode; } void server_mode (bool arg) { m_server_mode = arg; } @@ -333,9 +333,9 @@ void bind_ans (const octave_value& val, bool print); - bool statement_printing_enabled (void); + bool statement_printing_enabled (); - void reset_debug_state (void); + void reset_debug_state (); void reset_debug_state (bool mode); @@ -353,7 +353,7 @@ SC_OTHER // command-line input or eval string }; - Matrix ignored_fcn_outputs (void) const; + Matrix ignored_fcn_outputs () const; octave_value make_fcn_handle (const std::string& nm); @@ -424,11 +424,11 @@ bool switch_case_label_matches (tree_switch_case *expr, const octave_value& val); - interpreter& get_interpreter (void) { return m_interpreter; } + interpreter& get_interpreter () { return m_interpreter; } - bp_table& get_bp_table (void) { return m_bp_table; } + bp_table& get_bp_table () { return m_bp_table; } - profiler& get_profiler (void) { return m_profiler; } + profiler& get_profiler () { return m_profiler; } void push_stack_frame (const symbol_scope& scope); @@ -443,52 +443,52 @@ void push_stack_frame (octave_function *fcn); - void pop_stack_frame (void); + void pop_stack_frame (); - std::shared_ptr get_current_stack_frame (void) const + std::shared_ptr get_current_stack_frame () const { return m_call_stack.get_current_stack_frame (); } - std::shared_ptr current_user_frame (void) const + std::shared_ptr current_user_frame () const { return m_call_stack.current_user_frame (); } // 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; // 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; void debug_where (std::ostream& os) const; - 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 (); // Current function that we are debugging. - octave_user_code * debug_user_code (void) const; + octave_user_code * debug_user_code () const; octave_function * current_function (bool skip_first = false) const; - octave_function * caller_function (void) const; + octave_function * caller_function () const; bool goto_frame (std::size_t n = 0, bool verbose = false); - void goto_caller_frame (void); + void goto_caller_frame (); - void goto_base_frame (void); + void goto_base_frame (); void restore_frame (std::size_t n); - std::string get_dispatch_class (void) const; + std::string get_dispatch_class () const; void set_dispatch_class (const std::string& class_name); @@ -504,22 +504,22 @@ 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; 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; - std::string backtrace_message (void) const; + std::string backtrace_message () const; void push_dummy_scope (const std::string& name); - void pop_scope (void); + void pop_scope (); - 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; void mlock (bool skip_first = false) const; @@ -530,11 +530,11 @@ octave_value max_stack_depth (const octave_value_list& args, int nargout); // Useful for debugging - void display_call_stack (void) const; + void display_call_stack () const; octave_value find (const std::string& name); - void clear_objects (void); + void clear_objects (); void clear_variable (const std::string& name); @@ -542,7 +542,7 @@ void clear_variable_regexp (const std::string& pattern); - void clear_variables (void); + void clear_variables (); void clear_global_variable (const std::string& name); @@ -550,7 +550,7 @@ void clear_global_variable_regexp (const std::string& pattern); - void clear_global_variables (void); + void clear_global_variables (); void clear_all (bool force = false); @@ -560,32 +560,32 @@ void clear_symbol_regexp (const std::string& pattern); - 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; octave_user_code * get_user_code (const std::string& fname = "", const std::string& class_name = ""); std::string current_function_name (bool skip_first = false) const; - bool in_user_code (void) const; + bool in_user_code () const; 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_map get_autoload_map (void) const; + octave_map get_autoload_map () const; std::string lookup_autoload (const std::string& nm) const; - std::list autoloaded_functions (void) const; + std::list autoloaded_functions () const; std::list reverse_lookup_autoload (const std::string& nm) const; @@ -593,7 +593,7 @@ void remove_autoload (const std::string& fcn, const std::string& nm); - int max_recursion_depth (void) const { return m_max_recursion_depth; } + int max_recursion_depth () const { return m_max_recursion_depth; } int max_recursion_depth (int n) { @@ -605,7 +605,7 @@ octave_value max_recursion_depth (const octave_value_list& args, int nargout); - bool silent_functions (void) const { return m_silent_functions; } + bool silent_functions () const { return m_silent_functions; } bool silent_functions (bool b) { @@ -616,7 +616,7 @@ octave_value whos_line_format (const octave_value_list& args, int nargout); - std::string whos_line_format (void) const { return m_whos_line_format; } + std::string whos_line_format () const { return m_whos_line_format; } std::string whos_line_format (const std::string& s) { @@ -628,7 +628,7 @@ octave_value silent_functions (const octave_value_list& args, int nargout); - std::size_t debug_frame (void) const { return m_debug_frame; } + std::size_t debug_frame () const { return m_debug_frame; } std::size_t debug_frame (std::size_t n) { @@ -637,12 +637,12 @@ return val; } - std::size_t current_call_stack_frame_number (void) const + std::size_t current_call_stack_frame_number () const { return m_call_stack.current_frame (); } - bool quiet_breakpoint_flag (void) const { return m_quiet_breakpoint_flag; } + bool quiet_breakpoint_flag () const { return m_quiet_breakpoint_flag; } bool quiet_breakpoint_flag (bool flag) { @@ -651,7 +651,7 @@ return val; } - char string_fill_char (void) const { return m_string_fill_char; } + char string_fill_char () const { return m_string_fill_char; } char string_fill_char (char c) { @@ -664,9 +664,9 @@ // call the corresponding functions in the debugger class for the // current debugger (if any). - bool in_debug_repl (void) const; + bool in_debug_repl () const; - void dbcont (void); + void dbcont (); // Return true if we are in the debug repl and m_execution_mode is // set to exit the debugger. Otherwise, do nothing. @@ -689,21 +689,21 @@ // 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 () { m_debug_watch_expressions.clear (); } // 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 { return m_debug_watch_expressions; } octave_value PS4 (const octave_value_list& args, int nargout); - std::string PS4 (void) const { return m_PS4; } + std::string PS4 () const { return m_PS4; } std::string PS4 (const std::string& s) { @@ -712,7 +712,9 @@ return val; } - octave_value indexed_object (void) const + void set_PS4 (const std::string& s) { m_PS4 = s; } + + octave_value indexed_object () const { return m_indexed_object; } @@ -722,7 +724,7 @@ m_indexed_object = obj; } - const std::list& index_list (void) const + const std::list& index_list () const { return m_index_list; } @@ -734,7 +736,7 @@ m_index_list = index_list; } - void clear_index_list (void) + void clear_index_list () { m_index_type = ""; m_index_list.clear (); @@ -746,18 +748,18 @@ m_index_list.push_back (idx); } - const std::string& index_type (void) const + const std::string& index_type () const { return m_index_type; } - int index_position (void) const { return m_index_position; } + int index_position () const { return m_index_position; } - int num_indices (void) const { return m_num_indices; } + int num_indices () const { return m_num_indices; } octave_value_list evaluate_end_expression (const octave_value_list& args); - const std::list * lvalue_list (void) const + const std::list * lvalue_list () const { return m_lvalue_list; } @@ -767,7 +769,7 @@ m_lvalue_list = lst; } - int breaking (void) const { return m_breaking; } + int breaking () const { return m_breaking; } int breaking (int n) { @@ -776,7 +778,7 @@ return val; } - int continuing (void) const { return m_continuing; } + int continuing () const { return m_continuing; } int continuing (int n) { @@ -785,7 +787,7 @@ return val; } - int returning (void) const { return m_returning; } + int returning () const { return m_returning; } int returning (int n) { @@ -794,7 +796,7 @@ return val; } - int dbstep_flag (void) const { return m_dbstep_flag; } + int dbstep_flag () const { return m_dbstep_flag; } int dbstep_flag (int val) { @@ -805,7 +807,7 @@ void set_dbstep_flag (int step) { m_dbstep_flag = step; } - bool break_on_next_statement (void) const + bool break_on_next_statement () const { return m_break_on_next_stmt; } @@ -824,7 +826,7 @@ octave_value echo (const octave_value_list& args, int nargout); - int echo (void) const { return m_echo; } + int echo () const { return m_echo; } int echo (int val) { @@ -857,11 +859,11 @@ void set_echo_state (int type, const std::string& file_name, int pos); - void maybe_set_echo_state (void); + void maybe_set_echo_state (); void push_echo_state_cleanup (unwind_protect& frame); - bool maybe_push_echo_state_cleanup (void); + bool maybe_push_echo_state_cleanup (); void do_breakpoint (tree_statement& stmt); @@ -877,7 +879,7 @@ void echo_code (int line); - bool quit_loop_now (void); + bool quit_loop_now (); void bind_auto_fcn_vars (const string_vector& arg_names, const Matrix& ignored_outputs, int nargin, diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-except.cc --- a/libinterp/parse-tree/pt-except.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-except.cc Mon Jan 30 18:36:03 2023 +0100 @@ -47,7 +47,7 @@ // Simple exception handling. -tree_try_catch_command::~tree_try_catch_command (void) +tree_try_catch_command::~tree_try_catch_command () { delete m_expr_id; delete m_try_code; @@ -59,7 +59,7 @@ // Simple exception handling. -tree_unwind_protect_command::~tree_unwind_protect_command (void) +tree_unwind_protect_command::~tree_unwind_protect_command () { delete m_unwind_protect_code; delete m_cleanup_code; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-except.h --- a/libinterp/parse-tree/pt-except.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-except.h Mon Jan 30 18:36:03 2023 +0100 @@ -65,19 +65,19 @@ tree_try_catch_command& operator = (const tree_try_catch_command&) = delete; - ~tree_try_catch_command (void); + ~tree_try_catch_command (); - tree_identifier * identifier (void) { return m_expr_id; } + tree_identifier * identifier () { return m_expr_id; } - tree_statement_list * body (void) { return m_try_code; } + tree_statement_list * body () { return m_try_code; } - tree_statement_list * cleanup (void) { return m_catch_code; } + tree_statement_list * cleanup () { return m_catch_code; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * middle_comment (void) { return m_mid_comm; } + comment_list * middle_comment () { return m_mid_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { @@ -134,17 +134,17 @@ tree_unwind_protect_command& operator = (const tree_unwind_protect_command&) = delete; - ~tree_unwind_protect_command (void); + ~tree_unwind_protect_command (); - tree_statement_list * body (void) { return m_unwind_protect_code; } + tree_statement_list * body () { return m_unwind_protect_code; } - tree_statement_list * cleanup (void) { return m_cleanup_code; } + tree_statement_list * cleanup () { return m_cleanup_code; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * middle_comment (void) { return m_mid_comm; } + comment_list * middle_comment () { return m_mid_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-exp.cc --- a/libinterp/parse-tree/pt-exp.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-exp.cc Mon Jan 30 18:36:03 2023 +0100 @@ -46,7 +46,7 @@ } std::string -tree_expression::original_text (void) const +tree_expression::original_text () const { return ""; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-exp.h --- a/libinterp/parse-tree/pt-exp.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-exp.h Mon Jan 30 18:36:03 2023 +0100 @@ -57,61 +57,61 @@ tree_expression& operator = (const tree_expression&) = delete; - virtual ~tree_expression (void) = default; + virtual ~tree_expression () = default; virtual tree_expression * dup (symbol_scope& scope) const = 0; - virtual bool is_constant (void) const { return false; } + virtual bool is_constant () const { return false; } - virtual bool is_matrix (void) const { return false; } + virtual bool is_matrix () const { return false; } - virtual bool iscell (void) const { return false; } + virtual bool iscell () const { return false; } - virtual bool is_identifier (void) const { return false; } + virtual bool is_identifier () const { return false; } - virtual bool is_index_expression (void) const { return false; } + virtual bool is_index_expression () const { return false; } - virtual bool is_assignment_expression (void) const { return false; } + virtual bool is_assignment_expression () const { return false; } - virtual bool is_prefix_expression (void) const { return false; } + virtual bool is_prefix_expression () const { return false; } - virtual bool is_unary_expression (void) const { return false; } + virtual bool is_unary_expression () const { return false; } - virtual bool is_binary_expression (void) const { return false; } + virtual bool is_binary_expression () const { return false; } - virtual bool is_boolean_expression (void) const { return false; } + virtual bool is_boolean_expression () const { return false; } - virtual bool is_colon_expression (void) const { return false; } + virtual bool is_colon_expression () const { return false; } - virtual bool lvalue_ok (void) const { return false; } + virtual bool lvalue_ok () const { return false; } - virtual bool rvalue_ok (void) const { return false; } + virtual bool rvalue_ok () const { return false; } virtual octave_lvalue lvalue (tree_evaluator&); - int paren_count (void) const { return m_num_parens; } + int paren_count () const { return m_num_parens; } - bool is_postfix_indexed (void) const + bool is_postfix_indexed () const { return (m_postfix_index_type != '\0'); } - char postfix_index (void) const { return m_postfix_index_type; } + char postfix_index () const { return m_postfix_index_type; } // Check if the result of the expression should be printed. // Should normally be used in conjunction with // tree_evaluator::statement_printing_enabled. - bool print_result (void) const { return m_print_flag; } + bool print_result () const { return m_print_flag; } - virtual std::string oper (void) const { return ""; } + virtual std::string oper () const { return ""; } - virtual std::string name (void) const { return ""; } + virtual std::string name () const { return ""; } - virtual std::string original_text (void) const; + virtual std::string original_text () const; - void mark_as_for_cmd_expr (void) { m_for_cmd_expr = true; } + void mark_as_for_cmd_expr () { m_for_cmd_expr = true; } - bool is_for_cmd_expr (void) const { return m_for_cmd_expr; } + bool is_for_cmd_expr () const { return m_for_cmd_expr; } - tree_expression * mark_in_parens (void) + tree_expression * mark_in_parens () { m_num_parens++; return this; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-fcn-handle.cc --- a/libinterp/parse-tree/pt-fcn-handle.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-fcn-handle.cc Mon Jan 30 18:36:03 2023 +0100 @@ -66,7 +66,7 @@ return tw.make_fcn_handle (m_name); } -tree_anon_fcn_handle::~tree_anon_fcn_handle (void) +tree_anon_fcn_handle::~tree_anon_fcn_handle () { delete m_parameter_list; delete m_expression; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-fcn-handle.h --- a/libinterp/parse-tree/pt-fcn-handle.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-fcn-handle.h Mon Jan 30 18:36:03 2023 +0100 @@ -61,7 +61,7 @@ tree_fcn_handle& operator = (const tree_fcn_handle&) = delete; - ~tree_fcn_handle (void) = default; + ~tree_fcn_handle () = default; void print (std::ostream& os, bool pr_as_read_syntax = false, bool pr_orig_txt = true); @@ -69,9 +69,9 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false, bool pr_orig_txt = true); - std::string name (void) const { return m_name; } + std::string name () const { return m_name; } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } tree_expression * dup (symbol_scope& scope) const; @@ -117,22 +117,22 @@ tree_anon_fcn_handle& operator = (const tree_anon_fcn_handle&) = delete; - ~tree_anon_fcn_handle (void); + ~tree_anon_fcn_handle (); - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } - tree_parameter_list * parameter_list (void) const + tree_parameter_list * parameter_list () const { return m_parameter_list; } - tree_expression * expression (void) const { return m_expression; } + tree_expression * expression () const { return m_expression; } - symbol_scope scope (void) const { return m_scope; } + symbol_scope scope () const { return m_scope; } - symbol_scope parent_scope (void) const { return m_parent_scope; } + symbol_scope parent_scope () const { return m_parent_scope; } - bool has_parent_scope (void) const { return m_parent_scope.is_valid (); } + bool has_parent_scope () const { return m_parent_scope.is_valid (); } tree_expression * dup (symbol_scope& scope) const; @@ -147,7 +147,7 @@ void stash_file_name (const std::string& file) { m_file_name = file; } - std::string file_name (void) const { return m_file_name; } + std::string file_name () const { return m_file_name; } private: diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-id.cc --- a/libinterp/parse-tree/pt-id.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-id.cc Mon Jan 30 18:36:03 2023 +0100 @@ -30,7 +30,6 @@ #include "error.h" #include "interpreter-private.h" #include "oct-lvalue.h" -#include "parse.h" #include "pt-const.h" #include "pt-id.h" #include "symscope.h" @@ -42,7 +41,7 @@ // Symbols from the symbol table. void -tree_identifier::eval_undefined_error (void) +tree_identifier::eval_undefined_error () { int l = line (); int c = column (); @@ -136,7 +135,10 @@ { octave_value_list args = ovl (val); args.stash_name_tags (string_vector (name ())); - feval ("display", args); + + interpreter& interp = tw.get_interpreter (); + + interp.feval ("display", args); } retval = ovl (val); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-id.h --- a/libinterp/parse-tree/pt-id.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-id.h Mon Jan 30 18:36:03 2023 +0100 @@ -66,26 +66,26 @@ tree_identifier& operator = (const tree_identifier&) = delete; - ~tree_identifier (void) = default; + ~tree_identifier () = default; - bool is_identifier (void) const { return true; } + bool is_identifier () const { return true; } - std::string name (void) const { return m_sym.name (); } + std::string name () const { return m_sym.name (); } - virtual bool is_black_hole (void) const { return false; } + virtual bool is_black_hole () const { return false; } - void mark_as_formal_parameter (void) { m_sym.mark_formal (); } + void mark_as_formal_parameter () { m_sym.mark_formal (); } // We really need to know whether this symbol refers to a variable // or a function, but we may not know that yet. - bool lvalue_ok (void) const { return true; } + bool lvalue_ok () const { return true; } octave_lvalue lvalue (tree_evaluator& tw); - void eval_undefined_error (void); + void eval_undefined_error (); - void static_workspace_error (void) + void static_workspace_error () { error (R"(can not add variable "%s" to a static workspace)", name ().c_str ()); @@ -107,7 +107,7 @@ tw.visit_identifier (*this); } - symbol_record symbol (void) const { return m_sym; } + symbol_record symbol () const { return m_sym; } protected: @@ -122,9 +122,9 @@ tree_black_hole (int l = -1, int c = -1) : tree_identifier (l, c) { } - std::string name (void) const { return "~"; } + std::string name () const { return "~"; } - bool is_black_hole (void) const { return true; } + bool is_black_hole () const { return true; } tree_black_hole * dup (symbol_scope&) const { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-idx.cc --- a/libinterp/parse-tree/pt-idx.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-idx.cc Mon Jan 30 18:36:03 2023 +0100 @@ -113,7 +113,7 @@ return this; } -tree_index_expression::~tree_index_expression (void) +tree_index_expression::~tree_index_expression () { delete m_expr; @@ -136,7 +136,7 @@ // assignment. std::string -tree_index_expression::name (void) const +tree_index_expression::name () const { return m_expr->name (); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-idx.h --- a/libinterp/parse-tree/pt-idx.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-idx.h Mon Jan 30 18:36:03 2023 +0100 @@ -68,7 +68,7 @@ tree_index_expression& operator = (const tree_index_expression&) = delete; - ~tree_index_expression (void); + ~tree_index_expression (); tree_index_expression * append (tree_argument_list *lst = nullptr, char t = '('); @@ -77,27 +77,27 @@ tree_index_expression * append (tree_expression *df); - bool is_index_expression (void) const { return true; } + bool is_index_expression () const { return true; } - std::string name (void) const; + std::string name () const; - tree_expression * expression (void) { return m_expr; } + tree_expression * expression () { return m_expr; } - std::list arg_lists (void) { return m_args; } + std::list arg_lists () { return m_args; } - std::string type_tags (void) { return m_type; } + std::string type_tags () { return m_type; } - std::list arg_names (void) { return m_arg_nm; } + std::list arg_names () { return m_arg_nm; } - std::list dyn_fields (void) { return m_dyn_field; } + std::list dyn_fields () { return m_dyn_field; } - void mark_word_list_cmd (void) { m_word_list_cmd = true; } + void mark_word_list_cmd () { m_word_list_cmd = true; } - bool is_word_list_cmd (void) const { return m_word_list_cmd; } + bool is_word_list_cmd () const { return m_word_list_cmd; } - bool lvalue_ok (void) const { return m_expr->lvalue_ok (); } + bool lvalue_ok () const { return m_expr->lvalue_ok (); } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } octave_lvalue lvalue (tree_evaluator& tw); @@ -145,7 +145,7 @@ tree_index_expression (int l, int c); - octave_map make_arg_struct (void) const; + octave_map make_arg_struct () const; }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-jump.h --- a/libinterp/parse-tree/pt-jump.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-jump.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,7 +48,7 @@ tree_break_command& operator = (const tree_break_command&) = delete; - ~tree_break_command (void) = default; + ~tree_break_command () = default; void accept (tree_walker& tw) { @@ -71,7 +71,7 @@ tree_continue_command& operator = (const tree_continue_command&) = delete; - ~tree_continue_command (void) = default; + ~tree_continue_command () = default; void accept (tree_walker& tw) { @@ -94,7 +94,7 @@ tree_return_command& operator = (const tree_return_command&) = delete; - ~tree_return_command (void) = default; + ~tree_return_command () = default; void accept (tree_walker& tw) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-loop.cc --- a/libinterp/parse-tree/pt-loop.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-loop.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,7 @@ // While. -tree_while_command::~tree_while_command (void) +tree_while_command::~tree_while_command () { delete m_expr; delete m_list; @@ -46,7 +46,7 @@ // For. -tree_simple_for_command::~tree_simple_for_command (void) +tree_simple_for_command::~tree_simple_for_command () { delete m_lhs; delete m_expr; @@ -56,7 +56,7 @@ delete m_trail_comm; } -tree_complex_for_command::~tree_complex_for_command (void) +tree_complex_for_command::~tree_complex_for_command () { delete m_lhs; delete m_expr; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-loop.h --- a/libinterp/parse-tree/pt-loop.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-loop.h Mon Jan 30 18:36:03 2023 +0100 @@ -72,15 +72,15 @@ tree_while_command& operator = (const tree_while_command&) = delete; - ~tree_while_command (void); + ~tree_while_command (); - tree_expression * condition (void) { return m_expr; } + tree_expression * condition () { return m_expr; } - tree_statement_list * body (void) { return m_list; } + tree_statement_list * body () { return m_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { @@ -132,7 +132,7 @@ tree_do_until_command& operator = (const tree_do_until_command&) = delete; - ~tree_do_until_command (void) = default; + ~tree_do_until_command () = default; void accept (tree_walker& tw) { @@ -170,21 +170,21 @@ tree_simple_for_command& operator = (const tree_simple_for_command&) = delete; - ~tree_simple_for_command (void); + ~tree_simple_for_command (); - bool in_parallel (void) { return m_parallel; } + bool in_parallel () { return m_parallel; } - tree_expression * left_hand_side (void) { return m_lhs; } + tree_expression * left_hand_side () { return m_lhs; } - tree_expression * control_expr (void) { return m_expr; } + tree_expression * control_expr () { return m_expr; } - tree_expression * maxproc_expr (void) { return m_maxproc; } + tree_expression * maxproc_expr () { return m_maxproc; } - tree_statement_list * body (void) { return m_list; } + tree_statement_list * body () { return m_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { @@ -240,17 +240,17 @@ tree_complex_for_command& operator = (const tree_complex_for_command&) = delete; - ~tree_complex_for_command (void); + ~tree_complex_for_command (); - tree_argument_list * left_hand_side (void) { return m_lhs; } + tree_argument_list * left_hand_side () { return m_lhs; } - tree_expression * control_expr (void) { return m_expr; } + tree_expression * control_expr () { return m_expr; } - tree_statement_list * body (void) { return m_list; } + tree_statement_list * body () { return m_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-mat.h --- a/libinterp/parse-tree/pt-mat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-mat.h Mon Jan 30 18:36:03 2023 +0100 @@ -60,11 +60,11 @@ tree_matrix& operator = (const tree_matrix&) = delete; - ~tree_matrix (void) = default; + ~tree_matrix () = default; - bool is_matrix (void) const { return true; } + bool is_matrix () const { return true; } - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } tree_expression * dup (symbol_scope& scope) const; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-misc.cc --- a/libinterp/parse-tree/pt-misc.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-misc.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,7 +34,7 @@ // Parameter lists. -tree_parameter_list::~tree_parameter_list (void) +tree_parameter_list::~tree_parameter_list () { while (! empty ()) { @@ -45,14 +45,14 @@ } void -tree_parameter_list::mark_as_formal_parameters (void) +tree_parameter_list::mark_as_formal_parameters () { for (tree_decl_elt *elt : *this) elt->mark_as_formal_parameter (); } std::list -tree_parameter_list::variable_names (void) const +tree_parameter_list::variable_names () const { std::list retval; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-misc.h --- a/libinterp/parse-tree/pt-misc.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-misc.h Mon Jan 30 18:36:03 2023 +0100 @@ -74,25 +74,25 @@ tree_parameter_list& operator = (const tree_parameter_list&) = delete; - ~tree_parameter_list (void); + ~tree_parameter_list (); - void mark_as_formal_parameters (void); + void mark_as_formal_parameters (); - void mark_varargs (void) { m_marked_for_varargs = 1; } + void mark_varargs () { m_marked_for_varargs = 1; } - void mark_varargs_only (void) { m_marked_for_varargs = -1; } + void mark_varargs_only () { m_marked_for_varargs = -1; } - bool takes_varargs (void) const { return m_marked_for_varargs != 0; } + bool takes_varargs () const { return m_marked_for_varargs != 0; } - bool varargs_only (void) { return (m_marked_for_varargs < 0); } + bool varargs_only () { return (m_marked_for_varargs < 0); } - bool is_input_list (void) const { return m_in_or_out == in; } + bool is_input_list () const { return m_in_or_out == in; } - bool is_output_list (void) const { return m_in_or_out == out; } + bool is_output_list () const { return m_in_or_out == out; } - std::list variable_names (void) const; + std::list variable_names () const; - std::string varargs_symbol_name (void) const + std::string varargs_symbol_name () const { return m_in_or_out == in ? "varargin" : "varargout"; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-pr-code.cc --- a/libinterp/parse-tree/pt-pr-code.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-pr-code.cc Mon Jan 30 18:36:03 2023 +0100 @@ -1201,7 +1201,7 @@ // Each print_code() function should call this before printing anything. void -tree_print_code::indent (void) +tree_print_code::indent () { panic_unless (m_curr_print_indent_level >= 0); @@ -1236,7 +1236,7 @@ // For resetting print_code state. void -tree_print_code::reset (void) +tree_print_code::reset () { m_beginning_of_line = true; m_curr_print_indent_level = 0; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-pr-code.h --- a/libinterp/parse-tree/pt-pr-code.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-pr-code.h Mon Jan 30 18:36:03 2023 +0100 @@ -64,7 +64,7 @@ tree_print_code& operator = (const tree_print_code&) = delete; - ~tree_print_code (void) = default; + ~tree_print_code () = default; void visit_anon_fcn_handle (tree_anon_fcn_handle&); @@ -185,17 +185,17 @@ // Nonzero means we are not printing newlines and indenting. int m_suppress_newlines; - void reset_indent_level (void) { m_curr_print_indent_level = 0; } + void reset_indent_level () { m_curr_print_indent_level = 0; } - void increment_indent_level (void) { m_curr_print_indent_level += 2; } + void increment_indent_level () { m_curr_print_indent_level += 2; } - void decrement_indent_level (void) { m_curr_print_indent_level -= 2; } + void decrement_indent_level () { m_curr_print_indent_level -= 2; } void newline (const char *alt_txt = ", "); - void indent (void); + void indent (); - void reset (void); + void reset (); void print_parens (const tree_expression& expr, const char *txt); @@ -207,7 +207,7 @@ // Must create with an output stream! - tree_print_code (void); + tree_print_code (); }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-select.cc --- a/libinterp/parse-tree/pt-select.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-select.cc Mon Jan 30 18:36:03 2023 +0100 @@ -35,7 +35,7 @@ // If clauses. -tree_if_clause::~tree_if_clause (void) +tree_if_clause::~tree_if_clause () { delete m_expr; delete m_list; @@ -44,7 +44,7 @@ // If. -tree_if_command::~tree_if_command (void) +tree_if_command::~tree_if_command () { delete m_list; delete m_lead_comm; @@ -53,7 +53,7 @@ // Switch cases. -tree_switch_case::~tree_switch_case (void) +tree_switch_case::~tree_switch_case () { delete m_label; delete m_list; @@ -62,7 +62,7 @@ // Switch. -tree_switch_command::~tree_switch_command (void) +tree_switch_command::~tree_switch_command () { delete m_expr; delete m_list; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-select.h --- a/libinterp/parse-tree/pt-select.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-select.h Mon Jan 30 18:36:03 2023 +0100 @@ -63,15 +63,15 @@ tree_if_clause& operator = (const tree_if_clause&) = delete; - ~tree_if_clause (void); + ~tree_if_clause (); - bool is_else_clause (void) { return ! m_expr; } + bool is_else_clause () { return ! m_expr; } - tree_expression * condition (void) { return m_expr; } + tree_expression * condition () { return m_expr; } - tree_statement_list * commands (void) { return m_list; } + tree_statement_list * commands () { return m_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } void accept (tree_walker& tw) { @@ -94,7 +94,7 @@ { public: - tree_if_command_list (void) { } + tree_if_command_list () { } tree_if_command_list (tree_if_clause *t) { append (t); } @@ -104,7 +104,7 @@ tree_if_command_list& operator = (const tree_if_command_list&) = delete; - ~tree_if_command_list (void) + ~tree_if_command_list () { while (! empty ()) { @@ -140,13 +140,13 @@ tree_if_command& operator = (const tree_if_command&) = delete; - ~tree_if_command (void); + ~tree_if_command (); - tree_if_command_list * cmd_list (void) { return m_list; } + tree_if_command_list * cmd_list () { return m_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { @@ -190,15 +190,15 @@ tree_switch_case& operator = (const tree_switch_case&) = delete; - ~tree_switch_case (void); + ~tree_switch_case (); - bool is_default_case (void) { return ! m_label; } + bool is_default_case () { return ! m_label; } - tree_expression * case_label (void) { return m_label; } + tree_expression * case_label () { return m_label; } - tree_statement_list * commands (void) { return m_list; } + tree_statement_list * commands () { return m_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } void accept (tree_walker& tw) { @@ -221,7 +221,7 @@ { public: - tree_switch_case_list (void) { } + tree_switch_case_list () { } tree_switch_case_list (tree_switch_case *t) { append (t); } @@ -231,7 +231,7 @@ tree_switch_case_list& operator = (const tree_switch_case_list&) = delete; - ~tree_switch_case_list (void) + ~tree_switch_case_list () { while (! empty ()) { @@ -267,15 +267,15 @@ tree_switch_command& operator = (const tree_switch_command&) = delete; - ~tree_switch_command (void); + ~tree_switch_command (); - tree_expression * switch_value (void) { return m_expr; } + tree_expression * switch_value () { return m_expr; } - tree_switch_case_list * case_list (void) { return m_list; } + tree_switch_case_list * case_list () { return m_list; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-spmd.cc --- a/libinterp/parse-tree/pt-spmd.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-spmd.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,7 +33,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -tree_spmd_command::~tree_spmd_command (void) +tree_spmd_command::~tree_spmd_command () { delete m_body; delete m_lead_comm; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-spmd.h --- a/libinterp/parse-tree/pt-spmd.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-spmd.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,13 +54,13 @@ tree_spmd_command& operator = (const tree_spmd_command&) = delete; - ~tree_spmd_command (void); + ~tree_spmd_command (); - tree_statement_list * body (void) { return m_body; } + tree_statement_list * body () { return m_body; } - comment_list * leading_comment (void) { return m_lead_comm; } + comment_list * leading_comment () { return m_lead_comm; } - comment_list * trailing_comment (void) { return m_trail_comm; } + comment_list * trailing_comment () { return m_trail_comm; } void accept (tree_walker& tw) { diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-stmt.cc --- a/libinterp/parse-tree/pt-stmt.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-stmt.cc Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ // A list of commands to be executed. -tree_statement::~tree_statement (void) +tree_statement::~tree_statement () { delete m_command; delete m_expression; @@ -68,7 +68,7 @@ } bool -tree_statement::print_result (void) +tree_statement::print_result () { return m_expression && m_expression->print_result (); } @@ -83,7 +83,7 @@ } void -tree_statement::delete_breakpoint (void) +tree_statement::delete_breakpoint () { if (m_command) m_command->delete_breakpoint (); @@ -92,7 +92,7 @@ } bool -tree_statement::is_breakpoint (void) const +tree_statement::is_breakpoint () const { return m_command ? m_command->is_breakpoint () : (m_expression ? m_expression->is_breakpoint () @@ -116,7 +116,7 @@ } int -tree_statement::line (void) const +tree_statement::line () const { return (m_command ? m_command->line () @@ -124,7 +124,7 @@ } int -tree_statement::column (void) const +tree_statement::column () const { return (m_command ? m_command->column () @@ -149,7 +149,7 @@ } bool -tree_statement::is_end_of_fcn_or_script (void) const +tree_statement::is_end_of_fcn_or_script () const { bool retval = false; @@ -166,7 +166,7 @@ } bool -tree_statement::is_end_of_file (void) const +tree_statement::is_end_of_file () const { bool retval = false; @@ -218,7 +218,7 @@ } octave_value_list -tree_statement_list::list_breakpoints (void) +tree_statement_list::list_breakpoints () { tree_breakpoint tbp (0, tree_breakpoint::list); accept (tbp); @@ -228,7 +228,7 @@ // Get list of pairs (breakpoint line, breakpoint condition) std::list -tree_statement_list::breakpoints_and_conds (void) +tree_statement_list::breakpoints_and_conds () { tree_breakpoint tbp (0, tree_breakpoint::list); accept (tbp); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-stmt.h --- a/libinterp/parse-tree/pt-stmt.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-stmt.h Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ { public: - tree_statement (void) + tree_statement () : m_command (nullptr), m_expression (nullptr), m_comment_list (nullptr) { } @@ -69,47 +69,47 @@ tree_statement& operator = (const tree_statement&) = delete; - ~tree_statement (void); + ~tree_statement (); void set_print_flag (bool print_flag); - bool print_result (void); + bool print_result (); - bool is_command (void) const { return m_command != nullptr; } + bool is_command () const { return m_command != nullptr; } - bool is_expression (void) const { return m_expression != nullptr; } + bool is_expression () const { return m_expression != nullptr; } void set_breakpoint (const std::string& condition); - void delete_breakpoint (void); + void delete_breakpoint (); - bool is_breakpoint (void) const; + bool is_breakpoint () const; bool is_active_breakpoint (tree_evaluator& tw) const; std::string bp_cond () const; - int line (void) const; - int column (void) const; + int line () const; + int column () const; void set_location (int l, int c); void echo_code (const std::string& prefix); - tree_command * command (void) { return m_command; } + tree_command * command () { return m_command; } - tree_expression * expression (void) { return m_expression; } + tree_expression * expression () { return m_expression; } - comment_list * comment_text (void) { return m_comment_list; } + comment_list * comment_text () { return m_comment_list; } - bool is_null_statement (void) const + bool is_null_statement () const { return ! (m_command || m_expression || m_comment_list); } - bool is_end_of_fcn_or_script (void) const; + bool is_end_of_fcn_or_script () const; - bool is_end_of_file (void) const; + bool is_end_of_file () const; // Allow modification of this statement. Note that there is no // checking. If you use these, are you sure you know what you are @@ -144,7 +144,7 @@ { public: - tree_statement_list (void) + tree_statement_list () : m_function_body (false), m_anon_function_body (false), m_script_body (false) { } @@ -158,7 +158,7 @@ tree_statement_list& operator = (const tree_statement_list&) = delete; - ~tree_statement_list (void) + ~tree_statement_list () { while (! empty ()) { @@ -168,25 +168,25 @@ } } - void mark_as_function_body (void) { m_function_body = true; } + void mark_as_function_body () { m_function_body = true; } - void mark_as_anon_function_body (void) { m_anon_function_body = true; } + void mark_as_anon_function_body () { m_anon_function_body = true; } - void mark_as_script_body (void) { m_script_body = true; } + void mark_as_script_body () { m_script_body = true; } - bool is_function_body (void) const { return m_function_body; } + bool is_function_body () const { return m_function_body; } - bool is_anon_function_body (void) const { return m_anon_function_body; } + bool is_anon_function_body () const { return m_anon_function_body; } - bool is_script_body (void) const { return m_script_body; } + bool is_script_body () const { return m_script_body; } int set_breakpoint (int line, const std::string& condition); void delete_breakpoint (int line); - octave_value_list list_breakpoints (void); + octave_value_list list_breakpoints (); - std::list breakpoints_and_conds (void); + std::list breakpoints_and_conds (); bp_table::bp_lines add_breakpoint (event_manager& evmgr, const std::string& file, diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-tm-const.cc --- a/libinterp/parse-tree/pt-tm-const.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-tm-const.cc Mon Jan 30 18:36:03 2023 +0100 @@ -60,7 +60,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -void tm_row_const::cellify (void) +void tm_row_const::cellify () { bool elt_changed = false; @@ -421,7 +421,7 @@ return octave_value (result, type); } -octave_value tm_const::class_concat (void) const +octave_value tm_const::class_concat () const { octave_value retval; @@ -454,7 +454,7 @@ return retval; } -octave_value tm_const::generic_concat (void) const +octave_value tm_const::generic_concat () const { // The line below might seem crazy, since we take a copy of the // first argument, resize it to be empty and then resize it to be @@ -590,7 +590,7 @@ } template -TYPE tm_const::array_concat (void) const +TYPE tm_const::array_concat () const { typedef typename TYPE::element_type ELT_T; @@ -639,7 +639,7 @@ } template -TYPE tm_const::sparse_array_concat (void) const +TYPE tm_const::sparse_array_concat () const { if (m_dv.any_zero ()) return TYPE (m_dv); @@ -673,7 +673,7 @@ } template -octave_map tm_const::map_concat (void) const +octave_map tm_const::map_concat () const { if (m_dv.any_zero ()) return octave_map (m_dv); diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-tm-const.h --- a/libinterp/parse-tree/pt-tm-const.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-tm-const.h Mon Jan 30 18:36:03 2023 +0100 @@ -77,25 +77,25 @@ m_first_elem_is_struct (false), m_class_name () { } - dim_vector dims (void) const { return m_dv; } + dim_vector dims () const { return m_dv; } - octave_idx_type rows (void) const { return m_dv(0); } - octave_idx_type cols (void) const { return m_dv(1); } + octave_idx_type rows () const { return m_dv(0); } + octave_idx_type cols () const { return m_dv(1); } - bool all_strings_p (void) const { return m_all_strings; } - bool all_sq_strings_p (void) const { return m_all_sq_strings; } - bool all_dq_strings_p (void) const { return m_all_dq_strings; } - bool some_strings_p (void) const { return m_some_strings; } - bool all_real_p (void) const { return m_all_real; } - bool all_complex_p (void) const { return m_all_complex; } - bool all_empty_p (void) const { return m_all_empty; } - bool any_cell_p (void) const { return m_any_cell; } - bool any_sparse_p (void) const { return m_any_sparse; } - bool any_class_p (void) const { return m_any_class; } - bool all_1x1_p (void) const { return m_all_1x1; } - bool first_elem_struct_p (void) const { return m_first_elem_is_struct; } + bool all_strings_p () const { return m_all_strings; } + bool all_sq_strings_p () const { return m_all_sq_strings; } + bool all_dq_strings_p () const { return m_all_dq_strings; } + bool some_strings_p () const { return m_some_strings; } + bool all_real_p () const { return m_all_real; } + bool all_complex_p () const { return m_all_complex; } + bool all_empty_p () const { return m_all_empty; } + bool any_cell_p () const { return m_any_cell; } + bool any_sparse_p () const { return m_any_sparse; } + bool any_class_p () const { return m_any_class; } + bool all_1x1_p () const { return m_all_1x1; } + bool first_elem_struct_p () const { return m_first_elem_is_struct; } - std::string class_name (void) const { return m_class_name; } + std::string class_name () const { return m_class_name; } protected: @@ -149,7 +149,7 @@ typedef std::list::iterator iterator; typedef std::list::const_iterator const_iterator; - tm_row_const (void) = delete; + tm_row_const () = delete; tm_row_const (const tree_argument_list& row, tree_evaluator& tw) : tm_info (row.empty ()), m_values () @@ -161,19 +161,19 @@ tm_row_const& operator = (const tm_row_const&) = delete; - ~tm_row_const (void) = default; + ~tm_row_const () = default; - iterator begin (void) { return m_values.begin (); } - const_iterator begin (void) const { return m_values.begin (); } + iterator begin () { return m_values.begin (); } + const_iterator begin () const { return m_values.begin (); } - iterator end (void) { return m_values.end (); } - const_iterator end (void) const { return m_values.end (); } + iterator end () { return m_values.end (); } + const_iterator end () const { return m_values.end (); } - bool empty (void) const { return m_values.empty (); } + bool empty () const { return m_values.empty (); } - std::size_t length (void) const { return m_values.size (); } + std::size_t length () const { return m_values.size (); } - void cellify (void); + void cellify (); private: @@ -191,7 +191,7 @@ typedef std::list::iterator iterator; typedef std::list::const_iterator const_iterator; - tm_const (void) = delete; + tm_const () = delete; tm_const (const tree_matrix& tm, tree_evaluator& tw) : tm_info (tm.empty ()), m_evaluator (tw), m_tm_rows () @@ -205,7 +205,7 @@ tm_const& operator = (const tm_const&) = delete; - ~tm_const (void) = default; + ~tm_const () = default; octave_value concat (char string_fill_char) const; @@ -223,21 +223,21 @@ octave_value char_array_concat (char string_fill_char) const; - octave_value class_concat (void) const; + octave_value class_concat () const; - octave_value generic_concat (void) const; + octave_value generic_concat () const; template void array_concat_internal (TYPE& result) const; template - TYPE array_concat (void) const; + TYPE array_concat () const; template - TYPE sparse_array_concat (void) const; + TYPE sparse_array_concat () const; template - octave_map map_concat (void) const; + octave_map map_concat () const; }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-unop.cc --- a/libinterp/parse-tree/pt-unop.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-unop.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ // Unary expressions. std::string -tree_unary_expression::oper (void) const +tree_unary_expression::oper () const { return octave_value::unary_op_as_string (m_etype); } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-unop.h --- a/libinterp/parse-tree/pt-unop.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-unop.h Mon Jan 30 18:36:03 2023 +0100 @@ -65,15 +65,15 @@ tree_unary_expression& operator = (const tree_unary_expression&) = delete; - ~tree_unary_expression (void) { delete m_op; } + ~tree_unary_expression () { delete m_op; } - bool is_unary_expression (void) const { return true; } + bool is_unary_expression () const { return true; } - tree_expression * operand (void) { return m_op; } + tree_expression * operand () { return m_op; } - std::string oper (void) const; + std::string oper () const; - octave_value::unary_op op_type (void) const { return m_etype; } + octave_value::unary_op op_type () const { return m_etype; } protected: @@ -104,9 +104,9 @@ tree_prefix_expression& operator = (const tree_prefix_expression&) = delete; - ~tree_prefix_expression (void) = default; + ~tree_prefix_expression () = default; - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } tree_expression * dup (symbol_scope& scope) const; @@ -122,7 +122,7 @@ tw.visit_prefix_expression (*this); } - std::string profiler_name (void) const { return "prefix " + oper (); } + std::string profiler_name () const { return "prefix " + oper (); } }; // Postfix expressions. @@ -145,9 +145,9 @@ tree_postfix_expression& operator = (const tree_postfix_expression&) = delete; - ~tree_postfix_expression (void) = default; + ~tree_postfix_expression () = default; - bool rvalue_ok (void) const { return true; } + bool rvalue_ok () const { return true; } tree_expression * dup (symbol_scope& scope) const; @@ -163,7 +163,7 @@ tw.visit_postfix_expression (*this); } - std::string profiler_name (void) const { return "postfix " + oper (); } + std::string profiler_name () const { return "postfix " + oper (); } }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt-walk.h --- a/libinterp/parse-tree/pt-walk.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt-walk.h Mon Jan 30 18:36:03 2023 +0100 @@ -111,9 +111,9 @@ { protected: - tree_walker (void) { } + tree_walker () { } - virtual ~tree_walker (void) = default; + virtual ~tree_walker () = default; public: diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt.cc --- a/libinterp/parse-tree/pt.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt.cc Mon Jan 30 18:36:03 2023 +0100 @@ -43,7 +43,7 @@ // create a memory leak. std::string -tree::str_print_code (void) +tree::str_print_code () { std::ostringstream buf; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/pt.h --- a/libinterp/parse-tree/pt.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/pt.h Mon Jan 30 18:36:03 2023 +0100 @@ -55,11 +55,11 @@ tree& operator = (const tree&) = delete; - virtual ~tree (void) = default; + virtual ~tree () = default; - virtual int line (void) const { return m_line_num; } + virtual int line () const { return m_line_num; } - virtual int column (void) const { return m_column_num; } + virtual int column () const { return m_column_num; } void line (int l) { m_line_num = l; } @@ -79,7 +79,7 @@ m_bp_cond = new std::string (condition); } - virtual void delete_breakpoint (void) + virtual void delete_breakpoint () { if (m_bp_cond) { @@ -91,7 +91,7 @@ bool meets_bp_condition (tree_evaluator& tw) const; - bool is_breakpoint (void) const + bool is_breakpoint () const { return m_bp_cond; } @@ -103,12 +103,12 @@ // breakpoint condition, or "0" (i.e., "false") if no breakpoint. // To distinguish "0" from a disabled breakpoint, test "is_breakpoint" too. - const std::string bp_cond (void) const + const std::string bp_cond () const { return m_bp_cond ? *m_bp_cond : "0"; } - std::string str_print_code (void); + std::string str_print_code (); virtual void accept (tree_walker& tw) = 0; diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/token.cc --- a/libinterp/parse-tree/token.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/token.cc Mon Jan 30 18:36:03 2023 +0100 @@ -83,7 +83,7 @@ m_tok_info (meth, cls), m_orig_text () { } -token::~token (void) +token::~token () { if (m_type_tag == string_token) delete m_tok_info.m_str; @@ -94,48 +94,48 @@ } std::string -token::text (void) const +token::text () const { panic_if (m_type_tag != string_token); return *m_tok_info.m_str; } octave_value -token::number (void) const +token::number () const { panic_if (m_type_tag != numeric_token); return *m_tok_info.m_num; } token::token_type -token::ttype (void) const +token::ttype () const { return m_type_tag; } token::end_tok_type -token::ettype (void) const +token::ettype () const { panic_if (m_type_tag != ettype_token); return m_tok_info.m_et; } std::string -token::superclass_method_name (void) const +token::superclass_method_name () const { panic_if (m_type_tag != scls_name_token); return m_tok_info.m_superclass_info->m_method_name; } std::string -token::superclass_class_name (void) const +token::superclass_class_name () const { panic_if (m_type_tag != scls_name_token); return m_tok_info.m_superclass_info->m_class_name; } std::string -token::text_rep (void) const +token::text_rep () const { return m_orig_text; } diff -r 17d568574e1c -r 7860fcc69082 libinterp/parse-tree/token.h --- a/libinterp/parse-tree/token.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/parse-tree/token.h Mon Jan 30 18:36:03 2023 +0100 @@ -95,43 +95,43 @@ token& operator = (const token&) = delete; - ~token (void); + ~token (); - void mark_may_be_command (void) { m_maybe_cmd = true; } - bool may_be_command (void) const { return m_maybe_cmd; } + void mark_may_be_command () { m_maybe_cmd = true; } + bool may_be_command () const { return m_maybe_cmd; } - void mark_trailing_space (void) { m_tspc = true; } - bool space_follows_token (void) const { return m_tspc; } + void mark_trailing_space () { m_tspc = true; } + bool space_follows_token () const { return m_tspc; } - int token_value (void) const { return m_tok_val; } + int token_value () const { return m_tok_val; } bool token_value_is (int tv) const { return tv == m_tok_val; } - filepos beg_pos (void) const { return m_beg_pos; } - filepos end_pos (void) const { return m_end_pos; } + filepos beg_pos () const { return m_beg_pos; } + filepos end_pos () const { return m_end_pos; } void beg_pos (const filepos& pos) { m_beg_pos = pos; } void end_pos (const filepos& pos) { m_end_pos = pos; } // These will probably be removed. - int line (void) const { return m_beg_pos.line (); } - int column (void) const { return m_beg_pos.column (); } + int line () const { return m_beg_pos.line (); } + int column () const { return m_beg_pos.column (); } - bool iskeyword (void) const + bool iskeyword () const { return m_type_tag == keyword_token || m_type_tag == ettype_token; } - bool isstring (void) const { return m_type_tag == string_token; } + bool isstring () const { return m_type_tag == string_token; } - std::string text (void) const; - octave_value number (void) const; - token_type ttype (void) const; - end_tok_type ettype (void) const; + std::string text () const; + octave_value number () const; + token_type ttype () const; + end_tok_type ettype () const; - std::string superclass_method_name (void) const; - std::string superclass_class_name (void) const; + std::string superclass_method_name () const; + std::string superclass_class_name () const; - std::string text_rep (void) const; + std::string text_rep () const; private: @@ -148,7 +148,7 @@ union tok_info { - tok_info (void) { } + tok_info () { } tok_info (const char *s) : m_str (new std::string (s)) { } @@ -166,7 +166,7 @@ tok_info& operator = (const tok_info&) = delete; - ~tok_info (void) { } + ~tok_info () { } std::string *m_str; @@ -181,13 +181,13 @@ : m_method_name (meth), m_class_name (cls) { } - superclass_info (void) = delete; + superclass_info () = delete; superclass_info (const superclass_info&) = delete; superclass_info& operator = (const superclass_info&) = delete; - ~superclass_info (void) = default; + ~superclass_info () = default; //-------- diff -r 17d568574e1c -r 7860fcc69082 libinterp/usage.h --- a/libinterp/usage.h Mon Jan 30 18:30:33 2023 +0100 +++ b/libinterp/usage.h Mon Jan 30 18:36:03 2023 +0100 @@ -46,7 +46,7 @@ // Usage message with extra help. static void -octave_print_verbose_usage_and_exit (void) +octave_print_verbose_usage_and_exit () { std::cout << octave_name_version_copyright_copying_and_warranty () << "\n\ @@ -103,7 +103,7 @@ // Terse usage message. static void -octave_print_terse_usage_and_exit (void) +octave_print_terse_usage_and_exit () { std::cerr << "\nusage: " << usage_string << "\n\n"; @@ -111,7 +111,7 @@ } static void -octave_print_version_and_exit (void) +octave_print_version_and_exit () { std::cout << octave_name_version_copyright_copying_warranty_and_bugs () << "\n"; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/Array-base.cc --- a/liboctave/array/Array-base.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/Array-base.cc Mon Jan 30 18:36:03 2023 +0100 @@ -43,7 +43,7 @@ template typename Array::ArrayRep * -Array::nil_rep (void) +Array::nil_rep () { static ArrayRep nr; return &nr; @@ -106,7 +106,7 @@ template void -Array::clear (void) +Array::clear () { if (--m_rep->m_count == 0) delete m_rep; @@ -136,7 +136,7 @@ template Array -Array::squeeze (void) const +Array::squeeze () const { Array retval = *this; @@ -356,7 +356,7 @@ rec_permute_helper& operator = (const rec_permute_helper&) = delete; - ~rec_permute_helper (void) { delete [] m_dim; } + ~rec_permute_helper () { delete [] m_dim; } template void permute (const T *src, T *dest) const { do_permute (src, dest, m_top); } @@ -561,7 +561,7 @@ rec_index_helper& operator = (const rec_index_helper&) = delete; - ~rec_index_helper (void) { delete [] m_idx; delete [] m_dim; } + ~rec_index_helper () { delete [] m_idx; delete [] m_dim; } template void index (const T *src, T *dest) const { do_index (src, dest, m_top); } @@ -677,7 +677,7 @@ rec_resize_helper& operator = (const rec_resize_helper&) = delete; - ~rec_resize_helper (void) { delete [] m_cext; } + ~rec_resize_helper () { delete [] m_cext; } template void resize_fill (const T *src, T *dest, const T& rfv) const @@ -905,7 +905,7 @@ template T -Array::resize_fill_value (void) const +Array::resize_fill_value () const { static T zero = T (); return zero; @@ -1622,7 +1622,7 @@ template Array -Array::transpose (void) const +Array::transpose () const { assert (ndims () == 2); @@ -1763,7 +1763,7 @@ template T * -Array::fortran_vec (void) +Array::fortran_vec () { make_unique (); @@ -2222,7 +2222,7 @@ template octave_idx_type -Array::nnz (void) const +Array::nnz () const { const T *src = data (); octave_idx_type nel = numel (); @@ -2522,7 +2522,7 @@ return Array (); \ } \ template <> API octave_idx_type \ - Array::nnz (void) const \ + Array::nnz () const \ { \ return 0; \ } \ diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/Array.h --- a/liboctave/array/Array.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/Array.h Mon Jan 30 18:36:03 2023 +0100 @@ -160,7 +160,7 @@ // Use new instead of setting data to 0 so that fortran_vec and // data always return valid addresses, even for zero-size arrays. - ArrayRep (void) + ArrayRep () : Alloc (), m_data (allocate (0)), m_len (0), m_count (1) { } explicit ArrayRep (octave_idx_type len) @@ -185,9 +185,9 @@ std::copy_n (a.m_data, a.m_len, m_data); } - ~ArrayRep (void) { deallocate (m_data, m_len); } + ~ArrayRep () { deallocate (m_data, m_len); } - octave_idx_type numel (void) const { return m_len; } + octave_idx_type numel () const { return m_len; } // No assignment! @@ -213,7 +213,7 @@ public: - OCTARRAY_OVERRIDABLE_FUNC_API void make_unique (void) + OCTARRAY_OVERRIDABLE_FUNC_API void make_unique () { if (m_rep->m_count > 1) { @@ -267,12 +267,12 @@ private: - static OCTARRAY_API typename Array::ArrayRep *nil_rep (void); + static OCTARRAY_API typename Array::ArrayRep *nil_rep (); public: //! Empty ctor (0 by 0). - Array (void) + Array () : m_dimensions (), m_rep (nil_rep ()), m_slice_data (m_rep->m_data), m_slice_len (m_rep->m_len) { @@ -348,7 +348,7 @@ public: - virtual ~Array (void) + virtual ~Array () { // Because we define a move constructor and a move assignment // operator, m_rep may be a nullptr here. We should only need to @@ -403,7 +403,7 @@ OCTARRAY_API void fill (const T& val); - OCTARRAY_API void clear (void); + OCTARRAY_API void clear (); OCTARRAY_API void clear (const dim_vector& dv); void clear (octave_idx_type r, octave_idx_type c) @@ -411,13 +411,13 @@ //! Number of elements in the array. OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type - numel (void) const + numel () const { return m_slice_len; } //@} //! Return the array as a column vector. OCTARRAY_OVERRIDABLE_FUNC_API Array - as_column (void) const + as_column () const { Array retval (*this); if (m_dimensions.ndims () != 2 || m_dimensions(1) != 1) @@ -428,7 +428,7 @@ //! Return the array as a row vector. OCTARRAY_OVERRIDABLE_FUNC_API Array - as_row (void) const + as_row () const { Array retval (*this); if (m_dimensions.ndims () != 2 || m_dimensions(0) != 1) @@ -439,7 +439,7 @@ //! Return the array as a matrix. OCTARRAY_OVERRIDABLE_FUNC_API Array - as_matrix (void) const + as_matrix () const { Array retval (*this); if (m_dimensions.ndims () != 2) @@ -453,10 +453,10 @@ //! Get the first dimension of the array (number of rows) //@{ OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type - dim1 (void) const + dim1 () const { return m_dimensions(0); } OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type - rows (void) const + rows () const { return dim1 (); } //@} @@ -464,11 +464,11 @@ //! //! Get the second dimension of the array (number of columns) //@{ - OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type dim2 (void) const + OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type dim2 () const { return m_dimensions(1); } - OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type cols (void) const + OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type cols () const { return dim2 (); } - OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type columns (void) const + OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type columns () const { return dim2 (); } //@} @@ -476,9 +476,9 @@ //! //! Get the third dimension of the array (number of pages) //@{ - OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type dim3 (void) const + OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type dim3 () const { return m_dimensions.ndims () >= 3 ? m_dimensions(2) : 1; } - OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type pages (void) const + OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type pages () const { return dim3 (); } //@} @@ -496,15 +496,15 @@ return d >= ndims () ? 1 : m_dimensions(d); } - OCTARRAY_OVERRIDABLE_FUNC_API std::size_t byte_size (void) const + OCTARRAY_OVERRIDABLE_FUNC_API std::size_t byte_size () const { return static_cast (numel ()) * sizeof (T); } //! Return a const-reference so that dims ()(i) works efficiently. - OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector& dims (void) const + OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector& dims () const { return m_dimensions; } //! Chop off leading singleton dimensions - OCTARRAY_API Array squeeze (void) const; + OCTARRAY_API Array squeeze () const; OCTARRAY_API octave_idx_type compute_index (octave_idx_type i, octave_idx_type j) const; @@ -645,36 +645,30 @@ ipermute (const Array& vec) const { return permute (vec, true); } - OCTARRAY_OVERRIDABLE_FUNC_API bool issquare (void) const + OCTARRAY_OVERRIDABLE_FUNC_API bool issquare () const { return (dim1 () == dim2 ()); } - OCTARRAY_OVERRIDABLE_FUNC_API bool isempty (void) const + OCTARRAY_OVERRIDABLE_FUNC_API bool isempty () const { return numel () == 0; } - OCTARRAY_OVERRIDABLE_FUNC_API bool isvector (void) const + OCTARRAY_OVERRIDABLE_FUNC_API bool isvector () const { return m_dimensions.isvector (); } - OCTARRAY_OVERRIDABLE_FUNC_API bool is_nd_vector (void) const + OCTARRAY_OVERRIDABLE_FUNC_API bool is_nd_vector () const { return m_dimensions.is_nd_vector (); } - OCTARRAY_API Array transpose (void) const; + OCTARRAY_API Array transpose () const; OCTARRAY_API Array hermitian (T (*fcn) (const T&) = nullptr) const; - OCTARRAY_OVERRIDABLE_FUNC_API const T * data (void) const + OCTARRAY_OVERRIDABLE_FUNC_API const T * data () const { return m_slice_data; } -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "for read-only access, use 'data' method instead") - OCTARRAY_OVERRIDABLE_FUNC_API const T * fortran_vec (void) const - { return data (); } -#endif + OCTARRAY_API T * fortran_vec (); - OCTARRAY_API T * fortran_vec (void); - - OCTARRAY_OVERRIDABLE_FUNC_API bool is_shared (void) const + OCTARRAY_OVERRIDABLE_FUNC_API bool is_shared () const { return m_rep->m_count > 1; } - OCTARRAY_OVERRIDABLE_FUNC_API int ndims (void) const + OCTARRAY_OVERRIDABLE_FUNC_API int ndims () const { return m_dimensions.ndims (); } //@{ @@ -686,7 +680,7 @@ OCTARRAY_API Array index (const Array& ia) const; //@} - virtual OCTARRAY_API T resize_fill_value (void) const; + virtual OCTARRAY_API T resize_fill_value () const; //@{ //! Resizing (with fill). @@ -792,7 +786,7 @@ OCTARRAY_API Array& insert (const Array& a, octave_idx_type r, octave_idx_type c); - OCTARRAY_OVERRIDABLE_FUNC_API void maybe_economize (void) + OCTARRAY_OVERRIDABLE_FUNC_API void maybe_economize () { if (m_rep->m_count == 1 && m_slice_len != m_rep->m_len) { @@ -828,7 +822,7 @@ sortmode mode = UNSORTED) const; //! Count nonzero elements. - OCTARRAY_API octave_idx_type nnz (void) const; + OCTARRAY_API octave_idx_type nnz () const; //! Find indices of (at most n) nonzero elements. If n is specified, //! backward specifies search from backward. diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CColVector.cc --- a/liboctave/array/CColVector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CColVector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -196,19 +196,19 @@ } ComplexRowVector -ComplexColumnVector::hermitian (void) const +ComplexColumnVector::hermitian () const { return MArray::hermitian (std::conj); } ComplexRowVector -ComplexColumnVector::transpose (void) const +ComplexColumnVector::transpose () const { return MArray::transpose (); } ColumnVector -ComplexColumnVector::abs (void) const +ComplexColumnVector::abs () const { return do_mx_unary_map (*this); } @@ -420,7 +420,7 @@ // other operations Complex -ComplexColumnVector::min (void) const +ComplexColumnVector::min () const { octave_idx_type len = numel (); if (len == 0) @@ -440,7 +440,7 @@ } Complex -ComplexColumnVector::max (void) const +ComplexColumnVector::max () const { octave_idx_type len = numel (); if (len == 0) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CColVector.h --- a/liboctave/array/CColVector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CColVector.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ public: - ComplexColumnVector (void) : MArray (dim_vector (0, 1)) { } + ComplexColumnVector () : MArray (dim_vector (0, 1)) { } explicit ComplexColumnVector (octave_idx_type n) : MArray (dim_vector (n, 1)) { } @@ -87,8 +87,8 @@ OCTAVE_API ComplexColumnVector stack (const ColumnVector& a) const; OCTAVE_API ComplexColumnVector stack (const ComplexColumnVector& a) const; - OCTAVE_API ComplexRowVector hermitian (void) const; - OCTAVE_API ComplexRowVector transpose (void) const; + OCTAVE_API ComplexRowVector hermitian () const; + OCTAVE_API ComplexRowVector transpose () const; friend OCTAVE_API ComplexColumnVector conj (const ComplexColumnVector& a); @@ -131,10 +131,10 @@ // other operations - OCTAVE_API Complex min (void) const; - OCTAVE_API Complex max (void) const; + OCTAVE_API Complex min () const; + OCTAVE_API Complex max () const; - OCTAVE_API ColumnVector abs (void) const; + OCTAVE_API ColumnVector abs () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CDiagMatrix.cc --- a/liboctave/array/CDiagMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CDiagMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -206,7 +206,7 @@ } DiagMatrix -ComplexDiagMatrix::abs (void) const +ComplexDiagMatrix::abs () const { return DiagMatrix (extract_diag ().abs (), rows (), columns ()); } @@ -301,7 +301,7 @@ } ComplexDiagMatrix -ComplexDiagMatrix::inverse (void) const +ComplexDiagMatrix::inverse () const { octave_idx_type info; return inverse (info); @@ -374,7 +374,7 @@ } bool -ComplexDiagMatrix::all_elements_are_real (void) const +ComplexDiagMatrix::all_elements_are_real () const { return mx_inline_all_real (length (), data ()); } @@ -490,7 +490,7 @@ // other operations ComplexDET -ComplexDiagMatrix::determinant (void) const +ComplexDiagMatrix::determinant () const { ComplexDET det (1.0); if (rows () != cols ()) @@ -504,7 +504,7 @@ } double -ComplexDiagMatrix::rcond (void) const +ComplexDiagMatrix::rcond () const { ColumnVector av = extract_diag (0).map (std::abs); double amx = av.max (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CDiagMatrix.h --- a/liboctave/array/CDiagMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CDiagMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,13 +48,13 @@ typedef Complex complex_elt_type; typedef Complex element_type; - ComplexDiagMatrix (void) = default; + ComplexDiagMatrix () = default; ComplexDiagMatrix (const ComplexDiagMatrix& a) = default; ComplexDiagMatrix& operator = (const ComplexDiagMatrix& a) = default; - ~ComplexDiagMatrix (void) = default; + ~ComplexDiagMatrix () = default; ComplexDiagMatrix (octave_idx_type r, octave_idx_type c) : MDiagArray2 (r, c) { } @@ -102,11 +102,11 @@ OCTAVE_API ComplexDiagMatrix& fill (const ComplexRowVector& a, octave_idx_type beg); - ComplexDiagMatrix hermitian (void) const + ComplexDiagMatrix hermitian () const { return MDiagArray2::hermitian (std::conj); } - ComplexDiagMatrix transpose (void) const + ComplexDiagMatrix transpose () const { return MDiagArray2::transpose (); } - DiagMatrix abs (void) const; + DiagMatrix abs () const; friend OCTAVE_API ComplexDiagMatrix conj (const ComplexDiagMatrix& a); @@ -125,10 +125,10 @@ OCTAVE_API ComplexColumnVector column (char *s) const; OCTAVE_API ComplexDiagMatrix inverse (octave_idx_type& info) const; - OCTAVE_API ComplexDiagMatrix inverse (void) const; + OCTAVE_API ComplexDiagMatrix inverse () const; OCTAVE_API ComplexDiagMatrix pseudo_inverse (double tol = 0.0) const; - OCTAVE_API bool all_elements_are_real (void) const; + OCTAVE_API bool all_elements_are_real () const; // diagonal matrix by diagonal matrix -> diagonal matrix operations @@ -140,8 +140,8 @@ ComplexColumnVector extract_diag (octave_idx_type k = 0) const { return MDiagArray2::extract_diag (k); } - OCTAVE_API ComplexDET determinant (void) const; - OCTAVE_API double rcond (void) const; + OCTAVE_API ComplexDET determinant () const; + OCTAVE_API double rcond () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CMatrix.cc --- a/liboctave/array/CMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -171,7 +171,7 @@ } bool -ComplexMatrix::ishermitian (void) const +ComplexMatrix::ishermitian () const { octave_idx_type nr = rows (); octave_idx_type nc = cols (); @@ -734,7 +734,7 @@ } ComplexMatrix -ComplexMatrix::inverse (void) const +ComplexMatrix::inverse () const { octave_idx_type info; double rcon; @@ -1042,7 +1042,7 @@ #if defined (HAVE_FFTW) ComplexMatrix -ComplexMatrix::fourier (void) const +ComplexMatrix::fourier () const { std::size_t nr = rows (); std::size_t nc = cols (); @@ -1071,7 +1071,7 @@ } ComplexMatrix -ComplexMatrix::ifourier (void) const +ComplexMatrix::ifourier () const { std::size_t nr = rows (); std::size_t nc = cols (); @@ -1100,7 +1100,7 @@ } ComplexMatrix -ComplexMatrix::fourier2d (void) const +ComplexMatrix::fourier2d () const { dim_vector dv (rows (), cols ()); @@ -1114,7 +1114,7 @@ } ComplexMatrix -ComplexMatrix::ifourier2d (void) const +ComplexMatrix::ifourier2d () const { dim_vector dv (rows (), cols ()); @@ -1130,7 +1130,7 @@ #else ComplexMatrix -ComplexMatrix::fourier (void) const +ComplexMatrix::fourier () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -1139,7 +1139,7 @@ } ComplexMatrix -ComplexMatrix::ifourier (void) const +ComplexMatrix::ifourier () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -1148,7 +1148,7 @@ } ComplexMatrix -ComplexMatrix::fourier2d (void) const +ComplexMatrix::fourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -1157,7 +1157,7 @@ } ComplexMatrix -ComplexMatrix::ifourier2d (void) const +ComplexMatrix::ifourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -1168,7 +1168,7 @@ #endif ComplexDET -ComplexMatrix::determinant (void) const +ComplexMatrix::determinant () const { octave_idx_type info; double rcon; @@ -1347,7 +1347,7 @@ } double -ComplexMatrix::rcond (void) const +ComplexMatrix::rcond () const { MatrixType mattype (*this); return rcond (mattype); @@ -2821,7 +2821,7 @@ } Matrix -ComplexMatrix::abs (void) const +ComplexMatrix::abs () const { return ComplexNDArray::abs (); } @@ -2883,7 +2883,7 @@ } ComplexColumnVector -ComplexMatrix::row_min (void) const +ComplexMatrix::row_min () const { Array dummy_idx; return row_min (dummy_idx); @@ -2958,7 +2958,7 @@ } ComplexColumnVector -ComplexMatrix::row_max (void) const +ComplexMatrix::row_max () const { Array dummy_idx; return row_max (dummy_idx); @@ -3033,7 +3033,7 @@ } ComplexRowVector -ComplexMatrix::column_min (void) const +ComplexMatrix::column_min () const { Array dummy_idx; return column_min (dummy_idx); @@ -3108,7 +3108,7 @@ } ComplexRowVector -ComplexMatrix::column_max (void) const +ComplexMatrix::column_max () const { Array dummy_idx; return column_max (dummy_idx); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CMatrix.h --- a/liboctave/array/CMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -60,13 +60,13 @@ typedef void (*solve_singularity_handler) (double rcon); - ComplexMatrix (void) = default; + ComplexMatrix () = default; ComplexMatrix (const ComplexMatrix& a) = default; ComplexMatrix& operator = (const ComplexMatrix& a) = default; - ~ComplexMatrix (void) = default; + ~ComplexMatrix () = default; ComplexMatrix (octave_idx_type r, octave_idx_type c) : ComplexNDArray (dim_vector (r, c)) { } @@ -116,7 +116,7 @@ OCTAVE_API bool operator == (const ComplexMatrix& a) const; OCTAVE_API bool operator != (const ComplexMatrix& a) const; - OCTAVE_API bool ishermitian (void) const; + OCTAVE_API bool ishermitian () const; // destructive insert/delete/reorder operations @@ -167,9 +167,9 @@ OCTAVE_API ComplexMatrix stack (const ComplexColumnVector& a) const; OCTAVE_API ComplexMatrix stack (const ComplexDiagMatrix& a) const; - ComplexMatrix hermitian (void) const + ComplexMatrix hermitian () const { return MArray::hermitian (std::conj); } - ComplexMatrix transpose (void) const + ComplexMatrix transpose () const { return MArray::transpose (); } friend OCTAVE_API ComplexMatrix conj (const ComplexMatrix& a); @@ -204,7 +204,7 @@ double& rcon, bool force, bool calc_cond) const; public: - OCTAVE_API ComplexMatrix inverse (void) const; + OCTAVE_API ComplexMatrix inverse () const; OCTAVE_API ComplexMatrix inverse (octave_idx_type& info) const; OCTAVE_API ComplexMatrix inverse (octave_idx_type& info, double& rcon, @@ -219,13 +219,13 @@ OCTAVE_API ComplexMatrix pseudo_inverse (double tol = 0.0) const; - OCTAVE_API ComplexMatrix fourier (void) const; - OCTAVE_API ComplexMatrix ifourier (void) const; + OCTAVE_API ComplexMatrix fourier () const; + OCTAVE_API ComplexMatrix ifourier () const; - OCTAVE_API ComplexMatrix fourier2d (void) const; - OCTAVE_API ComplexMatrix ifourier2d (void) const; + OCTAVE_API ComplexMatrix fourier2d () const; + OCTAVE_API ComplexMatrix ifourier2d () const; - OCTAVE_API ComplexDET determinant (void) const; + OCTAVE_API ComplexDET determinant () const; OCTAVE_API ComplexDET determinant (octave_idx_type& info) const; OCTAVE_API ComplexDET determinant (octave_idx_type& info, double& rcon, @@ -234,7 +234,7 @@ determinant (MatrixType& mattype, octave_idx_type& info, double& rcon, bool calc_cond = true) const; - OCTAVE_API double rcond (void) const; + OCTAVE_API double rcond () const; OCTAVE_API double rcond (MatrixType& mattype) const; private: @@ -418,7 +418,7 @@ OCTAVE_API ComplexMatrix prod (int dim = -1) const; OCTAVE_API ComplexMatrix sum (int dim = -1) const; OCTAVE_API ComplexMatrix sumsq (int dim = -1) const; - OCTAVE_API Matrix abs (void) const; + OCTAVE_API Matrix abs () const; OCTAVE_API ComplexMatrix diag (octave_idx_type k = 0) const; @@ -428,14 +428,14 @@ OCTAVE_API bool row_is_real_only (octave_idx_type) const; OCTAVE_API bool column_is_real_only (octave_idx_type) const; - OCTAVE_API ComplexColumnVector row_min (void) const; - OCTAVE_API ComplexColumnVector row_max (void) const; + OCTAVE_API ComplexColumnVector row_min () const; + OCTAVE_API ComplexColumnVector row_max () const; OCTAVE_API ComplexColumnVector row_min (Array& index) const; OCTAVE_API ComplexColumnVector row_max (Array& index) const; - OCTAVE_API ComplexRowVector column_min (void) const; - OCTAVE_API ComplexRowVector column_max (void) const; + OCTAVE_API ComplexRowVector column_min () const; + OCTAVE_API ComplexRowVector column_max () const; OCTAVE_API ComplexRowVector column_min (Array& index) const; OCTAVE_API ComplexRowVector column_max (Array& index) const; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CNDArray.cc --- a/liboctave/array/CNDArray.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CNDArray.cc Mon Jan 30 18:36:03 2023 +0100 @@ -117,7 +117,7 @@ } ComplexNDArray -ComplexNDArray::fourier2d (void) const +ComplexNDArray::fourier2d () const { dim_vector dv = dims (); if (dv.ndims () < 2) @@ -137,7 +137,7 @@ } ComplexNDArray -ComplexNDArray::ifourier2d (void) const +ComplexNDArray::ifourier2d () const { dim_vector dv = dims (); if (dv.ndims () < 2) @@ -157,7 +157,7 @@ } ComplexNDArray -ComplexNDArray::fourierNd (void) const +ComplexNDArray::fourierNd () const { dim_vector dv = dims (); int rank = dv.ndims (); @@ -172,7 +172,7 @@ } ComplexNDArray -ComplexNDArray::ifourierNd (void) const +ComplexNDArray::ifourierNd () const { dim_vector dv = dims (); int rank = dv.ndims (); @@ -211,7 +211,7 @@ } ComplexNDArray -ComplexNDArray::fourier2d (void) const +ComplexNDArray::fourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -220,7 +220,7 @@ } ComplexNDArray -ComplexNDArray::ifourier2d (void) const +ComplexNDArray::ifourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -229,7 +229,7 @@ } ComplexNDArray -ComplexNDArray::fourierNd (void) const +ComplexNDArray::fourierNd () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -238,7 +238,7 @@ } ComplexNDArray -ComplexNDArray::ifourierNd (void) const +ComplexNDArray::ifourierNd () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -251,7 +251,7 @@ // unary operations boolNDArray -ComplexNDArray::operator ! (void) const +ComplexNDArray::operator ! () const { if (any_element_is_nan ()) octave::err_nan_to_logical_conversion (); @@ -262,13 +262,13 @@ // FIXME: this is not quite the right thing. bool -ComplexNDArray::any_element_is_nan (void) const +ComplexNDArray::any_element_is_nan () const { return do_mx_check (*this, mx_inline_any_nan); } bool -ComplexNDArray::any_element_is_inf_or_nan (void) const +ComplexNDArray::any_element_is_inf_or_nan () const { return ! do_mx_check (*this, mx_inline_all_finite); } @@ -276,7 +276,7 @@ // Return true if no elements have imaginary components. bool -ComplexNDArray::all_elements_are_real (void) const +ComplexNDArray::all_elements_are_real () const { return do_mx_check (*this, mx_inline_all_real); } @@ -337,7 +337,7 @@ } bool -ComplexNDArray::too_large_for_float (void) const +ComplexNDArray::too_large_for_float () const { return test_any (octave::too_large_for_float); } @@ -475,25 +475,25 @@ } NDArray -ComplexNDArray::abs (void) const +ComplexNDArray::abs () const { return do_mx_unary_map (*this); } boolNDArray -ComplexNDArray::isnan (void) const +ComplexNDArray::isnan () const { return do_mx_unary_map (*this); } boolNDArray -ComplexNDArray::isinf (void) const +ComplexNDArray::isinf () const { return do_mx_unary_map (*this); } boolNDArray -ComplexNDArray::isfinite (void) const +ComplexNDArray::isfinite () const { return do_mx_unary_map (*this); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CNDArray.h --- a/liboctave/array/CNDArray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CNDArray.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ { public: - ComplexNDArray (void) : MArray () { } + ComplexNDArray () : MArray () { } ComplexNDArray (const dim_vector& dv) : MArray (dv) { } @@ -64,15 +64,15 @@ // unary operations - OCTAVE_API boolNDArray operator ! (void) const; + OCTAVE_API boolNDArray operator ! () const; // FIXME: this is not quite the right thing. - OCTAVE_API bool any_element_is_nan (void) const; - OCTAVE_API bool any_element_is_inf_or_nan (void) const; - OCTAVE_API bool all_elements_are_real (void) const; + OCTAVE_API bool any_element_is_nan () const; + OCTAVE_API bool any_element_is_inf_or_nan () const; + OCTAVE_API bool all_elements_are_real () const; OCTAVE_API bool all_integers (double& max_val, double& min_val) const; - OCTAVE_API bool too_large_for_float (void) const; + OCTAVE_API bool too_large_for_float () const; OCTAVE_API boolNDArray all (int dim = -1) const; OCTAVE_API boolNDArray any (int dim = -1) const; @@ -112,23 +112,23 @@ OCTAVE_API ComplexNDArray& insert (const ComplexNDArray& a, const Array& ra_idx); - OCTAVE_API NDArray abs (void) const; - OCTAVE_API boolNDArray isnan (void) const; - OCTAVE_API boolNDArray isinf (void) const; - OCTAVE_API boolNDArray isfinite (void) const; + OCTAVE_API NDArray abs () const; + OCTAVE_API boolNDArray isnan () const; + OCTAVE_API boolNDArray isinf () const; + OCTAVE_API boolNDArray isfinite () const; friend OCTAVE_API ComplexNDArray conj (const ComplexNDArray& a); OCTAVE_API ComplexNDArray fourier (int dim = 1) const; OCTAVE_API ComplexNDArray ifourier (int dim = 1) const; - OCTAVE_API ComplexNDArray fourier2d (void) const; - OCTAVE_API ComplexNDArray ifourier2d (void) const; + OCTAVE_API ComplexNDArray fourier2d () const; + OCTAVE_API ComplexNDArray ifourier2d () const; - OCTAVE_API ComplexNDArray fourierNd (void) const; - OCTAVE_API ComplexNDArray ifourierNd (void) const; + OCTAVE_API ComplexNDArray fourierNd () const; + OCTAVE_API ComplexNDArray ifourierNd () const; - ComplexNDArray squeeze (void) const { return MArray::squeeze (); } + ComplexNDArray squeeze () const { return MArray::squeeze (); } static OCTAVE_API void increment_index (Array& ra_idx, @@ -146,14 +146,14 @@ friend OCTAVE_API std::istream& operator >> (std::istream& is, ComplexNDArray& a); - // bool all_elements_are_real (void) const; + // bool all_elements_are_real () const; // bool all_integers (double& max_val, double& min_val) const; OCTAVE_API ComplexNDArray diag (octave_idx_type k = 0) const; OCTAVE_API ComplexNDArray diag (octave_idx_type m, octave_idx_type n) const; - ComplexNDArray& changesign (void) + ComplexNDArray& changesign () { MArray::changesign (); return *this; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CRowVector.cc --- a/liboctave/array/CRowVector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CRowVector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -193,13 +193,13 @@ } ComplexColumnVector -ComplexRowVector::hermitian (void) const +ComplexRowVector::hermitian () const { return MArray::hermitian (std::conj); } ComplexColumnVector -ComplexRowVector::transpose (void) const +ComplexRowVector::transpose () const { return MArray::transpose (); } @@ -323,7 +323,7 @@ // other operations Complex -ComplexRowVector::min (void) const +ComplexRowVector::min () const { octave_idx_type len = numel (); if (len == 0) @@ -343,7 +343,7 @@ } Complex -ComplexRowVector::max (void) const +ComplexRowVector::max () const { octave_idx_type len = numel (); if (len == 0) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CRowVector.h --- a/liboctave/array/CRowVector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CRowVector.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ public: - ComplexRowVector (void) : MArray (dim_vector (1, 0)) { } + ComplexRowVector () : MArray (dim_vector (1, 0)) { } explicit ComplexRowVector (octave_idx_type n) : MArray (dim_vector (1, n)) { } @@ -86,8 +86,8 @@ OCTAVE_API ComplexRowVector append (const RowVector& a) const; OCTAVE_API ComplexRowVector append (const ComplexRowVector& a) const; - OCTAVE_API ComplexColumnVector hermitian (void) const; - OCTAVE_API ComplexColumnVector transpose (void) const; + OCTAVE_API ComplexColumnVector hermitian () const; + OCTAVE_API ComplexColumnVector transpose () const; friend OCTAVE_API ComplexRowVector conj (const ComplexRowVector& a); @@ -114,8 +114,8 @@ // other operations - OCTAVE_API Complex min (void) const; - OCTAVE_API Complex max (void) const; + OCTAVE_API Complex min () const; + OCTAVE_API Complex max () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CSparse.cc --- a/liboctave/array/CSparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CSparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -139,7 +139,7 @@ } bool -SparseComplexMatrix::ishermitian (void) const +SparseComplexMatrix::ishermitian () const { octave_idx_type nr = rows (); octave_idx_type nc = cols (); @@ -597,13 +597,13 @@ } ComplexMatrix -SparseComplexMatrix::matrix_value (void) const +SparseComplexMatrix::matrix_value () const { return Sparse::array_value (); } SparseComplexMatrix -SparseComplexMatrix::hermitian (void) const +SparseComplexMatrix::hermitian () const { octave_idx_type nr = rows (); octave_idx_type nc = cols (); @@ -657,7 +657,7 @@ } SparseComplexMatrix -SparseComplexMatrix::inverse (void) const +SparseComplexMatrix::inverse () const { octave_idx_type info; double rcond; @@ -1068,7 +1068,7 @@ } ComplexDET -SparseComplexMatrix::determinant (void) const +SparseComplexMatrix::determinant () const { octave_idx_type info; double rcond; @@ -7210,7 +7210,7 @@ // unary operations SparseBoolMatrix -SparseComplexMatrix::operator ! (void) const +SparseComplexMatrix::operator ! () const { if (any_element_is_nan ()) octave::err_nan_to_logical_conversion (); @@ -7244,7 +7244,7 @@ } SparseComplexMatrix -SparseComplexMatrix::squeeze (void) const +SparseComplexMatrix::squeeze () const { return MSparse::squeeze (); } @@ -7270,7 +7270,7 @@ // other operations bool -SparseComplexMatrix::any_element_is_nan (void) const +SparseComplexMatrix::any_element_is_nan () const { octave_idx_type nel = nnz (); @@ -7285,7 +7285,7 @@ } bool -SparseComplexMatrix::any_element_is_inf_or_nan (void) const +SparseComplexMatrix::any_element_is_inf_or_nan () const { octave_idx_type nel = nnz (); @@ -7302,7 +7302,7 @@ // Return true if no elements have imaginary components. bool -SparseComplexMatrix::all_elements_are_real (void) const +SparseComplexMatrix::all_elements_are_real () const { return mx_inline_all_real (nnz (), data ()); } @@ -7350,7 +7350,7 @@ } bool -SparseComplexMatrix::too_large_for_float (void) const +SparseComplexMatrix::too_large_for_float () const { return test_any (octave::too_large_for_float); } @@ -7417,7 +7417,7 @@ #undef COL_EXPR } -SparseMatrix SparseComplexMatrix::abs (void) const +SparseMatrix SparseComplexMatrix::abs () const { octave_idx_type nz = nnz (); octave_idx_type nc = cols (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/CSparse.h --- a/liboctave/array/CSparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/CSparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ typedef void (*solve_singularity_handler) (double rcond); - SparseComplexMatrix (void) : MSparse () { } + SparseComplexMatrix () : MSparse () { } SparseComplexMatrix (octave_idx_type r, octave_idx_type c) : MSparse (r, c) { } @@ -108,7 +108,7 @@ OCTAVE_API bool operator == (const SparseComplexMatrix& a) const; OCTAVE_API bool operator != (const SparseComplexMatrix& a) const; - OCTAVE_API bool ishermitian (void) const; + OCTAVE_API bool ishermitian () const; OCTAVE_API SparseComplexMatrix max (int dim = -1) const; OCTAVE_API SparseComplexMatrix @@ -131,10 +131,10 @@ OCTAVE_API SparseComplexMatrix concat (const SparseMatrix& rb, const Array& ra_idx); - OCTAVE_API ComplexMatrix matrix_value (void) const; + OCTAVE_API ComplexMatrix matrix_value () const; - OCTAVE_API SparseComplexMatrix hermitian (void) const; // complex conjugate transpose - SparseComplexMatrix transpose (void) const + OCTAVE_API SparseComplexMatrix hermitian () const; // complex conjugate transpose + SparseComplexMatrix transpose () const { return MSparse::transpose (); } friend OCTAVE_API SparseComplexMatrix conj (const SparseComplexMatrix& a); @@ -155,7 +155,7 @@ const bool calccond = true) const; public: - OCTAVE_API SparseComplexMatrix inverse (void) const; + OCTAVE_API SparseComplexMatrix inverse () const; OCTAVE_API SparseComplexMatrix inverse (MatrixType& mattype) const; OCTAVE_API SparseComplexMatrix inverse (MatrixType& mattype, octave_idx_type& info) const; @@ -163,7 +163,7 @@ inverse (MatrixType& mattype, octave_idx_type& info, double& rcond, bool force = false, bool calc_cond = true) const; - OCTAVE_API ComplexDET determinant (void) const; + OCTAVE_API ComplexDET determinant () const; OCTAVE_API ComplexDET determinant (octave_idx_type& info) const; OCTAVE_API ComplexDET determinant (octave_idx_type& info, double& rcond, @@ -437,7 +437,7 @@ solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcond, solve_singularity_handler sing_handler) const; - OCTAVE_API SparseComplexMatrix squeeze (void) const; + OCTAVE_API SparseComplexMatrix squeeze () const; OCTAVE_API SparseComplexMatrix reshape (const dim_vector& new_dims) const; @@ -447,13 +447,13 @@ OCTAVE_API SparseComplexMatrix ipermute (const Array& vec) const; - OCTAVE_API bool any_element_is_nan (void) const; - OCTAVE_API bool any_element_is_inf_or_nan (void) const; - OCTAVE_API bool all_elements_are_real (void) const; + OCTAVE_API bool any_element_is_nan () const; + OCTAVE_API bool any_element_is_inf_or_nan () const; + OCTAVE_API bool all_elements_are_real () const; OCTAVE_API bool all_integers (double& max_val, double& min_val) const; - OCTAVE_API bool too_large_for_float (void) const; + OCTAVE_API bool too_large_for_float () const; - OCTAVE_API SparseBoolMatrix operator ! (void) const; + OCTAVE_API SparseBoolMatrix operator ! () const; OCTAVE_API SparseBoolMatrix all (int dim = -1) const; OCTAVE_API SparseBoolMatrix any (int dim = -1) const; @@ -463,7 +463,7 @@ OCTAVE_API SparseComplexMatrix prod (int dim = -1) const; OCTAVE_API SparseComplexMatrix sum (int dim = -1) const; OCTAVE_API SparseComplexMatrix sumsq (int dim = -1) const; - OCTAVE_API SparseMatrix abs (void) const; + OCTAVE_API SparseMatrix abs () const; OCTAVE_API SparseComplexMatrix diag (octave_idx_type k = 0) const; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/DiagArray2.cc --- a/liboctave/array/DiagArray2.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/DiagArray2.cc Mon Jan 30 18:36:03 2023 +0100 @@ -66,7 +66,7 @@ template DiagArray2 -DiagArray2::transpose (void) const +DiagArray2::transpose () const { return DiagArray2 (*this, m_d2, m_d1); } @@ -113,7 +113,7 @@ template Array -DiagArray2::array_value (void) const +DiagArray2::array_value () const { Array result (dims (), T (0)); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/DiagArray2.h --- a/liboctave/array/DiagArray2.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/DiagArray2.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,7 +48,7 @@ using typename Array::element_type; - DiagArray2 (void) + DiagArray2 () : Array (), m_d1 (0), m_d2 (0) { } DiagArray2 (octave_idx_type r, octave_idx_type c) @@ -69,7 +69,7 @@ DiagArray2 (const DiagArray2& a) : Array (a.extract_diag ()), m_d1 (a.dim1 ()), m_d2 (a.dim2 ()) { } - ~DiagArray2 (void) = default; + ~DiagArray2 () = default; DiagArray2& operator = (const DiagArray2& a) { @@ -83,26 +83,26 @@ return *this; } - octave_idx_type dim1 (void) const { return m_d1; } - octave_idx_type dim2 (void) const { return m_d2; } + octave_idx_type dim1 () const { return m_d1; } + octave_idx_type dim2 () const { return m_d2; } - octave_idx_type rows (void) const { return dim1 (); } - octave_idx_type cols (void) const { return dim2 (); } - octave_idx_type columns (void) const { return dim2 (); } + octave_idx_type rows () const { return dim1 (); } + octave_idx_type cols () const { return dim2 (); } + octave_idx_type columns () const { return dim2 (); } - octave_idx_type diag_length (void) const { return Array::numel (); } + octave_idx_type diag_length () const { return Array::numel (); } // FIXME: a dangerous ambiguity? - octave_idx_type length (void) const { return Array::numel (); } - octave_idx_type nelem (void) const { return dim1 () * dim2 (); } - octave_idx_type numel (void) const { return nelem (); } + octave_idx_type length () const { return Array::numel (); } + octave_idx_type nelem () const { return dim1 () * dim2 (); } + octave_idx_type numel () const { return nelem (); } - std::size_t byte_size (void) const { return Array::byte_size (); } + std::size_t byte_size () const { return Array::byte_size (); } - dim_vector dims (void) const { return dim_vector (m_d1, m_d2); } + dim_vector dims () const { return dim_vector (m_d1, m_d2); } - bool isempty (void) const { return numel () == 0; } + bool isempty () const { return numel () == 0; } - int ndims (void) const { return 2; } + int ndims () const { return 2; } OCTAVE_API Array extract_diag (octave_idx_type k = 0) const; @@ -161,19 +161,14 @@ resize (n, m, Array::resize_fill_value ()); } - OCTAVE_API DiagArray2 transpose (void) const; + OCTAVE_API DiagArray2 transpose () const; OCTAVE_API DiagArray2 hermitian (T (*fcn) (const T&) = nullptr) const; - OCTAVE_API Array array_value (void) const; - - const T * data (void) const { return Array::data (); } + OCTAVE_API Array array_value () const; -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "for read-only access, use 'data' method instead") - const T * fortran_vec (void) const { return Array::data (); } -#endif + const T * data () const { return Array::data (); } - T * fortran_vec (void) { return Array::fortran_vec (); } + T * fortran_vec () { return Array::fortran_vec (); } void print_info (std::ostream& os, const std::string& prefix) const { Array::print_info (os, prefix); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/MArray.cc --- a/liboctave/array/MArray.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/MArray.cc Mon Jan 30 18:36:03 2023 +0100 @@ -213,7 +213,7 @@ // N-dimensional array with math ops. template void -MArray::changesign (void) +MArray::changesign () { if (Array::is_shared ()) *this = - *this; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/MArray.h --- a/liboctave/array/MArray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/MArray.h Mon Jan 30 18:36:03 2023 +0100 @@ -63,7 +63,7 @@ { public: - MArray (void) : Array () { } + MArray () : Array () { } explicit MArray (const dim_vector& dv) : Array (dv) { } @@ -76,7 +76,7 @@ template MArray (const Array& a) : Array (a) { } - ~MArray (void) = default; + ~MArray () = default; MArray& operator = (const MArray& a) { @@ -94,9 +94,9 @@ MArray ipermute (const Array& vec) const { return Array::ipermute (vec); } - MArray squeeze (void) const { return Array::squeeze (); } + MArray squeeze () const { return Array::squeeze (); } - MArray transpose (void) const + MArray transpose () const { return Array::transpose (); } MArray hermitian (T (*fcn) (const T&) = nullptr) const @@ -119,7 +119,7 @@ idx_add_nd (const octave::idx_vector& idx, const MArray& vals, int dim = -1); - OCTARRAY_API void changesign (void); + OCTARRAY_API void changesign (); private: OCTARRAY_API static void instantiation_guard (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/MDiagArray2.h --- a/liboctave/array/MDiagArray2.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/MDiagArray2.h Mon Jan 30 18:36:03 2023 +0100 @@ -56,7 +56,7 @@ { public: - MDiagArray2 (void) : DiagArray2 () { } + MDiagArray2 () : DiagArray2 () { } MDiagArray2 (octave_idx_type r, octave_idx_type c) : DiagArray2 (r, c) { } @@ -75,7 +75,7 @@ MDiagArray2 (const Array& a, octave_idx_type r, octave_idx_type c) : DiagArray2 (a, r, c) { } - ~MDiagArray2 (void) = default; + ~MDiagArray2 () = default; MDiagArray2& operator = (const MDiagArray2& a) { @@ -88,7 +88,7 @@ return DiagArray2::array_value (); } - octave_idx_type nnz (void) const + octave_idx_type nnz () const { const T *d = this->data (); @@ -103,7 +103,7 @@ MArray diag (octave_idx_type k = 0) const { return DiagArray2::extract_diag (k); } - MDiagArray2 transpose (void) const { return DiagArray2::transpose (); } + MDiagArray2 transpose () const { return DiagArray2::transpose (); } MDiagArray2 hermitian (T (*fcn) (const T&) = nullptr) const { return DiagArray2::hermitian (fcn); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/MSparse.h --- a/liboctave/array/MSparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/MSparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -46,7 +46,7 @@ { public: - MSparse (void) : Sparse () { } + MSparse () : Sparse () { } MSparse (octave_idx_type n, octave_idx_type m) : Sparse (n, m) { } @@ -75,7 +75,7 @@ MSparse (octave_idx_type r, octave_idx_type c, octave_idx_type num_nz) : Sparse (r, c, num_nz) { } - ~MSparse (void) = default; + ~MSparse () = default; MSparse& operator = (const MSparse& a) { @@ -95,9 +95,9 @@ return *this; } - MSparse transpose (void) const { return Sparse::transpose (); } + MSparse transpose () const { return Sparse::transpose (); } - MSparse squeeze (void) const { return Sparse::squeeze (); } + MSparse squeeze () const { return Sparse::squeeze (); } MSparse reshape (const dim_vector& new_dims) const { return Sparse::reshape (new_dims); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/MatrixType.cc --- a/liboctave/array/MatrixType.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/MatrixType.cc Mon Jan 30 18:36:03 2023 +0100 @@ -41,21 +41,21 @@ #include "oct-locbuf.h" static void -warn_cached (void) +warn_cached () { (*current_liboctave_warning_with_id_handler) ("Octave:matrix-type-info", "using cached matrix type"); } static void -warn_invalid (void) +warn_invalid () { (*current_liboctave_warning_with_id_handler) ("Octave:matrix-type-info", "invalid matrix type"); } static void -warn_calculating_sparse_type (void) +warn_calculating_sparse_type () { (*current_liboctave_warning_with_id_handler) ("Octave:matrix-type-info", "calculating sparse matrix type"); @@ -63,7 +63,7 @@ // FIXME: There is a large code duplication here -MatrixType::MatrixType (void) +MatrixType::MatrixType () : m_type (MatrixType::Unknown), m_sp_bandden (octave::sparse_params::get_bandden ()), m_bandden (0), m_upper_band (0), m_lower_band (0), @@ -613,7 +613,7 @@ warn_invalid (); } -MatrixType::~MatrixType (void) +MatrixType::~MatrixType () { if (m_nperm != 0) { @@ -900,7 +900,7 @@ } void -MatrixType::mark_as_symmetric (void) +MatrixType::mark_as_symmetric () { if (m_type == MatrixType::Tridiagonal || m_type == MatrixType::Tridiagonal_Hermitian) @@ -917,7 +917,7 @@ } void -MatrixType::mark_as_unsymmetric (void) +MatrixType::mark_as_unsymmetric () { if (m_type == MatrixType::Tridiagonal || m_type == MatrixType::Tridiagonal_Hermitian) @@ -952,7 +952,7 @@ } void -MatrixType::mark_as_unpermuted (void) +MatrixType::mark_as_unpermuted () { if (m_nperm) { @@ -970,7 +970,7 @@ } MatrixType -MatrixType::transpose (void) const +MatrixType::transpose () const { MatrixType retval (*this); if (m_type == MatrixType::Upper) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/MatrixType.h --- a/liboctave/array/MatrixType.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/MatrixType.h Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ Rectangular }; - OCTAVE_API MatrixType (void); + OCTAVE_API MatrixType (); OCTAVE_API MatrixType (const MatrixType& a); @@ -78,7 +78,7 @@ OCTAVE_API MatrixType (const matrix_type t, const octave_idx_type ku, const octave_idx_type kl, bool _full = false); - OCTAVE_API ~MatrixType (void); + OCTAVE_API ~MatrixType (); OCTAVE_API MatrixType& operator = (const MatrixType& a); @@ -96,77 +96,77 @@ OCTAVE_API int type (const SparseComplexMatrix& a); - double band_density (void) const { return m_bandden; } + double band_density () const { return m_bandden; } - int nupper (void) const { return m_upper_band; } + int nupper () const { return m_upper_band; } - int nlower (void) const { return m_lower_band; } + int nlower () const { return m_lower_band; } - bool is_dense (void) const { return m_dense; } + bool is_dense () const { return m_dense; } - bool isdiag (void) const + bool isdiag () const { return (m_type == Diagonal || m_type == Permuted_Diagonal); } - bool istriu (void) const + bool istriu () const { return (m_type == Upper || m_type == Permuted_Upper); } - bool istril (void) const + bool istril () const { return (m_type == Lower || m_type == Permuted_Lower); } - bool isbanded (void) const + bool isbanded () const { return (m_type == Banded || m_type == Banded_Hermitian); } - bool is_tridiagonal (void) const + bool is_tridiagonal () const { return (m_type == Tridiagonal || m_type == Tridiagonal_Hermitian); } - bool ishermitian (void) const + bool ishermitian () const { return (m_type == Banded_Hermitian || m_type == Tridiagonal_Hermitian || m_type == Hermitian); } - bool is_rectangular (void) const { return (m_type == Rectangular); } + bool is_rectangular () const { return (m_type == Rectangular); } - bool is_known (void) const { return (m_type != Unknown); } + bool is_known () const { return (m_type != Unknown); } - bool is_unknown (void) const { return (m_type == Unknown); } + bool is_unknown () const { return (m_type == Unknown); } - OCTAVE_API void info (void) const; + OCTAVE_API void info () const; - octave_idx_type * triangular_perm (void) const { return m_perm; } + octave_idx_type * triangular_perm () const { return m_perm; } - void invalidate_type (void) { m_type = Unknown; } + void invalidate_type () { m_type = Unknown; } - void mark_as_diagonal (void) { m_type = Diagonal; } + void mark_as_diagonal () { m_type = Diagonal; } - void mark_as_permuted_diagonal (void) { m_type = Permuted_Diagonal; } + void mark_as_permuted_diagonal () { m_type = Permuted_Diagonal; } - void mark_as_upper_triangular (void) { m_type = Upper; } + void mark_as_upper_triangular () { m_type = Upper; } - void mark_as_lower_triangular (void) { m_type = Lower; } + void mark_as_lower_triangular () { m_type = Lower; } - void mark_as_tridiagonal (void) {m_type = Tridiagonal; } + void mark_as_tridiagonal () {m_type = Tridiagonal; } void mark_as_banded (const octave_idx_type ku, const octave_idx_type kl) { m_type = Banded; m_upper_band = ku; m_lower_band = kl; } - void mark_as_full (void) { m_type = Full; } + void mark_as_full () { m_type = Full; } - void mark_as_rectangular (void) { m_type = Rectangular; } + void mark_as_rectangular () { m_type = Rectangular; } - void mark_as_dense (void) { m_dense = true; } + void mark_as_dense () { m_dense = true; } - void mark_as_not_dense (void) { m_dense = false; } + void mark_as_not_dense () { m_dense = false; } - OCTAVE_API void mark_as_symmetric (void); + OCTAVE_API void mark_as_symmetric (); - OCTAVE_API void mark_as_unsymmetric (void); + OCTAVE_API void mark_as_unsymmetric (); OCTAVE_API void mark_as_permuted (const octave_idx_type np, const octave_idx_type *p); - OCTAVE_API void mark_as_unpermuted (void); + OCTAVE_API void mark_as_unpermuted (); - OCTAVE_API MatrixType transpose (void) const; + OCTAVE_API MatrixType transpose () const; private: void type (int new_typ) { m_type = static_cast (new_typ); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/PermMatrix.cc --- a/liboctave/array/PermMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/PermMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -34,7 +34,7 @@ OCTAVE_NORETURN static void -err_invalid_permutation (void) +err_invalid_permutation () { (*current_liboctave_error_handler) ("PermMatrix: invalid permutation vector"); } @@ -98,7 +98,7 @@ } PermMatrix -PermMatrix::transpose (void) const +PermMatrix::transpose () const { octave_idx_type len = Array::numel (); @@ -111,13 +111,13 @@ } PermMatrix -PermMatrix::inverse (void) const +PermMatrix::inverse () const { return transpose (); } octave_idx_type -PermMatrix::determinant (void) const +PermMatrix::determinant () const { // Determine the sign of a permutation in linear time. // Is this widely known? diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/PermMatrix.h --- a/liboctave/array/PermMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/PermMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -38,13 +38,13 @@ { public: - PermMatrix (void) = default; + PermMatrix () = default; PermMatrix (const PermMatrix& m) = default; PermMatrix& operator = (const PermMatrix& m) = default; - ~PermMatrix (void) = default; + ~PermMatrix () = default; OCTAVE_API PermMatrix (octave_idx_type n); @@ -54,33 +54,33 @@ OCTAVE_API PermMatrix (const octave::idx_vector& idx, bool colp, octave_idx_type n = 0); - octave_idx_type dim1 (void) const + octave_idx_type dim1 () const { return Array::numel (); } - octave_idx_type dim2 (void) const + octave_idx_type dim2 () const { return Array::numel (); } - octave_idx_type rows (void) const { return dim1 (); } - octave_idx_type cols (void) const { return dim2 (); } - octave_idx_type columns (void) const { return dim2 (); } + octave_idx_type rows () const { return dim1 (); } + octave_idx_type cols () const { return dim2 (); } + octave_idx_type columns () const { return dim2 (); } - octave_idx_type perm_length (void) const + octave_idx_type perm_length () const { return Array::numel (); } // FIXME: a dangerous ambiguity? - octave_idx_type length (void) const + octave_idx_type length () const { return perm_length (); } - octave_idx_type numel (void) const { return dim1 () * dim2 (); } + octave_idx_type numel () const { return dim1 () * dim2 (); } - std::size_t byte_size (void) const + std::size_t byte_size () const { return Array::byte_size (); } - dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); } + dim_vector dims () const { return dim_vector (dim1 (), dim2 ()); } - bool isempty (void) const { return numel () == 0; } + bool isempty () const { return numel () == 0; } - int ndims (void) const { return 2; } + int ndims () const { return 2; } - const Array& col_perm_vec (void) const + const Array& col_perm_vec () const { return *this; } octave_idx_type @@ -99,17 +99,17 @@ } // These are, in fact, super-fast. - OCTAVE_API PermMatrix transpose (void) const; - OCTAVE_API PermMatrix inverse (void) const; + OCTAVE_API PermMatrix transpose () const; + OCTAVE_API PermMatrix inverse () const; // Determinant, i.e., the sign of permutation. - OCTAVE_API octave_idx_type determinant (void) const; + OCTAVE_API octave_idx_type determinant () const; // Efficient integer power of a permutation. OCTAVE_API PermMatrix power (octave_idx_type n) const; - bool is_col_perm (void) const { return true; } - bool is_row_perm (void) const { return false; } + bool is_col_perm () const { return true; } + bool is_row_perm () const { return false; } void print_info (std::ostream& os, const std::string& prefix) const { Array::print_info (os, prefix); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/Range.cc --- a/liboctave/array/Range.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/Range.cc Mon Jan 30 18:36:03 2023 +0100 @@ -302,28 +302,28 @@ template <> bool -range::all_elements_are_ints (void) const +range::all_elements_are_ints () const { return xall_elements_are_ints (m_base, m_increment, m_final, m_numel); } template <> bool -range::all_elements_are_ints (void) const +range::all_elements_are_ints () const { return xall_elements_are_ints (m_base, m_increment, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } @@ -334,56 +334,56 @@ template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } template <> void -range::init (void) +range::init () { xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel); } @@ -392,14 +392,14 @@ template <> bool -range::is_storable (void) const +range::is_storable () const { return xis_storable (m_base, m_limit, m_numel); } template <> bool -range::is_storable (void) const +range::is_storable () const { return xis_storable (m_base, m_limit, m_numel); } @@ -440,566 +440,16 @@ template <> octave_idx_type -range::nnz (void) const +range::nnz () const { return xnnz (m_base, m_limit, m_increment, m_final, m_numel); } template <> octave_idx_type -range::nnz (void) const +range::nnz () const { return xnnz (m_base, m_limit, m_increment, m_final, m_numel); } OCTAVE_END_NAMESPACE(octave) - -bool -Range::all_elements_are_ints (void) const -{ - // If the base and increment are ints, the final value in the range will also - // be an integer, even if the limit is not. If there is one or fewer - // elements only the base needs to be an integer. - - return (! (octave::math::isnan (m_base) || octave::math::isnan (m_inc)) - && (octave::math::nint_big (m_base) == m_base || m_numel < 1) - && (octave::math::nint_big (m_inc) == m_inc || m_numel <= 1)); -} - -octave_idx_type -Range::nnz (void) const -{ - octave_idx_type retval = 0; - - if (! isempty ()) - { - if ((m_base > 0.0 && m_limit > 0.0) || (m_base < 0.0 && m_limit < 0.0)) - { - // All elements have the same sign, hence there are no zeros. - retval = m_numel; - } - else if (m_inc != 0.0) - { - if (m_base == 0.0 || m_limit == 0.0) - // Exactly one zero at beginning or end of range. - retval = m_numel - 1; - else if ((m_base / m_inc) != std::floor (m_base / m_inc)) - // Range crosses negative/positive without hitting zero. - retval = m_numel; - else - // Range crosses negative/positive and hits zero. - retval = m_numel - 1; - } - else - { - // All elements are equal (m_inc = 0) but not positive or negative, - // therefore all elements are zero. - retval = 0; - } - } - - return retval; -} - -Matrix -Range::matrix_value (void) const -{ - Matrix retval (1, m_numel); - - if (m_numel > 0) - { - // The first element must always be *exactly* the base. - // E.g, -0 would otherwise become +0 in the loop (-0 + 0*increment). - retval(0) = m_base; - - double b = m_base; - double increment = m_inc; - for (octave_idx_type i = 1; i < m_numel - 1; i++) - retval.xelem (i) = b + i * increment; - - retval.xelem (m_numel - 1) = m_limit; - } - - return retval; -} - -double -Range::checkelem (octave_idx_type i) const -{ - if (i < 0 || i >= m_numel) - octave::err_index_out_of_range (2, 2, i+1, m_numel, dims ()); - - if (i == 0) - return m_base; - else if (i < m_numel - 1) - return m_base + i * m_inc; - else - return m_limit; -} - -double -Range::checkelem (octave_idx_type i, octave_idx_type j) const -{ - // Ranges are *always* row vectors. - if (i != 0) - octave::err_index_out_of_range (1, 1, i+1, m_numel, dims ()); - - return checkelem (j); -} - -double -Range::elem (octave_idx_type i) const -{ - if (i == 0) - return m_base; - else if (i < m_numel - 1) - return m_base + i * m_inc; - else - return m_limit; -} - -Array -Range::index (const octave::idx_vector& idx) const -{ - Array retval; - - octave_idx_type n = m_numel; - - if (idx.is_colon ()) - { - retval = matrix_value ().reshape (dim_vector (m_numel, 1)); - } - else - { - if (idx.extent (n) != n) - octave::err_index_out_of_range (1, 1, idx.extent (n), n, dims ()); // throws - - dim_vector idx_dims = idx.orig_dimensions (); - octave_idx_type idx_len = idx.length (n); - - // taken from Array.cc. - if (n != 1 && idx_dims.isvector ()) - idx_dims = dim_vector (1, idx_len); - - retval.clear (idx_dims); - - // Loop over all values in IDX, executing the lambda expression - // for each index value. - - double *array = retval.fortran_vec (); - - idx.loop (n, [=, &array] (idx_vector i) - { - if (i == 0) - *array++ = m_base; - else if (i < m_numel - 1) - *array++ = m_base + i * m_inc; - else - *array++ = m_limit; - }); - } - - return retval; -} - -// NOTE: max and min only return useful values if numel > 0. -// do_minmax_body() in max.cc avoids calling Range::min/max if numel == 0. - -double -Range::min (void) const -{ - double retval = 0.0; - if (m_numel > 0) - { - if (m_inc > 0) - retval = m_base; - else - { - retval = m_base + (m_numel - 1) * m_inc; - - // Require '<=' test. See note in max (). - if (retval <= m_limit) - retval = m_limit; - } - - } - return retval; -} - -double -Range::max (void) const -{ - double retval = 0.0; - if (m_numel > 0) - { - if (m_inc > 0) - { - retval = m_base + (m_numel - 1) * m_inc; - - // On some machines (x86 with extended precision floating point - // arithmetic, for example) it is possible that we can overshoot the - // limit by approximately the machine precision even though we were - // very careful in our calculation of the number of elements. - // Therefore, we clip the result to the limit if it overshoots. - // The test also includes equality (>= m_limit) to have expressions - // such as -5:1:-0 result in a -0 endpoint. - if (retval >= m_limit) - retval = m_limit; - } - else - retval = m_base; - } - return retval; -} - -void -Range::sort_internal (bool ascending) -{ - if ((ascending && m_base > m_limit && m_inc < 0.0) - || (! ascending && m_base < m_limit && m_inc > 0.0)) - { - std::swap (m_base, m_limit); - m_inc = -m_inc; - } -} - -void -Range::sort_internal (Array& sidx, bool ascending) -{ - octave_idx_type nel = numel (); - - sidx.resize (dim_vector (1, nel)); - - octave_idx_type *psidx = sidx.fortran_vec (); - - bool reverse = false; - - if ((ascending && m_base > m_limit && m_inc < 0.0) - || (! ascending && m_base < m_limit && m_inc > 0.0)) - { - std::swap (m_base, m_limit); - m_inc = -m_inc; - reverse = true; - } - - octave_idx_type tmp = (reverse ? nel - 1 : 0); - octave_idx_type stp = (reverse ? -1 : 1); - - for (octave_idx_type i = 0; i < nel; i++, tmp += stp) - psidx[i] = tmp; -} - -Matrix -Range::diag (octave_idx_type k) const -{ - return matrix_value ().diag (k); -} - -Range -Range::sort (octave_idx_type dim, sortmode mode) const -{ - Range retval = *this; - - if (dim == 1) - { - if (mode == ASCENDING) - retval.sort_internal (true); - else if (mode == DESCENDING) - retval.sort_internal (false); - } - else if (dim != 0) - (*current_liboctave_error_handler) ("Range::sort: invalid dimension"); - - return retval; -} - -Range -Range::sort (Array& sidx, octave_idx_type dim, - sortmode mode) const -{ - Range retval = *this; - - if (dim == 1) - { - if (mode == ASCENDING) - retval.sort_internal (sidx, true); - else if (mode == DESCENDING) - retval.sort_internal (sidx, false); - } - else if (dim != 0) - (*current_liboctave_error_handler) ("Range::sort: invalid dimension"); - - return retval; -} - -sortmode -Range::issorted (sortmode mode) const -{ - if (m_numel > 1 && m_inc > 0) - mode = (mode == DESCENDING) ? UNSORTED : ASCENDING; - else if (m_numel > 1 && m_inc < 0) - mode = (mode == ASCENDING) ? UNSORTED : DESCENDING; - else - mode = (mode == UNSORTED) ? ASCENDING : mode; - - return mode; -} - -void -Range::set_base (double b) -{ - if (m_base != b) - { - m_base = b; - - init (); - } -} - -void -Range::set_limit (double l) -{ - if (m_limit != l) - { - m_limit = l; - - init (); - } -} - -void -Range::set_inc (double i) -{ - if (m_inc != i) - { - m_inc = i; - - init (); - } -} - -std::ostream& -operator << (std::ostream& os, const Range& a) -{ - double b = a.base (); - double increment = a.increment (); - octave_idx_type nel = a.numel (); - - if (nel > 1) - { - // First element must be the base *exactly* (e.g., -0). - os << b << ' '; - for (octave_idx_type i = 1; i < nel-1; i++) - os << b + i * increment << ' '; - } - - // Print out the last element exactly, rather than a calculated last element. - os << a.m_limit << "\n"; - - return os; -} - -std::istream& -operator >> (std::istream& is, Range& a) -{ - is >> a.m_base; - if (is) - { - double tmp_limit; - is >> tmp_limit; - - if (is) - is >> a.m_inc; - - // Clip the m_limit to the true limit, rebuild numel, clear cache - a.set_limit (tmp_limit); - } - - return is; -} - -// DEPRECATED in Octave 7. -Range operator - (const Range& r) -{ - return Range (-r.base (), -r.limit (), -r.increment (), r.numel ()); -} - -// DEPRECATED in Octave 7. -Range operator + (double x, const Range& r) -{ - return Range (x + r.base (), x + r.limit (), r.increment (), r.numel ()); -} - -// DEPRECATED in Octave 7. -Range operator + (const Range& r, double x) -{ - return Range (r.base () + x, r.limit () + x, r.increment (), r.numel ()); -} - -// DEPRECATED in Octave 7. -Range operator - (double x, const Range& r) -{ - return Range (x - r.base (), x - r.limit (), -r.increment (), r.numel ()); -} - -// DEPRECATED in Octave 7. -Range operator - (const Range& r, double x) -{ - return Range (r.base () - x, r.limit () - x, r.increment (), r.numel ()); -} - -// DEPRECATED in Octave 7. -Range operator * (double x, const Range& r) -{ - return Range (x * r.base (), x * r.limit (), x * r.increment (), r.numel ()); -} - -// DEPRECATED in Octave 7. -Range operator * (const Range& r, double x) -{ - return Range (r.base () * x, r.limit () * x, r.increment () * x, r.numel ()); -} - -// C See Knuth, Art Of Computer Programming, Vol. 1, Problem 1.2.4-5. -// C -// C===Tolerant FLOOR function. -// C -// C X - is given as a Double Precision argument to be operated on. -// C It is assumed that X is represented with M mantissa bits. -// C CT - is given as a Comparison Tolerance such that -// C 0.LT.CT.LE.3-SQRT(5)/2. If the relative difference between -// C X and A whole number is less than CT, then TFLOOR is -// C returned as this whole number. By treating the -// C floating-point numbers as a finite ordered set note that -// C the heuristic EPS=2.**(-(M-1)) and CT=3*EPS causes -// C arguments of TFLOOR/TCEIL to be treated as whole numbers -// C if they are exactly whole numbers or are immediately -// C adjacent to whole number representations. Since EPS, the -// C "distance" between floating-point numbers on the unit -// C interval, and M, the number of bits in X'S mantissa, exist -// C on every floating-point computer, TFLOOR/TCEIL are -// C consistently definable on every floating-point computer. -// C -// C For more information see the following references: -// C (1) P. E. Hagerty, "More On Fuzzy Floor And Ceiling," APL QUOTE -// C QUAD 8(4):20-24, June 1978. Note that TFLOOR=FL5. -// C (2) L. M. Breed, "Definitions For Fuzzy Floor And Ceiling", APL -// C QUOTE QUAD 8(3):16-23, March 1978. This paper cites FL1 through -// C FL5, the history of five years of evolutionary development of -// C FL5 - the seven lines of code below - by open collaboration -// C and corroboration of the mathematical-computing community. -// C -// C Penn State University Center for Academic Computing -// C H. D. Knoble - August, 1978. - -static inline double -tfloor (double x, double ct) -{ -// C---------FLOOR(X) is the largest integer algebraically less than -// C or equal to X; that is, the unfuzzy FLOOR function. - -// DINT (X) = X - DMOD (X, 1.0); -// FLOOR (X) = DINT (X) - DMOD (2.0 + DSIGN (1.0, X), 3.0); - -// C---------Hagerty's FL5 function follows... - - double q = 1.0; - - if (x < 0.0) - q = 1.0 - ct; - - double rmax = q / (2.0 - ct); - - double t1 = 1.0 + std::floor (x); - t1 = (ct / q) * (t1 < 0.0 ? -t1 : t1); - t1 = (rmax < t1 ? rmax : t1); - t1 = (ct > t1 ? ct : t1); - t1 = std::floor (x + t1); - - if (x <= 0.0 || (t1 - x) < rmax) - return t1; - else - return t1 - 1.0; -} - -static inline bool -teq (double u, double v, - double ct = 3.0 * std::numeric_limits::epsilon ()) -{ - double tu = std::abs (u); - double tv = std::abs (v); - - return std::abs (u - v) < ((tu > tv ? tu : tv) * ct); -} - -octave_idx_type -Range::numel_internal (void) const -{ - octave_idx_type retval = -1; - - if (! octave::math::isfinite (m_base) || ! octave::math::isfinite (m_inc) - || octave::math::isnan (m_limit)) - retval = -2; - else if (octave::math::isinf (m_limit) - && ((m_inc > 0 && m_limit > 0) - || (m_inc < 0 && m_limit < 0))) - retval = std::numeric_limits::max () - 1; - else if (m_inc == 0 - || (m_limit > m_base && m_inc < 0) - || (m_limit < m_base && m_inc > 0)) - { - retval = 0; - } - else - { - double ct = 3.0 * std::numeric_limits::epsilon (); - - double tmp = tfloor ((m_limit - m_base + m_inc) / m_inc, ct); - - octave_idx_type n_elt = (tmp > 0.0 - ? static_cast (tmp) : 0); - - // If the final element that we would compute for the range is equal to - // the limit of the range, or is an adjacent floating point number, - // accept it. Otherwise, try a range with one fewer element. If that - // fails, try again with one more element. - // - // I'm not sure this is very good, but it seems to work better than just - // using tfloor as above. For example, without it, the expression - // 1.8:0.05:1.9 fails to produce the expected result of [1.8, 1.85, 1.9]. - - if (! teq (m_base + (n_elt - 1) * m_inc, m_limit)) - { - if (teq (m_base + (n_elt - 2) * m_inc, m_limit)) - n_elt--; - else if (teq (m_base + n_elt * m_inc, m_limit)) - n_elt++; - } - - retval = ((n_elt < std::numeric_limits::max ()) - ? n_elt : -1); - } - - return retval; -} - -double -Range::limit_internal (void) const -{ - double new_limit = m_inc > 0 ? max () : min (); - - // If result must be an integer then force the new_limit to be one. - if (all_elements_are_ints ()) - new_limit = std::round (new_limit); - - return new_limit; -} - -void -Range::init (void) -{ - m_numel = numel_internal (); - - if (! octave::math::isinf (m_limit)) - m_limit = limit_internal (); -} diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/Range.h --- a/liboctave/array/Range.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/Range.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,550 +40,360 @@ OCTAVE_BEGIN_NAMESPACE(octave) -// For now, only define for floating point types. However, we only -// need range as a temporary local variable in make_float_range -// in ov.cc. - -template -class -range::value>::type> -{ -public: - - range (void) - : m_base (0), m_increment (0), m_limit (0), m_final (0), m_numel (0), - m_reverse (false) - { } - - // LIMIT is an upper limit and may be outside the range of actual - // values. For floating point ranges, we perform a tolerant check - // to attempt to capture limit in the set of values if it is "close" - // to the value of base + a multiple of the increment. - - range (const T& base, const T& increment, const T& limit, - bool reverse = false) - : m_base (base), m_increment (increment), m_limit (limit), - m_final (), m_numel (), m_reverse (reverse) - { - init (); - } - - range (const T& base, const T& limit) - : m_base (base), m_increment (1), m_limit (limit), m_final (), m_numel (), - m_reverse (false) - { - init (); - } + // For now, only define for floating point types. However, we only + // need range as a temporary local variable in make_float_range + // in ov.cc. - // Allow conversion from (presumably) properly constructed Range - // objects. The values of base, limit, increment, and numel must be - // consistent. - - // FIXME: Actually check that base, limit, increment, and numel are - // consistent? - - range (const T& base, const T& increment, const T& limit, - octave_idx_type numel, bool reverse = false) - : m_base (base), m_increment (increment), m_limit (limit), - m_final (limit), m_numel (numel), m_reverse (reverse) - { } - - // We don't use a constructor for this because it will conflict with - // range (base, limit, increment) when T is octave_idx_type. - - static range make_n_element_range (const T& base, const T& increment, - octave_idx_type numel, - bool reverse = false) - { - // We could just make this constructor public, but it allows - // inconsistent ranges to be constructed. And it is probably much - // clearer to see "make_n_element_range" instead of puzzling over the - // purpose of this strange constructor form. - - T final_val = (reverse ? base - (numel - 1) * increment - : base + (numel - 1) * increment); - - return range (base, increment, final_val, numel, reverse); - } - - range (const range& r) - : m_base (r.m_base), m_increment (r.m_increment), - m_limit (r.m_limit), m_final (r.m_final), - m_numel (r.m_numel), m_reverse (r.m_reverse) - { } - - range& operator = (const range& r) + template + class + range::value>::type> { - if (this != &r) - { - m_base = r.m_base; - m_increment = r.m_increment; - m_limit = r.m_limit; - m_final = r.m_final; - m_numel = r.m_numel; - m_reverse = r.m_reverse; - } + public: + + range () + : m_base (0), m_increment (0), m_limit (0), m_final (0), m_numel (0), + m_reverse (false) + { } + + // LIMIT is an upper limit and may be outside the range of actual + // values. For floating point ranges, we perform a tolerant check + // to attempt to capture limit in the set of values if it is "close" + // to the value of base + a multiple of the increment. - return *this; - } - - ~range (void) = default; + range (const T& base, const T& increment, const T& limit, + bool reverse = false) + : m_base (base), m_increment (increment), m_limit (limit), + m_final (), m_numel (), m_reverse (reverse) + { + init (); + } - T base (void) const { return m_base; } - T increment (void) const { return m_increment; } - T limit (void) const { return m_limit; } - bool reverse (void) const { return m_reverse; } + range (const T& base, const T& limit) + : m_base (base), m_increment (1), m_limit (limit), m_final (), m_numel (), + m_reverse (false) + { + init (); + } + + // Allow conversion from (presumably) properly constructed Range + // objects. The values of base, limit, increment, and numel must be + // consistent. - T final_value (void) const { return m_final; } + // FIXME: Actually check that base, limit, increment, and numel are + // consistent? - T min (void) const - { - return (m_numel > 0 - ? ((m_reverse ? m_increment > T (0) - : m_increment > T (0)) ? base () : final_value ()) - : T (0)); - } + range (const T& base, const T& increment, const T& limit, + octave_idx_type numel, bool reverse = false) + : m_base (base), m_increment (increment), m_limit (limit), + m_final (limit), m_numel (numel), m_reverse (reverse) + { } + + // We don't use a constructor for this because it will conflict with + // range (base, limit, increment) when T is octave_idx_type. - T max (void) const - { - return (m_numel > 0 - ? ((m_reverse ? m_increment < T (0) - : m_increment > T (0)) ? final_value () : base ()) - : T (0)); - } + static range make_n_element_range (const T& base, const T& increment, + octave_idx_type numel, + bool reverse = false) + { + // We could just make this constructor public, but it allows + // inconsistent ranges to be constructed. And it is probably much + // clearer to see "make_n_element_range" instead of puzzling over the + // purpose of this strange constructor form. - octave_idx_type numel (void) const { return m_numel; } + T final_val = (reverse ? base - (numel - 1) * increment + : base + (numel - 1) * increment); + + return range (base, increment, final_val, numel, reverse); + } + + range (const range& r) + : m_base (r.m_base), m_increment (r.m_increment), + m_limit (r.m_limit), m_final (r.m_final), + m_numel (r.m_numel), m_reverse (r.m_reverse) + { } - // To support things like "for i = 1:Inf; ...; end" that are - // required for Matlab compatibility, creation of a range object - // like 1:Inf is allowed with m_numel set to - // numeric_limits::max(). However, it is not - // possible to store these ranges. The following function allows - // us to easily distinguish ranges with an infinite number of - // elements. There are specializations for double and float. + range& operator = (const range& r) + { + if (this != &r) + { + m_base = r.m_base; + m_increment = r.m_increment; + m_limit = r.m_limit; + m_final = r.m_final; + m_numel = r.m_numel; + m_reverse = r.m_reverse; + } - bool is_storable (void) const { return true; } + return *this; + } + + ~range () = default; - dim_vector dims (void) const { return dim_vector (1, m_numel); } + T base () const { return m_base; } + T increment () const { return m_increment; } + T limit () const { return m_limit; } + bool reverse () const { return m_reverse; } - octave_idx_type rows (void) const { return 1; } + T final_value () const { return m_final; } - octave_idx_type cols (void) const { return numel (); } - octave_idx_type columns (void) const { return numel (); } + T min () const + { + return (m_numel > 0 + ? ((m_reverse ? m_increment > T (0) + : m_increment > T (0)) ? base () : final_value ()) + : T (0)); + } - bool isempty (void) const { return numel () == 0; } + T max () const + { + return (m_numel > 0 + ? ((m_reverse ? m_increment < T (0) + : m_increment > T (0)) ? final_value () : base ()) + : T (0)); + } - bool all_elements_are_ints (void) const { return true; } + octave_idx_type numel () const { return m_numel; } - sortmode issorted (sortmode mode = ASCENDING) const - { - if (m_numel > 1 && (m_reverse ? m_increment < T (0) - : m_increment > T (0))) - mode = ((mode == DESCENDING) ? UNSORTED : ASCENDING); - else if (m_numel > 1 && (m_reverse ? m_increment > T (0) - : m_increment < T (0))) - mode = ((mode == ASCENDING) ? UNSORTED : DESCENDING); - else - mode = ((mode == UNSORTED) ? ASCENDING : mode); + // To support things like "for i = 1:Inf; ...; end" that are + // required for Matlab compatibility, creation of a range object + // like 1:Inf is allowed with m_numel set to + // numeric_limits::max(). However, it is not + // possible to store these ranges. The following function allows + // us to easily distinguish ranges with an infinite number of + // elements. There are specializations for double and float. + + bool is_storable () const { return true; } + + dim_vector dims () const { return dim_vector (1, m_numel); } + + octave_idx_type rows () const { return 1; } + + octave_idx_type cols () const { return numel (); } + octave_idx_type columns () const { return numel (); } + + bool isempty () const { return numel () == 0; } + + bool all_elements_are_ints () const { return true; } - return mode; - } - - OCTAVE_API octave_idx_type nnz (void) const; + sortmode issorted (sortmode mode = ASCENDING) const + { + if (m_numel > 1 && (m_reverse ? m_increment < T (0) + : m_increment > T (0))) + mode = ((mode == DESCENDING) ? UNSORTED : ASCENDING); + else if (m_numel > 1 && (m_reverse ? m_increment > T (0) + : m_increment < T (0))) + mode = ((mode == ASCENDING) ? UNSORTED : DESCENDING); + else + mode = ((mode == UNSORTED) ? ASCENDING : mode); - // Support for single-index subscripting, without generating matrix cache. + return mode; + } + + OCTAVE_API octave_idx_type nnz () const; - T checkelem (octave_idx_type i) const - { - if (i < 0 || i >= m_numel) - err_index_out_of_range (2, 2, i+1, m_numel, dims ()); + // Support for single-index subscripting, without generating matrix cache. + + T checkelem (octave_idx_type i) const + { + if (i < 0 || i >= m_numel) + err_index_out_of_range (2, 2, i+1, m_numel, dims ()); - if (i == 0) - // Required for proper NaN handling. - return (m_numel == 1 ? final_value () : m_base); - else if (i < m_numel - 1) - return (m_reverse ? m_base + T (i) * m_increment - : m_base + T (i) * m_increment); - else - return final_value (); - } + if (i == 0) + // Required for proper NaN handling. + return (m_numel == 1 ? final_value () : m_base); + else if (i < m_numel - 1) + return (m_reverse ? m_base + T (i) * m_increment + : m_base + T (i) * m_increment); + else + return final_value (); + } - T checkelem (octave_idx_type i, octave_idx_type j) const - { - // Ranges are *always* row vectors. - if (i != 0) - err_index_out_of_range (1, 1, i+1, m_numel, dims ()); + T checkelem (octave_idx_type i, octave_idx_type j) const + { + // Ranges are *always* row vectors. + if (i != 0) + err_index_out_of_range (1, 1, i+1, m_numel, dims ()); - return checkelem (j); - } + return checkelem (j); + } - T elem (octave_idx_type i) const - { - if (i == 0) - // Required for proper NaN handling. - return (m_numel == 1 ? final_value () : m_base); - else if (i < m_numel - 1) - return (m_reverse ? m_base - T (i) * m_increment - : m_base + T (i) * m_increment); - else - return final_value (); - } + T elem (octave_idx_type i) const + { + if (i == 0) + // Required for proper NaN handling. + return (m_numel == 1 ? final_value () : m_base); + else if (i < m_numel - 1) + return (m_reverse ? m_base - T (i) * m_increment + : m_base + T (i) * m_increment); + else + return final_value (); + } - T elem (octave_idx_type /* i */, octave_idx_type j) const - { - return elem (j); - } + T elem (octave_idx_type /* i */, octave_idx_type j) const + { + return elem (j); + } - T operator () (octave_idx_type i) const - { - return elem (i); - } + T operator () (octave_idx_type i) const + { + return elem (i); + } - T operator () (octave_idx_type i, octave_idx_type j) const - { - return elem (i, j); - } + T operator () (octave_idx_type i, octave_idx_type j) const + { + return elem (i, j); + } - Array index (const idx_vector& idx) const - { - Array retval; + Array index (const idx_vector& idx) const + { + Array retval; - octave_idx_type n = m_numel; + octave_idx_type n = m_numel; - if (idx.is_colon ()) - { - retval = array_value ().reshape (dim_vector (m_numel, 1)); - } - else - { - if (idx.extent (n) != n) - err_index_out_of_range (1, 1, idx.extent (n), n, dims ()); + if (idx.is_colon ()) + { + retval = array_value ().reshape (dim_vector (m_numel, 1)); + } + else + { + if (idx.extent (n) != n) + err_index_out_of_range (1, 1, idx.extent (n), n, dims ()); - dim_vector idx_dims = idx.orig_dimensions (); - octave_idx_type idx_len = idx.length (n); + dim_vector idx_dims = idx.orig_dimensions (); + octave_idx_type idx_len = idx.length (n); - // taken from Array.cc. - if (n != 1 && idx_dims.isvector ()) - idx_dims = dim_vector (1, idx_len); + // taken from Array.cc. + if (n != 1 && idx_dims.isvector ()) + idx_dims = dim_vector (1, idx_len); - retval.clear (idx_dims); + retval.clear (idx_dims); - // Loop over all values in IDX, executing the lambda - // expression for each index value. + // Loop over all values in IDX, executing the lambda + // expression for each index value. - T *array = retval.fortran_vec (); + T *array = retval.fortran_vec (); - idx.loop (n, [=, &array] (octave_idx_type i) - { - if (i == 0) - // Required for proper NaN handling. - *array++ = (m_numel == 0 ? m_final : m_base); - else if (i < m_numel - 1) - *array++ = (m_reverse ? m_base - T (i) * m_increment - : m_base + T (i) * m_increment); - else - *array++ = m_final; - }); - } + idx.loop (n, [=, &array] (octave_idx_type i) + { + if (i == 0) + // Required for proper NaN handling. + *array++ = (m_numel == 0 ? m_final : m_base); + else if (i < m_numel - 1) + *array++ = (m_reverse ? m_base - T (i) * m_increment + : m_base + T (i) * m_increment); + else + *array++ = m_final; + }); + } - return retval; - } + return retval; + } - Array diag (octave_idx_type k) const - { - return array_value ().diag (k); - } + Array diag (octave_idx_type k) const + { + return array_value ().diag (k); + } - Array array_value (void) const - { - octave_idx_type nel = numel (); + Array array_value () const + { + octave_idx_type nel = numel (); - Array retval (dim_vector (1, nel)); + Array retval (dim_vector (1, nel)); - if (nel == 1) - // Required for proper NaN handling. - retval(0) = final_value (); - else if (nel > 1) - { - // The first element must always be *exactly* the base. - // E.g, -0 would otherwise become +0 in the loop (-0 + 0*increment). - retval(0) = m_base; + if (nel == 1) + // Required for proper NaN handling. + retval(0) = final_value (); + else if (nel > 1) + { + // The first element must always be *exactly* the base. + // E.g, -0 would otherwise become +0 in the loop (-0 + 0*increment). + retval(0) = m_base; - if (m_reverse) - for (octave_idx_type i = 1; i < nel - 1; i++) - retval.xelem (i) = m_base - i * m_increment; - else - for (octave_idx_type i = 1; i < nel - 1; i++) - retval.xelem (i) = m_base + i * m_increment; + if (m_reverse) + for (octave_idx_type i = 1; i < nel - 1; i++) + retval.xelem (i) = m_base - i * m_increment; + else + for (octave_idx_type i = 1; i < nel - 1; i++) + retval.xelem (i) = m_base + i * m_increment; - retval.xelem (nel - 1) = final_value (); - } + retval.xelem (nel - 1) = final_value (); + } - return retval; - } + return retval; + } -private: + private: - T m_base; - T m_increment; - T m_limit; - T m_final; - octave_idx_type m_numel; - bool m_reverse; + T m_base; + T m_increment; + T m_limit; + T m_final; + octave_idx_type m_numel; + bool m_reverse; - // Setting the number of elements to zero when the increment is zero - // is intentional and matches the behavior of Matlab's colon - // operator. + // Setting the number of elements to zero when the increment is zero + // is intentional and matches the behavior of Matlab's colon + // operator. - // These calculations are appropriate for integer ranges. There are - // specializations for double and float. + // These calculations are appropriate for integer ranges. There are + // specializations for double and float. - void init (void) - { - if (m_reverse) - { - m_numel = ((m_increment == T (0) - || (m_limit > m_base && m_increment > T (0)) - || (m_limit < m_base && m_increment < T (0))) - ? T (0) - : (m_base - m_limit - m_increment) / m_increment); + void init () + { + if (m_reverse) + { + m_numel = ((m_increment == T (0) + || (m_limit > m_base && m_increment > T (0)) + || (m_limit < m_base && m_increment < T (0))) + ? T (0) + : (m_base - m_limit - m_increment) / m_increment); - m_final = m_base - (m_numel - 1) * m_increment; - } - else - { - m_numel = ((m_increment == T (0) - || (m_limit > m_base && m_increment < T (0)) - || (m_limit < m_base && m_increment > T (0))) - ? T (0) - : (m_limit - m_base + m_increment) / m_increment); + m_final = m_base - (m_numel - 1) * m_increment; + } + else + { + m_numel = ((m_increment == T (0) + || (m_limit > m_base && m_increment < T (0)) + || (m_limit < m_base && m_increment > T (0))) + ? T (0) + : (m_limit - m_base + m_increment) / m_increment); - m_final = m_base + (m_numel - 1) * m_increment; - } - } -}; + m_final = m_base + (m_numel - 1) * m_increment; + } + } + }; -// Specializations defined externally. + // Specializations defined externally. -template <> OCTAVE_API bool range::all_elements_are_ints (void) const; -template <> OCTAVE_API bool range::all_elements_are_ints (void) const; + template <> OCTAVE_API bool range::all_elements_are_ints () const; + template <> OCTAVE_API bool range::all_elements_are_ints () const; -template <> OCTAVE_API void range::init (void); -template <> OCTAVE_API void range::init (void); + template <> OCTAVE_API void range::init (); + template <> OCTAVE_API void range::init (); -// For now, only define for floating point types. However, we only -// need range as a temporary local variable in make_float_range -// in ov.cc. + // For now, only define for floating point types. However, we only + // need range as a temporary local variable in make_float_range + // in ov.cc. #if 0 -template <> OCTAVE_API void range::init (void); -template <> OCTAVE_API void range::init (void); -template <> OCTAVE_API void range::init (void); -template <> OCTAVE_API void range::init (void); -template <> OCTAVE_API void range::init (void); -template <> OCTAVE_API void range::init (void); -template <> OCTAVE_API void range::init (void); -template <> OCTAVE_API void range::init (void); + template <> OCTAVE_API void range::init (); + template <> OCTAVE_API void range::init (); + template <> OCTAVE_API void range::init (); + template <> OCTAVE_API void range::init (); + template <> OCTAVE_API void range::init (); + template <> OCTAVE_API void range::init (); + template <> OCTAVE_API void range::init (); + template <> OCTAVE_API void range::init (); #endif -template <> OCTAVE_API bool range::is_storable (void) const; -template <> OCTAVE_API bool range::is_storable (void) const; + template <> OCTAVE_API bool range::is_storable () const; + template <> OCTAVE_API bool range::is_storable () const; -template <> OCTAVE_API octave_idx_type range::nnz (void) const; -template <> OCTAVE_API octave_idx_type range::nnz (void) const; + template <> OCTAVE_API octave_idx_type range::nnz () const; + template <> OCTAVE_API octave_idx_type range::nnz () const; OCTAVE_END_NAMESPACE(octave) -class -Range -{ -public: - - OCTAVE_DEPRECATED (7, "use the 'octave::range' class instead") - Range (void) - : m_base (0), m_limit (0), m_inc (0), m_numel (0) - { } - - // Assume range is already properly constructed, so just copy internal - // values. However, we set LIMIT to the computed final value because - // that mimics the behavior of the other Range class constructors that - // reset limit to the computed final value. - - OCTAVE_DEPRECATED (7, "use the 'octave::range' class instead") - Range (const octave::range& r) - : m_base (r.base ()), m_limit (r.final_value ()), m_inc (r.increment ()), - m_numel (r.numel ()) - { } - - Range (const Range& r) = default; - - Range& operator = (const Range& r) = default; - - ~Range (void) = default; - - OCTAVE_DEPRECATED (7, "use the 'octave::range' class instead") - Range (double b, double l) - : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ()) - { - if (! octave::math::isinf (m_limit)) - m_limit = limit_internal (); - } - - OCTAVE_DEPRECATED (7, "use the 'octave::range' class instead") - Range (double b, double l, double i) - : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ()) - { - if (! octave::math::isinf (m_limit)) - m_limit = limit_internal (); - } - - // NOTE: The following constructor may be deprecated and removed after - // the arithmetic operators are removed. - - // For operators' usage (to preserve element count) and to create - // constant row vectors (obsolete usage). - - OCTAVE_DEPRECATED (7, "use the 'octave::range' class instead") - Range (double b, double i, octave_idx_type n) - : m_base (b), m_limit (b + (n-1) * i), m_inc (i), m_numel (n) - { - if (! octave::math::isinf (m_limit)) - m_limit = limit_internal (); - } - - // The range has a finite number of elements. - bool ok (void) const - { - return (octave::math::isfinite (m_limit) - && (m_numel >= 0 || m_numel == -2)); - } - - double base (void) const { return m_base; } - double limit (void) const { return m_limit; } - double inc (void) const { return m_inc; } - double increment (void) const { return m_inc; } - - // We adjust the limit to be the final value, so return that. We - // could introduce a new variable to store the final value separately, - // but it seems like that would just add confusion. If we changed - // the meaning of the limit function, we would change the behavior of - // programs that expect limit to be the final value instead of the - // value of the limit when the range was created. This problem will - // be fixed with the new template range class. - double final_value (void) const { return m_limit; } - - octave_idx_type numel (void) const { return m_numel; } - - dim_vector dims (void) const { return dim_vector (1, m_numel); } - - octave_idx_type rows (void) const { return 1; } - - octave_idx_type cols (void) const { return numel (); } - octave_idx_type columns (void) const { return numel (); } - - bool isempty (void) const { return numel () == 0; } - - OCTAVE_API bool all_elements_are_ints (void) const; - - OCTAVE_API Matrix matrix_value (void) const; - - OCTAVE_API double min (void) const; - OCTAVE_API double max (void) const; - - OCTAVE_API void sort_internal (bool ascending = true); - OCTAVE_API void sort_internal (Array& sidx, bool ascending = true); - - OCTAVE_API Matrix diag (octave_idx_type k = 0) const; - - OCTAVE_API Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; - OCTAVE_API Range sort (Array& sidx, octave_idx_type dim = 0, - sortmode mode = ASCENDING) const; - - OCTAVE_API sortmode issorted (sortmode mode = ASCENDING) const; - - OCTAVE_API octave_idx_type nnz (void) const; - - // Support for single-index subscripting, without generating matrix cache. - - OCTAVE_API double checkelem (octave_idx_type i) const; - OCTAVE_API double checkelem (octave_idx_type i, octave_idx_type j) const; - - OCTAVE_API double elem (octave_idx_type i) const; - double elem (octave_idx_type /* i */, octave_idx_type j) const - { return elem (j); } - - double operator () (octave_idx_type i) const { return elem (i); } - double operator () (octave_idx_type i, octave_idx_type j) const - { return elem (i, j); } - - OCTAVE_API Array index (const octave::idx_vector& i) const; - - OCTAVE_API void set_base (double b); - - OCTAVE_API void set_limit (double l); - - OCTAVE_API void set_inc (double i); - - friend OCTAVE_API std::ostream& operator << (std::ostream& os, - const Range& r); - friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r); - - friend OCTAVE_API Range operator - (const Range& r); - friend OCTAVE_API Range operator + (double x, const Range& r); - friend OCTAVE_API Range operator + (const Range& r, double x); - friend OCTAVE_API Range operator - (double x, const Range& r); - friend OCTAVE_API Range operator - (const Range& r, double x); - friend OCTAVE_API Range operator * (double x, const Range& r); - friend OCTAVE_API Range operator * (const Range& r, double x); - -private: - - double m_base; - double m_limit; - double m_inc; - - octave_idx_type m_numel; - - OCTAVE_API octave_idx_type numel_internal (void) const; - - OCTAVE_API double limit_internal (void) const; - - OCTAVE_API void init (void); - -protected: - - // NOTE: The following constructor may be removed when the arithmetic - // operators are removed. - - // For operators' usage (to allow all values to be set directly). - Range (double b, double l, double i, octave_idx_type n) - : m_base (b), m_limit (l), m_inc (i), m_numel (n) - { } -}; - -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") -extern OCTAVE_API Range operator - (const Range& r); - -OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") -extern OCTAVE_API Range operator + (double x, const Range& r); - -OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") -extern OCTAVE_API Range operator + (const Range& r, double x); - -OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") -extern OCTAVE_API Range operator - (double x, const Range& r); - -OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") -extern OCTAVE_API Range operator - (const Range& r, double x); - -OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") -extern OCTAVE_API Range operator * (double x, const Range& r); - -OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") -extern OCTAVE_API Range operator * (const Range& r, double x); #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/Sparse-b.cc --- a/liboctave/array/Sparse-b.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/Sparse-b.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,7 @@ template <> OCTAVE_API bool -Sparse::SparseRep::any_element_is_nan (void) const +Sparse::SparseRep::any_element_is_nan () const { return false; } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/Sparse.cc --- a/liboctave/array/Sparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/Sparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -54,7 +54,7 @@ template OCTAVE_API typename Sparse::SparseRep * -Sparse::nil_rep (void) +Sparse::nil_rep () { static typename Sparse::SparseRep nr; return &nr; @@ -176,7 +176,7 @@ template OCTAVE_API bool -Sparse::SparseRep::indices_ok (void) const +Sparse::SparseRep::indices_ok () const { return sparse_indices_ok (m_ridx, m_cidx, m_nrows, m_ncols, nnz ()); } @@ -184,7 +184,7 @@ template OCTAVE_API bool -Sparse::SparseRep::any_element_is_nan (void) const +Sparse::SparseRep::any_element_is_nan () const { octave_idx_type nz = nnz (); @@ -705,7 +705,7 @@ template OCTAVE_API -Sparse::~Sparse (void) +Sparse::~Sparse () { if (--m_rep->m_count == 0) delete m_rep; @@ -1135,7 +1135,7 @@ template OCTAVE_API Sparse -Sparse::transpose (void) const +Sparse::transpose () const { assert (ndims () == 2); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/Sparse.h --- a/liboctave/array/Sparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/Sparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -76,7 +76,7 @@ octave_idx_type m_ncols; octave::refcount m_count; - SparseRep (void) + SparseRep () : Alloc (), m_data (T_allocate (1)), m_ridx (idx_type_allocate (1)), m_cidx (idx_type_allocate (1)), m_nzmax (1), m_nrows (0), m_ncols (0), m_count (1) @@ -141,19 +141,19 @@ std::copy_n (a.m_cidx, m_ncols + 1, m_cidx); } - ~SparseRep (void) + ~SparseRep () { T_deallocate (m_data, m_nzmax); idx_type_deallocate (m_ridx, m_nzmax); idx_type_deallocate (m_cidx, m_ncols + 1); } - octave_idx_type nzmax (void) const { return m_nzmax; } - octave_idx_type nnz (void) const { return m_cidx[m_ncols]; } + octave_idx_type nzmax () const { return m_nzmax; } + octave_idx_type nnz () const { return m_cidx[m_ncols]; } - octave_idx_type rows (void) const { return m_nrows; } - octave_idx_type cols (void) const { return m_ncols; } - octave_idx_type columns (void) const { return m_ncols; } + octave_idx_type rows () const { return m_nrows; } + octave_idx_type cols () const { return m_ncols; } + octave_idx_type columns () const { return m_ncols; } OCTAVE_API T& elem (octave_idx_type r, octave_idx_type c); @@ -175,12 +175,12 @@ OCTAVE_API void change_length (octave_idx_type nz); - OCTAVE_API bool indices_ok (void) const; + OCTAVE_API bool indices_ok () const; - OCTAVE_API bool any_element_is_nan (void) const; + OCTAVE_API bool any_element_is_nan () const; // Prefer nzmax. - octave_idx_type length (void) const { return m_nzmax; } + octave_idx_type length () const { return m_nzmax; } template friend class Sparse; @@ -231,7 +231,7 @@ //-------------------------------------------------------------------- - void make_unique (void) + void make_unique () { if (m_rep->m_count > 1) { @@ -252,11 +252,11 @@ private: - static OCTAVE_API typename Sparse::SparseRep * nil_rep (void); + static OCTAVE_API typename Sparse::SparseRep * nil_rep (); public: - Sparse (void) + Sparse () : m_rep (nil_rep ()), m_dimensions (dim_vector (0, 0)) { m_rep->m_count++; @@ -327,30 +327,30 @@ // Sparsify a normal matrix OCTAVE_API Sparse (const Array& a); - virtual ~Sparse (void); + virtual ~Sparse (); OCTAVE_API Sparse& operator = (const Sparse& a); //! Amount of storage for nonzero elements. //! This may differ from the actual number of elements, see nnz(). - octave_idx_type nzmax (void) const { return m_rep->nzmax (); } + octave_idx_type nzmax () const { return m_rep->nzmax (); } //! Actual number of nonzero terms. - octave_idx_type nnz (void) const { return m_rep->nnz (); } + octave_idx_type nnz () const { return m_rep->nnz (); } // Querying the number of elements (incl. zeros) may overflow the index type, // so don't do it unless you really need it. - octave_idx_type numel (void) const + octave_idx_type numel () const { return m_dimensions.safe_numel (); } - octave_idx_type dim1 (void) const { return m_dimensions(0); } - octave_idx_type dim2 (void) const { return m_dimensions(1); } + octave_idx_type dim1 () const { return m_dimensions(0); } + octave_idx_type dim2 () const { return m_dimensions(1); } - octave_idx_type rows (void) const { return dim1 (); } - octave_idx_type cols (void) const { return dim2 (); } - octave_idx_type columns (void) const { return dim2 (); } + octave_idx_type rows () const { return dim1 (); } + octave_idx_type cols () const { return dim2 (); } + octave_idx_type columns () const { return dim2 (); } octave_idx_type get_row_index (octave_idx_type k) { return ridx (k); } octave_idx_type get_col_index (octave_idx_type k) @@ -361,16 +361,16 @@ return ret; } - std::size_t byte_size (void) const + std::size_t byte_size () const { return (static_cast (cols () + 1) * sizeof (octave_idx_type) + static_cast (nzmax ()) * (sizeof (T) + sizeof (octave_idx_type))); } - dim_vector dims (void) const { return m_dimensions; } + dim_vector dims () const { return m_dimensions; } - Sparse squeeze (void) const { return *this; } + Sparse squeeze () const { return *this; } OCTAVE_API octave_idx_type compute_index (const Array& ra_idx) const; @@ -565,48 +565,48 @@ OCTAVE_API Sparse& insert (const Sparse& a, const Array& idx); - bool issquare (void) const { return (dim1 () == dim2 ()); } + bool issquare () const { return (dim1 () == dim2 ()); } - bool isempty (void) const { return (rows () < 1 || cols () < 1); } + bool isempty () const { return (rows () < 1 || cols () < 1); } - OCTAVE_API Sparse transpose (void) const; + OCTAVE_API Sparse transpose () const; - T * data (void) { make_unique (); return m_rep->m_data; } + T * data () { make_unique (); return m_rep->m_data; } T& data (octave_idx_type i) { make_unique (); return m_rep->data (i); } - T * xdata (void) { return m_rep->m_data; } + T * xdata () { return m_rep->m_data; } T& xdata (octave_idx_type i) { return m_rep->data (i); } T data (octave_idx_type i) const { return m_rep->data (i); } // FIXME: shouldn't this be returning const T*? - T * data (void) const { return m_rep->m_data; } + T * data () const { return m_rep->m_data; } - octave_idx_type * ridx (void) { make_unique (); return m_rep->m_ridx; } + octave_idx_type * ridx () { make_unique (); return m_rep->m_ridx; } octave_idx_type& ridx (octave_idx_type i) { make_unique (); return m_rep->ridx (i); } - octave_idx_type * xridx (void) { return m_rep->m_ridx; } + octave_idx_type * xridx () { return m_rep->m_ridx; } octave_idx_type& xridx (octave_idx_type i) { return m_rep->ridx (i); } octave_idx_type ridx (octave_idx_type i) const { return m_rep->cridx (i); } // FIXME: shouldn't this be returning const octave_idx_type*? - octave_idx_type * ridx (void) const { return m_rep->m_ridx; } + octave_idx_type * ridx () const { return m_rep->m_ridx; } - octave_idx_type * cidx (void) { make_unique (); return m_rep->m_cidx; } + octave_idx_type * cidx () { make_unique (); return m_rep->m_cidx; } octave_idx_type& cidx (octave_idx_type i) { make_unique (); return m_rep->cidx (i); } - octave_idx_type * xcidx (void) { return m_rep->m_cidx; } + octave_idx_type * xcidx () { return m_rep->m_cidx; } octave_idx_type& xcidx (octave_idx_type i) { return m_rep->cidx (i); } octave_idx_type cidx (octave_idx_type i) const { return m_rep->ccidx (i); } // FIXME: shouldn't this be returning const octave_idx_type*? - octave_idx_type * cidx (void) const { return m_rep->m_cidx; } + octave_idx_type * cidx () const { return m_rep->m_cidx; } - octave_idx_type ndims (void) const { return m_dimensions.ndims (); } + octave_idx_type ndims () const { return m_dimensions.ndims (); } OCTAVE_API void delete_elements (const octave::idx_vector& i); @@ -649,7 +649,7 @@ static OCTAVE_API Sparse cat (int dim, octave_idx_type n, const Sparse *sparse_list); - OCTAVE_API Array array_value (void) const; + OCTAVE_API Array array_value () const; // Generic any/all test functionality with arbitrary predicate. template @@ -746,9 +746,9 @@ map (U (&fcn) (const T&)) const { return map (fcn); } - bool indices_ok (void) const { return m_rep->indices_ok (); } + bool indices_ok () const { return m_rep->indices_ok (); } - bool any_element_is_nan (void) const + bool any_element_is_nan () const { return m_rep->any_element_is_nan (); } }; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/boolMatrix.cc --- a/liboctave/array/boolMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/boolMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -63,7 +63,7 @@ // unary operations boolMatrix -boolMatrix::operator ! (void) const +boolMatrix::operator ! () const { octave_idx_type nr = rows (); octave_idx_type nc = cols (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/boolMatrix.h --- a/liboctave/array/boolMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/boolMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,13 +39,13 @@ { public: - boolMatrix (void) = default; + boolMatrix () = default; boolMatrix (const boolMatrix& a) = default; boolMatrix& operator = (const boolMatrix& a) = default; - ~boolMatrix (void) = default; + ~boolMatrix () = default; boolMatrix (octave_idx_type r, octave_idx_type c) : boolNDArray (dim_vector (r, c)) { } @@ -63,7 +63,7 @@ OCTAVE_API bool operator == (const boolMatrix& a) const; OCTAVE_API bool operator != (const boolMatrix& a) const; - boolMatrix transpose (void) const { return Array::transpose (); } + boolMatrix transpose () const { return Array::transpose (); } // destructive insert/delete/reorder operations @@ -72,7 +72,7 @@ // unary operations - OCTAVE_API boolMatrix operator ! (void) const; + OCTAVE_API boolMatrix operator ! () const; // other operations diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/boolNDArray.cc --- a/liboctave/array/boolNDArray.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/boolNDArray.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,13 +39,13 @@ // unary operations boolNDArray -boolNDArray::operator ! (void) const +boolNDArray::operator ! () const { return do_mx_unary_op (*this, mx_inline_not); } boolNDArray& -boolNDArray::invert (void) +boolNDArray::invert () { if (is_shared ()) *this = ! *this; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/boolNDArray.h --- a/liboctave/array/boolNDArray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/boolNDArray.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,7 @@ typedef boolMatrix matrix_type; - boolNDArray (void) : Array () { } + boolNDArray () : Array () { } boolNDArray (const dim_vector& dv) : Array (dv) { } @@ -60,11 +60,11 @@ // unary operations - OCTAVE_API boolNDArray operator ! (void) const; + OCTAVE_API boolNDArray operator ! () const; - OCTAVE_API boolNDArray& invert (void); + OCTAVE_API boolNDArray& invert (); - bool any_element_is_nan (void) const { return false; } + bool any_element_is_nan () const { return false; } // FIXME: this is not quite the right thing. @@ -79,7 +79,7 @@ OCTAVE_API boolNDArray& insert (const boolNDArray& a, const Array& ra_idx); - boolNDArray squeeze (void) const { return Array::squeeze (); } + boolNDArray squeeze () const { return Array::squeeze (); } static OCTAVE_API void increment_index (Array& ra_idx, @@ -94,7 +94,7 @@ // friend std::ostream& operator << (std::ostream& os, const NDArray& a); // friend std::istream& operator >> (std::istream& is, NDArray& a); - // bool all_elements_are_real (void) const; + // bool all_elements_are_real () const; // bool all_integers (double& max_val, double& min_val) const; OCTAVE_API boolNDArray diag (octave_idx_type k = 0) const; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/boolSparse.cc --- a/liboctave/array/boolSparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/boolSparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -102,7 +102,7 @@ // unary operations SparseBoolMatrix -SparseBoolMatrix::operator ! (void) const +SparseBoolMatrix::operator ! () const { octave_idx_type nr = rows (); octave_idx_type nc = cols (); @@ -245,7 +245,7 @@ } boolMatrix -SparseBoolMatrix::matrix_value (void) const +SparseBoolMatrix::matrix_value () const { octave_idx_type nr = rows (); octave_idx_type nc = cols (); @@ -284,7 +284,7 @@ } SparseBoolMatrix -SparseBoolMatrix::squeeze (void) const +SparseBoolMatrix::squeeze () const { return Sparse::squeeze (); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/boolSparse.h --- a/liboctave/array/boolSparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/boolSparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,7 +44,7 @@ // Corresponding dense matrix type for this sparse matrix type. typedef boolMatrix dense_matrix_type; - SparseBoolMatrix (void) : Sparse () { } + SparseBoolMatrix () : Sparse () { } SparseBoolMatrix (octave_idx_type r, octave_idx_type c) : Sparse (r, c) { } @@ -86,7 +86,7 @@ OCTAVE_API bool operator == (const SparseBoolMatrix& a) const; OCTAVE_API bool operator != (const SparseBoolMatrix& a) const; - SparseBoolMatrix transpose (void) const + SparseBoolMatrix transpose () const { return Sparse::transpose (); } // destructive insert/delete/reorder operations @@ -102,9 +102,9 @@ OCTAVE_API SparseBoolMatrix diag (octave_idx_type k = 0) const; - OCTAVE_API boolMatrix matrix_value (void) const; + OCTAVE_API boolMatrix matrix_value () const; - OCTAVE_API SparseBoolMatrix squeeze (void) const; + OCTAVE_API SparseBoolMatrix squeeze () const; OCTAVE_API SparseBoolMatrix index (const octave::idx_vector& i, bool resize_ok) const; @@ -123,7 +123,7 @@ // unary operations - OCTAVE_API SparseBoolMatrix operator ! (void) const; + OCTAVE_API SparseBoolMatrix operator ! () const; // other operations diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/chMatrix.h --- a/liboctave/array/chMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/chMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,13 +44,13 @@ public: - charMatrix (void) = default; + charMatrix () = default; charMatrix (const charMatrix& a) = default; charMatrix& operator = (const charMatrix& a) = default; - ~charMatrix (void) = default; + ~charMatrix () = default; charMatrix (octave_idx_type r, octave_idx_type c) : charNDArray (dim_vector (r, c)) { } @@ -77,7 +77,7 @@ OCTAVE_API bool operator == (const charMatrix& a) const; OCTAVE_API bool operator != (const charMatrix& a) const; - charMatrix transpose (void) const { return Array::transpose (); } + charMatrix transpose () const { return Array::transpose (); } // destructive insert/delete/reorder operations diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/chNDArray.h --- a/liboctave/array/chNDArray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/chNDArray.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ typedef charMatrix matrix_type; - charNDArray (void) : Array () { } + charNDArray () : Array () { } charNDArray (const dim_vector& dv) : Array (dv) { } @@ -66,7 +66,7 @@ return *this; } - bool any_element_is_nan (void) const { return false; } + bool any_element_is_nan () const { return false; } // FIXME: this is not quite the right thing. @@ -89,7 +89,7 @@ OCTAVE_API charNDArray& insert (const charNDArray& a, const Array& ra_idx); - charNDArray squeeze (void) const { return Array::squeeze (); } + charNDArray squeeze () const { return Array::squeeze (); } static OCTAVE_API void increment_index (Array& ra_idx, diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dColVector.cc --- a/liboctave/array/dColVector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dColVector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -122,13 +122,13 @@ } RowVector -ColumnVector::transpose (void) const +ColumnVector::transpose () const { return MArray::transpose (); } ColumnVector -ColumnVector::abs (void) const +ColumnVector::abs () const { return do_mx_unary_map (*this); } @@ -242,7 +242,7 @@ // other operations double -ColumnVector::min (void) const +ColumnVector::min () const { octave_idx_type len = numel (); if (len == 0) @@ -258,7 +258,7 @@ } double -ColumnVector::max (void) const +ColumnVector::max () const { octave_idx_type len = numel (); if (len == 0) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dColVector.h --- a/liboctave/array/dColVector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dColVector.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - ColumnVector (void) : MArray (dim_vector (0, 1)) { } + ColumnVector () : MArray (dim_vector (0, 1)) { } explicit ColumnVector (octave_idx_type n) : MArray (dim_vector (n, 1)) { } @@ -72,7 +72,7 @@ OCTAVE_API ColumnVector stack (const ColumnVector& a) const; - OCTAVE_API RowVector transpose (void) const; + OCTAVE_API RowVector transpose () const; friend OCTAVE_API ColumnVector real (const ComplexColumnVector& a); friend OCTAVE_API ColumnVector imag (const ComplexColumnVector& a); @@ -97,10 +97,10 @@ // other operations - OCTAVE_API double min (void) const; - OCTAVE_API double max (void) const; + OCTAVE_API double min () const; + OCTAVE_API double max () const; - OCTAVE_API ColumnVector abs (void) const; + OCTAVE_API ColumnVector abs () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dDiagMatrix.cc --- a/liboctave/array/dDiagMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dDiagMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -125,7 +125,7 @@ } DiagMatrix -DiagMatrix::abs (void) const +DiagMatrix::abs () const { return DiagMatrix (extract_diag ().abs (), rows (), columns ()); } @@ -224,7 +224,7 @@ } DiagMatrix -DiagMatrix::inverse (void) const +DiagMatrix::inverse () const { octave_idx_type info; return inverse (info); @@ -328,7 +328,7 @@ // other operations DET -DiagMatrix::determinant (void) const +DiagMatrix::determinant () const { DET det (1.0); if (rows () != cols ()) @@ -342,7 +342,7 @@ } double -DiagMatrix::rcond (void) const +DiagMatrix::rcond () const { ColumnVector av = extract_diag (0).map (fabs); double amx = av.max (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dDiagMatrix.h --- a/liboctave/array/dDiagMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dDiagMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,13 +42,13 @@ typedef Matrix full_matrix_type; - DiagMatrix (void) = default; + DiagMatrix () = default; DiagMatrix (const DiagMatrix& a) = default; DiagMatrix& operator = (const DiagMatrix& a) = default; - ~DiagMatrix (void) = default; + ~DiagMatrix () = default; DiagMatrix (octave_idx_type r, octave_idx_type c) : MDiagArray2 (r, c) { } @@ -77,9 +77,9 @@ OCTAVE_API DiagMatrix& fill (const ColumnVector& a, octave_idx_type beg); OCTAVE_API DiagMatrix& fill (const RowVector& a, octave_idx_type beg); - DiagMatrix transpose (void) const + DiagMatrix transpose () const { return MDiagArray2::transpose (); } - DiagMatrix abs (void) const; + DiagMatrix abs () const; friend OCTAVE_API DiagMatrix real (const ComplexDiagMatrix& a); friend OCTAVE_API DiagMatrix imag (const ComplexDiagMatrix& a); @@ -98,7 +98,7 @@ OCTAVE_API ColumnVector column (octave_idx_type i) const; OCTAVE_API ColumnVector column (char *s) const; - OCTAVE_API DiagMatrix inverse (void) const; + OCTAVE_API DiagMatrix inverse () const; OCTAVE_API DiagMatrix inverse (octave_idx_type& info) const; OCTAVE_API DiagMatrix pseudo_inverse (double tol = 0.0) const; @@ -107,8 +107,8 @@ ColumnVector extract_diag (octave_idx_type k = 0) const { return MDiagArray2::extract_diag (k); } - OCTAVE_API DET determinant (void) const; - OCTAVE_API double rcond (void) const; + OCTAVE_API DET determinant () const; + OCTAVE_API double rcond () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dMatrix.cc --- a/liboctave/array/dMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -133,7 +133,7 @@ } bool -Matrix::issymmetric (void) const +Matrix::issymmetric () const { if (issquare () && rows () > 0) { @@ -448,7 +448,7 @@ } Matrix -Matrix::inverse (void) const +Matrix::inverse () const { octave_idx_type info; double rcon; @@ -731,7 +731,7 @@ #if defined (HAVE_FFTW) ComplexMatrix -Matrix::fourier (void) const +Matrix::fourier () const { std::size_t nr = rows (); std::size_t nc = cols (); @@ -760,7 +760,7 @@ } ComplexMatrix -Matrix::ifourier (void) const +Matrix::ifourier () const { std::size_t nr = rows (); std::size_t nc = cols (); @@ -790,7 +790,7 @@ } ComplexMatrix -Matrix::fourier2d (void) const +Matrix::fourier2d () const { dim_vector dv (rows (), cols ()); @@ -802,7 +802,7 @@ } ComplexMatrix -Matrix::ifourier2d (void) const +Matrix::ifourier2d () const { dim_vector dv (rows (), cols ()); @@ -817,7 +817,7 @@ #else ComplexMatrix -Matrix::fourier (void) const +Matrix::fourier () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -826,7 +826,7 @@ } ComplexMatrix -Matrix::ifourier (void) const +Matrix::ifourier () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -835,7 +835,7 @@ } ComplexMatrix -Matrix::fourier2d (void) const +Matrix::fourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -844,7 +844,7 @@ } ComplexMatrix -Matrix::ifourier2d (void) const +Matrix::ifourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -855,7 +855,7 @@ #endif DET -Matrix::determinant (void) const +Matrix::determinant () const { octave_idx_type info; double rcon; @@ -1026,7 +1026,7 @@ } double -Matrix::rcond (void) const +Matrix::rcond () const { MatrixType mattype (*this); return rcond (mattype); @@ -2398,7 +2398,7 @@ } Matrix -Matrix::abs (void) const +Matrix::abs () const { return NDArray::abs (); } @@ -2426,7 +2426,7 @@ } ColumnVector -Matrix::row_min (void) const +Matrix::row_min () const { Array dummy_idx; return row_min (dummy_idx); @@ -2481,7 +2481,7 @@ } ColumnVector -Matrix::row_max (void) const +Matrix::row_max () const { Array dummy_idx; return row_max (dummy_idx); @@ -2536,7 +2536,7 @@ } RowVector -Matrix::column_min (void) const +Matrix::column_min () const { Array dummy_idx; return column_min (dummy_idx); @@ -2591,7 +2591,7 @@ } RowVector -Matrix::column_max (void) const +Matrix::column_max () const { Array dummy_idx; return column_max (dummy_idx); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dMatrix.h --- a/liboctave/array/dMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -59,13 +59,13 @@ typedef void (*solve_singularity_handler) (double rcon); - Matrix (void) = default; + Matrix () = default; Matrix (const Matrix& a) = default; Matrix& operator = (const Matrix& a) = default; - ~Matrix (void) = default; + ~Matrix () = default; Matrix (octave_idx_type r, octave_idx_type c) : NDArray (dim_vector (r, c)) { } @@ -103,7 +103,7 @@ OCTAVE_API bool operator == (const Matrix& a) const; OCTAVE_API bool operator != (const Matrix& a) const; - OCTAVE_API bool issymmetric (void) const; + OCTAVE_API bool issymmetric () const; // destructive insert/delete/reorder operations @@ -136,8 +136,8 @@ friend class ComplexMatrix; - Matrix hermitian (void) const { return MArray::transpose (); } - Matrix transpose (void) const { return MArray::transpose (); } + Matrix hermitian () const { return MArray::transpose (); } + Matrix transpose () const { return MArray::transpose (); } // resize is the destructive equivalent for this one @@ -168,7 +168,7 @@ bool force, bool calc_cond) const; public: - OCTAVE_API Matrix inverse (void) const; + OCTAVE_API Matrix inverse () const; OCTAVE_API Matrix inverse (octave_idx_type& info) const; OCTAVE_API Matrix inverse (octave_idx_type& info, double& rcon, bool force = false, @@ -182,13 +182,13 @@ OCTAVE_API Matrix pseudo_inverse (double tol = 0.0) const; - OCTAVE_API ComplexMatrix fourier (void) const; - OCTAVE_API ComplexMatrix ifourier (void) const; + OCTAVE_API ComplexMatrix fourier () const; + OCTAVE_API ComplexMatrix ifourier () const; - OCTAVE_API ComplexMatrix fourier2d (void) const; - OCTAVE_API ComplexMatrix ifourier2d (void) const; + OCTAVE_API ComplexMatrix fourier2d () const; + OCTAVE_API ComplexMatrix ifourier2d () const; - OCTAVE_API DET determinant (void) const; + OCTAVE_API DET determinant () const; OCTAVE_API DET determinant (octave_idx_type& info) const; OCTAVE_API DET determinant (octave_idx_type& info, double& rcon, @@ -197,7 +197,7 @@ determinant (MatrixType& mattype, octave_idx_type& info, double& rcon, bool calc_cond = true) const; - OCTAVE_API double rcond (void) const; + OCTAVE_API double rcond () const; OCTAVE_API double rcond (MatrixType& mattype) const; private: @@ -371,20 +371,20 @@ OCTAVE_API Matrix prod (int dim = -1) const; OCTAVE_API Matrix sum (int dim = -1) const; OCTAVE_API Matrix sumsq (int dim = -1) const; - OCTAVE_API Matrix abs (void) const; + OCTAVE_API Matrix abs () const; OCTAVE_API Matrix diag (octave_idx_type k = 0) const; OCTAVE_API DiagMatrix diag (octave_idx_type m, octave_idx_type n) const; - OCTAVE_API ColumnVector row_min (void) const; - OCTAVE_API ColumnVector row_max (void) const; + OCTAVE_API ColumnVector row_min () const; + OCTAVE_API ColumnVector row_max () const; OCTAVE_API ColumnVector row_min (Array& index) const; OCTAVE_API ColumnVector row_max (Array& index) const; - OCTAVE_API RowVector column_min (void) const; - OCTAVE_API RowVector column_max (void) const; + OCTAVE_API RowVector column_min () const; + OCTAVE_API RowVector column_max () const; OCTAVE_API RowVector column_min (Array& index) const; OCTAVE_API RowVector column_max (Array& index) const; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dNDArray.cc --- a/liboctave/array/dNDArray.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dNDArray.cc Mon Jan 30 18:36:03 2023 +0100 @@ -158,7 +158,7 @@ } ComplexNDArray -NDArray::fourier2d (void) const +NDArray::fourier2d () const { dim_vector dv = dims (); if (dv.ndims () < 2) @@ -178,7 +178,7 @@ } ComplexNDArray -NDArray::ifourier2d (void) const +NDArray::ifourier2d () const { dim_vector dv = dims (); if (dv.ndims () < 2) @@ -197,7 +197,7 @@ } ComplexNDArray -NDArray::fourierNd (void) const +NDArray::fourierNd () const { dim_vector dv = dims (); int rank = dv.ndims (); @@ -212,7 +212,7 @@ } ComplexNDArray -NDArray::ifourierNd (void) const +NDArray::ifourierNd () const { dim_vector dv = dims (); int rank = dv.ndims (); @@ -252,7 +252,7 @@ } ComplexNDArray -NDArray::fourier2d (void) const +NDArray::fourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -261,7 +261,7 @@ } ComplexNDArray -NDArray::ifourier2d (void) const +NDArray::ifourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -270,7 +270,7 @@ } ComplexNDArray -NDArray::fourierNd (void) const +NDArray::fourierNd () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -279,7 +279,7 @@ } ComplexNDArray -NDArray::ifourierNd (void) const +NDArray::ifourierNd () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -292,7 +292,7 @@ // unary operations boolNDArray -NDArray::operator ! (void) const +NDArray::operator ! () const { if (any_element_is_nan ()) octave::err_nan_to_logical_conversion (); @@ -315,31 +315,31 @@ } bool -NDArray::any_element_is_nan (void) const +NDArray::any_element_is_nan () const { return do_mx_check (*this, mx_inline_any_nan); } bool -NDArray::any_element_is_inf_or_nan (void) const +NDArray::any_element_is_inf_or_nan () const { return ! do_mx_check (*this, mx_inline_all_finite); } bool -NDArray::any_element_not_one_or_zero (void) const +NDArray::any_element_not_one_or_zero () const { return ! test_all (octave::is_one_or_zero); } bool -NDArray::all_elements_are_zero (void) const +NDArray::all_elements_are_zero () const { return test_all (octave::is_zero); } bool -NDArray::all_elements_are_int_or_inf_or_nan (void) const +NDArray::all_elements_are_int_or_inf_or_nan () const { return test_all (octave::is_int_or_inf_or_nan); } @@ -378,13 +378,13 @@ } bool -NDArray::all_integers (void) const +NDArray::all_integers () const { return test_all (octave::math::isinteger); } bool -NDArray::too_large_for_float (void) const +NDArray::too_large_for_float () const { return test_any (octave::too_large_for_float); } @@ -567,25 +567,25 @@ } NDArray -NDArray::abs (void) const +NDArray::abs () const { return do_mx_unary_map (*this); } boolNDArray -NDArray::isnan (void) const +NDArray::isnan () const { return do_mx_unary_map (*this); } boolNDArray -NDArray::isinf (void) const +NDArray::isinf () const { return do_mx_unary_map (*this); } boolNDArray -NDArray::isfinite (void) const +NDArray::isfinite () const { return do_mx_unary_map (*this); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dNDArray.h --- a/liboctave/array/dNDArray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dNDArray.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ { public: - NDArray (void) : MArray () { } + NDArray () : MArray () { } NDArray (const dim_vector& dv) : MArray (dv) { } @@ -71,18 +71,18 @@ // unary operations - OCTAVE_API boolNDArray operator ! (void) const; + OCTAVE_API boolNDArray operator ! () const; OCTAVE_API bool any_element_is_negative (bool = false) const; OCTAVE_API bool any_element_is_positive (bool = false) const; - OCTAVE_API bool any_element_is_nan (void) const; - OCTAVE_API bool any_element_is_inf_or_nan (void) const; - OCTAVE_API bool any_element_not_one_or_zero (void) const; - OCTAVE_API bool all_elements_are_zero (void) const; - OCTAVE_API bool all_elements_are_int_or_inf_or_nan (void) const; + OCTAVE_API bool any_element_is_nan () const; + OCTAVE_API bool any_element_is_inf_or_nan () const; + OCTAVE_API bool any_element_not_one_or_zero () const; + OCTAVE_API bool all_elements_are_zero () const; + OCTAVE_API bool all_elements_are_int_or_inf_or_nan () const; OCTAVE_API bool all_integers (double& max_val, double& min_val) const; - OCTAVE_API bool all_integers (void) const; - OCTAVE_API bool too_large_for_float (void) const; + OCTAVE_API bool all_integers () const; + OCTAVE_API bool too_large_for_float () const; // FIXME: this is not quite the right thing. @@ -121,26 +121,26 @@ OCTAVE_API NDArray& insert (const NDArray& a, const Array& ra_idx); - OCTAVE_API NDArray abs (void) const; - OCTAVE_API boolNDArray isnan (void) const; - OCTAVE_API boolNDArray isinf (void) const; - OCTAVE_API boolNDArray isfinite (void) const; + OCTAVE_API NDArray abs () const; + OCTAVE_API boolNDArray isnan () const; + OCTAVE_API boolNDArray isinf () const; + OCTAVE_API boolNDArray isfinite () const; OCTAVE_API ComplexNDArray fourier (int dim = 1) const; OCTAVE_API ComplexNDArray ifourier (int dim = 1) const; - OCTAVE_API ComplexNDArray fourier2d (void) const; - OCTAVE_API ComplexNDArray ifourier2d (void) const; + OCTAVE_API ComplexNDArray fourier2d () const; + OCTAVE_API ComplexNDArray ifourier2d () const; - OCTAVE_API ComplexNDArray fourierNd (void) const; - OCTAVE_API ComplexNDArray ifourierNd (void) const; + OCTAVE_API ComplexNDArray fourierNd () const; + OCTAVE_API ComplexNDArray ifourierNd () const; friend OCTAVE_API NDArray real (const ComplexNDArray& a); friend OCTAVE_API NDArray imag (const ComplexNDArray& a); friend class ComplexNDArray; - NDArray squeeze (void) const { return MArray::squeeze (); } + NDArray squeeze () const { return MArray::squeeze (); } static OCTAVE_API void increment_index (Array& ra_idx, @@ -159,7 +159,7 @@ OCTAVE_API NDArray diag (octave_idx_type m, octave_idx_type n) const; - NDArray& changesign (void) + NDArray& changesign () { MArray::changesign (); return *this; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dRowVector.cc --- a/liboctave/array/dRowVector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dRowVector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -123,7 +123,7 @@ } ColumnVector -RowVector::transpose (void) const +RowVector::transpose () const { return MArray::transpose (); } @@ -204,7 +204,7 @@ // other operations double -RowVector::min (void) const +RowVector::min () const { octave_idx_type len = numel (); if (len == 0) @@ -220,7 +220,7 @@ } double -RowVector::max (void) const +RowVector::max () const { octave_idx_type len = numel (); if (len == 0) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dRowVector.h --- a/liboctave/array/dRowVector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dRowVector.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - RowVector (void) : MArray (dim_vector (1, 0)) { } + RowVector () : MArray (dim_vector (1, 0)) { } explicit RowVector (octave_idx_type n) : MArray (dim_vector (1, n)) { } @@ -71,7 +71,7 @@ OCTAVE_API RowVector append (const RowVector& a) const; - OCTAVE_API ColumnVector transpose (void) const; + OCTAVE_API ColumnVector transpose () const; friend OCTAVE_API RowVector real (const ComplexRowVector& a); friend OCTAVE_API RowVector imag (const ComplexRowVector& a); @@ -88,8 +88,8 @@ // other operations - OCTAVE_API double min (void) const; - OCTAVE_API double max (void) const; + OCTAVE_API double min () const; + OCTAVE_API double max () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dSparse.cc --- a/liboctave/array/dSparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dSparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -128,7 +128,7 @@ } bool -SparseMatrix::issymmetric (void) const +SparseMatrix::issymmetric () const { octave_idx_type nr = rows (); octave_idx_type nc = cols (); @@ -600,7 +600,7 @@ */ SparseMatrix -SparseMatrix::inverse (void) const +SparseMatrix::inverse () const { octave_idx_type info; double rcond; @@ -1009,7 +1009,7 @@ } DET -SparseMatrix::determinant (void) const +SparseMatrix::determinant () const { octave_idx_type info; double rcond; @@ -7216,7 +7216,7 @@ } bool -SparseMatrix::any_element_is_nan (void) const +SparseMatrix::any_element_is_nan () const { octave_idx_type nel = nnz (); @@ -7231,7 +7231,7 @@ } bool -SparseMatrix::any_element_is_inf_or_nan (void) const +SparseMatrix::any_element_is_inf_or_nan () const { octave_idx_type nel = nnz (); @@ -7246,7 +7246,7 @@ } bool -SparseMatrix::any_element_not_one_or_zero (void) const +SparseMatrix::any_element_not_one_or_zero () const { octave_idx_type nel = nnz (); @@ -7261,7 +7261,7 @@ } bool -SparseMatrix::all_elements_are_zero (void) const +SparseMatrix::all_elements_are_zero () const { octave_idx_type nel = nnz (); @@ -7273,7 +7273,7 @@ } bool -SparseMatrix::all_elements_are_int_or_inf_or_nan (void) const +SparseMatrix::all_elements_are_int_or_inf_or_nan () const { octave_idx_type nel = nnz (); @@ -7321,13 +7321,13 @@ } bool -SparseMatrix::too_large_for_float (void) const +SparseMatrix::too_large_for_float () const { return test_any (octave::too_large_for_float); } SparseBoolMatrix -SparseMatrix::operator ! (void) const +SparseMatrix::operator ! () const { if (any_element_is_nan ()) octave::err_nan_to_logical_conversion (); @@ -7423,7 +7423,7 @@ } SparseMatrix -SparseMatrix::abs (void) const +SparseMatrix::abs () const { octave_idx_type nz = nnz (); @@ -7442,7 +7442,7 @@ } Matrix -SparseMatrix::matrix_value (void) const +SparseMatrix::matrix_value () const { return Sparse::array_value (); } @@ -7477,7 +7477,7 @@ } SparseMatrix -SparseMatrix::squeeze (void) const +SparseMatrix::squeeze () const { return MSparse::squeeze (); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dSparse.h --- a/liboctave/array/dSparse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dSparse.h Mon Jan 30 18:36:03 2023 +0100 @@ -50,7 +50,7 @@ typedef void (*solve_singularity_handler) (double rcond); - SparseMatrix (void) : MSparse () { } + SparseMatrix () : MSparse () { } SparseMatrix (octave_idx_type r, octave_idx_type c) : MSparse (r, c) { } @@ -98,7 +98,7 @@ OCTAVE_API bool operator == (const SparseMatrix& a) const; OCTAVE_API bool operator != (const SparseMatrix& a) const; - OCTAVE_API bool issymmetric (void) const; + OCTAVE_API bool issymmetric () const; OCTAVE_API SparseMatrix max (int dim = -1) const; OCTAVE_API SparseMatrix max (Array& index, int dim = -1) const; @@ -121,11 +121,11 @@ friend OCTAVE_API SparseMatrix real (const SparseComplexMatrix& a); friend OCTAVE_API SparseMatrix imag (const SparseComplexMatrix& a); - SparseMatrix transpose (void) const + SparseMatrix transpose () const { return MSparse::transpose (); } - SparseMatrix hermitian (void) const { return transpose (); } + SparseMatrix hermitian () const { return transpose (); } // extract row or column i. @@ -143,7 +143,7 @@ const bool force = false, const bool calccond = true) const; public: - OCTAVE_API SparseMatrix inverse (void) const; + OCTAVE_API SparseMatrix inverse () const; OCTAVE_API SparseMatrix inverse (MatrixType& mattype) const; OCTAVE_API SparseMatrix inverse (MatrixType& mattype, octave_idx_type& info) const; @@ -151,7 +151,7 @@ inverse (MatrixType& mattype, octave_idx_type& info, double& rcond, bool force = false, bool calc_cond = true) const; - OCTAVE_API DET determinant (void) const; + OCTAVE_API DET determinant () const; OCTAVE_API DET determinant (octave_idx_type& info) const; OCTAVE_API DET determinant (octave_idx_type& info, double& rcond, bool calc_cond = true) const; @@ -420,15 +420,15 @@ // other operations OCTAVE_API bool any_element_is_negative (bool = false) const; - OCTAVE_API bool any_element_is_nan (void) const; - OCTAVE_API bool any_element_is_inf_or_nan (void) const; - OCTAVE_API bool any_element_not_one_or_zero (void) const; - OCTAVE_API bool all_elements_are_zero (void) const; - OCTAVE_API bool all_elements_are_int_or_inf_or_nan (void) const; + OCTAVE_API bool any_element_is_nan () const; + OCTAVE_API bool any_element_is_inf_or_nan () const; + OCTAVE_API bool any_element_not_one_or_zero () const; + OCTAVE_API bool all_elements_are_zero () const; + OCTAVE_API bool all_elements_are_int_or_inf_or_nan () const; OCTAVE_API bool all_integers (double& max_val, double& min_val) const; - OCTAVE_API bool too_large_for_float (void) const; + OCTAVE_API bool too_large_for_float () const; - OCTAVE_API SparseBoolMatrix operator ! (void) const; + OCTAVE_API SparseBoolMatrix operator ! () const; OCTAVE_API SparseBoolMatrix all (int dim = -1) const; OCTAVE_API SparseBoolMatrix any (int dim = -1) const; @@ -438,13 +438,13 @@ OCTAVE_API SparseMatrix prod (int dim = -1) const; OCTAVE_API SparseMatrix sum (int dim = -1) const; OCTAVE_API SparseMatrix sumsq (int dim = -1) const; - OCTAVE_API SparseMatrix abs (void) const; + OCTAVE_API SparseMatrix abs () const; OCTAVE_API SparseMatrix diag (octave_idx_type k = 0) const; - OCTAVE_API Matrix matrix_value (void) const; + OCTAVE_API Matrix matrix_value () const; - OCTAVE_API SparseMatrix squeeze (void) const; + OCTAVE_API SparseMatrix squeeze () const; OCTAVE_API SparseMatrix reshape (const dim_vector& new_dims) const; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dim-vector.cc --- a/liboctave/array/dim-vector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dim-vector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -41,13 +41,13 @@ // Currently 1 is subtracted to allow safe conversion of any 2D Array into // Sparse, but this offset may change in the future. octave_idx_type -dim_vector::dim_max (void) +dim_vector::dim_max () { return std::numeric_limits::max () - 1; } void -dim_vector::chop_all_singletons (void) +dim_vector::chop_all_singletons () { int j = 0; int nd = ndims (); @@ -83,7 +83,7 @@ } int -dim_vector::num_ones (void) const +dim_vector::num_ones () const { int retval = 0; @@ -95,7 +95,7 @@ } octave_idx_type -dim_vector::safe_numel (void) const +dim_vector::safe_numel () const { octave_idx_type idx_max = dim_max (); octave_idx_type n = 1; @@ -114,7 +114,7 @@ } dim_vector -dim_vector::squeeze (void) const +dim_vector::squeeze () const { dim_vector new_dims = *this; new_dims.chop_all_singletons (); @@ -263,7 +263,7 @@ } Array -dim_vector::as_array (void) const +dim_vector::as_array () const { octave_idx_type nd = ndims (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/dim-vector.h --- a/liboctave/array/dim-vector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/dim-vector.h Mon Jan 30 18:36:03 2023 +0100 @@ -161,13 +161,13 @@ octave_idx_type elem (int i) const { return xelem (i); } - void chop_trailing_singletons (void) + void chop_trailing_singletons () { while (m_num_dims > 2 && xelem(m_num_dims-1) == 1) m_num_dims--; } - OCTAVE_API void chop_all_singletons (void); + OCTAVE_API void chop_all_singletons (); private: @@ -179,9 +179,9 @@ public: - static OCTAVE_API octave_idx_type dim_max (void); + static OCTAVE_API octave_idx_type dim_max (); - explicit dim_vector (void) + explicit dim_vector () : m_num_dims (2), m_dims (new octave_idx_type [m_num_dims]) { std::fill_n (m_dims, m_num_dims, 0); @@ -239,7 +239,7 @@ return *this; } - ~dim_vector (void) + ~dim_vector () { // Because we define a move constructor and a move assignment // operator, m_dims may be a nullptr here. We should only need to @@ -254,7 +254,7 @@ //! elements in the dim_vector including trailing singletons. It is also //! the number of dimensions an Array with this dim_vector would have. - octave_idx_type ndims (void) const { return m_num_dims; } + octave_idx_type ndims () const { return m_num_dims; } //! Number of dimensions. //! Synonymous with ndims(). @@ -263,7 +263,7 @@ //! instead to avoid confusion. Array does not have length because of its //! odd definition as length of the longest dimension. - int length (void) const { return ndims (); } + int length () const { return ndims (); } octave_idx_type& operator () (int i) { return elem (i); } @@ -297,31 +297,31 @@ OCTAVE_API std::string str (char sep = 'x') const; - bool all_zero (void) const + bool all_zero () const { return std::all_of (m_dims, m_dims + ndims (), [] (octave_idx_type dim) { return dim == 0; }); } - bool empty_2d (void) const + bool empty_2d () const { return ndims () == 2 && (xelem (0) == 0 || xelem (1) == 0); } - bool zero_by_zero (void) const + bool zero_by_zero () const { return ndims () == 2 && xelem (0) == 0 && xelem (1) == 0; } - bool any_zero (void) const + bool any_zero () const { return std::any_of (m_dims, m_dims + ndims (), [] (octave_idx_type dim) { return dim == 0; }); } - OCTAVE_API int num_ones (void) const; + OCTAVE_API int num_ones () const; - bool all_ones (void) const + bool all_ones () const { return (num_ones () == ndims ()); } @@ -352,15 +352,15 @@ //! function that is iterating over an array using octave_idx_type //! indices. - OCTAVE_API octave_idx_type safe_numel (void) const; + OCTAVE_API octave_idx_type safe_numel () const; - bool any_neg (void) const + bool any_neg () const { return std::any_of (m_dims, m_dims + ndims (), [] (octave_idx_type dim) { return dim < 0; }); } - OCTAVE_API dim_vector squeeze (void) const; + OCTAVE_API dim_vector squeeze () const; //! This corresponds to cat(). OCTAVE_API bool concat (const dim_vector& dvb, int dim); @@ -376,7 +376,7 @@ OCTAVE_API dim_vector redim (int n) const; - dim_vector as_column (void) const + dim_vector as_column () const { if (ndims () == 2 && xelem (1) == 1) return *this; @@ -384,7 +384,7 @@ return dim_vector (numel (), 1); } - dim_vector as_row (void) const + dim_vector as_row () const { if (ndims () == 2 && xelem (0) == 1) return *this; @@ -392,12 +392,12 @@ return dim_vector (1, numel ()); } - bool isvector (void) const + bool isvector () const { return (ndims () == 2 && (xelem (0) == 1 || xelem (1) == 1)); } - bool is_nd_vector (void) const + bool is_nd_vector () const { int num_non_one = 0; @@ -485,7 +485,7 @@ //! Return cumulative dimensions. - dim_vector cumulative (void) const + dim_vector cumulative () const { int nd = ndims (); dim_vector retval = alloc (nd); @@ -513,7 +513,7 @@ friend OCTAVE_API bool operator == (const dim_vector& a, const dim_vector& b); - OCTAVE_API Array as_array (void) const; + OCTAVE_API Array as_array () const; }; inline bool diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCColVector.cc --- a/liboctave/array/fCColVector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCColVector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -198,19 +198,19 @@ } FloatComplexRowVector -FloatComplexColumnVector::hermitian (void) const +FloatComplexColumnVector::hermitian () const { return MArray::hermitian (std::conj); } FloatComplexRowVector -FloatComplexColumnVector::transpose (void) const +FloatComplexColumnVector::transpose () const { return MArray::transpose (); } FloatColumnVector -FloatComplexColumnVector::abs (void) const +FloatComplexColumnVector::abs () const { return do_mx_unary_map (*this); } @@ -421,7 +421,7 @@ // other operations FloatComplex -FloatComplexColumnVector::min (void) const +FloatComplexColumnVector::min () const { octave_idx_type len = numel (); if (len == 0) @@ -441,7 +441,7 @@ } FloatComplex -FloatComplexColumnVector::max (void) const +FloatComplexColumnVector::max () const { octave_idx_type len = numel (); if (len == 0) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCColVector.h --- a/liboctave/array/fCColVector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCColVector.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ public: - FloatComplexColumnVector (void) + FloatComplexColumnVector () : MArray (dim_vector (0, 1)) { } explicit FloatComplexColumnVector (octave_idx_type n) @@ -90,8 +90,8 @@ OCTAVE_API FloatComplexColumnVector stack (const FloatComplexColumnVector& a) const; - OCTAVE_API FloatComplexRowVector hermitian (void) const; - OCTAVE_API FloatComplexRowVector transpose (void) const; + OCTAVE_API FloatComplexRowVector hermitian () const; + OCTAVE_API FloatComplexRowVector transpose () const; friend OCTAVE_API FloatComplexColumnVector OCTAVE_API conj (const FloatComplexColumnVector& a); @@ -137,10 +137,10 @@ // other operations - OCTAVE_API FloatComplex min (void) const; - OCTAVE_API FloatComplex max (void) const; + OCTAVE_API FloatComplex min () const; + OCTAVE_API FloatComplex max () const; - OCTAVE_API FloatColumnVector abs (void) const; + OCTAVE_API FloatColumnVector abs () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCDiagMatrix.cc --- a/liboctave/array/fCDiagMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCDiagMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -209,7 +209,7 @@ } FloatDiagMatrix -FloatComplexDiagMatrix::abs (void) const +FloatComplexDiagMatrix::abs () const { return FloatDiagMatrix (extract_diag ().abs (), rows (), columns ()); } @@ -305,7 +305,7 @@ } FloatComplexDiagMatrix -FloatComplexDiagMatrix::inverse (void) const +FloatComplexDiagMatrix::inverse () const { octave_idx_type info; return inverse (info); @@ -358,7 +358,7 @@ } bool -FloatComplexDiagMatrix::all_elements_are_real (void) const +FloatComplexDiagMatrix::all_elements_are_real () const { return mx_inline_all_real (length (), data ()); } @@ -474,7 +474,7 @@ // other operations FloatComplexDET -FloatComplexDiagMatrix::determinant (void) const +FloatComplexDiagMatrix::determinant () const { FloatComplexDET det (1.0f); if (rows () != cols ()) @@ -488,7 +488,7 @@ } float -FloatComplexDiagMatrix::rcond (void) const +FloatComplexDiagMatrix::rcond () const { FloatColumnVector av = extract_diag (0).map (std::abs); float amx = av.max (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCDiagMatrix.h --- a/liboctave/array/fCDiagMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCDiagMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,13 +48,13 @@ typedef FloatComplex complex_elt_type; typedef FloatComplex element_type; - FloatComplexDiagMatrix (void) = default; + FloatComplexDiagMatrix () = default; FloatComplexDiagMatrix (const FloatComplexDiagMatrix& a) = default; FloatComplexDiagMatrix& operator = (const FloatComplexDiagMatrix& a) = default; - ~FloatComplexDiagMatrix (void) = default; + ~FloatComplexDiagMatrix () = default; FloatComplexDiagMatrix (octave_idx_type r, octave_idx_type c) @@ -105,11 +105,11 @@ OCTAVE_API FloatComplexDiagMatrix& fill (const FloatComplexRowVector& a, octave_idx_type beg); - FloatComplexDiagMatrix hermitian (void) const + FloatComplexDiagMatrix hermitian () const { return MDiagArray2::hermitian (std::conj); } - FloatComplexDiagMatrix transpose (void) const + FloatComplexDiagMatrix transpose () const { return MDiagArray2::transpose (); } - OCTAVE_API FloatDiagMatrix abs (void) const; + OCTAVE_API FloatDiagMatrix abs () const; friend OCTAVE_API FloatComplexDiagMatrix conj (const FloatComplexDiagMatrix& a); @@ -129,10 +129,10 @@ OCTAVE_API FloatComplexColumnVector column (char *s) const; OCTAVE_API FloatComplexDiagMatrix inverse (octave_idx_type& info) const; - OCTAVE_API FloatComplexDiagMatrix inverse (void) const; + OCTAVE_API FloatComplexDiagMatrix inverse () const; OCTAVE_API FloatComplexDiagMatrix pseudo_inverse (float tol = 0.0f) const; - OCTAVE_API bool all_elements_are_real (void) const; + OCTAVE_API bool all_elements_are_real () const; // diagonal matrix by diagonal matrix -> diagonal matrix operations @@ -144,8 +144,8 @@ FloatComplexColumnVector extract_diag (octave_idx_type k = 0) const { return MDiagArray2::extract_diag (k); } - OCTAVE_API FloatComplexDET determinant (void) const; - OCTAVE_API float rcond (void) const; + OCTAVE_API FloatComplexDET determinant () const; + OCTAVE_API float rcond () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCMatrix.cc --- a/liboctave/array/fCMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -171,7 +171,7 @@ } bool -FloatComplexMatrix::ishermitian (void) const +FloatComplexMatrix::ishermitian () const { octave_idx_type nr = rows (); octave_idx_type nc = cols (); @@ -737,7 +737,7 @@ } FloatComplexMatrix -FloatComplexMatrix::inverse (void) const +FloatComplexMatrix::inverse () const { octave_idx_type info; float rcon; @@ -1045,7 +1045,7 @@ #if defined (HAVE_FFTW) FloatComplexMatrix -FloatComplexMatrix::fourier (void) const +FloatComplexMatrix::fourier () const { std::size_t nr = rows (); std::size_t nc = cols (); @@ -1074,7 +1074,7 @@ } FloatComplexMatrix -FloatComplexMatrix::ifourier (void) const +FloatComplexMatrix::ifourier () const { std::size_t nr = rows (); std::size_t nc = cols (); @@ -1103,7 +1103,7 @@ } FloatComplexMatrix -FloatComplexMatrix::fourier2d (void) const +FloatComplexMatrix::fourier2d () const { dim_vector dv (rows (), cols ()); @@ -1117,7 +1117,7 @@ } FloatComplexMatrix -FloatComplexMatrix::ifourier2d (void) const +FloatComplexMatrix::ifourier2d () const { dim_vector dv (rows (), cols ()); @@ -1133,7 +1133,7 @@ #else FloatComplexMatrix -FloatComplexMatrix::fourier (void) const +FloatComplexMatrix::fourier () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -1142,7 +1142,7 @@ } FloatComplexMatrix -FloatComplexMatrix::ifourier (void) const +FloatComplexMatrix::ifourier () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -1151,7 +1151,7 @@ } FloatComplexMatrix -FloatComplexMatrix::fourier2d (void) const +FloatComplexMatrix::fourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -1160,7 +1160,7 @@ } FloatComplexMatrix -FloatComplexMatrix::ifourier2d (void) const +FloatComplexMatrix::ifourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -1171,7 +1171,7 @@ #endif FloatComplexDET -FloatComplexMatrix::determinant (void) const +FloatComplexMatrix::determinant () const { octave_idx_type info; float rcon; @@ -1350,7 +1350,7 @@ } float -FloatComplexMatrix::rcond (void) const +FloatComplexMatrix::rcond () const { MatrixType mattype (*this); return rcond (mattype); @@ -2849,7 +2849,7 @@ return FloatComplexNDArray::sumsq (dim); } -FloatMatrix FloatComplexMatrix::abs (void) const +FloatMatrix FloatComplexMatrix::abs () const { return FloatComplexNDArray::abs (); } @@ -2915,7 +2915,7 @@ } FloatComplexColumnVector -FloatComplexMatrix::row_min (void) const +FloatComplexMatrix::row_min () const { Array dummy_idx; return row_min (dummy_idx); @@ -2990,7 +2990,7 @@ } FloatComplexColumnVector -FloatComplexMatrix::row_max (void) const +FloatComplexMatrix::row_max () const { Array dummy_idx; return row_max (dummy_idx); @@ -3065,7 +3065,7 @@ } FloatComplexRowVector -FloatComplexMatrix::column_min (void) const +FloatComplexMatrix::column_min () const { Array dummy_idx; return column_min (dummy_idx); @@ -3140,7 +3140,7 @@ } FloatComplexRowVector -FloatComplexMatrix::column_max (void) const +FloatComplexMatrix::column_max () const { Array dummy_idx; return column_max (dummy_idx); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCMatrix.h --- a/liboctave/array/fCMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -60,13 +60,13 @@ typedef void (*solve_singularity_handler) (float rcon); - FloatComplexMatrix (void) = default; + FloatComplexMatrix () = default; FloatComplexMatrix (const FloatComplexMatrix& a) = default; FloatComplexMatrix& operator = (const FloatComplexMatrix& a) = default; - ~FloatComplexMatrix (void) = default; + ~FloatComplexMatrix () = default; FloatComplexMatrix (octave_idx_type r, octave_idx_type c) : FloatComplexNDArray (dim_vector (r, c)) { } @@ -120,7 +120,7 @@ OCTAVE_API bool operator == (const FloatComplexMatrix& a) const; OCTAVE_API bool operator != (const FloatComplexMatrix& a) const; - OCTAVE_API bool ishermitian (void) const; + OCTAVE_API bool ishermitian () const; // destructive insert/delete/reorder operations @@ -175,9 +175,9 @@ OCTAVE_API FloatComplexMatrix stack (const FloatComplexColumnVector& a) const; OCTAVE_API FloatComplexMatrix stack (const FloatComplexDiagMatrix& a) const; - FloatComplexMatrix hermitian (void) const + FloatComplexMatrix hermitian () const { return MArray::hermitian (std::conj); } - FloatComplexMatrix transpose (void) const + FloatComplexMatrix transpose () const { return MArray::transpose (); } friend OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a); @@ -212,7 +212,7 @@ float& rcon, bool force, bool calc_cond) const; public: - OCTAVE_API FloatComplexMatrix inverse (void) const; + OCTAVE_API FloatComplexMatrix inverse () const; OCTAVE_API FloatComplexMatrix inverse (octave_idx_type& info) const; OCTAVE_API FloatComplexMatrix inverse (octave_idx_type& info, float& rcon, bool force = false, @@ -227,13 +227,13 @@ OCTAVE_API FloatComplexMatrix pseudo_inverse (float tol = 0.0) const; - OCTAVE_API FloatComplexMatrix fourier (void) const; - OCTAVE_API FloatComplexMatrix ifourier (void) const; + OCTAVE_API FloatComplexMatrix fourier () const; + OCTAVE_API FloatComplexMatrix ifourier () const; - OCTAVE_API FloatComplexMatrix fourier2d (void) const; - OCTAVE_API FloatComplexMatrix ifourier2d (void) const; + OCTAVE_API FloatComplexMatrix fourier2d () const; + OCTAVE_API FloatComplexMatrix ifourier2d () const; - OCTAVE_API FloatComplexDET determinant (void) const; + OCTAVE_API FloatComplexDET determinant () const; OCTAVE_API FloatComplexDET determinant (octave_idx_type& info) const; OCTAVE_API FloatComplexDET determinant (octave_idx_type& info, float& rcon, @@ -242,7 +242,7 @@ determinant (MatrixType& mattype, octave_idx_type& info, float& rcon, bool calc_cond = true) const; - OCTAVE_API float rcond (void) const; + OCTAVE_API float rcond () const; OCTAVE_API float rcond (MatrixType& mattype) const; private: @@ -426,7 +426,7 @@ // unary operations - OCTAVE_API boolMatrix operator ! (void) const; + OCTAVE_API boolMatrix operator ! () const; // other operations @@ -438,7 +438,7 @@ OCTAVE_API FloatComplexMatrix prod (int dim = -1) const; OCTAVE_API FloatComplexMatrix sum (int dim = -1) const; OCTAVE_API FloatComplexMatrix sumsq (int dim = -1) const; - OCTAVE_API FloatMatrix abs (void) const; + OCTAVE_API FloatMatrix abs () const; OCTAVE_API FloatComplexMatrix diag (octave_idx_type k = 0) const; @@ -448,16 +448,16 @@ OCTAVE_API bool row_is_real_only (octave_idx_type) const; OCTAVE_API bool column_is_real_only (octave_idx_type) const; - OCTAVE_API FloatComplexColumnVector row_min (void) const; - OCTAVE_API FloatComplexColumnVector row_max (void) const; + OCTAVE_API FloatComplexColumnVector row_min () const; + OCTAVE_API FloatComplexColumnVector row_max () const; OCTAVE_API FloatComplexColumnVector row_min (Array& index) const; OCTAVE_API FloatComplexColumnVector row_max (Array& index) const; - OCTAVE_API FloatComplexRowVector column_min (void) const; - OCTAVE_API FloatComplexRowVector column_max (void) const; + OCTAVE_API FloatComplexRowVector column_min () const; + OCTAVE_API FloatComplexRowVector column_max () const; OCTAVE_API FloatComplexRowVector column_min (Array& index) const; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCNDArray.cc --- a/liboctave/array/fCNDArray.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCNDArray.cc Mon Jan 30 18:36:03 2023 +0100 @@ -117,7 +117,7 @@ } FloatComplexNDArray -FloatComplexNDArray::fourier2d (void) const +FloatComplexNDArray::fourier2d () const { dim_vector dv = dims (); if (dv.ndims () < 2) @@ -137,7 +137,7 @@ } FloatComplexNDArray -FloatComplexNDArray::ifourier2d (void) const +FloatComplexNDArray::ifourier2d () const { dim_vector dv = dims (); if (dv.ndims () < 2) @@ -157,7 +157,7 @@ } FloatComplexNDArray -FloatComplexNDArray::fourierNd (void) const +FloatComplexNDArray::fourierNd () const { dim_vector dv = dims (); int rank = dv.ndims (); @@ -172,7 +172,7 @@ } FloatComplexNDArray -FloatComplexNDArray::ifourierNd (void) const +FloatComplexNDArray::ifourierNd () const { dim_vector dv = dims (); int rank = dv.ndims (); @@ -211,7 +211,7 @@ } FloatComplexNDArray -FloatComplexNDArray::fourier2d (void) const +FloatComplexNDArray::fourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -220,7 +220,7 @@ } FloatComplexNDArray -FloatComplexNDArray::ifourier2d (void) const +FloatComplexNDArray::ifourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -229,7 +229,7 @@ } FloatComplexNDArray -FloatComplexNDArray::fourierNd (void) const +FloatComplexNDArray::fourierNd () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -238,7 +238,7 @@ } FloatComplexNDArray -FloatComplexNDArray::ifourierNd (void) const +FloatComplexNDArray::ifourierNd () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -251,7 +251,7 @@ // unary operations boolNDArray -FloatComplexNDArray::operator ! (void) const +FloatComplexNDArray::operator ! () const { if (any_element_is_nan ()) octave::err_nan_to_logical_conversion (); @@ -262,13 +262,13 @@ // FIXME: this is not quite the right thing. bool -FloatComplexNDArray::any_element_is_nan (void) const +FloatComplexNDArray::any_element_is_nan () const { return do_mx_check (*this, mx_inline_any_nan); } bool -FloatComplexNDArray::any_element_is_inf_or_nan (void) const +FloatComplexNDArray::any_element_is_inf_or_nan () const { return ! do_mx_check (*this, mx_inline_all_finite); } @@ -276,7 +276,7 @@ // Return true if no elements have imaginary components. bool -FloatComplexNDArray::all_elements_are_real (void) const +FloatComplexNDArray::all_elements_are_real () const { return do_mx_check (*this, mx_inline_all_real); } @@ -337,7 +337,7 @@ } bool -FloatComplexNDArray::too_large_for_float (void) const +FloatComplexNDArray::too_large_for_float () const { return false; } @@ -487,25 +487,25 @@ } FloatNDArray -FloatComplexNDArray::abs (void) const +FloatComplexNDArray::abs () const { return do_mx_unary_map (*this); } boolNDArray -FloatComplexNDArray::isnan (void) const +FloatComplexNDArray::isnan () const { return do_mx_unary_map (*this); } boolNDArray -FloatComplexNDArray::isinf (void) const +FloatComplexNDArray::isinf () const { return do_mx_unary_map (*this); } boolNDArray -FloatComplexNDArray::isfinite (void) const +FloatComplexNDArray::isfinite () const { return do_mx_unary_map (*this); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCNDArray.h --- a/liboctave/array/fCNDArray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCNDArray.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ { public: - FloatComplexNDArray (void) : MArray () { } + FloatComplexNDArray () : MArray () { } FloatComplexNDArray (const dim_vector& dv) : MArray (dv) { } @@ -65,15 +65,15 @@ // unary operations - OCTAVE_API boolNDArray operator ! (void) const; + OCTAVE_API boolNDArray operator ! () const; // FIXME: this is not quite the right thing. - OCTAVE_API bool any_element_is_nan (void) const; - OCTAVE_API bool any_element_is_inf_or_nan (void) const; - OCTAVE_API bool all_elements_are_real (void) const; + OCTAVE_API bool any_element_is_nan () const; + OCTAVE_API bool any_element_is_inf_or_nan () const; + OCTAVE_API bool all_elements_are_real () const; OCTAVE_API bool all_integers (float& max_val, float& min_val) const; - OCTAVE_API bool too_large_for_float (void) const; + OCTAVE_API bool too_large_for_float () const; OCTAVE_API boolNDArray all (int dim = -1) const; OCTAVE_API boolNDArray any (int dim = -1) const; @@ -114,23 +114,23 @@ OCTAVE_API FloatComplexNDArray& insert (const FloatComplexNDArray& a, const Array& ra_idx); - OCTAVE_API FloatNDArray abs (void) const; - OCTAVE_API boolNDArray isnan (void) const; - OCTAVE_API boolNDArray isinf (void) const; - OCTAVE_API boolNDArray isfinite (void) const; + OCTAVE_API FloatNDArray abs () const; + OCTAVE_API boolNDArray isnan () const; + OCTAVE_API boolNDArray isinf () const; + OCTAVE_API boolNDArray isfinite () const; friend OCTAVE_API FloatComplexNDArray conj (const FloatComplexNDArray& a); OCTAVE_API FloatComplexNDArray fourier (int dim = 1) const; OCTAVE_API FloatComplexNDArray ifourier (int dim = 1) const; - OCTAVE_API FloatComplexNDArray fourier2d (void) const; - OCTAVE_API FloatComplexNDArray ifourier2d (void) const; + OCTAVE_API FloatComplexNDArray fourier2d () const; + OCTAVE_API FloatComplexNDArray ifourier2d () const; - OCTAVE_API FloatComplexNDArray fourierNd (void) const; - OCTAVE_API FloatComplexNDArray ifourierNd (void) const; + OCTAVE_API FloatComplexNDArray fourierNd () const; + OCTAVE_API FloatComplexNDArray ifourierNd () const; - FloatComplexNDArray squeeze (void) const + FloatComplexNDArray squeeze () const { return MArray::squeeze (); } static OCTAVE_API void @@ -147,7 +147,7 @@ friend OCTAVE_API std::istream& operator >> (std::istream& is, FloatComplexNDArray& a); - // bool all_elements_are_real (void) const; + // bool all_elements_are_real () const; // bool all_integers (float& max_val, float& min_val) const; OCTAVE_API FloatComplexNDArray diag (octave_idx_type k = 0) const; @@ -155,7 +155,7 @@ OCTAVE_API FloatComplexNDArray diag (octave_idx_type m, octave_idx_type n) const; - FloatComplexNDArray& changesign (void) + FloatComplexNDArray& changesign () { MArray::changesign (); return *this; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCRowVector.cc --- a/liboctave/array/fCRowVector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCRowVector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -194,13 +194,13 @@ } FloatComplexColumnVector -FloatComplexRowVector::hermitian (void) const +FloatComplexRowVector::hermitian () const { return MArray::hermitian (std::conj); } FloatComplexColumnVector -FloatComplexRowVector::transpose (void) const +FloatComplexRowVector::transpose () const { return MArray::transpose (); } @@ -324,7 +324,7 @@ // other operations FloatComplex -FloatComplexRowVector::min (void) const +FloatComplexRowVector::min () const { octave_idx_type len = numel (); if (len == 0) @@ -344,7 +344,7 @@ } FloatComplex -FloatComplexRowVector::max (void) const +FloatComplexRowVector::max () const { octave_idx_type len = numel (); if (len == 0) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fCRowVector.h --- a/liboctave/array/fCRowVector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fCRowVector.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ public: - FloatComplexRowVector (void) + FloatComplexRowVector () : MArray (dim_vector (1, 0)) { } explicit FloatComplexRowVector (octave_idx_type n) @@ -91,8 +91,8 @@ OCTAVE_API FloatComplexRowVector append (const FloatComplexRowVector& a) const; - OCTAVE_API FloatComplexColumnVector hermitian (void) const; - OCTAVE_API FloatComplexColumnVector transpose (void) const; + OCTAVE_API FloatComplexColumnVector hermitian () const; + OCTAVE_API FloatComplexColumnVector transpose () const; friend OCTAVE_API FloatComplexRowVector conj (const FloatComplexRowVector& a); @@ -120,8 +120,8 @@ // other operations - OCTAVE_API FloatComplex min (void) const; - OCTAVE_API FloatComplex max (void) const; + OCTAVE_API FloatComplex min () const; + OCTAVE_API FloatComplex max () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fColVector.cc --- a/liboctave/array/fColVector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fColVector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -122,13 +122,13 @@ } FloatRowVector -FloatColumnVector::transpose (void) const +FloatColumnVector::transpose () const { return MArray::transpose (); } FloatColumnVector -FloatColumnVector::abs (void) const +FloatColumnVector::abs () const { return do_mx_unary_map (*this); } @@ -242,7 +242,7 @@ // other operations float -FloatColumnVector::min (void) const +FloatColumnVector::min () const { octave_idx_type len = numel (); if (len == 0) @@ -258,7 +258,7 @@ } float -FloatColumnVector::max (void) const +FloatColumnVector::max () const { octave_idx_type len = numel (); if (len == 0) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fColVector.h --- a/liboctave/array/fColVector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fColVector.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - FloatColumnVector (void) : MArray (dim_vector (0, 1)) { } + FloatColumnVector () : MArray (dim_vector (0, 1)) { } explicit FloatColumnVector (octave_idx_type n) : MArray (dim_vector (n, 1)) { } @@ -76,7 +76,7 @@ OCTAVE_API FloatColumnVector stack (const FloatColumnVector& a) const; - OCTAVE_API FloatRowVector transpose (void) const; + OCTAVE_API FloatRowVector transpose () const; friend OCTAVE_API FloatColumnVector real (const FloatComplexColumnVector& a); friend OCTAVE_API FloatColumnVector imag (const FloatComplexColumnVector& a); @@ -101,10 +101,10 @@ // other operations - OCTAVE_API float min (void) const; - OCTAVE_API float max (void) const; + OCTAVE_API float min () const; + OCTAVE_API float max () const; - OCTAVE_API FloatColumnVector abs (void) const; + OCTAVE_API FloatColumnVector abs () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fDiagMatrix.cc --- a/liboctave/array/fDiagMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fDiagMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -125,7 +125,7 @@ } FloatDiagMatrix -FloatDiagMatrix::abs (void) const +FloatDiagMatrix::abs () const { return FloatDiagMatrix (extract_diag ().abs (), rows (), columns ()); } @@ -224,7 +224,7 @@ } FloatDiagMatrix -FloatDiagMatrix::inverse (void) const +FloatDiagMatrix::inverse () const { octave_idx_type info; return inverse (info); @@ -306,7 +306,7 @@ // other operations FloatDET -FloatDiagMatrix::determinant (void) const +FloatDiagMatrix::determinant () const { FloatDET det (1.0f); if (rows () != cols ()) @@ -320,7 +320,7 @@ } float -FloatDiagMatrix::rcond (void) const +FloatDiagMatrix::rcond () const { FloatColumnVector av = extract_diag (0).map (fabsf); float amx = av.max (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fDiagMatrix.h --- a/liboctave/array/fDiagMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fDiagMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,13 +42,13 @@ typedef FloatMatrix full_matrix_type; - FloatDiagMatrix (void) = default; + FloatDiagMatrix () = default; FloatDiagMatrix (const FloatDiagMatrix& a) = default; FloatDiagMatrix& operator = (const FloatDiagMatrix& a) = default; - ~FloatDiagMatrix (void) = default; + ~FloatDiagMatrix () = default; FloatDiagMatrix (octave_idx_type r, octave_idx_type c) : MDiagArray2 (r, c) { } @@ -79,10 +79,10 @@ OCTAVE_API FloatDiagMatrix& fill (const FloatRowVector& a, octave_idx_type beg); - FloatDiagMatrix transpose (void) const + FloatDiagMatrix transpose () const { return MDiagArray2::transpose (); } - OCTAVE_API FloatDiagMatrix abs (void) const; + OCTAVE_API FloatDiagMatrix abs () const; friend OCTAVE_API FloatDiagMatrix real (const FloatComplexDiagMatrix& a); friend OCTAVE_API FloatDiagMatrix imag (const FloatComplexDiagMatrix& a); @@ -101,7 +101,7 @@ OCTAVE_API FloatColumnVector column (octave_idx_type i) const; OCTAVE_API FloatColumnVector column (char *s) const; - OCTAVE_API FloatDiagMatrix inverse (void) const; + OCTAVE_API FloatDiagMatrix inverse () const; OCTAVE_API FloatDiagMatrix inverse (octave_idx_type& info) const; OCTAVE_API FloatDiagMatrix pseudo_inverse (float tol = 0.0f) const; @@ -110,8 +110,8 @@ FloatColumnVector extract_diag (octave_idx_type k = 0) const { return MDiagArray2::extract_diag (k); } - OCTAVE_API FloatDET determinant (void) const; - OCTAVE_API float rcond (void) const; + OCTAVE_API FloatDET determinant () const; + OCTAVE_API float rcond () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fMatrix.cc --- a/liboctave/array/fMatrix.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fMatrix.cc Mon Jan 30 18:36:03 2023 +0100 @@ -135,7 +135,7 @@ } bool -FloatMatrix::issymmetric (void) const +FloatMatrix::issymmetric () const { if (issquare () && rows () > 0) { @@ -454,7 +454,7 @@ } FloatMatrix -FloatMatrix::inverse (void) const +FloatMatrix::inverse () const { octave_idx_type info; float rcon; @@ -737,7 +737,7 @@ #if defined (HAVE_FFTW) FloatComplexMatrix -FloatMatrix::fourier (void) const +FloatMatrix::fourier () const { std::size_t nr = rows (); std::size_t nc = cols (); @@ -766,7 +766,7 @@ } FloatComplexMatrix -FloatMatrix::ifourier (void) const +FloatMatrix::ifourier () const { std::size_t nr = rows (); std::size_t nc = cols (); @@ -796,7 +796,7 @@ } FloatComplexMatrix -FloatMatrix::fourier2d (void) const +FloatMatrix::fourier2d () const { dim_vector dv (rows (), cols ()); @@ -808,7 +808,7 @@ } FloatComplexMatrix -FloatMatrix::ifourier2d (void) const +FloatMatrix::ifourier2d () const { dim_vector dv (rows (), cols ()); @@ -823,7 +823,7 @@ #else FloatComplexMatrix -FloatMatrix::fourier (void) const +FloatMatrix::fourier () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -832,7 +832,7 @@ } FloatComplexMatrix -FloatMatrix::ifourier (void) const +FloatMatrix::ifourier () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -841,7 +841,7 @@ } FloatComplexMatrix -FloatMatrix::fourier2d (void) const +FloatMatrix::fourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -850,7 +850,7 @@ } FloatComplexMatrix -FloatMatrix::ifourier2d (void) const +FloatMatrix::ifourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -861,7 +861,7 @@ #endif FloatDET -FloatMatrix::determinant (void) const +FloatMatrix::determinant () const { octave_idx_type info; float rcon; @@ -1035,7 +1035,7 @@ } float -FloatMatrix::rcond (void) const +FloatMatrix::rcond () const { MatrixType mattype (*this); return rcond (mattype); @@ -2408,7 +2408,7 @@ } FloatMatrix -FloatMatrix::abs (void) const +FloatMatrix::abs () const { return FloatNDArray::abs (); } @@ -2436,7 +2436,7 @@ } FloatColumnVector -FloatMatrix::row_min (void) const +FloatMatrix::row_min () const { Array dummy_idx; return row_min (dummy_idx); @@ -2491,7 +2491,7 @@ } FloatColumnVector -FloatMatrix::row_max (void) const +FloatMatrix::row_max () const { Array dummy_idx; return row_max (dummy_idx); @@ -2546,7 +2546,7 @@ } FloatRowVector -FloatMatrix::column_min (void) const +FloatMatrix::column_min () const { Array dummy_idx; return column_min (dummy_idx); @@ -2601,7 +2601,7 @@ } FloatRowVector -FloatMatrix::column_max (void) const +FloatMatrix::column_max () const { Array dummy_idx; return column_max (dummy_idx); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fMatrix.h --- a/liboctave/array/fMatrix.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fMatrix.h Mon Jan 30 18:36:03 2023 +0100 @@ -59,13 +59,13 @@ typedef void (*solve_singularity_handler) (float rcon); - FloatMatrix (void) = default; + FloatMatrix () = default; FloatMatrix (const FloatMatrix& a) = default; FloatMatrix& operator = (const FloatMatrix& a) = default; - ~FloatMatrix (void) = default; + ~FloatMatrix () = default; FloatMatrix (octave_idx_type r, octave_idx_type c) : FloatNDArray (dim_vector (r, c)) { } @@ -103,7 +103,7 @@ OCTAVE_API bool operator == (const FloatMatrix& a) const; OCTAVE_API bool operator != (const FloatMatrix& a) const; - OCTAVE_API bool issymmetric (void) const; + OCTAVE_API bool issymmetric () const; // destructive insert/delete/reorder operations @@ -136,8 +136,8 @@ friend class FloatComplexMatrix; - FloatMatrix hermitian (void) const { return MArray::transpose (); } - FloatMatrix transpose (void) const { return MArray::transpose (); } + FloatMatrix hermitian () const { return MArray::transpose (); } + FloatMatrix transpose () const { return MArray::transpose (); } // resize is the destructive equivalent for this one @@ -168,7 +168,7 @@ float& rcon, bool force, bool calc_cond) const; public: - OCTAVE_API FloatMatrix inverse (void) const; + OCTAVE_API FloatMatrix inverse () const; OCTAVE_API FloatMatrix inverse (octave_idx_type& info) const; OCTAVE_API FloatMatrix inverse (octave_idx_type& info, float& rcon, bool force = false, @@ -183,13 +183,13 @@ OCTAVE_API FloatMatrix pseudo_inverse (float tol = 0.0) const; - OCTAVE_API FloatComplexMatrix fourier (void) const; - OCTAVE_API FloatComplexMatrix ifourier (void) const; + OCTAVE_API FloatComplexMatrix fourier () const; + OCTAVE_API FloatComplexMatrix ifourier () const; - OCTAVE_API FloatComplexMatrix fourier2d (void) const; - OCTAVE_API FloatComplexMatrix ifourier2d (void) const; + OCTAVE_API FloatComplexMatrix fourier2d () const; + OCTAVE_API FloatComplexMatrix ifourier2d () const; - OCTAVE_API FloatDET determinant (void) const; + OCTAVE_API FloatDET determinant () const; OCTAVE_API FloatDET determinant (octave_idx_type& info) const; OCTAVE_API FloatDET determinant (octave_idx_type& info, float& rcon, @@ -198,7 +198,7 @@ determinant (MatrixType& mattype, octave_idx_type& info, float& rcon, bool calc_cond = true) const; - OCTAVE_API float rcond (void) const; + OCTAVE_API float rcond () const; OCTAVE_API float rcond (MatrixType& mattype) const; private: @@ -374,20 +374,20 @@ OCTAVE_API FloatMatrix prod (int dim = -1) const; OCTAVE_API FloatMatrix sum (int dim = -1) const; OCTAVE_API FloatMatrix sumsq (int dim = -1) const; - OCTAVE_API FloatMatrix abs (void) const; + OCTAVE_API FloatMatrix abs () const; OCTAVE_API FloatMatrix diag (octave_idx_type k = 0) const; OCTAVE_API FloatDiagMatrix diag (octave_idx_type m, octave_idx_type n) const; - OCTAVE_API FloatColumnVector row_min (void) const; - OCTAVE_API FloatColumnVector row_max (void) const; + OCTAVE_API FloatColumnVector row_min () const; + OCTAVE_API FloatColumnVector row_max () const; OCTAVE_API FloatColumnVector row_min (Array& index) const; OCTAVE_API FloatColumnVector row_max (Array& index) const; - OCTAVE_API FloatRowVector column_min (void) const; - OCTAVE_API FloatRowVector column_max (void) const; + OCTAVE_API FloatRowVector column_min () const; + OCTAVE_API FloatRowVector column_max () const; OCTAVE_API FloatRowVector column_min (Array& index) const; OCTAVE_API FloatRowVector column_max (Array& index) const; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fNDArray.cc --- a/liboctave/array/fNDArray.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fNDArray.cc Mon Jan 30 18:36:03 2023 +0100 @@ -116,7 +116,7 @@ } FloatComplexNDArray -FloatNDArray::fourier2d (void) const +FloatNDArray::fourier2d () const { dim_vector dv = dims (); if (dv.ndims () < 2) @@ -136,7 +136,7 @@ } FloatComplexNDArray -FloatNDArray::ifourier2d (void) const +FloatNDArray::ifourier2d () const { dim_vector dv = dims (); if (dv.ndims () < 2) @@ -155,7 +155,7 @@ } FloatComplexNDArray -FloatNDArray::fourierNd (void) const +FloatNDArray::fourierNd () const { dim_vector dv = dims (); int rank = dv.ndims (); @@ -170,7 +170,7 @@ } FloatComplexNDArray -FloatNDArray::ifourierNd (void) const +FloatNDArray::ifourierNd () const { dim_vector dv = dims (); int rank = dv.ndims (); @@ -209,7 +209,7 @@ } FloatComplexNDArray -FloatNDArray::fourier2d (void) const +FloatNDArray::fourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -218,7 +218,7 @@ } FloatComplexNDArray -FloatNDArray::ifourier2d (void) const +FloatNDArray::ifourier2d () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -227,7 +227,7 @@ } FloatComplexNDArray -FloatNDArray::fourierNd (void) const +FloatNDArray::fourierNd () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -236,7 +236,7 @@ } FloatComplexNDArray -FloatNDArray::ifourierNd (void) const +FloatNDArray::ifourierNd () const { (*current_liboctave_error_handler) ("support for FFTW was unavailable or disabled when liboctave was built"); @@ -249,7 +249,7 @@ // unary operations boolNDArray -FloatNDArray::operator ! (void) const +FloatNDArray::operator ! () const { if (any_element_is_nan ()) octave::err_nan_to_logical_conversion (); @@ -272,31 +272,31 @@ } bool -FloatNDArray::any_element_is_nan (void) const +FloatNDArray::any_element_is_nan () const { return do_mx_check (*this, mx_inline_any_nan); } bool -FloatNDArray::any_element_is_inf_or_nan (void) const +FloatNDArray::any_element_is_inf_or_nan () const { return ! do_mx_check (*this, mx_inline_all_finite); } bool -FloatNDArray::any_element_not_one_or_zero (void) const +FloatNDArray::any_element_not_one_or_zero () const { return ! test_all (octave::is_one_or_zero); } bool -FloatNDArray::all_elements_are_zero (void) const +FloatNDArray::all_elements_are_zero () const { return test_all (octave::is_zero); } bool -FloatNDArray::all_elements_are_int_or_inf_or_nan (void) const +FloatNDArray::all_elements_are_int_or_inf_or_nan () const { return test_all (octave::is_int_or_inf_or_nan); } @@ -335,13 +335,13 @@ } bool -FloatNDArray::all_integers (void) const +FloatNDArray::all_integers () const { return test_all (octave::math::isinteger); } bool -FloatNDArray::too_large_for_float (void) const +FloatNDArray::too_large_for_float () const { return false; } @@ -535,25 +535,25 @@ } FloatNDArray -FloatNDArray::abs (void) const +FloatNDArray::abs () const { return do_mx_unary_map (*this); } boolNDArray -FloatNDArray::isnan (void) const +FloatNDArray::isnan () const { return do_mx_unary_map (*this); } boolNDArray -FloatNDArray::isinf (void) const +FloatNDArray::isinf () const { return do_mx_unary_map (*this); } boolNDArray -FloatNDArray::isfinite (void) const +FloatNDArray::isfinite () const { return do_mx_unary_map (*this); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fNDArray.h --- a/liboctave/array/fNDArray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fNDArray.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ { public: - FloatNDArray (void) : MArray () { } + FloatNDArray () : MArray () { } FloatNDArray (const dim_vector& dv) : MArray (dv) { } @@ -68,18 +68,18 @@ // unary operations - OCTAVE_API boolNDArray operator ! (void) const; + OCTAVE_API boolNDArray operator ! () const; OCTAVE_API bool any_element_is_negative (bool = false) const; OCTAVE_API bool any_element_is_positive (bool = false) const; - OCTAVE_API bool any_element_is_nan (void) const; - OCTAVE_API bool any_element_is_inf_or_nan (void) const; - OCTAVE_API bool any_element_not_one_or_zero (void) const; - OCTAVE_API bool all_elements_are_zero (void) const; - OCTAVE_API bool all_elements_are_int_or_inf_or_nan (void) const; + OCTAVE_API bool any_element_is_nan () const; + OCTAVE_API bool any_element_is_inf_or_nan () const; + OCTAVE_API bool any_element_not_one_or_zero () const; + OCTAVE_API bool all_elements_are_zero () const; + OCTAVE_API bool all_elements_are_int_or_inf_or_nan () const; OCTAVE_API bool all_integers (float& max_val, float& min_val) const; - OCTAVE_API bool all_integers (void) const; - OCTAVE_API bool too_large_for_float (void) const; + OCTAVE_API bool all_integers () const; + OCTAVE_API bool too_large_for_float () const; // FIXME: this is not quite the right thing. @@ -121,26 +121,26 @@ OCTAVE_API FloatNDArray& insert (const FloatNDArray& a, const Array& ra_idx); - OCTAVE_API FloatNDArray abs (void) const; - OCTAVE_API boolNDArray isnan (void) const; - OCTAVE_API boolNDArray isinf (void) const; - OCTAVE_API boolNDArray isfinite (void) const; + OCTAVE_API FloatNDArray abs () const; + OCTAVE_API boolNDArray isnan () const; + OCTAVE_API boolNDArray isinf () const; + OCTAVE_API boolNDArray isfinite () const; OCTAVE_API FloatComplexNDArray fourier (int dim = 1) const; OCTAVE_API FloatComplexNDArray ifourier (int dim = 1) const; - OCTAVE_API FloatComplexNDArray fourier2d (void) const; - OCTAVE_API FloatComplexNDArray ifourier2d (void) const; + OCTAVE_API FloatComplexNDArray fourier2d () const; + OCTAVE_API FloatComplexNDArray ifourier2d () const; - OCTAVE_API FloatComplexNDArray fourierNd (void) const; - OCTAVE_API FloatComplexNDArray ifourierNd (void) const; + OCTAVE_API FloatComplexNDArray fourierNd () const; + OCTAVE_API FloatComplexNDArray ifourierNd () const; friend OCTAVE_API FloatNDArray real (const FloatComplexNDArray& a); friend OCTAVE_API FloatNDArray imag (const FloatComplexNDArray& a); friend class FloatComplexNDArray; - FloatNDArray squeeze (void) const { return MArray::squeeze (); } + FloatNDArray squeeze () const { return MArray::squeeze (); } static OCTAVE_API void increment_index (Array& ra_idx, @@ -160,7 +160,7 @@ OCTAVE_API FloatNDArray diag (octave_idx_type m, octave_idx_type n) const; - FloatNDArray& changesign (void) + FloatNDArray& changesign () { MArray::changesign (); return *this; diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fRowVector.cc --- a/liboctave/array/fRowVector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fRowVector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -123,7 +123,7 @@ } FloatColumnVector -FloatRowVector::transpose (void) const +FloatRowVector::transpose () const { return MArray::transpose (); } @@ -204,7 +204,7 @@ // other operations float -FloatRowVector::min (void) const +FloatRowVector::min () const { octave_idx_type len = numel (); if (len == 0) @@ -220,7 +220,7 @@ } float -FloatRowVector::max (void) const +FloatRowVector::max () const { octave_idx_type len = numel (); if (len == 0) diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/fRowVector.h --- a/liboctave/array/fRowVector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/fRowVector.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - FloatRowVector (void) : MArray (dim_vector (1, 0)) { } + FloatRowVector () : MArray (dim_vector (1, 0)) { } explicit FloatRowVector (octave_idx_type n) : MArray (dim_vector (1, n)) { } @@ -74,7 +74,7 @@ OCTAVE_API FloatRowVector append (const FloatRowVector& a) const; - OCTAVE_API FloatColumnVector transpose (void) const; + OCTAVE_API FloatColumnVector transpose () const; friend OCTAVE_API FloatRowVector real (const FloatComplexRowVector& a); friend OCTAVE_API FloatRowVector imag (const FloatComplexRowVector& a); @@ -94,8 +94,8 @@ // other operations - OCTAVE_API float min (void) const; - OCTAVE_API float max (void) const; + OCTAVE_API float min () const; + OCTAVE_API float max () const; // i/o diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/idx-vector.cc --- a/liboctave/array/idx-vector.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/idx-vector.cc Mon Jan 30 18:36:03 2023 +0100 @@ -44,24 +44,24 @@ OCTAVE_BEGIN_NAMESPACE(octave) -OCTAVE_NORETURN static void err_invalid_range (void) +OCTAVE_NORETURN static void err_invalid_range () { (*current_liboctave_error_handler) ("invalid range used as index"); } -OCTAVE_NORETURN static void err_index_out_of_range (void) +OCTAVE_NORETURN static void err_index_out_of_range () { (*current_liboctave_error_handler) ("internal error: idx_vector index out of range"); } -idx_vector::idx_vector_rep *idx_vector::nil_rep (void) +idx_vector::idx_vector_rep *idx_vector::nil_rep () { static idx_vector_rep ivr; return &ivr; } -Array idx_vector::idx_base_rep::as_array (void) +Array idx_vector::idx_base_rep::as_array () { (*current_liboctave_error_handler) ("internal error: as_array not allowed for this index class"); @@ -191,13 +191,13 @@ return os; } -range idx_vector::idx_range_rep::unconvert (void) const +range idx_vector::idx_range_rep::unconvert () const { return range::make_n_element_range (static_cast (m_start+1), static_cast (m_step), m_len); } -Array idx_vector::idx_range_rep::as_array (void) +Array idx_vector::idx_range_rep::as_array () { Array retval (dim_vector (1, m_len)); for (octave_idx_type i = 0; i < m_len; i++) @@ -279,12 +279,12 @@ return os << m_data; } -double idx_vector::idx_scalar_rep::unconvert (void) const +double idx_vector::idx_scalar_rep::unconvert () const { return m_data + 1; } -Array idx_vector::idx_scalar_rep::as_array (void) +Array idx_vector::idx_scalar_rep::as_array () { return Array (dim_vector (1, 1), m_data); } @@ -414,7 +414,7 @@ } } -idx_vector::idx_vector_rep::~idx_vector_rep (void) +idx_vector::idx_vector_rep::~idx_vector_rep () { if (m_aowner) delete m_aowner; @@ -581,7 +581,7 @@ return os; } -Array idx_vector::idx_vector_rep::unconvert (void) const +Array idx_vector::idx_vector_rep::unconvert () const { Array retval (m_orig_dims); for (octave_idx_type i = 0; i < m_len; i++) @@ -589,7 +589,7 @@ return retval; } -Array idx_vector::idx_vector_rep::as_array (void) +Array idx_vector::idx_vector_rep::as_array () { if (m_aowner) return *m_aowner; @@ -645,7 +645,7 @@ m_data = bnda.data (); } -idx_vector::idx_mask_rep::~idx_mask_rep (void) +idx_vector::idx_mask_rep::~idx_mask_rep () { if (m_aowner) delete m_aowner; @@ -693,7 +693,7 @@ return os; } -Array idx_vector::idx_mask_rep::unconvert (void) const +Array idx_vector::idx_mask_rep::unconvert () const { if (m_aowner) return *m_aowner; @@ -706,7 +706,7 @@ } } -Array idx_vector::idx_mask_rep::as_array (void) +Array idx_vector::idx_mask_rep::as_array () { if (m_aowner) return m_aowner->find ().reshape (m_orig_dims); @@ -967,7 +967,7 @@ return res; } -octave_idx_type idx_vector::increment (void) const +octave_idx_type idx_vector::increment () const { octave_idx_type retval = 0; @@ -996,7 +996,7 @@ return retval; } -const octave_idx_type *idx_vector::raw (void) +const octave_idx_type *idx_vector::raw () { if (m_rep->idx_class () != class_vector) *this = idx_vector (as_array (), extent (0)); @@ -1157,7 +1157,7 @@ return retval; } -idx_vector idx_vector::unmask (void) const +idx_vector idx_vector::unmask () const { if (idx_class () == class_mask) { @@ -1224,12 +1224,12 @@ } } -Array idx_vector::as_array (void) const +Array idx_vector::as_array () const { return m_rep->as_array (); } -bool idx_vector::isvector (void) const +bool idx_vector::isvector () const { return idx_class () != class_vector || orig_dimensions ().isvector (); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/idx-vector.h --- a/liboctave/array/idx-vector.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/idx-vector.h Mon Jan 30 18:36:03 2023 +0100 @@ -78,7 +78,7 @@ { public: - idx_base_rep (void) : m_count (1) { } + idx_base_rep () : m_count (1) { } // No copying! @@ -86,7 +86,7 @@ idx_base_rep& operator = (const idx_base_rep&) = delete; - virtual ~idx_base_rep (void) = default; + virtual ~idx_base_rep () = default; // Non-range-checking element query. virtual octave_idx_type xelem (octave_idx_type i) const = 0; @@ -101,7 +101,7 @@ virtual octave_idx_type extent (octave_idx_type n) const = 0; // Index class. - virtual idx_class_type idx_class (void) const { return class_invalid; } + virtual idx_class_type idx_class () const { return class_invalid; } // Sorts, maybe uniqifies, and returns a clone object pointer. virtual idx_base_rep * sort_uniq_clone (bool uniq = false) = 0; @@ -112,12 +112,12 @@ virtual bool is_colon_equiv (octave_idx_type) const { return false; } // The original dimensions of object (used when subscribing by matrices). - virtual dim_vector orig_dimensions (void) const { return dim_vector (); } + virtual dim_vector orig_dimensions () const { return dim_vector (); } // i/o virtual std::ostream& print (std::ostream& os) const = 0; - virtual Array as_array (void); + virtual Array as_array (); refcount m_count; }; @@ -127,7 +127,7 @@ { public: - idx_colon_rep (void) = default; + idx_colon_rep () = default; OCTAVE_API idx_colon_rep (char c); @@ -145,7 +145,7 @@ octave_idx_type extent (octave_idx_type n) const { return n; } - idx_class_type idx_class (void) const { return class_colon; } + idx_class_type idx_class () const { return class_colon; } idx_base_rep * sort_uniq_clone (bool = false) { m_count++; return this; } @@ -165,7 +165,7 @@ { public: - idx_range_rep (void) = delete; + idx_range_rep () = delete; idx_range_rep (octave_idx_type start, octave_idx_type len, octave_idx_type step, direct) @@ -196,7 +196,7 @@ return m_len ? std::max (n, m_start + 1 + (m_step < 0 ? 0 : m_step * (m_len - 1))) : n; } - idx_class_type idx_class (void) const { return class_range; } + idx_class_type idx_class () const { return class_range; } OCTAVE_API idx_base_rep * sort_uniq_clone (bool uniq = false); @@ -205,18 +205,18 @@ bool is_colon_equiv (octave_idx_type n) const { return m_start == 0 && m_step == 1 && m_len == n; } - dim_vector orig_dimensions (void) const + dim_vector orig_dimensions () const { return dim_vector (1, m_len); } - octave_idx_type get_start (void) const { return m_start; } + octave_idx_type get_start () const { return m_start; } - octave_idx_type get_step (void) const { return m_step; } + octave_idx_type get_step () const { return m_step; } OCTAVE_API std::ostream& print (std::ostream& os) const; - OCTAVE_API range unconvert (void) const; + OCTAVE_API range unconvert () const; - OCTAVE_API Array as_array (void); + OCTAVE_API Array as_array (); private: @@ -228,7 +228,7 @@ { public: - idx_scalar_rep (void) = delete; + idx_scalar_rep () = delete; idx_scalar_rep (octave_idx_type i, direct) : idx_base_rep (), m_data (i) { } @@ -253,7 +253,7 @@ octave_idx_type extent (octave_idx_type n) const { return std::max (n, m_data + 1); } - idx_class_type idx_class (void) const { return class_scalar; } + idx_class_type idx_class () const { return class_scalar; } idx_base_rep * sort_uniq_clone (bool = false) { m_count++; return this; } @@ -263,15 +263,15 @@ bool is_colon_equiv (octave_idx_type n) const { return n == 1 && m_data == 0; } - dim_vector orig_dimensions (void) const { return dim_vector (1, 1); } + dim_vector orig_dimensions () const { return dim_vector (1, 1); } - octave_idx_type get_data (void) const { return m_data; } + octave_idx_type get_data () const { return m_data; } OCTAVE_API std::ostream& print (std::ostream& os) const; - OCTAVE_API double unconvert (void) const; + OCTAVE_API double unconvert () const; - OCTAVE_API Array as_array (void); + OCTAVE_API Array as_array (); private: @@ -283,7 +283,7 @@ { public: - idx_vector_rep (void) + idx_vector_rep () : m_data (nullptr), m_len (0), m_ext (0), m_aowner (nullptr), m_orig_dims () { } // Direct constructor. @@ -314,7 +314,7 @@ idx_vector_rep& operator = (const idx_vector_rep& idx) = delete; - ~idx_vector_rep (void); + ~idx_vector_rep (); octave_idx_type xelem (octave_idx_type i) const { return m_data[i]; } @@ -325,21 +325,21 @@ octave_idx_type extent (octave_idx_type n) const { return std::max (n, m_ext); } - idx_class_type idx_class (void) const { return class_vector; } + idx_class_type idx_class () const { return class_vector; } idx_base_rep * sort_uniq_clone (bool uniq = false); OCTAVE_API idx_base_rep * sort_idx (Array&); - dim_vector orig_dimensions (void) const { return m_orig_dims; } + dim_vector orig_dimensions () const { return m_orig_dims; } - const octave_idx_type * get_data (void) const { return m_data; } + const octave_idx_type * get_data () const { return m_data; } OCTAVE_API std::ostream& print (std::ostream& os) const; - OCTAVE_API Array unconvert (void) const; + OCTAVE_API Array unconvert () const; - OCTAVE_API Array as_array (void); + OCTAVE_API Array as_array (); private: @@ -364,7 +364,7 @@ { public: - idx_mask_rep (void) = delete; + idx_mask_rep () = delete; // Direct constructor. idx_mask_rep (bool *data, octave_idx_type len, @@ -383,7 +383,7 @@ idx_mask_rep& operator = (const idx_mask_rep& idx) = delete; - OCTAVE_API ~idx_mask_rep (void); + OCTAVE_API ~idx_mask_rep (); octave_idx_type xelem (octave_idx_type i) const; @@ -394,25 +394,25 @@ octave_idx_type extent (octave_idx_type n) const { return std::max (n, m_ext); } - idx_class_type idx_class (void) const { return class_mask; } + idx_class_type idx_class () const { return class_mask; } idx_base_rep * sort_uniq_clone (bool = false) { m_count++; return this; } OCTAVE_API idx_base_rep * sort_idx (Array&); - dim_vector orig_dimensions (void) const { return m_orig_dims; } + dim_vector orig_dimensions () const { return m_orig_dims; } bool is_colon_equiv (octave_idx_type n) const { return m_len == n && m_ext == n; } - const bool * get_data (void) const { return m_data; } + const bool * get_data () const { return m_data; } OCTAVE_API std::ostream& print (std::ostream& os) const; - OCTAVE_API Array unconvert (void) const; + OCTAVE_API Array unconvert () const; - OCTAVE_API Array as_array (void); + OCTAVE_API Array as_array (); private: @@ -441,12 +441,12 @@ // The shared empty vector representation (for fast default // constructor). - static OCTAVE_API idx_vector_rep * nil_rep (void); + static OCTAVE_API idx_vector_rep * nil_rep (); public: // Fast empty constructor. - idx_vector (void) : m_rep (nil_rep ()) { m_rep->m_count++; } + idx_vector () : m_rep (nil_rep ()) { m_rep->m_count++; } // Zero-based constructors (for use from C++). idx_vector (octave_idx_type i) : m_rep (new idx_scalar_rep (i)) { } @@ -514,7 +514,7 @@ idx_vector (const idx_vector& a) : m_rep (a.m_rep) { m_rep->m_count++; } - ~idx_vector (void) + ~idx_vector () { if (--m_rep->m_count == 0 && m_rep != nil_rep ()) delete m_rep; @@ -533,7 +533,7 @@ return *this; } - idx_class_type idx_class (void) const { return m_rep->idx_class (); } + idx_class_type idx_class () const { return m_rep->idx_class (); } octave_idx_type length (octave_idx_type n = 0) const { return m_rep->length (n); } @@ -552,15 +552,15 @@ // FIXME: idx_vector objects are either created successfully or an // error is thrown, so this method no longer makes sense. - operator bool (void) const { return true; } + operator bool () const { return true; } - bool is_colon (void) const + bool is_colon () const { return m_rep->idx_class () == class_colon; } - bool is_scalar (void) const + bool is_scalar () const { return m_rep->idx_class () == class_scalar; } - bool is_range (void) const + bool is_range () const { return m_rep->idx_class () == class_range; } bool is_colon_equiv (octave_idx_type n) const @@ -572,15 +572,15 @@ idx_vector sorted (Array& sidx) const { return idx_vector (m_rep->sort_idx (sidx)); } - dim_vector orig_dimensions (void) const { return m_rep->orig_dimensions (); } + dim_vector orig_dimensions () const { return m_rep->orig_dimensions (); } - octave_idx_type orig_rows (void) const + octave_idx_type orig_rows () const { return orig_dimensions () (0); } - octave_idx_type orig_columns (void) const + octave_idx_type orig_columns () const { return orig_dimensions () (1); } - int orig_empty (void) const + int orig_empty () const { return (! is_colon () && orig_dimensions ().any_zero ()); } // i/o @@ -976,7 +976,7 @@ // Returns the increment for ranges and colon, 0 for scalars and empty // vectors, 1st difference otherwise. - OCTAVE_API octave_idx_type increment (void) const; + OCTAVE_API octave_idx_type increment () const; OCTAVE_API idx_vector complement (octave_idx_type n) const; @@ -991,20 +991,20 @@ OCTAVE_API void copy_data (octave_idx_type *data) const; // If the index is a mask, convert it to index vector. - OCTAVE_API idx_vector unmask (void) const; + OCTAVE_API idx_vector unmask () const; // Unconverts the index to a scalar, Range, double array or a mask. OCTAVE_API void unconvert (idx_class_type& iclass, double& scalar, range& range, Array& array, Array& mask) const; - OCTAVE_API Array as_array (void) const; + OCTAVE_API Array as_array () const; // Raw pointer to index array. This is non-const because it may be // necessary to mutate the index. - const OCTAVE_API octave_idx_type * raw (void); + const OCTAVE_API octave_idx_type * raw (); - OCTAVE_API bool isvector (void) const; + OCTAVE_API bool isvector () const; // FIXME: these are here for compatibility. They should be removed // when no longer in use. @@ -1021,9 +1021,9 @@ void sort (bool uniq = false) { *this = sorted (uniq); } - OCTAVE_API octave_idx_type ones_count (void) const; + OCTAVE_API octave_idx_type ones_count () const; - octave_idx_type max (void) const { return extent (1) - 1; } + octave_idx_type max () const { return extent (1) - 1; } private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/intNDArray.cc --- a/liboctave/array/intNDArray.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/intNDArray.cc Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,7 @@ template boolNDArray -intNDArray::operator ! (void) const +intNDArray::operator ! () const { boolNDArray b (this->dims ()); @@ -48,7 +48,7 @@ template bool -intNDArray::any_element_not_one_or_zero (void) const +intNDArray::any_element_not_one_or_zero () const { octave_idx_type nel = this->numel (); @@ -180,7 +180,7 @@ template intNDArray -intNDArray::abs (void) const +intNDArray::abs () const { octave_idx_type nel = this->numel (); intNDArray ret (this->dims ()); @@ -196,7 +196,7 @@ template intNDArray -intNDArray::signum (void) const +intNDArray::signum () const { octave_idx_type nel = this->numel (); intNDArray ret (this->dims ()); diff -r 17d568574e1c -r 7860fcc69082 liboctave/array/intNDArray.h --- a/liboctave/array/intNDArray.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/array/intNDArray.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,13 +41,13 @@ using typename MArray::element_type; - intNDArray (void) = default; + intNDArray () = default; intNDArray (const intNDArray& a) = default; intNDArray& operator = (const intNDArray& a) = default; - ~intNDArray (void) = default; + ~intNDArray () = default; intNDArray (T val) : MArray (dim_vector (1, 1), val) { } @@ -65,16 +65,16 @@ template intNDArray (const intNDArray& a) : MArray (a) { } - OCTAVE_API boolNDArray operator ! (void) const; + OCTAVE_API boolNDArray operator ! () const; - bool any_element_is_nan (void) const { return false; } - OCTAVE_API bool any_element_not_one_or_zero (void) const; + bool any_element_is_nan () const { return false; } + OCTAVE_API bool any_element_not_one_or_zero () const; OCTAVE_API intNDArray diag (octave_idx_type k = 0) const; OCTAVE_API intNDArray diag (octave_idx_type m, octave_idx_type n) const; - intNDArray& changesign (void) + intNDArray& changesign () { MArray::changesign (); return *this; @@ -106,13 +106,13 @@ OCTAVE_API intNDArray diff (octave_idx_type order = 1, int dim = -1) const; - OCTAVE_API intNDArray abs (void) const; - OCTAVE_API intNDArray signum (void) const; + OCTAVE_API intNDArray abs () const; + OCTAVE_API intNDArray signum () const; - intNDArray squeeze (void) const + intNDArray squeeze () const { return intNDArray (MArray::squeeze ()); } - intNDArray transpose (void) const + intNDArray transpose () const { return intNDArray (MArray::transpose ()); } OCTAVE_API intNDArray diff -r 17d568574e1c -r 7860fcc69082 liboctave/liboctave-build-info.h --- a/liboctave/liboctave-build-info.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/liboctave-build-info.h Mon Jan 30 18:36:03 2023 +0100 @@ -30,6 +30,6 @@ #include -extern OCTAVE_API std::string liboctave_hg_id (void); +extern OCTAVE_API std::string liboctave_hg_id (); #endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/liboctave-build-info.in.cc --- a/liboctave/liboctave-build-info.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/liboctave-build-info.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,7 @@ #include "liboctave-build-info.h" std::string -liboctave_hg_id (void) +liboctave_hg_id () { return "%OCTAVE_HG_ID%"; } diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/CollocWt.cc --- a/liboctave/numeric/CollocWt.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/CollocWt.cc Mon Jan 30 18:36:03 2023 +0100 @@ -402,7 +402,7 @@ return *this; } -void CollocWt::init (void) +void CollocWt::init () { // Check for possible errors. diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/CollocWt.h --- a/liboctave/numeric/CollocWt.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/CollocWt.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ { public: - CollocWt (void) + CollocWt () : m_n (0), m_inc_left (0), m_inc_right (0), m_lb (0.0), m_rb (1.0), m_alpha (0.0), m_beta (0.0), m_r (), m_q (), m_A (), m_B (), m_initialized (false) @@ -77,7 +77,7 @@ CollocWt& operator = (const CollocWt& a) = default; - ~CollocWt (void) = default; + ~CollocWt () = default; CollocWt& resize (octave_idx_type nc) { @@ -86,14 +86,14 @@ return *this; } - CollocWt& add_left (void) + CollocWt& add_left () { m_inc_left = 1; m_initialized = false; return *this; } - CollocWt& delete_left (void) + CollocWt& delete_left () { m_inc_left = 0; m_initialized = false; @@ -102,14 +102,14 @@ CollocWt& set_left (double val); - CollocWt& add_right (void) + CollocWt& add_right () { m_inc_right = 1; m_initialized = false; return *this; } - CollocWt& delete_right (void) + CollocWt& delete_right () { m_inc_right = 0; m_initialized = false; @@ -132,20 +132,20 @@ return *this; } - octave_idx_type ncol (void) const { return m_n; } + octave_idx_type ncol () const { return m_n; } - octave_idx_type left_included (void) const { return m_inc_left; } - octave_idx_type right_included (void) const { return m_inc_right; } + octave_idx_type left_included () const { return m_inc_left; } + octave_idx_type right_included () const { return m_inc_right; } - double left (void) const { return m_lb; } - double right (void) const { return m_rb; } + double left () const { return m_lb; } + double right () const { return m_rb; } - double width (void) const { return m_rb - m_lb; } + double width () const { return m_rb - m_lb; } - double alpha (void) const { return m_alpha; } - double beta (void) const { return m_beta; } + double alpha () const { return m_alpha; } + double beta () const { return m_beta; } - ColumnVector roots (void) + ColumnVector roots () { if (! m_initialized) init (); @@ -153,7 +153,7 @@ return m_r; } - ColumnVector quad (void) + ColumnVector quad () { if (! m_initialized) init (); @@ -161,9 +161,9 @@ return m_q; } - ColumnVector quad_weights (void) { return quad (); } + ColumnVector quad_weights () { return quad (); } - Matrix first (void) + Matrix first () { if (! m_initialized) init (); @@ -171,7 +171,7 @@ return m_A; } - Matrix second (void) + Matrix second () { if (! m_initialized) init (); @@ -202,16 +202,11 @@ bool m_initialized; - void init (void); + void init (); void error (const char *msg); }; OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "use 'octave::CollocWt' instead") -typedef octave::CollocWt CollocWt; #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DAE.h --- a/liboctave/numeric/DAE.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DAE.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - DAE (void) + DAE () : base_diff_alg_eqn (), DAEFunc () { } DAE (const ColumnVector& xx, double tt, DAEFunc& f) @@ -60,7 +60,7 @@ return *this; } - virtual ~DAE (void) = default; + virtual ~DAE () = default; }; #endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DAEFunc.h --- a/liboctave/numeric/DAEFunc.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DAEFunc.h Mon Jan 30 18:36:03 2023 +0100 @@ -47,7 +47,7 @@ const ColumnVector& xdot, double t, double cj); - DAEFunc (void) + DAEFunc () : m_fcn (nullptr), m_jac (nullptr), m_reset (true) { } DAEFunc (DAERHSFunc f) @@ -70,9 +70,9 @@ return *this; } - virtual ~DAEFunc (void) = default; + virtual ~DAEFunc () = default; - DAERHSFunc function (void) const { return m_fcn; } + DAERHSFunc function () const { return m_fcn; } DAEFunc& set_function (DAERHSFunc f) { @@ -81,7 +81,7 @@ return *this; } - DAEJacFunc jacobian_function (void) const { return m_jac; } + DAEJacFunc jacobian_function () const { return m_jac; } DAEFunc& set_jacobian_function (DAEJacFunc j) { diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DAERT.h --- a/liboctave/numeric/DAERT.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DAERT.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - DAERT (void) + DAERT () : base_diff_alg_eqn (), DAERTFunc () { } DAERT (const ColumnVector& xx, double tt, DAERTFunc& f) @@ -61,7 +61,7 @@ return *this; } - virtual ~DAERT (void) = default; + virtual ~DAERT () = default; void initialize (const ColumnVector& xx, const ColumnVector& xxdot, double tt) diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DAERTFunc.h --- a/liboctave/numeric/DAERTFunc.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DAERTFunc.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ typedef ColumnVector (*DAERTConstrFunc) (const ColumnVector& x, double t); - DAERTFunc (void) + DAERTFunc () : DAEFunc (), m_constr (nullptr), m_reset (true) { } DAERTFunc (DAERHSFunc f) @@ -66,9 +66,9 @@ return *this; } - virtual ~DAERTFunc (void) = default; + virtual ~DAERTFunc () = default; - DAERTConstrFunc constraint_function (void) const { return m_constr; } + DAERTConstrFunc constraint_function () const { return m_constr; } DAERTFunc& set_constraint_function (DAERTConstrFunc cf) { diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DASPK.cc --- a/liboctave/numeric/DASPK.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DASPK.cc Mon Jan 30 18:36:03 2023 +0100 @@ -692,7 +692,7 @@ } std::string -DASPK::error_message (void) const +DASPK::error_message () const { std::string retval; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DASPK.h --- a/liboctave/numeric/DASPK.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DASPK.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,7 @@ { public: - DASPK (void) + DASPK () : DAE (), DASPK_options (), m_initialized (false), m_liw (0), m_lrw (0), m_info (), m_iwork (), m_rwork (), m_abs_tol (), m_rel_tol () { } @@ -56,7 +56,7 @@ m_liw (0), m_lrw (0), m_info (), m_iwork (), m_rwork (), m_abs_tol (), m_rel_tol () { } - ~DASPK (void) = default; + ~DASPK () = default; ColumnVector do_integrate (double t); @@ -69,7 +69,7 @@ Matrix integrate (const ColumnVector& tout, Matrix& xdot_out, const ColumnVector& tcrit); - std::string error_message (void) const; + std::string error_message () const; private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DASRT.cc --- a/liboctave/numeric/DASRT.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DASRT.cc Mon Jan 30 18:36:03 2023 +0100 @@ -551,7 +551,7 @@ } std::string -DASRT::error_message (void) const +DASRT::error_message () const { std::string retval; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DASRT.h --- a/liboctave/numeric/DASRT.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DASRT.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ { public: - DASRT_result (void) + DASRT_result () : m_x (), m_xdot (), m_t () { } DASRT_result (const Matrix& x, const Matrix& xdot, const ColumnVector& t) @@ -59,11 +59,11 @@ return *this; } - ~DASRT_result (void) = default; + ~DASRT_result () = default; - Matrix state (void) const { return m_x; } - Matrix deriv (void) const { return m_xdot; } - ColumnVector times (void) const { return m_t; } + Matrix state () const { return m_x; } + Matrix deriv () const { return m_xdot; } + ColumnVector times () const { return m_t; } private: @@ -78,7 +78,7 @@ { public: - DASRT (void) + DASRT () : DAERT (), DASRT_options (), m_initialized (false), m_liw (0), m_lrw (0), m_ng (0), m_info (), m_iwork (), m_jroot (), m_rwork (), m_abs_tol (), m_rel_tol () @@ -97,14 +97,14 @@ m_rwork (), m_abs_tol (), m_rel_tol () { } - ~DASRT (void) = default; + ~DASRT () = default; DASRT_result integrate (const ColumnVector& tout); DASRT_result integrate (const ColumnVector& tout, const ColumnVector& tcrit); - std::string error_message (void) const; + std::string error_message () const; private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DASSL.cc --- a/liboctave/numeric/DASSL.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DASSL.cc Mon Jan 30 18:36:03 2023 +0100 @@ -499,7 +499,7 @@ } std::string -DASSL::error_message (void) const +DASSL::error_message () const { std::string retval; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DASSL.h --- a/liboctave/numeric/DASSL.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DASSL.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,7 @@ { public: - DASSL (void) + DASSL () : DAE (), DASSL_options (), m_initialized (false), m_liw (0), m_lrw (0), m_info (), m_iwork (), m_rwork (), m_abs_tol (), m_rel_tol () { } @@ -56,7 +56,7 @@ m_liw (0), m_lrw (0), m_info (), m_iwork (), m_rwork (), m_abs_tol (), m_rel_tol () { } - ~DASSL (void) = default; + ~DASSL () = default; ColumnVector do_integrate (double t); @@ -69,7 +69,7 @@ Matrix integrate (const ColumnVector& tout, Matrix& xdot_out, const ColumnVector& tcrit); - std::string error_message (void) const; + std::string error_message () const; private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/DET.h --- a/liboctave/numeric/DET.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/DET.h Mon Jan 30 18:36:03 2023 +0100 @@ -66,8 +66,8 @@ return *this; } - T coef (void) const { return m_c2; } - int exp (void) const { return m_e2; } + T coef () const { return m_c2; } + int exp () const { return m_e2; } T value () const { return m_c2 * static_cast (std::ldexp (1.0, m_e2)); } operator T () const { return value (); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/EIG.h --- a/liboctave/numeric/EIG.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/EIG.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,7 +44,7 @@ public: - EIG (void) : m_lambda (), m_v (), m_w () { } + EIG () : m_lambda (), m_v (), m_w () { } EIG (const Matrix& a, bool calc_rev = true, bool calc_lev = true, bool balance = true) @@ -116,11 +116,11 @@ return *this; } - ~EIG (void) = default; + ~EIG () = default; - ComplexColumnVector eigenvalues (void) const { return m_lambda; } - ComplexMatrix right_eigenvectors (void) const { return m_v; } - ComplexMatrix left_eigenvectors (void) const { return m_w; } + ComplexColumnVector eigenvalues () const { return m_lambda; } + ComplexMatrix right_eigenvectors () const { return m_v; } + ComplexMatrix left_eigenvectors () const { return m_w; } friend std::ostream& operator << (std::ostream& os, const EIG& a); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/LSODE.cc --- a/liboctave/numeric/LSODE.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/LSODE.cc Mon Jan 30 18:36:03 2023 +0100 @@ -348,7 +348,7 @@ } std::string -LSODE::error_message (void) const +LSODE::error_message () const { std::string retval; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/LSODE.h --- a/liboctave/numeric/LSODE.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/LSODE.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ { public: - LSODE (void) + LSODE () : ODE (), LSODE_options (), m_initialized (false), m_method_flag (0), m_itask (0), m_iopt (0), m_itol (0), m_liw (0), m_lrw (0), m_iwork (), m_rwork (), m_rel_tol (0.0), m_abs_tol () { } @@ -49,7 +49,7 @@ m_method_flag (0), m_itask (0), m_iopt (0), m_itol (0), m_liw (0), m_lrw (0), m_iwork (), m_rwork (), m_rel_tol (0.0), m_abs_tol () { } - ~LSODE (void) = default; + ~LSODE () = default; ColumnVector do_integrate (double t); @@ -57,7 +57,7 @@ Matrix do_integrate (const ColumnVector& tout, const ColumnVector& tcrit); - std::string error_message (void) const; + std::string error_message () const; private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/ODE.h --- a/liboctave/numeric/ODE.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/ODE.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - ODE (void) + ODE () : base_diff_eqn (), ODEFunc () { } ODE (const ColumnVector& s, double tm, const ODEFunc& f) @@ -56,7 +56,7 @@ return *this; } - virtual ~ODE (void) = default; + virtual ~ODE () = default; // Derived classes must provide functions to actually do the // integration. diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/ODEFunc.h --- a/liboctave/numeric/ODEFunc.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/ODEFunc.h Mon Jan 30 18:36:03 2023 +0100 @@ -38,7 +38,7 @@ typedef ColumnVector (*ODERHSFunc) (const ColumnVector&, double); typedef Matrix (*ODEJacFunc) (const ColumnVector&, double); - ODEFunc (void) + ODEFunc () : m_fcn (nullptr), m_jac (nullptr), m_reset (true) { } ODEFunc (ODERHSFunc f) @@ -61,9 +61,9 @@ return *this; } - virtual ~ODEFunc (void) = default; + virtual ~ODEFunc () = default; - ODERHSFunc function (void) const { return m_fcn; } + ODERHSFunc function () const { return m_fcn; } ODEFunc& set_function (ODERHSFunc f) { @@ -72,7 +72,7 @@ return *this; } - ODEJacFunc jacobian_function (void) const { return m_jac; } + ODEJacFunc jacobian_function () const { return m_jac; } ODEFunc& set_jacobian_function (ODEJacFunc j) { diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/ODES.h --- a/liboctave/numeric/ODES.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/ODES.h Mon Jan 30 18:36:03 2023 +0100 @@ -36,7 +36,7 @@ { public: - ODES (void) + ODES () : base_diff_eqn (), ODESFunc (), m_xdot (), m_theta () { } ODES (const ColumnVector& s, double tm, ODESFunc& f) @@ -65,9 +65,9 @@ return *this; } - ~ODES (void) = default; + ~ODES () = default; - ColumnVector parameter_vector (void) { return m_theta; } + ColumnVector parameter_vector () { return m_theta; } OCTAVE_API void initialize (const ColumnVector& x, double t); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/ODESFunc.h --- a/liboctave/numeric/ODESFunc.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/ODESFunc.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ typedef Matrix (*ODES_jsub) (const ColumnVector& x, double, const ColumnVector& theta); - ODESFunc (void) + ODESFunc () : m_fsub (nullptr), m_bsub (nullptr), m_jsub (nullptr) { } ODESFunc (ODES_fsub f) @@ -78,9 +78,9 @@ return *this; } - virtual ~ODESFunc (void) = default; + virtual ~ODESFunc () = default; - ODES_fsub fsub_function (void) const { return m_fsub; } + ODES_fsub fsub_function () const { return m_fsub; } ODESFunc& set_fsub_function (ODES_fsub f) { @@ -88,7 +88,7 @@ return *this; } - ODES_bsub bsub_function (void) const { return m_bsub; } + ODES_bsub bsub_function () const { return m_bsub; } ODESFunc& set_bsub_function (ODES_bsub b) { @@ -96,7 +96,7 @@ return *this; } - ODES_jsub jsub_function (void) const { return m_jsub; } + ODES_jsub jsub_function () const { return m_jsub; } ODESFunc& set_jsub_function (ODES_jsub j) { diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/Quad.h --- a/liboctave/numeric/Quad.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/Quad.h Mon Jan 30 18:36:03 2023 +0100 @@ -48,16 +48,16 @@ Quad (float_integrand_fcn fcn) : Quad_options (), m_f (), m_ff (fcn) { } - virtual ~Quad (void) = default; + virtual ~Quad () = default; - virtual double integrate (void) + virtual double integrate () { octave_idx_type ier, neval; double abserr; return do_integrate (ier, neval, abserr); } - virtual float float_integrate (void) + virtual float float_integrate () { octave_idx_type ier, neval; float abserr; @@ -137,7 +137,7 @@ : Quad (fcn), m_lower_limit (0.0), m_upper_limit (1.0), m_singularities (sing) { } - ~DefQuad (void) = default; + ~DefQuad () = default; double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); @@ -167,7 +167,7 @@ IndefQuad (integrand_fcn fcn, double b, IntegralType t) : Quad (fcn), m_bound (b), m_type (t) { } - ~IndefQuad (void) = default; + ~IndefQuad () = default; double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); @@ -204,7 +204,7 @@ : Quad (fcn), m_lower_limit (0.0), m_upper_limit (1.0), m_singularities (sing) { } - ~FloatDefQuad (void) = default; + ~FloatDefQuad () = default; OCTAVE_NORETURN double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); @@ -234,7 +234,7 @@ FloatIndefQuad (float_integrand_fcn fcn, double b, IntegralType t) : Quad (fcn), m_bound (b), m_type (t) { } - ~FloatIndefQuad (void) = default; + ~FloatIndefQuad () = default; OCTAVE_NORETURN double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/aepbalance.cc --- a/liboctave/numeric/aepbalance.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/aepbalance.cc Mon Jan 30 18:36:03 2023 +0100 @@ -74,7 +74,7 @@ template <> OCTAVE_API Matrix -aepbalance::balancing_matrix (void) const +aepbalance::balancing_matrix () const { F77_INT n = to_f77_int (m_balanced_mat.rows ()); @@ -126,7 +126,7 @@ template <> OCTAVE_API FloatMatrix -aepbalance::balancing_matrix (void) const +aepbalance::balancing_matrix () const { F77_INT n = to_f77_int (m_balanced_mat.rows ()); @@ -179,7 +179,7 @@ template <> OCTAVE_API ComplexMatrix -aepbalance::balancing_matrix (void) const +aepbalance::balancing_matrix () const { F77_INT n = to_f77_int (m_balanced_mat.rows ()); @@ -233,7 +233,7 @@ template <> OCTAVE_API FloatComplexMatrix -aepbalance::balancing_matrix (void) const +aepbalance::balancing_matrix () const { F77_INT n = to_f77_int (m_balanced_mat.rows ()); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/aepbalance.h --- a/liboctave/numeric/aepbalance.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/aepbalance.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ typedef typename MT::real_column_vector_type VT; - aepbalance (void) : m_balanced_mat (), m_scale (), m_ilo (), m_ihi (), m_job () { } + aepbalance () : m_balanced_mat (), m_scale (), m_ilo (), m_ihi (), m_job () { } OCTAVE_API aepbalance (const MT& a, bool noperm = false, bool noscal = false); @@ -65,16 +65,16 @@ return *this; } - virtual ~aepbalance (void) = default; + virtual ~aepbalance () = default; - OCTAVE_API MT balancing_matrix (void) const; + OCTAVE_API MT balancing_matrix () const; - MT balanced_matrix (void) const + MT balanced_matrix () const { return m_balanced_mat; } - VT permuting_vector (void) const + VT permuting_vector () const { octave_idx_type n = m_balanced_mat.rows (); @@ -98,7 +98,7 @@ return pv; } - VT scaling_vector (void) const + VT scaling_vector () const { octave_idx_type n = m_balanced_mat.rows (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/base-dae.h --- a/liboctave/numeric/base-dae.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/base-dae.h Mon Jan 30 18:36:03 2023 +0100 @@ -35,7 +35,7 @@ { public: - base_diff_alg_eqn (void) + base_diff_alg_eqn () : base_diff_eqn (), m_xdot () { } base_diff_alg_eqn (const ColumnVector& xx, double tt) @@ -48,7 +48,7 @@ base_diff_alg_eqn (const base_diff_alg_eqn& a) : base_diff_eqn (a), m_xdot (a.m_xdot) { } - virtual ~base_diff_alg_eqn (void) = default; + virtual ~base_diff_alg_eqn () = default; base_diff_alg_eqn& operator = (const base_diff_alg_eqn& a) { @@ -73,7 +73,7 @@ m_xdot = xdot0; } - ColumnVector state_derivative (void) { return m_xdot; } + ColumnVector state_derivative () { return m_xdot; } protected: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/base-de.h --- a/liboctave/numeric/base-de.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/base-de.h Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ { public: - base_diff_eqn (void) + base_diff_eqn () : m_x (), m_t (0.0), m_stop_time (0.0), m_stop_time_set (false), m_restart (true), m_integration_error (false), m_istate (0) { } @@ -49,7 +49,7 @@ : m_x (a.m_x), m_t (a.m_t), m_stop_time (0.0), m_stop_time_set (false), m_restart (true), m_integration_error (false), m_istate (0) { } - virtual ~base_diff_eqn (void) = default; + virtual ~base_diff_eqn () = default; base_diff_eqn& operator = (const base_diff_eqn& a) { @@ -76,11 +76,11 @@ force_restart (); } - octave_idx_type size (void) const { return m_x.numel (); } + octave_idx_type size () const { return m_x.numel (); } - ColumnVector state (void) const { return m_x; } + ColumnVector state () const { return m_x; } - double time (void) const { return m_t; } + double time () const { return m_t; } void set_stop_time (double tt) { @@ -89,19 +89,19 @@ force_restart (); } - void clear_stop_time (void) + void clear_stop_time () { m_stop_time_set = false; force_restart (); } - virtual void force_restart (void) { m_restart = true; } + virtual void force_restart () { m_restart = true; } - bool integration_ok (void) const { return ! m_integration_error; } + bool integration_ok () const { return ! m_integration_error; } - octave_idx_type integration_state (void) const { return m_istate; } + octave_idx_type integration_state () const { return m_istate; } - virtual std::string error_message (void) const = 0; + virtual std::string error_message () const = 0; protected: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/chol.cc --- a/liboctave/numeric/chol.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/chol.cc Mon Jan 30 18:36:03 2023 +0100 @@ -247,7 +247,7 @@ // Compute the inverse of a matrix using the Cholesky factorization. template T -chol::inverse (void) const +chol::inverse () const { return chol2inv_internal (m_chol_mat, m_is_upper); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/chol.h --- a/liboctave/numeric/chol.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/chol.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,7 @@ typedef typename T::column_vector_type VT; typedef typename T::real_elt_type COND_T; - chol (void) : m_chol_mat (), m_rcond (0), m_is_upper (true) { } + chol () : m_chol_mat (), m_rcond (0), m_is_upper (true) { } chol (const T& a, bool upper = true, bool calc_cond = false) : m_chol_mat (), m_rcond (0) @@ -71,12 +71,12 @@ return *this; } - T chol_matrix (void) const { return m_chol_mat; } + T chol_matrix () const { return m_chol_mat; } - COND_T rcond (void) const { return m_rcond; } + COND_T rcond () const { return m_rcond; } // Compute the inverse of a matrix using the Cholesky factorization. - OCTAVE_API T inverse (void) const; + OCTAVE_API T inverse () const; OCTAVE_API void set (const T& R); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/eigs-base.cc --- a/liboctave/numeric/eigs-base.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/eigs-base.cc Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ #if defined (HAVE_ARPACK) static void -warn_convergence (void) +warn_convergence () { (*current_liboctave_warning_with_id_handler) ("Octave:convergence", diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/fEIG.h --- a/liboctave/numeric/fEIG.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/fEIG.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,7 +44,7 @@ public: - FloatEIG (void) : m_lambda (), m_v (), m_w () { } + FloatEIG () : m_lambda (), m_v (), m_w () { } FloatEIG (const FloatMatrix& a, bool calc_rev = true, bool calc_lev = true, bool balance = true) @@ -116,11 +116,11 @@ return *this; } - ~FloatEIG (void) = default; + ~FloatEIG () = default; - FloatComplexColumnVector eigenvalues (void) const { return m_lambda; } - FloatComplexMatrix right_eigenvectors (void) const { return m_v; } - FloatComplexMatrix left_eigenvectors (void) const { return m_w; } + FloatComplexColumnVector eigenvalues () const { return m_lambda; } + FloatComplexMatrix right_eigenvectors () const { return m_v; } + FloatComplexMatrix left_eigenvectors () const { return m_w; } friend std::ostream& operator << (std::ostream& os, const FloatEIG& a); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/gepbalance.h --- a/liboctave/numeric/gepbalance.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/gepbalance.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ typedef typename T::real_matrix_type RT; - gepbalance (void) + gepbalance () : m_balanced_mat (), m_balanced_mat2 (), m_balancing_mat (), m_balancing_mat2 () { } @@ -74,15 +74,15 @@ return *this; } - ~gepbalance (void) = default; + ~gepbalance () = default; - T balanced_matrix (void) const { return m_balanced_mat; } + T balanced_matrix () const { return m_balanced_mat; } - T balanced_matrix2 (void) const { return m_balanced_mat2; } + T balanced_matrix2 () const { return m_balanced_mat2; } - RT balancing_matrix (void) const { return m_balancing_mat; } + RT balancing_matrix () const { return m_balancing_mat; } - RT balancing_matrix2 (void) const { return m_balancing_mat2; } + RT balancing_matrix2 () const { return m_balancing_mat2; } private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/gsvd.cc --- a/liboctave/numeric/gsvd.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/gsvd.cc Mon Jan 30 18:36:03 2023 +0100 @@ -53,7 +53,7 @@ #define xSTRINGIZE(x) #x #define STRINGIZE(x) xSTRINGIZE(x) -static void initialize_gsvd (void) +static void initialize_gsvd () { if (gsvd_initialized) return; @@ -436,7 +436,7 @@ template T -gsvd::left_singular_matrix_A (void) const +gsvd::left_singular_matrix_A () const { if (m_type == gsvd::Type::sigma_only) (*current_liboctave_error_handler) @@ -447,7 +447,7 @@ template T -gsvd::left_singular_matrix_B (void) const +gsvd::left_singular_matrix_B () const { if (m_type == gsvd::Type::sigma_only) (*current_liboctave_error_handler) @@ -458,7 +458,7 @@ template T -gsvd::right_singular_matrix (void) const +gsvd::right_singular_matrix () const { if (m_type == gsvd::Type::sigma_only) (*current_liboctave_error_handler) diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/gsvd.h --- a/liboctave/numeric/gsvd.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/gsvd.h Mon Jan 30 18:36:03 2023 +0100 @@ -46,7 +46,7 @@ sigma_only }; - gsvd (void) : m_sigmaA (), m_sigmaB (), m_left_smA (), m_left_smB (), m_right_sm () + gsvd () : m_sigmaA (), m_sigmaB (), m_left_smA (), m_left_smB (), m_right_sm () { } gsvd (const T& a, const T& b, @@ -73,18 +73,18 @@ return *this; } - ~gsvd (void) = default; + ~gsvd () = default; typename T::real_matrix_type - singular_values_A (void) const { return m_sigmaA; } + singular_values_A () const { return m_sigmaA; } typename T::real_matrix_type - singular_values_B (void) const { return m_sigmaB; } + singular_values_B () const { return m_sigmaB; } - T left_singular_matrix_A (void) const; - T left_singular_matrix_B (void) const; + T left_singular_matrix_A () const; + T left_singular_matrix_B () const; - T right_singular_matrix (void) const; + T right_singular_matrix () const; private: typedef typename T::value_type P; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/hess.h --- a/liboctave/numeric/hess.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/hess.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ { public: - hess (void) + hess () : m_hess_mat (), m_unitary_hess_mat () { } @@ -71,11 +71,11 @@ return *this; } - ~hess (void) = default; + ~hess () = default; - T hess_matrix (void) const { return m_hess_mat; } + T hess_matrix () const { return m_hess_mat; } - T unitary_hess_matrix (void) const { return m_unitary_hess_mat; } + T unitary_hess_matrix () const { return m_unitary_hess_mat; } private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/lu.cc --- a/liboctave/numeric/lu.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/lu.cc Mon Jan 30 18:36:03 2023 +0100 @@ -65,14 +65,14 @@ template bool -lu::packed (void) const +lu::packed () const { return m_L.dims () == dim_vector (); } template void -lu::unpack (void) +lu::unpack () { if (packed ()) { @@ -93,7 +93,7 @@ template T -lu::L (void) const +lu::L () const { if (packed ()) { @@ -120,7 +120,7 @@ template T -lu::U (void) const +lu::U () const { if (packed ()) { @@ -144,7 +144,7 @@ template T -lu::Y (void) const +lu::Y () const { if (! packed ()) (*current_liboctave_error_handler) @@ -155,7 +155,7 @@ template Array -lu::getp (void) const +lu::getp () const { if (packed ()) { @@ -186,14 +186,14 @@ template PermMatrix -lu::P (void) const +lu::P () const { return PermMatrix (getp (), false); } template ColumnVector -lu::P_vec (void) const +lu::P_vec () const { octave_idx_type a_nr = m_a_fact.rows (); @@ -209,7 +209,7 @@ template bool -lu::regular (void) const +lu::regular () const { bool retval = true; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/lu.h --- a/liboctave/numeric/lu.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/lu.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,7 +45,7 @@ typedef typename T::column_vector_type VT; typedef typename T::element_type ELT_T; - lu (void) + lu () : m_a_fact (), m_L (), m_ipvt () { } OCTAVE_API lu (const T& a); @@ -67,23 +67,23 @@ return *this; } - virtual ~lu (void) = default; + virtual ~lu () = default; - OCTAVE_API bool packed (void) const; + OCTAVE_API bool packed () const; - OCTAVE_API void unpack (void); + OCTAVE_API void unpack (); - OCTAVE_API T L (void) const; + OCTAVE_API T L () const; - OCTAVE_API T U (void) const; + OCTAVE_API T U () const; - OCTAVE_API T Y (void) const; + OCTAVE_API T Y () const; - OCTAVE_API PermMatrix P (void) const; + OCTAVE_API PermMatrix P () const; - OCTAVE_API ColumnVector P_vec (void) const; + OCTAVE_API ColumnVector P_vec () const; - OCTAVE_API bool regular (void) const; + OCTAVE_API bool regular () const; OCTAVE_API void update (const VT& u, const VT& v); @@ -97,7 +97,7 @@ // The result of getp is passed to other Octave Matrix functions, // so we use octave_idx_type. - OCTAVE_API Array getp (void) const; + OCTAVE_API Array getp () const; T m_a_fact; T m_L; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-convn.h --- a/liboctave/numeric/oct-convn.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-convn.h Mon Jan 30 18:36:03 2023 +0100 @@ -158,152 +158,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline NDArray -convn (const NDArray& a, const NDArray& b, convn_type ct) -{ - return octave::convn (a, b, static_cast (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline Matrix -convn (const Matrix& a, const Matrix& b, convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline Matrix -convn (const Matrix& a, const ColumnVector& c, const RowVector& r, - convn_type ct) -{ - return octave::convn (a, c, r, octave::convert_enum (ct)); -} - -// double complex X double real - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline ComplexNDArray -convn (const ComplexNDArray& a, const NDArray& b, convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline ComplexMatrix -convn (const ComplexMatrix& a, const Matrix& b, convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline ComplexMatrix -convn (const ComplexMatrix& a, const ColumnVector& c, const RowVector& r, - convn_type ct) -{ - return octave::convn (a, c, r, octave::convert_enum (ct)); -} - -// double complex X double complex - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline ComplexNDArray -convn (const ComplexNDArray& a, const ComplexNDArray& b, convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline ComplexMatrix -convn (const ComplexMatrix& a, const ComplexMatrix& b, convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline ComplexMatrix -convn (const ComplexMatrix& a, const ComplexColumnVector& c, - const ComplexRowVector& r, convn_type ct) -{ - return octave::convn (a, c, r, octave::convert_enum (ct)); -} - -// float real X float real - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatNDArray -convn (const FloatNDArray& a, const FloatNDArray& b, convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatMatrix -convn (const FloatMatrix& a, const FloatMatrix& b, convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatMatrix -convn (const FloatMatrix& a, const FloatColumnVector& c, - const FloatRowVector& r, convn_type ct) -{ - return octave::convn (a, c, r, octave::convert_enum (ct)); -} - -// float complex X float real - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatComplexNDArray -convn (const FloatComplexNDArray& a, const FloatNDArray& b, - convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatComplexMatrix -convn (const FloatComplexMatrix& a, const FloatMatrix& b, - convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatComplexMatrix -convn (const FloatComplexMatrix& a, const FloatColumnVector& c, - const FloatRowVector& r, convn_type ct) -{ - return octave::convn (a, c, r, octave::convert_enum (ct)); -} - -// float complex X float complex - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatComplexNDArray -convn (const FloatComplexNDArray& a, const FloatComplexNDArray& b, - convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatComplexMatrix -convn (const FloatComplexMatrix& a, const FloatComplexMatrix& b, - convn_type ct) -{ - return octave::convn (a, b, octave::convert_enum (ct)); -} - -OCTAVE_DEPRECATED (7, "use 'octave::convn' instead") -inline FloatComplexMatrix -convn (const FloatComplexMatrix& a, const FloatComplexColumnVector& c, - const FloatComplexRowVector& r, convn_type ct) -{ - return octave::convn (a, c, r, octave::convert_enum (ct)); -} #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-fftw.cc --- a/liboctave/numeric/oct-fftw.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-fftw.cc Mon Jan 30 18:36:03 2023 +0100 @@ -65,7 +65,7 @@ // Note that it is profitable to store the FFTW3 plans, for small FFTs. -fftw_planner::fftw_planner (void) +fftw_planner::fftw_planner () : m_meth (ESTIMATE), m_rplan (nullptr), m_rd (0), m_rs (0), m_rr (0), m_rh (0), m_rn (), m_rsimd_align (false), m_nthreads (1) { @@ -97,7 +97,7 @@ fftw_import_system_wisdom (); } -fftw_planner::~fftw_planner (void) +fftw_planner::~fftw_planner () { fftw_plan *plan_p; @@ -115,7 +115,7 @@ } bool -fftw_planner::instance_ok (void) +fftw_planner::instance_ok () { bool retval = true; @@ -395,7 +395,7 @@ } fftw_planner::FftwMethod -fftw_planner::do_method (void) +fftw_planner::do_method () { return m_meth; } @@ -427,7 +427,7 @@ float_fftw_planner *float_fftw_planner::s_instance = nullptr; -float_fftw_planner::float_fftw_planner (void) +float_fftw_planner::float_fftw_planner () : m_meth (ESTIMATE), m_rplan (nullptr), m_rd (0), m_rs (0), m_rr (0), m_rh (0), m_rn (), m_rsimd_align (false), m_nthreads (1) { @@ -454,7 +454,7 @@ fftwf_import_system_wisdom (); } -float_fftw_planner::~float_fftw_planner (void) +float_fftw_planner::~float_fftw_planner () { fftwf_plan *plan_p; @@ -472,7 +472,7 @@ } bool -float_fftw_planner::instance_ok (void) +float_fftw_planner::instance_ok () { bool retval = true; @@ -750,7 +750,7 @@ } float_fftw_planner::FftwMethod -float_fftw_planner::do_method (void) +float_fftw_planner::do_method () { return m_meth; } @@ -1135,7 +1135,7 @@ #endif std::string -fftw_version (void) +fftw_version () { #if defined (HAVE_FFTW) return ::fftw_version; @@ -1145,7 +1145,7 @@ } std::string -fftwf_version (void) +fftwf_version () { #if defined (HAVE_FFTW) return ::fftwf_version; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-fftw.h --- a/liboctave/numeric/oct-fftw.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-fftw.h Mon Jan 30 18:36:03 2023 +0100 @@ -43,7 +43,7 @@ { protected: - fftw_planner (void); + fftw_planner (); public: @@ -53,7 +53,7 @@ fftw_planner& operator = (const fftw_planner&) = delete; - ~fftw_planner (void); + ~fftw_planner (); enum FftwMethod { @@ -65,7 +65,7 @@ HYBRID }; - static bool instance_ok (void); + static bool instance_ok (); static void * create_plan (int dir, const int rank, const dim_vector& dims, @@ -90,7 +90,7 @@ : nullptr; } - static FftwMethod method (void) + static FftwMethod method () { static FftwMethod dummy; @@ -106,7 +106,7 @@ static void threads (int nt); - static int threads (void) + static int threads () { return instance_ok () ? s_instance->m_nthreads : 0; } @@ -115,7 +115,7 @@ static fftw_planner *s_instance; - static void cleanup_instance (void) + static void cleanup_instance () { delete s_instance; s_instance = nullptr; } void * @@ -129,7 +129,7 @@ octave_idx_type howmany, octave_idx_type stride, octave_idx_type dist, const double *in, Complex *out); - FftwMethod do_method (void); + FftwMethod do_method (); FftwMethod do_method (FftwMethod meth); @@ -189,7 +189,7 @@ { protected: - float_fftw_planner (void); + float_fftw_planner (); public: @@ -200,7 +200,7 @@ float_fftw_planner& operator = (const float_fftw_planner&) = delete; - ~float_fftw_planner (void); + ~float_fftw_planner (); enum FftwMethod { @@ -212,7 +212,7 @@ HYBRID }; - static bool instance_ok (void); + static bool instance_ok (); static void * create_plan (int dir, const int rank, const dim_vector& dims, @@ -237,7 +237,7 @@ : nullptr; } - static FftwMethod method (void) + static FftwMethod method () { static FftwMethod dummy; @@ -253,7 +253,7 @@ static void threads (int nt); - static int threads (void) + static int threads () { return instance_ok () ? s_instance->m_nthreads : 0; } @@ -262,7 +262,7 @@ static float_fftw_planner *s_instance; - static void cleanup_instance (void) + static void cleanup_instance () { delete s_instance; s_instance = nullptr; } void * @@ -276,7 +276,7 @@ octave_idx_type howmany, octave_idx_type stride, octave_idx_type dist, const float *in, FloatComplex *out); - FftwMethod do_method (void); + FftwMethod do_method (); FftwMethod do_method (FftwMethod meth); @@ -336,7 +336,7 @@ { public: - fftw (void) = delete; + fftw () = delete; // No copying. @@ -378,8 +378,8 @@ const dim_vector&); }; -extern OCTAVE_API std::string fftw_version (void); -extern OCTAVE_API std::string fftwf_version (void); +extern OCTAVE_API std::string fftw_version (); +extern OCTAVE_API std::string fftwf_version (); OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-norm.cc --- a/liboctave/numeric/oct-norm.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-norm.cc Mon Jan 30 18:36:03 2023 +0100 @@ -65,261 +65,261 @@ OCTAVE_BEGIN_NAMESPACE(octave) -// Theory: norm accumulator is an object that has an accum method able -// to handle both real and complex element, and a cast operator -// returning the intermediate norm. Reference: Higham, N. "Estimating -// the Matrix p-Norm." Numer. Math. 62, 539-555, 1992. + // Theory: norm accumulator is an object that has an accum method able + // to handle both real and complex element, and a cast operator + // returning the intermediate norm. Reference: Higham, N. "Estimating + // the Matrix p-Norm." Numer. Math. 62, 539-555, 1992. -// norm accumulator for the p-norm -template -class norm_accumulator_p -{ -public: - norm_accumulator_p () { } // we need this one for Array - norm_accumulator_p (R pp) : m_p(pp), m_scl(0), m_sum(1) { } + // norm accumulator for the p-norm + template + class norm_accumulator_p + { + public: + norm_accumulator_p () { } // we need this one for Array + norm_accumulator_p (R pp) : m_p(pp), m_scl(0), m_sum(1) { } - template - void accum (U val) - { - octave_quit (); - R t = std::abs (val); - if (m_scl == t) // we need this to handle Infs properly - m_sum += 1; - else if (m_scl < t) - { - m_sum *= std::pow (m_scl/t, m_p); + template + void accum (U val) + { + octave_quit (); + R t = std::abs (val); + if (m_scl == t) // we need this to handle Infs properly m_sum += 1; - m_scl = t; - } - else if (t != 0) - m_sum += std::pow (t/m_scl, m_p); - } + else if (m_scl < t) + { + m_sum *= std::pow (m_scl/t, m_p); + m_sum += 1; + m_scl = t; + } + else if (t != 0) + m_sum += std::pow (t/m_scl, m_p); + } + + operator R () { return m_scl * std::pow (m_sum, 1/m_p); } - operator R () { return m_scl * std::pow (m_sum, 1/m_p); } + private: + R m_p, m_scl, m_sum; + }; -private: - R m_p, m_scl, m_sum; -}; + // norm accumulator for the minus p-pseudonorm + template + class norm_accumulator_mp + { + public: + norm_accumulator_mp () { } // we need this one for Array + norm_accumulator_mp (R pp) : m_p(pp), m_scl(0), m_sum(1) { } -// norm accumulator for the minus p-pseudonorm -template -class norm_accumulator_mp -{ -public: - norm_accumulator_mp () { } // we need this one for Array - norm_accumulator_mp (R pp) : m_p(pp), m_scl(0), m_sum(1) { } + template + void accum (U val) + { + octave_quit (); + R t = 1 / std::abs (val); + if (m_scl == t) + m_sum += 1; + else if (m_scl < t) + { + m_sum *= std::pow (m_scl/t, m_p); + m_sum += 1; + m_scl = t; + } + else if (t != 0) + m_sum += std::pow (t/m_scl, m_p); + } - template - void accum (U val) + operator R () { return m_scl * std::pow (m_sum, -1/m_p); } + + private: + R m_p, m_scl, m_sum; + }; + + // norm accumulator for the 2-norm (euclidean) + template + class norm_accumulator_2 { - octave_quit (); - R t = 1 / std::abs (val); - if (m_scl == t) - m_sum += 1; - else if (m_scl < t) - { - m_sum *= std::pow (m_scl/t, m_p); + public: + norm_accumulator_2 () : m_scl(0), m_sum(1) { } + + void accum (R val) + { + R t = std::abs (val); + if (m_scl == t) m_sum += 1; - m_scl = t; - } - else if (t != 0) - m_sum += std::pow (t/m_scl, m_p); - } + else if (m_scl < t) + { + m_sum *= pow2 (m_scl/t); + m_sum += 1; + m_scl = t; + } + else if (t != 0) + m_sum += pow2 (t/m_scl); + } - operator R () { return m_scl * std::pow (m_sum, -1/m_p); } + void accum (std::complex val) + { + accum (val.real ()); + accum (val.imag ()); + } + + operator R () { return m_scl * std::sqrt (m_sum); } + + private: + static inline R pow2 (R x) { return x*x; } + + //-------- -private: - R m_p, m_scl, m_sum; -}; + R m_scl, m_sum; + }; -// norm accumulator for the 2-norm (euclidean) -template -class norm_accumulator_2 -{ -public: - norm_accumulator_2 () : m_scl(0), m_sum(1) { } + // norm accumulator for the 1-norm (city metric) + template + class norm_accumulator_1 + { + public: + norm_accumulator_1 () : m_sum (0) { } + template + void accum (U val) + { + m_sum += std::abs (val); + } - void accum (R val) + operator R () { return m_sum; } + + private: + R m_sum; + }; + + // norm accumulator for the inf-norm (max metric) + template + class norm_accumulator_inf { - R t = std::abs (val); - if (m_scl == t) - m_sum += 1; - else if (m_scl < t) - { - m_sum *= pow2 (m_scl/t); - m_sum += 1; - m_scl = t; - } - else if (t != 0) - m_sum += pow2 (t/m_scl); - } + public: + norm_accumulator_inf () : m_max (0) { } + template + void accum (U val) + { + if (math::isnan (val)) + m_max = numeric_limits::NaN (); + else + m_max = std::max (m_max, std::abs (val)); + } + + operator R () { return m_max; } - void accum (std::complex val) + private: + R m_max; + }; + + // norm accumulator for the -inf pseudonorm (min abs value) + template + class norm_accumulator_minf { - accum (val.real ()); - accum (val.imag ()); - } + public: + norm_accumulator_minf () : m_min (numeric_limits::Inf ()) { } + template + void accum (U val) + { + if (math::isnan (val)) + m_min = numeric_limits::NaN (); + else + m_min = std::min (m_min, std::abs (val)); + } - operator R () { return m_scl * std::sqrt (m_sum); } - -private: - static inline R pow2 (R x) { return x*x; } + operator R () { return m_min; } - //-------- - - R m_scl, m_sum; -}; + private: + R m_min; + }; -// norm accumulator for the 1-norm (city metric) -template -class norm_accumulator_1 -{ -public: - norm_accumulator_1 () : m_sum (0) { } - template - void accum (U val) + // norm accumulator for the 0-pseudonorm (hamming distance) + template + class norm_accumulator_0 { - m_sum += std::abs (val); + public: + norm_accumulator_0 () : m_num (0) { } + template + void accum (U val) + { + if (val != static_cast (0)) ++m_num; + } + + operator R () { return m_num; } + + private: + unsigned int m_num; + }; + + // OK, we're armed :) Now let's go for the fun + + template + inline void vector_norm (const Array& v, R& res, ACC acc) + { + for (octave_idx_type i = 0; i < v.numel (); i++) + acc.accum (v(i)); + + res = acc; } - operator R () { return m_sum; } - -private: - R m_sum; -}; + // dense versions + template + void column_norms (const MArray& m, MArray& res, ACC acc) + { + res = MArray (dim_vector (1, m.columns ())); + for (octave_idx_type j = 0; j < m.columns (); j++) + { + ACC accj = acc; + for (octave_idx_type i = 0; i < m.rows (); i++) + accj.accum (m(i, j)); -// norm accumulator for the inf-norm (max metric) -template -class norm_accumulator_inf -{ -public: - norm_accumulator_inf () : m_max (0) { } - template - void accum (U val) - { - if (math::isnan (val)) - m_max = numeric_limits::NaN (); - else - m_max = std::max (m_max, std::abs (val)); + res.xelem (j) = accj; + } } - operator R () { return m_max; } - -private: - R m_max; -}; - -// norm accumulator for the -inf pseudonorm (min abs value) -template -class norm_accumulator_minf -{ -public: - norm_accumulator_minf () : m_min (numeric_limits::Inf ()) { } - template - void accum (U val) + template + void row_norms (const MArray& m, MArray& res, ACC acc) { - if (math::isnan (val)) - m_min = numeric_limits::NaN (); - else - m_min = std::min (m_min, std::abs (val)); - } - - operator R () { return m_min; } + res = MArray (dim_vector (m.rows (), 1)); + std::vector acci (m.rows (), acc); + for (octave_idx_type j = 0; j < m.columns (); j++) + { + for (octave_idx_type i = 0; i < m.rows (); i++) + acci[i].accum (m(i, j)); + } -private: - R m_min; -}; - -// norm accumulator for the 0-pseudonorm (hamming distance) -template -class norm_accumulator_0 -{ -public: - norm_accumulator_0 () : m_num (0) { } - template - void accum (U val) - { - if (val != static_cast (0)) ++m_num; + for (octave_idx_type i = 0; i < m.rows (); i++) + res.xelem (i) = acci[i]; } - operator R () { return m_num; } - -private: - unsigned int m_num; -}; - -// OK, we're armed :) Now let's go for the fun - -template -inline void vector_norm (const Array& v, R& res, ACC acc) -{ - for (octave_idx_type i = 0; i < v.numel (); i++) - acc.accum (v(i)); + // sparse versions + template + void column_norms (const MSparse& m, MArray& res, ACC acc) + { + res = MArray (dim_vector (1, m.columns ())); + for (octave_idx_type j = 0; j < m.columns (); j++) + { + ACC accj = acc; + for (octave_idx_type k = m.cidx (j); k < m.cidx (j+1); k++) + accj.accum (m.data (k)); - res = acc; -} - -// dense versions -template -void column_norms (const MArray& m, MArray& res, ACC acc) -{ - res = MArray (dim_vector (1, m.columns ())); - for (octave_idx_type j = 0; j < m.columns (); j++) - { - ACC accj = acc; - for (octave_idx_type i = 0; i < m.rows (); i++) - accj.accum (m(i, j)); - - res.xelem (j) = accj; - } -} + res.xelem (j) = accj; + } + } -template -void row_norms (const MArray& m, MArray& res, ACC acc) -{ - res = MArray (dim_vector (m.rows (), 1)); - std::vector acci (m.rows (), acc); - for (octave_idx_type j = 0; j < m.columns (); j++) - { - for (octave_idx_type i = 0; i < m.rows (); i++) - acci[i].accum (m(i, j)); - } - - for (octave_idx_type i = 0; i < m.rows (); i++) - res.xelem (i) = acci[i]; -} + template + void row_norms (const MSparse& m, MArray& res, ACC acc) + { + res = MArray (dim_vector (m.rows (), 1)); + std::vector acci (m.rows (), acc); + for (octave_idx_type j = 0; j < m.columns (); j++) + { + for (octave_idx_type k = m.cidx (j); k < m.cidx (j+1); k++) + acci[m.ridx (k)].accum (m.data (k)); + } -// sparse versions -template -void column_norms (const MSparse& m, MArray& res, ACC acc) -{ - res = MArray (dim_vector (1, m.columns ())); - for (octave_idx_type j = 0; j < m.columns (); j++) - { - ACC accj = acc; - for (octave_idx_type k = m.cidx (j); k < m.cidx (j+1); k++) - accj.accum (m.data (k)); - - res.xelem (j) = accj; - } -} + for (octave_idx_type i = 0; i < m.rows (); i++) + res.xelem (i) = acci[i]; + } -template -void row_norms (const MSparse& m, MArray& res, ACC acc) -{ - res = MArray (dim_vector (m.rows (), 1)); - std::vector acci (m.rows (), acc); - for (octave_idx_type j = 0; j < m.columns (); j++) - { - for (octave_idx_type k = m.cidx (j); k < m.cidx (j+1); k++) - acci[m.ridx (k)].accum (m.data (k)); - } - - for (octave_idx_type i = 0; i < m.rows (); i++) - res.xelem (i) = acci[i]; -} - -// now the dispatchers + // now the dispatchers #define DEFINE_DISPATCHER(FCN_NAME, ARG_TYPE, RES_TYPE) \ template \ RES_TYPE FCN_NAME (const ARG_TYPE& v, R p) \ @@ -345,224 +345,216 @@ return res; \ } -DEFINE_DISPATCHER (vector_norm, MArray, R) -DEFINE_DISPATCHER (column_norms, MArray, MArray) -DEFINE_DISPATCHER (row_norms, MArray, MArray) -DEFINE_DISPATCHER (column_norms, MSparse, MArray) -DEFINE_DISPATCHER (row_norms, MSparse, MArray) + DEFINE_DISPATCHER (vector_norm, MArray, R) + DEFINE_DISPATCHER (column_norms, MArray, MArray) + DEFINE_DISPATCHER (row_norms, MArray, MArray) + DEFINE_DISPATCHER (column_norms, MSparse, MArray) + DEFINE_DISPATCHER (row_norms, MSparse, MArray) -// The approximate subproblem in Higham's method. Find lambda and mu such -// that norm ([lambda, mu], p) == 1 and norm (y*lambda + col*mu, p) is -// maximized. -// Real version. As in Higham's paper. -template -static void -higham_subp (const ColVectorT& y, const ColVectorT& col, - octave_idx_type nsamp, R p, R& lambda, R& mu) -{ - R nrm = 0; - for (octave_idx_type i = 0; i < nsamp; i++) - { - octave_quit (); - R fi = i * static_cast (M_PI) / nsamp; - R lambda1 = cos (fi); - R mu1 = sin (fi); - R lmnr = std::pow (std::pow (std::abs (lambda1), p) + - std::pow (std::abs (mu1), p), 1/p); - lambda1 /= lmnr; mu1 /= lmnr; - R nrm1 = vector_norm (lambda1 * y + mu1 * col, p); - if (nrm1 > nrm) - { - lambda = lambda1; - mu = mu1; - nrm = nrm1; - } - } -} + // The approximate subproblem in Higham's method. Find lambda and mu such + // that norm ([lambda, mu], p) == 1 and norm (y*lambda + col*mu, p) is + // maximized. + // Real version. As in Higham's paper. + template + static void + higham_subp (const ColVectorT& y, const ColVectorT& col, + octave_idx_type nsamp, R p, R& lambda, R& mu) + { + R nrm = 0; + for (octave_idx_type i = 0; i < nsamp; i++) + { + octave_quit (); + R fi = i * static_cast (M_PI) / nsamp; + R lambda1 = cos (fi); + R mu1 = sin (fi); + R lmnr = std::pow (std::pow (std::abs (lambda1), p) + + std::pow (std::abs (mu1), p), 1/p); + lambda1 /= lmnr; mu1 /= lmnr; + R nrm1 = vector_norm (lambda1 * y + mu1 * col, p); + if (nrm1 > nrm) + { + lambda = lambda1; + mu = mu1; + nrm = nrm1; + } + } + } -// Complex version. Higham's paper does not deal with complex case, so we -// use a simple extension. First, guess the magnitudes as in real version, -// then try to rotate lambda to improve further. -template -static void -higham_subp (const ColVectorT& y, const ColVectorT& col, - octave_idx_type nsamp, R p, - std::complex& lambda, std::complex& mu) -{ - typedef std::complex CR; - R nrm = 0; - lambda = 1.0; - CR lamcu = lambda / std::abs (lambda); - // Probe magnitudes - for (octave_idx_type i = 0; i < nsamp; i++) - { - octave_quit (); - R fi = i * static_cast (M_PI) / nsamp; - R lambda1 = cos (fi); - R mu1 = sin (fi); - R lmnr = std::pow (std::pow (std::abs (lambda1), p) + - std::pow (std::abs (mu1), p), 1/p); - lambda1 /= lmnr; mu1 /= lmnr; - R nrm1 = vector_norm (lambda1 * lamcu * y + mu1 * col, p); - if (nrm1 > nrm) - { - lambda = lambda1 * lamcu; - mu = mu1; - nrm = nrm1; - } - } - R lama = std::abs (lambda); - // Probe orientation - for (octave_idx_type i = 0; i < nsamp; i++) - { - octave_quit (); - R fi = i * static_cast (M_PI) / nsamp; - lamcu = CR (cos (fi), sin (fi)); - R nrm1 = vector_norm (lama * lamcu * y + mu * col, p); - if (nrm1 > nrm) - { - lambda = lama * lamcu; - nrm = nrm1; - } - } -} + // Complex version. Higham's paper does not deal with complex case, so we + // use a simple extension. First, guess the magnitudes as in real version, + // then try to rotate lambda to improve further. + template + static void + higham_subp (const ColVectorT& y, const ColVectorT& col, + octave_idx_type nsamp, R p, + std::complex& lambda, std::complex& mu) + { + typedef std::complex CR; + R nrm = 0; + lambda = 1.0; + CR lamcu = lambda / std::abs (lambda); + // Probe magnitudes + for (octave_idx_type i = 0; i < nsamp; i++) + { + octave_quit (); + R fi = i * static_cast (M_PI) / nsamp; + R lambda1 = cos (fi); + R mu1 = sin (fi); + R lmnr = std::pow (std::pow (std::abs (lambda1), p) + + std::pow (std::abs (mu1), p), 1/p); + lambda1 /= lmnr; mu1 /= lmnr; + R nrm1 = vector_norm (lambda1 * lamcu * y + mu1 * col, p); + if (nrm1 > nrm) + { + lambda = lambda1 * lamcu; + mu = mu1; + nrm = nrm1; + } + } + R lama = std::abs (lambda); + // Probe orientation + for (octave_idx_type i = 0; i < nsamp; i++) + { + octave_quit (); + R fi = i * static_cast (M_PI) / nsamp; + lamcu = CR (cos (fi), sin (fi)); + R nrm1 = vector_norm (lama * lamcu * y + mu * col, p); + if (nrm1 > nrm) + { + lambda = lama * lamcu; + nrm = nrm1; + } + } + } -// the p-dual element (should work for both real and complex) -template -inline T elem_dual_p (T x, R p) -{ - return math::signum (x) * std::pow (std::abs (x), p-1); -} + // the p-dual element (should work for both real and complex) + template + inline T elem_dual_p (T x, R p) + { + return math::signum (x) * std::pow (std::abs (x), p-1); + } -// the VectorT is used for vectors, but actually it has to be -// a Matrix type to allow all the operations. For instance SparseMatrix -// does not support multiplication with column/row vectors. -// the dual vector -template -VectorT dual_p (const VectorT& x, R p, R q) -{ - VectorT res (x.dims ()); - for (octave_idx_type i = 0; i < x.numel (); i++) - res.xelem (i) = elem_dual_p (x(i), p); - return res / vector_norm (res, q); -} + // the VectorT is used for vectors, but actually it has to be + // a Matrix type to allow all the operations. For instance SparseMatrix + // does not support multiplication with column/row vectors. + // the dual vector + template + VectorT dual_p (const VectorT& x, R p, R q) + { + VectorT res (x.dims ()); + for (octave_idx_type i = 0; i < x.numel (); i++) + res.xelem (i) = elem_dual_p (x(i), p); + return res / vector_norm (res, q); + } -// Higham's hybrid method -template -R higham (const MatrixT& m, R p, R tol, int maxiter, - VectorT& x) -{ - x.resize (m.columns (), 1); - // the OSE part - VectorT y(m.rows (), 1, 0), z(m.rows (), 1); - typedef typename VectorT::element_type RR; - RR lambda = 0; - RR mu = 1; - for (octave_idx_type k = 0; k < m.columns (); k++) - { - octave_quit (); - VectorT col (m.column (k)); - if (k > 0) - higham_subp (y, col, 4*k, p, lambda, mu); - for (octave_idx_type i = 0; i < k; i++) - x(i) *= lambda; - x(k) = mu; - y = lambda * y + mu * col; - } - - // the PM part - x = x / vector_norm (x, p); - R q = p/(p-1); + // Higham's hybrid method + template + R higham (const MatrixT& m, R p, R tol, int maxiter, + VectorT& x) + { + x.resize (m.columns (), 1); + // the OSE part + VectorT y(m.rows (), 1, 0), z(m.rows (), 1); + typedef typename VectorT::element_type RR; + RR lambda = 0; + RR mu = 1; + for (octave_idx_type k = 0; k < m.columns (); k++) + { + octave_quit (); + VectorT col (m.column (k)); + if (k > 0) + higham_subp (y, col, 4*k, p, lambda, mu); + for (octave_idx_type i = 0; i < k; i++) + x(i) *= lambda; + x(k) = mu; + y = lambda * y + mu * col; + } - R gamma = 0, gamma1; - int iter = 0; - while (iter < maxiter) - { - octave_quit (); - y = m*x; - gamma1 = gamma; - gamma = vector_norm (y, p); - z = dual_p (y, p, q); - z = z.hermitian (); - z = z * m; + // the PM part + x = x / vector_norm (x, p); + R q = p/(p-1); - if (iter > 0 && (vector_norm (z, q) <= gamma - || (gamma - gamma1) <= tol*gamma)) - break; + R gamma = 0, gamma1; + int iter = 0; + while (iter < maxiter) + { + octave_quit (); + y = m*x; + gamma1 = gamma; + gamma = vector_norm (y, p); + z = dual_p (y, p, q); + z = z.hermitian (); + z = z * m; - z = z.hermitian (); - x = dual_p (z, q, p); - iter++; - } + if (iter > 0 && (vector_norm (z, q) <= gamma + || (gamma - gamma1) <= tol*gamma)) + break; - return gamma; -} + z = z.hermitian (); + x = dual_p (z, q, p); + iter++; + } -// derive column vector and SVD types + return gamma; + } -static const char *p_less1_gripe = "xnorm: p must be >= 1"; + // derive column vector and SVD types -// Static constant to control the maximum number of iterations. 100 seems to -// be a good value. Eventually, we can provide a means to change this -// constant from Octave. -static int max_norm_iter = 100; + static const char *p_less1_gripe = "xnorm: p must be >= 1"; -// version with SVD for dense matrices -template -R svd_matrix_norm (const MatrixT& m, R p, VectorT) -{ - // NOTE: The octave:: namespace tags are needed for the following - // function calls until the deprecated inline functions are removed - // from oct-norm.h. + // Static constant to control the maximum number of iterations. 100 seems to + // be a good value. Eventually, we can provide a means to change this + // constant from Octave. + static int max_norm_iter = 100; - R res = 0; - if (p == 2) - { - math::svd fact (m, math::svd::Type::sigma_only); - res = fact.singular_values () (0, 0); - } - else if (p == 1) - res = octave::xcolnorms (m, static_cast (1)).max (); - else if (lo_ieee_isinf (p) && p > 1) - res = octave::xrownorms (m, static_cast (1)).max (); - else if (p > 1) - { - VectorT x; - const R sqrteps = std::sqrt (std::numeric_limits::epsilon ()); - res = higham (m, p, sqrteps, max_norm_iter, x); - } - else - (*current_liboctave_error_handler) ("%s", p_less1_gripe); - - return res; -} + // version with SVD for dense matrices + template + R svd_matrix_norm (const MatrixT& m, R p, VectorT) + { + R res = 0; + if (p == 2) + { + math::svd fact (m, math::svd::Type::sigma_only); + res = fact.singular_values () (0, 0); + } + else if (p == 1) + res = xcolnorms (m, static_cast (1)).max (); + else if (lo_ieee_isinf (p) && p > 1) + res = xrownorms (m, static_cast (1)).max (); + else if (p > 1) + { + VectorT x; + const R sqrteps = std::sqrt (std::numeric_limits::epsilon ()); + res = higham (m, p, sqrteps, max_norm_iter, x); + } + else + (*current_liboctave_error_handler) ("%s", p_less1_gripe); -// SVD-free version for sparse matrices -template -R matrix_norm (const MatrixT& m, R p, VectorT) -{ - // NOTE: The octave:: namespace tags are needed for the following - // function calls until the deprecated inline functions are removed - // from oct-norm.h. + return res; + } - R res = 0; - if (p == 1) - res = octave::xcolnorms (m, static_cast (1)).max (); - else if (lo_ieee_isinf (p) && p > 1) - res = octave::xrownorms (m, static_cast (1)).max (); - else if (p > 1) - { - VectorT x; - const R sqrteps = std::sqrt (std::numeric_limits::epsilon ()); - res = higham (m, p, sqrteps, max_norm_iter, x); - } - else - (*current_liboctave_error_handler) ("%s", p_less1_gripe); + // SVD-free version for sparse matrices + template + R matrix_norm (const MatrixT& m, R p, VectorT) + { + R res = 0; + if (p == 1) + res = xcolnorms (m, static_cast (1)).max (); + else if (lo_ieee_isinf (p) && p > 1) + res = xrownorms (m, static_cast (1)).max (); + else if (p > 1) + { + VectorT x; + const R sqrteps = std::sqrt (std::numeric_limits::epsilon ()); + res = higham (m, p, sqrteps, max_norm_iter, x); + } + else + (*current_liboctave_error_handler) ("%s", p_less1_gripe); - return res; -} + return res; + } -// and finally, here's what we've promised in the header file + // and finally, here's what we've promised in the header file #define DEFINE_XNORM_FCNS(PREFIX, RTYPE) \ RTYPE xnorm (const PREFIX##ColumnVector& x, RTYPE p) \ @@ -582,21 +574,21 @@ return vector_norm (x, static_cast (2)); \ } -DEFINE_XNORM_FCNS(, double) -DEFINE_XNORM_FCNS(Complex, double) -DEFINE_XNORM_FCNS(Float, float) -DEFINE_XNORM_FCNS(FloatComplex, float) + DEFINE_XNORM_FCNS(, double) + DEFINE_XNORM_FCNS(Complex, double) + DEFINE_XNORM_FCNS(Float, float) + DEFINE_XNORM_FCNS(FloatComplex, float) -// this is needed to avoid copying the sparse matrix for xfrobnorm -template -inline void array_norm_2 (const T *v, octave_idx_type n, R& res) -{ - norm_accumulator_2 acc; - for (octave_idx_type i = 0; i < n; i++) - acc.accum (v[i]); + // this is needed to avoid copying the sparse matrix for xfrobnorm + template + inline void array_norm_2 (const T *v, octave_idx_type n, R& res) + { + norm_accumulator_2 acc; + for (octave_idx_type i = 0; i < n; i++) + acc.accum (v[i]); - res = acc; -} + res = acc; + } #define DEFINE_XNORM_SPARSE_FCNS(PREFIX, RTYPE) \ RTYPE xnorm (const Sparse##PREFIX##Matrix& x, RTYPE p) \ @@ -610,8 +602,8 @@ return res; \ } -DEFINE_XNORM_SPARSE_FCNS(, double) -DEFINE_XNORM_SPARSE_FCNS(Complex, double) + DEFINE_XNORM_SPARSE_FCNS(, double) + DEFINE_XNORM_SPARSE_FCNS(Complex, double) #define DEFINE_COLROW_NORM_FCNS(PREFIX, RPREFIX, RTYPE) \ RPREFIX##RowVector \ @@ -625,12 +617,12 @@ return row_norms (m, p); \ } \ -DEFINE_COLROW_NORM_FCNS(,, double) -DEFINE_COLROW_NORM_FCNS(Complex,, double) -DEFINE_COLROW_NORM_FCNS(Float, Float, float) -DEFINE_COLROW_NORM_FCNS(FloatComplex, Float, float) + DEFINE_COLROW_NORM_FCNS(, , double) + DEFINE_COLROW_NORM_FCNS(Complex, , double) + DEFINE_COLROW_NORM_FCNS(Float, Float, float) + DEFINE_COLROW_NORM_FCNS(FloatComplex, Float, float) -DEFINE_COLROW_NORM_FCNS(Sparse,, double) -DEFINE_COLROW_NORM_FCNS(SparseComplex,, double) + DEFINE_COLROW_NORM_FCNS(Sparse, , double) + DEFINE_COLROW_NORM_FCNS(SparseComplex, , double) OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-norm.h --- a/liboctave/numeric/oct-norm.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-norm.h Mon Jan 30 18:36:03 2023 +0100 @@ -32,14 +32,6 @@ #include "oct-cmplx.h" -// The remaining includes can be removed when the deprecated functions -// at the end of this file are removed. - -#include "dColVector.h" -#include "dRowVector.h" -#include "fColVector.h" -#include "fRowVector.h" - OCTAVE_BEGIN_NAMESPACE(octave) extern OCTAVE_API double xnorm (const ColumnVector&, double p = 2); @@ -88,198 +80,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline double xnorm (const ColumnVector& v, double p = 2) -{ - return octave::xnorm (v, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline double xnorm (const RowVector& v, double p = 2) -{ - return octave::xnorm (v, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline double xnorm (const Matrix& m, double p = 2) -{ - return octave::xnorm (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xfrobnorm' instead") -inline double xfrobnorm (const Matrix& m) -{ - return octave::xfrobnorm (m); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline double xnorm (const ComplexColumnVector& v, double p = 2) -{ - return octave::xnorm (v, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline double xnorm (const ComplexRowVector& v, double p = 2) -{ - return octave::xnorm (v, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline double xnorm (const ComplexMatrix& m, double p = 2) -{ - return octave::xnorm (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xfrobnorm' instead") -inline double xfrobnorm (const ComplexMatrix& m) -{ - return octave::xfrobnorm (m); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline float xnorm (const FloatColumnVector& v, float p = 2) -{ - return octave::xnorm (v, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline float xnorm (const FloatRowVector& v, float p = 2) -{ - return octave::xnorm (v, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline float xnorm (const FloatMatrix& m, float p = 2) -{ - return octave::xnorm (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xfrobnorm' instead") -inline float xfrobnorm (const FloatMatrix& m) -{ - return octave::xfrobnorm (m); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline float xnorm (const FloatComplexColumnVector& v, float p = 2) -{ - return octave::xnorm (v, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline float xnorm (const FloatComplexRowVector& v, float p = 2) -{ - return octave::xnorm (v, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline float xnorm (const FloatComplexMatrix& m, float p = 2) -{ - return octave::xnorm (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xfrobnorm' instead") -inline float xfrobnorm (const FloatComplexMatrix& m) -{ - return octave::xfrobnorm (m); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline double xnorm (const SparseMatrix& m, double p = 2) -{ - return octave::xnorm (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xfrobnorm' instead") -inline double xfrobnorm (const SparseMatrix& m) -{ - return octave::xfrobnorm (m); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xnorm' instead") -inline double xnorm (const SparseComplexMatrix& m, double p = 2) -{ - return octave::xnorm (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xfrobnorm' instead") -inline double xfrobnorm (const SparseComplexMatrix& m) -{ - return octave::xfrobnorm (m); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xcolnorms' instead") -inline RowVector xcolnorms (const Matrix& m, double p = 2) -{ - return octave::xcolnorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xrownorms' instead") -inline ColumnVector xrownorms (const Matrix& m, double p = 2) -{ - return octave::xrownorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xcolnorms' instead") -inline RowVector xcolnorms (const ComplexMatrix& m, double p = 2) -{ - return octave::xcolnorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xrownorms' instead") -inline ColumnVector xrownorms (const ComplexMatrix& m, double p = 2) -{ - return octave::xrownorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xcolnorms' instead") -inline FloatRowVector xcolnorms (const FloatMatrix& m, float p = 2) -{ - return octave::xcolnorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xrownorms' instead") -inline FloatColumnVector xrownorms (const FloatMatrix& m, float p = 2) -{ - return octave::xrownorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xcolnorms' instead") -inline FloatRowVector xcolnorms (const FloatComplexMatrix& m, float p = 2) -{ - return octave::xcolnorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xrownorms' instead") -inline FloatColumnVector xrownorms (const FloatComplexMatrix& m, float p = 2) -{ - return octave::xrownorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xcolnorms' instead") -inline RowVector xcolnorms (const SparseMatrix& m, double p = 2) -{ - return octave::xcolnorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xrownorms' instead") -inline ColumnVector xrownorms (const SparseMatrix& m, double p = 2) -{ - return octave::xrownorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xcolnorms' instead") -inline RowVector xcolnorms (const SparseComplexMatrix& m, double p = 2) -{ - return octave::xcolnorms (m, p); -} - -OCTAVE_DEPRECATED (7, "use 'octave::xrownorms' instead") -inline ColumnVector xrownorms (const SparseComplexMatrix& m, double p = 2) -{ - return octave::xrownorms (m, p); -} #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-rand.cc --- a/liboctave/numeric/oct-rand.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-rand.cc Mon Jan 30 18:36:03 2023 +0100 @@ -50,7 +50,7 @@ rand *rand::m_instance = nullptr; -rand::rand (void) +rand::rand () : m_current_distribution (uniform_dist), m_use_old_generators (false), m_rand_states () { @@ -59,7 +59,7 @@ initialize_mersenne_twister (); } -bool rand::instance_ok (void) +bool rand::instance_ok () { bool retval = true; @@ -72,7 +72,7 @@ return retval; } -double rand::do_seed (void) +double rand::do_seed () { union d2i { double d; int32_t i[2]; }; union d2i u; @@ -135,7 +135,7 @@ F77_FUNC (setsd, SETSD) (i0, i1); } -void rand::do_reset (void) +void rand::do_reset () { m_use_old_generators = true; initialize_ranlib_generators (); @@ -187,7 +187,7 @@ m_rand_states[old_dist] = saved_state; } -std::string rand::do_distribution (void) +std::string rand::do_distribution () { std::string retval; @@ -255,35 +255,35 @@ } } -void rand::do_uniform_distribution (void) +void rand::do_uniform_distribution () { switch_to_generator (uniform_dist); F77_FUNC (setcgn, SETCGN) (uniform_dist); } -void rand::do_normal_distribution (void) +void rand::do_normal_distribution () { switch_to_generator (normal_dist); F77_FUNC (setcgn, SETCGN) (normal_dist); } -void rand::do_exponential_distribution (void) +void rand::do_exponential_distribution () { switch_to_generator (expon_dist); F77_FUNC (setcgn, SETCGN) (expon_dist); } -void rand::do_poisson_distribution (void) +void rand::do_poisson_distribution () { switch_to_generator (poisson_dist); F77_FUNC (setcgn, SETCGN) (poisson_dist); } -void rand::do_gamma_distribution (void) +void rand::do_gamma_distribution () { switch_to_generator (gamma_dist); @@ -291,7 +291,7 @@ } template <> -OCTAVE_API double rand::uniform (void) +OCTAVE_API double rand::uniform () { double retval; @@ -304,7 +304,7 @@ } template <> -OCTAVE_API double rand::normal (void) +OCTAVE_API double rand::normal () { double retval; @@ -317,7 +317,7 @@ } template <> -OCTAVE_API double rand::exponential (void) +OCTAVE_API double rand::exponential () { double retval; @@ -370,7 +370,7 @@ } template <> -OCTAVE_API float rand::uniform (void) +OCTAVE_API float rand::uniform () { float retval; @@ -383,7 +383,7 @@ } template <> -OCTAVE_API float rand::normal (void) +OCTAVE_API float rand::normal () { float retval; @@ -396,7 +396,7 @@ } template <> -OCTAVE_API float rand::exponential (void) +OCTAVE_API float rand::exponential () { float retval; @@ -549,7 +549,7 @@ // technique used below will cycle monthly, but it does seem to // work ok to give fairly different seeds each time Octave starts. -void rand::initialize_ranlib_generators (void) +void rand::initialize_ranlib_generators () { sys::localtime tm; int stored_distribution = m_current_distribution; @@ -569,7 +569,7 @@ F77_FUNC (setcgn, SETCGN) (stored_distribution); } -void rand::initialize_mersenne_twister (void) +void rand::initialize_mersenne_twister () { uint32NDArray s; @@ -598,7 +598,7 @@ set_internal_state (m_rand_states[m_current_distribution]); } -uint32NDArray rand::get_internal_state (void) +uint32NDArray rand::get_internal_state () { uint32NDArray s (dim_vector (MT_N + 1, 1)); @@ -607,7 +607,7 @@ return s; } -void rand::save_state (void) +void rand::save_state () { m_rand_states[m_current_distribution] = get_internal_state ();; } @@ -664,21 +664,21 @@ { case uniform_dist: if (m_use_old_generators) - std::generate_n (v, len, [](void) { double x; F77_FUNC (dgenunf, DGENUNF) (0.0, 1.0, x); return x; }); + std::generate_n (v, len, []() { double x; F77_FUNC (dgenunf, DGENUNF) (0.0, 1.0, x); return x; }); else rand_uniform (len, v); break; case normal_dist: if (m_use_old_generators) - std::generate_n (v, len, [](void) { double x; F77_FUNC (dgennor, DGENNOR) (0.0, 1.0, x); return x; }); + std::generate_n (v, len, []() { double x; F77_FUNC (dgennor, DGENNOR) (0.0, 1.0, x); return x; }); else rand_normal (len, v); break; case expon_dist: if (m_use_old_generators) - std::generate_n (v, len, [](void) { double x; F77_FUNC (dgenexp, DGENEXP) (1.0, x); return x; }); + std::generate_n (v, len, []() { double x; F77_FUNC (dgenexp, DGENEXP) (1.0, x); return x; }); else rand_exponential (len, v); break; @@ -693,7 +693,7 @@ // workaround bug in ignpoi, by calling with different Mu double tmp; F77_FUNC (dignpoi, DIGNPOI) (a + 1, tmp); - std::generate_n (v, len, [a](void) { double x; F77_FUNC (dignpoi, DIGNPOI) (a, x); return x; }); + std::generate_n (v, len, [a]() { double x; F77_FUNC (dignpoi, DIGNPOI) (a, x); return x; }); } } else @@ -706,7 +706,7 @@ if (a <= 0.0 || ! math::isfinite (a)) std::fill_n (v, len, numeric_limits::NaN ()); else - std::generate_n (v, len, [a](void) { double x; F77_FUNC (dgengam, DGENGAM) (1.0, a, x); return x; }); + std::generate_n (v, len, [a]() { double x; F77_FUNC (dgengam, DGENGAM) (1.0, a, x); return x; }); } else rand_gamma (a, len, v); @@ -732,21 +732,21 @@ { case uniform_dist: if (m_use_old_generators) - std::generate_n (v, len, [](void) { float x; F77_FUNC (fgenunf, FGENUNF) (0.0f, 1.0f, x); return x; }); + std::generate_n (v, len, []() { float x; F77_FUNC (fgenunf, FGENUNF) (0.0f, 1.0f, x); return x; }); else rand_uniform (len, v); break; case normal_dist: if (m_use_old_generators) - std::generate_n (v, len, [](void) { float x; F77_FUNC (fgennor, FGENNOR) (0.0f, 1.0f, x); return x; }); + std::generate_n (v, len, []() { float x; F77_FUNC (fgennor, FGENNOR) (0.0f, 1.0f, x); return x; }); else rand_normal (len, v); break; case expon_dist: if (m_use_old_generators) - std::generate_n (v, len, [](void) { float x; F77_FUNC (fgenexp, FGENEXP) (1.0f, x); return x; }); + std::generate_n (v, len, []() { float x; F77_FUNC (fgenexp, FGENEXP) (1.0f, x); return x; }); else rand_exponential (len, v); break; @@ -761,7 +761,7 @@ // workaround bug in ignpoi, by calling with different Mu float tmp; F77_FUNC (fignpoi, FIGNPOI) (a + 1, tmp); - std::generate_n (v, len, [a](void) { float x; F77_FUNC (fignpoi, FIGNPOI) (a, x); return x; }); + std::generate_n (v, len, [a]() { float x; F77_FUNC (fignpoi, FIGNPOI) (a, x); return x; }); } } else @@ -774,7 +774,7 @@ if (a <= 0.0f || ! math::isfinite (a)) std::fill_n (v, len, numeric_limits::NaN ()); else - std::generate_n (v, len, [a](void) { float x; F77_FUNC (fgengam, FGENGAM) (1.0f, a, x); return x; }); + std::generate_n (v, len, [a]() { float x; F77_FUNC (fgengam, FGENGAM) (1.0f, a, x); return x; }); } else rand_gamma (a, len, v); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-rand.h --- a/liboctave/numeric/oct-rand.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-rand.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,16 +45,16 @@ { protected: - OCTAVE_API rand (void); + OCTAVE_API rand (); public: - ~rand (void) = default; + ~rand () = default; - static bool instance_ok (void); + static bool instance_ok (); // Return the current seed. - static double seed (void) + static double seed () { return (instance_ok () ? m_instance->do_seed () : numeric_limits::NaN ()); @@ -68,7 +68,7 @@ } // Reset the seed. - static void reset (void) + static void reset () { if (instance_ok ()) m_instance->do_reset (); @@ -96,7 +96,7 @@ } // Return the current distribution. - static std::string distribution (void) + static std::string distribution () { return instance_ok () ? m_instance->do_distribution () : ""; } @@ -109,31 +109,31 @@ m_instance->do_distribution (d); } - static void uniform_distribution (void) + static void uniform_distribution () { if (instance_ok ()) m_instance->do_uniform_distribution (); } - static void normal_distribution (void) + static void normal_distribution () { if (instance_ok ()) m_instance->do_normal_distribution (); } - static void exponential_distribution (void) + static void exponential_distribution () { if (instance_ok ()) m_instance->do_exponential_distribution (); } - static void poisson_distribution (void) + static void poisson_distribution () { if (instance_ok ()) m_instance->do_poisson_distribution (); } - static void gamma_distribution (void) + static void gamma_distribution () { if (instance_ok ()) m_instance->do_gamma_distribution (); @@ -184,7 +184,7 @@ static rand *m_instance; - static void cleanup_instance (void) + static void cleanup_instance () { delete m_instance; m_instance = nullptr; } enum @@ -208,7 +208,7 @@ std::map m_rand_states; // Return the current seed. - OCTAVE_API double do_seed (void); + OCTAVE_API double do_seed (); // Set the seed. OCTAVE_API void do_seed (double s); @@ -226,30 +226,30 @@ OCTAVE_API void do_reset (const std::string& d); // Return the current distribution. - OCTAVE_API std::string do_distribution (void); + OCTAVE_API std::string do_distribution (); // Set the current distribution. May be either "uniform" (the // default), "normal", "exponential", "poisson", or "gamma". OCTAVE_API void do_distribution (const std::string& d); - OCTAVE_API void do_uniform_distribution (void); + OCTAVE_API void do_uniform_distribution (); - OCTAVE_API void do_normal_distribution (void); + OCTAVE_API void do_normal_distribution (); - OCTAVE_API void do_exponential_distribution (void); + OCTAVE_API void do_exponential_distribution (); - OCTAVE_API void do_poisson_distribution (void); + OCTAVE_API void do_poisson_distribution (); - OCTAVE_API void do_gamma_distribution (void); + OCTAVE_API void do_gamma_distribution (); // The following templates only make sense for double and float // types. - template OCTAVE_API T uniform (void); + template OCTAVE_API T uniform (); - template OCTAVE_API T normal (void); + template OCTAVE_API T normal (); - template OCTAVE_API T exponential (void); + template OCTAVE_API T exponential (); template OCTAVE_API T poisson (T a); @@ -273,13 +273,13 @@ // Some helper functions. - OCTAVE_API void initialize_ranlib_generators (void); + OCTAVE_API void initialize_ranlib_generators (); - OCTAVE_API void initialize_mersenne_twister (void); + OCTAVE_API void initialize_mersenne_twister (); - OCTAVE_API uint32NDArray get_internal_state (void); + OCTAVE_API uint32NDArray get_internal_state (); - OCTAVE_API void save_state (void); + OCTAVE_API void save_state (); OCTAVE_API int get_dist_id (const std::string& d); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-spparms.cc --- a/liboctave/numeric/oct-spparms.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-spparms.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ sparse_params *sparse_params::s_instance = nullptr; -bool sparse_params::instance_ok (void) +bool sparse_params::instance_ok () { bool retval = true; @@ -52,24 +52,24 @@ return retval; } -void sparse_params::defaults (void) +void sparse_params::defaults () { if (instance_ok ()) s_instance->do_defaults (); } -void sparse_params::tight (void) +void sparse_params::tight () { if (instance_ok ()) s_instance->do_tight (); } -string_vector sparse_params::get_keys (void) +string_vector sparse_params::get_keys () { return instance_ok () ? s_instance->do_get_keys () : string_vector (); } -ColumnVector sparse_params::get_vals (void) +ColumnVector sparse_params::get_vals () { return instance_ok () ? s_instance->do_get_vals () : ColumnVector (); } @@ -90,7 +90,7 @@ ? s_instance->do_get_key (key) : numeric_limits::NaN ()); } -double sparse_params::get_bandden (void) +double sparse_params::get_bandden () { return instance_ok () ? s_instance->do_get_bandden () : 0.0; } @@ -101,7 +101,7 @@ s_instance->do_print_info (os, prefix); } -void sparse_params::do_defaults (void) +void sparse_params::do_defaults () { m_params(0) = 0; // spumoni m_params(1) = 1; // ths_rel @@ -118,7 +118,7 @@ m_params(12) = 0.001; // sym_tol } -void sparse_params::do_tight (void) +void sparse_params::do_tight () { m_params(0) = 0; // spumoni m_params(1) = 1; // ths_rel @@ -135,7 +135,7 @@ m_params(12) = 0.001; // sym_tol } -void sparse_params::init_keys (void) +void sparse_params::init_keys () { m_keys(0) = "spumoni"; m_keys(1) = "ths_rel"; @@ -152,7 +152,7 @@ m_keys(12) = "sym_tol"; } -double sparse_params::do_get_bandden (void) +double sparse_params::do_get_bandden () { return m_params(10); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/oct-spparms.h --- a/liboctave/numeric/oct-spparms.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/oct-spparms.h Mon Jan 30 18:36:03 2023 +0100 @@ -43,7 +43,7 @@ { protected: - sparse_params (void) + sparse_params () : m_params (OCTAVE_SPARSE_CONTROLS_SIZE), m_keys (OCTAVE_SPARSE_CONTROLS_SIZE) { @@ -57,17 +57,17 @@ sparse_params& operator = (const sparse_params&) = default; - ~sparse_params (void) = default; + ~sparse_params () = default; - static bool instance_ok (void); + static bool instance_ok (); - static void defaults (void); + static void defaults (); - static void tight (void); + static void tight (); - static string_vector get_keys (void); + static string_vector get_keys (); - static ColumnVector get_vals (void); + static ColumnVector get_vals (); static bool set_vals (const Array& vals); @@ -75,7 +75,7 @@ static double get_key (const std::string& key); - static double get_bandden (void); + static double get_bandden (); static void print_info (std::ostream& os, const std::string& prefix); @@ -87,19 +87,19 @@ static sparse_params *s_instance; - static void cleanup_instance (void) + static void cleanup_instance () { delete s_instance; s_instance = nullptr; } - void do_defaults (void); + void do_defaults (); - void do_tight (void); + void do_tight (); - string_vector do_get_keys (void) const { return m_keys; } + string_vector do_get_keys () const { return m_keys; } - ColumnVector do_get_vals (void) const { return m_params; } + ColumnVector do_get_vals () const { return m_params; } bool do_set_vals (const Array& vals); @@ -107,18 +107,13 @@ double do_get_key (const std::string& key); - double do_get_bandden (void); + double do_get_bandden (); void do_print_info (std::ostream& os, const std::string& prefix) const; - void init_keys (void); + void init_keys (); }; OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "use 'octave::sparse_params' instead") -typedef octave::sparse_params octave_sparse_params; #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/qr.cc --- a/liboctave/numeric/qr.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/qr.cc Mon Jan 30 18:36:03 2023 +0100 @@ -70,7 +70,7 @@ template typename qr::type -qr::get_type (void) const +qr::get_type () const { type retval; @@ -86,7 +86,7 @@ template bool -qr::regular (void) const +qr::regular () const { bool retval = true; @@ -109,7 +109,7 @@ // Replacement update methods. void -warn_qrupdate_once (void) +warn_qrupdate_once () { static bool warned = false; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/qr.h --- a/liboctave/numeric/qr.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/qr.h Mon Jan 30 18:36:03 2023 +0100 @@ -51,7 +51,7 @@ economy }; - qr (void) : m_q (), m_r () { } + qr () : m_q (), m_r () { } qr (const T& a, type qr_type = qr::std) : m_q (), m_r () @@ -74,15 +74,15 @@ return *this; } - virtual ~qr (void) = default; + virtual ~qr () = default; - T Q (void) const { return m_q; } + T Q () const { return m_q; } - T R (void) const { return m_r; } + T R () const { return m_r; } - OCTAVE_API type get_type (void) const; + OCTAVE_API type get_type () const; - OCTAVE_API bool regular (void) const; + OCTAVE_API bool regular () const; OCTAVE_API void init (const T& a, type qr_type); @@ -113,7 +113,7 @@ form (octave_idx_type n, T& afact, ELT_T *tau, type qr_type); }; -extern OCTAVE_API void warn_qrupdate_once (void); +extern OCTAVE_API void warn_qrupdate_once (); OCTAVE_END_NAMESPACE(math) OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/qrp.cc --- a/liboctave/numeric/qrp.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/qrp.cc Mon Jan 30 18:36:03 2023 +0100 @@ -113,7 +113,7 @@ template <> OCTAVE_API RowVector -qrp::Pvec (void) const +qrp::Pvec () const { Array pa (m_p.col_perm_vec ()); RowVector pv (MArray (pa) + 1.0); @@ -184,7 +184,7 @@ template <> OCTAVE_API FloatRowVector -qrp::Pvec (void) const +qrp::Pvec () const { Array pa (m_p.col_perm_vec ()); FloatRowVector pv (MArray (pa) + 1.0f); @@ -263,7 +263,7 @@ template <> OCTAVE_API RowVector -qrp::Pvec (void) const +qrp::Pvec () const { Array pa (m_p.col_perm_vec ()); RowVector pv (MArray (pa) + 1.0); @@ -342,7 +342,7 @@ template <> OCTAVE_API FloatRowVector -qrp::Pvec (void) const +qrp::Pvec () const { Array pa (m_p.col_perm_vec ()); FloatRowVector pv (MArray (pa) + 1.0f); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/qrp.h --- a/liboctave/numeric/qrp.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/qrp.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,7 +45,7 @@ typedef typename qr::type type; - qrp (void) : qr (), m_p () { } + qrp () : qr (), m_p () { } OCTAVE_API qrp (const T&, type = qr::std); @@ -62,13 +62,13 @@ return *this; } - ~qrp (void) = default; + ~qrp () = default; OCTAVE_API void init (const T&, type = qr::std); - PermMatrix P (void) const { return m_p; } + PermMatrix P () const { return m_p; } - OCTAVE_API RV_T Pvec (void) const; + OCTAVE_API RV_T Pvec () const; private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/randmtzig.cc --- a/liboctave/numeric/randmtzig.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/randmtzig.cc Mon Jan 30 18:36:03 2023 +0100 @@ -121,7 +121,7 @@ === Mersenne Twister === random initial state: - void init_mersenne_twister (void) + void init_mersenne_twister () // 32-bit initial state: void init_mersenne_twister (uint32_t s) @@ -135,18 +135,18 @@ // restores state from array void set_mersenne_twister_state (uint32_t save[MT_N+1]) - static uint32_t randmt (void) returns 32-bit unsigned int + static uint32_t randmt () returns 32-bit unsigned int === inline generators === - static uint32_t randi32 (void) returns 32-bit unsigned int - static uint64_t randi53 (void) returns 53-bit unsigned int - static uint64_t randi54 (void) returns 54-bit unsigned int - static float randu24 (void) returns 24-bit uniform in (0,1) - static double randu53 (void) returns 53-bit uniform in (0,1) + static uint32_t randi32 () returns 32-bit unsigned int + static uint64_t randi53 () returns 53-bit unsigned int + static uint64_t randi54 () returns 54-bit unsigned int + static float randu24 () returns 24-bit uniform in (0,1) + static double randu53 () returns 53-bit uniform in (0,1) - double rand_uniform (void) returns M-bit uniform in (0,1) - double rand_normal (void) returns M-bit standard normal - double rand_exponential (void) returns N-bit standard exponential + double rand_uniform () returns M-bit uniform in (0,1) + double rand_normal () returns M-bit standard normal + double rand_exponential () returns N-bit standard exponential === Array generators === void rand_uniform (octave_idx_type, double []) @@ -257,7 +257,7 @@ initf = 1; } -void init_mersenne_twister (void) +void init_mersenne_twister () { uint32_t entropy[MT_N]; int n = 0; @@ -321,7 +321,7 @@ save[MT_N] = left; } -static void next_state (void) +static void next_state () { uint32_t *p = state; int j; @@ -346,7 +346,7 @@ } /* generates a random number on [0,0xffffffff]-interval */ -static uint32_t randmt (void) +static uint32_t randmt () { uint32_t y; @@ -366,7 +366,7 @@ /* Select which 32 bit generator to use */ #define randi32 randmt -static uint64_t randi53 (void) +static uint64_t randi53 () { const uint32_t lo = randi32 (); const uint32_t hi = randi32 () & 0x1FFFFF; @@ -381,7 +381,7 @@ #endif } -static uint64_t randi54 (void) +static uint64_t randi54 () { const uint32_t lo = randi32 (); const uint32_t hi = randi32 () & 0x3FFFFF; @@ -397,7 +397,7 @@ } /* generates a random number on (0,1)-real-interval */ -static float randu24 (void) +static float randu24 () { uint32_t i; @@ -411,7 +411,7 @@ } /* generates a random number on (0,1) with 53-bit resolution */ -static double randu53 (void) +static double randu53 () { int32_t a, b; @@ -428,7 +428,7 @@ /* Determine mantissa for uniform doubles */ template <> OCTAVE_API double -rand_uniform (void) +rand_uniform () { return randu53 (); } @@ -436,7 +436,7 @@ /* Determine mantissa for uniform floats */ template <> OCTAVE_API float -rand_uniform (void) +rand_uniform () { return randu24 (); } @@ -503,7 +503,7 @@ so I'm not going to try and optimize further. */ -void create_ziggurat_tables (void) +void create_ziggurat_tables () { int i; double x, x1; @@ -582,7 +582,7 @@ */ -template <> OCTAVE_API double rand_normal (void) +template <> OCTAVE_API double rand_normal () { if (initt) create_ziggurat_tables (); @@ -646,7 +646,7 @@ } } -template <> OCTAVE_API double rand_exponential (void) +template <> OCTAVE_API double rand_exponential () { if (initt) create_ziggurat_tables (); @@ -674,17 +674,17 @@ template <> OCTAVE_API void rand_uniform (octave_idx_type n, double *p) { - std::generate_n (p, n, [](void) { return rand_uniform (); }); + std::generate_n (p, n, []() { return rand_uniform (); }); } template <> OCTAVE_API void rand_normal (octave_idx_type n, double *p) { - std::generate_n (p, n, [](void) { return rand_normal (); }); + std::generate_n (p, n, []() { return rand_normal (); }); } template <> OCTAVE_API void rand_exponential (octave_idx_type n, double *p) { - std::generate_n (p, n, [](void) { return rand_exponential (); }); + std::generate_n (p, n, []() { return rand_exponential (); }); } #undef ZIGINT @@ -706,7 +706,7 @@ static ZIGINT fke[ZIGGURAT_TABLE_SIZE]; static float fwe[ZIGGURAT_TABLE_SIZE], ffe[ZIGGURAT_TABLE_SIZE]; -static void create_ziggurat_float_tables (void) +static void create_ziggurat_float_tables () { int i; float x, x1; @@ -784,7 +784,7 @@ * distribution is exp(-0.5*x*x) */ -template <> OCTAVE_API float rand_normal (void) +template <> OCTAVE_API float rand_normal () { if (inittf) create_ziggurat_float_tables (); @@ -824,7 +824,7 @@ } } -template <> OCTAVE_API float rand_exponential (void) +template <> OCTAVE_API float rand_exponential () { if (inittf) create_ziggurat_float_tables (); @@ -852,17 +852,17 @@ template <> OCTAVE_API void rand_uniform (octave_idx_type n, float *p) { - std::generate_n (p, n, [](void) { return rand_uniform (); }); + std::generate_n (p, n, []() { return rand_uniform (); }); } template <> OCTAVE_API void rand_normal (octave_idx_type n, float *p) { - std::generate_n (p, n, [](void) { return rand_normal (); }); + std::generate_n (p, n, []() { return rand_normal (); }); } template <> OCTAVE_API void rand_exponential (octave_idx_type n, float *p) { - std::generate_n (p, n, [](void) { return rand_exponential (); }); + std::generate_n (p, n, []() { return rand_exponential (); }); } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/randmtzig.h --- a/liboctave/numeric/randmtzig.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/randmtzig.h Mon Jan 30 18:36:03 2023 +0100 @@ -75,7 +75,7 @@ // Mersenne Twister. -extern OCTAVE_API void init_mersenne_twister (void); +extern OCTAVE_API void init_mersenne_twister (); extern OCTAVE_API void init_mersenne_twister (const uint32_t seed); extern OCTAVE_API void init_mersenne_twister (const uint32_t *init_key, const int key_length); @@ -83,22 +83,22 @@ extern OCTAVE_API void set_mersenne_twister_state (const uint32_t *save); extern OCTAVE_API void get_mersenne_twister_state (uint32_t *save); -template OCTAVE_API T rand_uniform (void); -template OCTAVE_API T rand_normal (void); -template OCTAVE_API T rand_exponential (void); +template OCTAVE_API T rand_uniform (); +template OCTAVE_API T rand_normal (); +template OCTAVE_API T rand_exponential (); template OCTAVE_API void rand_uniform (octave_idx_type n, T *p); template OCTAVE_API void rand_normal (octave_idx_type n, T *p); template OCTAVE_API void rand_exponential (octave_idx_type n, T *p); -template <> OCTAVE_API double rand_uniform (void); -template <> OCTAVE_API double rand_normal (void); -template <> OCTAVE_API double rand_exponential (void); +template <> OCTAVE_API double rand_uniform (); +template <> OCTAVE_API double rand_normal (); +template <> OCTAVE_API double rand_exponential (); -template <> OCTAVE_API float rand_uniform (void); -template <> OCTAVE_API float rand_normal (void); -template <> OCTAVE_API float rand_exponential (void); +template <> OCTAVE_API float rand_uniform (); +template <> OCTAVE_API float rand_normal (); +template <> OCTAVE_API float rand_exponential (); template <> OCTAVE_API void rand_uniform (octave_idx_type n, double *p); diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/schur.h --- a/liboctave/numeric/schur.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/schur.h Mon Jan 30 18:36:03 2023 +0100 @@ -47,7 +47,7 @@ { public: - schur (void) : m_schur_mat (), m_unitary_schur_mat () { } + schur () : m_schur_mat (), m_unitary_schur_mat () { } schur (const T& a, const std::string& ord, bool calc_unitary = true) : m_schur_mat (), m_unitary_schur_mat () @@ -84,11 +84,11 @@ return *this; } - ~schur (void) = default; + ~schur () = default; - T schur_matrix (void) const { return m_schur_mat; } + T schur_matrix () const { return m_schur_mat; } - T unitary_schur_matrix (void) const { return m_unitary_schur_mat; } + T unitary_schur_matrix () const { return m_unitary_schur_mat; } protected: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/sparse-chol.cc --- a/liboctave/numeric/sparse-chol.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/sparse-chol.cc Mon Jan 30 18:36:03 2023 +0100 @@ -50,7 +50,7 @@ { public: - sparse_chol_rep (void) + sparse_chol_rep () : m_is_pd (false), m_minor_p (0), m_perm (), m_rcond (0) #if defined (HAVE_CHOLMOD) , m_L (nullptr), m_common () @@ -82,7 +82,7 @@ sparse_chol_rep& operator = (const sparse_chol_rep&) = delete; - ~sparse_chol_rep (void) + ~sparse_chol_rep () { #if defined (HAVE_CHOLMOD) if (m_L) @@ -93,13 +93,13 @@ } #if defined (HAVE_CHOLMOD) - cholmod_sparse * L (void) const + cholmod_sparse * L () const { return m_L; } #endif - octave_idx_type P (void) const + octave_idx_type P () const { #if defined (HAVE_CHOLMOD) return (m_minor_p == static_cast (m_L->ncol) ? @@ -109,13 +109,13 @@ #endif } - RowVector perm (void) const { return m_perm + 1; } + RowVector perm () const { return m_perm + 1; } - SparseMatrix Q (void) const; + SparseMatrix Q () const; - bool is_positive_definite (void) const { return m_is_pd; } + bool is_positive_definite () const { return m_is_pd; } - double rcond (void) const { return m_rcond; } + double rcond () const { return m_rcond; } private: @@ -186,18 +186,18 @@ // Must provide a specialization for this function. template int -get_xtype (void); +get_xtype (); template <> inline int -get_xtype (void) +get_xtype () { return CHOLMOD_REAL; } template <> inline int -get_xtype (void) +get_xtype () { return CHOLMOD_COMPLEX; } @@ -352,7 +352,7 @@ template SparseMatrix -sparse_chol::sparse_chol_rep::Q (void) const +sparse_chol::sparse_chol_rep::Q () const { #if defined (HAVE_CHOLMOD) @@ -378,7 +378,7 @@ } template -sparse_chol::sparse_chol (void) +sparse_chol::sparse_chol () : m_rep (new typename sparse_chol::sparse_chol_rep ()) { } @@ -414,7 +414,7 @@ template chol_type -sparse_chol::L (void) const +sparse_chol::L () const { #if defined (HAVE_CHOLMOD) @@ -445,42 +445,42 @@ template octave_idx_type -sparse_chol::P (void) const +sparse_chol::P () const { return m_rep->P (); } template RowVector -sparse_chol::perm (void) const +sparse_chol::perm () const { return m_rep->perm (); } template SparseMatrix -sparse_chol::Q (void) const +sparse_chol::Q () const { return m_rep->Q (); } template bool -sparse_chol::is_positive_definite (void) const +sparse_chol::is_positive_definite () const { return m_rep->is_positive_definite (); } template double -sparse_chol::rcond (void) const +sparse_chol::rcond () const { return m_rep->rcond (); } template chol_type -sparse_chol::inverse (void) const +sparse_chol::inverse () const { chol_type retval; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/sparse-chol.h --- a/liboctave/numeric/sparse-chol.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/sparse-chol.h Mon Jan 30 18:36:03 2023 +0100 @@ -50,7 +50,7 @@ { public: - sparse_chol (void); + sparse_chol (); sparse_chol (const chol_type& a, bool natural, bool force); @@ -63,26 +63,26 @@ sparse_chol (const sparse_chol& a) = default; - virtual ~sparse_chol (void) = default; + virtual ~sparse_chol () = default; sparse_chol& operator = (const sparse_chol& a) = default; - chol_type L (void) const; + chol_type L () const; - chol_type R (void) const { return L ().hermitian (); } + chol_type R () const { return L ().hermitian (); } - octave_idx_type P (void) const; + octave_idx_type P () const; - RowVector perm (void) const; + RowVector perm () const; - SparseMatrix Q (void) const; + SparseMatrix Q () const; - bool is_positive_definite (void) const; + bool is_positive_definite () const; - double rcond (void) const; + double rcond () const; - chol_type inverse (void) const; + chol_type inverse () const; protected: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/sparse-lu.cc --- a/liboctave/numeric/sparse-lu.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/sparse-lu.cc Mon Jan 30 18:36:03 2023 +0100 @@ -863,7 +863,7 @@ template lu_type -sparse_lu::Y (void) const +sparse_lu::Y () const { octave_idx_type nr = m_L.rows (); octave_idx_type nz = m_L.cols (); @@ -900,7 +900,7 @@ template SparseMatrix -sparse_lu::Pr (void) const +sparse_lu::Pr () const { octave_idx_type nr = m_L.rows (); @@ -920,7 +920,7 @@ template ColumnVector -sparse_lu::Pr_vec (void) const +sparse_lu::Pr_vec () const { octave_idx_type nr = m_L.rows (); @@ -934,14 +934,14 @@ template PermMatrix -sparse_lu::Pr_mat (void) const +sparse_lu::Pr_mat () const { return PermMatrix (m_P, false); } template SparseMatrix -sparse_lu::Pc (void) const +sparse_lu::Pc () const { octave_idx_type nc = m_U.cols (); @@ -961,7 +961,7 @@ template ColumnVector -sparse_lu::Pc_vec (void) const +sparse_lu::Pc_vec () const { octave_idx_type nc = m_U.cols (); @@ -975,7 +975,7 @@ template PermMatrix -sparse_lu::Pc_mat (void) const +sparse_lu::Pc_mat () const { return PermMatrix (m_Q, true); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/sparse-lu.h --- a/liboctave/numeric/sparse-lu.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/sparse-lu.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ typedef typename lu_type::element_type lu_elt_type; - sparse_lu (void) + sparse_lu () : m_L (), m_U (), m_R (), m_cond (0), m_P (), m_Q () { } OCTAVE_API @@ -84,33 +84,33 @@ return *this; } - virtual ~sparse_lu (void) = default; + virtual ~sparse_lu () = default; - lu_type L (void) const { return m_L; } + lu_type L () const { return m_L; } - lu_type U (void) const { return m_U; } + lu_type U () const { return m_U; } - SparseMatrix R (void) const { return m_R; } + SparseMatrix R () const { return m_R; } - OCTAVE_API lu_type Y (void) const; + OCTAVE_API lu_type Y () const; - OCTAVE_API SparseMatrix Pc (void) const; + OCTAVE_API SparseMatrix Pc () const; - OCTAVE_API SparseMatrix Pr (void) const; + OCTAVE_API SparseMatrix Pr () const; - OCTAVE_API ColumnVector Pc_vec (void) const; + OCTAVE_API ColumnVector Pc_vec () const; - OCTAVE_API ColumnVector Pr_vec (void) const; + OCTAVE_API ColumnVector Pr_vec () const; - OCTAVE_API PermMatrix Pc_mat (void) const; + OCTAVE_API PermMatrix Pc_mat () const; - OCTAVE_API PermMatrix Pr_mat (void) const; + OCTAVE_API PermMatrix Pr_mat () const; - const octave_idx_type * row_perm (void) const { return m_P.data (); } + const octave_idx_type * row_perm () const { return m_P.data (); } - const octave_idx_type * col_perm (void) const { return m_Q.data (); } + const octave_idx_type * col_perm () const { return m_Q.data (); } - double rcond (void) const { return m_cond; } + double rcond () const { return m_cond; } protected: diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/sparse-qr.cc --- a/liboctave/numeric/sparse-qr.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/sparse-qr.cc Mon Jan 30 18:36:03 2023 +0100 @@ -81,9 +81,9 @@ sparse_qr_rep& operator = (const sparse_qr_rep&) = delete; - ~sparse_qr_rep (void); - - bool ok (void) const + ~sparse_qr_rep (); + + bool ok () const { #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD)) return (m_H && m_Htau && m_HPinv && m_R && m_E); @@ -94,13 +94,13 @@ #endif } - SPARSE_T V (void) const; - - ColumnVector Pinv (void) const; - - ColumnVector P (void) const; - - ColumnVector E (void) const; + SPARSE_T V () const; + + ColumnVector Pinv () const; + + ColumnVector P () const; + + ColumnVector E () const; SPARSE_T R (bool econ) const; @@ -149,7 +149,7 @@ template ColumnVector -sparse_qr::sparse_qr_rep::Pinv (void) const +sparse_qr::sparse_qr_rep::Pinv () const { #if defined (HAVE_CXSPARSE) @@ -169,7 +169,7 @@ template ColumnVector -sparse_qr::sparse_qr_rep::P (void) const +sparse_qr::sparse_qr_rep::P () const { #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD)) @@ -199,7 +199,7 @@ template ColumnVector -sparse_qr::sparse_qr_rep::E (void) const +sparse_qr::sparse_qr_rep::E () const { #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD)) @@ -570,7 +570,7 @@ #endif template <> -sparse_qr::sparse_qr_rep::~sparse_qr_rep (void) +sparse_qr::sparse_qr_rep::~sparse_qr_rep () { #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD)) @@ -591,7 +591,7 @@ template <> SparseMatrix -sparse_qr::sparse_qr_rep::V (void) const +sparse_qr::sparse_qr_rep::V () const { #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD)) @@ -1507,7 +1507,7 @@ #endif template <> -sparse_qr::sparse_qr_rep::~sparse_qr_rep (void) +sparse_qr::sparse_qr_rep::~sparse_qr_rep () { #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD)) @@ -1528,7 +1528,7 @@ template <> SparseComplexMatrix -sparse_qr::sparse_qr_rep::V (void) const +sparse_qr::sparse_qr_rep::V () const { #if defined (HAVE_CXSPARSE) // Drop zeros from V and sort @@ -2675,7 +2675,7 @@ } template -sparse_qr::sparse_qr (void) +sparse_qr::sparse_qr () : m_rep (new sparse_qr_rep (SPARSE_T (), 0)) { } @@ -2686,35 +2686,35 @@ template bool -sparse_qr::ok (void) const +sparse_qr::ok () const { return m_rep->ok (); } template SPARSE_T -sparse_qr::V (void) const +sparse_qr::V () const { return m_rep->V (); } template ColumnVector -sparse_qr::Pinv (void) const +sparse_qr::Pinv () const { return m_rep->P (); } template ColumnVector -sparse_qr::P (void) const +sparse_qr::P () const { return m_rep->P (); } template ColumnVector -sparse_qr::E (void) const +sparse_qr::E () const { return m_rep->E(); } @@ -2722,7 +2722,7 @@ template SparseMatrix -sparse_qr::E_MAT (void) const +sparse_qr::E_MAT () const { ColumnVector perm = m_rep->E (); octave_idx_type nrows = perm.rows (); @@ -3226,11 +3226,11 @@ //explicit instantiations of member function E_MAT template OCTAVE_API SparseMatrix -sparse_qr::E_MAT (void) const; +sparse_qr::E_MAT () const; template OCTAVE_API SparseMatrix -sparse_qr::E_MAT (void) const; +sparse_qr::E_MAT () const; template template @@ -3250,33 +3250,33 @@ // Explicitly instantiate all member functions -template OCTAVE_API sparse_qr::sparse_qr (void); +template OCTAVE_API sparse_qr::sparse_qr (); template OCTAVE_API sparse_qr::sparse_qr (const SparseMatrix& a, int order); -template OCTAVE_API bool sparse_qr::ok (void) const; -template OCTAVE_API ColumnVector sparse_qr::E (void) const; -template OCTAVE_API SparseMatrix sparse_qr::V (void) const; -template OCTAVE_API ColumnVector sparse_qr::Pinv (void) const; -template OCTAVE_API ColumnVector sparse_qr::P (void) const; +template OCTAVE_API bool sparse_qr::ok () const; +template OCTAVE_API ColumnVector sparse_qr::E () const; +template OCTAVE_API SparseMatrix sparse_qr::V () const; +template OCTAVE_API ColumnVector sparse_qr::Pinv () const; +template OCTAVE_API ColumnVector sparse_qr::P () const; template OCTAVE_API SparseMatrix sparse_qr::R (bool econ) const; template OCTAVE_API Matrix sparse_qr::C (const Matrix& b, bool econ) const; template OCTAVE_API Matrix sparse_qr::Q (bool econ) const; -template OCTAVE_API sparse_qr::sparse_qr (void); +template OCTAVE_API sparse_qr::sparse_qr (); template OCTAVE_API sparse_qr::sparse_qr (const SparseComplexMatrix& a, int order); -template OCTAVE_API bool sparse_qr::ok (void) const; +template OCTAVE_API bool sparse_qr::ok () const; template OCTAVE_API ColumnVector -sparse_qr::E (void) const; +sparse_qr::E () const; template OCTAVE_API SparseComplexMatrix -sparse_qr::V (void) const; +sparse_qr::V () const; template OCTAVE_API ColumnVector -sparse_qr::Pinv (void) const; +sparse_qr::Pinv () const; template OCTAVE_API ColumnVector -sparse_qr::P (void) const; +sparse_qr::P () const; template OCTAVE_API SparseComplexMatrix sparse_qr::R (bool econ) const; template OCTAVE_API ComplexMatrix diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/sparse-qr.h --- a/liboctave/numeric/sparse-qr.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/sparse-qr.h Mon Jan 30 18:36:03 2023 +0100 @@ -49,7 +49,7 @@ { public: - OCTAVE_API sparse_qr (void); + OCTAVE_API sparse_qr (); #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD)) // order = 7 selects SPQR default ordering @@ -60,22 +60,22 @@ sparse_qr (const sparse_qr& a) = default; - ~sparse_qr (void) = default; + ~sparse_qr () = default; sparse_qr& operator = (const sparse_qr& a) = default; - OCTAVE_API bool ok (void) const; + OCTAVE_API bool ok () const; - OCTAVE_API ColumnVector E (void) const; + OCTAVE_API ColumnVector E () const; // constructs permutation matrix from permutation vector rep -> E() OCTAVE_API SparseMatrix E_MAT () const; - OCTAVE_API SPARSE_T V (void) const; + OCTAVE_API SPARSE_T V () const; - OCTAVE_API ColumnVector Pinv (void) const; + OCTAVE_API ColumnVector Pinv () const; - OCTAVE_API ColumnVector P (void) const; + OCTAVE_API ColumnVector P () const; OCTAVE_API SPARSE_T R (bool econ = false) const; diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/svd.cc --- a/liboctave/numeric/svd.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/svd.cc Mon Jan 30 18:36:03 2023 +0100 @@ -307,7 +307,7 @@ template T -svd::left_singular_matrix (void) const +svd::left_singular_matrix () const { if (m_type == svd::Type::sigma_only) (*current_liboctave_error_handler) @@ -318,7 +318,7 @@ template T -svd::right_singular_matrix (void) const +svd::right_singular_matrix () const { if (m_type == svd::Type::sigma_only) (*current_liboctave_error_handler) diff -r 17d568574e1c -r 7860fcc69082 liboctave/numeric/svd.h --- a/liboctave/numeric/svd.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/numeric/svd.h Mon Jan 30 18:36:03 2023 +0100 @@ -57,7 +57,7 @@ GEJSV }; - svd (void) + svd () : m_type (), m_driver (), m_left_sm (), m_sigma (), m_right_sm () { } @@ -83,13 +83,13 @@ return *this; } - ~svd (void) = default; + ~svd () = default; - T left_singular_matrix (void) const; + T left_singular_matrix () const; - DM_T singular_values (void) const { return m_sigma; } + DM_T singular_values () const { return m_sigma; } - T right_singular_matrix (void) const; + T right_singular_matrix () const; private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/child-list.cc --- a/liboctave/system/child-list.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/child-list.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ m_list.append (child (pid, f)); } -void child_list::reap (void) +void child_list::reap () { // Mark the record for PID invalid. @@ -70,7 +70,7 @@ // Wait on our children and record any changes in their status. -bool child_list::wait (void) +bool child_list::wait () { bool retval = false; diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/child-list.h --- a/liboctave/system/child-list.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/child-list.h Mon Jan 30 18:36:03 2023 +0100 @@ -56,7 +56,7 @@ child& operator = (const child&) = default; - ~child (void) = default; + ~child () = default; // The process ID of this child. pid_t m_pid; @@ -76,15 +76,15 @@ { public: - child_list (void) { } + child_list () { } void insert (pid_t pid, child::child_event_handler f); void remove (pid_t pid); - void reap (void); + void reap (); - bool wait (void); + bool wait (); private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/dir-ops.cc --- a/liboctave/system/dir-ops.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/dir-ops.cc Mon Jan 30 18:36:03 2023 +0100 @@ -70,7 +70,7 @@ } string_vector -dir_entry::read (void) +dir_entry::read () { string_vector retval; @@ -90,7 +90,7 @@ } bool -dir_entry::close (void) +dir_entry::close () { bool retval = true; @@ -105,7 +105,7 @@ } unsigned int -dir_entry::max_name_length (void) +dir_entry::max_name_length () { return octave_name_max_wrapper (); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/dir-ops.h --- a/liboctave/system/dir-ops.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/dir-ops.h Mon Jan 30 18:36:03 2023 +0100 @@ -73,21 +73,21 @@ return *this; } - ~dir_entry (void) { close (); } + ~dir_entry () { close (); } bool open (const std::string& = ""); - string_vector read (void); + string_vector read (); - bool close (void); + bool close (); - bool ok (void) const { return m_dir && ! m_fail; } + bool ok () const { return m_dir && ! m_fail; } operator bool () const { return ok (); } - std::string error (void) const { return ok () ? "" : m_errmsg; } + std::string error () const { return ok () ? "" : m_errmsg; } - static unsigned int max_name_length (void); + static unsigned int max_name_length (); private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/file-ops.cc --- a/liboctave/system/file-ops.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/file-ops.cc Mon Jan 30 18:36:03 2023 +0100 @@ -219,7 +219,7 @@ OCTAVE_BEGIN_NAMESPACE(file_ops) -char dev_sep_char (void) +char dev_sep_char () { #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) return ':'; @@ -228,7 +228,7 @@ #endif } -char dir_sep_char (void) +char dir_sep_char () { #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) return '\\'; @@ -237,7 +237,7 @@ #endif } -std::string dir_sep_str (void) +std::string dir_sep_str () { #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) return R"(\)"; @@ -246,7 +246,7 @@ #endif } -std::string dir_sep_chars (void) +std::string dir_sep_chars () { #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) return R"(/\)"; diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/file-ops.h --- a/liboctave/system/file-ops.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/file-ops.h Mon Jan 30 18:36:03 2023 +0100 @@ -75,15 +75,15 @@ // text which identified this tilde starter in LEN, excluding the // tilde itself. -extern OCTAVE_API char dev_sep_char (void); +extern OCTAVE_API char dev_sep_char (); extern OCTAVE_API bool is_dev_sep (char c); -extern OCTAVE_API char dir_sep_char (void); +extern OCTAVE_API char dir_sep_char (); -extern OCTAVE_API std::string dir_sep_str (void); +extern OCTAVE_API std::string dir_sep_str (); -extern OCTAVE_API std::string dir_sep_chars (void); +extern OCTAVE_API std::string dir_sep_chars (); extern OCTAVE_API bool is_dir_sep (char c); diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/file-stat.cc --- a/liboctave/system/file-stat.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/file-stat.cc Mon Jan 30 18:36:03 2023 +0100 @@ -50,43 +50,43 @@ // initialized, they should throw an exception. bool -base_file_stat::is_blk (void) const +base_file_stat::is_blk () const { return exists () && is_blk (m_mode); } bool -base_file_stat::is_chr (void) const +base_file_stat::is_chr () const { return exists () && is_chr (m_mode); } bool -base_file_stat::is_dir (void) const +base_file_stat::is_dir () const { return exists () && is_dir (m_mode); } bool -base_file_stat::is_fifo (void) const +base_file_stat::is_fifo () const { return exists () && is_fifo (m_mode); } bool -base_file_stat::is_lnk (void) const +base_file_stat::is_lnk () const { return exists () && is_lnk (m_mode); } bool -base_file_stat::is_reg (void) const +base_file_stat::is_reg () const { return exists () && is_reg (m_mode); } bool -base_file_stat::is_sock (void) const +base_file_stat::is_sock () const { return exists () && is_sock (m_mode); } @@ -134,25 +134,25 @@ } bool -base_file_stat::have_struct_stat_st_rdev (void) +base_file_stat::have_struct_stat_st_rdev () { return ::octave_have_struct_stat_st_rdev (); } bool -base_file_stat::have_struct_stat_st_blksize (void) +base_file_stat::have_struct_stat_st_blksize () { return octave_have_struct_stat_st_blksize (); } bool -base_file_stat::have_struct_stat_st_blocks (void) +base_file_stat::have_struct_stat_st_blocks () { return octave_have_struct_stat_st_blocks (); } std::string -base_file_stat::mode_as_string (void) const +base_file_stat::mode_as_string () const { char buf[12]; diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/file-stat.h --- a/liboctave/system/file-stat.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/file-stat.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,7 +44,7 @@ { public: - base_file_stat (void) + base_file_stat () : m_initialized (false), m_fail (false), m_errmsg (), m_mode (), m_ino (), m_dev (), m_nlink (), m_uid (), m_gid (), m_size (), m_atime (), m_mtime (), m_ctime (), m_rdev (), @@ -86,7 +86,7 @@ // The minimum difference in file time stamp values. // FIXME: This value should come from the filesystem itself. // How can we get that info? - sys::time time_resolution (void) const + sys::time time_resolution () const { static sys::time resolution (1.0); return resolution; @@ -97,13 +97,13 @@ // should all return 0 (or the equivalent, for the given object) // which is likely not meaningful. - bool is_blk (void) const; - bool is_chr (void) const; - bool is_dir (void) const; - bool is_fifo (void) const; - bool is_lnk (void) const; - bool is_reg (void) const; - bool is_sock (void) const; + bool is_blk () const; + bool is_chr () const; + bool is_dir () const; + bool is_fifo () const; + bool is_lnk () const; + bool is_reg () const; + bool is_sock () const; static bool is_blk (mode_t mode); static bool is_chr (mode_t mode); @@ -113,40 +113,40 @@ static bool is_reg (mode_t mode); static bool is_sock (mode_t mode); - static bool have_struct_stat_st_rdev (void); - static bool have_struct_stat_st_blksize (void); - static bool have_struct_stat_st_blocks (void); + static bool have_struct_stat_st_rdev (); + static bool have_struct_stat_st_blksize (); + static bool have_struct_stat_st_blocks (); - ino_t ino (void) const { return m_ino; } - dev_t dev (void) const { return m_dev; } + ino_t ino () const { return m_ino; } + dev_t dev () const { return m_dev; } - nlink_t nlink (void) const { return m_nlink; } + nlink_t nlink () const { return m_nlink; } - uid_t uid (void) const { return m_uid; } - gid_t gid (void) const { return m_gid; } + uid_t uid () const { return m_uid; } + gid_t gid () const { return m_gid; } - off_t size (void) const { return m_size; } + off_t size () const { return m_size; } - sys::time atime (void) const { return m_atime; } - sys::time mtime (void) const { return m_mtime; } - sys::time ctime (void) const { return m_ctime; } + sys::time atime () const { return m_atime; } + sys::time mtime () const { return m_mtime; } + sys::time ctime () const { return m_ctime; } - dev_t rdev (void) const { return m_rdev; } + dev_t rdev () const { return m_rdev; } - long blksize (void) const { return m_blksize; } - long blocks (void) const { return m_blocks; } + long blksize () const { return m_blksize; } + long blocks () const { return m_blocks; } - mode_t mode (void) const { return m_mode; } + mode_t mode () const { return m_mode; } - std::string mode_as_string (void) const; + std::string mode_as_string () const; - bool ok (void) const { return m_initialized && ! m_fail; } + bool ok () const { return m_initialized && ! m_fail; } operator bool () const { return ok (); } - bool exists (void) const { return ok (); } + bool exists () const { return ok (); } - std::string error (void) const { return ok () ? "" : m_errmsg; } + std::string error () const { return ok () ? "" : m_errmsg; } // Has the file referenced by this object been modified since TIME? bool is_newer (const sys::time& time) const { return m_mtime > time; } @@ -157,7 +157,7 @@ protected: - virtual ~base_file_stat (void) = default; + virtual ~base_file_stat () = default; // TRUE means we have already called stat. bool m_initialized; @@ -237,7 +237,7 @@ // This destructor must remain as an empty destructor defined in the // cpp file rather than in the header file (bug #50234). - ~file_stat (void); + ~file_stat (); void get_stats (bool force = false) { @@ -295,7 +295,7 @@ return *this; } - ~file_fstat (void) = default; + ~file_fstat () = default; void get_stats (bool force = false) { diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/lo-sysdep.cc --- a/liboctave/system/lo-sysdep.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/lo-sysdep.cc Mon Jan 30 18:36:03 2023 +0100 @@ -68,7 +68,7 @@ } std::string -getcwd (void) +getcwd () { std::string retval; diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/lo-sysdep.h --- a/liboctave/system/lo-sysdep.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/lo-sysdep.h Mon Jan 30 18:36:03 2023 +0100 @@ -43,7 +43,7 @@ extern OCTAVE_API int system (const std::string& cmd_str); -extern OCTAVE_API std::string getcwd (void); +extern OCTAVE_API std::string getcwd (); extern OCTAVE_API int chdir (const std::string&); diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/lo-sysinfo.cc --- a/liboctave/system/lo-sysinfo.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/lo-sysinfo.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ OCTAVE_BEGIN_NAMESPACE(sys) -std::string blas_version (void) +std::string blas_version () { dynamic_library dyn_libs (""); @@ -73,7 +73,7 @@ } // OpenBLAS - typedef char *(*open_fcn_type) (void); + typedef char *(*open_fcn_type) (); open_fcn_type open_f_ptr = reinterpret_cast (dyn_libs.search ("openblas_get_config")); @@ -160,7 +160,7 @@ return retval; } -std::string lapack_version (void) +std::string lapack_version () { std::string retval = "unknown LAPACK"; diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/lo-sysinfo.h --- a/liboctave/system/lo-sysinfo.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/lo-sysinfo.h Mon Jan 30 18:36:03 2023 +0100 @@ -34,9 +34,9 @@ OCTAVE_BEGIN_NAMESPACE(sys) -extern OCTAVE_API std::string blas_version (void); +extern OCTAVE_API std::string blas_version (); -extern OCTAVE_API std::string lapack_version (void); +extern OCTAVE_API std::string lapack_version (); OCTAVE_END_NAMESPACE(sys) OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/mach-info.cc --- a/liboctave/system/mach-info.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/mach-info.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ OCTAVE_BEGIN_NAMESPACE(mach_info) -static float_format get_float_format (void) +static float_format get_float_format () { switch (octave_get_float_format ()) { @@ -57,26 +57,26 @@ } } -static bool is_big_endian (void) +static bool is_big_endian () { return octave_is_big_endian (); } -float_format native_float_format (void) +float_format native_float_format () { static float_format fmt = get_float_format (); return fmt; } -bool words_big_endian (void) +bool words_big_endian () { static bool big_endian = is_big_endian (); return big_endian; } -bool words_little_endian (void) +bool words_little_endian () { static bool little_endian = ! is_big_endian (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/mach-info.h --- a/liboctave/system/mach-info.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/mach-info.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,11 +44,11 @@ flt_fmt_ieee_big_endian = 2, }; -OCTAVE_API float_format native_float_format (void); +OCTAVE_API float_format native_float_format (); -OCTAVE_API bool words_big_endian (void); +OCTAVE_API bool words_big_endian (); -OCTAVE_API bool words_little_endian (void); +OCTAVE_API bool words_little_endian (); OCTAVE_API float_format string_to_float_format (const std::string&); diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-env.cc --- a/liboctave/system/oct-env.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-env.cc Mon Jan 30 18:36:03 2023 +0100 @@ -69,7 +69,7 @@ OCTAVE_BEGIN_NAMESPACE(sys) -env::env (void) +env::env () : m_follow_symbolic_links (true), m_verbatim_pwd (true), m_current_directory (), m_prog_name (), m_prog_invocation_name (), m_user_name (), m_host_name () @@ -86,7 +86,7 @@ env *env::m_instance = nullptr; bool -env::instance_ok (void) +env::instance_ok () { bool retval = true; @@ -170,14 +170,14 @@ } std::string -env::get_program_name (void) +env::get_program_name () { return (instance_ok ()) ? m_instance->m_prog_name : ""; } std::string -env::get_program_invocation_name (void) +env::get_program_invocation_name () { return (instance_ok ()) ? m_instance->m_prog_invocation_name : ""; @@ -191,21 +191,21 @@ } std::string -env::get_user_name (void) +env::get_user_name () { return (instance_ok ()) ? m_instance->do_get_user_name () : ""; } std::string -env::get_host_name (void) +env::get_host_name () { return (instance_ok ()) ? m_instance->do_get_host_name () : ""; } std::string -env::do_get_temp_directory (void) const +env::do_get_temp_directory () const { std::string tempd = do_getenv ("TMPDIR"); @@ -246,7 +246,7 @@ } std::string -env::do_get_user_config_directory (void) +env::do_get_user_config_directory () { std::string cfg_dir; @@ -267,7 +267,7 @@ } std::string -env::do_get_user_data_directory (void) +env::do_get_user_data_directory () { std::string data_dir; @@ -306,7 +306,7 @@ } bool -env::have_x11_display (void) +env::have_x11_display () { std::string display = getenv ("DISPLAY"); @@ -518,7 +518,7 @@ // Return a string which is the current working directory. std::string -env::do_getcwd (void) +env::do_getcwd () { if (! m_follow_symbolic_links) m_current_directory = ""; @@ -533,7 +533,7 @@ // running. std::string -env::do_get_home_directory (void) +env::do_get_home_directory () { std::string hd = do_getenv ("HOME"); @@ -560,7 +560,7 @@ } std::string -env::do_get_user_name (void) +env::do_get_user_name () { if (m_user_name.empty ()) { @@ -573,7 +573,7 @@ } std::string -env::do_get_host_name (void) +env::do_get_host_name () { if (m_host_name.empty ()) { diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-env.h --- a/liboctave/system/oct-env.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-env.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ { protected: - env (void); + env (); public: @@ -62,29 +62,29 @@ make_absolute (const std::string& s, const std::string& dot_path = get_current_directory ()); - static std::string get_current_directory (void); + static std::string get_current_directory (); - static std::string get_home_directory (void); + static std::string get_home_directory (); - static std::string get_temp_directory (void); + static std::string get_temp_directory (); - static std::string get_user_config_directory (void); + static std::string get_user_config_directory (); - static std::string get_user_data_directory (void); + static std::string get_user_data_directory (); - static std::string get_program_name (void); + static std::string get_program_name (); - static std::string get_program_invocation_name (void); + static std::string get_program_invocation_name (); - static std::string get_user_name (void); + static std::string get_user_name (); - static std::string get_host_name (void); + static std::string get_host_name (); static std::string getenv (const std::string& name); static void putenv (const std::string& name, const std::string& value); - static bool have_x11_display (void); + static bool have_x11_display (); static bool chdir (const std::string& newdir); @@ -92,7 +92,7 @@ private: - static bool instance_ok (void); + static bool instance_ok (); std::string do_polite_directory_format (const std::string& name); @@ -105,19 +105,19 @@ std::string do_make_absolute (const std::string& s, const std::string& dot_path) const; - std::string do_getcwd (void); + std::string do_getcwd (); - std::string do_get_home_directory (void); + std::string do_get_home_directory (); - std::string do_get_temp_directory (void) const; + std::string do_get_temp_directory () const; - std::string do_get_user_config_directory (void); + std::string do_get_user_config_directory (); - std::string do_get_user_data_directory (void); + std::string do_get_user_data_directory (); - std::string do_get_user_name (void); + std::string do_get_user_name (); - std::string do_get_host_name (void); + std::string do_get_host_name (); std::string do_getenv (const std::string& name) const; @@ -136,7 +136,7 @@ // The real thing. static env *m_instance; - static void cleanup_instance (void) + static void cleanup_instance () { delete m_instance; m_instance = nullptr; } // TRUE means follow symbolic links that point to directories just diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-group.cc --- a/liboctave/system/oct-group.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-group.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ OCTAVE_NORETURN static void -err_invalid (void) +err_invalid () { (*current_liboctave_error_handler) ("invalid group object"); } @@ -52,7 +52,7 @@ OCTAVE_BEGIN_NAMESPACE(sys) std::string -group::name (void) const +group::name () const { if (! ok ()) err_invalid (); @@ -61,7 +61,7 @@ } std::string -group::passwd (void) const +group::passwd () const { if (! ok ()) err_invalid (); @@ -70,7 +70,7 @@ } gid_t -group::gid (void) const +group::gid () const { if (! ok ()) err_invalid (); @@ -79,7 +79,7 @@ } string_vector -group::mem (void) const +group::mem () const { if (! ok ()) err_invalid (); @@ -88,7 +88,7 @@ } group -group::getgrent (void) +group::getgrent () { std::string msg; return getgrent (msg); @@ -149,7 +149,7 @@ } int -group::setgrent (void) +group::setgrent () { std::string msg; return setgrent (msg); @@ -169,7 +169,7 @@ } int -group::endgrent (void) +group::endgrent () { std::string msg; return endgrent (msg); diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-group.h --- a/liboctave/system/oct-group.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-group.h Mon Jan 30 18:36:03 2023 +0100 @@ -44,7 +44,7 @@ { public: - group (void) + group () : m_name (), m_passwd (), m_gid (0), m_mem (), m_valid (false) { } @@ -67,19 +67,19 @@ return *this; } - std::string name (void) const; + std::string name () const; - std::string passwd (void) const; + std::string passwd () const; - gid_t gid (void) const; + gid_t gid () const; - string_vector mem (void) const; + string_vector mem () const; - bool ok (void) const { return m_valid; } + bool ok () const { return m_valid; } operator bool () const { return ok (); } - static group getgrent (void); + static group getgrent (); static group getgrent (std::string& msg); static group getgrgid (gid_t gid); @@ -88,10 +88,10 @@ static group getgrnam (const std::string& nm); static group getgrnam (const std::string& nm, std::string& msg); - static int setgrent (void); + static int setgrent (); static int setgrent (std::string& msg); - static int endgrent (void); + static int endgrent (); static int endgrent (std::string& msg); private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-password.cc --- a/liboctave/system/oct-password.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-password.cc Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,7 @@ OCTAVE_NORETURN static void -err_invalid (void) +err_invalid () { (*current_liboctave_error_handler) ("invalid password object"); } @@ -51,7 +51,7 @@ OCTAVE_BEGIN_NAMESPACE(sys) std::string -password::name (void) const +password::name () const { if (! ok ()) err_invalid (); @@ -60,7 +60,7 @@ } std::string -password::passwd (void) const +password::passwd () const { if (! ok ()) err_invalid (); @@ -69,7 +69,7 @@ } uid_t -password::uid (void) const +password::uid () const { if (! ok ()) err_invalid (); @@ -78,7 +78,7 @@ } gid_t -password::gid (void) const +password::gid () const { if (! ok ()) err_invalid (); @@ -87,7 +87,7 @@ } std::string -password::gecos (void) const +password::gecos () const { if (! ok ()) err_invalid (); @@ -96,7 +96,7 @@ } std::string -password::dir (void) const +password::dir () const { if (! ok ()) err_invalid (); @@ -105,7 +105,7 @@ } std::string -password::shell (void) const +password::shell () const { if (! ok ()) err_invalid (); @@ -114,7 +114,7 @@ } password -password::getpwent (void) +password::getpwent () { std::string msg; return getpwent (msg); @@ -175,7 +175,7 @@ } int -password::setpwent (void) +password::setpwent () { std::string msg; return setpwent (msg); @@ -195,7 +195,7 @@ } int -password::endpwent (void) +password::endpwent () { std::string msg; return endpwent (msg); diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-password.h --- a/liboctave/system/oct-password.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-password.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ { public: - password (void) + password () : m_name (), m_passwd (), m_uid (0), m_gid (0), m_gecos (), m_dir (), m_shell (), m_valid (false) { } @@ -70,27 +70,27 @@ return *this; } - ~password (void) = default; + ~password () = default; - std::string name (void) const; + std::string name () const; - std::string passwd (void) const; + std::string passwd () const; - uid_t uid (void) const; + uid_t uid () const; - gid_t gid (void) const; + gid_t gid () const; - std::string gecos (void) const; + std::string gecos () const; - std::string dir (void) const; + std::string dir () const; - std::string shell (void) const; + std::string shell () const; - bool ok (void) const { return m_valid; } + bool ok () const { return m_valid; } operator bool () const { return ok (); } - static password getpwent (void); + static password getpwent (); static password getpwent (std::string& msg); static password getpwuid (uid_t uid); @@ -99,10 +99,10 @@ static password getpwnam (const std::string& nm); static password getpwnam (const std::string& nm, std::string& msg); - static int setpwent (void); + static int setpwent (); static int setpwent (std::string& msg); - static int endpwent (void); + static int endpwent (); static int endpwent (std::string& msg); private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-syscalls.cc --- a/liboctave/system/oct-syscalls.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-syscalls.cc Mon Jan 30 18:36:03 2023 +0100 @@ -146,37 +146,37 @@ } pid_t -getpid (void) +getpid () { return octave_getpid_wrapper (); } pid_t -getppid (void) +getppid () { return octave_getppid_wrapper (); } gid_t -getgid (void) +getgid () { return octave_getgid_wrapper (); } gid_t -getegid (void) +getegid () { return octave_getegid_wrapper (); } uid_t -getuid (void) +getuid () { return octave_getuid_wrapper (); } uid_t -geteuid (void) +geteuid () { return octave_geteuid_wrapper (); } @@ -226,7 +226,7 @@ } int -wcontinue (void) +wcontinue () { return octave_wcontinue_wrapper (); } @@ -268,7 +268,7 @@ } int -wnohang (void) +wnohang () { return octave_wnohang_wrapper (); } @@ -286,7 +286,7 @@ } int -wuntraced (void) +wuntraced () { return octave_wuntraced_wrapper (); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-syscalls.h --- a/liboctave/system/oct-syscalls.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-syscalls.h Mon Jan 30 18:36:03 2023 +0100 @@ -51,17 +51,17 @@ extern OCTAVE_API pid_t getpgrp (std::string&); -extern OCTAVE_API pid_t getpid (void); +extern OCTAVE_API pid_t getpid (); -extern OCTAVE_API pid_t getppid (void); +extern OCTAVE_API pid_t getppid (); -extern OCTAVE_API gid_t getgid (void); +extern OCTAVE_API gid_t getgid (); -extern OCTAVE_API gid_t getegid (void); +extern OCTAVE_API gid_t getegid (); -extern OCTAVE_API uid_t getuid (void); +extern OCTAVE_API uid_t getuid (); -extern OCTAVE_API uid_t geteuid (void); +extern OCTAVE_API uid_t geteuid (); extern OCTAVE_API int pipe (int *); extern OCTAVE_API int pipe (int *, std::string&); @@ -69,7 +69,7 @@ extern OCTAVE_API pid_t waitpid (pid_t, int *status, int); extern OCTAVE_API pid_t waitpid (pid_t, int *status, int, std::string&); -extern OCTAVE_API int wcontinue (void); +extern OCTAVE_API int wcontinue (); extern OCTAVE_API int wcoredump (int status); @@ -83,13 +83,13 @@ extern OCTAVE_API int wexitstatus (int status); -extern OCTAVE_API int wnohang (void); +extern OCTAVE_API int wnohang (); extern OCTAVE_API int wstopsig (int status); extern OCTAVE_API int wtermsig (int status); -extern OCTAVE_API int wuntraced (void); +extern OCTAVE_API int wuntraced (); extern OCTAVE_API int kill (pid_t, int); extern OCTAVE_API int kill (pid_t, int, std::string&); diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-time.cc --- a/liboctave/system/oct-time.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-time.cc Mon Jan 30 18:36:03 2023 +0100 @@ -94,7 +94,7 @@ } std::string -time::ctime (void) const +time::ctime () const { return localtime (*this).asctime (); } @@ -111,7 +111,7 @@ } void -time::stamp (void) +time::stamp () { time_t ot_unix_time; octave_gettimeofday_wrapper (&ot_unix_time, &m_ot_usec); @@ -346,7 +346,7 @@ } void -cpu_time::stamp (void) +cpu_time::stamp () { time_t usr_sec, sys_sec; octave_cpu_time (&usr_sec, &sys_sec, &m_usr_usec, &m_sys_usec); @@ -355,7 +355,7 @@ } void -resource_usage::stamp (void) +resource_usage::stamp () { time_t usr_sec, sys_sec; long usr_usec, sys_usec; diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-time.h --- a/liboctave/system/oct-time.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-time.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ { public: - time (void) + time () : m_ot_unix_time (0), m_ot_usec (0) { stamp (); } time (OCTAVE_TIME_T t) @@ -98,20 +98,20 @@ return *this; } - ~time (void) = default; + ~time () = default; - OCTAVE_API void stamp (void); + OCTAVE_API void stamp (); - double double_value (void) const + double double_value () const { return as_double (m_ot_unix_time, m_ot_usec); } - OCTAVE_TIME_T unix_time (void) const { return m_ot_unix_time; } + OCTAVE_TIME_T unix_time () const { return m_ot_unix_time; } - long usec (void) const { return m_ot_usec; } + long usec () const { return m_ot_usec; } - OCTAVE_API std::string ctime (void) const; + OCTAVE_API std::string ctime () const; friend OCTAVE_API std::ostream& operator << (std::ostream& os, const time& ot); @@ -186,7 +186,7 @@ { public: - base_tm (void) + base_tm () : m_usec (0), m_sec (0), m_min (0), m_hour (0), m_mday (0), m_mon (0), m_year (0), m_wday (0), m_yday (0), m_isdst (0), m_gmtoff (0), m_zone ("unknown") @@ -220,20 +220,20 @@ return *this; } - virtual ~base_tm (void) = default; + virtual ~base_tm () = default; - int usec (void) const { return m_usec; } - int sec (void) const { return m_sec; } - int min (void) const { return m_min; } - int hour (void) const { return m_hour; } - int mday (void) const { return m_mday; } - int mon (void) const { return m_mon; } - int year (void) const { return m_year; } - int wday (void) const { return m_wday; } - int yday (void) const { return m_yday; } - int isdst (void) const { return m_isdst; } - long gmtoff (void) const { return m_gmtoff; } - std::string zone (void) const { return m_zone; } + int usec () const { return m_usec; } + int sec () const { return m_sec; } + int min () const { return m_min; } + int hour () const { return m_hour; } + int mday () const { return m_mday; } + int mon () const { return m_mon; } + int year () const { return m_year; } + int wday () const { return m_wday; } + int yday () const { return m_yday; } + int isdst () const { return m_isdst; } + long gmtoff () const { return m_gmtoff; } + std::string zone () const { return m_zone; } OCTAVE_API base_tm& usec (int v); OCTAVE_API base_tm& sec (int v); @@ -250,7 +250,7 @@ OCTAVE_API std::string strftime (const std::string& fmt) const; - std::string asctime (void) const + std::string asctime () const { return strftime ("%a %b %d %H:%M:%S %Y\n"); } protected: @@ -299,7 +299,7 @@ { public: - localtime (void) + localtime () : base_tm () { init (time ()); } localtime (const time& ot) @@ -314,7 +314,7 @@ return *this; } - ~localtime (void) = default; + ~localtime () = default; private: @@ -326,7 +326,7 @@ { public: - gmtime (void) + gmtime () : base_tm () { init (time ()); } gmtime (const time& ot) @@ -338,7 +338,7 @@ return *this; } - ~gmtime (void) = default; + ~gmtime () = default; private: @@ -366,9 +366,9 @@ return *this; } - int characters_converted (void) const { return m_nchars; } + int characters_converted () const { return m_nchars; } - ~strptime (void) = default; + ~strptime () = default; private: @@ -384,7 +384,7 @@ friend class resource_usage; - cpu_time (void) + cpu_time () : m_usr_sec (0), m_sys_sec (0), m_usr_usec (0), m_sys_usec (0) { stamp (); @@ -408,23 +408,23 @@ return *this; } - OCTAVE_API void stamp (void); + OCTAVE_API void stamp (); - double user (void) const + double user () const { return as_double (m_usr_sec, m_usr_usec); } - double system (void) const + double system () const { return as_double (m_sys_sec, m_sys_usec); } - OCTAVE_TIME_T user_sec (void) const { return m_usr_sec; } - long user_usec (void) const { return m_usr_usec; } + OCTAVE_TIME_T user_sec () const { return m_usr_sec; } + long user_usec () const { return m_usr_usec; } - OCTAVE_TIME_T system_sec (void) const { return m_sys_sec; } - long system_usec (void) const { return m_sys_usec; } + OCTAVE_TIME_T system_sec () const { return m_sys_sec; } + long system_usec () const { return m_sys_usec; } private: @@ -445,7 +445,7 @@ { public: - resource_usage (void) + resource_usage () : m_cpu (), m_maxrss (0), m_ixrss (0), m_idrss (0), m_isrss (0), m_minflt (0), m_majflt (0), m_nswap (0), m_inblock (0), m_oublock (0), m_msgsnd (0), m_msgrcv (0), @@ -490,24 +490,24 @@ return *this; } - OCTAVE_API void stamp (void); + OCTAVE_API void stamp (); - cpu_time cpu (void) const { return m_cpu; } + cpu_time cpu () const { return m_cpu; } - long maxrss (void) const { return m_maxrss; } - long ixrss (void) const { return m_ixrss; } - long idrss (void) const { return m_idrss; } - long isrss (void) const { return m_isrss; } - long minflt (void) const { return m_minflt; } - long majflt (void) const { return m_majflt; } - long nswap (void) const { return m_nswap; } - long inblock (void) const { return m_inblock; } - long oublock (void) const { return m_oublock; } - long msgsnd (void) const { return m_msgsnd; } - long msgrcv (void) const { return m_msgrcv; } - long nsignals (void) const { return m_nsignals; } - long nvcsw (void) const { return m_nvcsw; } - long nivcsw (void) const { return m_nivcsw; } + long maxrss () const { return m_maxrss; } + long ixrss () const { return m_ixrss; } + long idrss () const { return m_idrss; } + long isrss () const { return m_isrss; } + long minflt () const { return m_minflt; } + long majflt () const { return m_majflt; } + long nswap () const { return m_nswap; } + long inblock () const { return m_inblock; } + long oublock () const { return m_oublock; } + long msgsnd () const { return m_msgsnd; } + long msgrcv () const { return m_msgrcv; } + long nsignals () const { return m_nsignals; } + long nvcsw () const { return m_nvcsw; } + long nivcsw () const { return m_nivcsw; } private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-uname.cc --- a/liboctave/system/oct-uname.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-uname.cc Mon Jan 30 18:36:03 2023 +0100 @@ -38,7 +38,7 @@ OCTAVE_BEGIN_NAMESPACE(sys) void -uname::init (void) +uname::init () { char *sysname, *nodename, *release, *version, *machine; diff -r 17d568574e1c -r 7860fcc69082 liboctave/system/oct-uname.h --- a/liboctave/system/oct-uname.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/system/oct-uname.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ { public: - uname (void) + uname () : m_sysname ("unknown"), m_nodename ("unknown"), m_release ("unknown"), m_version ("unknown"), m_machine ("unknown"), @@ -71,16 +71,16 @@ return *this; } - ~uname (void) = default; + ~uname () = default; - std::string sysname (void) const { return m_sysname; } - std::string nodename (void) const { return m_nodename; } - std::string release (void) const { return m_release; } - std::string version (void) const { return m_version; } - std::string machine (void) const { return m_machine; } + std::string sysname () const { return m_sysname; } + std::string nodename () const { return m_nodename; } + std::string release () const { return m_release; } + std::string version () const { return m_version; } + std::string machine () const { return m_machine; } - std::string message (void) const { return m_errmsg; } - int error (void) const { return m_errno; } + std::string message () const { return m_errmsg; } + int error () const { return m_errno; } private: @@ -93,7 +93,7 @@ std::string m_errmsg; int m_errno; - void init (void); + void init (); }; OCTAVE_END_NAMESPACE(sys) diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/action-container.h --- a/liboctave/util/action-container.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/action-container.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ friend class action_container; - elem (void) { } + elem () { } // No copying! @@ -60,12 +60,12 @@ elem& operator = (const elem&) = delete; - virtual ~elem (void) = default; + virtual ~elem () = default; - virtual void run (void) { } + virtual void run () { } }; - // An element that merely runs a void (*)(void) function. + // An element that merely runs a void (*)() function. class fcn_elem : public elem { @@ -79,11 +79,11 @@ : m_fcn (std::bind (fcn, args...)) { } - void run (void) { m_fcn (); } + void run () { m_fcn (); } private: - std::function m_fcn; + std::function m_fcn; }; // An element that stores arbitrary variable, and restores it. @@ -102,7 +102,7 @@ restore_var_elem& operator = (const restore_var_elem&) = delete; - void run (void) { *m_ptr = m_val; } + void run () { *m_ptr = m_val; } private: @@ -125,14 +125,14 @@ delete_ptr_elem operator = (const delete_ptr_elem&) = delete; - void run (void) { delete m_ptr; } + void run () { delete m_ptr; } private: T *m_ptr; }; - action_container (void) { } + action_container () { } // No copying! @@ -140,7 +140,7 @@ action_container& operator = (const action_container&) = delete; - virtual ~action_container (void) = default; + virtual ~action_container () = default; template void add (F&& fcn, Args&& ... args) @@ -193,15 +193,15 @@ add_action (new restore_var_elem (var, val)); } - operator bool (void) const { return ! empty (); } + operator bool () const { return ! empty (); } - virtual void run_first (void) = 0; + virtual void run_first () = 0; OCTAVE_API void run (std::size_t num); - void run (void) { run (size ()); } + void run () { run (size ()); } - virtual void discard_first (void) = 0; + virtual void discard_first () = 0; void discard (std::size_t num) { @@ -212,11 +212,11 @@ discard_first (); } - void discard (void) { discard (size ()); } + void discard () { discard (size ()); } - virtual std::size_t size (void) const = 0; + virtual std::size_t size () const = 0; - bool empty (void) const { return size () == 0; } + bool empty () const { return size () == 0; } protected: diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/base-list.h --- a/liboctave/util/base-list.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/base-list.h Mon Jan 30 18:36:03 2023 +0100 @@ -47,10 +47,10 @@ typedef typename std::list::const_reverse_iterator const_reverse_iterator; - bool empty (void) const { return m_lst.empty (); } + bool empty () const { return m_lst.empty (); } - std::size_t size (void) const { return m_lst.size (); } - std::size_t length (void) const { return size (); } + std::size_t size () const { return m_lst.size (); } + std::size_t length () const { return size (); } iterator erase (iterator pos) { return m_lst.erase (pos); } @@ -60,38 +60,38 @@ m_lst.remove_if (pred); } - void clear (void) { m_lst.clear (); } + void clear () { m_lst.clear (); } - iterator begin (void) { return iterator (m_lst.begin ()); } - const_iterator begin (void) const { return const_iterator (m_lst.begin ()); } + iterator begin () { return iterator (m_lst.begin ()); } + const_iterator begin () const { return const_iterator (m_lst.begin ()); } - iterator end (void) { return iterator (m_lst.end ()); } - const_iterator end (void) const { return const_iterator (m_lst.end ()); } + iterator end () { return iterator (m_lst.end ()); } + const_iterator end () const { return const_iterator (m_lst.end ()); } - reverse_iterator rbegin (void) { return reverse_iterator (m_lst.rbegin ()); } - const_reverse_iterator rbegin (void) const + reverse_iterator rbegin () { return reverse_iterator (m_lst.rbegin ()); } + const_reverse_iterator rbegin () const { return const_reverse_iterator (m_lst.rbegin ()); } - reverse_iterator rend (void) { return reverse_iterator (m_lst.rend ()); } - const_reverse_iterator rend (void) const + reverse_iterator rend () { return reverse_iterator (m_lst.rend ()); } + const_reverse_iterator rend () const { return const_reverse_iterator (m_lst.rend ()); } - elt_type& front (void) { return m_lst.front (); } - elt_type& back (void) { return m_lst.back (); } + elt_type& front () { return m_lst.front (); } + elt_type& back () { return m_lst.back (); } - const elt_type& front (void) const { return m_lst.front (); } - const elt_type& back (void) const { return m_lst.back (); } + const elt_type& front () const { return m_lst.front (); } + const elt_type& back () const { return m_lst.back (); } void push_front (const elt_type& s) { m_lst.push_front (s); } void push_back (const elt_type& s) { m_lst.push_back (s); } - void pop_front (void) { m_lst.pop_front (); } - void pop_back (void) { m_lst.pop_back (); } + void pop_front () { m_lst.pop_front (); } + void pop_back () { m_lst.pop_back (); } // For backward compatibility. void append (const elt_type& s) { m_lst.push_back (s); } - base_list (void) = default; + base_list () = default; base_list (const std::list& l) : m_lst (l) { } @@ -99,7 +99,7 @@ base_list& operator = (const base_list& bl) = default; - virtual ~base_list (void) = default; + virtual ~base_list () = default; protected: diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/caseless-str.h --- a/liboctave/util/caseless-str.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/caseless-str.h Mon Jan 30 18:36:03 2023 +0100 @@ -38,7 +38,7 @@ typedef std::string::iterator iterator; typedef std::string::const_iterator const_iterator; - caseless_str (void) = default; + caseless_str () = default; caseless_str (const std::string& s) : std::string (s) { } caseless_str (const char *s) : std::string (s) { } @@ -47,7 +47,7 @@ caseless_str& operator = (const caseless_str&) = default; - ~caseless_str (void) = default; + ~caseless_str () = default; bool operator < (const std::string& s) const { diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/cmd-edit.cc --- a/liboctave/util/cmd-edit.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/cmd-edit.cc Mon Jan 30 18:36:03 2023 +0100 @@ -81,9 +81,9 @@ typedef command_editor::completion_fcn completion_fcn; - gnu_readline (void); + gnu_readline (); - ~gnu_readline (void) = default; + ~gnu_readline () = default; void do_set_name (const std::string& n); @@ -91,27 +91,27 @@ void do_set_input_stream (FILE *f); - FILE * do_get_input_stream (void); + FILE * do_get_input_stream (); void do_set_output_stream (FILE *f); - FILE * do_get_output_stream (void); + FILE * do_get_output_stream (); - void do_redisplay (void); + void do_redisplay (); - int do_terminal_rows (void); + int do_terminal_rows (); - int do_terminal_cols (void); + int do_terminal_cols (); void do_clear_screen (bool skip_redisplay); - void do_resize_terminal (void); + void do_resize_terminal (); void do_set_screen_size (int ht, int wd); - std::string newline_chars (void); + std::string newline_chars (); - void do_restore_terminal_state (void); + void do_restore_terminal_state (); void do_blink_matching_paren (bool flag); @@ -139,56 +139,56 @@ void do_set_user_accept_line_function (user_accept_line_fcn f); - completion_fcn do_get_completion_function (void) const; + completion_fcn do_get_completion_function () const; - quoting_fcn do_get_quoting_function (void) const; + quoting_fcn do_get_quoting_function () const; - dequoting_fcn do_get_dequoting_function (void) const; + dequoting_fcn do_get_dequoting_function () const; - char_is_quoted_fcn do_get_char_is_quoted_function (void) const; + char_is_quoted_fcn do_get_char_is_quoted_function () const; - user_accept_line_fcn do_get_user_accept_line_function (void) const; + user_accept_line_fcn do_get_user_accept_line_function () const; string_vector do_generate_filename_completions (const std::string& text); - std::string do_get_line_buffer (void) const; + std::string do_get_line_buffer () const; - std::string do_get_current_line (void) const; + std::string do_get_current_line () const; char do_get_prev_char (int) const; void do_replace_line (const std::string& text, bool clear_undo); - void do_kill_full_line (void); + void do_kill_full_line (); void do_insert_text (const std::string& text); - void do_newline (void); + void do_newline (); - void do_accept_line (void); + void do_accept_line (); - bool do_undo (void); + bool do_undo (); - void do_clear_undo_list (void); + void do_clear_undo_list (); void set_startup_hook (startup_hook_fcn f); - void restore_startup_hook (void); + void restore_startup_hook (); void set_pre_input_hook (pre_input_hook_fcn f); - void restore_pre_input_hook (void); + void restore_pre_input_hook (); void set_event_hook (event_hook_fcn f); - void restore_event_hook (void); + void restore_event_hook (); - void do_restore_event_hook (void); + void do_restore_event_hook (); void do_read_init_file (const std::string& file); - void do_re_read_init_file (void); + void do_re_read_init_file (); bool do_filename_completion_desired (bool); @@ -198,7 +198,7 @@ void do_interrupt (bool); - void do_handle_interrupt_signal (void); + void do_handle_interrupt_signal (); static int operate_and_get_next (int, int); @@ -305,7 +305,7 @@ } FILE * -gnu_readline::do_get_input_stream (void) +gnu_readline::do_get_input_stream () { return ::octave_rl_get_input_stream (); } @@ -317,13 +317,13 @@ } FILE * -gnu_readline::do_get_output_stream (void) +gnu_readline::do_get_output_stream () { return ::octave_rl_get_output_stream (); } void -gnu_readline::do_redisplay (void) +gnu_readline::do_redisplay () { ::octave_rl_redisplay (); } @@ -335,7 +335,7 @@ // us. int -gnu_readline::do_terminal_rows (void) +gnu_readline::do_terminal_rows () { int sh = ::octave_rl_screen_height (); @@ -343,7 +343,7 @@ } int -gnu_readline::do_terminal_cols (void) +gnu_readline::do_terminal_cols () { int sw = ::octave_rl_screen_width (); @@ -357,7 +357,7 @@ } void -gnu_readline::do_resize_terminal (void) +gnu_readline::do_resize_terminal () { ::octave_rl_resize_terminal (); } @@ -369,13 +369,13 @@ } std::string -gnu_readline::newline_chars (void) +gnu_readline::newline_chars () { return "\r\n"; } void -gnu_readline::do_restore_terminal_state (void) +gnu_readline::do_restore_terminal_state () { ::octave_rl_restore_terminal_state (); } @@ -490,31 +490,31 @@ } gnu_readline::completion_fcn -gnu_readline::do_get_completion_function (void) const +gnu_readline::do_get_completion_function () const { return m_completion_function; } gnu_readline::quoting_fcn -gnu_readline::do_get_quoting_function (void) const +gnu_readline::do_get_quoting_function () const { return m_quoting_function; } gnu_readline::dequoting_fcn -gnu_readline::do_get_dequoting_function (void) const +gnu_readline::do_get_dequoting_function () const { return m_dequoting_function; } gnu_readline::char_is_quoted_fcn -gnu_readline::do_get_char_is_quoted_function (void) const +gnu_readline::do_get_char_is_quoted_function () const { return m_char_is_quoted_function; } gnu_readline::user_accept_line_fcn -gnu_readline::do_get_user_accept_line_function (void) const +gnu_readline::do_get_user_accept_line_function () const { return user_accept_line_function; } @@ -634,13 +634,13 @@ } std::string -gnu_readline::do_get_line_buffer (void) const +gnu_readline::do_get_line_buffer () const { return ::octave_rl_line_buffer (); } std::string -gnu_readline::do_get_current_line (void) const +gnu_readline::do_get_current_line () const { std::string retval; char *buf = ::octave_rl_copy_line (); @@ -667,7 +667,7 @@ } void -gnu_readline::do_kill_full_line (void) +gnu_readline::do_kill_full_line () { ::octave_rl_kill_full_line (); } @@ -679,19 +679,19 @@ } void -gnu_readline::do_newline (void) +gnu_readline::do_newline () { ::octave_rl_newline (1, '\n'); } void -gnu_readline::do_accept_line (void) +gnu_readline::do_accept_line () { command_accept_line (1, '\n'); } bool -gnu_readline::do_undo (void) +gnu_readline::do_undo () { return ::octave_rl_do_undo (); } @@ -712,7 +712,7 @@ } void -gnu_readline::restore_startup_hook (void) +gnu_readline::restore_startup_hook () { ::octave_rl_set_startup_hook (m_previous_startup_hook); } @@ -727,7 +727,7 @@ } void -gnu_readline::restore_pre_input_hook (void) +gnu_readline::restore_pre_input_hook () { ::octave_rl_set_pre_input_hook (m_previous_pre_input_hook); } @@ -741,7 +741,7 @@ } void -gnu_readline::restore_event_hook (void) +gnu_readline::restore_event_hook () { ::octave_rl_set_event_hook (m_previous_event_hook); } @@ -753,7 +753,7 @@ } void -gnu_readline::do_re_read_init_file (void) +gnu_readline::do_re_read_init_file () { ::octave_rl_re_read_init_file (); } @@ -783,7 +783,7 @@ } void -gnu_readline::do_handle_interrupt_signal (void) +gnu_readline::do_handle_interrupt_signal () { octave_signal_caught = 0; octave_interrupt_state = 0; @@ -933,7 +933,7 @@ { public: - default_command_editor (void) + default_command_editor () : command_editor (), m_input_stream (stdin), m_output_stream (stdout) { } // No copying! @@ -942,35 +942,35 @@ default_command_editor& operator = (const default_command_editor&) = delete; - ~default_command_editor (void) = default; + ~default_command_editor () = default; std::string do_readline (const std::string& prompt, bool& eof); void do_set_input_stream (FILE *f); - FILE * do_get_input_stream (void); + FILE * do_get_input_stream (); void do_set_output_stream (FILE *f); - FILE * do_get_output_stream (void); + FILE * do_get_output_stream (); string_vector do_generate_filename_completions (const std::string& text); - std::string do_get_line_buffer (void) const; + std::string do_get_line_buffer () const; - std::string do_get_current_line (void) const; + std::string do_get_current_line () const; char do_get_prev_char (int) const; void do_replace_line (const std::string& text, bool clear_undo); - void do_kill_full_line (void); + void do_kill_full_line (); void do_insert_text (const std::string& text); - void do_newline (void); + void do_newline (); - void do_accept_line (void); + void do_accept_line (); private: @@ -995,7 +995,7 @@ } FILE * -default_command_editor::do_get_input_stream (void) +default_command_editor::do_get_input_stream () { return m_input_stream; } @@ -1007,7 +1007,7 @@ } FILE * -default_command_editor::do_get_output_stream (void) +default_command_editor::do_get_output_stream () { return m_output_stream; } @@ -1020,13 +1020,13 @@ } std::string -default_command_editor::do_get_line_buffer (void) const +default_command_editor::do_get_line_buffer () const { return ""; } std::string -default_command_editor::do_get_current_line (void) const +default_command_editor::do_get_current_line () const { // FIXME return ""; @@ -1045,7 +1045,7 @@ } void -default_command_editor::do_kill_full_line (void) +default_command_editor::do_kill_full_line () { // FIXME } @@ -1057,19 +1057,19 @@ } void -default_command_editor::do_newline (void) +default_command_editor::do_newline () { // FIXME } void -default_command_editor::do_accept_line (void) +default_command_editor::do_accept_line () { // FIXME } bool -command_editor::instance_ok (void) +command_editor::instance_ok () { bool retval = true; @@ -1093,7 +1093,7 @@ } void -command_editor::make_command_editor (void) +command_editor::make_command_editor () { #if defined (USE_READLINE) s_instance = new gnu_readline (); @@ -1103,7 +1103,7 @@ } void -command_editor::force_default_editor (void) +command_editor::force_default_editor () { delete s_instance; s_instance = new default_command_editor (); @@ -1117,13 +1117,13 @@ } int -command_editor::insert_initial_input (void) +command_editor::insert_initial_input () { return instance_ok () ? s_instance->do_insert_initial_input () : 0; } int -command_editor::startup_handler (void) +command_editor::startup_handler () { // Iterate over a copy of the set to avoid problems if a hook // function attempts to remove itself from the startup_hook_set. @@ -1140,7 +1140,7 @@ } int -command_editor::pre_input_handler (void) +command_editor::pre_input_handler () { // Iterate over copy of the set to avoid problems if a hook function // attempts to remove itself from the pre_input_hook_set. @@ -1157,7 +1157,7 @@ } int -command_editor::event_handler (void) +command_editor::event_handler () { if (octave_interrupt_state) handle_interrupt_signal (); @@ -1216,7 +1216,7 @@ } FILE * -command_editor::get_input_stream (void) +command_editor::get_input_stream () { return instance_ok () ? s_instance->do_get_input_stream () : nullptr; } @@ -1229,26 +1229,26 @@ } FILE * -command_editor::get_output_stream (void) +command_editor::get_output_stream () { return instance_ok () ? s_instance->do_get_output_stream () : nullptr; } void -command_editor::redisplay (void) +command_editor::redisplay () { if (instance_ok ()) s_instance->do_redisplay (); } int -command_editor::terminal_rows (void) +command_editor::terminal_rows () { return instance_ok () ? s_instance->do_terminal_rows () : -1; } int -command_editor::terminal_cols (void) +command_editor::terminal_cols () { return instance_ok () ? s_instance->do_terminal_cols () : -1; } @@ -1261,7 +1261,7 @@ } void -command_editor::resize_terminal (void) +command_editor::resize_terminal () { if (instance_ok ()) s_instance->do_resize_terminal (); @@ -1281,7 +1281,7 @@ } int -command_editor::current_command_number (void) +command_editor::current_command_number () { return instance_ok () ? s_instance->m_command_number : 0; } @@ -1294,14 +1294,14 @@ } void -command_editor::increment_current_command_number (void) +command_editor::increment_current_command_number () { if (instance_ok ()) s_instance->m_command_number++; } void -command_editor::restore_terminal_state (void) +command_editor::restore_terminal_state () { if (instance_ok ()) s_instance->do_restore_terminal_state (); @@ -1398,32 +1398,32 @@ } command_editor::completion_fcn -command_editor::get_completion_function (void) +command_editor::get_completion_function () { return instance_ok () ? s_instance->do_get_completion_function () : nullptr; } command_editor::quoting_fcn -command_editor::get_quoting_function (void) +command_editor::get_quoting_function () { return instance_ok () ? s_instance->do_get_quoting_function () : nullptr; } command_editor::dequoting_fcn -command_editor::get_dequoting_function (void) +command_editor::get_dequoting_function () { return instance_ok () ? s_instance->do_get_dequoting_function () : nullptr; } command_editor::char_is_quoted_fcn -command_editor::get_char_is_quoted_function (void) +command_editor::get_char_is_quoted_function () { return (instance_ok () ? s_instance->do_get_char_is_quoted_function () : nullptr); } command_editor::user_accept_line_fcn -command_editor::get_user_accept_line_function (void) +command_editor::get_user_accept_line_function () { return (instance_ok () ? s_instance->do_get_user_accept_line_function () : nullptr); @@ -1438,13 +1438,13 @@ } std::string -command_editor::get_line_buffer (void) +command_editor::get_line_buffer () { return instance_ok () ? s_instance->do_get_line_buffer () : ""; } std::string -command_editor::get_current_line (void) +command_editor::get_current_line () { return instance_ok () ? s_instance->do_get_current_line () : ""; } @@ -1465,7 +1465,7 @@ } void -command_editor::kill_full_line (void) +command_editor::kill_full_line () { if (instance_ok ()) s_instance->do_kill_full_line (); @@ -1479,27 +1479,27 @@ } void -command_editor::newline (void) +command_editor::newline () { if (instance_ok ()) s_instance->do_newline (); } void -command_editor::accept_line (void) +command_editor::accept_line () { if (instance_ok ()) s_instance->do_accept_line (); } bool -command_editor::undo (void) +command_editor::undo () { return instance_ok () ? s_instance->do_undo () : false; } void -command_editor::clear_undo_list (void) +command_editor::clear_undo_list () { if (instance_ok ()) s_instance->do_clear_undo_list (); @@ -1578,7 +1578,7 @@ } void -command_editor::run_event_hooks (void) +command_editor::run_event_hooks () { event_handler (); } @@ -1595,7 +1595,7 @@ } void -command_editor::re_read_init_file (void) +command_editor::re_read_init_file () { if (instance_ok ()) s_instance->do_re_read_init_file (); @@ -1649,13 +1649,13 @@ } bool -command_editor::event_loop_interrupted (void) +command_editor::event_loop_interrupted () { return instance_ok () ? s_instance->do_event_loop_interrupted () : false; } void -command_editor::handle_interrupt_signal (void) +command_editor::handle_interrupt_signal () { if (instance_ok ()) s_instance->do_handle_interrupt_signal (); @@ -1915,7 +1915,7 @@ } int -command_editor::do_insert_initial_input (void) +command_editor::do_insert_initial_input () { std::string input = m_initial_input; diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/cmd-edit.h --- a/liboctave/util/cmd-edit.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/cmd-edit.h Mon Jan 30 18:36:03 2023 +0100 @@ -43,18 +43,18 @@ { protected: - command_editor (void) + command_editor () : m_command_number (1), m_rows (24), m_cols (80), m_interrupted (false), m_interrupt_event_loop (false), m_initial_input () { } public: - typedef int (*startup_hook_fcn) (void); + typedef int (*startup_hook_fcn) (); - typedef int (*pre_input_hook_fcn) (void); + typedef int (*pre_input_hook_fcn) (); - typedef int (*event_hook_fcn) (void); + typedef int (*event_hook_fcn) (); typedef std::string (*completion_fcn) (const std::string&, int); @@ -74,7 +74,7 @@ command_editor& operator = (const command_editor&) = delete; - virtual ~command_editor (void) = default; + virtual ~command_editor () = default; static void set_name (const std::string& n); @@ -84,27 +84,27 @@ static void set_input_stream (FILE *f); - static FILE * get_input_stream (void); + static FILE * get_input_stream (); static void set_output_stream (FILE *f); - static FILE * get_output_stream (void); + static FILE * get_output_stream (); - static void redisplay (void); + static void redisplay (); - static int terminal_rows (void); + static int terminal_rows (); - static int terminal_cols (void); + static int terminal_cols (); static void clear_screen (bool skip_redisplay = false); - static void resize_terminal (void); + static void resize_terminal (); static void set_screen_size (int ht, int wd); static std::string decode_prompt_string (const std::string& s); - static void restore_terminal_state (void); + static void restore_terminal_state (); static void blink_matching_paren (bool flag); @@ -132,38 +132,38 @@ static void set_user_accept_line_function (user_accept_line_fcn f); - static completion_fcn get_completion_function (void); + static completion_fcn get_completion_function (); - static quoting_fcn get_quoting_function (void); + static quoting_fcn get_quoting_function (); - static dequoting_fcn get_dequoting_function (void); + static dequoting_fcn get_dequoting_function (); - static char_is_quoted_fcn get_char_is_quoted_function (void); + static char_is_quoted_fcn get_char_is_quoted_function (); - static user_accept_line_fcn get_user_accept_line_function (void); + static user_accept_line_fcn get_user_accept_line_function (); static string_vector generate_filename_completions (const std::string& text); - static std::string get_line_buffer (void); + static std::string get_line_buffer (); - static std::string get_current_line (void); + static std::string get_current_line (); static char get_prev_char (int); static void replace_line (const std::string& text, bool clear_undo = true); - static void kill_full_line (void); + static void kill_full_line (); static void insert_text (const std::string& text); - static void newline (void); + static void newline (); - static void accept_line (void); + static void accept_line (); - static bool undo (void); + static bool undo (); - static void clear_undo_list (void); + static void clear_undo_list (); static void add_startup_hook (startup_hook_fcn f); @@ -177,11 +177,11 @@ static void remove_event_hook (event_hook_fcn f); - static void run_event_hooks (void); + static void run_event_hooks (); static void read_init_file (const std::string& file = ""); - static void re_read_init_file (void); + static void re_read_init_file (); static bool filename_completion_desired (bool); @@ -193,39 +193,39 @@ static void interrupt_event_loop (bool flag = true); - static bool event_loop_interrupted (void); + static bool event_loop_interrupted (); - static int current_command_number (void); + static int current_command_number (); static void reset_current_command_number (int n); - static void increment_current_command_number (void); + static void increment_current_command_number (); - static void force_default_editor (void); + static void force_default_editor (); static void set_initial_input (const std::string& text); - static int insert_initial_input (void); + static int insert_initial_input (); private: - static bool instance_ok (void); + static bool instance_ok (); - static void make_command_editor (void); + static void make_command_editor (); - static int startup_handler (void); + static int startup_handler (); - static int pre_input_handler (void); + static int pre_input_handler (); - static int event_handler (void); + static int event_handler (); - static void cleanup_instance (void) + static void cleanup_instance () { delete s_instance; s_instance = nullptr; } - static void handle_interrupt_signal (void); + static void handle_interrupt_signal (); //-------- @@ -254,21 +254,21 @@ virtual void do_set_input_stream (FILE *) = 0; - virtual FILE * do_get_input_stream (void) = 0; + virtual FILE * do_get_input_stream () = 0; virtual void do_set_output_stream (FILE *) = 0; - virtual FILE * do_get_output_stream (void) = 0; + virtual FILE * do_get_output_stream () = 0; - virtual void do_redisplay (void) { } + virtual void do_redisplay () { } - virtual int do_terminal_rows (void) { return m_rows; } + virtual int do_terminal_rows () { return m_rows; } - virtual int do_terminal_cols (void) { return m_cols; } + virtual int do_terminal_cols () { return m_cols; } virtual void do_clear_screen (bool) { } - virtual void do_resize_terminal (void) { } + virtual void do_resize_terminal () { } virtual void do_set_screen_size (int ht, int wd) { @@ -278,9 +278,9 @@ virtual std::string do_decode_prompt_string (const std::string&); - virtual std::string newline_chars (void) { return "\n"; } + virtual std::string newline_chars () { return "\n"; } - virtual void do_restore_terminal_state (void) { } + virtual void do_restore_terminal_state () { } virtual void do_blink_matching_paren (bool) { } @@ -310,60 +310,60 @@ virtual void do_set_user_accept_line_function (user_accept_line_fcn) { } - virtual completion_fcn do_get_completion_function (void) const + virtual completion_fcn do_get_completion_function () const { return nullptr; } - virtual quoting_fcn do_get_quoting_function (void) const + virtual quoting_fcn do_get_quoting_function () const { return nullptr; } - virtual dequoting_fcn do_get_dequoting_function (void) const + virtual dequoting_fcn do_get_dequoting_function () const { return nullptr; } - virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const + virtual char_is_quoted_fcn do_get_char_is_quoted_function () const { return nullptr; } - virtual user_accept_line_fcn do_get_user_accept_line_function (void) const + virtual user_accept_line_fcn do_get_user_accept_line_function () const { return nullptr; } virtual string_vector do_generate_filename_completions (const std::string& text) = 0; - virtual std::string do_get_line_buffer (void) const = 0; + virtual std::string do_get_line_buffer () const = 0; - virtual std::string do_get_current_line (void) const = 0; + virtual std::string do_get_current_line () const = 0; virtual char do_get_prev_char (int) const = 0; virtual void do_replace_line (const std::string& text, bool clear_undo) = 0; - virtual void do_kill_full_line (void) = 0; + virtual void do_kill_full_line () = 0; virtual void do_insert_text (const std::string& text) = 0; - virtual void do_newline (void) = 0; + virtual void do_newline () = 0; - virtual void do_accept_line (void) = 0; + virtual void do_accept_line () = 0; - virtual bool do_undo (void) { return false; } + virtual bool do_undo () { return false; } - virtual void do_clear_undo_list (void) { } + virtual void do_clear_undo_list () { } virtual void set_startup_hook (startup_hook_fcn) { } - virtual void restore_startup_hook (void) { } + virtual void restore_startup_hook () { } virtual void set_pre_input_hook (pre_input_hook_fcn) { } - virtual void restore_pre_input_hook (void) { } + virtual void restore_pre_input_hook () { } virtual void set_event_hook (event_hook_fcn) { } - virtual void restore_event_hook (void) { } + virtual void restore_event_hook () { } virtual void do_read_init_file (const std::string&) { } - virtual void do_re_read_init_file (void) { } + virtual void do_re_read_init_file () { } virtual bool do_filename_completion_desired (bool) { return false; } @@ -373,14 +373,14 @@ virtual void do_interrupt (bool) { } - virtual void do_handle_interrupt_signal (void) { } + virtual void do_handle_interrupt_signal () { } void do_interrupt_event_loop (bool arg) { m_interrupt_event_loop = arg; } - bool do_event_loop_interrupted (void) const + bool do_event_loop_interrupted () const { return m_interrupt_event_loop; } - int do_insert_initial_input (void); + int do_insert_initial_input (); int read_octal (const std::string& s); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/cmd-hist.cc --- a/liboctave/util/cmd-hist.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/cmd-hist.cc Mon Jan 30 18:36:03 2023 +0100 @@ -61,40 +61,40 @@ { public: - gnu_history (void) + gnu_history () : command_history (), mark (0) { } - ~gnu_history (void) = default; + ~gnu_history () = default; void do_process_histcontrol (const std::string&); - std::string do_histcontrol (void) const; + std::string do_histcontrol () const; bool do_add (const std::string&); void do_remove (int); - void do_clear (void); + void do_clear (); - int do_where (void) const; + int do_where () const; - int do_length (void) const; + int do_length () const; - int do_max_input_history (void) const; + int do_max_input_history () const; - int do_base (void) const; + int do_base () const; - int do_current_number (void) const; + int do_current_number () const; void do_stifle (int); - int do_unstifle (void); + int do_unstifle (); - int do_is_stifled (void) const; + int do_is_stifled () const; void do_set_mark (int); - int do_goto_mark (void); + int do_goto_mark (); void do_read (const std::string&, bool); @@ -160,7 +160,7 @@ } std::string -gnu_history::do_histcontrol (void) const +gnu_history::do_histcontrol () const { // FIXME: instead of reconstructing this value, should we just save // the string we were given when constructing the command_history object? @@ -217,37 +217,37 @@ } void -gnu_history::do_clear (void) +gnu_history::do_clear () { ::octave_clear_history (); } int -gnu_history::do_where (void) const +gnu_history::do_where () const { return ::octave_where_history (); } int -gnu_history::do_length (void) const +gnu_history::do_length () const { return ::octave_history_length (); } int -gnu_history::do_max_input_history (void) const +gnu_history::do_max_input_history () const { return ::octave_max_input_history (); } int -gnu_history::do_base (void) const +gnu_history::do_base () const { return ::octave_history_base (); } int -gnu_history::do_current_number (void) const +gnu_history::do_current_number () const { return m_size > 0 ? do_base () + do_where () : -1; } @@ -259,13 +259,13 @@ } int -gnu_history::do_unstifle (void) +gnu_history::do_unstifle () { return ::octave_unstifle_history (); } int -gnu_history::do_is_stifled (void) const +gnu_history::do_is_stifled () const { return ::octave_history_is_stifled (); } @@ -277,7 +277,7 @@ } int -gnu_history::do_goto_mark (void) +gnu_history::do_goto_mark () { if (mark) { @@ -512,7 +512,7 @@ #endif bool -command_history::instance_ok (void) +command_history::instance_ok () { bool retval = true; @@ -532,7 +532,7 @@ } void -command_history::make_command_history (void) +command_history::make_command_history () { #if defined (USE_READLINE) s_instance = new gnu_history (); @@ -551,7 +551,7 @@ } bool -command_history::is_initialized (void) +command_history::is_initialized () { // We just want to check the status of an existing instance, not // create one. @@ -570,7 +570,7 @@ } std::string -command_history::file (void) +command_history::file () { return instance_ok () ? s_instance->do_file () : ""; } @@ -583,7 +583,7 @@ } std::string -command_history::histcontrol (void) +command_history::histcontrol () { return instance_ok () ? s_instance->do_histcontrol () : ""; } @@ -596,7 +596,7 @@ } int -command_history::size (void) +command_history::size () { return instance_ok () ? s_instance->do_size () : 0; } @@ -609,7 +609,7 @@ } bool -command_history::ignoring_entries (void) +command_history::ignoring_entries () { return instance_ok () ? s_instance->do_ignoring_entries () : false; } @@ -630,38 +630,38 @@ } void -command_history::clear (void) +command_history::clear () { if (instance_ok ()) s_instance->do_clear (); } int -command_history::where (void) +command_history::where () { return instance_ok () ? s_instance->do_where () : 0; } int -command_history::length (void) +command_history::length () { return instance_ok () ? s_instance->do_length () : 0; } int -command_history::max_input_history (void) +command_history::max_input_history () { return instance_ok () ? s_instance->do_max_input_history () : 0; } int -command_history::base (void) +command_history::base () { return instance_ok () ? s_instance->do_base () : 0; } int -command_history::current_number (void) +command_history::current_number () { return instance_ok () ? s_instance->do_current_number () : 0; } @@ -674,13 +674,13 @@ } int -command_history::unstifle (void) +command_history::unstifle () { return instance_ok () ? s_instance->do_unstifle () : 0; } int -command_history::is_stifled (void) +command_history::is_stifled () { return instance_ok () ? s_instance->do_is_stifled () : 0; } @@ -693,7 +693,7 @@ } int -command_history::goto_mark (void) +command_history::goto_mark () { return instance_ok () ? s_instance->do_goto_mark () : 0; } @@ -793,7 +793,7 @@ } bool -command_history::do_is_initialized (void) const +command_history::do_is_initialized () const { return m_initialized; } @@ -805,7 +805,7 @@ } std::string -command_history::do_file (void) +command_history::do_file () { return m_file; } @@ -817,7 +817,7 @@ } int -command_history::do_size (void) const +command_history::do_size () const { return m_size; } @@ -829,7 +829,7 @@ } bool -command_history::do_ignoring_entries (void) const +command_history::do_ignoring_entries () const { return m_ignoring_additions; } @@ -845,35 +845,35 @@ { } void -command_history::do_clear (void) +command_history::do_clear () { } int -command_history::do_where (void) const +command_history::do_where () const { return 0; } int -command_history::do_length (void) const +command_history::do_length () const { return 0; } int -command_history::do_max_input_history (void) const +command_history::do_max_input_history () const { return 0; } int -command_history::do_base (void) const +command_history::do_base () const { return 0; } int -command_history::do_current_number (void) const +command_history::do_current_number () const { return m_size > 0 ? do_base () + do_where () : -1; } @@ -883,13 +883,13 @@ { } int -command_history::do_unstifle (void) +command_history::do_unstifle () { return -1; } int -command_history::do_is_stifled (void) const +command_history::do_is_stifled () const { return 0; } @@ -899,7 +899,7 @@ { } int -command_history::do_goto_mark (void) +command_history::do_goto_mark () { return 0; } diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/cmd-hist.h --- a/liboctave/util/cmd-hist.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/cmd-hist.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ { protected: - command_history (void) + command_history () : m_initialized (false), m_ignoring_additions (false), m_history_control (0), m_lines_in_file (0), m_lines_this_session (0), m_file (), m_size (-1) @@ -54,56 +54,56 @@ command_history& operator = (const command_history&) = delete; - virtual ~command_history (void) = default; + virtual ~command_history () = default; static void initialize (bool, const std::string&, int, const std::string&); - static bool is_initialized (void); + static bool is_initialized (); static void set_file (const std::string&); - static std::string file (void); + static std::string file (); static void process_histcontrol (const std::string&); - static std::string histcontrol (void); + static std::string histcontrol (); static void set_size (int); - static int size (void); + static int size (); static void ignore_entries (bool = true); - static bool ignoring_entries (void); + static bool ignoring_entries (); static bool add (const std::string&); static void remove (int); - static void clear (void); + static void clear (); - static int where (void); + static int where (); - static int length (void); + static int length (); - static int max_input_history (void); + static int max_input_history (); - static int base (void); + static int base (); - static int current_number (void); + static int current_number (); static void stifle (int); - static int unstifle (void); + static int unstifle (); - static int is_stifled (void); + static int is_stifled (); static void set_mark (int n); // Gag. This declaration has to match the Function typedef in // readline.h. - static int goto_mark (void); + static int goto_mark (); static void read (bool = true); @@ -130,14 +130,14 @@ private: - static bool instance_ok (void); + static bool instance_ok (); - static void make_command_history (void); + static void make_command_history (); // The real thing. static command_history *s_instance; - static void cleanup_instance (void) + static void cleanup_instance () { delete s_instance; s_instance = nullptr; @@ -151,50 +151,50 @@ virtual void do_set_file (const std::string&); - virtual std::string do_file (void); + virtual std::string do_file (); virtual void do_process_histcontrol (const std::string&); - virtual std::string do_histcontrol (void) const { return ""; } + virtual std::string do_histcontrol () const { return ""; } virtual void do_initialize (bool, const std::string&, int, const std::string&); - virtual bool do_is_initialized (void) const; + virtual bool do_is_initialized () const; virtual void do_set_size (int); - virtual int do_size (void) const; + virtual int do_size () const; virtual void do_ignore_entries (bool); - virtual bool do_ignoring_entries (void) const; + virtual bool do_ignoring_entries () const; virtual bool do_add (const std::string&); virtual void do_remove (int); - virtual void do_clear (void); + virtual void do_clear (); - virtual int do_where (void) const; + virtual int do_where () const; - virtual int do_length (void) const; + virtual int do_length () const; - virtual int do_max_input_history (void) const; + virtual int do_max_input_history () const; - virtual int do_base (void) const; + virtual int do_base () const; - virtual int do_current_number (void) const; + virtual int do_current_number () const; virtual void do_stifle (int); - virtual int do_unstifle (void); + virtual int do_unstifle (); - virtual int do_is_stifled (void) const; + virtual int do_is_stifled () const; virtual void do_set_mark (int); - virtual int do_goto_mark (void); + virtual int do_goto_mark (); virtual void do_read (const std::string&, bool); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/data-conv.cc --- a/liboctave/util/data-conv.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/data-conv.cc Mon Jan 30 18:36:03 2023 +0100 @@ -616,7 +616,7 @@ OCTAVE_NORETURN static void -err_unrecognized_float_fmt (void) +err_unrecognized_float_fmt () { (*current_liboctave_error_handler) ("unrecognized floating point format requested"); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/file-info.h --- a/liboctave/util/file-info.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/file-info.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,7 +41,7 @@ { public: - file_info (void) + file_info () : m_file_buf (), m_offsets (), m_timestamp (static_cast (0)) { } @@ -60,22 +60,22 @@ file_info& operator = (const file_info&) = default; - ~file_info (void) = default; + ~file_info () = default; OCTAVE_API std::string get_line (std::size_t line) const; OCTAVE_API std::deque get_lines (std::size_t line, std::size_t num_lines) const; - std::size_t num_lines (void) const { return m_offsets.size (); } + std::size_t num_lines () const { return m_offsets.size (); } - std::string text (void) const { return m_file_buf; } + std::string text () const { return m_file_buf; } - std::vector line_offsets (void) const { return m_offsets; } + std::vector line_offsets () const { return m_offsets; } - sys::time timestamp (void) const { return m_timestamp; } + sys::time timestamp () const { return m_timestamp; } - std::size_t size (void) const { return m_file_buf.length (); } + std::size_t size () const { return m_file_buf.length (); } private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/glob-match.cc --- a/liboctave/util/glob-match.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/glob-match.cc Mon Jan 30 18:36:03 2023 +0100 @@ -38,7 +38,7 @@ } string_vector -glob_match::glob (void) const +glob_match::glob () const { return octave::sys::glob (m_pat); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/glob-match.h --- a/liboctave/util/glob-match.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/glob-match.h Mon Jan 30 18:36:03 2023 +0100 @@ -60,7 +60,7 @@ glob_match& operator = (const glob_match& gm) = default; - ~glob_match (void) = default; + ~glob_match () = default; void set_pattern (const std::string& p) { m_pat = p; } @@ -83,7 +83,7 @@ // We forward to glob_internal here to avoid problems with gnulib's // glob.h defining glob to be rpl_glob. - string_vector glob (void) const; + string_vector glob () const; private: diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/kpse.cc --- a/liboctave/util/kpse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/kpse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -92,7 +92,7 @@ unsigned int kpse_debug = 0; void -kpse_path_iterator::set_end (void) +kpse_path_iterator::set_end () { m_e = m_b + 1; @@ -111,7 +111,7 @@ } void -kpse_path_iterator::next (void) +kpse_path_iterator::next () { m_b = m_e + 1; diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/kpse.h --- a/liboctave/util/kpse.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/kpse.h Mon Jan 30 18:36:03 2023 +0100 @@ -50,7 +50,7 @@ kpse_path_iterator& operator = (const kpse_path_iterator&) = delete; - ~kpse_path_iterator (void) = default; + ~kpse_path_iterator () = default; kpse_path_iterator operator ++ (int) { @@ -59,7 +59,7 @@ return retval; } - std::string operator * (void) { return m_path.substr (m_b, m_e-m_b); } + std::string operator * () { return m_path.substr (m_b, m_e-m_b); } bool operator != (const std::size_t sz) { return m_b != sz; } @@ -70,8 +70,8 @@ std::size_t m_e; std::size_t m_len; - void set_end (void); - void next (void); + void set_end (); + void next (); }; extern unsigned int kpse_debug; diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-array-errwarn.cc --- a/liboctave/util/lo-array-errwarn.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-array-errwarn.cc Mon Jan 30 18:36:03 2023 +0100 @@ -54,14 +54,14 @@ static const char *warning_id_singular_matrix = "Octave:singular-matrix"; void -err_nan_to_logical_conversion (void) +err_nan_to_logical_conversion () { (*current_liboctave_error_handler) ("invalid conversion from NaN to logical"); } void -err_nan_to_character_conversion (void) +err_nan_to_character_conversion () { (*current_liboctave_error_handler) ("invalid conversion from NaN to character"); @@ -124,7 +124,7 @@ // offending one, e.g., (), (,_), or (_,,...[x5]...) std::string -index_exception::expression (void) const +index_exception::expression () const { std::ostringstream buf; @@ -179,7 +179,7 @@ update_message (); } - void update_message (void) + void update_message () { static std::string exp = std::to_string (std::numeric_limits::digits); @@ -190,7 +190,7 @@ } // ID of error to throw - const char * err_id (void) const + const char * err_id () const { return error_id_invalid_index; } @@ -247,7 +247,7 @@ update_message (); } - void update_message (void) + void update_message () { set_message (expression () + ": out of bound " + std::to_string (m_extent) @@ -255,7 +255,7 @@ } // ID of error to throw. - const char * err_id (void) const + const char * err_id () const { return error_id_index_out_of_bounds; } @@ -278,7 +278,7 @@ } void -err_invalid_resize (void) +err_invalid_resize () { (*current_liboctave_error_with_id_handler) ("Octave:invalid-resize", diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-array-errwarn.h --- a/liboctave/util/lo-array-errwarn.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-array-errwarn.h Mon Jan 30 18:36:03 2023 +0100 @@ -52,13 +52,13 @@ set_message (expression ()); } - ~index_exception (void) = default; + ~index_exception () = default; // ID of error to throw. - virtual const char * err_id (void) const = 0; + virtual const char * err_id () const = 0; // By default, update message to show the erroneous index expression. - virtual void update_message (void) { set_message (expression ()); } + virtual void update_message () { set_message (expression ()); } // Position of error: dimension in error, and number of dimensions. void set_pos (octave_idx_type nd_arg, octave_idx_type dim_arg) @@ -96,7 +96,7 @@ protected: // Show what's wrong, e.g., A(-1,_), A(0+1i). - OCTAVE_API std::string expression (void) const; + OCTAVE_API std::string expression () const; // Number of dimensions of indexed object. octave_idx_type m_nd; @@ -109,10 +109,10 @@ }; OCTAVE_NORETURN extern OCTAVE_API void -err_nan_to_logical_conversion (void); +err_nan_to_logical_conversion (); OCTAVE_NORETURN extern OCTAVE_API void -err_nan_to_character_conversion (void); +err_nan_to_character_conversion (); OCTAVE_NORETURN extern OCTAVE_API void err_nonconformant (const char *op, octave_idx_type op1_len, @@ -151,7 +151,7 @@ const std::string& var = ""); OCTAVE_NORETURN extern OCTAVE_API void -err_invalid_resize (void); +err_invalid_resize (); extern OCTAVE_API void warn_singular_matrix (double rcond = 0.0); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-hash.cc --- a/liboctave/util/lo-hash.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-hash.cc Mon Jan 30 18:36:03 2023 +0100 @@ -57,14 +57,14 @@ return buf.str (); } -int md2_digest_size (void) { return octave_md2_digest_size (); } -int md4_digest_size (void) { return octave_md4_digest_size (); } -int md5_digest_size (void) { return octave_md5_digest_size (); } -int sha1_digest_size (void) { return octave_sha1_digest_size (); } -int sha224_digest_size (void) { return octave_sha224_digest_size (); } -int sha256_digest_size (void) { return octave_sha256_digest_size (); } -int sha384_digest_size (void) { return octave_sha384_digest_size (); } -int sha512_digest_size (void) { return octave_sha512_digest_size (); } +int md2_digest_size () { return octave_md2_digest_size (); } +int md4_digest_size () { return octave_md4_digest_size (); } +int md5_digest_size () { return octave_md5_digest_size (); } +int sha1_digest_size () { return octave_sha1_digest_size (); } +int sha224_digest_size () { return octave_sha224_digest_size (); } +int sha256_digest_size () { return octave_sha256_digest_size (); } +int sha384_digest_size () { return octave_sha384_digest_size (); } +int sha512_digest_size () { return octave_sha512_digest_size (); } std::string md2_hash (const std::string& str) diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-hash.h --- a/liboctave/util/lo-hash.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-hash.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,14 +39,14 @@ OCTAVE_API std::string hash (hash_fptr hash_fcn, const std::string& str, int result_buf_len); -OCTAVE_API int md2_digest_size (void); -OCTAVE_API int md4_digest_size (void); -OCTAVE_API int md5_digest_size (void); -OCTAVE_API int sha1_digest_size (void); -OCTAVE_API int sha224_digest_size (void); -OCTAVE_API int sha256_digest_size (void); -OCTAVE_API int sha384_digest_size (void); -OCTAVE_API int sha512_digest_size (void); +OCTAVE_API int md2_digest_size (); +OCTAVE_API int md4_digest_size (); +OCTAVE_API int md5_digest_size (); +OCTAVE_API int sha1_digest_size (); +OCTAVE_API int sha224_digest_size (); +OCTAVE_API int sha256_digest_size (); +OCTAVE_API int sha384_digest_size (); +OCTAVE_API int sha512_digest_size (); OCTAVE_API std::string md2_hash (const std::string& str); OCTAVE_API std::string md4_hash (const std::string& str); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-ieee.cc --- a/liboctave/util/lo-ieee.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-ieee.cc Mon Jan 30 18:36:03 2023 +0100 @@ -65,7 +65,7 @@ } double -lo_ieee_inf_value (void) +lo_ieee_inf_value () { octave_ieee_init (); @@ -73,7 +73,7 @@ } double -lo_ieee_na_value (void) +lo_ieee_na_value () { octave_ieee_init (); @@ -81,7 +81,7 @@ } double -lo_ieee_nan_value (void) +lo_ieee_nan_value () { octave_ieee_init (); @@ -97,7 +97,7 @@ } float -lo_ieee_float_inf_value (void) +lo_ieee_float_inf_value () { octave_ieee_init (); @@ -105,7 +105,7 @@ } float -lo_ieee_float_na_value (void) +lo_ieee_float_na_value () { octave_ieee_init (); @@ -113,7 +113,7 @@ } float -lo_ieee_float_nan_value (void) +lo_ieee_float_nan_value () { octave_ieee_init (); @@ -121,7 +121,7 @@ } void -octave_ieee_init (void) +octave_ieee_init () { static bool initialized = false; diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-ieee.h --- a/liboctave/util/lo-ieee.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-ieee.h Mon Jan 30 18:36:03 2023 +0100 @@ -129,44 +129,31 @@ struct numeric_limits { public: - static T NA (void) { return static_cast (0); } - static T NaN (void) { return static_cast (0); } - static T Inf (void) { return static_cast (0); } + static T NA () { return static_cast (0); } + static T NaN () { return static_cast (0); } + static T Inf () { return static_cast (0); } }; template <> struct numeric_limits { public: - static double NA (void) { return octave_NA; } - static double NaN (void) { return octave_NaN; } - static double Inf (void) { return octave_Inf; } + static double NA () { return octave_NA; } + static double NaN () { return octave_NaN; } + static double Inf () { return octave_Inf; } }; template <> struct numeric_limits { public: - static float NA (void) { return octave_Float_NA; } - static float NaN (void) { return octave_Float_NaN; } - static float Inf (void) { return octave_Float_Inf; } + static float NA () { return octave_Float_NA; } + static float NaN () { return octave_Float_NaN; } + static float Inf () { return octave_Float_Inf; } }; OCTAVE_END_NAMESPACE(octave) #endif -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use '__lo_ieee_isfinite' instead") -inline int __lo_ieee_finite (double x) { return __lo_ieee_isfinite (x); } - -OCTAVE_DEPRECATED (7, "use '__lo_ieee_float_isfinite' instead") -inline int __lo_ieee_float_finite (float x) -{ return __lo_ieee_float_isfinite (x); } - -#define lo_ieee_finite(x) lo_ieee_isfinite(x) - #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-regexp.cc --- a/liboctave/util/lo-regexp.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-regexp.cc Mon Jan 30 18:36:03 2023 +0100 @@ -112,13 +112,13 @@ // the user doesn't want. void -regexp::free (void) +regexp::free () { octave_pcre_code_free (static_cast (m_code)); } void -regexp::compile_internal (void) +regexp::compile_internal () { // If we had a previously compiled pattern, release it. free (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-regexp.h --- a/liboctave/util/lo-regexp.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-regexp.h Mon Jan 30 18:36:03 2023 +0100 @@ -61,7 +61,7 @@ regexp& operator = (const regexp& rx) = default; - ~regexp (void) { free (); } + ~regexp () { free (); } void compile (const std::string& pat, const regexp::opts& opt = regexp::opts ()) @@ -125,7 +125,7 @@ { public: - opts (void) + opts () : m_case_insensitive (false), m_dotexceptnewline (false), m_emptymatch (false), m_freespacing (false), m_lineanchors (false), m_once (false) { } @@ -134,7 +134,7 @@ opts& operator = (const opts&) = default; - ~opts (void) = default; + ~opts () = default; void case_insensitive (bool val) { m_case_insensitive = val; } void dotexceptnewline (bool val) { m_dotexceptnewline = val; } @@ -143,12 +143,12 @@ void lineanchors (bool val) { m_lineanchors = val; } void once (bool val) { m_once = val; } - bool case_insensitive (void) const { return m_case_insensitive; } - bool dotexceptnewline (void) const { return m_dotexceptnewline; } - bool emptymatch (void) const { return m_emptymatch; } - bool freespacing (void) const { return m_freespacing; } - bool lineanchors (void) const { return m_lineanchors; } - bool once (void) const { return m_once; } + bool case_insensitive () const { return m_case_insensitive; } + bool dotexceptnewline () const { return m_dotexceptnewline; } + bool emptymatch () const { return m_emptymatch; } + bool freespacing () const { return m_freespacing; } + bool lineanchors () const { return m_lineanchors; } + bool once () const { return m_once; } private: @@ -175,12 +175,12 @@ match_element& operator = (const match_element&) = default; - std::string match_string (void) const { return m_match_string; } - string_vector named_tokens (void) const { return m_named_tokens; } - string_vector tokens (void) const { return m_tokens; } - Matrix token_extents (void) const { return m_token_extents; } - double start (void) const { return m_start; } - double end (void) const { return m_end; } + std::string match_string () const { return m_match_string; } + string_vector named_tokens () const { return m_named_tokens; } + string_vector tokens () const { return m_tokens; } + Matrix token_extents () const { return m_token_extents; } + double start () const { return m_start; } + double end () const { return m_end; } private: @@ -200,7 +200,7 @@ { public: - match_data (void) + match_data () : base_list (), m_named_pats () { } @@ -212,9 +212,9 @@ match_data& operator = (const match_data&) = default; - ~match_data (void) = default; + ~match_data () = default; - string_vector named_patterns (void) const { return m_named_pats; } + string_vector named_patterns () const { return m_named_pats; } private: @@ -236,9 +236,9 @@ Array m_named_idx; std::string m_who; - void free (void); + void free (); - void compile_internal (void); + void compile_internal (); }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-utils.cc --- a/liboctave/util/lo-utils.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-utils.cc Mon Jan 30 18:36:03 2023 +0100 @@ -47,473 +47,479 @@ OCTAVE_BEGIN_NAMESPACE(octave) -bool is_int_or_inf_or_nan (double x) -{ - return math::isnan (x) || math::x_nint (x) == x; -} + bool is_int_or_inf_or_nan (double x) + { + return math::isnan (x) || math::x_nint (x) == x; + } + + bool too_large_for_float (double x) + { + return (math::isfinite (x) + && fabs (x) > std::numeric_limits::max ()); + } + + bool too_large_for_float (const Complex& x) + { + return (too_large_for_float (x.real ()) + || too_large_for_float (x.imag ())); + } + + bool is_int_or_inf_or_nan (float x) + { + return math::isnan (x) || math::x_nint (x) == x; + } -bool too_large_for_float (double x) -{ - return (math::isfinite (x) - && fabs (x) > std::numeric_limits::max ()); -} + // Save a string. + + char * strsave (const char *s) + { + if (! s) + return nullptr; -bool too_large_for_float (const Complex& x) -{ - return (too_large_for_float (x.real ()) - || too_large_for_float (x.imag ())); -} + int len = strlen (s); + char *tmp = new char [len+1]; + tmp = strcpy (tmp, s); + return tmp; + } + + std::string fgets (FILE *f) + { + bool eof; + return fgets (f, eof); + } + + std::string fgets (FILE *f, bool& eof) + { + eof = false; + + std::string retval; -bool is_int_or_inf_or_nan (float x) -{ - return math::isnan (x) || math::x_nint (x) == x; -} + int grow_size = 1024; + int max_size = grow_size; + + char *buf = static_cast (std::malloc (max_size)); + if (! buf) + (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size); -// Save a string. + char *bufptr = buf; + int len = 0; -char * strsave (const char *s) -{ - if (! s) - return nullptr; + do + { + if (std::fgets (bufptr, grow_size, f)) + { + len = strlen (bufptr); - int len = strlen (s); - char *tmp = new char [len+1]; - tmp = strcpy (tmp, s); - return tmp; -} + if (len == grow_size - 1) + { + int tmp = bufptr - buf + grow_size - 1; + grow_size *= 2; + max_size += grow_size; + auto tmpbuf = static_cast (std::realloc (buf, max_size)); + if (! tmpbuf) + { + free (buf); + (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size); + } + buf = tmpbuf; + bufptr = buf + tmp; -std::string fgets (FILE *f) -{ - bool eof; - return fgets (f, eof); -} + if (*(bufptr-1) == '\n') + { + *bufptr = '\0'; + retval = buf; + } + } + else if (bufptr[len-1] != '\n') + { + bufptr[len++] = '\n'; + bufptr[len] = '\0'; + retval = buf; + } + else + retval = buf; + } + else + { + if (len == 0) + { + eof = true; -std::string fgets (FILE *f, bool& eof) -{ - eof = false; + free (buf); + + buf = nullptr; + } + + break; + } + } + while (retval.empty ()); + + free (buf); + + octave_quit (); - std::string retval; + return retval; + } - int grow_size = 1024; - int max_size = grow_size; + std::string fgetl (FILE *f) + { + bool eof; + return fgetl (f, eof); + } + + std::string fgetl (FILE *f, bool& eof) + { + std::string retval = fgets (f, eof); + + if (! retval.empty () && retval.back () == '\n') + retval.pop_back (); - char *buf = static_cast (std::malloc (max_size)); - if (! buf) - (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size); + return retval; + } + + template + T + read_value (std::istream& is) + { + T retval; + is >> retval; + return retval; + } - char *bufptr = buf; - int len = 0; + template OCTAVE_API bool read_value (std::istream& is); + template OCTAVE_API octave_int8 read_value (std::istream& is); + template OCTAVE_API octave_int16 read_value (std::istream& is); + template OCTAVE_API octave_int32 read_value (std::istream& is); + template OCTAVE_API octave_int64 read_value (std::istream& is); + template OCTAVE_API octave_uint8 read_value (std::istream& is); + template OCTAVE_API octave_uint16 read_value (std::istream& is); + template OCTAVE_API octave_uint32 read_value (std::istream& is); + template OCTAVE_API octave_uint64 read_value (std::istream& is); - do - { - if (std::fgets (bufptr, grow_size, f)) + // Note that the caller is responsible for repositioning the stream on + // failure. + + template + T + read_inf_nan_na (std::istream& is, char c0) + { + T val = 0.0; + + switch (c0) + { + case 'i': case 'I': { - len = strlen (bufptr); - - if (len == grow_size - 1) + char c1 = is.get (); + if (c1 == 'n' || c1 == 'N') { - int tmp = bufptr - buf + grow_size - 1; - grow_size *= 2; - max_size += grow_size; - auto tmpbuf = static_cast (std::realloc (buf, max_size)); - if (! tmpbuf) + char c2 = is.get (); + if (c2 == 'f' || c2 == 'F') { - free (buf); - (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size); + val = std::numeric_limits::infinity (); + is.peek (); // Potentially set EOF bit } - buf = tmpbuf; - bufptr = buf + tmp; + else + is.setstate (std::ios::failbit); + } + else + is.setstate (std::ios::failbit); + } + break; - if (*(bufptr-1) == '\n') + case 'n': case 'N': + { + char c1 = is.get (); + if (c1 == 'a' || c1 == 'A') + { + char c2 = is.get (); + if (c2 == 'n' || c2 == 'N') { - *bufptr = '\0'; - retval = buf; + val = std::numeric_limits::quiet_NaN (); + is.peek (); // Potentially set EOF bit + } + else + { + val = numeric_limits::NA (); + if (c2 != std::istream::traits_type::eof ()) + is.putback (c2); + else + is.clear (is.rdstate () & ~std::ios::failbit); } } - else if (bufptr[len-1] != '\n') - { - bufptr[len++] = '\n'; - bufptr[len] = '\0'; - retval = buf; - } else - retval = buf; + is.setstate (std::ios::failbit); } - else + break; + + default: + (*current_liboctave_error_handler) + ("read_inf_nan_na: invalid character '%c'", c0); + } + + return val; + } + + // Read a double value. Discard any sign on NaN and NA. + + template + double + read_fp_value (std::istream& is) + { + T val = 0.0; + + // FIXME: resetting stream position is likely to fail unless we are + // reading from a file. + std::streampos pos = is.tellg (); + + is >> std::ws; // skip through whitespace and advance stream pointer + + bool neg = false; + char c1 = is.get (); + switch (c1) + { + case '-': + neg = true; + OCTAVE_FALLTHROUGH; + + case '+': { - if (len == 0) + char c2 = 0; + c2 = is.get (); + if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') + val = read_inf_nan_na (is, c2); + else if (isspace (c2)) + is.setstate (std::ios::failbit); + else { - eof = true; - - free (buf); - - buf = nullptr; + is.putback (c2); + is >> val; } - break; + if (neg && ! math::isnan (val) && ! is.fail ()) + val = -val; } - } - while (retval.empty ()); - - free (buf); - - octave_quit (); - - return retval; -} + break; -std::string fgetl (FILE *f) -{ - bool eof; - return fgetl (f, eof); -} + case 'i': case 'I': + case 'n': case 'N': + val = read_inf_nan_na (is, c1); + break; -std::string fgetl (FILE *f, bool& eof) -{ - std::string retval = fgets (f, eof); - - if (! retval.empty () && retval.back () == '\n') - retval.pop_back (); - - return retval; -} + default: + is.putback (c1); + is >> val; + break; + } -template -T -read_value (std::istream& is) -{ - T retval; - is >> retval; - return retval; -} + std::ios::iostate status = is.rdstate (); + if (status & std::ios::failbit) + { + // Convert MAX_VAL returned by C++ streams for very large numbers to Inf + if (val == std::numeric_limits::max ()) + { + if (neg) + val = -std::numeric_limits::infinity (); + else + val = std::numeric_limits::infinity (); + is.clear (status & ~std::ios::failbit); + } + 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); + } + } -template OCTAVE_API bool read_value (std::istream& is); -template OCTAVE_API octave_int8 read_value (std::istream& is); -template OCTAVE_API octave_int16 read_value (std::istream& is); -template OCTAVE_API octave_int32 read_value (std::istream& is); -template OCTAVE_API octave_int64 read_value (std::istream& is); -template OCTAVE_API octave_uint8 read_value (std::istream& is); -template OCTAVE_API octave_uint16 read_value (std::istream& is); -template OCTAVE_API octave_uint32 read_value (std::istream& is); -template OCTAVE_API octave_uint64 read_value (std::istream& is); + return val; + } -// Note that the caller is responsible for repositioning the stream on -// failure. + template + std::complex + read_cx_fp_value (std::istream& is) + { + T re = 0.0; + T im = 0.0; -template -T -read_inf_nan_na (std::istream& is, char c0) -{ - T val = 0.0; + std::complex cx = 0.0; + + char ch = ' '; - switch (c0) - { - case 'i': case 'I': + while (isspace (ch)) + ch = is.get (); + + if (ch == '(') { - char c1 = is.get (); - if (c1 == 'n' || c1 == 'N') + re = read_value (is); + ch = is.get (); + + if (ch == ',') { - char c2 = is.get (); - if (c2 == 'f' || c2 == 'F') - val = std::numeric_limits::infinity (); + im = read_value (is); + ch = is.get (); + + if (ch == ')') + cx = std::complex (re, im); else is.setstate (std::ios::failbit); } - else - is.setstate (std::ios::failbit); - } - break; - - case 'n': case 'N': - { - char c1 = is.get (); - if (c1 == 'a' || c1 == 'A') - { - char c2 = is.get (); - if (c2 == 'n' || c2 == 'N') - val = std::numeric_limits::quiet_NaN (); - else - { - val = numeric_limits::NA (); - if (c2 != std::istream::traits_type::eof ()) - is.putback (c2); - else - is.clear (is.rdstate () & ~std::ios::failbit); - } - } + else if (ch == ')') + cx = re; else is.setstate (std::ios::failbit); } - break; - - default: - (*current_liboctave_error_handler) - ("read_inf_nan_na: invalid character '%c'", c0); - } - - return val; -} - -// Read a double value. Discard any sign on NaN and NA. - -template -double -read_fp_value (std::istream& is) -{ - T val = 0.0; - - // FIXME: resetting stream position is likely to fail unless we are - // reading from a file. - std::streampos pos = is.tellg (); - - char c1 = ' '; + else + { + is.putback (ch); + cx = read_value (is); + } - while (isspace (c1)) - c1 = is.get (); - - bool neg = false; - - switch (c1) - { - case '-': - neg = true; - OCTAVE_FALLTHROUGH; + return cx; + } - case '+': - { - char c2 = 0; - c2 = is.get (); - if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') - val = read_inf_nan_na (is, c2); - else - { - is.putback (c2); - is >> val; - } + // FIXME: Could we use traits and enable_if to avoid duplication in the + // following specializations? - if (neg && ! is.fail ()) - val = -val; - } - break; + template <> OCTAVE_API double read_value (std::istream& is) + { + return read_fp_value (is); + } - case 'i': case 'I': - case 'n': case 'N': - val = read_inf_nan_na (is, c1); - break; + template <> OCTAVE_API Complex read_value (std::istream& is) + { + return read_cx_fp_value (is); + } - default: - is.putback (c1); - is >> val; - break; - } + template <> OCTAVE_API float read_value (std::istream& is) + { + return read_fp_value (is); + } - std::ios::iostate status = is.rdstate (); - if (status & std::ios::failbit) - { - // Convert MAX_VAL returned by C++ streams for very large numbers to Inf - if (val == std::numeric_limits::max ()) - { - if (neg) - val = -std::numeric_limits::infinity (); - else - val = std::numeric_limits::infinity (); - is.clear (status & ~std::ios::failbit); - } - else - { - // True error. Reset stream to original position and pass status on. - is.clear (); - is.seekg (pos); - is.setstate (status); - } - } - - return val; -} + template <> OCTAVE_API FloatComplex read_value (std::istream& is) + { + return read_cx_fp_value (is); + } -template -std::complex -read_cx_fp_value (std::istream& is) -{ - T re = 0.0; - T im = 0.0; - - std::complex cx = 0.0; - - char ch = ' '; - - while (isspace (ch)) - ch = is.get (); - - if (ch == '(') - { - re = read_value (is); - ch = is.get (); - - if (ch == ',') - { - im = read_value (is); - ch = is.get (); + template + void + write_value (std::ostream& os, const T& value) + { + os << value; + } - if (ch == ')') - cx = std::complex (re, im); - else - is.setstate (std::ios::failbit); - } - else if (ch == ')') - cx = re; - else - is.setstate (std::ios::failbit); - } - else - { - is.putback (ch); - cx = read_value (is); - } - - return cx; -} - -// FIXME: Could we use traits and enable_if to avoid duplication in the -// following specializations? + template OCTAVE_API void + write_value (std::ostream& os, const bool& value); + template OCTAVE_API void + write_value (std::ostream& os, const octave_int8& value); + template OCTAVE_API void + write_value (std::ostream& os, const octave_int16& value); + template OCTAVE_API void + write_value (std::ostream& os, const octave_int32& value); + template OCTAVE_API void + write_value (std::ostream& os, const octave_int64& value); + template OCTAVE_API void + write_value (std::ostream& os, const octave_uint8& value); + template OCTAVE_API void + write_value (std::ostream& os, const octave_uint16& value); + template OCTAVE_API void + write_value (std::ostream& os, const octave_uint32& value); + template OCTAVE_API void + write_value (std::ostream& os, const octave_uint64& value); -template <> OCTAVE_API double read_value (std::istream& is) -{ - return read_fp_value (is); -} - -template <> OCTAVE_API Complex read_value (std::istream& is) -{ - return read_cx_fp_value (is); -} + // Note: precision is supposed to be managed outside of this function by + // setting stream parameters. -template <> OCTAVE_API float read_value (std::istream& is) -{ - return read_fp_value (is); -} - -template <> OCTAVE_API FloatComplex read_value (std::istream& is) -{ - return read_cx_fp_value (is); -} - -template -void -write_value (std::ostream& os, const T& value) -{ - os << value; -} + template <> OCTAVE_API void + write_value (std::ostream& os, const double& value) + { + if (lo_ieee_is_NA (value)) + os << "NA"; + else if (lo_ieee_isnan (value)) + os << "NaN"; + else if (lo_ieee_isinf (value)) + os << (value < 0 ? "-Inf" : "Inf"); + else + os << value; + } -template OCTAVE_API void -write_value (std::ostream& os, const bool& value); -template OCTAVE_API void -write_value (std::ostream& os, const octave_int8& value); -template OCTAVE_API void -write_value (std::ostream& os, const octave_int16& value); -template OCTAVE_API void -write_value (std::ostream& os, const octave_int32& value); -template OCTAVE_API void -write_value (std::ostream& os, const octave_int64& value); -template OCTAVE_API void -write_value (std::ostream& os, const octave_uint8& value); -template OCTAVE_API void -write_value (std::ostream& os, const octave_uint16& value); -template OCTAVE_API void -write_value (std::ostream& os, const octave_uint32& value); -template OCTAVE_API void -write_value (std::ostream& os, const octave_uint64& value); + template <> OCTAVE_API void + write_value (std::ostream& os, const Complex& value) + { + os << '('; + write_value (os, real (value)); + os << ','; + write_value (os, imag (value)); + os << ')'; + } -// Note: precision is supposed to be managed outside of this function by -// setting stream parameters. - -template <> OCTAVE_API void -write_value (std::ostream& os, const double& value) -{ - if (lo_ieee_is_NA (value)) - os << "NA"; - else if (lo_ieee_isnan (value)) - os << "NaN"; - else if (lo_ieee_isinf (value)) - os << (value < 0 ? "-Inf" : "Inf"); - else - os << value; -} + // Note: precision is supposed to be managed outside of this function by + // setting stream parameters. -template <> OCTAVE_API void -write_value (std::ostream& os, const Complex& value) -{ - os << '('; - write_value (os, real (value)); - os << ','; - write_value (os, imag (value)); - os << ')'; -} - -// Note: precision is supposed to be managed outside of this function by -// setting stream parameters. + template <> OCTAVE_API void + write_value (std::ostream& os, const float& value) + { + if (lo_ieee_is_NA (value)) + os << "NA"; + else if (lo_ieee_isnan (value)) + os << "NaN"; + else if (lo_ieee_isinf (value)) + os << (value < 0 ? "-Inf" : "Inf"); + else + os << value; + } -template <> OCTAVE_API void -write_value (std::ostream& os, const float& value) -{ - if (lo_ieee_is_NA (value)) - os << "NA"; - else if (lo_ieee_isnan (value)) - os << "NaN"; - else if (lo_ieee_isinf (value)) - os << (value < 0 ? "-Inf" : "Inf"); - else - os << value; -} - -template <> OCTAVE_API void -write_value (std::ostream& os, const FloatComplex& value) -{ - os << '('; - write_value (os, real (value)); - os << ','; - write_value (os, imag (value)); - os << ')'; -} + template <> OCTAVE_API void + write_value (std::ostream& os, const FloatComplex& value) + { + os << '('; + write_value (os, real (value)); + os << ','; + write_value (os, imag (value)); + os << ')'; + } OCTAVE_BEGIN_NAMESPACE(math) -bool int_multiply_overflow (int a, int b, int *r) -{ - return octave_i_multiply_overflow_wrapper (a, b, r); -} + bool int_multiply_overflow (int a, int b, int *r) + { + return octave_i_multiply_overflow_wrapper (a, b, r); + } -bool int_multiply_overflow (long int a, long int b, long int *r) -{ - return octave_li_multiply_overflow_wrapper (a, b, r); -} + bool int_multiply_overflow (long int a, long int b, long int *r) + { + return octave_li_multiply_overflow_wrapper (a, b, r); + } #if defined (OCTAVE_HAVE_LONG_LONG_INT) -bool int_multiply_overflow (long long int a, long long int b, - long long int *r) -{ - return octave_lli_multiply_overflow_wrapper (a, b, r); -} + bool int_multiply_overflow (long long int a, long long int b, + long long int *r) + { + return octave_lli_multiply_overflow_wrapper (a, b, r); + } #endif -bool int_multiply_overflow (unsigned int a, unsigned int b, - unsigned int *r) -{ - return octave_ui_multiply_overflow_wrapper (a, b, r); -} + bool int_multiply_overflow (unsigned int a, unsigned int b, + unsigned int *r) + { + return octave_ui_multiply_overflow_wrapper (a, b, r); + } -bool int_multiply_overflow (unsigned long int a, unsigned long int b, - unsigned long int *r) -{ - return octave_uli_multiply_overflow_wrapper (a, b, r); -} + bool int_multiply_overflow (unsigned long int a, unsigned long int b, + unsigned long int *r) + { + return octave_uli_multiply_overflow_wrapper (a, b, r); + } #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT) -bool int_multiply_overflow (unsigned long long int a, - unsigned long long int b, - unsigned long long int *r) -{ - return octave_ulli_multiply_overflow_wrapper (a, b, r); -} + bool int_multiply_overflow (unsigned long long int a, + unsigned long long int b, + unsigned long long int *r) + { + return octave_ulli_multiply_overflow_wrapper (a, b, r); + } #endif OCTAVE_END_NAMESPACE(math) diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/lo-utils.h --- a/liboctave/util/lo-utils.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/lo-utils.h Mon Jan 30 18:36:03 2023 +0100 @@ -137,146 +137,4 @@ OCTAVE_END_NAMESPACE(math) OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -template -OCTAVE_DEPRECATED (7, "use 'octave::any_all_test' instead") -bool -any_all_test (F fcn, const T *m, octave_idx_type len) -{ - return octave::any_all_test (fcn, m, len); -} - -OCTAVE_DEPRECATED (7, "use 'octave::is_int_or_inf_or_nan' instead") -inline bool xis_int_or_inf_or_nan (double x) -{ - return octave::is_int_or_inf_or_nan (x); -} - -template -OCTAVE_DEPRECATED (7, "use 'octave::is_one_or_zero' instead") -bool -xis_one_or_zero (const T& x) -{ - return octave::is_one_or_zero (x); -} - -template -OCTAVE_DEPRECATED (7, "use 'octave::is_zero' instead") -bool -xis_zero (const T& x) -{ - return octave::is_zero (x); -} - -OCTAVE_DEPRECATED (7, "use 'octave::' instead") -inline bool xtoo_large_for_float (double x) -{ - return octave::too_large_for_float (x); -} - -OCTAVE_DEPRECATED (7, "use 'octave::' instead") -inline bool xtoo_large_for_float (const Complex& x) -{ - return octave::too_large_for_float (x); -} - -OCTAVE_DEPRECATED (7, "use 'octave::' instead") -inline bool xis_int_or_inf_or_nan (float x) -{ - return octave::is_int_or_inf_or_nan (x); -} - -OCTAVE_DEPRECATED (7, "use 'octave::' instead") -inline bool xtoo_large_for_float (float x) -{ - return octave::too_large_for_float (x); -} - -OCTAVE_DEPRECATED (7, "use 'octave::strsave' instead") -inline char * strsave (const char *s) -{ - return octave::strsave (s); -} - -OCTAVE_DEPRECATED (7, "use 'octave::fgets' instead") -inline std::string octave_fgets (std::FILE *f) -{ - return octave::fgets (f); -} - -OCTAVE_DEPRECATED (7, "use 'octave::fgetl' instead") -inline std::string octave_fgetl (std::FILE *f) -{ - return octave::fgetl (f); -} - -OCTAVE_DEPRECATED (7, "use 'octave::fgets' instead") -inline std::string octave_fgets (std::FILE *f, bool& eof) -{ - return octave::fgets (f, eof); -} - -OCTAVE_DEPRECATED (7, "use 'octave::fgetl' instead") -inline std::string octave_fgetl (std::FILE *f, bool& eof) -{ - return octave::fgetl (f, eof); -} - -OCTAVE_DEPRECATED (7, "use 'octave::read_value' instead") -inline double -octave_read_double (std::istream& is) -{ - return octave::read_value (is); -} - -OCTAVE_DEPRECATED (7, "use 'octave::read_value' instead") -inline Complex -octave_read_complex (std::istream& is) -{ - return octave::read_value (is); -} - -OCTAVE_DEPRECATED (7, "use 'octave::read_value' instead") -inline float -octave_read_float (std::istream& is) -{ - return octave::read_value (is); -} - -OCTAVE_DEPRECATED (7, "use 'octave::read_value' instead") -inline FloatComplex -octave_read_float_complex (std::istream& is) -{ - return octave::read_value (is); -} - -OCTAVE_DEPRECATED (7, "use 'octave::write_value' instead") -inline void -octave_write_double (std::ostream& os, double value) -{ - octave::write_value (os, value); -} - -OCTAVE_DEPRECATED (7, "use 'octave::write_value' instead") -inline void -octave_write_complex (std::ostream& os, const Complex& value) -{ - octave::write_value (os, value); -} - -OCTAVE_DEPRECATED (7, "use 'octave::write_value' instead") -inline void -octave_write_float (std::ostream& os, float value) -{ - octave::write_value (os, value); -} - -OCTAVE_DEPRECATED (7, "use 'octave::write_value' instead") -inline void -octave_write_float_complex (std::ostream& os, const FloatComplex& value) -{ - octave::write_value (os, value); -} #endif - -#endif diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-inttypes.cc --- a/liboctave/util/oct-inttypes.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-inttypes.cc Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ #define DEFINE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME) \ template <> \ OCTAVE_API const char * \ - octave_int::type_name (void) { return TYPENAME; } + octave_int::type_name () { return TYPENAME; } DEFINE_OCTAVE_INT_TYPENAME (int8_t, "int8") DEFINE_OCTAVE_INT_TYPENAME (int16_t, "int16") diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-inttypes.h --- a/liboctave/util/oct-inttypes.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-inttypes.h Mon Jan 30 18:36:03 2023 +0100 @@ -346,8 +346,8 @@ { public: - static T min_val (void) { return std::numeric_limits::min (); } - static T max_val (void) { return std::numeric_limits::max (); } + static T min_val () { return std::numeric_limits::min (); } + static T max_val () { return std::numeric_limits::max (); } // Convert integer value. @@ -787,7 +787,7 @@ typedef T val_type; - octave_int (void) : m_ival () { } + octave_int () : m_ival () { } octave_int (T i) : m_ival (i) { } @@ -827,26 +827,26 @@ octave_int& operator = (const octave_int&) = default; - ~octave_int (void) = default; + ~octave_int () = default; - T value (void) const { return m_ival; } + T value () const { return m_ival; } - const unsigned char * iptr (void) const + const unsigned char * iptr () const { return reinterpret_cast (& m_ival); } - bool operator ! (void) const { return ! m_ival; } + bool operator ! () const { return ! m_ival; } - bool bool_value (void) const { return static_cast (value ()); } + bool bool_value () const { return static_cast (value ()); } - char char_value (void) const { return static_cast (value ()); } + char char_value () const { return static_cast (value ()); } - double double_value (void) const { return static_cast (value ()); } + double double_value () const { return static_cast (value ()); } - float float_value (void) const { return static_cast (value ()); } + float float_value () const { return static_cast (value ()); } - operator T (void) const { return value (); } + operator T () const { return value (); } octave_int operator + () const { return *this; } @@ -864,7 +864,7 @@ #undef OCTAVE_INT_UN_OP - octave_int operator ~ (void) const + octave_int operator ~ () const { T bitinv = ~ m_ival; return bitinv; @@ -895,12 +895,12 @@ #undef OCTAVE_INT_BIN_OP - static octave_int min (void) { return std::numeric_limits::min (); } - static octave_int max (void) { return std::numeric_limits::max (); } + static octave_int min () { return std::numeric_limits::min (); } + static octave_int max () { return std::numeric_limits::max (); } - static int nbits (void) { return std::numeric_limits::digits; } + static int nbits () { return std::numeric_limits::digits; } - static int byte_size (void) { return sizeof (T); } + static int byte_size () { return sizeof (T); } static const OCTAVE_API char * type_name (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-mutex.cc --- a/liboctave/util/oct-mutex.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-mutex.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,19 +39,19 @@ OCTAVE_BEGIN_NAMESPACE(octave) void -base_mutex::lock (void) +base_mutex::lock () { (*current_liboctave_error_handler) ("mutex not supported on this platform"); } void -base_mutex::unlock (void) +base_mutex::unlock () { (*current_liboctave_error_handler) ("mutex not supported on this platform"); } bool -base_mutex::try_lock (void) +base_mutex::try_lock () { (*current_liboctave_error_handler) ("mutex not supported on this platform"); @@ -64,28 +64,28 @@ w32_mutex : public base_mutex { public: - w32_mutex (void) + w32_mutex () : base_mutex () { InitializeCriticalSection (&cs); } - ~w32_mutex (void) + ~w32_mutex () { DeleteCriticalSection (&cs); } - void lock (void) + void lock () { EnterCriticalSection (&cs); } - void unlock (void) + void unlock () { LeaveCriticalSection (&cs); } - bool try_lock (void) + bool try_lock () { return (TryEnterCriticalSection (&cs) != 0); } @@ -97,13 +97,13 @@ static DWORD thread_id = 0; void -thread::init (void) +thread::init () { thread_id = GetCurrentThreadId (); } bool -thread::is_thread (void) +thread::is_thread () { return (GetCurrentThreadId () == thread_id); } @@ -114,7 +114,7 @@ pthread_mutex : public base_mutex { public: - pthread_mutex (void) + pthread_mutex () : base_mutex (), m_pm () { pthread_mutexattr_t attr; @@ -125,22 +125,22 @@ pthread_mutexattr_destroy (&attr); } - ~pthread_mutex (void) + ~pthread_mutex () { pthread_mutex_destroy (&m_pm); } - void lock (void) + void lock () { pthread_mutex_lock (&m_pm); } - void unlock (void) + void unlock () { pthread_mutex_unlock (&m_pm); } - bool try_lock (void) + bool try_lock () { return (pthread_mutex_trylock (&m_pm) == 0); } @@ -152,13 +152,13 @@ static pthread_t thread_id = 0; void -thread::init (void) +thread::init () { thread_id = pthread_self (); } bool -thread::is_thread (void) +thread::is_thread () { return (pthread_equal (thread_id, pthread_self ()) != 0); } @@ -166,7 +166,7 @@ #endif static base_mutex * -init_rep (void) +init_rep () { #if defined (OCTAVE_USE_WINDOWS_API) return new w32_mutex (); @@ -177,6 +177,6 @@ #endif } -mutex::mutex (void) : m_rep (init_rep ()) { } +mutex::mutex () : m_rep (init_rep ()) { } OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-mutex.h --- a/liboctave/util/oct-mutex.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-mutex.h Mon Jan 30 18:36:03 2023 +0100 @@ -41,15 +41,15 @@ public: friend class mutex; - base_mutex (void) = default; + base_mutex () = default; - virtual ~base_mutex (void) = default; + virtual ~base_mutex () = default; - virtual void lock (void); + virtual void lock (); - virtual void unlock (void); + virtual void unlock (); - virtual bool try_lock (void); + virtual bool try_lock (); }; class @@ -57,25 +57,25 @@ mutex { public: - mutex (void); + mutex (); mutex (const mutex& m) = default; - ~mutex (void) = default; + ~mutex () = default; mutex& operator = (const mutex& m) = default; - void lock (void) + void lock () { m_rep->lock (); } - void unlock (void) + void unlock () { m_rep->unlock (); } - bool try_lock (void) + bool try_lock () { return m_rep->try_lock (); } @@ -107,15 +107,15 @@ autolock& operator = (const autolock&) = delete; - ~autolock (void) + ~autolock () { if (m_lock_result) m_mutex.unlock (); } - bool ok (void) const { return m_lock_result; } + bool ok () const { return m_lock_result; } - operator bool (void) const { return ok (); } + operator bool () const { return ok (); } private: @@ -131,9 +131,9 @@ { public: - static void init (void); + static void init (); - static bool is_thread (void); + static bool is_thread (); }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-refcount.h --- a/liboctave/util/oct-refcount.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-refcount.h Mon Jan 30 18:36:03 2023 +0100 @@ -49,10 +49,10 @@ refcount& operator = (const refcount&) = delete; - ~refcount (void) = default; + ~refcount () = default; // Increment/Decrement. int is postfix. - count_type operator++ (void) + count_type operator++ () { return ++m_count; } @@ -62,7 +62,7 @@ return m_count++; } - count_type operator-- (void) + count_type operator-- () { return --m_count; } @@ -72,12 +72,12 @@ return m_count--; } - count_type value (void) const + count_type value () const { return m_count.load (); } - operator count_type (void) const + operator count_type () const { return value (); } diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-shlib.cc --- a/liboctave/util/oct-shlib.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-shlib.cc Mon Jan 30 18:36:03 2023 +0100 @@ -62,12 +62,12 @@ std::list possibly_unreferenced_dynamic_libraries; -void dynamic_library::delete_later (void) +void dynamic_library::delete_later () { possibly_unreferenced_dynamic_libraries.push_back (*this); } -int release_unreferenced_dynamic_libraries (void) +int release_unreferenced_dynamic_libraries () { possibly_unreferenced_dynamic_libraries.clear (); @@ -87,14 +87,14 @@ } bool -dynamic_library::dynlib_rep::is_out_of_date (void) const +dynamic_library::dynlib_rep::is_out_of_date () const { sys::file_stat fs (m_file); return (fs && fs.is_newer (m_time_loaded)); } void -dynamic_library::dynlib_rep::fake_reload (void) +dynamic_library::dynlib_rep::fake_reload () { // We can't actually reload the library, but we'll pretend we did. sys::file_stat fs (m_file); @@ -127,7 +127,7 @@ } std::list -dynamic_library::dynlib_rep::function_names (void) const +dynamic_library::dynlib_rep::function_names () const { std::list retval; @@ -184,7 +184,7 @@ octave_dlopen_shlib& operator = (const octave_dlopen_shlib&) = delete; - ~octave_dlopen_shlib (void); + ~octave_dlopen_shlib (); void * search (const std::string& name, const dynamic_library::name_mangler& mangler @@ -194,7 +194,7 @@ // normally throw an exception, avoiding the construction of an invalid // library. Leave it here for possible future use. - bool is_open (void) const + bool is_open () const { return (m_search_all_loaded || m_library != nullptr); } @@ -246,7 +246,7 @@ } } -octave_dlopen_shlib::~octave_dlopen_shlib (void) +octave_dlopen_shlib::~octave_dlopen_shlib () { if (m_library) dlclose (m_library); @@ -290,7 +290,7 @@ octave_w32_shlib& operator = (const octave_w32_shlib&) = delete; - ~octave_w32_shlib (void); + ~octave_w32_shlib (); void * search (const std::string& name, const dynamic_library::name_mangler& mangler @@ -298,7 +298,7 @@ void * global_search (const std::string& sym_name); - bool is_open (void) const + bool is_open () const { return (m_search_all_loaded || m_handle != nullptr); } @@ -354,7 +354,7 @@ } } -octave_w32_shlib::~octave_w32_shlib (void) +octave_w32_shlib::~octave_w32_shlib () { if (m_handle) FreeLibrary (m_handle); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-shlib.h --- a/liboctave/util/oct-shlib.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-shlib.h Mon Jan 30 18:36:03 2023 +0100 @@ -49,7 +49,7 @@ { public: - dynlib_rep (void) + dynlib_rep () : m_count (1), m_fcn_names (), m_file (), m_time_loaded (OCTAVE_TIME_T ()), m_search_all_loaded (false) { } @@ -61,40 +61,40 @@ public: - virtual ~dynlib_rep (void) + virtual ~dynlib_rep () { s_instances.erase (m_file); } - virtual bool is_open (void) const + virtual bool is_open () const { return false; } virtual void * search (const std::string&, const name_mangler& = name_mangler ()) { return nullptr; } - OCTAVE_API bool is_out_of_date (void) const; + OCTAVE_API bool is_out_of_date () const; // This method will be overridden conditionally. static OCTAVE_API dynlib_rep * new_instance (const std::string& f); static OCTAVE_API dynlib_rep * get_instance (const std::string& f, bool fake); - sys::time time_loaded (void) const + sys::time time_loaded () const { return m_time_loaded; } - std::string file_name (void) const + std::string file_name () const { return m_file; } - std::size_t num_fcn_names (void) const { return m_fcn_names.size (); } + std::size_t num_fcn_names () const { return m_fcn_names.size (); } - OCTAVE_API std::list function_names (void) const; + OCTAVE_API std::list function_names () const; OCTAVE_API void add_fcn_name (const std::string&); OCTAVE_API bool remove_fcn_name (const std::string&); - void clear_fcn_names (void) { m_fcn_names.clear (); } + void clear_fcn_names () { m_fcn_names.clear (); } public: @@ -102,7 +102,7 @@ protected: - OCTAVE_API void fake_reload (void); + OCTAVE_API void fake_reload (); static OCTAVE_API std::map s_instances; @@ -122,18 +122,18 @@ public: - dynamic_library (void) : m_rep (&s_nil_rep) { m_rep->m_count++; } + dynamic_library () : m_rep (&s_nil_rep) { m_rep->m_count++; } dynamic_library (const std::string& f, bool fake = true) : m_rep (dynlib_rep::get_instance (f, fake)) { } - ~dynamic_library (void) + ~dynamic_library () { if (--m_rep->m_count == 0 && m_rep != &s_nil_rep) delete m_rep; } - OCTAVE_API void delete_later (void); + OCTAVE_API void delete_later (); dynamic_library (const dynamic_library& sl) : m_rep (sl.m_rep) @@ -163,7 +163,7 @@ void open (const std::string& f) { *this = dynamic_library (f); } - std::list close (void) + std::list close () { std::list removed_fcns = m_rep->function_names (); @@ -190,16 +190,16 @@ bool remove (const std::string& name) { return m_rep->remove_fcn_name (name); } - std::size_t number_of_functions_loaded (void) const + std::size_t number_of_functions_loaded () const { return m_rep->num_fcn_names (); } - bool is_out_of_date (void) const + bool is_out_of_date () const { return m_rep->is_out_of_date (); } - std::string file_name (void) const + std::string file_name () const { return m_rep->file_name (); } - sys::time time_loaded (void) const + sys::time time_loaded () const { return m_rep->time_loaded (); } private: @@ -210,7 +210,7 @@ // FIXME: Currently must return int so that it may be used as an // event_hook function. -OCTAVE_API int release_unreferenced_dynamic_libraries (void); +OCTAVE_API int release_unreferenced_dynamic_libraries (); OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-sort.cc --- a/liboctave/util/oct-sort.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-sort.cc Mon Jan 30 18:36:03 2023 +0100 @@ -119,7 +119,7 @@ #include "oct-locbuf.h" template -octave_sort::octave_sort (void) : +octave_sort::octave_sort () : m_compare (ascending_compare), m_ms (nullptr) { } diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-sort.h --- a/liboctave/util/oct-sort.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-sort.h Mon Jan 30 18:36:03 2023 +0100 @@ -106,7 +106,7 @@ typedef std::function::type, typename ref_param::type)> compare_fcn_type; - octave_sort (void); + octave_sort (); octave_sort (const compare_fcn_type&); @@ -116,7 +116,7 @@ octave_sort& operator = (const octave_sort&) = delete; - ~octave_sort (void); + ~octave_sort (); void set_compare (const compare_fcn_type& comp) { m_compare = comp; } @@ -199,7 +199,7 @@ { public: - MergeState (void) + MergeState () : m_min_gallop (), m_a (nullptr), m_ia (nullptr), m_alloced (0), m_n (0) { reset (); } @@ -209,10 +209,10 @@ MergeState& operator = (const MergeState&) = delete; - ~MergeState (void) + ~MergeState () { delete [] m_a; delete [] m_ia; } - void reset (void) + void reset () { m_min_gallop = MIN_GALLOP; m_n = 0; } void getmem (octave_idx_type need); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/oct-sparse.cc --- a/liboctave/util/oct-sparse.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/oct-sparse.cc Mon Jan 30 18:36:03 2023 +0100 @@ -37,7 +37,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) static inline void -check_suitesparse_integer_size (void) +check_suitesparse_integer_size () { // FIXME: maybe it would be better to make this a configure check and // disable suitesparse if it fails? diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/octave-preserve-stream-state.h --- a/liboctave/util/octave-preserve-stream-state.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/octave-preserve-stream-state.h Mon Jan 30 18:36:03 2023 +0100 @@ -42,7 +42,7 @@ m_owidth (s.width ()), m_ofill (s.fill ()) { } - ~preserve_stream_state (void) + ~preserve_stream_state () { m_stream.flags (m_oflags); m_stream.precision (m_oprecision); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/pathsearch.cc --- a/liboctave/util/pathsearch.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/pathsearch.cc Mon Jan 30 18:36:03 2023 +0100 @@ -47,12 +47,12 @@ init (); } -std::list directory_path::elements (void) +std::list directory_path::elements () { return m_initialized ? m_path_elements : std::list (); } -std::list directory_path::all_directories (void) +std::list directory_path::all_directories () { std::list retval; @@ -97,7 +97,7 @@ : std::list ()); } -void directory_path::init (void) +void directory_path::init () { static bool octave_kpse_initialized = false; @@ -119,12 +119,12 @@ m_initialized = true; } -char directory_path::path_sep_char (void) +char directory_path::path_sep_char () { return SEPCHAR; } -std::string directory_path::path_sep_str (void) +std::string directory_path::path_sep_str () { return SEPCHAR_STR; } diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/pathsearch.h --- a/liboctave/util/pathsearch.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/pathsearch.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,7 +45,7 @@ directory_path& operator = (const directory_path&) = default; - ~directory_path (void) = default; + ~directory_path () = default; void set (const std::string& s) { @@ -54,9 +54,9 @@ init (); } - std::list elements (void); + std::list elements (); - std::list all_directories (void); + std::list all_directories (); std::string find_first (const std::string&); @@ -69,17 +69,17 @@ std::list find_all_first_of (const std::list& names); - void rehash (void) + void rehash () { m_initialized = false; init (); } - static char path_sep_char (void); + static char path_sep_char (); // static void path_sep_char (char c); - static std::string path_sep_str (void); + static std::string path_sep_str (); static bool is_path_sep (char c) { return c == path_sep_char (); } @@ -98,7 +98,7 @@ // The elements of the list. std::list m_path_elements; - void init (void); + void init (); }; OCTAVE_END_NAMESPACE(octave) diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/quit.cc --- a/liboctave/util/quit.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/quit.cc Mon Jan 30 18:36:03 2023 +0100 @@ -39,12 +39,12 @@ volatile sig_atomic_t octave_signal_caught = 0; -void (*octave_signal_hook) (void) = nullptr; -void (*octave_interrupt_hook) (void) = nullptr; +void (*octave_signal_hook) () = nullptr; +void (*octave_interrupt_hook) () = nullptr; OCTAVE_BEGIN_NAMESPACE(octave) -std::string execution_exception::stack_trace (void) const +std::string execution_exception::stack_trace () const { std::size_t nframes = m_stack_info.size (); @@ -98,7 +98,7 @@ OCTAVE_END_NAMESPACE(octave) void -octave_handle_signal (void) +octave_handle_signal () { if (octave_signal_hook) octave_signal_hook (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/singleton-cleanup.cc --- a/liboctave/util/singleton-cleanup.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/singleton-cleanup.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,7 @@ singleton_cleanup_list *singleton_cleanup_list::s_instance = nullptr; -singleton_cleanup_list::~singleton_cleanup_list (void) +singleton_cleanup_list::~singleton_cleanup_list () { for (fptr fcn : m_fcn_list) { @@ -41,7 +41,7 @@ } bool -singleton_cleanup_list::instance_ok (void) +singleton_cleanup_list::instance_ok () { bool retval = true; diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/singleton-cleanup.h --- a/liboctave/util/singleton-cleanup.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/singleton-cleanup.h Mon Jan 30 18:36:03 2023 +0100 @@ -36,11 +36,11 @@ { protected: - singleton_cleanup_list (void) : m_fcn_list () { } + singleton_cleanup_list () : m_fcn_list () { } public: - typedef void (*fptr) (void); + typedef void (*fptr) (); // No copying! @@ -48,7 +48,7 @@ singleton_cleanup_list& operator = (const singleton_cleanup_list&) = delete; - ~singleton_cleanup_list (void); + ~singleton_cleanup_list (); static void add (fptr f) { @@ -56,7 +56,7 @@ s_instance->do_add (f); } - static void cleanup (void) + static void cleanup () { delete s_instance; s_instance = nullptr; @@ -66,9 +66,9 @@ static singleton_cleanup_list *s_instance; - static bool instance_ok (void); + static bool instance_ok (); - static void cleanup_instance (void) + static void cleanup_instance () { delete s_instance; s_instance = nullptr; diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/str-vec.cc --- a/liboctave/util/str-vec.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/str-vec.cc Mon Jan 30 18:36:03 2023 +0100 @@ -86,7 +86,7 @@ return *this; } string_vector& -string_vector::uniq (void) +string_vector::uniq () { octave_idx_type len = numel (); @@ -154,7 +154,7 @@ } char ** -string_vector::c_str_vec (void) const +string_vector::c_str_vec () const { octave_idx_type len = numel (); @@ -169,7 +169,7 @@ } std::list -string_vector::std_list (void) const +string_vector::std_list () const { octave_idx_type len = numel (); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/str-vec.h --- a/liboctave/util/str-vec.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/str-vec.h Mon Jan 30 18:36:03 2023 +0100 @@ -40,7 +40,7 @@ { public: - string_vector (void) = default; + string_vector () = default; explicit string_vector (octave_idx_type n) : m_data (dim_vector (n, 1)) { } @@ -72,11 +72,11 @@ string_vector& operator = (string_vector&&) = default; - ~string_vector (void) = default; + ~string_vector () = default; - bool empty (void) const { return numel () == 0; } + bool empty () const { return numel () == 0; } - octave_idx_type max_length (void) const + octave_idx_type max_length () const { octave_idx_type n = numel (); octave_idx_type longest = 0; @@ -97,9 +97,9 @@ m_data.resize (dim_vector (n, 1), rfv); } - octave_idx_type numel (void) const { return m_data.numel (); } + octave_idx_type numel () const { return m_data.numel (); } - bool isempty (void) const { return m_data.isempty (); } + bool isempty () const { return m_data.isempty (); } std::string& elem (octave_idx_type i) { return m_data.elem (i); } @@ -119,7 +119,7 @@ string_vector& sort (bool make_uniq = false); - string_vector& uniq (void); + string_vector& uniq (); string_vector& append (const std::string& s); @@ -127,9 +127,9 @@ std::string join (const std::string& sep = "") const; - char ** c_str_vec (void) const; + char ** c_str_vec () const; - std::list std_list (void) const; + std::list std_list () const; static void delete_c_str_vec (const char * const*); diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/unwind-prot.cc --- a/liboctave/util/unwind-prot.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/unwind-prot.cc Mon Jan 30 18:36:03 2023 +0100 @@ -33,7 +33,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) void -unwind_protect_safe::warn_unhandled_exception (void) const +unwind_protect_safe::warn_unhandled_exception () const { (*current_liboctave_warning_handler) ("unhandled exception in unwind_protect_safe handler. " @@ -42,7 +42,7 @@ } void -unwind_action_safe::warn_unhandled_exception (void) const +unwind_action_safe::warn_unhandled_exception () const { (*current_liboctave_warning_handler) ("unhandled exception in unwind_action_safe handler. " diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/unwind-prot.h --- a/liboctave/util/unwind-prot.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/unwind-prot.h Mon Jan 30 18:36:03 2023 +0100 @@ -43,7 +43,7 @@ { public: - unwind_protect (void) : m_lifo () { } + unwind_protect () : m_lifo () { } // No copying! @@ -55,11 +55,11 @@ // registered should be exception-safe. If you're not sure, see // unwind_protect_safe. - ~unwind_protect (void) { run (); } + ~unwind_protect () { run (); } - operator bool (void) const { return ! empty (); } + operator bool () const { return ! empty (); } - void run_first (void) + void run_first () { if (! empty ()) { @@ -70,7 +70,7 @@ } } - void discard_first (void) + void discard_first () { if (! empty ()) { @@ -80,7 +80,7 @@ } } - std::size_t size (void) const { return m_lifo.size (); } + std::size_t size () const { return m_lifo.size (); } protected: @@ -102,11 +102,11 @@ { private: - void warn_unhandled_exception (void) const; + void warn_unhandled_exception () const; public: - unwind_protect_safe (void) : unwind_protect () { } + unwind_protect_safe () : unwind_protect () { } // No copying! @@ -114,7 +114,7 @@ unwind_protect_safe& operator = (const unwind_protect_safe&) = delete; - ~unwind_protect_safe (void) + ~unwind_protect_safe () { while (! empty ()) { @@ -150,7 +150,7 @@ // // flexibility in calling forms (function pointer or lambda): // // unwind_action act1 (fcn, val); -// unwind_action act2 ([val] (void) { fcn (val); }); +// unwind_action act2 ([val] () { fcn (val); }); // } // // NOTE: Don't forget to provide a name for the unwind_action @@ -166,7 +166,7 @@ { public: - unwind_action (void) : m_fcn () { } + unwind_action () : m_fcn () { } // FIXME: Do we need to apply std::forward to the arguments to // std::bind here? @@ -182,7 +182,7 @@ unwind_action& operator = (const unwind_action&) = delete; - ~unwind_action (void) { run (); } + ~unwind_action () { run (); } // FIXME: Do we need to apply std::forward to the arguments to // std::bind here? @@ -193,12 +193,12 @@ m_fcn = std::bind (fcn, args...); } - void set (void) { m_fcn = nullptr; } + void set () { m_fcn = nullptr; } // Alias for set() which is clearer about programmer intention. - void discard (void) { set (); } + void discard () { set (); } - void run (void) + void run () { if (m_fcn) m_fcn (); @@ -209,7 +209,7 @@ private: - std::function m_fcn; + std::function m_fcn; }; // Like unwind_action, but this one will guard against the possibility @@ -220,11 +220,11 @@ { private: - void warn_unhandled_exception (void) const; + void warn_unhandled_exception () const; public: - unwind_action_safe (void) : m_fcn () { } + unwind_action_safe () : m_fcn () { } // FIXME: Do we need to apply std::forward to the arguments to // std::bind here? @@ -240,7 +240,7 @@ unwind_action_safe& operator = (const unwind_action_safe&) = delete; - ~unwind_action_safe (void) { run (); } + ~unwind_action_safe () { run (); } // FIXME: Do we need to apply std::forward to the arguments to // std::bind here? @@ -251,12 +251,12 @@ m_fcn = std::bind (fcn, args...); } - void set (void) { m_fcn = nullptr; } + void set () { m_fcn = nullptr; } // Alias for set() which is clearer about programmer intention. - void discard (void) { set (); } + void discard () { set (); } - void run (void) + void run () { try { @@ -274,7 +274,7 @@ private: - std::function m_fcn; + std::function m_fcn; }; // Reset a variable value at the end of the current scope when @@ -339,7 +339,7 @@ unwind_protect_var& operator = (const unwind_protect_var&) = delete; - ~unwind_protect_var (void) + ~unwind_protect_var () { m_ref = m_val; } diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/url-transfer.cc --- a/liboctave/util/url-transfer.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/url-transfer.cc Mon Jan 30 18:36:03 2023 +0100 @@ -48,7 +48,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -base_url_transfer::base_url_transfer (void) +base_url_transfer::base_url_transfer () : m_host_or_url (), m_valid (false), m_ftp (false), m_ascii_mode (false), m_ok (true), m_errmsg (), m_curr_istream (&std::cin), m_curr_ostream (&std::cout) @@ -289,7 +289,7 @@ { public: - curl_transfer (void) + curl_transfer () : base_url_transfer (), m_curl (curl_easy_init ()), m_errnum (), m_url (), m_userpwd () { @@ -358,13 +358,13 @@ curl_transfer& operator = (const curl_transfer&) = delete; - ~curl_transfer (void) + ~curl_transfer () { if (m_curl) curl_easy_cleanup (m_curl); } - void perform (void) + void perform () { m_errnum = curl_easy_perform (m_curl); @@ -375,7 +375,7 @@ } } - std::string lasterror (void) const + std::string lasterror () const { return std::string (curl_easy_strerror (m_errnum)); } @@ -396,13 +396,13 @@ return retval; } - void ascii (void) + void ascii () { m_ascii_mode = true; SETOPT (CURLOPT_TRANSFERTEXT, 1); } - void binary (void) + void binary () { m_ascii_mode = false; SETOPT (CURLOPT_TRANSFERTEXT, 0); @@ -483,7 +483,7 @@ SETOPT (CURLOPT_URL, m_url.c_str ()); } - void dir (void) + void dir () { m_url = "ftp://" + m_host_or_url + '/'; SETOPT (CURLOPT_URL, m_url.c_str ()); @@ -498,7 +498,7 @@ SETOPT (CURLOPT_URL, m_url.c_str ()); } - string_vector list (void) + string_vector list () { string_vector retval; @@ -577,7 +577,7 @@ curl_easy_getinfo (m_curl, CURLINFO_FILETIME, &ft); filetime = ft; double fs; - curl_easy_getinfo (m_curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fs); + curl_easy_getinfo (m_curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &fs); filesize = fs; SETOPT (CURLOPT_WRITEFUNCTION, write_data); @@ -593,7 +593,7 @@ cwd ('/' + path); } - std::string pwd (void) + std::string pwd () { std::string retval; @@ -712,12 +712,12 @@ // path of the file as its value. void form_data_post (const Array& param) { - struct curl_httppost *post = nullptr; - struct curl_httppost *last = nullptr; + curl_mime *mime = nullptr; + curl_mimepart *part = nullptr; SETOPT (CURLOPT_URL, m_host_or_url.c_str ()); - unwind_action cleanup_httppost ([=] () { curl_formfree (post); }); + unwind_action cleanup_mime ([=] () { curl_mime_free (mime); }); if (param.numel () >= 2) { @@ -726,15 +726,15 @@ std::string name = param(i); std::string data = param(i+1); + part = curl_mime_addpart (mime); + curl_mime_name (part, name.c_str ()); if (name == "file") - curl_formadd (&post, &last, CURLFORM_COPYNAME, name.c_str (), - CURLFORM_FILE, data.c_str (), CURLFORM_END); + curl_mime_filedata (part, data.c_str ()); else - curl_formadd(&post, &last, CURLFORM_COPYNAME, name.c_str (), - CURLFORM_COPYCONTENTS, data.c_str (), CURLFORM_END); + curl_mime_data (part, data.c_str (), CURL_ZERO_TERMINATED); } - SETOPT (CURLOPT_HTTPPOST, post); + SETOPT (CURLOPT_MIMEPOST, mime); } perform (); @@ -918,7 +918,7 @@ # define REP_CLASS base_url_transfer #endif -url_transfer::url_transfer (void) : m_rep (new REP_CLASS ()) +url_transfer::url_transfer () : m_rep (new REP_CLASS ()) { } url_transfer::url_transfer (const std::string& host, const std::string& user, diff -r 17d568574e1c -r 7860fcc69082 liboctave/util/url-transfer.h --- a/liboctave/util/url-transfer.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/util/url-transfer.h Mon Jan 30 18:36:03 2023 +0100 @@ -59,7 +59,7 @@ friend class url_transfer; - base_url_transfer (void); + base_url_transfer (); base_url_transfer (const std::string& host, const std::string& /* user_arg */, @@ -74,15 +74,15 @@ base_url_transfer& operator = (const base_url_transfer&) = delete; - virtual ~base_url_transfer (void) = default; + virtual ~base_url_transfer () = default; - bool is_valid (void) const { return m_valid; } + bool is_valid () const { return m_valid; } - bool good (void) const { return m_valid && m_ok; } + bool good () const { return m_valid && m_ok; } - virtual void perform (void) { } + virtual void perform () { } - virtual std::string lasterror (void) const { return m_errmsg; } + virtual std::string lasterror () const { return m_errmsg; } virtual std::ostream& set_ostream (std::ostream& /* os */) { @@ -94,13 +94,13 @@ return *m_curr_istream; } - virtual void ascii (void) { } + virtual void ascii () { } - virtual void binary (void) { } + virtual void binary () { } - bool is_ascii (void) const { return m_ascii_mode; } + bool is_ascii () const { return m_ascii_mode; } - bool is_binary (void) const { return ! m_ascii_mode; } + bool is_binary () const { return ! m_ascii_mode; } virtual void cwd (const std::string& /* path */) { } @@ -125,16 +125,16 @@ string_vector mput_directory (const std::string& base, const std::string& directory); - virtual void dir (void) { } + virtual void dir () { } - virtual string_vector list (void) { return string_vector (); } + virtual string_vector list () { return string_vector (); } virtual void get_fileinfo (const std::string& /* filename */, double& /* filesize */, OCTAVE_TIME_T& /* filetime */, bool& /* fileisdir */) { } - virtual std::string pwd (void) { return ""; } + virtual std::string pwd () { return ""; } virtual void http_get (const Array& /* param */) { } @@ -170,7 +170,7 @@ { public: - url_transfer (void); + url_transfer (); url_transfer (const std::string& host, const std::string& user, const std::string& passwd, std::ostream& os); @@ -181,13 +181,13 @@ url_transfer& operator = (const url_transfer&) = default; - ~url_transfer (void) = default; + ~url_transfer () = default; - bool is_valid (void) const { return m_rep->is_valid (); } + bool is_valid () const { return m_rep->is_valid (); } - bool good (void) const { return m_rep->good (); } + bool good () const { return m_rep->good (); } - std::string lasterror (void) const { return m_rep->lasterror (); } + std::string lasterror () const { return m_rep->lasterror (); } std::ostream& set_ostream (std::ostream& os) { @@ -199,13 +199,13 @@ return m_rep->set_istream (is); } - void ascii (void) { m_rep->ascii (); } + void ascii () { m_rep->ascii (); } - void binary (void) { m_rep->binary (); } + void binary () { m_rep->binary (); } - bool is_ascii (void) const { return m_rep->is_ascii (); } + bool is_ascii () const { return m_rep->is_ascii (); } - bool is_binary (void) const { return m_rep->is_binary (); } + bool is_binary () const { return m_rep->is_binary (); } void cwd (const std::string& path) { m_rep->cwd (path); } @@ -242,9 +242,9 @@ return m_rep->mput_directory (base, directory); } - void dir (void) { m_rep->dir (); } + void dir () { m_rep->dir (); } - string_vector list (void) { return m_rep->list (); } + string_vector list () { return m_rep->list (); } void get_fileinfo (const std::string& filename, double& filesize, OCTAVE_TIME_T& filetime, bool& fileisdir) @@ -252,7 +252,7 @@ m_rep->get_fileinfo (filename, filesize, filetime, fileisdir); } - std::string pwd (void) { return m_rep->pwd (); } + std::string pwd () { return m_rep->pwd (); } void http_get (const Array& param) { diff -r 17d568574e1c -r 7860fcc69082 liboctave/version.cc --- a/liboctave/version.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/version.cc Mon Jan 30 18:36:03 2023 +0100 @@ -68,7 +68,7 @@ } std::string -octave_name_version_and_copyright (void) +octave_name_version_and_copyright () { // The GNU coding standards say that on the first line printed by // --version, the version number should follow the last space on the diff -r 17d568574e1c -r 7860fcc69082 liboctave/version.in.h --- a/liboctave/version.in.h Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/version.in.h Mon Jan 30 18:36:03 2023 +0100 @@ -62,7 +62,7 @@ extern OCTAVE_API std::string octave_bugs_statement (bool html = false); -extern OCTAVE_API std::string octave_name_version_and_copyright (void); +extern OCTAVE_API std::string octave_name_version_and_copyright (); extern OCTAVE_API std::string octave_name_version_copyright_copying_and_warranty diff -r 17d568574e1c -r 7860fcc69082 liboctave/wrappers/cxx-signal-helpers.cc --- a/liboctave/wrappers/cxx-signal-helpers.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/liboctave/wrappers/cxx-signal-helpers.cc Mon Jan 30 18:36:03 2023 +0100 @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2016-2022 The Octave Project Developers +// Copyright (C) 2016-2023 The Octave Project Developers // // See the file COPYRIGHT.md in the top-level directory of this // distribution or . @@ -45,7 +45,7 @@ // The following pattern often used in C code to initialize a static // variable could possibly cause trouble in multi-threaded code: // -// TYPE * get_var (void) { +// TYPE * get_var () { // static bool initialized = false; // static TYPE *var; // if (! initialized) { @@ -57,14 +57,14 @@ // // Changing this code to // -// static TYPE *var = init_var (void); +// static TYPE *var = init_var (); // // doesn't work in C because the static variable can't be initialized by // a function call. So we have to do this job in C++. To avoid calling // new, initialize sigset_t rather than a pointer to allocated storage. static const sigset_t -init_async_signals (void) +init_async_signals () { sigset_t sigmask; @@ -148,7 +148,7 @@ #endif void -octave_block_async_signals (void) +octave_block_async_signals () { #if ! defined (__WIN32__) || defined (__CYGWIN__) pthread_sigmask (SIG_BLOCK, &async_signals, 0); @@ -156,7 +156,7 @@ } void -octave_unblock_async_signals (void) +octave_unblock_async_signals () { #if ! defined (__WIN32__) || defined (__CYGWIN__) pthread_sigmask (SIG_UNBLOCK, &async_signals, 0); diff -r 17d568574e1c -r 7860fcc69082 liboctave/wrappers/signal-wrappers.c diff -r 17d568574e1c -r 7860fcc69082 liboctave/wrappers/signal-wrappers.h diff -r 17d568574e1c -r 7860fcc69082 m4/acinclude.m4 --- a/m4/acinclude.m4 Mon Jan 30 18:30:33 2023 +0100 +++ b/m4/acinclude.m4 Mon Jan 30 18:36:03 2023 +0100 @@ -167,93 +167,6 @@ fi ]) dnl -dnl Check for broken stl_algo.h header file in gcc versions 4.8.0, 4.8.1, 4.8.2 -dnl which leads to failures in nth_element. -dnl -AC_DEFUN([OCTAVE_CHECK_BROKEN_STL_ALGO_H], [ - AC_CACHE_CHECK([whether stl_algo.h is broken], - [octave_cv_broken_stl_algo_h], - [AC_LANG_PUSH(C++) - AC_RUN_IFELSE([AC_LANG_PROGRAM([[ -// Based on code from a GCC test program. - -// Copyright (C) 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. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -// 25.3.2 [lib.alg.nth.element] - -// { dg-options "-std=gnu++11" } - -#include -#include - ]], [[ -std::vector v (7); - -v[0] = 207089; -v[1] = 202585; -v[2] = 180067; -v[3] = 157549; -v[4] = 211592; -v[5] = 216096; -v[6] = 207089; - -std::nth_element (v.begin (), v.begin () + 3, v.end ()); - -return v[3] == 207089 ? 0 : 1; - ]])], - octave_cv_broken_stl_algo_h=no, - octave_cv_broken_stl_algo_h=yes, - [case "$GXX_VERSION" in - *4.8.2*) - octave_cv_broken_stl_algo_h=yes - ;; - *) - octave_cv_broken_stl_algo_h=no - ;; - esac - ]) - AC_LANG_POP(C++) - ]) - if test "$GXX" = yes; then - if test $octave_cv_broken_stl_algo_h = yes; then - case "$GXX_VERSION" in - 4.8.[[012]]) - ;; - *) - octave_cv_broken_stl_algo_h=no - warn_stl_algo_h="UNEXPECTED: found nth_element broken in g++ $GXX_VERSION. Refusing to fix except for g++ 4.8.0, 4.8.1, or 4.8.2. You appear to have g++ $GXX_VERSION." - OCTAVE_CONFIGURE_WARNING([warn_stl_algo_h]) - ;; - esac - else - case "$GXX_VERSION" in - 4.8.2) - warn_stl_algo_h="UNEXPECTED: found nth_element working in g++ 4.8.2. Has it been patched on your system?" - OCTAVE_CONFIGURE_WARNING([warn_stl_algo_h]) - ;; - esac - fi - else - octave_cv_broken_stl_algo_h=no - warn_stl_algo_h="UNEXPECTED: nth_element test failed. Refusing to fix except for g++ 4.8.2." - OCTAVE_CONFIGURE_WARNING([warn_stl_algo_h]) - fi -]) -dnl dnl Check whether std::pmr::polymorphic_allocator is available. dnl AC_DEFUN([OCTAVE_CHECK_STD_PMR_POLYMORPHIC_ALLOCATOR], [ @@ -491,6 +404,8 @@ dnl Check whether the Qt class QList has a constructor that accepts dnl a pair of iterators. This constructor was introduced in Qt 5.14. dnl +dnl FIXME: Delete this entirely when we drop support for Qt 5.13 or older. +dnl AC_DEFUN([OCTAVE_CHECK_FUNC_QFONTMETRICS_HORIZONTAL_ADVANCE], [ AC_CACHE_CHECK([for QFontMetrics::horizontalAdvance function], [octave_cv_func_qfontmetrics_horizontal_advance], @@ -521,39 +436,11 @@ fi ]) dnl -dnl Check whether the Qt QGuiApplication class has the setDesktopFileName -dnl static member function. This function was introduced in Qt 5.7. -dnl -dnl FIXME: Delete this entirely when we drop support for Qt 5.6 or older. -dnl -AC_DEFUN([OCTAVE_CHECK_FUNC_QGUIAPPLICATION_SETDESKTOPFILENAME], [ - AC_CACHE_CHECK([for QGuiApplication::setDesktopFileName], - [octave_cv_func_qguiapplication_setdesktopfilename], - [AC_LANG_PUSH(C++) - ac_octave_save_CPPFLAGS="$CPPFLAGS" - ac_octave_save_CXXFLAGS="$CXXFLAGS" - CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS" - CXXFLAGS="$CXXPICFLAG $CXXFLAGS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[ - QGuiApplication::setDesktopFileName ("com.example.Example.desktop"); - ]])], - octave_cv_func_qguiapplication_setdesktopfilename=yes, - octave_cv_func_qguiapplication_setdesktopfilename=no) - CPPFLAGS="$ac_octave_save_CPPFLAGS" - CXXFLAGS="$ac_octave_save_CXXFLAGS" - AC_LANG_POP(C++) - ]) - if test $octave_cv_func_qguiapplication_setdesktopfilename = yes; then - AC_DEFINE(HAVE_QGUIAPPLICATION_SETDESKTOPFILENAME, 1, - [Define to 1 if you have the `QGuiApplication::setDesktopFileName' member function.]) - fi -]) -dnl dnl Check whether the Qt class QHelpEngine has the documentsForIdentifier dnl function. dnl This member function was introduced in Qt 5.15. dnl +dnl FIXME: Delete this entirely when we drop support for Qt 5.14 or older. +dnl AC_DEFUN([OCTAVE_CHECK_FUNC_QHELPENGINE_DOCUMENTSFORIDENTIFIER], [ AC_CACHE_CHECK([for QHelpEngine::documentsForIdentifier in ], [octave_cv_func_qhelpengine_documentsforidentifier], @@ -621,6 +508,8 @@ dnl Check whether the Qt class QList has a constructor that accepts dnl a pair of iterators. This constructor was introduced in Qt 5.14. dnl +dnl FIXME: Delete this entirely when we drop support for Qt 5.13 or older. +dnl AC_DEFUN([OCTAVE_CHECK_FUNC_QLIST_ITERATOR_CONSTRUCTOR], [ AC_CACHE_CHECK([for QList::QList (iterator, iterator) constructor], [octave_cv_func_qlist_iterator_constructor], @@ -647,136 +536,11 @@ fi ]) dnl -dnl Check whether the Qt class QMainWindow has the resizeDocks member function. -dnl This member function was introduced in Qt 5.6. -dnl -dnl FIXME: remove this test when we drop support for Qt older than 5.6 -dnl -AC_DEFUN([OCTAVE_CHECK_FUNC_QMAINWINDOW_RESIZEDOCKS], [ - AC_CACHE_CHECK([for QMainWindow::resizeDocks in ], - [octave_cv_func_mainwindow_resizedocks], - [AC_LANG_PUSH(C++) - ac_octave_save_CPPFLAGS="$CPPFLAGS" - ac_octave_save_CXXFLAGS="$CXXFLAGS" - CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS" - CXXFLAGS="$CXXPICFLAG $CXXFLAGS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include - #include - ]], [[ - QMainWindow *mw = new QMainWindow (); - QDockWidget *dw = new QDockWidget (mw); - mw->addDockWidget (Qt::LeftDockWidgetArea, dw); - mw->resizeDocks ({dw},{20},Qt::Horizontal); - ]])], - octave_cv_func_mainwindow_resizedocks=yes, - octave_cv_func_mainwindow_resizedocks=no) - CPPFLAGS="$ac_octave_save_CPPFLAGS" - CXXFLAGS="$ac_octave_save_CXXFLAGS" - AC_LANG_POP(C++) - ]) - if test $octave_cv_func_mainwindow_resizedocks = yes; then - AC_DEFINE(HAVE_QMAINWINDOW_RESIZEDOCKS, 1, - [Define to 1 if you have the 'QMainWindow::resizeDocks' member function.]) - fi -]) -dnl -dnl Check whether the Qt class QPrinter has the setPageSize member function. -dnl This member function was introduced in Qt 5.3. -dnl -dnl FIXME: remove this test when we drop support for Qt older than 5.3. -dnl -AC_DEFUN([OCTAVE_CHECK_FUNC_QPRINTER_SETPAGESIZE], [ - AC_CACHE_CHECK([for QPrinter::setPageSize in ], - [octave_cv_func_qprinter_setpagesize], - [AC_LANG_PUSH(C++) - ac_octave_save_CPPFLAGS="$CPPFLAGS" - ac_octave_save_CXXFLAGS="$CXXFLAGS" - CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS" - CXXFLAGS="$CXXPICFLAG $CXXFLAGS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[ - QPrinter printer; - printer.setPageSize (QPageSize (QSizeF (8.5, 11.0), QPageSize::Inch)); - ]])], - octave_cv_func_qprinter_setpagesize=yes, - octave_cv_func_qprinter_setpagesize=no) - CPPFLAGS="$ac_octave_save_CPPFLAGS" - CXXFLAGS="$ac_octave_save_CXXFLAGS" - AC_LANG_POP(C++) - ]) - if test $octave_cv_func_qprinter_setpagesize = yes; then - AC_DEFINE(HAVE_QPRINTER_SETPAGESIZE, 1, - [Define to 1 if you have the 'QPrinter::setPageSize' member function.]) - fi -]) -dnl -dnl Check whether the Qt class QScreen has the devicePixelRatio member function. -dnl This member function was introduced in Qt 5.5. -dnl -AC_DEFUN([OCTAVE_CHECK_FUNC_QSCREEN_DEVICEPIXELRATIO], [ - AC_CACHE_CHECK([for QScreen::devicePixelRatio in ], - [octave_cv_func_qscreen_devicepixelratio], - [AC_LANG_PUSH(C++) - ac_octave_save_CPPFLAGS="$CPPFLAGS" - ac_octave_save_CXXFLAGS="$CXXFLAGS" - CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS" - CXXFLAGS="$CXXPICFLAG $CXXFLAGS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include - #include - ]], [[ - QScreen *screen = QApplication::primaryScreen (); - qreal ratio = screen->devicePixelRatio (); - ]])], - octave_cv_func_qscreen_devicepixelratio=yes, - octave_cv_func_qscreen_devicepixelratio=no) - CPPFLAGS="$ac_octave_save_CPPFLAGS" - CXXFLAGS="$ac_octave_save_CXXFLAGS" - AC_LANG_POP(C++) - ]) - if test $octave_cv_func_qscreen_devicepixelratio = yes; then - AC_DEFINE(HAVE_QSCREEN_DEVICEPIXELRATIO, 1, - [Define to 1 if you have the `QScreen::devicePixelRatio' member function.]) - fi -]) -dnl -dnl Check whether the Qt class QWheelEvent has the angleDelta member function. -dnl This member function was introduced in Qt 5. -dnl -dnl FIXME: Delete this entirely when we drop support for Qt 4. -dnl -AC_DEFUN([OCTAVE_CHECK_FUNC_QWHEELEVENT_ANGLEDELTA], [ - AC_CACHE_CHECK([for QWheelEvent::angleDelta in ], - [octave_cv_func_qwheelevent_angledelta], - [AC_LANG_PUSH(C++) - ac_octave_save_CPPFLAGS="$CPPFLAGS" - ac_octave_save_CXXFLAGS="$CXXFLAGS" - CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS" - CXXFLAGS="$CXXPICFLAG $CXXFLAGS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include - void foo (const QWheelEvent& ev) - { - ev.angleDelta (); - }; - ]])], - octave_cv_func_qwheelevent_angledelta=yes, - octave_cv_func_qwheelevent_angledelta=no) - CPPFLAGS="$ac_octave_save_CPPFLAGS" - CXXFLAGS="$ac_octave_save_CXXFLAGS" - AC_LANG_POP(C++) - ]) - if test $octave_cv_func_qwheelevent_angledelta = yes; then - AC_DEFINE(HAVE_QWHEELEVENT_ANGLEDELTA, 1, - [Define to 1 if you have the `QWheelEvent::angleDelta' member function.]) - fi -]) -dnl dnl Check whether the Qt class QWheelEvent has the position member function. dnl This member function was introduced in Qt 5.14. dnl +dnl FIXME: Delete this entirely when we drop support for Qt 5.13 or older. +dnl AC_DEFUN([OCTAVE_CHECK_FUNC_QWHEELEVENT_POSITION], [ AC_CACHE_CHECK([for QWheelEvent::position in ], [octave_cv_func_qwheelevent_position], @@ -805,7 +569,10 @@ ]) dnl dnl Check whether the Qt method QPainter::setRenderHint accepts the -dnl QPainter::LosslessImageRendering flag. This flag was introduced in Qt 5.13. +dnl QPainter::LosslessImageRendering flag. This flag was introduced in +dnl Qt 5.13. +dnl +dnl FIXME: Delete this entirely when we drop support for Qt 5.12 or older. dnl AC_DEFUN([OCTAVE_CHECK_FUNC_QPAINTER_SETRENDERHINT_LOSSLESS], [ AC_CACHE_CHECK([for QPainter::LosslessImageRendering flag], @@ -1696,42 +1463,11 @@ fi ]) dnl -dnl Check whether Qt has the QOverload template introduced in Qt 5.7. -dnl -AC_DEFUN([OCTAVE_CHECK_QOVERLOAD_TEMPLATE], [ - AC_CACHE_CHECK([for QOverload template], - [octave_cv_qoverload_template], - [AC_LANG_PUSH(C++) - ac_octave_save_CPPFLAGS="$CPPFLAGS" - ac_octave_save_CXXFLAGS="$CXXFLAGS" - CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS" - CXXFLAGS="$CXXPICFLAG $CXXFLAGS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[ - struct Foo - { - void overloadedFunction (int) const; - void overloadedFunction (int, const QString &) const; - }; - QOverload::of (&Foo::overloadedFunction); - QOverload::of (&Foo::overloadedFunction); - ]])], - octave_cv_qoverload_template=yes, - octave_cv_qoverload_template=no) - CPPFLAGS="$ac_octave_save_CPPFLAGS" - CXXFLAGS="$ac_octave_save_CXXFLAGS" - AC_LANG_POP(C++) - ]) - if test $octave_cv_qoverload_template = yes; then - AC_DEFINE(HAVE_QOVERLOAD_TEMPLATE, 1, - [Define to 1 if you have the `QOverload' template.]) - fi -]) -dnl dnl Check whether the Qt class QRegion has the iterators and related dnl functions introduced in Qt 5.8. dnl +dnl FIXME: Delete this entirely when we drop support for Qt 5.7 or older. +dnl AC_DEFUN([OCTAVE_CHECK_QREGION_ITERATORS], [ AC_CACHE_CHECK([for QRegion iterators and related functions], [octave_cv_qregion_iterators], @@ -1878,7 +1614,6 @@ octave_qt_versions="$1" build_qt_gui=no - build_qt_graphics=no use_qscintilla=no win32_terminal=no @@ -1888,12 +1623,18 @@ have_qt_version=$ver break elif test -n "$QT_MODULES_AVAILABLE"; then - ## If some modules were found for $ver, then warn about possible - ## incomplete or broken Qt installation instead of checking for - ## next version in the list. Don't attempt a similar check for - ## tools here because Qt4 and Qt5 tools may be installed with - ## the same name so determining whether there is a mix of versions - ## will require more work than just looking which tools are installed. + ## We currently only support Qt5, but previously, when it was + ## possible to build Octave with either qt4 or Qt5 and we detected + ## only some modules available for a particular version $ver, then + ## we warned about a possible incomplete or broken Qt installation + ## instead of checking for next version in the list. We did not + ## attempt a similar check for tools here because version-specific + ## Qt tools may be installed with the same name so determining + ## whether there is a mix of versions requires more work than just + ## looking which tools are installed. + ## + ## NOTE: Leave this logic in place because it may be needed again + ## if/when we begin supporting both Qt5 and Qt6 warn_qt_modules="Your installation of Qt version $ver appears incomplete or broken in some way. Fix that or use --with-qt=VER to use another version." break fi @@ -1941,126 +1682,10 @@ fi AM_CONDITIONAL([AMCOND_BUILD_QT_GUI], [test $build_qt_gui = yes]) - AM_CONDITIONAL([AMCOND_BUILD_QT_GRAPHICS], [test $build_qt_graphics = yes]) AM_CONDITIONAL([AMCOND_HAVE_QSCINTILLA], [test $use_qscintilla = yes]) AM_CONDITIONAL([WIN32_TERMINAL], [test $win32_terminal = yes]) ]) dnl -dnl Check whether QOffscreenSurface is present. -dnl -AC_DEFUN([OCTAVE_CHECK_QT_OPENGL_OFFSCREEN_OK], [ - dnl Normally the language and compiler flags would be set and restored - dnl inside of the AC_CACHE_CHECK body. Because we also need to check for - dnl Qt header files associated with the compilation test, set and restore - dnl these values outside of the AC_CACHE_CHECK for this macro only. - AC_LANG_PUSH(C++) - ac_octave_save_CPPFLAGS="$CPPFLAGS" - ac_octave_save_CXXFLAGS="$CXXFLAGS" - CPPFLAGS="$QT_OPENGL_CPPFLAGS $CXXPICFLAG $CPPFLAGS" - CXXFLAGS="$CXXPICFLAG $CXXFLAGS" - AC_CHECK_HEADERS([QOffscreenSurface]) - AC_CACHE_CHECK([whether Qt supports full offscreen OpenGL rendering], - [octave_cv_qt_opengl_os_ok], - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #if HAVE_WINDOWS_H - # include - #endif - #if defined (HAVE_GL_GL_H) - # include - #elif defined (HAVE_OPENGL_GL_H) - # include - #endif - #if defined (HAVE_GL_GLU_H) - # include - #elif defined HAVE_OPENGL_GLU_H || defined HAVE_FRAMEWORK_OPENGL - # include - #endif - #if defined (HAVE_QOPENGLWIDGET) - # include - # include - #endif - #if defined (HAVE_QOFFSCREENSURFACE) - # include - #endif - QOpenGLContext ctx; - QOffscreenSurface surf; - ]])], - octave_cv_qt_opengl_os_ok=yes, - octave_cv_qt_opengl_os_ok=no) - ]) - CPPFLAGS="$ac_octave_save_CPPFLAGS" - CXXFLAGS="$ac_octave_save_CXXFLAGS" - AC_LANG_POP(C++) - if test $octave_cv_qt_opengl_os_ok = yes; then - $1 - : - else - $2 - : - fi -]) -dnl -dnl Check whether Qt works with full OpenGL support -dnl -AC_DEFUN([OCTAVE_CHECK_QT_OPENGL_OK], [ - dnl Normally the language and compiler flags would be set and restored - dnl inside of the AC_CACHE_CHECK body. Because we also need to check for - dnl Qt header files associated with the compilation test, set and restore - dnl these values outside of the AC_CACHE_CHECK for this macro only. - AC_LANG_PUSH(C++) - ac_octave_save_CPPFLAGS="$CPPFLAGS" - ac_octave_save_CXXFLAGS="$CXXFLAGS" - CPPFLAGS="$QT_OPENGL_CPPFLAGS $CXXPICFLAG $CPPFLAGS" - CXXFLAGS="$CXXPICFLAG $CXXFLAGS" - AC_CHECK_HEADERS([QOpenGLWidget QGLWidget QGLFunctions_1_1]) - AC_CACHE_CHECK([whether Qt works with OpenGL and GLU], - [octave_cv_qt_opengl_ok], - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #if HAVE_WINDOWS_H - # include - #endif - #if defined (HAVE_GL_GL_H) - # include - #elif defined (HAVE_OPENGL_GL_H) - # include - #endif - #if defined (HAVE_GL_GLU_H) - # include - #elif defined HAVE_OPENGL_GLU_H || defined HAVE_FRAMEWORK_OPENGL - # include - #endif - #if defined (HAVE_QOPENGLWIDGET) - # include - # define OCTAVE_QT_OPENGL_WIDGET QOpenGLWidget - #elif defined (HAVE_QGLWIDGET) - # include - # define OCTAVE_QT_OPENGL_WIDGET QGLWidget - #endif - class gl_widget : public OCTAVE_QT_OPENGL_WIDGET - { - public: - gl_widget (QWidget *parent = 0) - : OCTAVE_QT_OPENGL_WIDGET (parent) { } - ~gl_widget () {} - }; - ]], [[ - gl_widget widget; - ]])], - octave_cv_qt_opengl_ok=yes, - octave_cv_qt_opengl_ok=no) - ]) - CPPFLAGS="$ac_octave_save_CPPFLAGS" - CXXFLAGS="$ac_octave_save_CXXFLAGS" - AC_LANG_POP(C++) - if test $octave_cv_qt_opengl_ok = yes; then - $1 - : - else - $2 - : - fi -]) -dnl dnl Check whether the Qt::ImCursorRectangle enum value exists. dnl It replaces the Qt::ImMicroFocus enum value that was deprecated dnl in Qt 5.14. @@ -2094,6 +1719,8 @@ dnl Qt::KeepEmptyParts and Qt::SkipEmptyParts members. This enum dnl was introduced or modified in Qt 5.14. dnl +dnl FIXME: Delete this entirely when we drop support for Qt 5.13 or older. +dnl AC_DEFUN([OCTAVE_CHECK_QT_SPLITBEHAVIOR_ENUM], [ AC_CACHE_CHECK([for Qt::SplitBehavior enum], [octave_cv_qt_splitbehavior_enum], @@ -2140,8 +1767,8 @@ fi ]) dnl -dnl Check whether Qt VERSION is present, supports QtOpenGL and -dnl QScintilla, and will work for Octave. +dnl Check whether Qt VERSION is present, supports QScintilla, +dnl and will work for Octave. dnl dnl OCTAVE_CHECK_QT_VERSION(VERSION) dnl @@ -2153,8 +1780,6 @@ qt_version="$1"; build_qt_gui=yes - build_qt_graphics=no - have_qt_opengl_offscreen=no win32_terminal=no warn_qt_libraries="" @@ -2168,8 +1793,7 @@ ## Check for Qt libraries case "$qt_version" in 5) - QT_OPENGL_MODULE="Qt5OpenGL" - QT_MODULES="Qt5Core Qt5Gui Qt5Help Qt5Network Qt5PrintSupport Qt5Xml" + QT_MODULES="Qt5Core Qt5Gui Qt5Help Qt5Network Qt5OpenGL Qt5PrintSupport Qt5Xml" ;; *) AC_MSG_ERROR([Unrecognized Qt version $qt_version]) @@ -2199,9 +1823,6 @@ QT_CPPFLAGS="$($PKG_CONFIG --cflags-only-I $QT_MODULES | $SED -e 's/^ *$//')" QT_LDFLAGS="$($PKG_CONFIG --libs-only-L $QT_MODULES | $SED -e 's/^ *$//')" QT_LIBS="$($PKG_CONFIG --libs-only-l $QT_MODULES | $SED -e 's/^ *$//')" - QT_OPENGL_CPPFLAGS="$($PKG_CONFIG --cflags-only-I $QT_OPENGL_MODULE | $SED -e 's/^ *$//')" - QT_OPENGL_LDFLAGS="$($PKG_CONFIG --libs-only-L $QT_OPENGL_MODULE | $SED -e 's/^ *$//')" - QT_OPENGL_LIBS="$($PKG_CONFIG --libs-only-l $QT_OPENGL_MODULE | $SED -e 's/^ *$//')" case $host_os in *darwin*) @@ -2209,8 +1830,6 @@ if test -z "$QT_LIBS"; then QT_LDFLAGS="`$PKG_CONFIG --libs-only-other $QT_MODULES | tr ' ' '\n' | $GREP -e '-F' | uniq | tr '\n' ' '`" QT_LIBS="`$PKG_CONFIG --libs-only-other $QT_MODULES | tr ' ' '\n' | $GREP -v -e '-F' | uniq | tr '\n' ' '`" - QT_OPENGL_LDFLAGS="`$PKG_CONFIG --libs-only-other $QT_OPENGL_MODULE | tr ' ' '\n' | $GREP -e '-F' | uniq | tr '\n' ' '`" - QT_OPENGL_LIBS="`$PKG_CONFIG --libs-only-other $QT_OPENGL_MODULE | tr ' ' '\n' | $GREP -v -e '-F' | uniq | tr '\n' ' '`" ## Enabling link_all_deps works around libtool's imperfect handling ## of the -F flag if test -n "$QT_LDFLAGS"; then @@ -2302,36 +1921,17 @@ ## version that we are testing now will be the one used. OCTAVE_CHECK_FUNC_QFONTMETRICS_HORIZONTAL_ADVANCE - OCTAVE_CHECK_FUNC_QGUIAPPLICATION_SETDESKTOPFILENAME OCTAVE_CHECK_FUNC_QHELPSEARCHQUERYWIDGET_SEARCHINPUT OCTAVE_CHECK_NEW_QHELPINDEXWIDGET_API OCTAVE_CHECK_FUNC_QLIST_ITERATOR_CONSTRUCTOR - OCTAVE_CHECK_FUNC_QMAINWINDOW_RESIZEDOCKS - OCTAVE_CHECK_FUNC_QPRINTER_SETPAGESIZE - OCTAVE_CHECK_FUNC_QSCREEN_DEVICEPIXELRATIO OCTAVE_CHECK_FUNC_QHELPENGINE_DOCUMENTSFORIDENTIFIER - OCTAVE_CHECK_FUNC_QWHEELEVENT_ANGLEDELTA OCTAVE_CHECK_FUNC_QWHEELEVENT_POSITION OCTAVE_CHECK_FUNC_QPAINTER_SETRENDERHINT_LOSSLESS - OCTAVE_CHECK_QOVERLOAD_TEMPLATE OCTAVE_CHECK_QREGION_ITERATORS OCTAVE_CHECK_QT_IMCURSORRECTANGLE_ENUM_VALUE OCTAVE_CHECK_QT_SPLITBEHAVIOR_ENUM - if test -n "$OPENGL_LIBS"; then - OCTAVE_CHECK_QT_OPENGL_OK([build_qt_graphics=yes], - [warn_qt_opengl="Qt does not work with the OpenGL libs (GL and GLU); disabling OpenGL graphics with Qt GUI"]) - - if test $build_qt_graphics = yes; then - AC_DEFINE(HAVE_QT_GRAPHICS, 1, [Define to 1 if Qt works with OpenGL libs (GL and GLU)]) - OCTAVE_CHECK_QT_OPENGL_OFFSCREEN_OK([have_qt_opengl_offscreen=yes]) - if test $have_qt_opengl_offscreen = yes; then - AC_DEFINE(HAVE_QT_OFFSCREEN, 1, [Define to 1 if Qt handles offscreen OpenGL rendering]) - fi - fi - fi - OCTAVE_CHECK_QSCINTILLA([$qt_version]) fi @@ -2344,9 +1944,6 @@ AC_SUBST(QT_CPPFLAGS) AC_SUBST(QT_LDFLAGS) AC_SUBST(QT_LIBS) - AC_SUBST(QT_OPENGL_CPPFLAGS) - AC_SUBST(QT_OPENGL_LDFLAGS) - AC_SUBST(QT_OPENGL_LIBS) ]) dnl dnl Check if the default Fortran INTEGER is 64 bits wide. @@ -2635,7 +2232,7 @@ ]) if test $octave_cv_cxx_complex_reference_accessors = yes; then AC_DEFINE(HAVE_CXX_COMPLEX_REFERENCE_ACCESSORS, 1, - [Define to 1 if C++ complex class has T& real (void) and T& imag (void) methods.]) + [Define to 1 if C++ complex class has T& real () and T& imag () methods.]) fi ]) dnl diff -r 17d568574e1c -r 7860fcc69082 oct-conf-post-public.in.h --- a/oct-conf-post-public.in.h Mon Jan 30 18:30:33 2023 +0100 +++ b/oct-conf-post-public.in.h Mon Jan 30 18:36:03 2023 +0100 @@ -39,7 +39,7 @@ OCTAVE_ATTRIBUTE_NAME in place of vendor specific attribute mechanisms. As compilers evolve, the underlying implementation can be changed with the macro definitions below. FIXME: Update macros - to use C++ standard attribute syntax when Octave moves to C++ 2011 + to use C++ standard attribute syntax when Octave moves to C++ 2014 standard. */ #if defined (__GNUC__) diff -r 17d568574e1c -r 7860fcc69082 scripts/deprecated/disable_diagonal_matrix.m --- a/scripts/deprecated/disable_diagonal_matrix.m Mon Jan 30 18:30:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +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 -## . -## -######################################################################## - -## -*- texinfo -*- -## @deftypefn {} {@var{val} =} disable_diagonal_matrix () -## @deftypefnx {} {@var{old_val} =} disable_diagonal_matrix (@var{new_val}) -## @deftypefnx {} {@var{old_val} =} disable_diagonal_matrix (@var{new_val}, "local") -## -## @code{disable_diagonal_matrix} is deprecated and will be removed in Octave -## version 9. Use @code{optimize_diagonal_matrix} instead. -## -## Query or set whether storing diagonal matrices in a special space-efficient -## format is disabled. -## -## The default value is false. If this option is set to true, Octave will -## store ranges as full matrices. -## -## When called from inside a function with the @qcode{"local"} option, the -## setting is changed locally for the function and any subroutines it calls. -## The original setting is restored when exiting the function. -## @seealso{disable_diagonal_matrix, disable_permutation_matrix} -## @end deftypefn - -## FIXME: DEPRECATED: Remove in version 9. - -function retval = disable_diagonal_matrix (varargin) - - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - "disable_diagonal_matrix is obsolete and will be removed from a future version of Octave, please use optimize_diagonal_matrix instead\n"); - endif - - if (nargin == 0) - retval = ! optimize_diagonal_matrix (); - elseif (nargout == 0) - optimize_diagonal_matrix (! varargin{1}, varargin{2:end}); - else - retval = ! optimize_diagonal_matrix (! varargin{1}, varargin{2:end}); - endif - -endfunction diff -r 17d568574e1c -r 7860fcc69082 scripts/deprecated/disable_permutation_matrix.m --- a/scripts/deprecated/disable_permutation_matrix.m Mon Jan 30 18:30:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +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 -## . -## -######################################################################## - -## -*- texinfo -*- -## @deftypefn {} {@var{val} =} disable_permutation_matrix () -## @deftypefnx {} {@var{old_val} =} disable_permutation_matrix (@var{new_val}) -## @deftypefnx {} {@var{old_val} =} disable_permutation_matrix (@var{new_val}, "local") -## -## @code{disable_permutation_matrix} is deprecated and will be removed in -## Octave version 9. Use @code{optimize_permutation_matrix} instead. -## -## Query or set whether storing permutation matrices in a special -## space-efficient format is disabled. -## -## The default value is false. If this option is set to true, Octave will -## store ranges as full matrices. -## -## When called from inside a function with the @qcode{"local"} option, the -## setting is changed locally for the function and any subroutines it calls. -## The original setting is restored when exiting the function. -## @seealso{disable_diagonal_matrix, disable_permutation_matrix} -## @end deftypefn - -## FIXME: DEPRECATED: Remove in version 9. - -function retval = disable_permutation_matrix (varargin) - - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - "disable_permutation_matrix is obsolete and will be removed from a future version of Octave, please use optimize_permutation_matrix instead\n"); - endif - - if (nargin == 0) - retval = ! optimize_permutation_matrix (); - elseif (nargout == 0) - optimize_permutation_matrix (! varargin{1}, varargin{2:end}); - else - retval = ! optimize_permutation_matrix (! varargin{1}, varargin{2:end}); - endif - -endfunction diff -r 17d568574e1c -r 7860fcc69082 scripts/deprecated/disable_range.m --- a/scripts/deprecated/disable_range.m Mon Jan 30 18:30:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +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 -## . -## -######################################################################## - -## -*- texinfo -*- -## @deftypefn {} {@var{val} =} disable_range () -## @deftypefnx {} {@var{old_val} =} disable_range (@var{new_val}) -## @deftypefnx {} {@var{old_val} =} disable_range (@var{new_val}, "local") -## -## @code{disable_range} is deprecated and will be removed in Octave version 9. -## Use @code{optimize_range} instead. -## -## Query or set whether storing ranges in a special space-efficient format is -## disabled. -## -## The default value is false. If this option is set to true, Octave will -## store ranges as full matrices. -## -## When called from inside a function with the @qcode{"local"} option, the -## setting is changed locally for the function and any subroutines it calls. -## The original setting is restored when exiting the function. -## @seealso{disable_diagonal_matrix, disable_permutation_matrix} -## @end deftypefn - -## FIXME: DEPRECATED: Remove in version 9. - -function retval = disable_range (varargin) - - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - "disable_range is obsolete and will be removed from a future version of Octave, please use optimize_range instead\n"); - endif - - if (nargin == 0) - retval = ! optimize_range (); - elseif (nargout == 0) - optimize_range (! varargin{1}, varargin{2:end}); - else - retval = ! optimize_range (! varargin{1}, varargin{2:end}); - endif - -endfunction diff -r 17d568574e1c -r 7860fcc69082 scripts/deprecated/module.mk --- a/scripts/deprecated/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/deprecated/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -2,9 +2,6 @@ %canon_reldir%_FCN_FILES = \ %reldir%/.oct-config \ - %reldir%/disable_diagonal_matrix.m \ - %reldir%/disable_permutation_matrix.m \ - %reldir%/disable_range.m \ %reldir%/shift.m \ %reldir%/sparse_auto_mutate.m diff -r 17d568574e1c -r 7860fcc69082 scripts/geometry/tsearchn.m --- a/scripts/geometry/tsearchn.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/geometry/tsearchn.m Mon Jan 30 18:36:03 2023 +0100 @@ -26,15 +26,17 @@ ## -*- texinfo -*- ## @deftypefn {} {@var{idx} =} tsearchn (@var{x}, @var{t}, @var{xi}) ## @deftypefnx {} {[@var{idx}, @var{p}] =} tsearchn (@var{x}, @var{t}, @var{xi}) -## Search for the enclosing Delaunay convex hull. +## Find the simplexes enclosing the given points. ## -## For @code{@var{t} = delaunayn (@var{x})}, finds the index in @var{t} -## containing the points @var{xi}. For points outside the convex hull, -## @var{idx} is NaN. +## @code{tsearchn} is typically used with @code{delaunayn}: +## @code{@var{t} = delaunayn (@var{x})} returns a set of simplexes @code{t}, +## then @code{tsearchn} returns the row index of @var{t} containing each point +## of @var{xi}. For points outside the convex hull, @var{idx} is NaN. ## -## If requested @code{tsearchn} also returns the Barycentric coordinates -## @var{p} of the enclosing triangles. -## @seealso{delaunay, delaunayn} +## If requested, @code{tsearchn} also returns the barycentric coordinates +## @var{p} of the enclosing simplexes. +## +## @seealso{delaunay, delaunayn, tsearch} ## @end deftypefn function [idx, p] = tsearchn (x, t, xi) @@ -43,57 +45,53 @@ print_usage (); endif + if (columns (x) != columns (xi)) + error ("tsearchn: number of columns of X and XI must match"); + endif + + if (max (t(:)) > rows (x)) + error ("tsearchn: triangulation T must not access points outside X"); + endif + + if (nargout <= 1 && columns (x) == 2) # pass to the faster tsearch.cc + idx = tsearch (x(:,1), x(:,2), t, xi(:,1), xi(:,2)); + return; + endif + nt = rows (t); [m, n] = size (x); mi = rows (xi); idx = NaN (mi, 1); p = NaN (mi, n + 1); - ni = [1:mi].'; - for i = 1 : nt - ## Only calculate the Barycentric coordinates for points that have not - ## already been found in a triangle. - b = cart2bary (x (t (i, :), :), xi(ni,:)); - ## Our points xi are in the current triangle if - ## (all (b >= 0) && all (b <= 1)). However as we impose that - ## sum (b,2) == 1 we only need to test all(b>=0). Note need to add - ## a small margin for rounding errors - intri = all (b >= -1e-12, 2); - idx(ni(intri)) = i; - p(ni(intri),:) = b(intri, :); - ni(intri) = []; - endfor + for i = 1 : nt # each simplex in turn -endfunction - -function Beta = cart2bary (T, P) + T = x(t(i, :), :); # T is the current simplex + P = xi(ni, :); # P is the set of points left to calculate - ## Conversion of Cartesian to Barycentric coordinates. - ## Given a reference simplex in N dimensions represented by an - ## N+1-by-N matrix, an arbitrary point P in Cartesian coordinates, - ## represented by an N-by-1 column vector can be written as - ## - ## P = Beta * T - ## - ## Where Beta is an N+1 vector of the barycentric coordinates. A criteria - ## on Beta is that - ## - ## sum (Beta) == 1 - ## - ## and therefore we can write the above as - ## - ## P - T(end, :) = Beta(1:end-1) * (T(1:end-1,:) - ones (N,1) * T(end,:)) - ## - ## and then we can solve for Beta as - ## - ## Beta(1:end-1) = (P - T(end,:)) / (T(1:end-1,:) - ones (N,1) * T(end,:)) - ## Beta(end) = sum (Beta) - ## - ## Note code below is generalized for multiple values of P, one per row. - [M, N] = size (P); - Beta = (P - ones (M,1) * T(end,:)) / (T(1:end-1,:) - ones (N,1) * T(end,:)); - Beta (:,end+1) = 1 - sum (Beta, 2); + ## Convert to barycentric coords: these are used to express a point P + ## as P = Beta * T + ## where T is a simplex. + ## + ## If 0 <= Beta <= 1, then the linear combination is also convex, + ## and the point P is inside the simplex T, otherwise it is outside. + ## Since the equation system is underdetermined, we apply the constraint + ## sum (Beta) == 1 to make it unique up to scaling. + ## + ## Note that the code below is vectorized over P, one point per row. + + b = (P - T(end,:)) / (T(1:end-1,:) - T(end,:)); + b(:, end+1) = 1 - sum (b, 2); + + ## The points xi are inside the current simplex if + ## (all (b >= 0) && all (b <= 1)). As sum (b,2) == 1, we only need to + ## test all(b>=0). + inside = all (b >= -1e-12, 2); # -1e-12 instead of 0 for rounding errors + idx(ni(inside)) = i; + p(ni(inside), :) = b(inside, :); + ni = ni(! inside); + endfor endfunction @@ -121,3 +119,10 @@ %! [idx, p] = tsearchn (x,tri,[1,1]); %! assert (idx, NaN); %! assert (p, [NaN, NaN, NaN]); + +## Test input validation +%!error tsearchn () +%!error tsearchn (1) +%!error tsearchn (1, 2) +%!error tsearchn ([1,2], 3, 4) +%!error tsearchn (1, 2, 3) diff -r 17d568574e1c -r 7860fcc69082 scripts/image/getframe.m --- a/scripts/image/getframe.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/image/getframe.m Mon Jan 30 18:36:03 2023 +0100 @@ -167,8 +167,9 @@ %! image (frame.cdata); %! title ("Lower left hand corner"); -%!testif HAVE_QT_OFFSCREEN; have_window_system () && strcmp ("qt", graphics_toolkit ()) +%!testif HAVE_OPENGL, HAVE_QT; have_window_system () && any (strcmp ("qt", graphics_toolkit ())) %! hf = figure ("visible", "off"); +%! graphics_toolkit (hf, "qt"); %! unwind_protect %! pos = get (hf, "position"); %! assert (size (getframe (hf).cdata)(1:2), pos(4:-1:3)); @@ -176,8 +177,9 @@ %! close (hf); %! end_unwind_protect -%!testif HAVE_QT_OFFSCREEN; have_window_system () && strcmp ("qt", graphics_toolkit ()) +%!testif HAVE_OPENGL, HAVE_QT; have_window_system () && any (strcmp ("qt", graphics_toolkit ())) %! hf = figure ("visible", "off"); +%! graphics_toolkit (hf, "qt"); %! unwind_protect %! hax = axes ("visible", "off", "position", [0 0 1 1]); %! verts = [0 0; .5 0; 1 0; ... diff -r 17d568574e1c -r 7860fcc69082 scripts/linear-algebra/module.mk --- a/scripts/linear-algebra/module.mk Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/linear-algebra/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -35,6 +35,7 @@ %reldir%/rref.m \ %reldir%/subspace.m \ %reldir%/trace.m \ + %reldir%/tensorprod.m \ %reldir%/vech.m \ %reldir%/vecnorm.m diff -r 17d568574e1c -r 7860fcc69082 scripts/linear-algebra/tensorprod.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/linear-algebra/tensorprod.m Mon Jan 30 18:36:03 2023 +0100 @@ -0,0 +1,437 @@ +######################################################################## +## +## Copyright (C) 2022-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 +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{C} =} tensorprod (@var{A}, @var{B}, @var{dimA}, @var{dimB}) +## @deftypefnx {} {@var{C} =} tensorprod (@var{A}, @var{B}, @var{dim}) +## @deftypefnx {} {@var{C} =} tensorprod (@var{A}, @var{B}) +## @deftypefnx {} {@var{C} =} tensorprod (@var{A}, @var{B}, "all") +## @deftypefnx {} {@var{C} =} tensorprod (@var{A}, @var{B}, @dots{}, "NumDimensionsA", @var{value}) +## Compute the tensor product between numeric tensors @var{A} and @var{B}. +## +## The dimensions of @var{A} and @var{B} that are contracted are defined by +## @var{dimA} and @var{dimB}, respectively. @var{dimA} and @var{dimB} are +## scalars or equal length vectors that define the dimensions to match up. +## The matched dimensions of @var{A} and @var{B} must have equal lengths. +## +## When @var{dim} is used, it is equivalent to @var{dimA} = @var{dimB} = +## @var{dim}. +## +## When no dimensions are specified, @var{dimA} = @var{dimB} = []. This +## computes the outer product between @var{A} and @var{B}. +## +## Using the "all" option results in the inner product between @var{A} and +## @var{B}. This requires size(@var{A}) == size(@var{B}). +## +## Use the property-value pair with the property name "NumDimensionsA" when +## @var{A} has trailing singleton dimensions that should be transfered to +## @var{C}. The specified @var{value} should be the total number of +## dimensions of @var{A}. +## +## Matlab Compatibility: Octave does not currently support the "name=value" +## syntax for the "NumDimensionsA" parameter. +## +## @seealso{kron, dot, mtimes} +## @end deftypefn + +function C = tensorprod (A, B, varargin) + + ## FIXME: shortcut code paths could be added for trivial cases, such as if + ## either A or B are a scalars, null, identity tensors, etc. + + if (nargin < 2 || nargin > 6) + print_usage (); + endif + + ## Check that A and B are single or double + if (! isfloat (A)) + error ("tensorprod: A must be a single or double precision array"); + endif + + if (! isfloat (B)) + error ("tensorprod: B must be a single or double precision array"); + endif + + ## Check for misplaced NumDimensionsA property + if (nargin > 2) + if (strcmpi (varargin{end}, "NumDimensionsA")) + error (["tensorprod: a value for the NumDimensionsA property must ", ... + "be provided"]); + elseif (strcmpi ( strtok (inputname (nargin, false)), "NumDimensionsA")) + ## FIXME: Add support for keyword=value syntax + error (["tensorprod: NumDimensionsA=ndimsA syntax is not yet ", ... + "supported in Octave - provide the value as a ", ... + "property-value pair"]); + endif + endif + + ## Check for NumDimensionsA property + if (nargin > 3) + if (strcmpi (varargin{end - 1}, "NumDimensionsA")) + if (! (isnumeric (varargin{end}) && isscalar (varargin{end}))) + error (["tensorprod: value for NumDimensionsA must be a ", ... + "numeric scalar"]); + elseif (varargin{end} < 1 || rem (varargin{end}, 1) != 0) + error (["tensorprod: value for NumDimensionsA must be a ", ... + "positive integer"]); + endif + NumDimensionsA = varargin{end}; + endif + endif + + existNumDimensionsA = exist ("NumDimensionsA"); + ndimargs = nargin - 2 - 2 * existNumDimensionsA; + + ## Set dimA and dimB + if (ndimargs == 0) + ## Calling without dimension arguments + dimA = []; + dimB = []; + elseif (ndimargs == 1) + ## Calling with dim or "all" option + if (isnumeric (varargin{1})) + if (! (isvector (varargin{1}) || isnull (varargin{1}))) + error ("tensorprod: dim must be a numeric vector of integers or []"); + endif + ## Calling with dim + dimA = transpose ([varargin{1}(:)]); + elseif (ischar (varargin{1})) + if (strcmpi (varargin{1}, "all")) + if (! size_equal (A, B)) + error (["tensorprod: size of A and B must be identical when ", ... + "using the 'all' option"]); + endif + else + error ("tensorprod: unknown option '%s'", varargin{1}); + endif + ## Calling with "all" option + dimA = 1:ndims(A); + else + error (["tensorprod: third argument must be a numeric vector of ", ... + "integers, [], or 'all'"]); + endif + dimB = dimA; + elseif (ndimargs == 2) + ## Calling with dimA and dimB + if (! (isnumeric (varargin{1}) && (isvector (varargin{1}) || ... + isnull (varargin{1})))) + error("tensorprod: dimA must be a numeric vector of integers or []"); + endif + + if (! (isnumeric (varargin{2}) && (isvector (varargin{2}) || ... + isnull (varargin{2})))) + error ("tensorprod: dimB must be a numeric vector of integers or []"); + endif + + if (length (varargin{1}) != length (varargin{2})) + error (["tensorprod: an equal number of dimensions must be ", ... + "matched for A and B"]); + endif + dimA = transpose ([varargin{1}(:)]); + dimB = transpose ([varargin{2}(:)]); + else + ## Something is wrong - try to find the error + for i = 1:ndimargs + if (ischar (varargin{i})) + if (strcmpi (varargin{i}, "NumDimensionsA")) + error ("tensorprod: misplaced 'NumDimensionsA' option"); + elseif (strcmpi (varargin{i}, "all")) + error ("tensorprod: misplaced 'all' option"); + else + error ("tensorprod: unknown option '%s'", varargin{i}); + endif + elseif (! isnumeric (varargin{i})) + error (["tensorprod: optional arguments must be numeric vectors ", ... + "of integers, [], 'all', or 'NumDimensionsA'"]); + endif + endfor + error ("tensorprod: too many dimension inputs given"); + endif + + ## Check that dimensions are positive integers ([] will also pass) + if (any ([dimA < 1, dimB < 1, (rem (dimA, 1) != 0), (rem (dimB, 1) != 0)])) + error ("tensorprod: dimension(s) must be positive integer(s)"); + endif + + ## Check that the length of matched dimensions are equal + if (any (size (A, dimA) != size (B, dimB))) + error (["tensorprod: matched dimension(s) of A and B must have the ", ... + "same length(s)"]); + endif + + ## Find size and ndims of A and B + ndimsA = max ([ndims(A), max(dimA)]); + sizeA = size (A, 1:ndimsA); + ndimsB = max ([ndims(B), max(dimB)]); + sizeB = size (B, 1:ndimsB); + + ## Take NumDimensionsA property into account + if (existNumDimensionsA) + if (NumDimensionsA < ndimsA) + if (ndimargs == 1) + error (["tensorprod: highest dimension of dim must be less than ", ... + "or equal to NumDimensionsA"]); + elseif (ndimargs == 2) + error (["tensorprod: highest dimension of dimA must be less ", ... + "than or equal to NumDimensionsA"]); + else + error (["tensorprod: NumDimensionsA cannot be smaller than the ", ... + "number of dimensions of A"]); + endif + elseif (NumDimensionsA > ndimsA) + sizeA = [sizeA, ones(1, NumDimensionsA - ndimsA)]; + ndimsA = NumDimensionsA; + endif + endif + + ## Interchange the dimension to sum over the end of A and the front of B + ## Prepare for A + remainDimA = setdiff (1:ndimsA, dimA); # Dimensions of A to keep + newDimOrderA = [remainDimA, dimA]; # New dim order [to_keep, to_contract] + newSizeA = [prod(sizeA(remainDimA)), prod(sizeA(dimA))]; # Temp. 2D size for A + remainSizeA = sizeA(remainDimA); # Contrib. to size of C from remaining A dims + + ## Prepare for B (See comments for A. Note that in principle, + ## prod (sizeB (dimB)) should always be equal to prod (sizeA (dimA)). May + ## be able to optimize further here. + remainDimB = setdiff (1:ndimsB, dimB); + newDimOrderB = [remainDimB, dimB]; + newSizeB = [prod(sizeB(remainDimB)), prod(sizeB(dimB))]; + remainSizeB = sizeB(remainDimB); + + ## Do reshaping into 2D array + newA = reshape (permute (A, newDimOrderA), newSizeA); + newB = reshape (permute (B, newDimOrderB), newSizeB); + + ## Compute + C = newA * transpose (newB); + + ## If not an inner product, reshape back to tensor + if (! isscalar (C)) + C = reshape (C, [remainSizeA, remainSizeB]); + endif + +endfunction + + +%!assert (tensorprod (2, 3), 6) +%!assert (tensorprod (2, 3, 1), 6) +%!assert (tensorprod (2, 3, 2), 6) +%!assert (tensorprod (2, 3, 10), 6) +%!assert (tensorprod (2, 3, [1 2]), 6) +%!assert (tensorprod (2, 3, [1 10]), 6) +%!assert (tensorprod (2, 3, []), 6) +%!assert (tensorprod (2, 3, 2, 1), 6) +%!assert (tensorprod (2, 3, [], []), 6) + +%!shared v1, v2, M1, M2, T +%! v1 = [1, 2]; +%! M1 = [1, 2; 3, 4]; +%! M2 = [1, 2; 3, 4; 5, 6]; +%! T = cat (3, M2, M2); + +%!assert (tensorprod (3, v1), reshape ([3, 6], [1, 1, 1, 2])); +%!assert (tensorprod (v1, 3), [3, 6]); +%!assert (tensorprod (v1, v1, "all"), 5); +%!assert (tensorprod (v1, v1), reshape ([1, 2, 2, 4], [1, 2, 1, 2])); +%!assert (tensorprod (v1, v1, 1), [1, 2; 2, 4]); +%!assert (tensorprod (v1, v1, 2), 5); +%!assert (tensorprod (v1, v1, 3), reshape ([1, 2, 2, 4], [1, 2, 1, 2])); +%!assert (tensorprod (v1, v1, 5), reshape ([1, 2, 2, 4], [1, 2, 1, 1, 1, 2])); + +%!assert (tensorprod (M1, v1), cat (4, [1,2;3,4], [2,4;6,8])) +%!assert (tensorprod (M1, v1'), cat (3, [1,2;3,4], [2,4;6,8])) +%!assert (tensorprod (v1, M1), reshape ([1 2 3 6 2 4 4 8], [1,2,2,2])) +%!assert (tensorprod (v1', M1), reshape ([1 2 3 6 2 4 4 8], [2,1,2,2])) +%!assert (tensorprod (M1, v1', 2, 1), [5; 11]) +%!assert (tensorprod (M1, v1', 4, 4), cat(4, M1, 2*M1)) +%!assert (tensorprod (M1, v1', [1, 3]), [7; 10]) +%!assert (tensorprod (M1, v1', [1, 3], [1, 3]), [7; 10]) +%!assert (tensorprod (M1, v1', [2, 3], [1, 3]), [5; 11]) +%!assert (tensorprod (M1, v1', [2; 3], [1; 3]), [5; 11]) +%!assert (tensorprod (M1, v1', [2; 3], [1, 3]), [5; 11]) +%!assert (tensorprod (M1, v1', [2, 3], [1; 3]), [5; 11]) +%!assert (tensorprod (M1, v1', [], []), cat (3, M1, 2*M1)) +%!assert (tensorprod (M1, M1, "all"), 30) +%!assert (tensorprod (M1, M1, 1), [10, 14; 14, 20]) +%!assert (tensorprod (M1, M1, 2), [5, 11; 11, 25]) +%!assert (tensorprod (M1, M2, 2), [5, 11, 17; 11, 25, 39]) +%!assert (tensorprod (M1, M2, 1, 2), [7, 15, 23; 10, 22, 34]) +%!assert (tensorprod (M1, M2), reshape ([1,3,2,4,3,9,6,12,5,15,10,20,2,6,4, ... +%! 8,4,12,8,16,6,18,12,24], [2,2,3,2])) + +%!assert (tensorprod (T, M1), +%! reshape([1,3,5,2,4,6,1,3,5,2,4,6,3,9,15,6,12,18,3,9,15,6,12,18,2, ... +%! 6,10,4,8,12,2,6,10,4,8,12,4,12,20,8,16,24,4,12,20,8,16,24], +%! [3,2,2,2,2])) +%!assert (tensorprod (T, M1, 2), +%! cat (3, [5, 5; 11 11; 17, 17], [11, 11; 25, 25; 39, 39])) +%!assert (tensorprod (T, M2, 1), cat (3, [35, 35; 44, 44], [44, 44; 56, 56])) +%!assert (tensorprod (T, M2, 2), cat (3, [5, 5; 11, 11; 17, 17], +%! [11,11;25,25;39,39], [17, 17; 39, 39; 61, 61])) +%!assert (tensorprod (T, T, "all"), 182) +%!assert (tensorprod (T, T, 1), +%! reshape ([35,44,35,44,44,56,44,56,35,44,35,44,44,56,44,56], +%! [2,2,2,2])) +%!assert (tensorprod (T, T, 2), +%! reshape ([5,11,17,5,11,17,11,25,39,11,25,39,17,39,61,17,39,61,5, ... +%! 11,17,5,11,17,11,25,39,11,25,39,17,39,61,17,39,61], +%! [3,2,3,2])) +%!assert (tensorprod (T, T, 3), +%! reshape ([2,6,10,4,8,12,6,18,30,12,24,36,10,30,50,20,40,60,4,12, ... +%! 20,8,16,24,8,24,40,16,32,48,12,36,60,24,48,72], [3,2,3,2])); +%!assert (tensorprod (T, T, 10), +%! reshape ([1,3,5,2,4,6,1,3,5,2,4,6,3,9,15,6,12,18,3,9,15,6,12,18, ... +%! 5,15,25,10,20,30,5,15,25,10,20,30,2,6,10,4,8,12,2,6,10, ... +%! 4,8,12,4,12,20,8,16,24,4,12,20,8,16,24,6,18,30,12,24,36, ... +%! 6,18,30,12,24,36,1,3,5,2,4,6,1,3,5,2,4,6,3,9,15,6,12,18, ... +%! 3,9,15,6,12,18,5,15,25,10,20,30,5,15,25,10,20,30,2,6,10, ... +%! 4,8,12,2,6,10,4,8,12,4,12,20,8,16,24,4,12,20,8,16,24,6, ... +%! 18,30,12,24,36,6,18,30,12,24,36], +%! [3,2,2,1,1,1,1,1,1,3,2,2])) +%!assert (tensorprod (T, T, []), +%! reshape ([1,3,5,2,4,6,1,3,5,2,4,6,3,9,15,6,12,18,3,9,15,6,12,18, ... +%! 5,15,25,10,20,30,5,15,25,10,20,30,2,6,10,4,8,12,2,6,10, ... +%! 4,8,12,4,12,20,8,16,24,4,12,20,8,16,24,6,18,30,12,24,36, ... +%! 6,18,30,12,24,36,1,3,5,2,4,6,1,3,5,2,4,6,3,9,15,6,12,18, ... +%! 3,9,15,6,12,18,5,15,25,10,20,30,5,15,25,10,20,30,2,6,10, ... +%! 4,8,12,2,6,10,4,8,12,4,12,20,8,16,24,4,12,20,8,16,24,6, ... +%! 18,30,12,24,36,6,18,30,12,24,36], +%! [3,2,2,3,2,2])) +%!assert (tensorprod (T, T, 2, 3), +%! reshape ([3,7,11,3,7,11,9,21,33,9,21,33,15,35,55,15,35,55,6,14, ... +%! 22,6,14,22,12,28,44,12,28,44,18,42,66,18,42,66], +%! [3,2,3,2])) +%!assert (tensorprod (T, T(1:2, 1:2, :), [2, 3],[1, 3]), +%! [14, 20; 30, 44; 46, 68]) +%!assert (tensorprod (T, T(1:2, 1:2, :), [3, 2],[1, 3]), +%! [12, 18; 28, 42; 44, 66]) +%!assert (tensorprod (T, reshape (T, [2, 2, 3]), 2, 1), +%! reshape ([7,15,23,7,15,23,9,23,37,9,23,37,16,36,56,16,36,56,7,15, ... +%! 23,7,15,23,9,23,37,9,23,37,16,36,56,16,36,56], +%! [3,2,2,3])) +%!assert (tensorprod (T, T, [1, 3]), [70, 88; 88, 112]) +%!assert (tensorprod (T, T, [1, 3]), tensorprod (T, T, [3, 1])) +%!assert (tensorprod (T, reshape (T, [2, 2, 3]), [2, 3], [1, 2]), +%! [16, 23, 25; 38, 51, 59; 60, 79, 93]) + +## NumDimensionsA tests +%!assert (tensorprod (v1, v1, "NumDimensionsA", 2), +%! reshape ([1, 2, 2, 4], [1, 2, 1, 2])); +%!assert (tensorprod (v1, v1, "numdimensionsa", 2), +%! tensorprod (v1, v1, "NumDimensionsA", 2)); +%!assert (tensorprod (v1, v1, "NumDimensionsA", 3), +%! reshape ([1, 2, 2, 4], [1, 2, 1, 1, 2])); +%!assert (tensorprod (v1, v1, [], "NumDimensionsA", 3), +%! reshape ([1, 2, 2, 4], [1, 2, 1, 1, 2])); +%!assert (tensorprod (v1, v1, [], [], "NumDimensionsA", 3), +%! reshape ([1, 2, 2, 4], [1, 2, 1, 1, 2])); +%!assert (tensorprod (v1, v1, "all", "NumDimensionsA", 3), 5); +%!assert (tensorprod (M1, v1, 2, "NumDimensionsA", 2), [5; 11]); +%!assert (tensorprod (M1, v1, 2, "NumDimensionsA", 5), [5; 11]); +%!assert (tensorprod (M1, v1, [2, 3], "NumDimensionsA", 5), [5; 11]); +%!assert (tensorprod (M1, M2, "NumDimensionsA", 2), reshape ([1,3,2,4,3,9,6, ... +%! 12,5,15,10,20,2,6,4,8,4,12,8,16,6,18,12,24], [2,2,3,2])) +%!assert (tensorprod (M1, M2, "NumDimensionsA", 3), reshape ([1,3,2,4,3,9,6, ... +%! 12,5,15,10,20,2,6,4,8,4,12,8,16,6,18,12,24], [2,2,1,3,2])) +%!assert (tensorprod (T, T, 1, "NumDimensionsA", 3), +%! reshape ([35,44,35,44,44,56,44,56,35,44,35,44,44,56,44,56], +%! [2,2,2,2])) +%!assert (tensorprod (T, T, 3, "NumDimensionsA", 3), +%! reshape ([2,6,10,4,8,12,6,18,30,12,24,36,10,30,50,20,40,60,4,12, ... +%! 20,8,16,24, 8,24,40,16,32,48,12,36,60,24,48,72], +%! [3,2,3,2])) +%!assert (tensorprod (T, T, 1, "NumDimensionsA", 4), +%! reshape ([35,44,35,44,44,56,44,56,35,44,35,44,44,56,44,56], +%! [2,2,1,2,2])) +%!assert (tensorprod (T, T, 4, "NumDimensionsA", 4), +%! reshape ([1,3,5,2,4,6,1,3,5,2,4,6,3,9,15,6,12,18,3,9,15,6,12,18,5, ... +%! 15,25,10,20,30,5,15,25,10,20,30,2,6,10,4,8,12,2,6,10,4,8, ... +%! 12,4,12,20,8,16,24,4,12,20,8,16,24,6,18,30,12,24,36,6,18, ... +%! 30,12,24,36,1,3,5,2,4,6,1,3,5,2,4,6,3,9,15,6,12,18,3,9,15, ... +%! 6,12,18,5,15,25,10,20,30,5,15,25,10,20,30,2,6,10,4,8,12,2, ... +%! 6,10,4,8,12,4,12,20,8,16,24,4,12,20,8,16,24,6,18,30,12,24, ... +%! 36,6,18,30,12,24,36], +%! [3,2,2,3,2,2])) + +## Test empty inputs +%!assert (tensorprod ([], []), zeros (0, 0, 0, 0)) +%!assert (tensorprod ([], 1), []) +%!assert (tensorprod (1, []), zeros (1, 1, 0, 0)) +%!assert (tensorprod (zeros (0, 0, 0), zeros (0, 0, 0)), zeros (0, 0, 0, 0, 0, 0)) +%!assert (tensorprod ([], [], []), zeros (0, 0, 0, 0)) +%!assert (tensorprod ([], [], 1), []) +%!assert (tensorprod ([], [], 2), []) +%!assert (tensorprod ([], [], 3), zeros (0, 0, 0, 0)) +%!assert (tensorprod ([], [], 4), zeros (0, 0, 1, 0, 0)) +%!assert (tensorprod ([], [], 5), zeros (0, 0, 1, 1, 0, 0)) +%!assert (tensorprod ([], [], 3, "NumDimensionsA", 4), zeros (0, 0, 1, 0, 0)) +%!assert (tensorprod ([], [], 3, 4, "NumDimensionsA", 5), zeros (0, 0, 1, 1, 0, 0)) + +## Test input validation +%!error tensorprod () +%!error tensorprod (1) +%!error tensorprod (1,2,3,4,5,6,7) +%!error tensorprod ("foo", 1) +%!error tensorprod (1, "bar") +%!error tensorprod (int32(1), 1) +%!error tensorprod (1, int32(1)) +%!error tensorprod (1, 1, "foo") +%!error tensorprod (1, 1, 1, "foo", 1) +%!error tensorprod (1, 1, "foo", 1) +%!error tensorprod (1, 1, 1, "bar") +%!error tensorprod (1, 1, zeros(0,0,0), []) +%!error tensorprod (1, 1, [], zeros(0,0,0)) +%!error tensorprod (1, 1, zeros(0,0,0)) +%!error tensorprod (1, 1, 1, "all", 1) +%!error tensorprod (1, 1, "NumDimensionsA", 1, 1) +%!error tensorprod (1, 1, 1, {}, 1) +%!error tensorprod (ones (3, 4), ones (4, 3), 1) +%!error tensorprod (ones (3, 4), ones (4, 3), 1, 1) +%!error tensorprod (1, 1, 0) +%!error tensorprod (1, 1, -1) +%!error tensorprod (1, 1, 1.5) +%!error tensorprod (1, 1, NaN) +%!error tensorprod (1, 1, Inf) +%!error tensorprod (1, 1, {}) +%!error tensorprod (ones (3, 4), ones (4, 3), 1, [1, 2]) +%!error tensorprod (ones (3, 4), ones (4, 3), 1, []) +%!error tensorprod (ones (3, 4), ones (4, 3), [], [1, 2]) +%!error tensorprod (ones (3, 4), ones (4, 3), "all") +%!error tensorprod (1, 1, "NumDimensionsA") +%!error tensorprod (ones (2, 2, 2), 1, "NumDimensionsA", 2) +%!error tensorprod (1, 1, 5, "NumDimensionsA", 4) +%!error tensorprod (1, 1, 5, 5, "NumDimensionsA", 4) +%!error tensorprod (1, 1, NumDimensionsA=4) +%!error tensorprod (1, 1, numdimensionsa=4) +%!error tensorprod (1, 1, 2, 1, 1) +%!error tensorprod (1, 1, 2, 1, 1, 1) +%!error tensorprod (1, 1, 2, 1, "NumDimensionsA", "foo") +%!error tensorprod (1, 1, 2, 1, "NumDimensionsA", {}) +%!error tensorprod (1, 1, 2, 1, "NumDimensionsA", -1) +%!error tensorprod (1, 1, 2, 1, "NumDimensionsA", 0) +%!error tensorprod (1, 1, 2, 1, "NumDimensionsA", 1.5) +%!error tensorprod (1, 1, 2, 1, "NumDimensionsA", NaN) +%!error tensorprod (1, 1, 2, 1, "NumDimensionsA", Inf) diff -r 17d568574e1c -r 7860fcc69082 scripts/optimization/sqp.m --- a/scripts/optimization/sqp.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/optimization/sqp.m Mon Jan 30 18:36:03 2023 +0100 @@ -121,8 +121,7 @@ ## inequality constraints @var{g} and @var{h}. If the arguments are vectors ## then @var{x}(i) is bound by @var{lb}(i) and @var{ub}(i). A bound can also ## be a scalar in which case all elements of @var{x} will share the same -## bound. If only one bound (lb, ub) is specified then the other will -## default to (-@var{realmax}, +@var{realmax}). +## bound. ## ## The seventh argument @var{maxiter} specifies the maximum number of ## iterations. The default value is 100. @@ -288,37 +287,43 @@ ## constraint inequality function with bounds present lb_idx = ub_idx = true (size (x0)); ub_grad = - (lb_grad = eye (rows (x0))); + + ## if unspecified set ub and lb to +/-Inf, preserving single type + if (isempty (lb)) + if (isa (x0, "single")) + lb = - inf (size (x0), "single"); + else + lb = - inf (size (x0)); + endif + endif + if (isvector (lb)) - globals.lb = tmp_lb = lb(:); - lb_idx(:) = tmp_idx = (lb != -Inf); - globals.lb = globals.lb(tmp_idx, 1); + lb = lb(:); + lb_idx(:) = (lb != -Inf); + globals.lb = lb(lb_idx, 1); lb_grad = lb_grad(lb_idx, :); - elseif (isempty (lb)) - if (isa (x0, "single")) - globals.lb = tmp_lb = -realmax ("single"); - else - globals.lb = tmp_lb = -realmax (); - endif else error ("sqp: invalid lower bound"); endif + if (isempty (ub)) + if (isa (x0, "single")) + ub = inf (size (x0), "single"); + else + ub = inf (size (x0)); + endif + endif + if (isvector (ub)) - globals.ub = tmp_ub = ub(:); - ub_idx(:) = tmp_idx = (ub != Inf); - globals.ub = globals.ub(tmp_idx, 1); + ub = ub(:); + ub_idx(:) = (ub != Inf); + globals.ub = ub(ub_idx, 1); ub_grad = ub_grad(ub_idx, :); - elseif (isempty (ub)) - if (isa (x0, "single")) - globals.ub = tmp_ub = realmax ("single"); - else - globals.ub = tmp_ub = realmax (); - endif else error ("sqp: invalid upper bound"); endif - if (any (tmp_lb > tmp_ub)) + if (any (globals.lb > globals.ub)) error ("sqp: upper bound smaller than lower bound"); endif bounds_grad = [lb_grad; ub_grad]; @@ -705,15 +710,32 @@ function res = cf_ub_lb (x, lbidx, ubidx, globals) + ## function returning constraint evaluated at x, and distance between ub/lb + ## and x, when they are specified (otherwise return empty) - ## combine constraint function with ub and lb - if (isempty (globals.cifcn)) - res = [x(lbidx,1)-globals.lb; globals.ub-x(ubidx,1)]; + ## inequality constraints + if (! isempty (globals.cifcn)) + ci = feval (globals.cifcn, x); + else + ci = []; + endif + + ## lower bounds + if (! isempty (globals.lb)) + lb = x(lbidx, 1) - globals.lb; else - res = [feval(globals.cifcn,x); x(lbidx,1)-globals.lb; - globals.ub-x(ubidx,1)]; + lb = []; endif + ## upper bounds + if (! isempty (globals.ub)) + ub = globals.ub - x(ubidx, 1); + else + ub = []; + end + + res = [ci; lb; ub]; + endfunction diff -r 17d568574e1c -r 7860fcc69082 scripts/plot/util/__check_rendering_capability__.m --- a/scripts/plot/util/__check_rendering_capability__.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/plot/util/__check_rendering_capability__.m Mon Jan 30 18:36:03 2023 +0100 @@ -35,21 +35,12 @@ endif toolkit = get (fig, "__graphics_toolkit__"); - display = getenv ("DISPLAY"); - if (! strcmp (toolkit, "qt")) - error ("%s: rendering with %s toolkit requires visible figure (DISPLAY='%s')", - who, toolkit, display); - endif - - gl_window = get (fig, "__gl_window__"); - qt_offscreen = __have_feature__ ("QT_OFFSCREEN"); - - if (strcmp (gl_window, "on") || qt_offscreen) + if (strcmp (toolkit, "qt")) return; endif - error ("%s: offscreen rendering with %s toolkit requires __gl_window__='on' or QT_OFFSCREEN feature (__gl_window__='%s'; QT_OFFSCREEN=%d, DISPLAY='%s')", - who, toolkit, gl_window, qt_offscreen, display); + error ("%s: rendering with %s toolkit requires visible figure (DISPLAY='%s')", + who, toolkit, getenv ("DISPLAY")); endfunction diff -r 17d568574e1c -r 7860fcc69082 scripts/plot/util/__pltopt__.m --- a/scripts/plot/util/__pltopt__.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/plot/util/__pltopt__.m Mon Jan 30 18:36:03 2023 +0100 @@ -158,12 +158,6 @@ topt = opt(1); n = 1; - if (any (topt == "0":"6")) - warning ("Octave:deprecated-option", ... - ["%s: using numbers to select line colors is deprecated. ", ... - "Use the corresponding color identifier instead."], caller); - endif - ## LineStyles if (strncmp (opt, "--", 2) || strncmp (opt, "-.", 2)) options.linestyle = opt(1:2); @@ -195,20 +189,19 @@ topt = "+"; endif options.marker = topt; - ## Numeric color specs are for backward compatibility. Don't document. - elseif (topt == "k" || topt == "0") + elseif (topt == "k") options.color = [0, 0, 0]; - elseif (topt == "r" || topt == "1") + elseif (topt == "r") if (strncmp (opt, "red", 3)) n = 3; endif options.color = [1, 0, 0]; - elseif (topt == "g" || topt == "2") + elseif (topt == "g") if (strncmp (opt, "green", 5)) n = 5; endif options.color = [0, 1, 0]; - elseif (topt == "b" || topt == "3") + elseif (topt == "b") if (strncmp (opt, "black", 5)) options.color = [0, 0, 0]; n = 5; @@ -223,17 +216,17 @@ n = 6; endif options.color = [1, 1, 0]; - elseif (topt == "m" || topt == "4") + elseif (topt == "m") if (strncmp (opt, "magenta", 7)) n = 7; endif options.color = [1, 0, 1]; - elseif (topt == "c" || topt == "5") + elseif (topt == "c") if (strncmp (opt, "cyan", 4)) n = 4; endif options.color = [0, 1, 1]; - elseif (topt == "w" || topt == "6") + elseif (topt == "w") if (strncmp (opt, "white", 5)) n = 5; endif diff -r 17d568574e1c -r 7860fcc69082 scripts/plot/util/copyobj.m --- a/scripts/plot/util/copyobj.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/plot/util/copyobj.m Mon Jan 30 18:36:03 2023 +0100 @@ -203,7 +203,7 @@ %! set (hnew, "position", [scrn(3)/2, scrn(4)/2-pos(4)/2, pos(3:4)]); %! drawnow (); -%!testif HAVE_MAGICK; (have_window_system () && __have_feature__ ("QT_OFFSCREEN") && any (strcmp ("qt", available_graphics_toolkits ()))); +%!testif HAVE_MAGICK; (have_window_system () && any (strcmp ("qt", available_graphics_toolkits ()))); %! toolkit = graphics_toolkit (); %! graphics_toolkit ("qt"); %! unwind_protect diff -r 17d568574e1c -r 7860fcc69082 scripts/plot/util/hgsave.m --- a/scripts/plot/util/hgsave.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/plot/util/hgsave.m Mon Jan 30 18:36:03 2023 +0100 @@ -90,7 +90,7 @@ endfunction -%!testif HAVE_MAGICK; (have_window_system () && __have_feature__ ("QT_OFFSCREEN") && any (strcmp ("qt", available_graphics_toolkits ()))); +%!testif HAVE_MAGICK; (have_window_system () && any (strcmp ("qt", available_graphics_toolkits ()))); %! toolkit = graphics_toolkit (); %! graphics_toolkit ("qt"); %! h1 = figure ("visible", "off", "paperposition", [0.25, 2.5, 8.0, 6.0]); diff -r 17d568574e1c -r 7860fcc69082 scripts/plot/util/private/__print_parse_opts__.m --- a/scripts/plot/util/private/__print_parse_opts__.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/plot/util/private/__print_parse_opts__.m Mon Jan 30 18:36:03 2023 +0100 @@ -234,7 +234,7 @@ if (any (strcmp (unsupported, arg_st.devopt))) warning ('Octave:print:deprecated-format', - 'print: "%s" format is no more officially supported', ... + 'print: "%s" format is no longer officially supported', arg_st.devopt); endif diff -r 17d568574e1c -r 7860fcc69082 scripts/strings/isstring.m --- a/scripts/strings/isstring.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/strings/isstring.m Mon Jan 30 18:36:03 2023 +0100 @@ -46,7 +46,7 @@ print_usage (); endif - tf = false; + tf = isa (s, 'string'); endfunction @@ -60,4 +60,3 @@ %!assert (isstring ({"b"}), false) %!error isstring () -%!error isstring ("a", "b") diff -r 17d568574e1c -r 7860fcc69082 scripts/testfun/assert.m --- a/scripts/testfun/assert.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/testfun/assert.m Mon Jan 30 18:36:03 2023 +0100 @@ -128,7 +128,7 @@ if (ischar (expected)) if (! ischar (cond)) err.index{end+1} = "."; - err.expected{end+1} = expected; + err.expected{end+1} = ["'" expected "'"]; if (isnumeric (cond)) err.observed{end+1} = num2str (cond); err.reason{end+1} = "Expected string, but observed number"; @@ -138,8 +138,8 @@ endif elseif (! strcmp (cond, expected)) err.index{end+1} = "[]"; - err.observed{end+1} = cond; - err.expected{end+1} = expected; + err.observed{end+1} = ["'" cond "'"]; + err.expected{end+1} = ["'" expected "'"]; err.reason{end+1} = "Strings don't match"; endif diff -r 17d568574e1c -r 7860fcc69082 scripts/testfun/oruntests.m --- a/scripts/testfun/oruntests.m Mon Jan 30 18:30:33 2023 +0100 +++ b/scripts/testfun/oruntests.m Mon Jan 30 18:36:03 2023 +0100 @@ -71,29 +71,34 @@ no_tests = {}; printf ("Processing files in %s:\n\n", directory); fflush (stdout); - for i = 1:numel (flist) - f = flist{i}; - if ((length (f) > 2 && strcmpi (f((end-1):end), ".m")) - || (length (f) > 3 && strcmpi (f((end-2):end), ".cc"))) - ff = fullfile (directory, f); - if (! isfile (ff)) - continue; + unwind_protect + old_dir = cd (directory); + for i = 1:numel (flist) + f = flist{i}; + if ((length (f) > 2 && strcmpi (f((end-1):end), ".m")) + || (length (f) > 3 && strcmpi (f((end-2):end), ".cc"))) + ff = fullfile (directory, f); + if (! isfile (ff)) + continue; + endif + if (has_tests (ff)) + print_test_file_name (f); + [p, n, xf, xb, sk, rtsk, rgrs] = test (ff, "quiet"); + print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs); + fflush (stdout); + elseif (has_functions (ff)) + no_tests(end+1) = f; + endif + elseif (f(1) == "@") + f = fullfile (directory, f); + if (isfolder (f)) + dirs(end+1) = f; + endif endif - if (has_tests (ff)) - print_test_file_name (f); - [p, n, xf, xb, sk, rtsk, rgrs] = test (ff, "quiet"); - print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs); - fflush (stdout); - elseif (has_functions (ff)) - no_tests(end+1) = f; - endif - elseif (f(1) == "@") - f = fullfile (directory, f); - if (isfolder (f)) - dirs(end+1) = f; - endif - endif - endfor + endfor + unwind_protect_cleanup + cd (old_dir); + end_unwind_protect if (! isempty (no_tests)) printf ("\nThe following files in %s have no tests:\n\n", directory); printf ("%s", list_in_columns (no_tests)); diff -r 17d568574e1c -r 7860fcc69082 src/main-cli.cc --- a/src/main-cli.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/src/main-cli.cc Mon Jan 30 18:36:03 2023 +0100 @@ -52,7 +52,7 @@ #include "sysdep.h" static void -check_hg_versions (void) +check_hg_versions () { bool ok = true; diff -r 17d568574e1c -r 7860fcc69082 src/main-gui.cc --- a/src/main-gui.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/src/main-gui.cc Mon Jan 30 18:36:03 2023 +0100 @@ -52,9 +52,10 @@ #include "octave-build-info.h" #include "qt-application.h" #include "sysdep.h" +#include "version.h" static void -check_hg_versions (void) +check_hg_versions () { bool ok = true; @@ -143,7 +144,8 @@ octave::sys::env::set_program_name (argv[0]); - octave::qt_application app (argc, argv); + octave::qt_application app ("octave", "octave-gui", OCTAVE_VERSION, + argc, argv); int ret = app.execute (); diff -r 17d568574e1c -r 7860fcc69082 src/main.in.cc --- a/src/main.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/src/main.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -111,7 +111,7 @@ } static void -install_signal_handlers (void) +install_signal_handlers () { // FIXME: do we need to handle and forward all the signals that Octave // handles, or is it sufficient to only forward things like SIGINT, @@ -169,7 +169,7 @@ } static std::string -get_octave_bindir (void) +get_octave_bindir () { // Accept value from the environment literally, but substitute // OCTAVE_HOME in the configuration value OCTAVE_BINDIR in case Octave @@ -183,7 +183,7 @@ } static std::string -get_octave_archlibdir (void) +get_octave_archlibdir () { // Accept value from the environment literally, but substitute // OCTAVE_HOME in the configuration value OCTAVE_ARCHLIBDIR in case diff -r 17d568574e1c -r 7860fcc69082 src/mkoctfile.in.cc --- a/src/mkoctfile.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/src/mkoctfile.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -356,11 +356,6 @@ vars["LD_STATIC_FLAG"] = get_variable ("LD_STATIC_FLAG", %OCTAVE_CONF_LD_STATIC_FLAG%); - // FIXME: Remove LFLAGS in Octave 9 - vars["LFLAGS"] = get_variable ("LFLAGS", DEFAULT_LDFLAGS); - if (vars["LFLAGS"] != DEFAULT_LDFLAGS) - std::cerr << "mkoctfile: warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead" << std::endl; - vars["F77_INTEGER8_FLAG"] = get_variable ("F77_INTEGER8_FLAG", %OCTAVE_CONF_F77_INTEGER_8_FLAG%); vars["ALL_FFLAGS"] = vars["FFLAGS"] + ' ' + vars["F77_INTEGER8_FLAG"]; @@ -608,7 +603,7 @@ } static std::string -get_temp_directory (void) +get_temp_directory () { std::string tempd; @@ -648,7 +643,7 @@ } static std::string -create_interleaved_complex_file (void) +create_interleaved_complex_file () { std::string tmpl = get_temp_directory () + "/oct-XXXXXX.c"; @@ -674,7 +669,7 @@ } static std::string -tmp_objfile_name (void) +tmp_objfile_name () { std::string tmpl = get_temp_directory () + "/oct-XXXXXX.o"; @@ -888,10 +883,6 @@ { ++i; - // FIXME: Remove LFLAGS checking in Octave 9 - if (argv[i] == "LFLAGS") - std::cerr << "mkoctfile: warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead" << std::endl; - if (! var_to_print.empty ()) std::cerr << "mkoctfile: warning: only one '" << arg << "' option will be processed" << std::endl; @@ -1317,13 +1308,12 @@ octave_libs = "-L" + quote_path (vars["OCTLIBDIR"]) + ' ' + vars["OCTAVE_LIBS"]; - // FIXME: Remove LFLAGS in Octave 9 std::string cmd = (vars["CXXLD"] + ' ' + vars["CPPFLAGS"] + ' ' + vars["ALL_CXXFLAGS"] + ' ' + vars["RDYNAMIC_FLAG"] + ' ' + pass_on_options + ' ' + output_option + ' ' + objfiles + ' ' + libfiles + ' ' + ldflags + ' ' + vars["ALL_LDFLAGS"] + ' ' - + vars["LFLAGS"] + ' ' + octave_libs + ' ' + + octave_libs + ' ' + vars["OCTAVE_LINK_OPTS"] + ' ' + vars["OCTAVE_LINK_DEPS"]); int status = run_command (cmd, verbose, printonly); @@ -1348,12 +1338,11 @@ + ' ' + vars["OCTAVE_LIBS"]; #endif - // FIXME: Remove LFLAGS in Octave 9 std::string cmd = (vars["CXXLD"] + ' ' + vars["ALL_CXXFLAGS"] + ' ' + pass_on_options + " -o " + octfile + ' ' + objfiles + ' ' + libfiles + ' ' + ldflags + ' ' + vars["DL_LDFLAGS"] + ' ' - + vars["LDFLAGS"] + ' ' + vars["LFLAGS"] + ' ' + octave_libs + ' ' + + vars["LDFLAGS"] + ' ' + octave_libs + ' ' + vars["OCT_LINK_OPTS"] + ' ' + vars["OCT_LINK_DEPS"]); #if defined (OCTAVE_USE_WINDOWS_API) || defined(CROSS) diff -r 17d568574e1c -r 7860fcc69082 src/octave-build-info.h --- a/src/octave-build-info.h Mon Jan 30 18:30:33 2023 +0100 +++ b/src/octave-build-info.h Mon Jan 30 18:36:03 2023 +0100 @@ -30,6 +30,6 @@ #include -extern std::string octave_hg_id (void); +extern std::string octave_hg_id (); #endif diff -r 17d568574e1c -r 7860fcc69082 src/octave-build-info.in.cc --- a/src/octave-build-info.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/src/octave-build-info.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -32,7 +32,7 @@ #include "octave-build-info.h" std::string -octave_hg_id (void) +octave_hg_id () { return "%OCTAVE_HG_ID%"; } diff -r 17d568574e1c -r 7860fcc69082 src/octave-config.in.cc --- a/src/octave-config.in.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/src/octave-config.in.cc Mon Jan 30 18:36:03 2023 +0100 @@ -99,7 +99,7 @@ "\n"; static void -initialize (void) +initialize () { set_octave_home (); diff -r 17d568574e1c -r 7860fcc69082 src/octave-svgconvert.cc --- a/src/octave-svgconvert.cc Mon Jan 30 18:30:33 2023 +0100 +++ b/src/octave-svgconvert.cc Mon Jan 30 18:36:03 2023 +0100 @@ -61,20 +61,16 @@ m_printer.setFontEmbeddingEnabled (true); m_printer.setOutputFileName (fname); m_printer.setFullPage (true); -#if defined (HAVE_QPRINTER_SETPAGESIZE) m_printer.setPageSize (QPageSize (sz.size (), QPageSize::Point, QString ("custom"), QPageSize::ExactMatch)); -#else - m_printer.setPaperSize (sz.size (), QPrinter::Point); -#endif // Painter settings begin (&m_printer); setWindow (sz.toRect ()); } - ~pdfpainter (void) { end (); } + ~pdfpainter () { end (); } private: QPrinter m_printer; @@ -151,21 +147,21 @@ class octave_polygon { public: - octave_polygon (void) + octave_polygon () { } octave_polygon (QPolygonF p) { m_polygons.push_back (p); } - ~octave_polygon (void) { } + ~octave_polygon () { } - int count (void) const + int count () const { return m_polygons.count (); } - void reset (void) + void reset () { m_polygons.clear (); } - QList reconstruct (void) + QList reconstruct () { if (m_polygons.isEmpty ()) return QList (); diff -r 17d568574e1c -r 7860fcc69082 src/shared-fcns.h --- a/src/shared-fcns.h Mon Jan 30 18:30:33 2023 +0100 +++ b/src/shared-fcns.h Mon Jan 30 18:36:03 2023 +0100 @@ -45,7 +45,7 @@ # endif static std::string -w32_get_octave_home (void) +w32_get_octave_home () { std::string retval; @@ -108,7 +108,7 @@ static std::string Voctave_exec_home; static void -set_octave_home (void) +set_octave_home () { std::string op = OCTAVE_PREFIX; std::string oep = OCTAVE_EXEC_PREFIX; diff -r 17d568574e1c -r 7860fcc69082 test/bug-48693/bug-48693.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-48693/bug-48693.tst Mon Jan 30 18:36:03 2023 +0100 @@ -0,0 +1,3 @@ +%!test +%! x = bug48693(); +%! assert ({x{1:10}}, num2cell (zeros(1,10))) diff -r 17d568574e1c -r 7860fcc69082 test/bug-48693/bug48693.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-48693/bug48693.m Mon Jan 30 18:36:03 2023 +0100 @@ -0,0 +1,7 @@ +classdef bug48693 < handle + methods + function varargout = subsref (x, idx) + varargout = num2cell (zeros (size (idx(1).subs{1}))); + end + end +end diff -r 17d568574e1c -r 7860fcc69082 test/bug-48693/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-48693/module.mk Mon Jan 30 18:36:03 2023 +0100 @@ -0,0 +1,5 @@ +bug_48693_TEST_FILES = \ + %reldir%/bug48693.m \ + %reldir%/bug-48693.tst + +TEST_FILES += $(bug_48693_TEST_FILES) diff -r 17d568574e1c -r 7860fcc69082 test/io.tst --- a/test/io.tst Mon Jan 30 18:30:33 2023 +0100 +++ b/test/io.tst Mon Jan 30 18:36:03 2023 +0100 @@ -297,6 +297,118 @@ %!assert (sscanf ('0177 08', '%i'), [127; 0; 8]) %!assert (sscanf ('0177 08', '%d'), [177; 8]) +## Extensive testing of '%c' +%!test +%! [val, cnt, msg, pos] = sscanf ('abcde', '%c'); +%! assert (val, 'abcde'); +%! assert (cnt, 5); +%! assert (msg, ''); +%! assert (pos, 6); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%10c'); +%! assert (val, 'abcde'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 6); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%3c'); +%! assert (val, 'abcde'); +%! assert (cnt, 2); +%! assert (msg, ''); +%! assert (pos, 6); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%3c', 1); +%! assert (val, 'abc'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 4); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%c', 5); +%! assert (val, 'abcde'); +%! assert (cnt, 5); +%! assert (msg, ''); +%! assert (pos, 6); + +## Extensive testing of '%s' +%!test +%! [val, cnt, msg, pos] = sscanf ('abcde', '%s'); +%! assert (val, 'abcde'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 6); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%10s'); +%! assert (val, 'abcde'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 6); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%3s'); +%! assert (val, 'abcde'); +%! assert (cnt, 2); +%! assert (msg, ''); +%! assert (pos, 6); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%3s', 1); +%! assert (val, 'abc'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 4); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%1s', 5); +%! assert (val, 'abcde'); +%! assert (cnt, 5); +%! assert (msg, ''); +%! assert (pos, 6); + +## Extensive testing of '%[]' +%!test +%! [val, cnt, msg, pos] = sscanf ('abcde', '%[a-c]'); +%! assert (val, 'abc'); +%! assert (cnt, 1); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 4); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%10[a-c]'); +%! assert (val, 'abc'); +%! assert (cnt, 1); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 4); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%2[a-c]'); +%! assert (val, 'abc'); +%! assert (cnt, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 4); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%2[a-c]', 1); +%! assert (val, 'ab'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 3); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%[a-c]', 1); +%! assert (val, 'abc'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 4); + +## Extensive testing of '%[^]' +%!test +%! [val, cnt, msg, pos] = sscanf ('abcde', '%[^de]'); +%! assert (val, 'abc'); +%! assert (cnt, 1); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 4); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%10[^de]'); +%! assert (val, 'abc'); +%! assert (cnt, 1); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 4); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%2[^de]'); +%! assert (val, 'abc'); +%! assert (cnt, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 4); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%2[^de]', 1); +%! assert (val, 'ab'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 3); +%! [val, cnt, msg, pos] = sscanf ('abcde', '%[^de]', 1); +%! assert (val, 'abc'); +%! assert (cnt, 1); +%! assert (msg, ''); +%! assert (pos, 4); + ## bug #47741 %!assert (sscanf ('2147483647', '%d'), 2147483647) %!assert (sscanf ('2147483647', '%i'), 2147483647) @@ -389,10 +501,169 @@ %!test <*62723> %! [val, count, msg, pos] = sscanf ("p", "%c"); -%! assert (val, "p"); +%! assert (val, 'p'); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 2); + +%!test <*62723> +%! [val, count, msg, pos] = sscanf (' ,1 ', ' %s ', 1); +%! assert (val, ',1'); %! assert (count, 1); -%! assert (msg, ""); -%! assert (pos, 2); +%! assert (msg, ''); +%! assert (pos, 5); + +## Test NaN at EOF +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('2 3 n', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 na', '%f'); +%! assert (val, [2; 3; NA]); +%! assert (count, 3); +%! assert (msg, ''); +%! assert (pos, 7); +%! [val, count, msg, pos] = sscanf ('2 3 nan', '%f'); +%! assert (val, [2; 3; NaN]); +%! assert (count, 3); +%! assert (msg, ''); +%! assert (pos, 8); + +## Test NaN within string +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('2 3 n 4', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 na 4', '%f'); +%! assert (val, [2; 3; NA; 4]); +%! assert (count, 4); +%! assert (msg, ''); +%! assert (pos, 9); +%! [val, count, msg, pos] = sscanf ('2 3 nan 4', '%f'); +%! assert (val, [2; 3; NaN; 4]); +%! assert (count, 4); +%! assert (msg, ''); +%! assert (pos, 10); + +## Test Inf at EOF +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('2 3 i', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 in', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 inf', '%f'); +%! assert (val, [2; 3; Inf]); +%! assert (count, 3); +%! assert (msg, ''); +%! assert (pos, 8); + +## Test Inf within string +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('2 3 i 4', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 in 4', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 inf 4', '%f'); +%! assert (val, [2; 3; Inf; 4]); +%! assert (count, 4); +%! assert (msg, ''); +%! assert (pos, 10); + +## Test '-' at EOF +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('2 3 -', '%d'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 -', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); + +## Test '-' within string +%!test <63383> +%! [val, count, msg, pos] = sscanf ('1 2 - 3', '%d'); +%! assert (val, [1; 2]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('1 2 - 3', '%f'); +%! assert (val, [1; 2]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); + +## Test '+' at EOF +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('2 3 +', '%d'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('2 3 +', '%f'); +%! assert (val, [2; 3]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); + +## Test '+' within string +%!test <63383> +%! [val, count, msg, pos] = sscanf ('1 2 + 3', '%d'); +%! assert (val, [1; 2]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('1 2 + 3', '%f'); +%! assert (val, [1; 2]); +%! assert (count, 2); +%! assert (msg, 'sscanf: format failed to match'); +%! assert (pos, 5); + +%## Test +NA, -NA, +NAN, -NAN +%!test <*63383> +%! [val, count, msg, pos] = sscanf ('+NA -NA 1 +NAN -NAN', '%f'); +%! assert (val, [NA; NA; 1; NaN; NaN]); +%! assert (count, 5); +%! assert (msg, ''); +%! assert (pos, 20); +%! [val, count, msg, pos] = sscanf ('-NA', '%f'); +%! assert (val, NA); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 4); +%! [val, count, msg, pos] = sscanf ('+NA', '%f'); +%! assert (val, NA); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 4); +%! [val, count, msg, pos] = sscanf ('-NaN', '%f'); +%! assert (val, NaN); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 5); +%! [val, count, msg, pos] = sscanf ('+NaN', '%f'); +%! assert (val, NaN); +%! assert (count, 1); +%! assert (msg, ''); +%! assert (pos, 5); %!test %! [a, b, c] = sscanf ("1.2 3 foo", "%f%d%s", "C"); @@ -403,14 +674,16 @@ %! && v1 == [1; 2; 3; 4; 5; 6] && c1 == 6 && ischar (m1) %! && v2 == [1; 2] && c2 == 2 && ischar (m2))); -%!error sscanf () -%!error sscanf (1, 2) -%!error sscanf ("foo", "bar", "C", 1) - %!test %! [x, n] = sscanf (" 0.024000 0.200 0.200 2.000 1987 5 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 2 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 4 5 1 2 2 5 5 8 2 8 12 6 15 18 28 26 47 88 118 162 192 130 88 56 27 23 14 9 6 3 4 1 0 2 3 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0.026000 0.250 0.250 2.100 3115 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 1 0 1 1 1 0 1 0 1 3 2 0 5 15 25 44 66 145 179 193 172 104 57 17 11 12 2 1 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.028000 0.300 0.300 2.200 4929 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 2 2 3 2 3 14 21 49 80 148 184 218 159 124 63 37 13 12 3 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.030000 0.350 0.350 2.300 7051 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 2 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 2 0 0 0 1 5 6 14 28 51 88 154 177 208 169 124 65 39 15 5 3 3 2 1 0 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.032000 0.400 0.400 2.400 9113 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 2 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 2 0 1 0 0 1 1 0 2 3 5 3 17 30 60 117 156 189 209 129 102 64 56 16 11 4 2 2 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0.034000 0.450 0.450 2.500 11811 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 2 1 0 0 1 0 5 5 15 21 57 99 149 190 195 159 130 69 41 16 10 2 5 3 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.036000 0.500 0.500 2.600 14985 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 2 2 6 10 34 60 95 126 177 194 155 99 71 44 17 6 7 2 0 0 0 3 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.038000 0.550 0.550 2.700 18391 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 2 0 0 1 1 0 1 2 1 0 0 0 1 0 1 3 6 19 27 52 95 161 154 169 134 94 64 37 19 9 6 0 2 1 0 0 0 0 1 2 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 2 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.040000 0.600 0.600 2.800 22933 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 2 0 3 4 7 18 27 47 82 134 163 133 138 101 58 34 26 10 5 2 1 2 1 1 0 2 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0.042000 0.650 0.650 2.900 27719 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 2 8 16 37 51 87 128 153 146 123 105 62 35 24 8 3 5 0 1 2 1 0 0 0 1 1 1 0 0 0 1 0 1 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.044000 0.700 0.700 3.000 32922 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 2 0 0 0 0 0 0 0 0 2 1 0 0 0 0 1 1 1 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 1 1 1 0 0 0 1 4 3 5 5 15 35 54 88 132 168 149 105 92 62 30 16 17 4 5 1 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.046000 0.750 0.750 3.100 38973 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 4 3 5 20 37 56 94 110 135 149 124 84 58 36 17 14 7 1 0 2 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.048000 0.800 0.800 3.200 45376 5 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 1 1 0 0 2 1 1 2 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 3 18 34 55 82 104 135 116 99 79 60 51 29 10 4 3 1 1 1 0 0 1 0 0 0 1 0 0 3 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.050000 0.850 0.850 3.300 52060 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 2 2 1 3 12 24 40 39 107 121 127 138 100 86 68 44 23 15 7 3 1 1 0 1 1 0 0 2 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0 2 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.052000 0.900 0.900 3.400 59454 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 2 0 2 1 0 0 0 1 0 0 1 0 0 0 0 0 3 3 6 21 32 68 90 132 111 122 107 73 57 47 24 11 7 4 2 2 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 2 0 1 1 0 0 1 0 0 0 0 0 3 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0.054000 0.950 0.950 3.500 67013 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 2 4 3 7 9 28 31 71 94 115 96 108 78 82 60 38 17 12 11 4 3 1 1 0 2 1 0 0 0 2 1 3 0 0 0 0 3 0 0 1 0 0 0 0 0 0 0 2 0 0 0 1 0 2 0 1 0 2 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0.056000 1.000 1.000 3.600 75475 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 3 0 0 1 1 2 0 1 4 0 1 8 6 7 17 41 56 71 109 113 84 103 72 54 35 22 6 9 1 7 5 4 0 0 1 0 0 0 0 0 0 1 0 0 2 1 0 0 0 0 2 0 0 1 0 0 1 0 0 0 0 0 0 1 0 2 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 3 0 0 0 1 0 0 0 0 0 0 1 1 0 0 2 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0.058000 1.050 1.050 3.700 83558 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 1 2 0 0 2 0 0 1 0 3 2 3 6 15 27 41 77 73 94 94 92 76 61 56 42 23 13 11 6 2 1 2 0 1 2 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 2 0 0 0 0 0 1 2 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0.060000 1.100 1.100 3.800 93087 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 2 2 0 0 0 1 0 1 1 0 0 0 1 1 0 4 0 0 1 2 0 3 1 3 5 13 33 31 65 75 77 96 97 80 59 45 36 32 18 2 5 0 1 0 0 1 0 0 3 0 0 0 0 1 0 0 0 0 0 1 0 0 1 2 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 2 0 0 2 0 1 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.062000 1.150 1.150 3.900 102829 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 1 1 1 0 1 0 1 1 0 1 1 0 2 0 2 1 2 0 0 2 4 3 5 11 9 23 43 53 68 65 87 83 77 59 49 34 18 15 9 4 2 3 2 0 0 0 4 0 1 1 0 0 2 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 2 0 0 0 0 1 0 0 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0.064000 1.200 1.200 4.000 113442 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 1 0 0 0 1 2 0 0 0 2 0 4 5 11 13 29 39 61 68 61 75 76 74 73 44 37 29 19 6 3 3 2 0 1 2 1 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 2 0 2 1 1 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0.066000 1.250 1.250 4.100 126668 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 1 2 3 0 2 1 2 0 1 0 3 0 0 0 1 0 1 1 3 0 0 1 3 0 2 4 3 12 12 30 48 56 66 77 78 71 82 52 31 32 19 20 16 8 2 1 3 0 0 2 1 0 1 0 1 0 0 0 1 3 1 0 1 0 1 1 1 0 0 0 0 0 2 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 2 0 3 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.068000 1.300 1.300 4.200 138042 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 2 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 2 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 3 0 0 1 0 0 1 2 0 0 0 3 0 1 0 0 3 0 1 0 1 1 3 1 4 7 11 14 27 36 44 68 72 70 71 45 44 46 29 13 16 11 5 2 0 3 0 0 0 0 1 1 2 0 0 1 1 2 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 2 0 0 1 1 0 1 1 1 0 0 1 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.070000 1.350 1.350 4.300 152335 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 2 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 2 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 2 0 0 0 0 1 1 1 0 1 1 0 1 1 1 1 0 2 0 0 0 0 0 2 0 1 7 14 19 34 35 54 72 68 72 68 58 48 36 37 27 25 17 1 4 1 0 0 0 1 2 2 0 0 1 1 1 2 1 0 3 1 0 1 0 2 1 0 0 0 1 1 1 2 0 0 0 0 1 1 0 1 1 0 2 1 1 1 1 0 0 0 1 1 0 0 2 0 0 1 0 0 0 1 1 0 2 1 1 0 0 0 0 2 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0.072000 1.400 1.400 4.400 166280 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 0 1 0 1 1 1 0 0 1 0 1 0 0 3 4 2 2 0 0 0 0 0 1 1 3 1 0 3 2 2 1 2 2 0 2 2 1 8 14 26 24 29 47 47 68 65 63 55 42 41 26 29 17 8 4 4 1 0 1 2 0 0 0 1 1 2 0 1 2 1 0 0 1 1 1 0 0 1 0 0 0 1 0 0 1 2 1 2 1 0 0 0 0 0 1 1 2 0 2 2 0 0 0 0 1 1 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0.074000 1.450 1.450 4.500 179484 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 1 0 1 0 0 1 0 1 2 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 2 0 0 1 1 2 1 0 1 1 2 2 0 1 5 6 10 20 43 50 57 62 53 62 66 45 42 33 27 26 23 14 3 0 2 0 1 0 0 1 1 0 0 2 1 1 0 0 3 0 1 1 1 0 1 1 0 1 0 1 2 1 0 0 1 2 0 2 0 0 0 0 1 1 3 1 0 0 2 1 1 1 0 0 0 0 0 0 1 2 0 1 0 0 0 0 0 1 1 0 2 0 0 0 0 0 1 0 2 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0.076000 1.500 1.500 4.600 197657 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 2 0 0 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 2 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 2 0 0 0 2 1 1 0 1 1 0 1 1 3 2 1 1 2 1 0 1 0 0 0 0 0 1 1 1 0 5 3 7 12 24 38 32 41 48 54 66 71 49 46 31 38 25 15 8 6 6 5 0 1 3 0 1 1 1 1 1 0 1 2 0 1 0 0 0 1 0 2 1 2 0 0 0 0 1 3 1 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 4 1 1 1 0 3 0 0 0 2 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0.078000 1.550 1.550 4.700 212054 3 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 2 0 0 0 1 0 0 1 0 1 1 0 1 3 1 0 0 1 2 0 0 0 1 0 0 0 0 0 2 1 2 1 1 1 0 0 1 5 1 1 2 3 5 7 9 11 22 31 37 48 50 52 54 57 37 38 38 33 24 11 19 11 3 1 2 0 3 3 2 1 0 1 3 0 1 1 1 1 1 2 0 0 0 1 1 2 0 1 1 3 0 1 1 0 0 1 0 2 0 1 0 0 1 3 0 2 0 1 0 1 2 0 1 1 1 1 1 0 3 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0.080000 1.600 1.600 4.800 231971 3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 2 0 0 0 1 1 1 0 1 0 0 0 0 1 0 1 1 0 0 0 0 2 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 2 1 0 1 1 1 0 1 0 0 1 0 1 3 0 0 0 1 0 0 0 1 1 1 0 0 4 1 1 0 2 0 1 1 1 2 0 0 0 1 0 1 2 1 2 3 2 0 1 0 4 3 1 1 1 1 3 1 0 0 0 2 1 0 2 7 17 13 29 47 58 59 52 38 51 51 38 34 35 21 14 13 4 1 0 1 1 1 0 2 2 4 1 0 1 1 4 0 0 0 2 0 2 2 2 0 0 1 3 2 1 1 2 2 2 2 1 0 3 0 2 1 2 1 2 2 0 0 1 1 0 2 0 2 2 0 1 0 2 2 3 1 2 3 1 1 0 1 0 2 0 1 2 1 2 0 2 1 0 0 3 0 0 1 1 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0.082000 1.650 1.650 4.900 252503 3 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 2 0 0 1 0 1 2 2 2 1 0 2 0 1 0 1 1 2 2 0 3 0 0 4 1 0 0 3 0 0 1 2 0 1 1 1 3 0 1 0 2 9 11 25 27 34 53 41 49 43 47 36 31 38 22 30 22 18 9 5 9 2 2 1 2 2 3 1 4 1 1 0 0 1 2 0 2 1 0 0 1 3 2 2 1 0 0 0 1 2 1 0 0 0 2 1 1 0 2 0 0 1 0 0 2 1 3 1 1 1 0 2 1 1 0 2 1 0 1 3 0 0 0 0 2 0 0 1 0 0 0 0 0 1 2 1 1 1 0 2 1 0 0 0 2 0 1 0 0 0 0 1 0 0 0 0 1 0 0 2 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0.084000 1.700 1.700 5.000 267889 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 0 3 0 1 1 1 0 1 2 1 0 2 0 2 4 0 1 0 0 0 1 1 0 1 3 2 0 2 0 4 0 0 2 0 1 4 2 4 3 3 6 10 14 28 37 54 36 40 52 40 50 46 40 32 26 29 12 18 5 2 0 2 4 1 2 1 0 2 1 2 2 1 0 1 0 2 1 2 4 1 1 5 1 0 2 0 1 2 3 2 2 1 2 1 0 2 1 2 1 1 4 1 2 1 4 0 2 2 0 0 3 1 0 2 0 0 1 1 1 0 0 2 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0.086000 1.750 1.750 5.100 290294 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 2 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 3 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 2 1 0 1 0 1 0 0 2 2 0 1 2 2 0 2 0 2 0 1 0 0 1 1 1 3 1 1 1 1 3 4 1 1 2 2 2 1 0 3 0 0 0 2 4 5 6 16 18 20 31 40 54 55 46 41 52 35 27 21 28 27 20 15 8 6 7 1 0 0 3 0 0 2 2 0 3 1 3 1 1 2 0 0 1 2 1 3 2 0 1 2 1 3 1 1 1 1 1 2 0 2 1 0 1 1 1 3 1 1 2 0 1 0 1 0 2 1 1 0 0 1 2 0 3 1 1 0 0 0 1 3 1 1 1 0 0 1 2 1 0 0 1 1 1 0 0 1 0 0 0 0 0 0 2 0 1 0 0 0 2 1 0 2 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0.088000 1.800 1.800 5.200 312476 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 2 0 0 0 1 0 1 0 0 0 0 0 0 2 1 0 0 1 0 0 1 1 1 1 4 2 0 1 0 0 3 0 0 0 0 0 1 1 4 0 0 0 0 1 1 2 1 0 3 0 0 2 2 4 0 3 1 6 9 10 13 21 24 32 43 33 41 43 49 50 32 26 31 27 12 16 17 3 3 3 5 0 3 0 2 1 3 3 2 1 2 3 1 2 1 1 1 2 0 1 1 0 2 0 3 0 0 2 0 0 0 0 1 0 1 1 3 3 0 1 1 1 1 1 1 2 2 2 0 3 1 0 2 2 2 0 0 0 0 3 1 2 5 1 1 2 0 0 3 3 0 2 2 0 0 0 0 1 2 0 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0.090000 1.850 1.850 5.300 337348 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 2 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 2 0 1 1 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 2 0 0 0 1 3 2 0 0 2 2 3 3 2 2 2 0 0 1 1 3 1 3 0 0 0 0 0 0 1 2 1 2 1 2 2 2 0 1 1 0 4 2 2 7 6 15 22 21 39 37 50 31 51 30 33 34 34 26 21 14 13 10 9 4 3 3 4 2 2 0 1 2 3 3 0 1 3 2 5 3 2 2 4 0 2 3 0 4 2 1 2 2 2 4 2 1 3 1 3 2 1 3 1 2 4 1 1 1 1 2 4 1 3 3 3 1 0 4 1 0 1 1 1 1 2 3 0 3 0 0 4 1 1 1 0 2 2 2 1 2 2 0 1 1 0 0 0 2 0 1 0 1 0 0 1 0 0 0 1 3 0 0 1 0 0 1 1 1 0 0 1 0 0 0 0 0 0 0.092000 1.900 1.900 5.400 357303 3 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 1 3 1 0 1 0 0 0 0 1 0 0 1 0 0 1 1 2 2 0 0 2 2 1 1 1 1 1 1 0 1 0 0 1 1 1 3 1 1 1 1 1 0 1 4 0 1 1 1 3 0 1 1 2 2 2 0 2 3 2 2 2 2 1 2 1 3 8 22 14 32 36 46 39 42 39 29 36 38 26 24 26 18 16 19 10 9 3 6 5 0 3 2 1 1 1 2 0 2 1 1 0 1 1 3 1 0 2 4 2 2 1 4 1 2 2 1 1 0 1 2 0 2 2 2 4 2 1 1 0 2 1 3 1 2 3 4 2 3 2 3 0 1 2 1 0 0 0 4 1 1 1 2 1 3 1 0 5 1 0 0 0 0 0 0 1 0 2 0 1 2 1 0 1 0 0 0 0 0 1 1 0 1 0 1 4 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0.094000 1.950 1.950 5.500 383138 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 2 1 0 1 1 1 0 0 0 0 0 0 1 1 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 2 1 1 1 1 2 1 0 2 0 1 0 3 2 1 3 0 1 3 1 1 0 5 0 1 0 1 2 0 0 1 1 2 0 0 6 1 0 3 2 2 3 4 5 0 4 2 1 5 4 11 15 22 27 28 57 38 38 40 38 39 38 27 26 30 18 14 10 10 4 4 4 3 3 2 2 2 2 1 1 1 1 2 2 3 4 1 2 3 1 2 1 2 2 2 1 3 2 1 5 0 1 1 1 3 2 2 2 1 3 1 1 0 3 2 2 0 0 2 2 2 0 0 0 2 0 1 3 1 2 3 2 1 1 0 1 1 1 0 3 2 2 1 0 0 1 3 1 1 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 3 1 0 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 0 0.096000 2.000 2.000 5.600 409868 3 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 2 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 2 0 1 0 0 2 0 2 0 0 0 0 1 0 0 2 1 2 2 2 1 2 1 1 1 1 1 2 0 0 1 1 0 1 0 2 1 2 0 2 0 3 1 2 1 3 1 5 0 2 2 1 2 4 1 2 0 3 1 4 7 5 9 13 22 19 31 27 28 41 34 39 37 22 23 21 22 17 23 15 8 9 3 8 0 3 1 2 2 2 3 1 0 4 2 4 2 2 2 2 4 2 1 1 0 2 0 3 0 3 2 2 1 2 2 1 4 1 2 2 1 1 5 2 1 2 1 2 2 1 0 2 4 3 2 1 2 2 3 2 3 1 2 1 1 1 1 2 1 1 2 2 1 2 3 2 1 1 0 2 2 4 0 1 1 1 1 1 0 0 1 1 3 0 0 0 0 0 1 0 0 2 0 1 2 0 1 1 1 0 1 0 1 0 0 0.098000 2.050 2.050 5.700 439102 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 1 1 0 0 1 0 1 0 1 0 0 0 0 1 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 2 0 0 1 1 1 1 2 0 1 1 0 0 0 0 1 1 1 0 4 0 0 0 2 1 1 0 3 4 0 1 2 2 1 0 3 0 3 2 0 0 2 0 1 0 0 1 0 1 3 1 3 5 0 2 2 3 5 2 2 2 0 3 2 3 6 5 16 21 19 23 28 29 35 42 42 44 39 33 23 30 18 25 24 15 13 5 4 2 2 0 3 3 0 0 1 3 0 1 1 3 2 4 3 4 2 1 1 1 3 1 0 0 2 2 4 2 2 1 4 2 4 2 2 2 1 2 2 1 2 0 4 2 2 3 1 2 1 1 2 2 1 2 4 2 1 4 1 2 2 2 2 0 2 0 3 0 1 0 2 1 0 4 2 1 3 2 1 0 2 1 1 1 1 0 1 1 2 1 1 1 2 0 1 0 2 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0.100000 2.100 2.100 5.800 467340 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 1 0 0 1 2 0 0 0 0 0 1 0 2 0 0 2 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 1 2 0 2 2 4 1 0 1 1 2 3 4 1 4 1 5 1 2 1 0 2 2 2 1 5 4 1 5 4 0 1 2 4 2 2 0 2 1 2 5 4 1 1 1 2 5 7 9 16 23 31 15 22 36 36 44 42 29 31 28 28 18 35 12 10 13 8 4 3 2 2 5 1 2 3 3 1 3 3 5 2 0 3 4 1 2 2 3 0 0 5 2 3 6 2 1 2 5 3 4 3 1 1 1 1 2 2 4 0 2 3 1 2 1 2 4 5 4 3 5 2 1 2 0 5 0 2 2 4 1 0 4 1 0 2 1 2 0 0 1 3 2 4 3 0 2 3 3 3 4 2 2 0 0 0 0 1 1 0 3 2 0 1 2 0 4 2 1 1 1 2 0 0 0 0 0 0 0 0 0 0 0.102000 2.150 2.150 5.900 497495 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 0 2 1 0 0 0 0 1 0 1 0 0 0 0 1 2 0 0 0 0 0 2 0 0 1 0 1 0 0 0 0 1 1 0 0 0 1 1 1 1 2 0 0 1 0 0 0 1 0 2 2 1 0 0 0 2 0 2 1 1 1 6 3 2 0 3 2 2 2 1 1 3 4 1 0 1 2 4 2 3 3 1 1 1 1 3 3 1 4 1 3 4 3 2 3 1 2 2 5 11 11 14 26 27 28 28 28 36 39 42 29 33 24 20 29 18 13 17 13 6 10 4 3 3 6 1 0 1 0 2 1 3 2 3 1 2 3 1 2 1 2 0 2 2 3 1 3 1 1 2 4 4 1 4 3 2 2 3 5 5 3 0 2 5 3 5 1 4 1 1 3 4 2 2 2 2 1 3 0 1 1 2 2 4 2 1 3 2 0 1 2 1 0 2 3 1 2 0 0 0 2 0 0 1 3 0 0 1 2 0 3 1 0 3 1 2 2 1 1 2 0 0 0 0 2 0 0 1 0 0 0 0 0 0.104000 2.200 2.200 6.000 529288 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 1 3 0 2 0 2 0 0 3 2 2 0 4 0 3 2 2 1 3 1 7 3 1 1 0 4 3 2 1 0 0 3 2 3 5 2 1 4 1 5 1 0 3 2 3 0 1 2 4 7 3 7 8 12 15 20 24 34 39 34 35 27 36 34 23 22 26 15 24 12 12 14 5 3 0 7 1 1 3 5 1 2 2 2 4 3 1 2 5 2 2 3 1 1 4 2 1 3 0 4 5 4 6 4 5 3 3 3 3 1 1 5 0 6 1 2 4 2 3 2 1 3 2 0 0 0 1 3 3 0 1 4 0 3 2 3 0 3 3 0 2 3 4 3 1 1 1 2 5 3 1 2 1 1 2 4 1 0 2 4 1 3 0 0 3 0 1 3 0 1 0 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0.106000 2.250 2.250 6.100 560628 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 2 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 2 0 0 0 0 2 0 3 1 1 0 0 2 2 2 0 5 2 1 1 1 1 3 1 2 3 0 1 0 0 0 0 1 0 2 2 1 2 1 0 4 3 2 1 2 1 0 4 2 2 0 2 1 1 2 3 1 2 1 2 4 4 11 12 17 19 19 29 30 24 30 35 51 32 36 34 31 19 22 17 11 19 11 7 6 6 3 4 0 3 3 2 0 2 2 2 3 1 5 3 2 3 5 1 0 2 2 5 4 2 3 2 0 1 6 1 2 2 2 2 1 1 2 2 1 4 3 2 2 1 2 5 2 0 2 0 2 5 4 5 2 1 3 6 1 3 4 4 0 0 6 0 2 6 1 2 2 2 0 1 3 1 3 4 2 1 4 2 1 2 3 3 0 3 1 0 2 0 2 1 0 2 1 2 0 0 1 1 0 2 0 0 0 0 0 0 0 0.108000 2.300 2.300 6.200 593293 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 2 0 2 2 1 0 0 2 0 1 0 1 0 0 1 2 2 1 0 0 1 0 2 0 0 0 0 0 1 1 1 1 1 0 0 1 1 0 0 1 1 1 2 2 1 0 1 1 0 1 5 0 2 4 1 0 1 4 2 1 3 2 2 3 2 3 2 0 0 3 4 3 1 3 2 2 0 3 0 2 4 0 3 2 5 1 2 1 4 6 1 2 4 0 3 6 1 7 6 4 5 4 10 16 24 22 20 40 37 44 34 29 21 28 36 36 27 23 24 14 10 4 5 2 5 3 6 2 3 3 1 4 2 1 5 1 3 5 3 2 1 2 2 6 2 3 1 1 0 5 3 3 3 4 5 2 2 3 3 5 5 1 6 2 3 2 6 0 5 2 4 3 5 1 2 2 5 1 2 3 1 2 2 2 4 2 5 5 2 2 2 5 0 1 2 5 2 3 2 3 1 1 2 4 0 2 1 4 2 1 1 1 0 1 2 0 0 1 3 1 0 2 1 1 3 3 2 0 0 0 1 2 0 0 0 0 0.110000 2.350 2.350 6.300 636559 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 1 0 0 0 1 1 2 0 0 1 0 0 0 0 0 0 0 1 2 0 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 0 0 2 0 1 0 1 0 1 0 0 1 1 3 0 1 2 2 0 2 1 1 1 1 0 1 0 1 3 0 3 2 3 4 3 3 4 3 3 2 6 3 1 1 1 2 4 2 3 1 5 1 3 1 4 5 3 3 2 1 3 7 4 3 10 19 17 19 23 27 28 33 39 36 23 23 32 32 16 19 35 23 12 11 12 8 4 5 7 1 2 2 1 2 3 5 4 2 3 2 6 4 4 2 4 1 2 2 1 2 3 0 4 2 1 2 6 2 2 1 3 3 1 6 4 8 5 2 3 5 2 3 0 3 2 3 1 2 2 3 4 3 8 6 2 1 4 6 3 1 2 0 2 0 2 5 0 3 3 3 3 1 3 3 2 5 4 2 1 4 2 2 4 4 1 3 2 5 2 3 1 2 0 4 0 1 0 6 3 1 2 0 2 0 1 0 0 0 0 0.112000 2.400 2.400 6.400 670484 3 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 2 0 1 1 1 3 0 0 0 2 1 3 0 1 1 1 0 1 1 1 0 0 1 2 0 1 3 1 5 2 3 0 4 0 2 0 0 1 2 1 0 1 0 0 1 0 2 2 3 2 3 2 2 2 3 4 4 2 3 5 3 3 2 3 3 4 2 4 0 3 2 4 4 1 3 1 3 4 2 2 5 2 8 6 12 17 14 22 27 26 29 39 30 24 36 22 22 20 9 19 15 5 12 16 4 7 5 7 5 5 1 4 5 5 4 4 1 4 4 3 3 3 4 2 2 4 2 4 4 4 4 0 2 3 2 1 4 3 6 1 3 3 3 4 5 4 2 2 2 5 3 0 2 5 4 2 5 3 5 1 1 3 1 1 3 6 6 2 3 2 0 3 2 4 3 4 1 2 2 6 2 0 3 2 2 5 3 3 5 2 1 0 3 1 1 2 2 0 1 1 3 2 3 2 1 1 1 1 3 2 1 0 0 0 0 0 0 0 0.114000 2.450 2.450 6.500 711783 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 1 0 2 1 2 0 1 0 0 1 0 0 1 1 1 1 0 0 0 1 1 2 0 1 1 0 0 0 2 1 1 1 1 1 2 1 2 3 3 1 1 1 2 3 1 3 2 2 1 0 1 1 4 4 4 1 0 4 0 0 1 1 2 1 3 2 0 3 4 1 1 1 1 3 2 0 1 3 2 1 2 1 0 3 3 2 5 4 2 5 3 4 2 2 5 3 3 3 3 5 5 8 7 14 12 28 22 24 23 36 33 26 32 27 26 18 30 24 15 13 19 15 17 6 5 7 5 4 3 5 3 1 4 4 9 5 3 1 4 0 0 6 2 5 3 3 3 1 2 3 2 4 1 5 5 3 8 2 1 1 4 1 7 5 6 6 4 4 3 2 6 3 3 3 3 1 3 4 5 4 3 4 3 1 2 3 1 2 1 2 2 6 5 2 2 2 4 2 2 0 2 3 3 2 7 4 4 1 4 2 0 3 1 1 2 1 2 3 1 3 2 2 4 3 1 4 0 0 4 2 2 2 1 0 0 0 0 0.116000 2.500 2.500 6.600 745364 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 1 2 1 1 2 1 1 1 0 1 0 2 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 2 3 0 1 4 4 0 4 0 1 0 1 3 3 0 2 1 2 3 2 1 1 1 2 0 4 0 0 4 5 2 5 4 1 3 5 5 4 0 4 4 2 3 2 3 5 2 2 4 2 3 4 2 3 3 3 3 3 2 4 12 10 13 14 19 22 23 24 36 19 32 25 25 36 24 18 20 21 14 18 13 8 6 9 2 9 5 2 5 3 4 4 3 3 0 4 3 2 5 3 4 2 2 6 3 4 0 2 4 1 3 4 7 4 5 3 2 4 5 5 3 4 4 4 2 3 2 4 4 2 1 5 7 1 5 2 4 1 5 5 3 4 4 3 2 4 2 4 0 6 2 3 4 1 2 2 2 4 1 4 2 2 2 5 6 5 1 4 4 2 3 3 3 1 4 3 4 2 6 2 5 3 2 2 1 3 2 2 5 1 1 0 0 1 0 0 0 0.118000 2.550 2.550 6.700 791846 4 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 1 0 0 0 0 0 1 0 0 0 1 1 0 1 0 1 0 1 1 0 1 0 1 4 1 2 3 0 3 1 0 1 1 1 0 3 1 2 1 1 1 0 0 1 1 1 3 1 3 2 3 1 2 2 1 3 2 4 1 4 0 2 4 1 4 3 2 1 1 2 1 3 2 3 3 2 1 1 5 3 3 3 3 2 3 4 3 5 3 1 1 2 2 3 5 1 2 1 1 4 4 6 9 6 6 13 17 21 20 24 22 25 20 29 23 28 30 26 27 18 20 17 16 17 12 10 8 5 6 6 6 4 3 1 2 4 6 9 2 2 3 5 7 6 2 3 8 5 4 5 6 4 6 5 3 5 3 2 5 3 2 8 3 5 4 5 3 5 4 3 4 8 4 3 8 3 3 3 1 1 2 2 5 4 7 3 2 3 3 2 2 3 6 3 2 2 1 1 5 2 5 6 3 5 3 4 1 3 1 2 1 0 4 1 4 2 2 2 3 1 1 1 1 3 2 0 1 6 1 1 0 2 1 0 1 0 0 0 0 0.120000 2.600 2.600 6.800 833394 3 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 2 2 1 1 1 2 1 0 0 0 1 0 1 0 0 0 1 0 0 1 1 2 1 0 0 0 0 0 2 2 0 3 1 0 0 2 1 1 1 1 0 1 2 1 5 0 1 0 2 2 1 2 0 4 2 1 4 3 4 2 2 1 2 1 5 2 3 1 3 0 2 2 2 2 3 4 0 4 2 3 3 4 5 2 2 6 3 4 5 5 5 3 4 6 5 1 3 0 5 4 5 1 3 2 2 6 18 13 17 27 27 21 28 28 24 26 27 29 23 21 16 17 19 22 14 11 9 5 14 7 7 6 4 4 12 3 6 4 5 4 6 4 2 0 1 8 1 6 8 5 2 3 4 5 6 4 2 5 8 3 1 1 6 3 7 8 4 1 6 5 2 8 11 5 6 5 6 2 4 5 1 2 7 2 2 5 5 6 3 3 2 3 8 5 1 9 3 3 2 3 6 3 5 3 2 4 6 3 1 3 5 4 4 4 6 3 3 5 0 2 2 5 1 3 2 2 1 4 2 0 2 2 2 2 4 1 2 1 2 1 1 0 0.122000 2.650 2.650 6.900 876007 3 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 1 1 1 1 2 2 1 0 0 1 0 0 0 1 1 0 0 0 2 0 0 4 1 0 2 1 2 0 1 2 0 1 3 2 1 0 1 1 0 1 2 1 0 2 3 3 5 3 3 3 0 1 4 0 1 5 3 4 3 1 2 2 2 4 1 3 3 3 2 3 2 3 2 1 4 4 2 2 5 5 3 4 1 2 1 2 4 2 4 7 2 4 4 2 7 3 5 7 5 3 6 8 10 10 18 21 22 24 14 25 27 29 31 22 25 24 21 27 20 19 22 19 14 13 14 10 5 7 3 4 5 5 3 1 4 3 8 4 5 4 0 3 4 3 4 1 7 6 1 1 3 4 4 3 4 3 6 4 3 4 2 4 4 3 5 6 5 1 1 6 2 6 6 3 5 5 3 2 6 5 4 3 4 6 4 3 5 5 6 5 6 2 4 2 1 2 2 4 2 7 6 2 1 3 1 5 2 1 2 4 3 3 3 2 5 2 4 1 4 3 2 2 5 5 1 1 3 3 2 2 2 2 1 0 0 0 0 0 0.124000 2.700 2.700 7.000 925764 3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 2 1 3 0 1 1 0 0 0 0 0 1 1 1 1 0 0 0 1 1 0 1 2 0 0 3 2 0 1 2 1 1 2 0 2 1 2 2 0 0 2 3 2 3 2 2 3 2 2 4 0 2 0 5 1 3 2 3 1 2 3 2 0 6 4 3 6 2 5 0 5 2 1 4 4 5 7 4 2 3 5 2 0 2 5 2 4 7 4 4 4 8 5 3 1 7 2 2 1 5 5 5 14 19 16 22 18 30 29 25 36 23 23 22 25 25 27 26 23 14 20 16 16 10 6 6 6 4 2 6 6 6 6 6 4 6 1 0 3 4 4 5 2 4 3 2 4 4 5 5 5 6 10 6 3 6 8 5 5 8 7 4 6 4 3 4 8 5 5 7 4 6 3 5 8 4 3 4 4 3 4 3 1 3 3 7 2 4 8 3 6 4 3 3 2 5 4 4 3 7 4 5 4 4 3 4 7 2 3 3 4 3 0 2 2 4 3 4 2 4 2 2 6 4 4 6 6 1 5 1 1 2 1 0 0 0 0 0 0.126000 2.750 2.750 7.100 969560 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 0 1 2 0 2 0 2 2 0 1 1 1 0 0 1 0 1 1 1 1 2 0 1 2 2 1 2 0 0 1 0 1 0 2 1 0 1 0 1 1 2 0 3 0 3 4 3 1 3 2 0 4 0 1 2 0 3 1 1 2 3 2 2 2 5 1 7 1 5 1 5 4 2 0 0 1 2 1 3 2 3 3 5 4 10 10 2 5 11 4 1 2 1 7 3 5 4 4 1 5 10 8 7 9 9 20 20 21 33 21 28 20 27 32 21 29 22 20 24 15 13 27 14 13 15 10 9 3 11 6 7 5 3 6 8 5 4 4 1 3 3 5 2 7 3 6 6 1 6 4 6 5 3 4 2 4 3 3 9 4 5 4 4 5 2 3 10 4 3 2 6 10 6 3 6 5 5 5 4 8 8 5 4 3 6 4 4 2 4 4 4 5 7 4 4 4 4 5 2 2 3 4 5 2 1 3 2 6 2 7 7 1 6 4 4 6 5 5 4 0 2 2 3 2 7 5 0 4 1 1 4 6 1 0 3 2 0 0 1 0.128000 2.800 2.800 7.200 1022713 5 0 0 0 0 0 0 0 0 0 0 0 0 1 0 2 0 0 0 1 0 1 1 0 0 1 1 1 0 0 0 2 1 0 0 4 0 0 1 2 3 1 1 0 1 0 1 0 3 1 1 1 2 2 1 1 1 3 1 0 2 4 2 1 2 1 2 0 3 1 3 2 1 5 2 1 3 1 2 1 5 3 2 1 2 5 3 8 2 3 2 5 5 4 3 6 4 4 4 3 2 3 8 4 3 4 5 4 5 4 7 6 5 3 3 3 5 2 9 10 7 9 12 11 13 17 15 22 19 33 24 28 30 26 21 24 22 27 20 26 16 10 10 9 20 10 7 4 5 7 7 2 7 5 3 5 1 6 1 5 7 5 6 3 1 5 1 1 3 4 8 6 3 9 5 5 3 6 7 4 6 7 6 4 2 4 6 2 3 6 5 6 7 6 4 4 9 6 8 6 9 7 1 2 6 2 7 5 4 4 4 4 5 5 4 4 3 6 3 5 3 6 4 3 6 6 2 5 2 8 4 5 3 6 5 4 5 8 4 3 5 6 5 5 2 8 1 2 2 5 4 1 3 0 0 0 0 0 0.130000 2.850 2.850 7.300 1081669 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 5 0 0 2 2 0 0 1 0 0 0 1 1 0 2 0 2 2 2 1 0 1 0 2 2 3 1 1 0 2 0 1 0 2 1 1 2 2 0 1 4 3 0 2 1 1 0 2 5 2 1 0 1 3 2 5 2 1 2 5 2 3 4 3 6 6 6 4 6 6 3 1 3 2 3 4 7 5 2 9 7 4 1 4 4 3 2 2 2 7 4 8 4 7 4 6 8 5 1 8 6 10 18 21 18 15 21 24 21 26 22 30 28 27 23 22 21 17 25 20 17 13 17 9 12 7 8 5 4 4 5 5 2 4 1 1 2 5 7 6 4 9 7 7 5 5 5 5 5 2 4 5 3 6 8 2 4 9 4 10 5 1 4 5 5 5 10 3 2 8 6 5 7 3 13 3 3 6 5 1 4 5 9 5 2 7 4 5 6 3 5 6 5 4 5 9 6 4 3 4 4 4 5 8 5 5 0 3 6 3 4 3 7 5 6 4 3 3 6 8 4 1 3 1 2 7 3 4 6 6 1 3 4 1 0 1 0 0 0.132000 2.900 2.900 7.400 1131887 3 0 0 0 0 0 0 0 0 0 1 0 0 1 2 1 1 0 0 0 1 2 2 1 1 0 2 1 1 0 1 1 1 0 2 2 3 1 0 1 0 1 0 2 0 2 0 1 4 0 1 2 2 0 0 0 2 3 0 1 2 3 0 1 2 3 5 6 2 2 3 1 4 4 8 4 3 3 3 7 2 2 5 7 4 1 2 4 8 1 5 2 7 3 4 2 9 6 5 5 6 2 2 3 6 2 5 6 7 7 2 8 3 3 3 3 6 6 5 3 10 15 15 17 19 13 29 20 23 22 34 28 28 33 20 20 22 17 22 18 15 19 14 11 9 13 6 6 13 4 2 9 8 8 7 6 5 6 4 4 9 6 2 8 9 7 2 6 3 7 3 6 3 7 4 4 5 4 5 6 4 7 5 4 10 2 6 6 8 3 6 6 9 5 8 8 7 6 4 8 5 7 5 5 7 3 5 5 5 10 7 3 8 7 5 7 2 4 4 6 4 10 7 6 4 4 4 4 3 2 4 2 6 5 9 7 3 2 6 2 5 1 5 6 2 2 1 9 2 5 2 5 1 0 0 0 1 1 0.134000 2.950 2.950 7.500 1185706 3 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 3 2 1 0 1 1 0 0 0 0 0 1 0 1 1 2 0 1 0 1 2 0 0 0 1 1 0 1 1 1 0 2 2 0 1 3 3 2 3 0 0 2 2 3 2 1 1 3 0 0 1 1 3 4 3 1 1 9 1 4 0 1 3 4 1 3 2 6 4 7 7 3 2 8 5 2 5 2 4 6 7 3 7 7 8 4 7 2 4 7 7 9 9 2 5 5 8 3 5 7 3 6 10 6 10 15 10 13 14 29 21 23 37 26 20 28 20 16 24 25 16 19 21 20 20 17 11 10 12 8 7 7 5 5 5 4 5 6 7 3 6 5 7 5 11 9 6 8 11 6 4 6 8 8 7 7 7 4 5 4 8 5 4 3 4 8 10 7 9 4 7 6 8 9 7 3 5 7 7 6 2 6 4 7 3 9 8 12 7 6 6 6 4 5 7 2 4 7 3 2 4 4 7 1 4 5 0 4 6 3 10 8 5 4 3 4 5 7 5 7 5 7 3 5 2 5 6 4 5 2 4 1 6 6 2 4 2 0 0 1 0 0.136000 3.000 3.000 7.600 1238426 3 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 4 0 2 0 2 2 0 1 1 1 0 2 1 1 2 1 0 1 1 0 3 1 0 0 1 0 1 0 0 2 1 1 0 4 0 2 6 3 3 4 0 3 1 2 4 0 4 4 0 1 5 2 2 5 1 3 4 3 3 5 2 4 4 6 2 5 3 4 5 4 5 6 7 5 6 2 8 3 4 7 2 4 4 3 7 6 5 1 4 8 3 7 10 3 3 6 1 5 3 8 11 5 7 15 11 15 17 21 23 21 24 28 16 21 29 15 22 27 28 20 13 19 13 7 15 10 11 9 6 8 8 4 7 5 4 6 5 10 6 7 8 9 3 5 5 9 5 9 4 4 4 3 5 7 4 10 6 8 4 9 8 4 6 7 9 11 6 8 3 5 8 12 3 6 9 7 11 9 6 7 4 7 7 7 2 5 4 5 0 2 9 5 5 5 10 7 5 6 3 9 4 4 13 2 7 5 7 4 7 2 0 4 5 4 4 6 8 1 2 5 6 4 7 3 11 4 3 3 5 5 4 4 3 1 4 2 2 1 1 0 0.138000 3.050 3.050 7.700 1299809 6 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 2 1 1 0 0 1 0 0 2 0 1 2 0 0 3 0 0 1 3 1 2 0 2 0 1 1 2 1 2 3 2 1 2 5 2 2 2 4 3 2 5 3 0 3 2 4 5 4 3 0 5 4 1 4 3 8 6 4 4 7 4 5 4 3 6 5 6 10 3 6 6 2 6 3 4 4 3 6 7 6 8 3 4 7 5 4 9 2 4 8 5 9 8 3 7 5 7 7 13 7 11 15 17 16 18 18 18 20 17 26 25 19 20 26 31 22 18 20 18 14 11 16 4 7 11 10 8 9 9 6 3 8 8 7 5 6 10 3 5 6 6 3 12 7 8 8 2 10 4 13 9 9 12 4 5 9 7 9 5 7 4 8 9 6 7 8 10 8 7 5 7 11 6 4 4 4 6 4 9 4 5 9 10 7 4 12 7 4 9 5 10 10 6 8 4 7 2 4 7 2 6 8 4 11 3 3 9 7 6 7 3 8 7 4 8 5 3 7 4 5 5 7 4 6 7 5 5 3 5 2 5 4 1 2 0 0 1 0.140000 3.100 3.100 7.800 1361810 3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 3 2 1 0 0 0 1 1 1 2 0 0 0 0 1 0 2 2 2 1 0 0 3 3 0 2 0 6 2 3 1 0 3 3 1 2 2 5 3 5 3 3 2 2 7 3 2 2 3 4 2 3 4 4 1 3 7 4 5 4 2 3 5 4 2 1 3 6 3 4 3 8 7 6 5 3 5 11 5 5 3 3 7 3 6 4 4 2 4 4 4 1 5 5 9 6 6 9 3 10 8 6 8 3 10 8 16 16 13 18 23 29 25 19 19 20 27 19 22 27 24 21 15 18 11 20 21 17 12 5 18 6 12 7 9 11 7 12 11 4 8 8 4 8 7 7 2 6 4 4 9 6 9 3 4 7 7 7 4 10 4 11 5 8 8 8 5 4 4 8 6 4 9 8 12 12 8 5 8 3 10 8 7 5 3 5 6 8 5 6 10 7 2 11 2 5 5 6 8 10 2 7 5 5 14 2 7 3 9 3 5 2 8 2 3 4 4 7 9 5 4 7 6 7 5 6 3 5 4 7 6 7 7 9 3 0 2 1 1 1 0 0 0.142000 3.150 3.150 7.900 1429499 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1 2 1 1 0 0 0 3 0 2 2 1 0 3 0 2 1 3 0 0 1 1 3 1 2 4 1 5 3 5 1 0 7 1 3 2 3 2 2 2 3 0 0 1 3 6 3 2 2 4 4 4 6 4 3 6 4 10 3 7 2 5 4 7 4 5 8 4 7 4 1 7 11 5 2 10 2 11 3 7 8 10 9 6 3 5 3 6 3 10 11 5 5 9 7 10 8 9 5 15 11 9 18 18 15 24 17 23 17 19 25 17 24 18 37 16 17 21 17 14 20 17 15 15 9 4 11 7 3 8 10 8 8 6 8 3 4 5 8 4 6 3 9 9 6 2 10 4 4 3 8 4 9 1 7 5 9 7 10 9 10 4 6 5 8 6 6 10 10 6 5 7 6 6 10 5 7 8 8 8 7 7 11 12 8 3 10 6 9 13 11 4 6 7 6 3 10 5 8 4 7 7 7 5 8 4 9 5 5 7 6 6 7 11 11 7 8 5 3 5 7 7 10 3 3 6 5 7 9 2 3 7 1 0 0 0 0 1 0.144000 3.200 3.200 8.000 1493946 3 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 2 3 0 0 1 2 1 1 1 4 1 0 1 0 1 2 1 3 1 1 1 1 2 1 1 3 2 6 0 4 0 1 4 2 4 5 2 1 3 0 2 2 4 2 3 2 4 3 5 4 4 4 1 5 1 3 4 5 6 4 7 2 8 8 8 5 3 6 0 7 3 2 2 5 7 5 7 5 8 9 6 4 3 6 8 6 10 2 5 6 3 3 6 6 6 6 17 5 10 6 6 11 11 13 12 21 26 18 24 21 24 23 30 18 22 20 24 19 13 17 25 22 17 15 8 13 7 10 8 9 6 7 9 8 7 8 9 7 7 6 12 5 9 9 12 9 12 6 9 7 10 7 7 4 9 7 4 2 7 4 5 8 8 9 7 6 7 5 9 4 8 13 6 5 4 7 9 6 7 7 9 4 4 5 8 10 9 10 6 6 7 9 12 11 8 8 9 11 5 8 7 5 5 8 5 9 10 5 5 11 11 6 8 8 4 8 5 5 5 4 7 4 5 6 5 6 6 7 7 4 2 6 3 2 1 0 0 0 0 0 0.146000 3.250 3.250 8.100 1562352 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 2 0 1 2 1 1 0 0 1 0 1 2 0 0 0 3 1 2 0 4 4 2 0 0 2 3 2 0 1 3 3 4 0 1 4 3 3 4 5 5 4 2 1 4 2 5 3 2 7 6 3 5 6 5 5 5 1 5 2 7 4 8 7 4 6 5 7 5 3 5 8 1 6 4 6 8 7 6 7 6 3 4 6 3 5 8 4 10 3 3 11 6 5 3 9 6 4 3 17 9 11 11 24 13 15 14 25 26 26 21 17 32 32 22 18 25 29 29 27 24 21 12 23 14 12 11 9 17 7 9 11 3 7 6 5 5 12 3 6 8 7 4 7 11 10 8 9 5 8 2 10 9 8 10 10 7 7 4 7 5 7 7 9 10 8 7 7 16 6 8 10 5 6 6 12 12 7 11 11 8 9 7 8 12 10 7 8 7 11 8 9 7 7 4 9 4 7 14 9 8 8 13 9 8 7 13 5 9 5 7 4 9 5 7 8 7 8 7 3 10 9 3 4 4 4 5 2 6 6 3 5 10 4 4 2 3 0 1 0 0 0.148000 3.300 3.300 8.200 1630559 3 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 4 2 1 1 1 2 1 2 0 2 1 5 0 1 1 4 0 2 1 4 5 3 0 1 1 1 2 1 3 3 3 1 1 1 1 1 3 4 6 6 8 8 4 3 2 7 2 2 1 7 4 4 5 1 10 6 4 4 4 3 3 3 6 11 6 4 5 4 8 5 5 9 4 5 5 7 6 4 13 12 3 6 7 5 2 7 9 7 8 8 4 7 6 4 10 6 8 9 9 9 13 15 17 23 25 13 16 24 22 26 21 27 24 24 21 21 21 15 17 22 25 21 22 17 14 11 8 12 5 9 7 8 5 11 10 6 6 5 9 13 10 9 8 8 8 6 4 9 10 9 9 7 8 7 5 7 8 14 13 5 14 5 12 11 8 9 6 5 4 9 13 7 10 13 11 11 8 5 9 10 8 7 6 7 13 3 13 8 7 13 17 5 8 5 10 7 12 7 6 6 9 7 8 8 11 8 11 9 11 11 8 5 6 10 4 9 3 10 8 7 10 8 7 8 10 10 7 4 11 5 7 8 2 4 3 0 0 1 0 1 0.150000 3.350 3.350 8.300 1707576 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 2 1 2 1 0 2 0 2 3 1 3 2 2 2 2 0 2 1 4 3 2 2 3 1 2 1 0 2 2 4 2 5 3 3 5 2 8 4 5 4 2 3 6 7 6 1 0 7 4 7 7 6 5 4 3 4 6 6 7 6 2 7 4 4 2 5 5 6 9 3 3 3 6 6 5 3 5 7 8 8 6 8 8 6 8 3 9 6 6 8 8 6 4 8 6 6 10 4 11 6 11 15 23 16 8 17 20 21 19 24 15 14 19 21 30 25 21 15 19 16 18 21 21 15 14 12 16 8 10 12 7 10 9 8 10 10 7 9 8 10 12 6 6 9 11 6 5 9 12 6 7 12 7 5 6 8 5 9 4 11 9 8 8 10 7 6 10 7 11 13 7 4 13 11 8 11 9 16 6 12 11 10 10 19 2 9 11 8 7 8 8 6 13 6 10 12 12 9 12 9 9 8 7 7 9 6 12 8 4 9 9 8 5 7 8 9 5 12 5 7 5 9 10 9 10 3 6 6 8 7 11 3 5 5 4 2 0 0 0 0 0.152000 3.400 3.400 8.400 1777231 3 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 0 1 1 3 1 0 3 4 2 3 3 3 3 3 2 1 1 1 1 3 3 0 1 8 0 0 5 3 7 4 4 4 4 4 3 5 2 2 5 3 6 1 7 6 1 2 2 5 2 1 6 6 8 7 7 5 10 4 1 6 9 3 4 5 3 5 8 4 9 8 11 8 3 2 7 7 9 10 9 10 8 6 8 6 8 7 10 8 7 3 8 4 10 7 6 8 9 6 5 16 9 19 24 23 17 23 24 22 30 21 15 23 27 20 20 20 18 20 23 18 17 15 19 17 18 13 9 4 4 7 12 7 10 4 8 6 10 5 6 13 2 3 8 7 8 7 3 11 8 7 9 7 19 7 8 9 6 14 8 8 11 10 11 13 14 10 16 8 9 13 8 9 9 12 7 12 11 6 9 15 5 9 9 9 11 11 13 6 10 6 4 12 9 9 12 11 8 6 9 16 10 10 10 8 10 10 6 7 4 1 15 6 8 4 9 13 11 8 10 11 9 8 3 3 6 6 7 9 4 6 8 7 4 2 1 2 2 1 0 0.154000 3.450 3.450 8.500 1849489 6 0 0 0 0 0 0 0 0 0 0 0 1 1 3 0 1 2 2 0 1 4 1 1 0 1 0 2 1 0 0 1 1 1 1 6 3 6 1 3 1 3 3 0 6 0 4 2 7 4 6 4 4 3 7 4 5 7 5 5 2 3 9 9 2 5 5 3 9 4 2 7 6 2 8 2 5 7 12 6 5 4 5 10 4 12 10 6 4 14 7 9 10 11 7 7 7 7 3 9 7 4 3 8 7 5 7 9 6 8 9 6 8 8 12 6 5 11 12 13 11 13 21 26 19 23 25 18 23 22 23 23 18 27 20 15 20 25 24 19 18 12 14 13 15 8 15 10 11 7 9 13 11 12 13 11 11 7 11 13 6 5 10 6 6 10 8 14 5 14 11 8 5 9 7 10 10 8 7 15 13 3 13 12 18 15 7 10 9 10 8 15 9 6 8 9 10 10 9 5 7 7 5 10 11 13 12 12 12 10 6 17 10 11 9 4 8 7 6 6 9 12 8 16 18 7 5 10 8 12 10 15 6 13 11 6 10 16 10 11 16 8 9 5 11 10 14 11 5 2 5 7 3 1 1 0 1 0 0.156000 3.500 3.500 8.600 1920727 4 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 2 1 2 0 3 0 1 1 0 1 0 3 0 4 4 1 3 1 2 3 3 4 3 1 2 3 9 5 2 3 7 3 3 6 5 2 6 1 4 3 2 3 6 5 1 8 3 8 5 3 7 6 13 11 9 5 8 7 7 5 8 7 4 8 6 4 10 4 6 5 6 9 9 12 6 7 10 9 9 8 8 3 8 9 8 8 2 12 11 13 8 13 7 8 6 6 9 6 8 16 13 14 16 16 22 20 21 21 17 20 18 19 22 20 11 20 22 21 14 19 15 23 17 15 12 14 19 16 10 11 14 11 9 11 9 12 8 16 14 9 6 18 10 11 7 10 11 17 10 13 8 10 12 9 12 7 7 10 10 11 11 9 8 8 14 10 10 9 14 9 14 13 9 19 16 17 4 11 8 12 11 10 21 6 10 8 9 12 9 7 7 12 7 16 14 10 13 6 13 8 9 10 6 10 8 7 10 4 6 11 19 12 6 7 5 8 11 10 12 13 9 6 10 5 11 11 4 14 10 7 2 6 5 1 2 5 1 1 0 0 0.158000 3.550 3.550 8.700 1999833 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 2 3 2 2 2 1 2 3 0 1 0 1 3 2 0 0 3 2 3 2 5 7 0 3 4 1 10 7 7 4 5 2 3 4 3 8 3 6 4 4 4 8 2 3 4 5 5 7 1 6 7 8 1 6 8 1 4 4 11 9 4 7 11 9 10 5 6 8 4 3 9 7 9 11 5 5 8 8 4 8 7 8 11 9 12 6 4 13 4 12 10 6 9 11 10 11 10 11 11 11 14 15 14 23 18 17 29 16 26 23 15 19 14 18 19 22 31 13 21 20 12 16 15 14 18 17 15 8 12 14 13 10 10 10 10 10 13 11 6 8 11 8 14 8 10 11 11 8 10 13 5 14 7 12 9 10 10 12 15 18 8 6 9 9 12 8 9 20 14 16 10 11 14 5 5 13 6 11 9 11 15 6 9 13 11 7 8 7 10 8 16 12 11 8 10 14 11 17 11 8 16 13 9 10 5 10 17 13 14 16 8 10 9 11 5 10 9 10 12 8 11 12 11 8 6 7 12 15 13 12 7 13 5 0 3 2 0 0 0 0 0.160000 3.600 3.600 8.800 2073149 3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 2 1 2 1 2 2 1 0 2 2 1 0 3 6 4 5 5 2 2 2 5 5 3 6 4 6 4 5 2 4 4 3 2 4 6 3 3 6 5 7 4 5 7 5 3 5 6 13 5 3 10 5 9 7 4 5 6 5 10 6 5 5 6 6 4 14 7 6 11 6 9 10 9 8 5 3 8 10 10 6 6 8 9 5 6 14 7 11 10 9 9 11 13 8 4 5 10 12 6 16 8 8 7 19 20 23 10 16 27 25 23 19 26 21 16 20 21 24 18 25 8 11 13 16 18 13 22 18 9 16 4 16 10 12 13 9 7 9 8 17 11 10 13 10 14 4 9 12 16 8 9 16 17 13 11 14 8 8 13 9 11 15 10 11 14 8 6 4 9 11 18 9 9 8 9 15 11 11 11 9 6 13 13 10 7 8 10 15 14 9 7 4 10 12 17 10 14 13 10 10 12 20 9 7 6 11 15 11 10 8 9 6 10 13 17 6 8 9 6 13 13 16 10 15 5 11 14 11 12 6 5 12 9 4 9 2 4 1 1 0 0 0 0.162000 3.650 3.650 8.900 2156456 5 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 2 0 1 1 3 2 3 4 3 3 2 1 3 6 5 2 3 4 4 3 6 2 3 4 4 5 5 3 4 1 4 5 9 3 3 4 3 3 8 5 6 12 2 10 3 4 6 8 9 8 8 2 2 7 5 8 2 8 9 7 2 6 8 6 5 8 2 7 5 6 13 5 6 8 11 6 10 5 6 3 8 10 11 10 10 14 10 11 8 11 8 12 6 12 5 15 12 13 10 13 13 18 23 12 21 18 21 23 20 30 20 23 26 24 24 21 21 29 19 21 16 23 20 13 19 13 16 11 15 13 13 11 8 11 14 14 13 4 16 15 18 13 9 19 8 11 6 9 14 8 13 12 13 10 13 10 14 11 13 11 8 10 13 11 11 14 11 8 14 11 10 9 14 12 14 18 8 12 7 13 12 10 14 14 8 12 17 11 13 9 12 12 15 7 9 13 17 11 11 11 12 17 12 11 16 15 8 9 12 7 13 15 11 16 7 10 7 14 5 18 10 10 8 8 6 6 13 14 6 9 11 9 9 3 5 1 1 3 0 0 0.164000 3.700 3.700 9.000 2234753 3 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 4 1 4 2 1 3 1 1 3 2 3 3 1 3 6 2 4 4 3 3 3 6 5 2 6 4 1 3 3 7 1 4 4 6 12 4 5 2 6 4 9 3 1 8 11 5 2 7 6 3 8 4 7 3 8 3 9 6 7 8 9 2 7 6 9 6 15 6 9 5 9 4 9 17 15 10 2 10 6 8 12 12 11 12 10 9 7 11 8 7 5 11 10 14 16 7 7 7 13 15 10 16 17 21 19 14 18 24 19 27 27 24 20 22 24 21 20 14 24 17 17 18 32 15 12 13 15 12 8 14 11 11 19 11 14 15 18 10 5 12 11 11 9 15 9 7 9 16 12 9 12 10 15 9 18 7 11 12 14 7 20 8 10 13 14 11 6 6 9 11 8 10 16 8 17 13 17 9 16 11 10 9 13 20 17 14 12 10 13 11 9 9 17 20 10 16 8 14 13 14 18 15 15 8 10 12 11 22 12 13 9 12 9 11 14 19 12 12 8 8 12 11 19 11 11 12 15 11 15 13 9 9 10 9 4 9 4 2 1 0 0 0.166000 3.750 3.750 9.100 2327990 3 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 2 0 1 2 2 1 1 0 0 3 1 4 2 6 4 2 4 3 2 5 5 2 3 1 3 1 2 10 2 7 4 3 4 3 3 4 3 10 6 9 6 3 8 5 5 3 4 4 6 8 4 4 7 5 5 11 14 5 3 6 8 8 7 10 11 7 17 7 11 10 8 7 8 12 13 11 12 6 13 9 7 7 6 5 8 13 10 10 14 11 11 8 12 15 14 9 13 10 9 18 13 18 12 23 14 17 24 15 23 25 31 19 17 29 19 19 19 26 25 19 17 22 19 19 19 11 11 12 22 21 8 10 18 10 14 19 17 13 14 10 6 9 10 15 11 5 13 13 11 11 17 16 9 7 14 7 19 6 10 13 7 12 18 14 7 12 15 13 13 9 13 13 13 12 12 14 12 19 10 16 18 18 12 8 10 10 9 7 14 9 11 13 12 8 15 12 11 10 12 11 17 15 19 14 14 12 7 7 12 11 15 16 12 11 12 10 19 19 12 14 12 15 11 20 13 7 18 9 15 19 16 11 5 9 8 6 2 4 0 2 0 1 0.168000 3.800 3.800 9.200 2406866 3 0 0 0 0 0 0 0 0 0 0 1 0 2 0 1 0 2 3 2 3 1 2 1 2 2 5 2 1 2 3 2 2 2 5 3 5 3 3 1 3 6 8 6 1 3 9 6 3 6 10 5 5 7 4 5 7 12 9 5 7 5 6 6 8 3 5 4 7 8 5 6 5 8 13 4 10 2 10 9 7 7 16 9 10 9 13 8 12 9 13 15 9 15 9 10 11 6 6 6 7 7 6 8 15 9 8 9 6 12 12 11 14 12 11 13 8 17 18 18 11 14 19 14 25 21 15 10 15 19 27 23 22 24 17 19 18 12 16 22 21 25 9 25 15 19 15 21 15 8 11 13 12 10 12 7 13 11 17 11 13 10 16 19 14 23 11 8 12 13 10 9 17 4 14 10 7 10 17 14 11 11 20 18 13 8 12 6 8 13 12 23 15 14 15 16 9 14 9 13 14 17 11 17 11 10 15 17 11 6 12 12 14 15 17 12 16 16 8 17 15 15 10 15 11 10 15 12 13 9 12 9 12 15 12 6 18 7 15 14 12 21 18 11 10 18 11 19 11 7 11 3 2 5 4 0 1 1 0.170000 3.850 3.850 9.300 2508471 7 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 1 2 1 4 3 3 1 2 7 0 3 2 2 2 2 5 2 3 2 3 3 4 3 7 3 5 3 4 4 6 2 3 10 4 11 3 13 7 7 5 6 3 8 10 6 6 4 10 11 4 12 7 8 9 7 7 8 4 6 7 9 9 5 9 11 5 14 9 10 7 9 8 8 5 6 11 13 14 10 10 10 10 8 9 9 9 9 14 14 13 11 8 18 9 10 9 16 12 13 15 13 10 17 16 20 14 22 20 26 29 29 27 24 20 37 21 24 13 18 13 28 24 22 25 21 13 14 15 9 11 18 8 16 17 16 13 12 16 11 11 17 15 11 15 10 11 12 13 12 12 20 15 14 15 16 12 17 15 15 12 10 14 14 17 15 19 15 13 13 11 12 16 14 17 16 8 16 12 8 14 13 13 10 10 9 12 11 19 20 13 11 4 15 11 14 11 20 18 18 13 20 12 20 21 15 15 12 13 18 18 11 16 9 14 9 18 11 10 11 20 11 13 17 13 13 12 14 16 10 12 12 23 12 11 12 8 8 1 0 1 2 0 0.172000 3.900 3.900 9.400 2591210 3 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 4 4 3 2 1 3 3 2 3 0 3 6 1 3 1 5 5 4 3 9 9 0 4 7 5 3 5 5 8 7 3 3 5 5 8 5 11 10 8 10 3 6 6 6 7 7 8 8 12 9 6 10 8 7 10 8 8 10 4 6 12 20 4 6 11 7 9 10 7 5 10 6 12 11 7 13 13 16 12 6 8 14 13 9 7 5 14 17 17 10 12 11 6 13 11 17 3 23 13 21 12 21 28 11 23 30 28 23 24 26 26 17 21 15 27 23 33 16 22 25 11 20 22 23 21 20 7 21 13 16 12 16 16 13 18 18 9 13 16 15 9 20 13 19 15 8 9 11 14 13 10 9 10 16 15 14 17 15 19 16 12 14 12 14 14 16 19 19 4 24 8 12 15 16 11 15 14 20 14 13 13 14 16 19 14 13 19 14 18 23 15 15 4 14 17 14 8 10 15 20 11 15 19 12 9 13 12 11 16 12 16 13 14 16 13 16 16 19 19 12 11 10 19 15 15 14 12 5 11 18 17 10 13 12 9 6 2 0 0 1 0 0.174000 3.950 3.950 9.500 2675515 3 0 0 0 0 0 0 0 0 0 0 0 2 0 1 1 0 2 1 2 3 3 1 3 1 3 7 5 3 6 4 3 9 4 5 2 5 3 3 3 6 9 5 5 2 6 8 5 8 4 8 5 6 5 6 4 6 3 7 11 6 9 9 3 6 6 7 6 8 7 9 12 18 6 9 8 11 11 8 14 15 15 11 15 13 9 19 10 15 14 9 4 18 5 8 10 8 10 13 9 12 11 8 8 12 6 15 8 9 9 18 7 17 21 9 13 18 14 21 24 18 22 17 26 15 21 23 25 19 26 23 20 27 17 27 20 26 15 22 15 19 15 16 24 12 15 24 13 13 17 11 7 10 21 15 15 16 13 20 22 12 16 12 16 15 14 18 11 12 14 14 24 10 13 16 19 8 11 18 19 15 15 23 16 16 11 12 18 11 13 14 16 10 14 13 18 12 15 15 14 8 11 17 12 22 13 12 14 15 10 11 15 19 15 12 17 8 21 23 13 19 11 8 12 15 11 14 15 19 15 10 17 9 16 14 18 14 16 14 14 23 14 14 13 16 12 14 15 14 9 14 7 5 2 3 1 1 1 0.176000 4.000 4.000 9.600 2779386 5 0 0 0 0 0 0 0 0 0 0 0 0 2 2 3 0 1 3 0 6 2 6 3 1 5 0 4 1 6 5 1 6 3 6 5 6 2 5 4 5 3 9 8 5 7 5 8 4 12 8 12 6 8 5 7 5 7 10 5 5 6 7 9 7 10 7 10 10 8 12 10 6 13 10 11 12 11 10 10 16 9 6 12 9 11 17 10 11 10 14 11 16 7 11 13 12 10 17 14 11 13 12 10 13 16 16 17 17 15 14 11 8 15 13 27 22 14 19 17 22 22 27 18 28 19 27 32 24 33 21 17 23 12 27 25 20 20 17 22 14 15 22 21 14 9 16 12 19 16 17 16 16 20 14 18 15 14 18 10 12 9 16 12 12 10 13 19 12 12 15 14 15 22 12 11 15 18 19 18 10 6 11 14 10 23 17 14 16 19 10 10 16 19 17 23 16 18 19 18 16 12 14 14 14 13 11 10 24 21 22 26 18 18 18 14 17 5 13 17 11 13 16 14 18 16 9 15 15 18 16 14 21 13 22 17 9 8 16 17 16 16 19 7 20 19 18 16 10 6 10 6 3 5 1 0 0 2 0.178000 4.050 4.050 9.700 2869617 3 0 0 0 0 0 0 0 0 0 0 0 2 2 2 0 1 4 1 3 2 2 1 2 3 2 2 4 4 7 5 6 5 3 6 6 5 7 8 1 5 2 3 5 5 8 10 7 6 10 9 6 8 9 7 8 10 15 4 10 5 8 8 6 11 8 8 11 7 5 8 14 5 11 7 13 10 9 7 8 9 14 12 10 9 11 6 14 15 14 13 11 9 18 18 10 14 14 10 12 16 12 9 8 14 15 6 11 11 12 10 14 12 11 18 13 13 27 16 23 23 20 21 32 20 18 25 22 24 32 25 34 19 23 21 25 22 25 19 23 19 21 16 19 16 18 9 18 6 13 12 13 18 12 8 19 14 14 11 16 13 15 14 21 11 14 14 13 11 20 14 14 26 10 22 16 18 15 20 24 18 19 19 16 14 14 14 21 13 19 18 20 13 17 11 17 14 22 17 15 15 20 8 21 15 16 16 23 17 13 19 21 20 12 15 18 15 19 15 18 17 20 15 13 14 24 18 15 15 14 18 20 19 17 19 20 21 21 15 19 19 17 11 16 16 11 23 10 20 13 10 5 10 2 3 1 1 0 0.180000 4.100 4.100 9.800 2975040 3 0 0 0 0 0 0 0 0 0 1 0 0 1 2 2 4 4 2 4 4 1 2 5 0 3 3 5 2 5 5 4 9 2 7 8 4 8 3 11 6 10 4 7 8 6 6 5 8 8 7 11 4 4 11 12 7 11 7 10 11 7 11 11 10 9 7 13 12 18 8 14 12 14 12 8 8 16 10 10 14 16 10 6 8 15 15 15 22 13 19 18 12 6 11 10 7 12 12 24 15 17 9 17 21 10 17 18 14 14 14 9 22 11 23 17 15 23 32 20 11 12 20 15 23 30 20 25 19 26 29 19 27 23 15 19 11 30 16 21 24 18 18 14 8 6 25 13 21 13 13 19 13 21 25 23 18 14 14 13 20 12 14 8 10 25 14 15 20 15 10 15 16 21 8 15 20 21 20 13 16 15 20 11 18 17 17 9 12 24 19 13 18 17 20 14 15 20 10 23 19 25 8 7 13 14 11 15 18 13 10 12 10 17 11 24 16 17 11 12 13 16 20 14 26 12 17 13 14 16 16 6 20 16 23 22 11 17 16 14 25 19 17 21 22 19 13 19 16 18 10 11 7 4 6 0 0 2 0.182000 4.150 4.150 9.900 3083416 6 0 0 0 0 0 0 0 0 0 0 0 2 1 1 4 1 3 4 3 5 6 2 1 4 2 3 5 6 6 7 2 4 1 11 7 5 2 6 6 8 9 8 12 7 11 9 6 12 7 8 9 6 6 8 11 6 6 8 11 8 11 12 11 13 9 10 7 9 6 11 9 13 12 12 8 14 15 8 9 8 8 11 22 16 6 11 16 15 9 13 12 12 13 11 15 9 9 16 14 14 12 21 12 12 12 16 19 10 15 18 8 16 14 16 16 21 30 22 9 25 19 19 26 23 33 25 22 21 19 21 20 20 21 20 26 20 29 27 25 25 21 20 25 21 21 18 14 19 15 6 20 18 16 20 16 13 13 15 15 15 15 22 16 15 15 11 21 19 11 19 13 14 15 17 21 12 18 12 22 18 21 18 13 23 15 18 9 21 11 14 23 18 21 25 18 22 15 21 23 15 15 16 19 21 18 19 21 17 13 24 23 22 19 14 20 22 15 14 14 20 20 23 13 18 15 18 20 20 24 9 12 17 21 21 12 16 17 16 16 21 26 19 15 21 22 24 15 11 13 13 6 8 1 4 0 1 0 0.184000 4.200 4.200 10.00 3174897 3 0 0 0 0 0 0 0 0 0 0 0 1 1 2 3 0 5 4 3 3 0 7 3 2 4 2 8 6 4 5 9 3 8 6 4 2 7 6 8 7 9 3 5 8 5 9 7 7 6 11 14 7 12 9 9 5 15 12 14 15 12 9 11 5 8 13 11 12 10 9 17 12 11 8 17 11 19 11 15 9 11 7 15 14 16 16 16 7 12 10 14 13 13 16 16 11 15 13 14 12 16 11 12 13 17 10 13 19 11 17 11 13 14 13 10 19 19 23 24 22 24 24 31 19 23 22 28 21 25 29 17 23 17 21 30 22 19 25 27 27 22 23 23 17 25 17 20 17 12 23 21 9 17 20 16 19 16 17 20 9 16 11 22 16 15 12 15 17 23 24 16 16 18 26 11 16 20 18 10 14 17 26 19 17 15 17 19 12 21 20 24 17 27 13 16 18 19 23 14 19 14 10 11 18 19 6 15 21 23 25 17 17 18 21 27 20 17 18 20 25 22 20 18 22 18 17 15 24 16 15 22 18 22 14 20 20 22 18 22 25 19 26 12 19 19 13 12 16 19 14 9 7 5 4 2 0 2 0.186000 4.250 4.250 10.10 3283256 3 0 0 0 0 0 0 0 0 1 0 0 1 1 4 1 5 2 5 5 3 4 6 3 2 4 7 8 2 6 6 4 10 7 8 7 5 4 4 9 8 18 10 7 6 6 13 12 10 13 10 7 15 4 7 10 13 12 8 8 13 5 14 6 9 14 9 10 16 12 13 11 8 12 11 10 13 9 11 15 17 23 18 13 10 12 11 12 14 14 14 10 12 12 16 13 15 13 13 14 18 10 13 17 14 14 14 12 12 8 18 14 23 20 16 19 16 16 16 27 18 21 19 20 19 37 22 21 22 28 24 26 18 21 28 21 22 21 21 22 16 15 13 22 22 27 22 11 13 20 10 17 16 19 20 30 18 25 8 7 22 18 17 14 23 16 17 11 16 24 19 18 22 15 15 23 16 13 15 22 14 8 12 18 13 15 22 17 15 15 17 27 21 19 21 24 17 10 12 14 19 17 22 18 19 17 28 19 15 14 16 28 17 20 15 11 22 18 19 16 21 17 24 19 22 22 20 10 20 18 18 18 21 18 23 18 32 26 21 21 22 20 22 16 17 20 22 21 17 13 13 11 9 5 0 1 1 1 0.188000 4.300 4.300 10.20 3396610 5 0 0 0 0 0 0 0 0 0 0 0 1 2 3 0 2 5 5 4 3 3 5 1 2 3 6 9 3 3 3 8 7 2 9 5 7 5 11 8 9 7 6 9 6 4 5 8 6 10 9 14 10 15 6 7 13 15 10 13 7 15 10 10 11 14 14 6 7 17 13 19 3 13 9 6 13 13 14 10 11 12 16 17 13 10 15 15 19 19 11 11 15 11 13 9 13 20 8 18 14 18 23 23 23 15 19 20 14 11 7 18 16 15 22 28 20 24 22 25 17 20 39 24 26 25 25 33 25 25 25 33 15 29 18 29 18 12 18 23 17 24 28 22 16 20 33 23 18 23 26 23 15 24 16 16 16 16 17 15 15 16 14 11 9 23 17 13 13 18 12 19 20 30 20 20 15 21 19 16 18 20 23 19 15 10 11 15 19 13 22 22 18 19 16 19 23 16 10 25 23 20 21 20 31 19 19 18 15 22 18 14 13 21 18 19 22 19 16 17 21 14 20 26 18 26 22 19 26 19 20 22 15 13 24 23 15 21 21 21 27 18 22 19 24 17 22 16 18 23 10 12 3 5 3 3 0 0 0.190000 4.350 4.350 10.30 3502025 3 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 2 3 4 4 3 4 5 10 7 6 6 4 5 12 10 6 6 13 10 6 7 14 9 6 13 10 12 16 3 9 9 7 5 6 13 11 10 8 11 19 12 14 13 16 13 14 9 12 14 13 14 16 10 14 7 16 18 16 9 15 11 20 15 10 14 14 11 14 17 10 6 16 10 15 12 17 17 20 15 7 12 23 15 8 13 12 8 16 15 20 16 16 20 14 11 20 24 23 20 16 18 27 25 31 27 27 25 21 31 27 20 23 24 32 17 21 34 27 17 19 19 25 30 27 21 24 28 30 19 26 21 14 16 21 23 27 8 17 21 17 11 23 15 22 15 18 10 17 20 23 18 18 17 19 22 15 22 21 19 23 18 18 26 17 18 26 18 24 15 22 23 23 19 23 25 23 24 26 10 21 16 32 23 18 19 24 21 28 26 22 19 19 14 30 21 24 23 22 21 13 27 20 27 24 15 20 22 22 13 25 14 19 32 21 18 18 23 22 22 14 18 20 24 14 19 20 18 17 24 29 27 20 12 18 17 11 9 2 3 2 1 0 0.192000 4.400 4.400 10.40 3593938 3 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 2 3 4 7 8 1 5 6 8 3 7 5 4 9 8 8 7 7 9 7 9 9 15 5 7 8 15 14 9 9 13 8 8 15 10 7 10 9 10 14 7 8 18 16 17 11 14 15 13 8 15 8 15 18 16 16 22 12 8 16 13 10 13 13 10 21 11 10 16 16 13 13 17 16 20 23 13 22 16 14 15 22 19 22 15 22 24 16 16 16 19 12 15 16 17 20 18 19 26 17 23 18 32 20 28 36 22 25 30 29 31 36 24 24 21 29 24 32 29 30 23 34 19 33 34 25 20 31 27 24 16 14 21 20 13 24 17 28 13 24 16 26 15 26 21 11 15 20 13 20 18 25 23 18 24 26 22 16 22 14 13 16 20 24 25 19 29 20 15 20 16 25 26 21 22 17 24 22 21 17 23 23 15 19 30 23 17 21 19 18 21 26 14 29 24 20 33 19 15 20 23 28 19 23 25 15 19 17 31 23 18 29 26 25 14 24 25 18 19 19 24 35 31 23 23 14 15 19 11 20 19 24 17 16 9 10 12 3 2 2 0 1 0.194000 4.450 4.450 10.50 3712573 7 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 5 3 5 4 3 11 3 10 4 6 7 8 5 5 5 8 9 12 7 7 11 8 6 7 9 10 13 10 6 13 9 9 9 11 14 14 12 13 10 6 13 13 15 12 13 19 8 14 13 16 11 13 14 15 9 15 16 13 16 17 17 17 23 18 16 19 10 13 18 16 10 9 21 11 22 14 20 14 18 13 15 12 13 14 16 14 15 20 29 17 14 18 8 15 21 15 19 15 22 20 17 15 23 26 16 26 24 23 23 23 23 30 24 29 28 26 35 33 31 22 23 22 20 37 22 27 33 26 27 26 17 16 18 27 22 21 24 18 18 18 17 15 18 14 19 24 22 15 20 21 15 19 25 15 16 26 19 22 29 20 16 13 15 16 32 24 23 13 33 17 22 18 18 23 24 22 21 20 26 21 16 22 18 18 16 15 26 26 17 22 21 13 25 24 13 23 18 18 25 32 20 24 21 17 19 24 24 23 33 19 19 21 32 18 22 23 19 23 32 18 31 22 25 23 23 31 29 21 16 20 20 15 22 14 12 5 10 9 2 1 0 1 0.196000 4.500 4.500 10.60 3829518 3 0 0 0 0 0 0 0 0 0 0 1 2 2 1 6 2 6 5 9 3 5 6 8 6 3 8 10 7 11 9 4 8 9 5 11 10 13 9 16 13 10 9 5 12 9 15 10 13 9 12 18 14 19 9 13 14 12 13 21 17 17 18 16 13 12 16 14 18 10 15 15 16 11 15 22 17 19 17 11 12 26 12 17 19 18 21 20 27 17 18 19 21 14 19 16 12 16 21 20 18 8 17 17 13 13 18 15 19 15 19 20 28 21 29 27 27 34 24 26 31 25 24 16 17 23 23 30 28 18 28 32 28 37 18 26 18 16 33 21 31 21 20 22 19 20 25 18 18 20 11 17 20 22 23 14 14 17 18 20 25 20 19 20 22 19 16 33 25 21 21 24 18 16 22 29 22 16 27 26 28 21 20 22 17 25 23 20 23 18 16 19 26 22 21 22 23 15 20 19 17 23 19 20 15 22 18 22 26 23 23 31 17 29 18 13 15 19 18 24 22 28 22 17 23 24 26 21 23 25 24 29 26 18 41 24 29 22 27 23 28 16 30 24 18 23 19 17 18 21 17 14 8 2 5 2 0 0 0.198000 4.550 4.550 10.70 3950740 3 0 0 0 0 0 0 0 0 0 1 1 1 2 1 3 7 5 6 7 7 7 4 5 6 4 1 8 9 10 9 8 10 8 12 6 10 8 10 8 11 9 10 15 7 11 8 13 11 13 15 15 17 12 10 8 17 12 9 14 12 14 11 14 21 14 15 20 18 16 8 15 22 24 14 10 18 14 15 16 12 10 16 21 16 25 17 20 17 17 20 15 24 15 17 22 25 17 13 22 18 20 19 11 21 22 21 16 21 24 16 22 17 21 17 24 22 24 35 27 24 28 24 32 37 34 25 24 29 37 37 25 28 21 23 24 22 21 20 25 22 32 19 21 22 24 20 21 20 22 18 27 17 14 20 22 22 22 14 19 20 20 21 23 22 14 20 21 23 20 18 23 20 25 31 24 18 22 14 23 22 21 23 27 27 20 21 18 22 23 24 23 21 18 22 17 22 21 35 15 24 24 12 27 30 27 28 22 31 24 24 19 27 24 28 23 25 26 35 27 22 29 21 24 18 19 26 33 29 31 23 25 19 24 26 21 10 23 24 26 28 20 27 26 17 29 22 18 14 22 8 10 11 4 4 1 2 0 0.200000 4.600 4.600 10.80 4068161 5 0 0 0 0 0 0 0 0 0 0 1 1 0 1 5 5 2 9 3 11 6 9 8 7 7 8 3 3 13 10 8 7 5 8 13 8 7 14 12 10 7 15 13 13 11 12 12 14 12 13 12 10 15 11 14 7 16 15 8 15 13 15 13 18 13 17 21 15 12 13 13 17 18 18 18 16 19 20 17 14 17 24 13 12 18 19 19 13 21 18 26 21 23 16 14 18 19 13 33 13 19 20 14 20 23 14 26 19 22 21 21 16 27 30 25 28 22 32 21 30 27 31 21 30 22 27 27 31 27 21 17 38 41 17 21 20 19 30 24 27 20 20 21 30 20 19 19 31 25 24 13 21 23 19 24 33 24 17 20 17 12 25 23 18 24 11 24 25 22 33 20 11 22 31 21 20 26 27 21 26 24 14 23 23 20 20 26 28 10 20 27 24 22 17 27 28 20 23 23 33 20 24 26 32 33 29 21 25 24 17 18 19 27 26 20 24 26 24 24 26 21 19 24 21 36 32 18 33 33 20 23 25 33 19 27 25 27 24 27 21 21 23 28 18 27 25 19 24 15 17 12 15 7 2 1 0 0 ", "%f ", Inf); %! assert (rows (x) == n); +## Test input validation +%!error sscanf () +%!error sscanf (1, "2") +%!error