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
ObjectFactory.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 <QApplication>
28 #include <QThread>
29 
30 #include "graphics.h"
31 
32 #include "Backend.h"
33 #include "CheckBoxControl.h"
34 #include "ContextMenu.h"
35 #include "EditControl.h"
36 #include "Figure.h"
37 #include "ListBoxControl.h"
38 #include "Logger.h"
39 #include "Menu.h"
40 #include "ObjectFactory.h"
41 #include "ObjectProxy.h"
42 #include "Panel.h"
43 #include "PopupMenuControl.h"
44 #include "PushButtonControl.h"
45 #include "PushTool.h"
46 #include "RadioButtonControl.h"
47 #include "SliderControl.h"
48 #include "TextControl.h"
49 #include "ToggleButtonControl.h"
50 #include "ToggleTool.h"
51 #include "ToolBar.h"
52 #include "QtHandlesUtils.h"
53 
54 namespace QtHandles
55 {
56 
57 ObjectFactory*
59 {
60  static ObjectFactory s_instance;
61  static bool s_instanceCreated = false;
62 
63  if (! s_instanceCreated)
64  {
65  if (QThread::currentThread () != QApplication::instance ()->thread ())
66  s_instance.moveToThread (QApplication::instance ()->thread ());
67  s_instanceCreated = true;
68  }
69 
70  return &s_instance;
71 }
72 
73 void
75 {
77 
79 
80  if (go.valid_object ())
81  {
82  if (go.get_properties ().is_beingdeleted ())
83  qWarning ("ObjectFactory::createObject: object is being deleted");
84  else
85  {
87 
88  if (proxy)
89  {
90  Logger::debug ("ObjectFactory::createObject: "
91  "create %s from thread %08x",
92  go.type ().c_str (), QThread::currentThreadId ());
93 
94  Object* obj = 0;
95 
96  if (go.isa ("figure"))
97  obj = Figure::create (go);
98  else if (go.isa ("uicontrol"))
99  {
101  Utils::properties<uicontrol> (go);
102 
103  if (up.style_is ("pushbutton"))
104  obj = PushButtonControl::create (go);
105  else if (up.style_is ("edit"))
106  obj = EditControl::create (go);
107  else if (up.style_is ("checkbox"))
108  obj = CheckBoxControl::create (go);
109  else if (up.style_is ("radiobutton"))
110  obj = RadioButtonControl::create (go);
111  else if (up.style_is ("togglebutton"))
112  obj = ToggleButtonControl::create (go);
113  else if (up.style_is ("text"))
114  obj = TextControl::create (go);
115  else if (up.style_is ("popupmenu"))
116  obj = PopupMenuControl::create (go);
117  else if (up.style_is ("slider"))
118  obj = SliderControl::create (go);
119  else if (up.style_is ("listbox"))
120  obj = ListBoxControl::create (go);
121  }
122  else if (go.isa ("uipanel"))
123  obj = Panel::create (go);
124  else if (go.isa ("uimenu"))
125  obj = Menu::create (go);
126  else if (go.isa ("uicontextmenu"))
127  obj = ContextMenu::create (go);
128  else if (go.isa ("uitoolbar"))
129  obj = ToolBar::create (go);
130  else if (go.isa ("uipushtool"))
131  obj = PushTool::create (go);
132  else if (go.isa ("uitoggletool"))
133  obj = ToggleTool::create (go);
134  else
135  qWarning ("ObjectFactory::createObject: unsupported type `%s'",
136  go.type ().c_str ());
137 
138  if (obj)
139  proxy->setObject (obj);
140  }
141  else
142  qWarning ("ObjectFactory::createObject: no proxy for handle %g",
143  handle);
144  }
145  }
146  else
147  qWarning ("ObjectFactory::createObject: invalid object for handle %g",
148  handle);
149 }
150 
151 };
static PopupMenuControl * create(const graphics_object &go)
void setObject(Object *obj)
Definition: ObjectProxy.cc:77
static SliderControl * create(const graphics_object &go)
static ToolBar * create(const graphics_object &go)
Definition: ToolBar.cc:67
bool isa(const std::string &go_name) const
Definition: graphics.h:3375
static Panel * create(const graphics_object &go)
Definition: Panel.cc:88
void createObject(double handle)
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:76
static ToggleButtonControl * create(const graphics_object &go)
bool is_beingdeleted(void) const
Definition: graphics.h:2715
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:208
base_properties & get_properties(void)
Definition: graphics.h:3377
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
std::string type(void) const
Definition: graphics.h:3397
bool valid_object(void) const
Definition: graphics.h:3395
static ListBoxControl * create(const graphics_object &go)
static graphics_object get_object(double val)
Definition: graphics.h:13212
static Figure * create(const graphics_object &go)
Definition: Figure.cc:121
static ContextMenu * create(const graphics_object &go)
Definition: ContextMenu.cc:37
bool style_is(const std::string &v) const
Definition: graphics.h:11749