annotate libgui/graphics/qt-graphics-toolkit.h @ 27645:028205a91a07

eliminate global access to Octave resources in qt graphics classes Provide reference to base_qobject to qt graphics classes to eliminate need for accessing it through a global variable. * qt-graphics-toolkit.h, qt-graphics-toolkit.cc (qt_graphics_toolkit::m_octave_qobj): New member variable. (qt_graphics_toolkit::qt_graphics_toolkit): Accept reference to base_qobject as argument. (qt_graphics_toolkit::create_object): Pass m_octave_qobj to create functions for individual graphics objects. * __init_qt__.cc (__init__): Temporarily access base_qobject by calling octave::base_qobject::the_octave_qobject. Pass it to qt_graphics_toolkit constructor. * BaseControl.h, BaseControl.cc, ButtonControl.h, ButtonControl.cc, ButtonGroup.h, ButtonGroup.cc, Canvas.h, Canvas.cc, CheckBoxControl.h, CheckBoxControl.cc, Container.h, Container.cc, ContextMenu.h, ContextMenu.cc, EditControl.h, EditControl.cc, Figure.h, Figure.cc, GLCanvas.h, GLCanvas.cc, ListBoxControl.h, ListBoxControl.cc, Menu.h, Menu.cc, Panel.h, Panel.cc, PopupMenuControl.h, PopupMenuControl.cc, PushButtonControl.h, PushButtonControl.cc, PushTool.h, PushTool.cc, RadioButtonControl.h, RadioButtonControl.cc, SliderControl.h, SliderControl.cc, Table.h, Table.cc, TextControl.h, TextControl.cc, ToggleButtonControl.h, ToggleButtonControl.cc, ToggleTool.h, ToggleTool.cc, ToolBar.h, ToolBar.cc, ToolBarButton.h, ToolBarButton.cc, annotation-dialog.h, annotation-dialog.cc: Accept reference to base_qobject in create function and constructors for graphics objects. Eliminate global access to GUI resources.
author John W. Eaton <jwe@octave.org>
date Tue, 05 Nov 2019 13:28:45 -0500
parents 6b2d20317b26
children b442ec6dda5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25799
diff changeset
3 Copyright (C) 2011-2019 Michael Goffioul
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
5 This file is part of Octave.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23535
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22413
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23535
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22413
diff changeset
10 (at your option) any later version.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22413
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22413
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22413
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22413
diff changeset
15 GNU General Public License for more details.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23535
diff changeset
19 <https://www.gnu.org/licenses/>.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
27317
718116e9c7d3 rename Backend to qt_graphics_toolkit
John W. Eaton <jwe@octave.org>
parents: 27316
diff changeset
23 #if ! defined (octave_qt_graphics_toolkit_h)
718116e9c7d3 rename Backend to qt_graphics_toolkit
John W. Eaton <jwe@octave.org>
parents: 27316
diff changeset
24 #define octave_qt_graphics_toolkit_h 1
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #include <QObject>
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
27303
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
28 #include "event-manager.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "graphics.h"
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
27303
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
31 namespace octave
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
32 {
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
33 class interpreter;
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
34 class base_qobject;
27303
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
35 }
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
36
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 namespace QtHandles
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 {
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
39 class Object;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
40 class ObjectProxy;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
27317
718116e9c7d3 rename Backend to qt_graphics_toolkit
John W. Eaton <jwe@octave.org>
parents: 27316
diff changeset
42 class qt_graphics_toolkit : public QObject, public base_graphics_toolkit
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
43 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
44 Q_OBJECT
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
46 public:
27316
22265a75be74 eliminate static instance of Qt graphics ObjectFactory class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
47
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
48 qt_graphics_toolkit (octave::interpreter& interp,
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
49 octave::base_qobject& oct_qobj);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
27318
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
51 ~qt_graphics_toolkit (void) = default;
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
52
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
53 // The interpreter may call graphics toolkit functions that we
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
54 // implement here. The Qt GUI that manages these actions runs in a
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
55 // separate thread. So in order to correctly cross from the
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
56 // interpreter thread to the GUI thread, these functions should emit
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
57 // signals (in the interpreter thread) that are handled by slots
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
58 // that will run in the GUI thread. This design is similar to the
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
59 // event_manager, interpreter_events, and qt_interpreter_events
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
60 // classes work to pass messages from the interpreter to the GUI.
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
61 //
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
62 // FIXME: currently most of these functions do not emit signals.
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
63 // They may work because they use locking and the gh_manager class,
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
64 // but it might be better to use Qt signals and slots. In any case,
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
65 // we should ensure that they are correctly handling the connection
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
66 // between the interpreter and GUI threads.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
68 bool is_valid (void) const { return true; }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
70 void redraw_figure (const graphics_object& h) const;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
25799
d04b74f5d02e make shg and figure (N) activate and raise figure windows (bug #45943)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
72 void show_figure (const graphics_object& h) const;
d04b74f5d02e make shg and figure (N) activate and raise figure windows (bug #45943)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
73
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
74 void update (const graphics_object& obj, int pId);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
76 bool initialize (const graphics_object& obj);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
78 void finalize (const graphics_object& obj);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
80 void print_figure (const graphics_object& go,
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
81 const std::string& term,
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
82 const std::string& file_cmd,
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
83 const std::string& /*debug_file*/) const;
19681
35bca657d74d printing for Qt plot widget (bug #42537)
John W. Eaton <jwe@octave.org>
parents: 19595
diff changeset
84
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
85 uint8NDArray get_pixels (const graphics_object& go) const;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
86
27254
e3d886685813 Let graphics toolkit compute the extent of uicontrol text strings (bug #48446)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
87 Matrix get_text_extent (const graphics_object& go) const;
e3d886685813 Let graphics toolkit compute the extent of uicontrol text strings (bug #48446)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
88
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
89 static Object * toolkitObject (const graphics_object& go);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
91 static ObjectProxy * toolkitObjectProxy (const graphics_object& go);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
93 signals:
27318
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
94
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
95 void create_object_signal (double handle);
27303
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
96
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
97 public slots:
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
98
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
99 void interpreter_event (const octave::fcn_callback& fcn);
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
100 void interpreter_event (const octave::meth_callback& meth);
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
101
27318
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
102 void create_object (double handle);
ae53e56e16f2 eliminate separate ObjectFactory class in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27317
diff changeset
103
27319
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
104 void gh_callback_event (const graphics_handle& h, const std::string& name);
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
105
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
106 void gh_callback_event (const graphics_handle& h, const std::string& name,
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
107 const octave_value& data);
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
108
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
109 void gh_set_event (const graphics_handle& h, const std::string& name,
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
110 const octave_value& value);
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
111
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
112 void gh_set_event (const graphics_handle& h, const std::string& name,
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
113 const octave_value& value, bool notify_toolkit);
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
114
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
115 void gh_set_event (const graphics_handle& h, const std::string& name,
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
116 const octave_value& value, bool notify_toolkit,
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27318
diff changeset
117 bool redraw_figure);
27303
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
118 private:
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
119
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27254
diff changeset
120 octave::interpreter& m_interpreter;
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
121
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
122 octave::base_qobject& m_octave_qobj;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
123 };
22413
8758addcf265 maint: Remove ';' at end of namespace declaration.
Rik <rik@octave.org>
parents: 22411
diff changeset
124 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125
19595
be7ac98fab43 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18501
diff changeset
126 #endif