qml 0.0.7 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/.travis.yml +5 -9
  4. data/LICENSE.txt +1 -1
  5. data/README.md +84 -114
  6. data/changes.md +5 -0
  7. data/examples/fizzbuzz/fizzbuzz.rb +3 -4
  8. data/examples/todo_array/todo_array.rb +4 -4
  9. data/examples/todo_sequel/todo_sequel.rb +7 -7
  10. data/examples/twitter/twitter.rb +5 -3
  11. data/ext/qml/application.c +88 -0
  12. data/ext/qml/application.h +9 -0
  13. data/ext/qml/component.c +89 -0
  14. data/ext/qml/component.h +10 -0
  15. data/ext/qml/conversion.c +60 -0
  16. data/ext/qml/conversion.h +8 -0
  17. data/ext/qml/dispatcher.c +31 -0
  18. data/ext/qml/dispatcher.h +7 -0
  19. data/ext/qml/engine.c +135 -0
  20. data/ext/qml/engine.h +10 -0
  21. data/ext/qml/exporter.c +93 -0
  22. data/ext/qml/exporter.h +7 -0
  23. data/ext/qml/extconf.rb +38 -97
  24. data/ext/qml/interface.c +156 -0
  25. data/ext/qml/interface.h +11 -0
  26. data/ext/qml/js_array.c +47 -0
  27. data/ext/qml/js_array.h +7 -0
  28. data/ext/qml/js_function.c +109 -0
  29. data/ext/qml/js_function.h +7 -0
  30. data/ext/qml/js_object.c +284 -0
  31. data/ext/qml/js_object.h +19 -0
  32. data/ext/qml/js_wrapper.c +19 -0
  33. data/ext/qml/js_wrapper.h +7 -0
  34. data/ext/qml/lib/libqmlbind/.gitignore +38 -0
  35. data/ext/qml/lib/libqmlbind/.gitmodules +3 -0
  36. data/ext/qml/lib/libqmlbind/.travis.yml +14 -0
  37. data/ext/qml/lib/libqmlbind/LICENSE.txt +22 -0
  38. data/ext/qml/lib/libqmlbind/libqmlbind.pro +3 -0
  39. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind.h +14 -0
  40. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/application.h +18 -0
  41. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/component.h +21 -0
  42. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/engine.h +34 -0
  43. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/exporter.h +37 -0
  44. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/interface.h +16 -0
  45. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/iterator.h +19 -0
  46. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/metaobject.h +13 -0
  47. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/plugin.h +17 -0
  48. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/qmlbind_global.h +78 -0
  49. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/register.h +17 -0
  50. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/signal_emitter.h +15 -0
  51. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/string.h +15 -0
  52. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/value.h +100 -0
  53. data/ext/qml/lib/libqmlbind/qmlbind/qmlbind.pro +62 -0
  54. data/ext/qml/lib/libqmlbind/qmlbind/src/api_application.cpp +103 -0
  55. data/ext/qml/lib/libqmlbind/qmlbind/src/api_component.cpp +54 -0
  56. data/ext/qml/lib/libqmlbind/qmlbind/src/api_engine.cpp +65 -0
  57. data/ext/qml/lib/libqmlbind/qmlbind/src/api_exporter.cpp +52 -0
  58. data/ext/qml/lib/libqmlbind/qmlbind/src/api_interface.cpp +19 -0
  59. data/ext/qml/lib/libqmlbind/qmlbind/src/api_iterator.cpp +32 -0
  60. data/ext/qml/lib/libqmlbind/qmlbind/src/api_metaobject.cpp +19 -0
  61. data/ext/qml/lib/libqmlbind/qmlbind/src/api_plugin.cpp +27 -0
  62. data/ext/qml/lib/libqmlbind/qmlbind/src/api_register.cpp +17 -0
  63. data/ext/qml/lib/libqmlbind/qmlbind/src/api_signal_emitter.cpp +27 -0
  64. data/ext/qml/lib/libqmlbind/qmlbind/src/api_string.cpp +22 -0
  65. data/ext/qml/lib/libqmlbind/qmlbind/src/api_value.cpp +215 -0
  66. data/ext/qml/lib/libqmlbind/qmlbind/src/backref.cpp +54 -0
  67. data/ext/qml/lib/libqmlbind/qmlbind/src/backref.h +29 -0
  68. data/ext/qml/lib/libqmlbind/qmlbind/src/engine.cpp +32 -0
  69. data/ext/qml/lib/libqmlbind/qmlbind/src/engine.h +27 -0
  70. data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.cpp +73 -0
  71. data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.h +46 -0
  72. data/ext/qml/lib/libqmlbind/qmlbind/src/interface.cpp +75 -0
  73. data/ext/qml/lib/libqmlbind/qmlbind/src/interface.h +37 -0
  74. data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.cpp +101 -0
  75. data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.h +29 -0
  76. data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.cpp +33 -0
  77. data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.h +25 -0
  78. data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.cpp +15 -0
  79. data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.h +19 -0
  80. data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.cpp +112 -0
  81. data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.h +28 -0
  82. data/ext/qml/lib/libqmlbind/qmlbind/src/util.h +13 -0
  83. data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.cpp +23 -0
  84. data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.h +29 -0
  85. data/ext/qml/lib/libqmlbind/readme.md +14 -0
  86. data/ext/qml/lib/libqmlbind/test/api.c +1 -0
  87. data/ext/qml/lib/libqmlbind/test/application_test.cpp +16 -0
  88. data/ext/qml/lib/libqmlbind/test/component_test.cpp +57 -0
  89. data/ext/qml/lib/libqmlbind/test/engine_test.cpp +94 -0
  90. data/ext/qml/lib/libqmlbind/test/exporter_test.cpp +312 -0
  91. data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.cpp +36 -0
  92. data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.h +6 -0
  93. data/ext/qml/lib/libqmlbind/test/fixtures/test.qml +5 -0
  94. data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/qmldir +2 -0
  95. data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/test.qml +5 -0
  96. data/ext/qml/lib/libqmlbind/test/iterator_test.cpp +37 -0
  97. data/ext/qml/lib/libqmlbind/test/main.cpp +11 -0
  98. data/ext/qml/lib/libqmlbind/test/plugin_test.cpp +41 -0
  99. data/ext/qml/lib/libqmlbind/test/test.pro +26 -0
  100. data/ext/qml/lib/libqmlbind/test/test_helper.h +20 -0
  101. data/ext/qml/lib/libqmlbind/test/value_test.cpp +252 -0
  102. data/ext/qml/lib/libqmlbind/testplugin/testplugin.cpp +11 -0
  103. data/ext/qml/lib/libqmlbind/testplugin/testplugin.h +21 -0
  104. data/ext/qml/lib/libqmlbind/testplugin/testplugin.json +3 -0
  105. data/ext/qml/lib/libqmlbind/testplugin/testplugin.pro +21 -0
  106. data/ext/qml/meta_object.c +81 -0
  107. data/ext/qml/meta_object.h +8 -0
  108. data/ext/qml/plugin_loader.c +71 -0
  109. data/ext/qml/plugin_loader.h +7 -0
  110. data/ext/qml/qml.c +95 -0
  111. data/ext/qml/qml.h +10 -0
  112. data/ext/qml/rubyqml-plugin/listmodel.cpp +102 -0
  113. data/ext/qml/rubyqml-plugin/listmodel.h +37 -0
  114. data/ext/qml/rubyqml-plugin/rubyqml-plugin.pro +19 -0
  115. data/ext/qml/rubyqml-plugin/rubyqmlplugin.cpp +25 -0
  116. data/ext/qml/rubyqml-plugin/rubyqmlplugin.h +19 -0
  117. data/ext/qml/signal_emitter.c +71 -0
  118. data/ext/qml/signal_emitter.h +9 -0
  119. data/lib/qml.rb +11 -10
  120. data/lib/qml/access.rb +64 -86
  121. data/lib/qml/application.rb +20 -71
  122. data/lib/qml/component.rb +41 -33
  123. data/lib/qml/core_ext.rb +1 -0
  124. data/lib/qml/core_ext/to_qml.rb +70 -0
  125. data/lib/qml/data.rb +1 -0
  126. data/lib/qml/data/array_model.rb +99 -101
  127. data/lib/qml/data/list_model.rb +107 -131
  128. data/lib/qml/data/list_model_access.rb +44 -0
  129. data/lib/qml/data/query_model.rb +45 -47
  130. data/lib/qml/dispatcher.rb +5 -13
  131. data/lib/qml/engine.rb +9 -58
  132. data/lib/qml/errors.rb +0 -21
  133. data/lib/qml/interface.rb +21 -0
  134. data/lib/qml/js_array.rb +8 -0
  135. data/lib/qml/js_object.rb +69 -0
  136. data/lib/qml/js_util.rb +18 -0
  137. data/lib/qml/plugin_loader.rb +1 -13
  138. data/lib/qml/plugins.rb +3 -17
  139. data/lib/qml/proc_access.rb +28 -0
  140. data/lib/qml/qt.rb +21 -3
  141. data/lib/qml/reactive.rb +147 -8
  142. data/lib/qml/signal.rb +67 -0
  143. data/lib/qml/version.rb +1 -1
  144. data/qml.gemspec +8 -2
  145. data/spec/qml/access_spec.rb +33 -120
  146. data/spec/qml/application_spec.rb +11 -24
  147. data/spec/qml/component_spec.rb +4 -4
  148. data/spec/qml/data/array_model_spec.rb +2 -2
  149. data/spec/qml/data/list_model_spec.rb +2 -2
  150. data/spec/qml/data/query_model_spec.rb +4 -4
  151. data/spec/qml/engine_spec.rb +23 -21
  152. data/spec/qml/interface_spec.rb +20 -0
  153. data/spec/qml/js_array_spec.rb +29 -0
  154. data/spec/qml/js_function_spec.rb +32 -0
  155. data/spec/qml/js_object_spec.rb +113 -0
  156. data/spec/qml/plugin_loader_spec.rb +9 -11
  157. data/spec/qml/qt_spec.rb +9 -0
  158. data/spec/qml/reactive_spec.rb +37 -0
  159. data/spec/qml/signal_connect_spec.rb +27 -0
  160. data/spec/qml/signal_spec.rb +73 -0
  161. data/spec/qml/to_qml_spec.rb +76 -0
  162. data/spec/shared/qml/access_example.rb +21 -0
  163. data/spec/shared/qml/data/list_model.rb +12 -13
  164. data/spec/spec_helper.rb +2 -3
  165. metadata +141 -166
  166. data/examples/imageprovider/imageprovider.rb +0 -57
  167. data/examples/imageprovider/main.qml +0 -51
  168. data/ext/qml/accessclass.cpp +0 -65
  169. data/ext/qml/accessclass.h +0 -19
  170. data/ext/qml/accessobject.cpp +0 -30
  171. data/ext/qml/accessobject.h +0 -22
  172. data/ext/qml/common.h +0 -18
  173. data/ext/qml/conversionerror.h +0 -14
  174. data/ext/qml/ext_accesswrapperfactory.cpp +0 -75
  175. data/ext/qml/ext_accesswrapperfactory.h +0 -39
  176. data/ext/qml/ext_anywrapper.cpp +0 -34
  177. data/ext/qml/ext_anywrapper.h +0 -23
  178. data/ext/qml/ext_kernel.cpp +0 -81
  179. data/ext/qml/ext_kernel.h +0 -9
  180. data/ext/qml/ext_metaobject.cpp +0 -399
  181. data/ext/qml/ext_metaobject.h +0 -60
  182. data/ext/qml/ext_pluginloader.cpp +0 -53
  183. data/ext/qml/ext_pluginloader.h +0 -30
  184. data/ext/qml/ext_pointer.cpp +0 -132
  185. data/ext/qml/ext_pointer.h +0 -41
  186. data/ext/qml/ext_testutil.cpp +0 -40
  187. data/ext/qml/ext_testutil.h +0 -9
  188. data/ext/qml/foreignclass.cpp +0 -72
  189. data/ext/qml/foreignclass.h +0 -88
  190. data/ext/qml/foreignmetaobject.cpp +0 -345
  191. data/ext/qml/foreignmetaobject.h +0 -46
  192. data/ext/qml/foreignobject.cpp +0 -22
  193. data/ext/qml/foreignobject.h +0 -21
  194. data/ext/qml/functioninfo.h +0 -16
  195. data/ext/qml/init.cpp +0 -67
  196. data/ext/qml/kernel.cpp +0 -39
  197. data/ext/qml/kernel.h +0 -32
  198. data/ext/qml/listmodel.cpp +0 -137
  199. data/ext/qml/listmodel.h +0 -45
  200. data/ext/qml/markable.h +0 -12
  201. data/ext/qml/objectdata.cpp +0 -26
  202. data/ext/qml/objectdata.h +0 -20
  203. data/ext/qml/objectgc.cpp +0 -69
  204. data/ext/qml/objectgc.h +0 -28
  205. data/ext/qml/plugins/core/applicationextension.cpp +0 -29
  206. data/ext/qml/plugins/core/applicationextension.h +0 -25
  207. data/ext/qml/plugins/core/componentextension.cpp +0 -41
  208. data/ext/qml/plugins/core/componentextension.h +0 -28
  209. data/ext/qml/plugins/core/contextextension.cpp +0 -39
  210. data/ext/qml/plugins/core/contextextension.h +0 -29
  211. data/ext/qml/plugins/core/core.pro +0 -29
  212. data/ext/qml/plugins/core/coreplugin.cpp +0 -87
  213. data/ext/qml/plugins/core/coreplugin.h +0 -49
  214. data/ext/qml/plugins/core/engineextension.cpp +0 -43
  215. data/ext/qml/plugins/core/engineextension.h +0 -31
  216. data/ext/qml/plugins/core/imageprovider.cpp +0 -38
  217. data/ext/qml/plugins/core/imageprovider.h +0 -18
  218. data/ext/qml/plugins/core/imagerequestpromise.cpp +0 -19
  219. data/ext/qml/plugins/core/imagerequestpromise.h +0 -21
  220. data/ext/qml/plugins/core/qmlexception.cpp +0 -11
  221. data/ext/qml/plugins/core/qmlexception.h +0 -17
  222. data/ext/qml/plugins/testutil/imageprovidertest.cpp +0 -40
  223. data/ext/qml/plugins/testutil/imageprovidertest.h +0 -17
  224. data/ext/qml/plugins/testutil/objectlifechecker.cpp +0 -17
  225. data/ext/qml/plugins/testutil/objectlifechecker.h +0 -24
  226. data/ext/qml/plugins/testutil/ownershiptest.cpp +0 -26
  227. data/ext/qml/plugins/testutil/ownershiptest.h +0 -30
  228. data/ext/qml/plugins/testutil/testobject.cpp +0 -6
  229. data/ext/qml/plugins/testutil/testobject.h +0 -108
  230. data/ext/qml/plugins/testutil/testobjectsubclass.cpp +0 -10
  231. data/ext/qml/plugins/testutil/testobjectsubclass.h +0 -19
  232. data/ext/qml/plugins/testutil/testutil.pro +0 -22
  233. data/ext/qml/plugins/testutil/testutilplugin.cpp +0 -55
  234. data/ext/qml/plugins/testutil/testutilplugin.h +0 -36
  235. data/ext/qml/qmltyperegisterer.cpp +0 -74
  236. data/ext/qml/qmltyperegisterer.h +0 -30
  237. data/ext/qml/rubyclass.cpp +0 -82
  238. data/ext/qml/rubyclass.h +0 -230
  239. data/ext/qml/rubyvalue.cpp +0 -656
  240. data/ext/qml/rubyvalue.h +0 -224
  241. data/ext/qml/signalforwarder.cpp +0 -64
  242. data/ext/qml/signalforwarder.h +0 -29
  243. data/ext/qml/util.cpp +0 -112
  244. data/ext/qml/util.h +0 -82
  245. data/ext/qml/valuereference.cpp +0 -50
  246. data/ext/qml/valuereference.h +0 -22
  247. data/ext/qml/weakvaluereference.cpp +0 -51
  248. data/ext/qml/weakvaluereference.h +0 -21
  249. data/lib/qml/context.rb +0 -71
  250. data/lib/qml/data/error.rb +0 -5
  251. data/lib/qml/dispatchable.rb +0 -34
  252. data/lib/qml/error_converter.rb +0 -16
  253. data/lib/qml/geometry.rb +0 -3
  254. data/lib/qml/geometry/point.rb +0 -5
  255. data/lib/qml/geometry/rectangle.rb +0 -5
  256. data/lib/qml/geometry/size.rb +0 -5
  257. data/lib/qml/image_provider.rb +0 -87
  258. data/lib/qml/init.rb +0 -29
  259. data/lib/qml/meta_object.rb +0 -20
  260. data/lib/qml/models.rb +0 -1
  261. data/lib/qml/qt_classes.rb +0 -9
  262. data/lib/qml/qt_object_base.rb +0 -233
  263. data/lib/qml/reactive/bindable.rb +0 -79
  264. data/lib/qml/reactive/chained_signal.rb +0 -25
  265. data/lib/qml/reactive/error.rb +0 -5
  266. data/lib/qml/reactive/object.rb +0 -293
  267. data/lib/qml/reactive/property.rb +0 -19
  268. data/lib/qml/reactive/signal.rb +0 -115
  269. data/lib/qml/reactive/signal_spy.rb +0 -27
  270. data/lib/qml/reactive/signals/map_signal.rb +0 -21
  271. data/lib/qml/reactive/signals/merge_signal.rb +0 -21
  272. data/lib/qml/reactive/signals/select_signal.rb +0 -21
  273. data/lib/qml/reactive/simple_property.rb +0 -17
  274. data/lib/qml/reactive/unbound_property.rb +0 -42
  275. data/lib/qml/reactive/unbound_signal.rb +0 -51
  276. data/lib/qml/test_util.rb +0 -1
  277. data/lib/qml/test_util/object_life_checker.rb +0 -17
  278. data/lib/qml/wrappable.rb +0 -9
  279. data/spec/qml/context_spec.rb +0 -43
  280. data/spec/qml/conversion_spec.rb +0 -60
  281. data/spec/qml/dispatchable_spec.rb +0 -26
  282. data/spec/qml/dispatcher_spec.rb +0 -71
  283. data/spec/qml/geometry/point_spec.rb +0 -4
  284. data/spec/qml/geometry/rectangle_spec.rb +0 -4
  285. data/spec/qml/geometry/size_spec.rb +0 -4
  286. data/spec/qml/image_provider_spec.rb +0 -33
  287. data/spec/qml/qt_object_base_spec.rb +0 -119
  288. data/spec/qml/reactive/object_spec.rb +0 -249
  289. data/spec/qml/reactive/property_spec.rb +0 -70
  290. data/spec/qml/reactive/signal_spec.rb +0 -191
  291. data/spec/qml/reactive/signal_spy_spec.rb +0 -26
  292. data/spec/qml/reactive/unbound_property_spec.rb +0 -40
  293. data/spec/qml/reactive/unbound_signal_spec.rb +0 -70
  294. data/spec/qml/test_object_spec.rb +0 -186
  295. data/spec/qml/wrappable_spec.rb +0 -10
  296. data/spec/shared/qml/reactive/object.rb +0 -39
@@ -1,55 +0,0 @@
1
- #include "testutilplugin.h"
2
- #include "testobject.h"
3
- #include "testobjectsubclass.h"
4
- #include "ownershiptest.h"
5
- #include "objectlifechecker.h"
6
- #include "imageprovidertest.h"
7
- #include <QtQml>
8
- #include <QQuickWindow>
9
-
10
- Q_DECLARE_METATYPE(const QMetaObject*)
11
-
12
- namespace RubyQml {
13
-
14
- TestUtilPlugin::TestUtilPlugin(QObject *parent) :
15
- QObject(parent)
16
- {
17
- qRegisterMetaType<TestObject *>();
18
- qRegisterMetaType<TestObject::Enums>();
19
- qRegisterMetaType<TestObjectSubclass *>();
20
- qRegisterMetaType<OwnershipTest *>();
21
- qRegisterMetaType<ObjectLifeChecker *>();
22
- qRegisterMetaType<ImageProviderTest *>();
23
-
24
- auto metaObjects = { &TestObject::staticMetaObject, &ObjectLifeChecker::staticMetaObject};
25
- for (auto metaobj : metaObjects) {
26
- mMetaObjects[metaobj->className()] = QVariant::fromValue(metaobj);
27
- }
28
- }
29
-
30
- TestObject *TestUtilPlugin::createTestObject()
31
- {
32
- return new TestObject();
33
- }
34
-
35
- TestObjectSubclass *TestUtilPlugin::createTestObjectSubclass()
36
- {
37
- return new TestObjectSubclass();
38
- }
39
-
40
- OwnershipTest *TestUtilPlugin::createOwnershipTest()
41
- {
42
- return new OwnershipTest();
43
- }
44
-
45
- ObjectLifeChecker *TestUtilPlugin::createObjectLifeChecker(QObject *target)
46
- {
47
- return new ObjectLifeChecker(target);
48
- }
49
-
50
- ImageProviderTest *TestUtilPlugin::createImageProviderTest()
51
- {
52
- return new ImageProviderTest();
53
- }
54
-
55
- } // namespace RubyQml
@@ -1,36 +0,0 @@
1
- #pragma once
2
- #include <QObject>
3
- #include <QVariant>
4
-
5
- class QQuickWindow;
6
-
7
- namespace RubyQml {
8
-
9
- class TestObject;
10
- class TestObjectSubclass;
11
- class OwnershipTest;
12
- class ObjectLifeChecker;
13
- class ImageProviderTest;
14
-
15
- class TestUtilPlugin : public QObject
16
- {
17
- Q_OBJECT
18
- Q_PLUGIN_METADATA(IID "org.ruby-qml.RubyQml.TestObject")
19
- public:
20
- explicit TestUtilPlugin(QObject *parent = 0);
21
- signals:
22
-
23
- public slots:
24
- QVariantHash metaObjects() { return mMetaObjects; }
25
-
26
- RubyQml::TestObject *createTestObject();
27
- RubyQml::TestObjectSubclass *createTestObjectSubclass();
28
- RubyQml::OwnershipTest *createOwnershipTest();
29
- RubyQml::ObjectLifeChecker *createObjectLifeChecker(QObject *target);
30
- RubyQml::ImageProviderTest *createImageProviderTest();
31
-
32
- private:
33
- QVariantHash mMetaObjects;
34
- };
35
-
36
- } // namespace RubyQml
@@ -1,74 +0,0 @@
1
- #include "qmltyperegisterer.h"
2
- #include "foreignmetaobject.h"
3
- #include "accessobject.h"
4
- #include <QtQml>
5
-
6
- namespace RubyQml {
7
-
8
- QmlTypeRegisterer::QmlTypeRegisterer(const SP<ForeignMetaObject> &metaObject, const std::function<void (void *)> &createFunc) :
9
- mMetaObject(metaObject),
10
- mCreateFunc(createFunc)
11
- {
12
- mFactoryArgs[0] = &ffi_type_pointer;
13
- if (ffi_prep_cif(&mFactoryCif, FFI_DEFAULT_ABI, 1, &ffi_type_void, mFactoryArgs) != FFI_OK) {
14
- throw std::runtime_error("failed to prepare FFI call interface");
15
- }
16
- mFactoryClosure = (ffi_closure *)ffi_closure_alloc(sizeof(ffi_closure), (void **)(&mFactoryFunc));
17
- if (!mFactoryClosure) {
18
- throw std::runtime_error("failed to allocate FFI closure");
19
- }
20
-
21
- auto callback = [](ffi_cif *cif, void *ret, void **args, void *data) {
22
- Q_UNUSED(cif);
23
- Q_UNUSED(ret);
24
- auto self = (QmlTypeRegisterer *)(data);
25
- self->mCreateFunc(*(void **)(args[0]));
26
- };
27
-
28
- if (ffi_prep_closure_loc(mFactoryClosure, &mFactoryCif, callback, this, (void *)mFactoryFunc) != FFI_OK) {
29
- ffi_closure_free(mFactoryClosure);
30
- throw std::runtime_error("failed to prepare FFI closure");
31
- }
32
- }
33
-
34
- QmlTypeRegisterer::~QmlTypeRegisterer()
35
- {
36
- ffi_closure_free(mFactoryClosure);
37
- }
38
-
39
- void QmlTypeRegisterer::registerType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
40
- {
41
- QByteArray className;
42
- className += mMetaObject->className();
43
- className += "*";
44
-
45
- QByteArray listName;
46
- listName += "QQmlListProperty<";
47
- listName += mMetaObject->className();
48
- listName += ">";
49
-
50
- QQmlPrivate::RegisterType type = {
51
- 0,
52
- qRegisterNormalizedMetaType<AccessWrapper *>(className),
53
- qRegisterNormalizedMetaType<QQmlListProperty<AccessWrapper> >(listName),
54
- sizeof(AccessWrapper), mFactoryFunc,
55
- QString(),
56
-
57
- uri, versionMajor, versionMinor, qmlName, mMetaObject.get(),
58
-
59
- 0, 0,
60
-
61
- QQmlPrivate::StaticCastSelector<AccessWrapper,QQmlParserStatus>::cast(),
62
- QQmlPrivate::StaticCastSelector<AccessWrapper,QQmlPropertyValueSource>::cast(),
63
- QQmlPrivate::StaticCastSelector<AccessWrapper,QQmlPropertyValueInterceptor>::cast(),
64
-
65
- 0, 0,
66
-
67
- 0,
68
- 0
69
- };
70
-
71
- QQmlPrivate::qmlregister(QQmlPrivate::TypeRegistration, &type);
72
- }
73
-
74
- } // namespace RubyQml
@@ -1,30 +0,0 @@
1
- #pragma once
2
- #include "common.h"
3
- #include <ffi.h>
4
- #include <functional>
5
-
6
- namespace RubyQml {
7
-
8
- class ForeignMetaObject;
9
-
10
- class QmlTypeRegisterer
11
- {
12
- public:
13
- using FactoryFunction = void (*)(void *);
14
-
15
- QmlTypeRegisterer(const SP<ForeignMetaObject> &metaObject, const std::function<void(void *)> &createFunc);
16
- ~QmlTypeRegisterer();
17
-
18
- void registerType(const char *uri, int versionMajor, int versionMinor, const char *qmlName);
19
-
20
- private:
21
-
22
- SP<ForeignMetaObject> mMetaObject;
23
- std::function<void (void *)> mCreateFunc;
24
- ffi_type *mFactoryArgs[1];
25
- ffi_cif mFactoryCif;
26
- ffi_closure *mFactoryClosure = nullptr;
27
- FactoryFunction mFactoryFunc = nullptr;
28
- };
29
-
30
- } // namespace RubyQml
@@ -1,82 +0,0 @@
1
- #include "rubyclass.h"
2
-
3
- namespace RubyQml {
4
-
5
- RubyModule::RubyModule(VALUE moduleValue) :
6
- RubyModule(RubyValue(moduleValue))
7
- {
8
- }
9
-
10
- RubyModule::RubyModule(RubyValue moduleValue) :
11
- mValue(moduleValue)
12
- {
13
- checkType();
14
- }
15
-
16
- RubyModule::RubyModule(const char *name)
17
- {
18
- mValue = rb_define_module(name);
19
- }
20
-
21
- RubyModule::RubyModule(const RubyModule &under, const char *name)
22
- {
23
- mValue = rb_define_module_under(under.toValue(), name);
24
- }
25
-
26
- RubyModule &RubyModule::operator=(const RubyModule &other)
27
- {
28
- mValue = other.mValue;
29
- checkType();
30
- return *this;
31
- }
32
-
33
- RubyModule RubyModule::fromPath(const char *path)
34
- {
35
- return rb_path2class(path);
36
- }
37
-
38
- void RubyModule::aliasMethod(const char *newName, const char *originalName)
39
- {
40
- rb_alias(mValue, rb_intern(newName), rb_intern(originalName));
41
- }
42
-
43
- void RubyModule::checkType()
44
- {
45
- if (!mValue.isKindOf(rb_cModule)) {
46
- throw std::logic_error("expected Module value");
47
- }
48
- }
49
-
50
- RubyClass::RubyClass(RubyValue classValue) :
51
- RubyModule(classValue)
52
- {
53
- checkType();
54
- }
55
-
56
- namespace {
57
-
58
- RubyValue defineClass(const RubyModule &under, const char *name)
59
- {
60
- return rb_define_class_under(under.toValue(), name, rb_cObject);
61
- }
62
-
63
- }
64
-
65
- RubyClass::RubyClass(const RubyModule &under, const char *name) :
66
- RubyModule(defineClass(under, name))
67
- {
68
- }
69
-
70
- RubyClass RubyClass::fromPath(const char *path)
71
- {
72
- return RubyClass(RubyModule::fromPath(path).toValue());
73
- }
74
-
75
- void RubyClass::checkType()
76
- {
77
- if (!toValue().isKindOf(rb_cClass)) {
78
- throw std::logic_error("expected Class value");
79
- }
80
- }
81
-
82
- } // namespace RubyQml
@@ -1,230 +0,0 @@
1
- #pragma once
2
- #include "functioninfo.h"
3
- #include "rubyvalue.h"
4
- #include <QDebug>
5
- #include <memory>
6
-
7
- namespace RubyQml {
8
-
9
- enum class MethodAccess { Public, Protected, Private };
10
- enum class MethodType { InstanceMethod, ModuleFunction };
11
-
12
- class RubyModule
13
- {
14
- public:
15
- RubyModule() = default;
16
- RubyModule(VALUE moduleValue);
17
- RubyModule(RubyValue moduleValue);
18
- RubyModule(const char *name);
19
- RubyModule(const RubyModule &under, const char *name);
20
- RubyModule(const RubyModule &) = default;
21
- RubyModule(RubyModule &&) = default;
22
- RubyModule &operator=(const RubyModule &other);
23
-
24
- static RubyModule fromPath(const char *path);
25
-
26
- template <typename TFunction, TFunction function>
27
- void defineMethod(MethodType type, MethodAccess access, const char *name, FunctionInfo<TFunction, function>)
28
- {
29
- using wrapper = FunctionWrapper<TFunction, function>;
30
- auto func = (VALUE (*)(...))wrapper::apply;
31
- auto argc = wrapper::argc - 1;
32
-
33
- switch (type) {
34
- case MethodType::InstanceMethod:
35
- switch (access) {
36
- case MethodAccess::Public:
37
- rb_define_method(mValue , name, func, argc);
38
- break;
39
- case MethodAccess::Protected:
40
- rb_define_protected_method(mValue, name, func, argc);
41
- break;
42
- case MethodAccess::Private:
43
- rb_define_private_method(mValue, name, func, argc);
44
- break;
45
- }
46
- break;
47
- case MethodType::ModuleFunction:
48
- rb_define_module_function(mValue, name, func, argc);
49
- break;
50
- }
51
- }
52
-
53
- template <typename T>
54
- void defineMethod(MethodAccess access, const char *name, T info)
55
- {
56
- defineMethod(MethodType::InstanceMethod, access, name, info);
57
- }
58
-
59
- template <typename T>
60
- void defineModuleFunction(const char *name, T info)
61
- {
62
- defineMethod(MethodType::ModuleFunction, MethodAccess::Public, name, info);
63
- }
64
-
65
- template <typename T>
66
- void defineMethod(const char *name, T info)
67
- {
68
- defineMethod(MethodAccess::Public, name, info);
69
- }
70
-
71
- void aliasMethod(const char *newName, const char *originalName);
72
-
73
- RubyValue toValue() const { return mValue; }
74
- operator RubyValue() const { return toValue(); }
75
- operator VALUE() const { return toValue(); }
76
-
77
- virtual void checkType();
78
-
79
- private:
80
- template <typename TFunction, TFunction function>
81
- struct FunctionWrapper;
82
-
83
- template <typename ... TArgs, RubyValue (*function)(TArgs...)>
84
- struct FunctionWrapper<RubyValue (*)(TArgs...), function>
85
- {
86
- static constexpr size_t argc = sizeof...(TArgs);
87
-
88
- static VALUE apply(typename std::conditional<true, VALUE, TArgs>::type... args)
89
- {
90
- RubyValue ret;
91
- // use tuple to avoid gcc 4.8's bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55914)
92
- auto tuple = std::make_tuple(args...);
93
- convertCppErrors([&] {
94
- ret = applyWithTuple(function, tuple);
95
- });
96
- return ret;
97
- }
98
- };
99
-
100
- RubyValue mValue;
101
- };
102
-
103
- class RubyClass : public RubyModule
104
- {
105
- public:
106
- RubyClass() = default;
107
- RubyClass(RubyValue classValue);
108
- RubyClass(const RubyModule &under, const char *name);
109
-
110
- static RubyClass fromPath(const char *path);
111
-
112
- void checkType() override;
113
-
114
- template <typename ... Args>
115
- RubyValue newInstance(Args ... args)
116
- {
117
- return toValue().send(RUBYQML_INTERN("new"), args...);
118
- }
119
- };
120
-
121
-
122
- template <typename T>
123
- class WrapperRubyClass : public RubyClass
124
- {
125
- public:
126
- WrapperRubyClass(const RubyModule &under, const char *name) :
127
- RubyClass(under, name)
128
- {
129
- if (mInstance) {
130
- throw std::logic_error("class already defined");
131
- }
132
- mInstance.reset(new WrapperRubyClass(*this));
133
-
134
- rb_define_alloc_func(toValue(), &alloc);
135
- }
136
-
137
- T *unwrap(RubyValue value)
138
- {
139
- auto klass = this->toValue();
140
-
141
- if (!RTEST(rb_obj_is_kind_of(value, klass))) {
142
- rb_raise(rb_eTypeError, "expected %s, got %s", rb_class2name(klass), rb_obj_classname(value));
143
- }
144
-
145
- T *ptr;
146
- Data_Get_Struct(VALUE(value), T, ptr);
147
- return ptr;
148
- }
149
-
150
- using RubyClass::defineMethod;
151
-
152
- template <typename TMemberFunction, TMemberFunction memberFunction>
153
- void defineMethod(MethodAccess access, const char *name, MemberFunctionInfo<TMemberFunction, memberFunction>)
154
- {
155
- using wrapper = MethodWrapper<TMemberFunction, memberFunction>;
156
- defineMethod(access, name, RUBYQML_FUNCTION_INFO(&wrapper::apply));
157
- }
158
-
159
- template <typename TMemberFunction, TMemberFunction memberFunction>
160
- void defineMethod(const char *name, MemberFunctionInfo<TMemberFunction, memberFunction> info)
161
- {
162
- defineMethod(MethodAccess::Public, name, info);
163
- }
164
-
165
- static WrapperRubyClass instance()
166
- {
167
- if (!mInstance) {
168
- throw std::logic_error("class not yet defined");
169
- }
170
- return *mInstance;
171
- }
172
-
173
- private:
174
-
175
- template <typename TMemberFunction, TMemberFunction memfn>
176
- struct MethodWrapper;
177
-
178
- template <typename ... TArgs, RubyValue (T::*memfn)(TArgs ...)>
179
- struct MethodWrapper<RubyValue (T::*)(TArgs ...), memfn>
180
- {
181
- static RubyValue apply(RubyValue self, TArgs ... args)
182
- {
183
- return (instance().unwrap(self)->*memfn)(args ...);
184
- }
185
- };
186
-
187
- template <typename ... TArgs, RubyValue (T::*memfn)(TArgs ...) const>
188
- struct MethodWrapper<RubyValue (T::*)(TArgs ...) const, memfn>
189
- {
190
- static RubyValue apply(RubyValue self, TArgs... args)
191
- {
192
- return (instance().unwrap(self)->*memfn)(args ...);
193
- }
194
- };
195
-
196
- static void mark(T *ptr) noexcept
197
- {
198
- ptr->gc_mark();
199
- }
200
-
201
- static void dealloc(T *ptr) noexcept
202
- {
203
- withoutGvl([&] {
204
- ptr->~T();
205
- });
206
- ruby_xfree(ptr);
207
- }
208
-
209
- static VALUE alloc(VALUE klass) noexcept
210
- {
211
- auto ptr = ruby_xmalloc(sizeof(T));
212
- auto self = Data_Wrap_Struct(klass, &mark, &dealloc, ptr);
213
- new(ptr) T(self);
214
- return self;
215
- }
216
-
217
- static std::unique_ptr<WrapperRubyClass> mInstance;
218
- };
219
-
220
- template <typename T>
221
- std::unique_ptr<WrapperRubyClass<T>> WrapperRubyClass<T>::mInstance = nullptr;
222
-
223
- template <typename T>
224
- inline WrapperRubyClass<T> wrapperRubyClass()
225
- {
226
- return WrapperRubyClass<T>::instance();
227
- }
228
-
229
- } // namespace RubyQml
230
-