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.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.travis.yml +5 -9
- data/LICENSE.txt +1 -1
- data/README.md +84 -114
- data/changes.md +5 -0
- data/examples/fizzbuzz/fizzbuzz.rb +3 -4
- data/examples/todo_array/todo_array.rb +4 -4
- data/examples/todo_sequel/todo_sequel.rb +7 -7
- data/examples/twitter/twitter.rb +5 -3
- data/ext/qml/application.c +88 -0
- data/ext/qml/application.h +9 -0
- data/ext/qml/component.c +89 -0
- data/ext/qml/component.h +10 -0
- data/ext/qml/conversion.c +60 -0
- data/ext/qml/conversion.h +8 -0
- data/ext/qml/dispatcher.c +31 -0
- data/ext/qml/dispatcher.h +7 -0
- data/ext/qml/engine.c +135 -0
- data/ext/qml/engine.h +10 -0
- data/ext/qml/exporter.c +93 -0
- data/ext/qml/exporter.h +7 -0
- data/ext/qml/extconf.rb +38 -97
- data/ext/qml/interface.c +156 -0
- data/ext/qml/interface.h +11 -0
- data/ext/qml/js_array.c +47 -0
- data/ext/qml/js_array.h +7 -0
- data/ext/qml/js_function.c +109 -0
- data/ext/qml/js_function.h +7 -0
- data/ext/qml/js_object.c +284 -0
- data/ext/qml/js_object.h +19 -0
- data/ext/qml/js_wrapper.c +19 -0
- data/ext/qml/js_wrapper.h +7 -0
- data/ext/qml/lib/libqmlbind/.gitignore +38 -0
- data/ext/qml/lib/libqmlbind/.gitmodules +3 -0
- data/ext/qml/lib/libqmlbind/.travis.yml +14 -0
- data/ext/qml/lib/libqmlbind/LICENSE.txt +22 -0
- data/ext/qml/lib/libqmlbind/libqmlbind.pro +3 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind.h +14 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/application.h +18 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/component.h +21 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/engine.h +34 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/exporter.h +37 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/interface.h +16 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/iterator.h +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/metaobject.h +13 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/plugin.h +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/qmlbind_global.h +78 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/register.h +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/signal_emitter.h +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/string.h +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/value.h +100 -0
- data/ext/qml/lib/libqmlbind/qmlbind/qmlbind.pro +62 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_application.cpp +103 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_component.cpp +54 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_engine.cpp +65 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_exporter.cpp +52 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_interface.cpp +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_iterator.cpp +32 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_metaobject.cpp +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_plugin.cpp +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_register.cpp +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_signal_emitter.cpp +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_string.cpp +22 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_value.cpp +215 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/backref.cpp +54 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/backref.h +29 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/engine.cpp +32 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/engine.h +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.cpp +73 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.h +46 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/interface.cpp +75 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/interface.h +37 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.cpp +101 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.h +29 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.cpp +33 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.h +25 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.cpp +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.h +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.cpp +112 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.h +28 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/util.h +13 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.cpp +23 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.h +29 -0
- data/ext/qml/lib/libqmlbind/readme.md +14 -0
- data/ext/qml/lib/libqmlbind/test/api.c +1 -0
- data/ext/qml/lib/libqmlbind/test/application_test.cpp +16 -0
- data/ext/qml/lib/libqmlbind/test/component_test.cpp +57 -0
- data/ext/qml/lib/libqmlbind/test/engine_test.cpp +94 -0
- data/ext/qml/lib/libqmlbind/test/exporter_test.cpp +312 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.cpp +36 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.h +6 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/test.qml +5 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/qmldir +2 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/test.qml +5 -0
- data/ext/qml/lib/libqmlbind/test/iterator_test.cpp +37 -0
- data/ext/qml/lib/libqmlbind/test/main.cpp +11 -0
- data/ext/qml/lib/libqmlbind/test/plugin_test.cpp +41 -0
- data/ext/qml/lib/libqmlbind/test/test.pro +26 -0
- data/ext/qml/lib/libqmlbind/test/test_helper.h +20 -0
- data/ext/qml/lib/libqmlbind/test/value_test.cpp +252 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.cpp +11 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.h +21 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.json +3 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.pro +21 -0
- data/ext/qml/meta_object.c +81 -0
- data/ext/qml/meta_object.h +8 -0
- data/ext/qml/plugin_loader.c +71 -0
- data/ext/qml/plugin_loader.h +7 -0
- data/ext/qml/qml.c +95 -0
- data/ext/qml/qml.h +10 -0
- data/ext/qml/rubyqml-plugin/listmodel.cpp +102 -0
- data/ext/qml/rubyqml-plugin/listmodel.h +37 -0
- data/ext/qml/rubyqml-plugin/rubyqml-plugin.pro +19 -0
- data/ext/qml/rubyqml-plugin/rubyqmlplugin.cpp +25 -0
- data/ext/qml/rubyqml-plugin/rubyqmlplugin.h +19 -0
- data/ext/qml/signal_emitter.c +71 -0
- data/ext/qml/signal_emitter.h +9 -0
- data/lib/qml.rb +11 -10
- data/lib/qml/access.rb +64 -86
- data/lib/qml/application.rb +20 -71
- data/lib/qml/component.rb +41 -33
- data/lib/qml/core_ext.rb +1 -0
- data/lib/qml/core_ext/to_qml.rb +70 -0
- data/lib/qml/data.rb +1 -0
- data/lib/qml/data/array_model.rb +99 -101
- data/lib/qml/data/list_model.rb +107 -131
- data/lib/qml/data/list_model_access.rb +44 -0
- data/lib/qml/data/query_model.rb +45 -47
- data/lib/qml/dispatcher.rb +5 -13
- data/lib/qml/engine.rb +9 -58
- data/lib/qml/errors.rb +0 -21
- data/lib/qml/interface.rb +21 -0
- data/lib/qml/js_array.rb +8 -0
- data/lib/qml/js_object.rb +69 -0
- data/lib/qml/js_util.rb +18 -0
- data/lib/qml/plugin_loader.rb +1 -13
- data/lib/qml/plugins.rb +3 -17
- data/lib/qml/proc_access.rb +28 -0
- data/lib/qml/qt.rb +21 -3
- data/lib/qml/reactive.rb +147 -8
- data/lib/qml/signal.rb +67 -0
- data/lib/qml/version.rb +1 -1
- data/qml.gemspec +8 -2
- data/spec/qml/access_spec.rb +33 -120
- data/spec/qml/application_spec.rb +11 -24
- data/spec/qml/component_spec.rb +4 -4
- data/spec/qml/data/array_model_spec.rb +2 -2
- data/spec/qml/data/list_model_spec.rb +2 -2
- data/spec/qml/data/query_model_spec.rb +4 -4
- data/spec/qml/engine_spec.rb +23 -21
- data/spec/qml/interface_spec.rb +20 -0
- data/spec/qml/js_array_spec.rb +29 -0
- data/spec/qml/js_function_spec.rb +32 -0
- data/spec/qml/js_object_spec.rb +113 -0
- data/spec/qml/plugin_loader_spec.rb +9 -11
- data/spec/qml/qt_spec.rb +9 -0
- data/spec/qml/reactive_spec.rb +37 -0
- data/spec/qml/signal_connect_spec.rb +27 -0
- data/spec/qml/signal_spec.rb +73 -0
- data/spec/qml/to_qml_spec.rb +76 -0
- data/spec/shared/qml/access_example.rb +21 -0
- data/spec/shared/qml/data/list_model.rb +12 -13
- data/spec/spec_helper.rb +2 -3
- metadata +141 -166
- data/examples/imageprovider/imageprovider.rb +0 -57
- data/examples/imageprovider/main.qml +0 -51
- data/ext/qml/accessclass.cpp +0 -65
- data/ext/qml/accessclass.h +0 -19
- data/ext/qml/accessobject.cpp +0 -30
- data/ext/qml/accessobject.h +0 -22
- data/ext/qml/common.h +0 -18
- data/ext/qml/conversionerror.h +0 -14
- data/ext/qml/ext_accesswrapperfactory.cpp +0 -75
- data/ext/qml/ext_accesswrapperfactory.h +0 -39
- data/ext/qml/ext_anywrapper.cpp +0 -34
- data/ext/qml/ext_anywrapper.h +0 -23
- data/ext/qml/ext_kernel.cpp +0 -81
- data/ext/qml/ext_kernel.h +0 -9
- data/ext/qml/ext_metaobject.cpp +0 -399
- data/ext/qml/ext_metaobject.h +0 -60
- data/ext/qml/ext_pluginloader.cpp +0 -53
- data/ext/qml/ext_pluginloader.h +0 -30
- data/ext/qml/ext_pointer.cpp +0 -132
- data/ext/qml/ext_pointer.h +0 -41
- data/ext/qml/ext_testutil.cpp +0 -40
- data/ext/qml/ext_testutil.h +0 -9
- data/ext/qml/foreignclass.cpp +0 -72
- data/ext/qml/foreignclass.h +0 -88
- data/ext/qml/foreignmetaobject.cpp +0 -345
- data/ext/qml/foreignmetaobject.h +0 -46
- data/ext/qml/foreignobject.cpp +0 -22
- data/ext/qml/foreignobject.h +0 -21
- data/ext/qml/functioninfo.h +0 -16
- data/ext/qml/init.cpp +0 -67
- data/ext/qml/kernel.cpp +0 -39
- data/ext/qml/kernel.h +0 -32
- data/ext/qml/listmodel.cpp +0 -137
- data/ext/qml/listmodel.h +0 -45
- data/ext/qml/markable.h +0 -12
- data/ext/qml/objectdata.cpp +0 -26
- data/ext/qml/objectdata.h +0 -20
- data/ext/qml/objectgc.cpp +0 -69
- data/ext/qml/objectgc.h +0 -28
- data/ext/qml/plugins/core/applicationextension.cpp +0 -29
- data/ext/qml/plugins/core/applicationextension.h +0 -25
- data/ext/qml/plugins/core/componentextension.cpp +0 -41
- data/ext/qml/plugins/core/componentextension.h +0 -28
- data/ext/qml/plugins/core/contextextension.cpp +0 -39
- data/ext/qml/plugins/core/contextextension.h +0 -29
- data/ext/qml/plugins/core/core.pro +0 -29
- data/ext/qml/plugins/core/coreplugin.cpp +0 -87
- data/ext/qml/plugins/core/coreplugin.h +0 -49
- data/ext/qml/plugins/core/engineextension.cpp +0 -43
- data/ext/qml/plugins/core/engineextension.h +0 -31
- data/ext/qml/plugins/core/imageprovider.cpp +0 -38
- data/ext/qml/plugins/core/imageprovider.h +0 -18
- data/ext/qml/plugins/core/imagerequestpromise.cpp +0 -19
- data/ext/qml/plugins/core/imagerequestpromise.h +0 -21
- data/ext/qml/plugins/core/qmlexception.cpp +0 -11
- data/ext/qml/plugins/core/qmlexception.h +0 -17
- data/ext/qml/plugins/testutil/imageprovidertest.cpp +0 -40
- data/ext/qml/plugins/testutil/imageprovidertest.h +0 -17
- data/ext/qml/plugins/testutil/objectlifechecker.cpp +0 -17
- data/ext/qml/plugins/testutil/objectlifechecker.h +0 -24
- data/ext/qml/plugins/testutil/ownershiptest.cpp +0 -26
- data/ext/qml/plugins/testutil/ownershiptest.h +0 -30
- data/ext/qml/plugins/testutil/testobject.cpp +0 -6
- data/ext/qml/plugins/testutil/testobject.h +0 -108
- data/ext/qml/plugins/testutil/testobjectsubclass.cpp +0 -10
- data/ext/qml/plugins/testutil/testobjectsubclass.h +0 -19
- data/ext/qml/plugins/testutil/testutil.pro +0 -22
- data/ext/qml/plugins/testutil/testutilplugin.cpp +0 -55
- data/ext/qml/plugins/testutil/testutilplugin.h +0 -36
- data/ext/qml/qmltyperegisterer.cpp +0 -74
- data/ext/qml/qmltyperegisterer.h +0 -30
- data/ext/qml/rubyclass.cpp +0 -82
- data/ext/qml/rubyclass.h +0 -230
- data/ext/qml/rubyvalue.cpp +0 -656
- data/ext/qml/rubyvalue.h +0 -224
- data/ext/qml/signalforwarder.cpp +0 -64
- data/ext/qml/signalforwarder.h +0 -29
- data/ext/qml/util.cpp +0 -112
- data/ext/qml/util.h +0 -82
- data/ext/qml/valuereference.cpp +0 -50
- data/ext/qml/valuereference.h +0 -22
- data/ext/qml/weakvaluereference.cpp +0 -51
- data/ext/qml/weakvaluereference.h +0 -21
- data/lib/qml/context.rb +0 -71
- data/lib/qml/data/error.rb +0 -5
- data/lib/qml/dispatchable.rb +0 -34
- data/lib/qml/error_converter.rb +0 -16
- data/lib/qml/geometry.rb +0 -3
- data/lib/qml/geometry/point.rb +0 -5
- data/lib/qml/geometry/rectangle.rb +0 -5
- data/lib/qml/geometry/size.rb +0 -5
- data/lib/qml/image_provider.rb +0 -87
- data/lib/qml/init.rb +0 -29
- data/lib/qml/meta_object.rb +0 -20
- data/lib/qml/models.rb +0 -1
- data/lib/qml/qt_classes.rb +0 -9
- data/lib/qml/qt_object_base.rb +0 -233
- data/lib/qml/reactive/bindable.rb +0 -79
- data/lib/qml/reactive/chained_signal.rb +0 -25
- data/lib/qml/reactive/error.rb +0 -5
- data/lib/qml/reactive/object.rb +0 -293
- data/lib/qml/reactive/property.rb +0 -19
- data/lib/qml/reactive/signal.rb +0 -115
- data/lib/qml/reactive/signal_spy.rb +0 -27
- data/lib/qml/reactive/signals/map_signal.rb +0 -21
- data/lib/qml/reactive/signals/merge_signal.rb +0 -21
- data/lib/qml/reactive/signals/select_signal.rb +0 -21
- data/lib/qml/reactive/simple_property.rb +0 -17
- data/lib/qml/reactive/unbound_property.rb +0 -42
- data/lib/qml/reactive/unbound_signal.rb +0 -51
- data/lib/qml/test_util.rb +0 -1
- data/lib/qml/test_util/object_life_checker.rb +0 -17
- data/lib/qml/wrappable.rb +0 -9
- data/spec/qml/context_spec.rb +0 -43
- data/spec/qml/conversion_spec.rb +0 -60
- data/spec/qml/dispatchable_spec.rb +0 -26
- data/spec/qml/dispatcher_spec.rb +0 -71
- data/spec/qml/geometry/point_spec.rb +0 -4
- data/spec/qml/geometry/rectangle_spec.rb +0 -4
- data/spec/qml/geometry/size_spec.rb +0 -4
- data/spec/qml/image_provider_spec.rb +0 -33
- data/spec/qml/qt_object_base_spec.rb +0 -119
- data/spec/qml/reactive/object_spec.rb +0 -249
- data/spec/qml/reactive/property_spec.rb +0 -70
- data/spec/qml/reactive/signal_spec.rb +0 -191
- data/spec/qml/reactive/signal_spy_spec.rb +0 -26
- data/spec/qml/reactive/unbound_property_spec.rb +0 -40
- data/spec/qml/reactive/unbound_signal_spec.rb +0 -70
- data/spec/qml/test_object_spec.rb +0 -186
- data/spec/qml/wrappable_spec.rb +0 -10
- data/spec/shared/qml/reactive/object.rb +0 -39
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#include "qmlbind/signal_emitter.h"
|
|
2
|
+
#include "signalemitter.h"
|
|
3
|
+
#include "engine.h"
|
|
4
|
+
#include <QQmlEngine>
|
|
5
|
+
#include <QQmlContext>
|
|
6
|
+
|
|
7
|
+
using namespace QmlBind;
|
|
8
|
+
|
|
9
|
+
extern "C" {
|
|
10
|
+
|
|
11
|
+
void qmlbind_signal_emitter_emit(qmlbind_signal_emitter emitter, const char *signal_name, int argc, qmlbind_value *argv)
|
|
12
|
+
{
|
|
13
|
+
emitter->emitSignal(signal_name, argc, argv);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
qmlbind_engine qmlbind_signal_emitter_get_engine(qmlbind_signal_emitter emitter)
|
|
17
|
+
{
|
|
18
|
+
Wrapper *wrapper = emitter->wrapper();
|
|
19
|
+
return qobject_cast<Engine *>(QQmlEngine::contextForObject(wrapper)->engine());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void qmlbind_signal_emitter_release(qmlbind_signal_emitter emitter)
|
|
23
|
+
{
|
|
24
|
+
delete emitter;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#include "qmlbind/string.h"
|
|
2
|
+
#include <QByteArray>
|
|
3
|
+
#include <QList>
|
|
4
|
+
|
|
5
|
+
extern "C" {
|
|
6
|
+
|
|
7
|
+
char *qmlbind_string_get_chars(qmlbind_string str)
|
|
8
|
+
{
|
|
9
|
+
return str->data();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
int qmlbind_string_get_length(qmlbind_string str)
|
|
13
|
+
{
|
|
14
|
+
return str->size();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
void qmlbind_string_release(qmlbind_string str)
|
|
18
|
+
{
|
|
19
|
+
delete str;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#include "qmlbind/value.h"
|
|
2
|
+
#include "wrapper.h"
|
|
3
|
+
#include <QJSValue>
|
|
4
|
+
#include <QJSEngine>
|
|
5
|
+
|
|
6
|
+
using namespace QmlBind;
|
|
7
|
+
|
|
8
|
+
extern "C" {
|
|
9
|
+
|
|
10
|
+
qmlbind_value qmlbind_value_new_undefined()
|
|
11
|
+
{
|
|
12
|
+
return new QJSValue(QJSValue::UndefinedValue);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
qmlbind_value qmlbind_value_new_null()
|
|
16
|
+
{
|
|
17
|
+
return new QJSValue(QJSValue::NullValue);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void qmlbind_value_release(qmlbind_value self)
|
|
21
|
+
{
|
|
22
|
+
delete self;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
qmlbind_value qmlbind_value_clone(qmlbind_value self)
|
|
26
|
+
{
|
|
27
|
+
return new QJSValue(*self);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
int qmlbind_value_is_equal(qmlbind_value value1, qmlbind_value value2)
|
|
31
|
+
{
|
|
32
|
+
return value1->equals(*value2);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
int qmlbind_value_is_identical(qmlbind_value value1, qmlbind_value value2)
|
|
36
|
+
{
|
|
37
|
+
return value1->strictlyEquals(*value2);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
int qmlbind_value_is_undefined(qmlbind_value self)
|
|
41
|
+
{
|
|
42
|
+
return self->isUndefined();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
int qmlbind_value_is_null(qmlbind_value self)
|
|
46
|
+
{
|
|
47
|
+
return self->isNull();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
int qmlbind_value_is_boolean(qmlbind_value self)
|
|
51
|
+
{
|
|
52
|
+
return self->isBool();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
int qmlbind_value_is_number(qmlbind_value self)
|
|
56
|
+
{
|
|
57
|
+
return self->isNumber();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
int qmlbind_value_is_string(qmlbind_value self)
|
|
61
|
+
{
|
|
62
|
+
return self->isString();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
int qmlbind_value_is_object(qmlbind_value self)
|
|
66
|
+
{
|
|
67
|
+
return self->isObject();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
int qmlbind_value_is_array(qmlbind_value self)
|
|
71
|
+
{
|
|
72
|
+
return self->isArray();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
int qmlbind_value_is_function(qmlbind_value self)
|
|
76
|
+
{
|
|
77
|
+
return self->isCallable();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
int qmlbind_value_is_error(qmlbind_value self)
|
|
81
|
+
{
|
|
82
|
+
return self->isError();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
int qmlbind_value_is_wrapper(qmlbind_value self)
|
|
86
|
+
{
|
|
87
|
+
return qmlbind_value_get_backref(self) != 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
qmlbind_value qmlbind_value_new_boolean(int x)
|
|
91
|
+
{
|
|
92
|
+
return new QJSValue(bool(x));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
int qmlbind_value_get_boolean(qmlbind_value self)
|
|
96
|
+
{
|
|
97
|
+
return self->toBool();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
qmlbind_value qmlbind_value_new_number(double x)
|
|
101
|
+
{
|
|
102
|
+
return new QJSValue(x);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
double qmlbind_value_get_number(qmlbind_value self)
|
|
106
|
+
{
|
|
107
|
+
return self->toNumber();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
qmlbind_value qmlbind_value_new_string(int len, const char *str)
|
|
111
|
+
{
|
|
112
|
+
return new QJSValue(QString::fromUtf8(str, len));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
qmlbind_value qmlbind_value_new_string_cstr(const char *str)
|
|
116
|
+
{
|
|
117
|
+
return new QJSValue(QString::fromUtf8(str));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
qmlbind_string qmlbind_value_get_string(qmlbind_value self)
|
|
121
|
+
{
|
|
122
|
+
return new QByteArray(self->toString().toUtf8());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
qmlbind_value qmlbind_value_get_property(qmlbind_value self, const char *key)
|
|
126
|
+
{
|
|
127
|
+
return new QJSValue(self->property(QString::fromUtf8(key)));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
void qmlbind_value_set_property(qmlbind_value self, const char *key, qmlbind_value value)
|
|
131
|
+
{
|
|
132
|
+
QJSValue obj = *self;
|
|
133
|
+
obj.setProperty(QString::fromUtf8(key), *value);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
int qmlbind_value_delete_property(qmlbind_value self, const char *key)
|
|
137
|
+
{
|
|
138
|
+
QJSValue value = *self;
|
|
139
|
+
return value.deleteProperty(key);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
int qmlbind_value_has_property(qmlbind_value value, const char *key)
|
|
143
|
+
{
|
|
144
|
+
return value->hasProperty(key);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
int qmlbind_value_has_index(qmlbind_value value, int index)
|
|
148
|
+
{
|
|
149
|
+
return value->hasProperty(QString::number(index));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
int qmlbind_value_has_own_property(qmlbind_value value, const char *key)
|
|
153
|
+
{
|
|
154
|
+
return value->hasOwnProperty(key);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
qmlbind_value qmlbind_value_get_prototype(qmlbind_value value)
|
|
158
|
+
{
|
|
159
|
+
return new QJSValue(value->prototype());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
void qmlbind_value_set_prototype(qmlbind_value self, qmlbind_value proto)
|
|
163
|
+
{
|
|
164
|
+
QJSValue obj = *self;
|
|
165
|
+
obj.setPrototype(*proto);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
qmlbind_value qmlbind_value_get_array_item(qmlbind_value value, int index)
|
|
169
|
+
{
|
|
170
|
+
return new QJSValue(value->property(index));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
void qmlbind_value_set_array_item(qmlbind_value self, int index, qmlbind_value property)
|
|
174
|
+
{
|
|
175
|
+
QJSValue obj = *self;
|
|
176
|
+
obj.setProperty(index, *property);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
qmlbind_backref qmlbind_value_get_backref(qmlbind_value self)
|
|
180
|
+
{
|
|
181
|
+
Wrapper *obj = dynamic_cast<Wrapper *>(self->toQObject());
|
|
182
|
+
if (!obj) {
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
return obj->backref().backref();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static QJSValueList pack_args(int argc, qmlbind_value *argv)
|
|
189
|
+
{
|
|
190
|
+
QJSValueList args;
|
|
191
|
+
for (int i = 0; i < argc; ++i) {
|
|
192
|
+
args << *argv[i];
|
|
193
|
+
}
|
|
194
|
+
return args;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
qmlbind_value qmlbind_value_call(qmlbind_value self, int argc, qmlbind_value *argv)
|
|
198
|
+
{
|
|
199
|
+
QJSValue func = *self;
|
|
200
|
+
return new QJSValue(func.call(pack_args(argc, argv)));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
qmlbind_value qmlbind_value_call_constructor(qmlbind_value self, int argc, qmlbind_value *argv)
|
|
204
|
+
{
|
|
205
|
+
QJSValue func = *self;
|
|
206
|
+
return new QJSValue(func.callAsConstructor(pack_args(argc, argv)));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
qmlbind_value qmlbind_value_call_with_instance(qmlbind_value self, qmlbind_value instance, int argc, qmlbind_value *argv)
|
|
210
|
+
{
|
|
211
|
+
QJSValue func = *self;
|
|
212
|
+
return new QJSValue(func.callWithInstance(*instance, pack_args(argc, argv)));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#include "backref.h"
|
|
2
|
+
#include "interface.h"
|
|
3
|
+
|
|
4
|
+
namespace QmlBind {
|
|
5
|
+
|
|
6
|
+
Backref::Backref()
|
|
7
|
+
{
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
Backref::Backref(qmlbind_backref backref, const QSharedPointer<Interface> &interface) :
|
|
11
|
+
mBackref(backref),
|
|
12
|
+
mInterface(interface)
|
|
13
|
+
{
|
|
14
|
+
retain();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Backref::Backref(const Backref &other) :
|
|
18
|
+
mBackref(other.mBackref),
|
|
19
|
+
mInterface(other.mInterface)
|
|
20
|
+
{
|
|
21
|
+
retain();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Backref::~Backref()
|
|
25
|
+
{
|
|
26
|
+
release();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Backref &Backref::operator=(const Backref &other)
|
|
30
|
+
{
|
|
31
|
+
release();
|
|
32
|
+
mInterface = other.mInterface;
|
|
33
|
+
mBackref = other.mBackref;
|
|
34
|
+
retain();
|
|
35
|
+
|
|
36
|
+
return *this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void Backref::retain()
|
|
40
|
+
{
|
|
41
|
+
if (mInterface) {
|
|
42
|
+
mInterface->retainObject(mBackref);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void Backref::release()
|
|
47
|
+
{
|
|
48
|
+
if (mInterface) {
|
|
49
|
+
mInterface->releaseObject(mBackref);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
} // namespace QmlBind
|
|
54
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "qmlbind/qmlbind_global.h"
|
|
4
|
+
#include <QSharedPointer>
|
|
5
|
+
|
|
6
|
+
namespace QmlBind {
|
|
7
|
+
|
|
8
|
+
class Backref
|
|
9
|
+
{
|
|
10
|
+
public:
|
|
11
|
+
Backref();
|
|
12
|
+
Backref(qmlbind_backref backref, const QSharedPointer<Interface> &interface);
|
|
13
|
+
Backref(const Backref &other);
|
|
14
|
+
~Backref();
|
|
15
|
+
|
|
16
|
+
Backref &operator=(const Backref &other);
|
|
17
|
+
|
|
18
|
+
qmlbind_backref backref() const { return mBackref; }
|
|
19
|
+
QSharedPointer<Interface> interface() const { return mInterface; }
|
|
20
|
+
|
|
21
|
+
private:
|
|
22
|
+
void retain();
|
|
23
|
+
void release();
|
|
24
|
+
|
|
25
|
+
qmlbind_backref mBackref;
|
|
26
|
+
QSharedPointer<Interface> mInterface;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // namespace QmlBind
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#include "engine.h"
|
|
2
|
+
#include <QQmlComponent>
|
|
3
|
+
|
|
4
|
+
namespace QmlBind {
|
|
5
|
+
|
|
6
|
+
Engine::Engine() : QQmlEngine(), mDeleteScheduled(false)
|
|
7
|
+
{
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
void Engine::addComponent(QQmlComponent *component)
|
|
11
|
+
{
|
|
12
|
+
mComponents << component;
|
|
13
|
+
connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(onComponentRemoved()));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
void Engine::scheduleDelete()
|
|
17
|
+
{
|
|
18
|
+
if (mComponents.size() == 0) {
|
|
19
|
+
delete this;
|
|
20
|
+
}
|
|
21
|
+
mDeleteScheduled = true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void Engine::onComponentRemoved()
|
|
25
|
+
{
|
|
26
|
+
mComponents.removeAll(qobject_cast<QQmlComponent *>(sender()));
|
|
27
|
+
if (mComponents.size() == 0) {
|
|
28
|
+
delete this;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
} // namespace QmlBind
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <QQmlEngine>
|
|
4
|
+
|
|
5
|
+
namespace QmlBind {
|
|
6
|
+
|
|
7
|
+
class Engine : public QQmlEngine
|
|
8
|
+
{
|
|
9
|
+
Q_OBJECT
|
|
10
|
+
public:
|
|
11
|
+
Engine();
|
|
12
|
+
|
|
13
|
+
void addComponent(QQmlComponent *component);
|
|
14
|
+
void scheduleDelete();
|
|
15
|
+
|
|
16
|
+
signals:
|
|
17
|
+
|
|
18
|
+
public slots:
|
|
19
|
+
void onComponentRemoved();
|
|
20
|
+
|
|
21
|
+
private:
|
|
22
|
+
|
|
23
|
+
bool mDeleteScheduled;
|
|
24
|
+
QList<QQmlComponent *> mComponents;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
} // namespace QmlBind
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#include "exporter.h"
|
|
2
|
+
#include "interface.h"
|
|
3
|
+
#include <stdexcept>
|
|
4
|
+
#include <QVector>
|
|
5
|
+
#include <QDebug>
|
|
6
|
+
|
|
7
|
+
namespace QmlBind {
|
|
8
|
+
|
|
9
|
+
Exporter::Exporter(const char *className, const Backref &classRef) :
|
|
10
|
+
mClassRef(classRef)
|
|
11
|
+
{
|
|
12
|
+
mBuilder.setClassName(className);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static QByteArray methodSignature(const char *name, int arity)
|
|
16
|
+
{
|
|
17
|
+
QByteArray sig;
|
|
18
|
+
sig += name;
|
|
19
|
+
sig += "(";
|
|
20
|
+
for (int i = 0; i < arity; ++i) {
|
|
21
|
+
if (i != 0) {
|
|
22
|
+
sig += ",";
|
|
23
|
+
}
|
|
24
|
+
sig += "QJSValue";
|
|
25
|
+
}
|
|
26
|
+
sig += ")";
|
|
27
|
+
return sig;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
QMetaMethodBuilder Exporter::addMethod(const char *name, int arity)
|
|
33
|
+
{
|
|
34
|
+
QMetaMethodBuilder method = mBuilder.addMethod(methodSignature(name, arity), "QJSValue");
|
|
35
|
+
|
|
36
|
+
Method methodInfo;
|
|
37
|
+
methodInfo.arity = arity;
|
|
38
|
+
methodInfo.name = name;
|
|
39
|
+
|
|
40
|
+
mMethodMap[method.index()] = methodInfo;
|
|
41
|
+
|
|
42
|
+
return method;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
QMetaMethodBuilder Exporter::addSignal(const char *name, const QList<QByteArray> &args)
|
|
46
|
+
{
|
|
47
|
+
QMetaMethodBuilder method = mBuilder.addSignal(methodSignature(name, args.size()));
|
|
48
|
+
method.setParameterNames(args);
|
|
49
|
+
|
|
50
|
+
mSignalIndexMap[name] = method.index();
|
|
51
|
+
|
|
52
|
+
return method;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
QMetaPropertyBuilder Exporter::addProperty(const char *name, const char *notifier)
|
|
56
|
+
{
|
|
57
|
+
if (!mSignalIndexMap.contains(notifier)) {
|
|
58
|
+
qWarning() << "signal" << notifier << "not yet added";
|
|
59
|
+
}
|
|
60
|
+
QMetaPropertyBuilder property = mBuilder.addProperty(name, "QJSValue", mSignalIndexMap[notifier]);
|
|
61
|
+
|
|
62
|
+
property.setReadable(true);
|
|
63
|
+
property.setWritable(true);
|
|
64
|
+
|
|
65
|
+
Property propertyInfo;
|
|
66
|
+
propertyInfo.name = name;
|
|
67
|
+
|
|
68
|
+
mPropertyMap[property.index()] = propertyInfo;
|
|
69
|
+
|
|
70
|
+
return property;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
} // namespace QmlBind
|