annotate libgui/graphics/ListBoxControl.cc @ 30398:d4d83344d653 stable

maint: style check C++ files in src/ and libgui/ ahead of 7.1 release. * ButtonGroup.cc, Canvas.cc, CheckBoxControl.cc, Container.cc, ContextMenu.cc, EditControl.cc, Figure.cc, Figure.h, FigureWindow.cc, GenericEventNotify.h, ListBoxControl.cc, ListBoxControl.h, Logger.cc, Menu.cc, Object.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc, PushTool.cc, RadioButtonControl.cc, SliderControl.cc, Table.cc, Table.h, TextControl.cc, ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, annotation-dialog.cc, qt-graphics-toolkit.cc, documentation-bookmarks.cc, documentation-bookmarks.h, documentation-dock-widget.h, documentation.cc, documentation.h, dw-main-window.h, files-dock-widget.cc, files-dock-widget.h, find-files-dialog.cc, find-files-model.cc, gui-preferences-dw.h, gui-preferences-ed.h, gui-preferences-global.h, gui-settings.h, interpreter-qobject.cc, led-indicator.cc, file-editor-interface.h, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc, find-dialog.h, marker.cc, octave-qscintilla.cc, octave-qscintilla.h, main-window.cc, main-window.h, octave-dock-widget.cc, octave-dock-widget.h, octave-qobject.cc, octave-qobject.h, octave-qtutils.h, qt-interpreter-events.cc, release-notes.cc, resource-manager.cc, set-path-dialog.cc, settings-dialog.cc, settings-dialog.h, shortcut-manager.cc, shortcut-manager.h, tab-bar.cc, tab-bar.h, variable-editor-model.cc, variable-editor-model.h, variable-editor.cc, variable-editor.h, workspace-model.cc, workspace-view.cc, mkoctfile.in.cc, octave-config.in.cc: Style check C++ files in src/ and libgui/ ahead of 7.1 release.
author Rik <rik@octave.org>
date Mon, 29 Nov 2021 15:58:51 -0800
parents 6ea4a84df9c7
children 796f54d4ddbf
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 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 // Copyright (C) 2011-2021 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
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
38 #include "octave-qobject.h"
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
39
29992
6ea4a84df9c7 rename QtHandles namespace to octave
John W. Eaton <jwe@octave.org>
parents: 29905
diff changeset
40 namespace octave
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
43 static void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
44 updateSelection (QListWidget *list, const Matrix& value)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
45 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
46 octave_idx_type n = value.numel ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
47 int lc = list->count ();
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 list->clearSelection ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
51 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
52 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
53 int idx = octave::math::round (value(i));
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
55 if (1 <= idx && idx <= lc)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
56 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
57 list->item (idx-1)->setSelected (true);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
58 list->scrollToItem (list->item (idx-1));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
59 if (i == 0
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
60 && list->selectionMode () == QAbstractItemView::SingleSelection)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
61 break;
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 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
64 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
65 // Invalid selection.
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
66 list->clearSelection ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 break;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
68 }
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 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29992
diff changeset
72 ListBoxControl *
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
73 ListBoxControl::create (octave::base_qobject& oct_qobj,
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
74 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
75 const graphics_object& go)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
76 {
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
77 Object *parent = parentObject (interp, go);
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 (parent)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
80 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
81 Container *container = parent->innerContainer ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
83 if (container)
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
84 return new ListBoxControl (oct_qobj, interp, go,
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
85 new QListWidget (container));
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
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23449
diff changeset
88 return nullptr;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
89 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90
27645
028205a91a07 eliminate global access to Octave resources in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27319
diff changeset
91 ListBoxControl::ListBoxControl (octave::base_qobject& oct_qobj,
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
92 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
93 const graphics_object& go, QListWidget *list)
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
94 : BaseControl (oct_qobj, 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
95 m_selectionChanged (false)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
96 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
97 uicontrol::properties& up = properties<uicontrol> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
99 list->addItems (Utils::fromStringVector (up.get_string_vector ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
100 if ((up.get_max () - up.get_min ()) > 1)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
101 list->setSelectionMode (QAbstractItemView::ExtendedSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
102 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
103 list->setSelectionMode (QAbstractItemView::SingleSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
104 Matrix value = up.get_value ().matrix_value ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
105 if (value.numel () > 0)
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 octave_idx_type n = value.numel ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
108 int lc = list->count ();
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 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
111 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
112 int idx = octave::math::round (value(i));
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
114 if (1 <= idx && idx <= lc)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
115 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
116 list->item (idx-1)->setSelected (true);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
117 list->scrollToItem (list->item (idx-1));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
118 if (i == 0 && (list->selectionMode ()
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
119 == QAbstractItemView::SingleSelection))
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
120 break;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
121 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
122 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
123 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
125 list->viewport ()->installEventFilter (this);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126
29542
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::itemSelectionChanged,
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::itemSelectionChanged);
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
129 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
130 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
131 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
132 this, &ListBoxControl::itemPressed);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
133 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
135 ListBoxControl::~ListBoxControl (void)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22413
diff changeset
136 { }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
138 void
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
139 ListBoxControl::update (int 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 uicontrol::properties& up = properties<uicontrol> ();
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
142 QListWidget *list = qWidget<QListWidget> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
144 switch (pId)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
145 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
146 case uicontrol::properties::ID_STRING:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
147 m_blockCallback = true;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
148 list->clear ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
149 list->addItems (Utils::fromStringVector (up.get_string_vector ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
150 updateSelection (list, up.get_value ().matrix_value ());
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
151 m_blockCallback = false;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
152 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
153
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
154 case uicontrol::properties::ID_MIN:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
155 case uicontrol::properties::ID_MAX:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
156 if ((up.get_max () - up.get_min ()) > 1)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
157 list->setSelectionMode (QAbstractItemView::ExtendedSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
158 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
159 list->setSelectionMode (QAbstractItemView::SingleSelection);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
160 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
161
29905
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
162 case uicontrol::properties::ID_LISTBOXTOP:
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
163 {
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
164 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
165 if (idx > 0)
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
166 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
167 QAbstractItemView::PositionAtTop);
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
168 break;
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
169 }
ad023dbe9606 Add support for ListBoxTop property of uicontrol objects (bug #60951)
Rik <rik@octave.org>
parents: 29542
diff changeset
170
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
171 case uicontrol::properties::ID_VALUE:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
172 m_blockCallback = true;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
173 updateSelection (list, up.get_value ().matrix_value ());
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
174 m_blockCallback = false;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
175 break;
19967
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 19866
diff changeset
176
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
177 default:
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
178 BaseControl::update (pId);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
179 break;
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 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
183 void
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
184 ListBoxControl::sendSelectionChange ()
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
185 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
186 if (! m_blockCallback)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
187 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
188 QListWidget *list = qWidget<QListWidget> ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
190 QModelIndexList l = list->selectionModel ()->selectedIndexes ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
191 Matrix value (dim_vector (1, l.size ()));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
192 int i = 0;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193
27677
92fea2cd024f use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27647
diff changeset
194 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
195 value(i++) = idx.row () + 1;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196
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
197 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
198 emit gh_callback_event (m_handle, "callback");
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
199 }
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
200
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
201 m_selectionChanged = false;
22726
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
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
204 void
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
205 ListBoxControl::itemSelectionChanged (void)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
206 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
207 if (! m_blockCallback)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
208 m_selectionChanged = true;
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
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::itemActivated (const QModelIndex&)
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;
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
215 }
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
216 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
217 ListBoxControl::itemPressed (QListWidgetItem *)
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
218 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
219 m_selectionChanged = true;
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
220 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
222 bool
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
223 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
224 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
225 // listbox change
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
226 if (watched == m_qobject)
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
227 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
228 switch (e->type ())
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
229 {
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
230 case QEvent::KeyRelease:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
231 if (m_selectionChanged)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
232 sendSelectionChange ();
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
233 m_selectionChanged = false;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
234 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
235
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
236 default:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
237 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
238 }
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
239
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
240 return Object::eventFilter (watched, e);
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
241 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
242 // listbox viewport
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
243 else
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
244 {
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
245 bool override_return = false;
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
246 QListWidget *list = qWidget<QListWidget> ();
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
247
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
248 switch (e->type ())
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 case QEvent::MouseButtonPress:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
251 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
252 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
253
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
254 if (m->button () & Qt::RightButton)
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 else
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 if (! list->indexAt (m->pos ()).isValid ())
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
259 override_return = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
260 m_selectionChanged = true;
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 break;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
263 }
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
264 case QEvent::MouseButtonRelease:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
265 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
266 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
267
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
268 if (m->button () & Qt::RightButton)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
269 override_return = true;
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
270
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
271 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
272 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
273 list->setCurrentRow (list->count () - 1);
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
274 override_return = true;
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
275 }
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
276
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
277 if (m_selectionChanged)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
278 sendSelectionChange ();
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
279 m_selectionChanged = false;
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 break;
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
282 }
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
283 default:
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
284 break;
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22726
diff changeset
285
22726
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
286 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
287 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
288 }
dd2f547c21a0 QtHandles: firie listbox callback on click of selected item (Bug #44748)
John Donoghue
parents: 22417
diff changeset
289 }
22413
8758addcf265 maint: Remove ';' at end of namespace declaration.
Rik <rik@octave.org>
parents: 22411
diff changeset
290 }