annotate libgui/graphics/PopupMenuControl.cc @ 27319:6b2d20317b26

use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit Limit access to the gh_manager object to the qt_graphics_toolkit class by using Qt signals to pass gh_manager events from individual graphics objects up to the qt_graphics_toolkit object. From there, we can make calls to the gh_manager object. * qt-graphics-toolkit.h, qt-graphics-toolkit.cc (qt_graphics_toolkit::gh_callback_event, qt_graphics_toolkit::gh_set_event): New slots. (qt_graphics_toolkit::create_object): Connect Object::gh_callback_event and Object::gh_set_event signals to qt_graphics_toolkit::gh_callback_event and qt_graphics_toolkit::gh_set_event slots. * BaseControl.cc, ButtonControl.cc, ButtonGroup.cc, Canvas.cc, ContextMenu.cc, EditControl.cc, Figure.cc, ListBoxControl.cc, Menu.cc, PopupMenuControl.cc, PushTool.cc, SliderControl.cc, Table.cc, ToggleTool.cc: Emit gh_callback_event and gh_set_event signals instead of calling gh_manager functions directly. * Object.h (Object::gh_callback_event, Object::gh_set_event): New signals. * Canvas.h (Canvas::gh_callback_event, Canvas::gh_set_event): New signals. * Container.h (Container::gh_callback_event, Container::gh_set_event): New signals.
author John W. Eaton <jwe@octave.org>
date Fri, 02 Aug 2019 15:19:43 -0500
parents 00f796120a6d
children 028205a91a07
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: 25688
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: 23795
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: 22726
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: 23795
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: 22726
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: 22726
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: 22726
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22726
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22726
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: 23795
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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21568
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
24 # include "config.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include <QComboBox>
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "Container.h"
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "PopupMenuControl.h"
18505
fb96b7f55242 rename file to avoid clash on case-insenstive filesystems (bug #41658)
John W. Eaton <jwe@octave.org>
parents: 18501
diff changeset
31 #include "QtHandlesUtils.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 namespace QtHandles
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
36 PopupMenuControl*
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
37 PopupMenuControl::create (const graphics_object& go)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
38 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
39 Object *parent = Object::parentObject (go);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
41 if (parent)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
42 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
43 Container *container = parent->innerContainer ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
45 if (container)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
46 return new PopupMenuControl (go, new QComboBox (container));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
47 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23449
diff changeset
49 return nullptr;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
50 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
52 PopupMenuControl::PopupMenuControl (const graphics_object& go, QComboBox *box)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
53 : BaseControl (go, box), m_blockUpdate (false)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
54 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
55 uicontrol::properties& up = properties<uicontrol> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
57 box->addItems (Utils::fromStdString (up.get_string_string ()).split ('|'));
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
59 update (uicontrol::properties::ID_VALUE);
20010
b08c13ed4a8c Qt PopupMenuControl: son creation se index to Value, and dont fire callback on programatic value set (Bug #44687)
John Donoghue
parents: 20003
diff changeset
60
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
61 connect (box, SIGNAL (activated (int)),
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
62 SLOT (currentIndexChanged (int)));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
63 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
65 PopupMenuControl::~PopupMenuControl (void)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22413
diff changeset
66 { }
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 void PopupMenuControl::update (int pId)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
69 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
70 uicontrol::properties& up = properties<uicontrol> ();
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
71 QComboBox *box = qWidget<QComboBox> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
73 switch (pId)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
74 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
75 case uicontrol::properties::ID_STRING:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
76 m_blockUpdate = true;
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
77 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
78 int oldCurrent = box->currentIndex ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
80 box->clear ();
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
81 box->addItems (Utils::fromStdString
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
82 (up.get_string_string ()).split ('|'));
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
83 if (box->count () > 0
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
84 && oldCurrent >= 0
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
85 && oldCurrent < box->count ())
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
86 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
87 box->setCurrentIndex (oldCurrent);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
88 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
89 else
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
90 {
27319
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
91 emit gh_set_event (m_handle, "value",
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
92 octave_value (box->count () > 0 ? 1.0 : 0.0),
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
93 false);
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
94 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
95 }
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
96 m_blockUpdate = false;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
97 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
98
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
99 case uicontrol::properties::ID_VALUE:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
100 m_blockUpdate = true;
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
101 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
102 Matrix value = up.get_value ().matrix_value ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
104 if (value.numel () > 0)
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
105 {
25688
b2917b7858ba maint: Use Octave convention for spacing of C++ cast statements.
Rik <rik@octave.org>
parents: 25054
diff changeset
106 if (value(0) != static_cast<int> (value(0)))
20022
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
107 warning ("popupmenu value should be integer");
20015
519eb032ac35 Check value set for PopuMenuControl and ButtonControl
John Donoghue
parents: 20010
diff changeset
108 else
20022
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
109 {
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
110 int newIndex = int (value(0)) - 1;
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
111
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
112 if (newIndex >= 0 && newIndex < box->count ())
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
113 {
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
114 if (newIndex != box->currentIndex ())
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
115 box->setCurrentIndex (newIndex);
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
116 }
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
117 else
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
118 warning ("popupmenu value not within valid display range");
5bd3216748fc PopupMenuControl: check value is integer (Bug #44678)
John Donoghue
parents: 20021
diff changeset
119 }
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
120 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
121 }
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
122 m_blockUpdate = false;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
123 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
124
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
125 default:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
126 BaseControl::update (pId);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
127 break;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
128 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
129 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
131 void
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
132 PopupMenuControl::currentIndexChanged (int index)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
133 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
134 if (! m_blockUpdate)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
135 {
27319
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
136 emit gh_set_event (m_handle, "value", octave_value (double (index + 1)),
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
137 false);
6b2d20317b26 use Qt signals to manage calls to gh_manager functions in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
138 emit gh_callback_event (m_handle, "callback");
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
139 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
140 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141
22413
8758addcf265 maint: Remove ';' at end of namespace declaration.
Rik <rik@octave.org>
parents: 22411
diff changeset
142 }