annotate libgui/graphics/ListBoxControl.cc @ 31649:deb553ac2c54

maint: Merge stable to default.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Dec 2022 15:45:27 -0500
parents 431f80aba37a 29d734430e5f
children 5f11de0e7440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30398
diff changeset
3 // Copyright (C) 2011-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
27 # include "config.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <QListWidget>
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
31 #include <QEvent>
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
32 #include <QMouseEvent>
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "Container.h"
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "ListBoxControl.h"
18505
fb96b7f55242 rename file to avoid clash on case-insenstive filesystems (bug #41658)
John W. Eaton <jwe@octave.org>
parents: 18501
diff changeset
36 #include "QtHandlesUtils.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
38 OCTAVE_BEGIN_NAMESPACE(octave)
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
40 static void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
41 updateSelection (QListWidget *list, const Matrix& value)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
42 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
43 octave_idx_type n = value.numel ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
44 int lc = list->count ();
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 list->clearSelection ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
48 for (octave_idx_type i = 0; i < n; i++)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
49 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
50 int idx = octave::math::round (value(i));
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 if (1 <= idx && idx <= lc)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
53 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
54 list->item (idx-1)->setSelected (true);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
55 list->scrollToItem (list->item (idx-1));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
56 if (i == 0
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
57 && list->selectionMode () == QAbstractItemView::SingleSelection)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
58 break;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
59 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
60 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
61 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
62 // Invalid selection.
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
63 list->clearSelection ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 break;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
65 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
66 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
67 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29992
diff changeset
69 ListBoxControl *
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
70 ListBoxControl::create (octave::interpreter& interp,
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
71 const graphics_object& go)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
72 {
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
73 Object *parent = parentObject (interp, go);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
75 if (parent)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
76 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
77 Container *container = parent->innerContainer ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
79 if (container)
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
80 return new ListBoxControl (interp, go,
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
81 new QListWidget (container));
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
82 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23449
diff changeset
84 return nullptr;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
85 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
87 ListBoxControl::ListBoxControl (octave::interpreter& interp,
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
88 const graphics_object& go, QListWidget *list)
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
89 : BaseControl (interp, go, list), m_blockCallback (false),
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
90 m_selectionChanged (false)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
91 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
92 uicontrol::properties& up = properties<uicontrol> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
94 list->addItems (Utils::fromStringVector (up.get_string_vector ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
95 if ((up.get_max () - up.get_min ()) > 1)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
96 list->setSelectionMode (QAbstractItemView::ExtendedSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
97 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
98 list->setSelectionMode (QAbstractItemView::SingleSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
99 Matrix value = up.get_value ().matrix_value ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
100 if (value.numel () > 0)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
101 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
102 octave_idx_type n = value.numel ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
103 int lc = list->count ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
105 for (octave_idx_type i = 0; i < n; i++)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
106 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
107 int idx = octave::math::round (value(i));
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
109 if (1 <= idx && idx <= lc)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
110 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
111 list->item (idx-1)->setSelected (true);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
112 list->scrollToItem (list->item (idx-1));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
113 if (i == 0 && (list->selectionMode ()
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
114 == QAbstractItemView::SingleSelection))
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
115 break;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
116 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
117 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
118 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
120 list->viewport ()->installEventFilter (this);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
122 connect (list, &QListWidget::itemSelectionChanged,
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
123 this, &ListBoxControl::itemSelectionChanged);
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
124 connect (list, &QListWidget::activated,
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
125 this, &ListBoxControl::itemActivated);
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
126 connect (list, &QListWidget::itemPressed,
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
127 this, &ListBoxControl::itemPressed);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
128 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
130 ListBoxControl::~ListBoxControl (void)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22413
diff changeset
131 { }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
133 void
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
134 ListBoxControl::update (int pId)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
135 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
136 uicontrol::properties& up = properties<uicontrol> ();
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
137 QListWidget *list = qWidget<QListWidget> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
139 switch (pId)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
140 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
141 case uicontrol::properties::ID_STRING:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
142 m_blockCallback = true;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
143 list->clear ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
144 list->addItems (Utils::fromStringVector (up.get_string_vector ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
145 updateSelection (list, up.get_value ().matrix_value ());
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
146 m_blockCallback = false;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
147 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
148
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
149 case uicontrol::properties::ID_MIN:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
150 case uicontrol::properties::ID_MAX:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
151 if ((up.get_max () - up.get_min ()) > 1)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
152 list->setSelectionMode (QAbstractItemView::ExtendedSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
153 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
154 list->setSelectionMode (QAbstractItemView::SingleSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
155 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
156
29905
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
157 case uicontrol::properties::ID_LISTBOXTOP:
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
158 {
29905
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
159 int idx = octave::math::fix (up.get_listboxtop ());
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
160 if (idx > 0)
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
161 list->scrollToItem (list->item (idx-1),
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
162 QAbstractItemView::PositionAtTop);
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
163 break;
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
164 }
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
165
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
166 case uicontrol::properties::ID_VALUE:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
167 m_blockCallback = true;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
168 updateSelection (list, up.get_value ().matrix_value ());
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
169 m_blockCallback = false;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
170 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
171
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
172 default:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
173 BaseControl::update (pId);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
174 break;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
175 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
176 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
178 void
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
179 ListBoxControl::sendSelectionChange ()
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
180 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
181 if (! m_blockCallback)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
182 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
183 QListWidget *list = qWidget<QListWidget> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
185 QModelIndexList l = list->selectionModel ()->selectedIndexes ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
186 Matrix value (dim_vector (1, l.size ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
187 int i = 0;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188
27677
92fea2cd024f use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27647
diff changeset
189 for (const auto& idx : l)
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
190 value(i++) = idx.row () + 1;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191
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
192 emit gh_set_event (m_handle, "value", octave_value (value), 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
193 emit gh_callback_event (m_handle, "callback");
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
194 }
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
195
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
196 m_selectionChanged = false;
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
197 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
198
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
199 void
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
200 ListBoxControl::itemSelectionChanged (void)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
201 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
202 if (! m_blockCallback)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
203 m_selectionChanged = true;
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
204 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
205
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
206 void
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29992
diff changeset
207 ListBoxControl::itemActivated (const QModelIndex&)
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
208 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
209 m_selectionChanged = true;
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
210 }
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
211 void
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29992
diff changeset
212 ListBoxControl::itemPressed (QListWidgetItem *)
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
213 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
214 m_selectionChanged = true;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
215 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
217 bool
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
218 ListBoxControl::eventFilter (QObject *watched, QEvent *e)
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
219 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
220 // listbox change
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
221 if (watched == m_qobject)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
222 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
223 switch (e->type ())
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
224 {
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
225 case QEvent::KeyRelease:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
226 if (m_selectionChanged)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
227 sendSelectionChange ();
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
228 m_selectionChanged = false;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
229 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
230
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
231 default:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
232 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
233 }
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
234
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
235 return Object::eventFilter (watched, e);
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
236 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
237 // listbox viewport
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
238 else
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
239 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
240 bool override_return = false;
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
241 QListWidget *list = qWidget<QListWidget> ();
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
242
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
243 switch (e->type ())
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
244 {
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
245 case QEvent::MouseButtonPress:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
246 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
247 QMouseEvent *m = dynamic_cast<QMouseEvent *> (e);
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
248
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
249 if (m->button () & Qt::RightButton)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
250 override_return = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
251 else
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
252 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
253 if (! list->indexAt (m->pos ()).isValid ())
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
254 override_return = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
255 m_selectionChanged = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
256 }
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
257 break;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
258 }
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
259 case QEvent::MouseButtonRelease:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
260 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
261 QMouseEvent *m = dynamic_cast<QMouseEvent *> (e);
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
262
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
263 if (m->button () & Qt::RightButton)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
264 override_return = true;
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
265
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
266 else if (! list->indexAt (m->pos ()).isValid ())
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
267 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
268 list->setCurrentRow (list->count () - 1);
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
269 override_return = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
270 }
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
271
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
272 if (m_selectionChanged)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
273 sendSelectionChange ();
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
274 m_selectionChanged = false;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
275
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
276 break;
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
277 }
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
278 default:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
279 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
280
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
281 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
282 return BaseControl::eventFilter (watched, e) || override_return;
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
283 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
284 }
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
285
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
286 OCTAVE_END_NAMESPACE(octave)