GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PopupMenuControl.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2015 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <QComboBox>
28 
29 #include "Container.h"
30 #include "PopupMenuControl.h"
31 #include "QtHandlesUtils.h"
32 
33 namespace QtHandles
34 {
35 
36 PopupMenuControl*
38 {
39  Object* parent = Object::parentObject (go);
40 
41  if (parent)
42  {
43  Container* container = parent->innerContainer ();
44 
45  if (container)
46  return new PopupMenuControl (go, new QComboBox (container));
47  }
48 
49  return 0;
50 }
51 
53  : BaseControl (go, box), m_blockUpdate (false)
54 {
55  uicontrol::properties& up = properties<uicontrol> ();
56 
57  box->addItems (Utils::fromStdString (up.get_string_string ()).split ('|'));
58 
60 
61  connect (box, SIGNAL (currentIndexChanged (int)),
62  SLOT (currentIndexChanged (int)));
63 }
64 
66 {
67 }
68 
70 {
71  uicontrol::properties& up = properties<uicontrol> ();
72  QComboBox* box = qWidget<QComboBox> ();
73 
74  switch (pId)
75  {
77  m_blockUpdate = true;
78  {
79  int oldCurrent = box->currentIndex ();
80 
81  box->clear ();
82  box->addItems (Utils::fromStdString
83  (up.get_string_string ()).split ('|'));
84  if (box->count() > 0
85  && oldCurrent >= 0
86  && oldCurrent < box->count ())
87  {
88  box->setCurrentIndex (oldCurrent);
89  }
90  else
91  {
93  octave_value (box->count () > 0
94  ? 1.0 : 0.0),
95  false);
96  }
97  }
98  m_blockUpdate = false;
99  break;
100 
102  m_blockUpdate = true;
103  {
104  Matrix value = up.get_value ().matrix_value ();
105 
106  if (value.numel () > 0)
107  {
108  if (value(0) != static_cast<int>(value(0)))
109  {
110  warning ("popupmenu value should be integer");
111  }
112  else
113  {
114  int newIndex = int (value(0)) - 1;
115 
116  if (newIndex >= 0 && newIndex < box->count ())
117  {
118  if (newIndex != box->currentIndex ())
119  box->setCurrentIndex (newIndex);
120  }
121  else
122  warning ("popupmenu value not within valid display range");
123  }
124  }
125  }
126  m_blockUpdate = false;
127  break;
128 
129  default:
130  BaseControl::update (pId);
131  break;
132  }
133 }
134 
135 void
137 {
138  if (! m_blockUpdate)
139  {
140  gh_manager::post_set (m_handle, "value",
141  octave_value (double (index + 1)),
142  false);
143  gh_manager::post_callback (m_handle, "callback");
144  }
145 }
146 
147 }; // namespace QtHandles
static PopupMenuControl * create(const graphics_object &go)
static void post_callback(const graphics_handle &h, const std::string &name, const octave_value &data=Matrix())
Definition: graphics.h:13329
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:275
OCTINTERP_API octave_value box(JNIEnv *jni_env, jobject jobj, jclass jcls=0)
QString fromStdString(const std::string &s)
static Object * parentObject(const graphics_object &go)
Definition: Object.cc:170
virtual Container * innerContainer(void)=0
graphics_handle m_handle
Definition: Object.h:100
Definition: dMatrix.h:35
std::string get_string_string(void) const
Definition: graphics.h:11745
Matrix matrix_value(bool frc_str_conv=false) const
Definition: ov.h:773
PopupMenuControl(const graphics_object &go, QComboBox *box)
void warning(const char *fmt,...)
Definition: error.cc:681
void update(int pId)
Definition: BaseControl.cc:106
octave_value get_value(void) const
Definition: graphics.h:11757
static void post_set(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit=true)
Definition: graphics.h:13343