GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ObjectFactory.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <QApplication>
28 #include <QThread>
29 
30 #include "graphics.h"
31 
32 #include "Backend.h"
33 #include "ButtonGroup.h"
34 #include "CheckBoxControl.h"
35 #include "ContextMenu.h"
36 #include "EditControl.h"
37 #include "Figure.h"
38 #include "ListBoxControl.h"
39 #include "Logger.h"
40 #include "Menu.h"
41 #include "ObjectFactory.h"
42 #include "ObjectProxy.h"
43 #include "Panel.h"
44 #include "PopupMenuControl.h"
45 #include "PushButtonControl.h"
46 #include "PushTool.h"
47 #include "RadioButtonControl.h"
48 #include "SliderControl.h"
49 #include "TextControl.h"
50 #include "ToggleButtonControl.h"
51 #include "ToggleTool.h"
52 #include "ToolBar.h"
53 #include "QtHandlesUtils.h"
54 
55 namespace QtHandles
56 {
57 
58  ObjectFactory*
60  {
61  static ObjectFactory s_instance;
62  static bool s_instanceCreated = false;
63 
64  if (! s_instanceCreated)
65  {
66  if (QThread::currentThread () != QApplication::instance ()->thread ())
67  s_instance.moveToThread (QApplication::instance ()->thread ());
68  s_instanceCreated = true;
69  }
70 
71  return &s_instance;
72  }
73 
74  void
76  {
78 
80 
81  if (go.valid_object ())
82  {
83  if (go.get_properties ().is_beingdeleted ())
84  qWarning ("ObjectFactory::createObject: object is being deleted");
85  else
86  {
88 
89  if (proxy)
90  {
91  Logger::debug ("ObjectFactory::createObject: "
92  "create %s from thread %08x",
93  go.type ().c_str (), QThread::currentThreadId ());
94 
95  Object *obj = nullptr;
96 
97  if (go.isa ("figure"))
98  obj = Figure::create (go);
99  else if (go.isa ("uicontrol"))
100  {
102  Utils::properties<uicontrol> (go);
103 
104  if (up.style_is ("pushbutton"))
105  obj = PushButtonControl::create (go);
106  else if (up.style_is ("edit"))
107  obj = EditControl::create (go);
108  else if (up.style_is ("checkbox"))
109  obj = CheckBoxControl::create (go);
110  else if (up.style_is ("radiobutton"))
111  obj = RadioButtonControl::create (go);
112  else if (up.style_is ("togglebutton"))
113  obj = ToggleButtonControl::create (go);
114  else if (up.style_is ("text"))
115  obj = TextControl::create (go);
116  else if (up.style_is ("popupmenu"))
117  obj = PopupMenuControl::create (go);
118  else if (up.style_is ("slider"))
119  obj = SliderControl::create (go);
120  else if (up.style_is ("listbox"))
121  obj = ListBoxControl::create (go);
122  }
123  else if (go.isa ("uibuttongroup"))
124  obj = ButtonGroup::create (go);
125  else if (go.isa ("uipanel"))
126  obj = Panel::create (go);
127  else if (go.isa ("uimenu"))
128  obj = Menu::create (go);
129  else if (go.isa ("uicontextmenu"))
130  obj = ContextMenu::create (go);
131  else if (go.isa ("uitoolbar"))
132  obj = ToolBar::create (go);
133  else if (go.isa ("uipushtool"))
134  obj = PushTool::create (go);
135  else if (go.isa ("uitoggletool"))
136  obj = ToggleTool::create (go);
137  else
138  qWarning ("ObjectFactory::createObject: unsupported type `%s'",
139  go.type ().c_str ());
140 
141  if (obj)
142  proxy->setObject (obj);
143  }
144  else
145  qWarning ("ObjectFactory::createObject: no proxy for handle %g",
146  handle);
147  }
148  }
149  else
150  qWarning ("ObjectFactory::createObject: invalid object for handle %g",
151  handle);
152  }
153 
154 };
static PopupMenuControl * create(const graphics_object &go)
void setObject(Object *obj)
Definition: ObjectProxy.cc:81
static SliderControl * create(const graphics_object &go)
static ToolBar * create(const graphics_object &go)
Definition: ToolBar.cc:67
static Panel * create(const graphics_object &go)
Definition: Panel.cc:88
static ButtonGroup * create(const graphics_object &go)
Definition: ButtonGroup.cc:96
bool isa(const std::string &go_name) const
Definition: graphics.in.h:2786
void createObject(double handle)
bool valid_object(void) const
Definition: graphics.in.h:2806
static Menu * create(const graphics_object &go)
Definition: Menu.cc:61
static ObjectFactory * instance(void)
static CheckBoxControl * create(const graphics_object &go)
static void debug(const char *fmt,...)
Definition: Logger.cc:75
static ToggleButtonControl * create(const graphics_object &go)
static PushButtonControl * create(const graphics_object &go)
static PushTool * create(const graphics_object &go)
Definition: PushTool.cc:35
static ObjectProxy * toolkitObjectProxy(const graphics_object &go)
Definition: Backend.cc:223
base_properties & get_properties(void)
Definition: graphics.in.h:2788
static EditControl * create(const graphics_object &go)
Definition: EditControl.cc:38
static TextControl * create(const graphics_object &go)
Definition: TextControl.cc:37
static RadioButtonControl * create(const graphics_object &go)
static ToggleTool * create(const graphics_object &go)
Definition: ToggleTool.cc:35
static ListBoxControl * create(const graphics_object &go)
static graphics_object get_object(double val)
Definition: graphics.in.h:6098
static Figure * create(const graphics_object &go)
Definition: Figure.cc:121
std::string type(void) const
Definition: graphics.in.h:2808
is a function handle
Definition: bsxfun.cc:337
static ContextMenu * create(const graphics_object &go)
Definition: ContextMenu.cc:37