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
ButtonControl.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 <QAbstractButton>
28 
29 #include "ButtonControl.h"
30 #include "ButtonGroup.h"
31 #include "Container.h"
32 #include "QtHandlesUtils.h"
33 
34 namespace QtHandles
35 {
36 
37  ButtonControl::ButtonControl (const graphics_object& go, QAbstractButton* btn)
38  : BaseControl (go, btn), m_blockCallback (false)
39  {
40  uicontrol::properties& up = properties<uicontrol> ();
41 
42  QString str = Utils::fromStdString (up.get_string_string ());
43  str.replace ("&", "&&");
44  btn->setText (str);
45  if (btn->isCheckable () || up.style_is ("togglebutton"))
46  {
47  btn->setCheckable (true);
48 
50 
51  if (value.numel () > 0 && value(0) == up.get_max ())
52  btn->setChecked (true);
53  }
54 
55  connect (btn, SIGNAL (clicked (void)), SLOT (clicked (void)));
56  connect (btn, SIGNAL (toggled (bool)), SLOT (toggled (bool)));
57  }
58 
60  { }
61 
62  void
64  {
65  uicontrol::properties& up = properties<uicontrol> ();
66  QAbstractButton* btn = qWidget<QAbstractButton> ();
67 
68  switch (pId)
69  {
71  {
72  QString str = Utils::fromStdString (up.get_string_string ());
73  str.replace ("&", "&&");
74  btn->setText (str);
75  break;
76  }
77 
79  m_blockCallback = true;
80  if (btn->isCheckable ())
81  {
83 
84  if (value.numel () > 0)
85  {
86  double dValue = value(0);
87 
88  if (dValue != 0.0 && dValue != 1.0)
89  warning ("button value not within valid display range");
90  else if (dValue == up.get_min () && btn->isChecked ())
91  {
92  btn->setChecked (false);
93  if (up.style_is ("radiobutton") || up.style_is ("togglebutton"))
94  {
96  up.get___myhandle__ ()));
97  ButtonGroup* btnGroup = dynamic_cast<ButtonGroup*>(parent);
98  if (btnGroup)
99  btnGroup->selectNothing ();
100  }
101  }
102  else if (dValue == up.get_max () && ! btn->isChecked ())
103  btn->setChecked (true);
104  }
105  }
106  m_blockCallback = false;
107  break;
108 
109  default:
110  BaseControl::update (pId);
111  break;
112  }
113  }
114 
115  void
116  ButtonControl::toggled (bool checked)
117  {
118  QAbstractButton* btn = qWidget<QAbstractButton> ();
119 
120  if (! m_blockCallback && btn->isCheckable ())
121  {
123 
124  uicontrol::properties& up = properties<uicontrol> ();
125 
126  Matrix oldValue = up.get_value ().matrix_value ();
127  double newValue = (checked ? up.get_max () : up.get_min ());
128 
129  if (oldValue.numel() != 1
130  || (newValue != oldValue(0)))
131  gh_manager::post_set (m_handle, "value", newValue, false);
132  gh_manager::post_callback (m_handle, "callback");
133  }
134  }
135 
136  void
138  {
139  QAbstractButton* btn = qWidget<QAbstractButton> ();
140 
141  if (! btn->isCheckable ())
142  gh_manager::post_callback (m_handle, "callback");
143  }
144 
145 };
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
std::string str
Definition: hash.cc:118
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
double get_min(void) const
Definition: graphics.h:11971
void warning(const char *fmt,...)
Definition: error.cc:788
void update(int pId)
Definition: BaseControl.cc:124
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!
static graphics_object get_object(double val)
Definition: graphics.h:13794
graphics_handle get___myhandle__(void) const
Definition: graphics.h:2710
octave_value get_value(void) const
Definition: graphics.h:11989
void toggled(bool checked)
double get_max(void) const
Definition: graphics.h:11969
ButtonControl(const graphics_object &go, QAbstractButton *btn)
bool style_is(const std::string &v) const
Definition: graphics.h:11981
static void post_set(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit=true)
Definition: graphics.h:13924