GNU Octave  4.2.1
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-2017 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 #if defined (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  void PopupMenuControl::update (int pId)
69  {
70  uicontrol::properties& up = properties<uicontrol> ();
71  QComboBox* box = qWidget<QComboBox> ();
72 
73  switch (pId)
74  {
76  m_blockUpdate = true;
77  {
78  int oldCurrent = box->currentIndex ();
79 
80  box->clear ();
81  box->addItems (Utils::fromStdString
82  (up.get_string_string ()).split ('|'));
83  if (box->count() > 0
84  && oldCurrent >= 0
85  && oldCurrent < box->count ())
86  {
87  box->setCurrentIndex (oldCurrent);
88  }
89  else
90  {
92  octave_value (box->count () > 0
93  ? 1.0 : 0.0),
94  false);
95  }
96  }
97  m_blockUpdate = false;
98  break;
99 
101  m_blockUpdate = true;
102  {
103  Matrix value = up.get_value ().matrix_value ();
104 
105  if (value.numel () > 0)
106  {
107  if (value(0) != static_cast<int>(value(0)))
108  warning ("popupmenu value should be integer");
109  else
110  {
111  int newIndex = int (value(0)) - 1;
112 
113  if (newIndex >= 0 && newIndex < box->count ())
114  {
115  if (newIndex != box->currentIndex ())
116  box->setCurrentIndex (newIndex);
117  }
118  else
119  warning ("popupmenu value not within valid display range");
120  }
121  }
122  }
123  m_blockUpdate = false;
124  break;
125 
126  default:
127  BaseControl::update (pId);
128  break;
129  }
130  }
131 
132  void
134  {
135  if (! m_blockUpdate)
136  {
137  gh_manager::post_set (m_handle, "value",
138  octave_value (double (index + 1)),
139  false);
140  gh_manager::post_callback (m_handle, "callback");
141  }
142  }
143 
144 }
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:13910
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
QString fromStdString(const std::string &s)
static Object * parentObject(const graphics_object &go)
Definition: Object.cc:165
virtual Container * innerContainer(void)=0
graphics_handle m_handle
Definition: Object.h:100
is false
Definition: cellfun.cc:398
Definition: dMatrix.h:37
std::string get_string_string(void) const
Definition: graphics.h:11977
Matrix matrix_value(bool frc_str_conv=false) const
Definition: ov.h:787
PopupMenuControl(const graphics_object &go, QComboBox *box)
void warning(const char *fmt,...)
Definition: error.cc:788
void update(int pId)
Definition: BaseControl.cc:124
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=0)
Convert the Java object pointed to by jobj_arg with class jcls_arg to an Octave value.
Definition: ov-java.cc:1192
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
octave_value get_value(void) const
Definition: graphics.h:11989
static void post_set(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit=true)
Definition: graphics.h:13924