annotate libgui/graphics/PopupMenuControl.cc @ 20050:519eb032ac35

Check value set for PopuMenuControl and ButtonControl * libgui/graphics/ButtonControl.cc (ButtonControl::update) if toggle button, check value is 0 or 1 and warn otherwise * libgui/graphics/PopupMenuControl.cc (PopupMenuControl::update) if value is outside valid index, show warning
author John Donoghue
date Thu, 02 Apr 2015 13:08:56 -0400
parents b08c13ed4a8c
children e70df1ff58b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
20038
f0e61a67ad9f Update copyright year in Qt graphics code.
John W. Eaton <jwe@octave.org>
parents: 20002
diff changeset
3 Copyright (C) 2011-2015 Michael Goffioul
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
5 This file is part of Octave.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
8 under the terms of the GNU General Public License as published by the
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
10 option) any later version.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
15 for more details.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
18 along with Octave; see the file COPYING. If not, see
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
19 <http://www.gnu.org/licenses/>.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 #include <config.h>
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include <QComboBox>
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "Container.h"
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "PopupMenuControl.h"
18505
fb96b7f55242 rename file to avoid clash on case-insenstive filesystems (bug #41658)
John W. Eaton <jwe@octave.org>
parents: 18501
diff changeset
31 #include "QtHandlesUtils.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 namespace QtHandles
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
20002
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
36 PopupMenuControl*
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
37 PopupMenuControl::create (const graphics_object& go)
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 Object* parent = Object::parentObject (go);
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 if (parent)
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 Container* container = parent->innerContainer ();
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 if (container)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
46 return new PopupMenuControl (go, new QComboBox (container));
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 }
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 return 0;
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 }
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 PopupMenuControl::PopupMenuControl (const graphics_object& go, QComboBox *box)
20002
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
53 : BaseControl (go, box), m_blockUpdate (false)
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 uicontrol::properties& up = properties<uicontrol> ();
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 box->addItems (Utils::fromStdString (up.get_string_string ()).split ('|'));
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
20045
b08c13ed4a8c Qt PopupMenuControl: son creation se index to Value, and dont fire callback on programatic value set (Bug #44687)
John Donoghue
parents: 20038
diff changeset
59 update (uicontrol::properties::ID_VALUE);
b08c13ed4a8c Qt PopupMenuControl: son creation se index to Value, and dont fire callback on programatic value set (Bug #44687)
John Donoghue
parents: 20038
diff changeset
60
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 connect (box, SIGNAL (currentIndexChanged (int)),
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
62 SLOT (currentIndexChanged (int)));
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 }
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 PopupMenuControl::~PopupMenuControl (void)
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 }
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 void PopupMenuControl::update (int pId)
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 uicontrol::properties& up = properties<uicontrol> ();
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 QComboBox* box = qWidget<QComboBox> ();
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 switch (pId)
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 case uicontrol::properties::ID_STRING:
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 m_blockUpdate = true;
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
78 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
79 int oldCurrent = box->currentIndex ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
81 box->clear ();
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
82 box->addItems (Utils::fromStdString
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
83 (up.get_string_string ()).split ('|'));
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
84 if (box->count() > 0
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
85 && oldCurrent >= 0
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
86 && oldCurrent < box->count ())
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
87 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
88 box->setCurrentIndex (oldCurrent);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
89 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
90 else
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
91 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
92 gh_manager::post_set (m_handle, "value",
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
93 octave_value (box->count () > 0
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
94 ? 1.0 : 0.0),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
95 false);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
96 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
97 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 m_blockUpdate = false;
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 break;
20002
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
100
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 case uicontrol::properties::ID_VALUE:
20045
b08c13ed4a8c Qt PopupMenuControl: son creation se index to Value, and dont fire callback on programatic value set (Bug #44687)
John Donoghue
parents: 20038
diff changeset
102 m_blockUpdate = true;
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
103 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
104 Matrix value = up.get_value ().matrix_value ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
106 if (value.numel () > 0)
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
107 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
108 int newIndex = int (value(0)) - 1;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
110 if (newIndex >= 0 && newIndex < box->count ()
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
111 && newIndex != box->currentIndex ())
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
112 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
113 box->setCurrentIndex (newIndex);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
114 }
20050
519eb032ac35 Check value set for PopuMenuControl and ButtonControl
John Donoghue
parents: 20045
diff changeset
115 else
519eb032ac35 Check value set for PopuMenuControl and ButtonControl
John Donoghue
parents: 20045
diff changeset
116 warning ("popupmenu value not within valid display range");
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
117 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
118 }
20045
b08c13ed4a8c Qt PopupMenuControl: son creation se index to Value, and dont fire callback on programatic value set (Bug #44687)
John Donoghue
parents: 20038
diff changeset
119 m_blockUpdate = false;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 break;
20002
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
121
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 default:
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 BaseControl::update (pId);
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 break;
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 }
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 }
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127
20002
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
128 void
3cc0734283dc style fixes in Qt graphics code
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
129 PopupMenuControl::currentIndexChanged (int index)
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 if (! m_blockUpdate)
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 {
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 gh_manager::post_set (m_handle, "value",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
134 octave_value (double (index + 1)),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18505
diff changeset
135 false);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 gh_manager::post_callback (m_handle, "callback");
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 }
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 }
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 }; // namespace QtHandles