annotate libgui/graphics/ListBoxControl.cc @ 31639:ca7d58406f82

eliminate unnecessary uses of octave_qobject in GUI classes * BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h, ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h, CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h, ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h, Figure.cc, Figure.h, GLCanvas.cc, GLCanvas.h, ListBoxControl.cc, ListBoxControl.h, Menu.cc, Menu.h, Object.cc, Object.h, Panel.cc, Panel.h, PopupMenuControl.cc, PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h, PushTool.cc, PushTool.h, RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc, SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h, ToggleButtonControl.cc, ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc, ToolBar.h, ToolBarButton.cc, ToolBarButton.h, annotation-dialog.cc, annotation-dialog.h, qt-graphics-toolkit.cc, qt-graphics-toolkit.h, command-widget.h, community-news.cc, community-news.h, documentation-bookmarks.cc, documentation-bookmarks.h, documentation.cc, external-editor-interface.cc, external-editor-interface.h, find-files-dialog.cc, find-files-dialog.h, graphics-init.cc, graphics-init.h, interpreter-qobject.cc, file-editor.cc, find-dialog.cc, find-dialog.h, main-window.cc, main-window.h, news-reader.cc, news-reader.h, octave-qobject.cc, release-notes.cc, resource-manager.cc, set-path-dialog.cc, set-path-dialog.h, shortcut-manager.cc, shortcut-manager.h, welcome-wizard.cc, welcome-wizard.h, workspace-model.cc: Don't store references to octave_qobject in GUI classes where it is no longer needed. Eliminate unnecessary octave_qobject constructor arguments. Change all uses.
author John W. Eaton <jwe@octave.org>
date Sun, 04 Dec 2022 22:57:02 -0500
parents 796f54d4ddbf
children 431f80aba37a
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
29992
6ea4a84df9c7 rename QtHandles namespace to octave
John W. Eaton <jwe@octave.org>
parents: 29905
diff changeset
38 namespace octave
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 {
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 static void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
42 updateSelection (QListWidget *list, const Matrix& value)
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 octave_idx_type n = value.numel ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
45 int lc = list->count ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
47 list->clearSelection ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
49 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
50 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
51 int idx = octave::math::round (value(i));
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
53 if (1 <= idx && idx <= lc)
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 list->item (idx-1)->setSelected (true);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
56 list->scrollToItem (list->item (idx-1));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
57 if (i == 0
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
58 && list->selectionMode () == QAbstractItemView::SingleSelection)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
59 break;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
60 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
61 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
62 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
63 // Invalid selection.
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
64 list->clearSelection ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 break;
22411
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 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
68 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29992
diff changeset
70 ListBoxControl *
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
71 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
72 const graphics_object& go)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
73 {
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
74 Object *parent = parentObject (interp, go);
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 if (parent)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
77 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
78 Container *container = parent->innerContainer ();
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 if (container)
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
81 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
82 new QListWidget (container));
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
83 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23449
diff changeset
85 return nullptr;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
86 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
88 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
89 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
90 : 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
91 m_selectionChanged (false)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
92 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
93 uicontrol::properties& up = properties<uicontrol> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
95 list->addItems (Utils::fromStringVector (up.get_string_vector ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
96 if ((up.get_max () - up.get_min ()) > 1)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
97 list->setSelectionMode (QAbstractItemView::ExtendedSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
98 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
99 list->setSelectionMode (QAbstractItemView::SingleSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
100 Matrix value = up.get_value ().matrix_value ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
101 if (value.numel () > 0)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
102 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
103 octave_idx_type n = value.numel ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
104 int lc = list->count ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
106 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
107 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
108 int idx = octave::math::round (value(i));
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
110 if (1 <= idx && idx <= lc)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
111 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
112 list->item (idx-1)->setSelected (true);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
113 list->scrollToItem (list->item (idx-1));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
114 if (i == 0 && (list->selectionMode ()
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
115 == QAbstractItemView::SingleSelection))
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
116 break;
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 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
119 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
121 list->viewport ()->installEventFilter (this);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
123 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
124 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
125 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
126 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
127 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
128 this, &ListBoxControl::itemPressed);
22411
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 ListBoxControl::~ListBoxControl (void)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22413
diff changeset
132 { }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
134 void
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
135 ListBoxControl::update (int pId)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
136 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
137 uicontrol::properties& up = properties<uicontrol> ();
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
138 QListWidget *list = qWidget<QListWidget> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
140 switch (pId)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
141 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
142 case uicontrol::properties::ID_STRING:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
143 m_blockCallback = true;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
144 list->clear ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
145 list->addItems (Utils::fromStringVector (up.get_string_vector ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
146 updateSelection (list, up.get_value ().matrix_value ());
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
147 m_blockCallback = false;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
148 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
149
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
150 case uicontrol::properties::ID_MIN:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
151 case uicontrol::properties::ID_MAX:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
152 if ((up.get_max () - up.get_min ()) > 1)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
153 list->setSelectionMode (QAbstractItemView::ExtendedSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
154 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
155 list->setSelectionMode (QAbstractItemView::SingleSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
156 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
157
29905
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
158 case uicontrol::properties::ID_LISTBOXTOP:
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
159 {
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
160 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
161 if (idx > 0)
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
162 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
163 QAbstractItemView::PositionAtTop);
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
164 break;
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
165 }
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
166
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
167 case uicontrol::properties::ID_VALUE:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
168 m_blockCallback = true;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
169 updateSelection (list, up.get_value ().matrix_value ());
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
170 m_blockCallback = false;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
171 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
172
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
173 default:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
174 BaseControl::update (pId);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
175 break;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
176 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
177 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
179 void
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
180 ListBoxControl::sendSelectionChange ()
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
181 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
182 if (! m_blockCallback)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
183 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
184 QListWidget *list = qWidget<QListWidget> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
186 QModelIndexList l = list->selectionModel ()->selectedIndexes ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
187 Matrix value (dim_vector (1, l.size ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
188 int i = 0;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189
27677
92fea2cd024f use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27647
diff changeset
190 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
191 value(i++) = idx.row () + 1;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192
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
193 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
194 emit gh_callback_event (m_handle, "callback");
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
195 }
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
196
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
197 m_selectionChanged = false;
22726
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
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
200 void
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
201 ListBoxControl::itemSelectionChanged (void)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
202 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
203 if (! m_blockCallback)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
204 m_selectionChanged = true;
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
205 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
206
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
207 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
208 ListBoxControl::itemActivated (const QModelIndex&)
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
209 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
210 m_selectionChanged = true;
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
211 }
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
212 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
213 ListBoxControl::itemPressed (QListWidgetItem *)
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
214 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
215 m_selectionChanged = true;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
216 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
218 bool
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
219 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
220 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
221 // listbox change
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
222 if (watched == m_qobject)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
223 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
224 switch (e->type ())
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
225 {
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
226 case QEvent::KeyRelease:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
227 if (m_selectionChanged)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
228 sendSelectionChange ();
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
229 m_selectionChanged = false;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
230 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
231
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
232 default:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
233 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
234 }
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
235
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
236 return Object::eventFilter (watched, e);
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
237 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
238 // listbox viewport
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
239 else
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
240 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
241 bool override_return = false;
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
242 QListWidget *list = qWidget<QListWidget> ();
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
243
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
244 switch (e->type ())
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
245 {
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
246 case QEvent::MouseButtonPress:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
247 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
248 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
249
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
250 if (m->button () & Qt::RightButton)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
251 override_return = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
252 else
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
253 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
254 if (! list->indexAt (m->pos ()).isValid ())
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
255 override_return = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
256 m_selectionChanged = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
257 }
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
258 break;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
259 }
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
260 case QEvent::MouseButtonRelease:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
261 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
262 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
263
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
264 if (m->button () & Qt::RightButton)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
265 override_return = true;
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
266
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
267 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
268 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
269 list->setCurrentRow (list->count () - 1);
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
270 override_return = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
271 }
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
272
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
273 if (m_selectionChanged)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
274 sendSelectionChange ();
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
275 m_selectionChanged = false;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
276
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
277 break;
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
278 }
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
279 default:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
280 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
281
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
282 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
283 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
284 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
285 }
22413
8758addcf265 maint: Remove ';' at end of namespace declaration.
Rik <rik@octave.org>
parents: 22411
diff changeset
286 }