qml 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,44 @@
|
|
1
|
+
module QML
|
2
|
+
# @api private
|
3
|
+
class ListModelAccess
|
4
|
+
include Access
|
5
|
+
|
6
|
+
signal :begin_insert, [:first, :last]
|
7
|
+
signal :end_insert
|
8
|
+
signal :begin_move, [:first, :last, :dest]
|
9
|
+
signal :end_move
|
10
|
+
signal :begin_remove, [:first, :last]
|
11
|
+
signal :end_remove
|
12
|
+
signal :update, [:first, :last]
|
13
|
+
signal :begin_reset
|
14
|
+
signal :end_reset
|
15
|
+
|
16
|
+
attr_accessor :model
|
17
|
+
|
18
|
+
def columns
|
19
|
+
@model.columns.to_qml
|
20
|
+
end
|
21
|
+
|
22
|
+
def data(index, column)
|
23
|
+
@model[index.to_i][column.to_sym].to_qml
|
24
|
+
end
|
25
|
+
|
26
|
+
def count
|
27
|
+
@model.count
|
28
|
+
end
|
29
|
+
|
30
|
+
register_to_qml under: 'RubyQml', version: QML::VERSION
|
31
|
+
|
32
|
+
# @return [QML::JSWrapper]
|
33
|
+
def self.create(model)
|
34
|
+
@component ||= QML::Component.new(data: <<-QML)
|
35
|
+
import RubyQml 1.0
|
36
|
+
ListModelAccess {}
|
37
|
+
QML
|
38
|
+
|
39
|
+
@component.create.tap do |access|
|
40
|
+
access.unwrap.model = model
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/qml/data/query_model.rb
CHANGED
@@ -1,59 +1,57 @@
|
|
1
1
|
module QML
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
2
|
+
# {QueryModel} provides a list model implementation with database backends like ActiveRecord.
|
3
|
+
class QueryModel < ListModel
|
4
|
+
attr_reader :count
|
5
|
+
|
6
|
+
# @param [Array<Symbol|String>] columns
|
7
|
+
def initialize(*columns)
|
8
|
+
super
|
9
|
+
@count = 0
|
10
|
+
@caches = []
|
11
|
+
update
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def [](index)
|
15
|
+
block_index = index / CACHE_SIZE
|
16
|
+
cache = @caches.find { |c| c.block_index == block_index } || add_cache(block_index)
|
17
|
+
cache.items[index % CACHE_SIZE]
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
20
|
+
# Updates the model.
|
21
|
+
def update
|
22
|
+
@caches = []
|
23
|
+
resetting do
|
24
|
+
@count = query_count
|
27
25
|
end
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
# @abstract
|
29
|
+
# Queries the count of the records.
|
30
|
+
# Called when {#update} is called and the result is set as the {#count} of the model.
|
31
|
+
# @return [Integer]
|
32
|
+
def query_count
|
33
|
+
fail ::NotImplementedError
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
# @abstract
|
37
|
+
# Queries a block of records. The results are chached.
|
38
|
+
# @param [Integer] offset
|
39
|
+
# @param [Integer] count
|
40
|
+
# @return [Array]
|
41
|
+
def query(offset, count)
|
42
|
+
fail ::NotImplementedError
|
43
|
+
end
|
45
44
|
|
46
|
-
|
45
|
+
private
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
Cache = Struct.new(:block_index, :items)
|
48
|
+
CACHE_SIZE = 256
|
49
|
+
CACHE_COUNT = 4
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
51
|
+
def add_cache(block_offset)
|
52
|
+
@caches.shift if @caches.size >= CACHE_COUNT
|
53
|
+
Cache.new(block_offset, query(block_offset * CACHE_SIZE, CACHE_SIZE)).tap do |cache|
|
54
|
+
@caches << cache
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
data/lib/qml/dispatcher.rb
CHANGED
@@ -16,7 +16,7 @@ module QML
|
|
16
16
|
|
17
17
|
def add_task(&task)
|
18
18
|
synchronize do
|
19
|
-
|
19
|
+
callback_enabled = true if @tasks.empty?
|
20
20
|
@tasks << task
|
21
21
|
end
|
22
22
|
end
|
@@ -36,17 +36,11 @@ module QML
|
|
36
36
|
task = @tasks.shift
|
37
37
|
task.call
|
38
38
|
end
|
39
|
-
|
39
|
+
callback_enabled = false if @tasks.empty?
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
on_init do
|
45
|
-
Kernel.event_loop_hook_timer.timeout.connect do
|
46
|
-
Dispatcher.instance.run_tasks
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
44
|
# Runs a block asynchronously within the event loop.
|
51
45
|
#
|
52
46
|
# QML UI is not thread-safe and can only be accessed from the main thread.
|
@@ -55,15 +49,13 @@ module QML
|
|
55
49
|
# def on_button_clicked
|
56
50
|
# Thread.new do
|
57
51
|
# result = do_task
|
58
|
-
# QML.
|
52
|
+
# QML.next_tick do
|
59
53
|
# set_result_to_ui(result)
|
60
54
|
# end
|
61
55
|
# end
|
62
56
|
# end
|
63
|
-
|
64
|
-
# @see Dispatcher#add_task
|
65
|
-
def later(&block)
|
57
|
+
def next_tick(&block)
|
66
58
|
Dispatcher.instance.add_task(&block)
|
67
59
|
end
|
68
|
-
module_function :
|
60
|
+
module_function :next_tick
|
69
61
|
end
|
data/lib/qml/engine.rb
CHANGED
@@ -1,69 +1,20 @@
|
|
1
|
-
require 'qml/qt_classes'
|
2
|
-
|
3
1
|
module QML
|
4
2
|
# @!parse class Engine < QtObjectBase; end
|
5
3
|
|
6
4
|
# {Engine} provides a QML engine.
|
7
|
-
#
|
5
|
+
#
|
8
6
|
# @see http://qt-project.org/doc/qt-5/qqmlengine.html QQmlEngine (C++)
|
9
7
|
class Engine
|
10
8
|
|
11
|
-
#
|
12
|
-
# @
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
fail EngineError, "cannot create Engine instance manually"
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
super()
|
24
|
-
@extension = Plugins.core.createEngineExtension(self)
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [Context] the root {Context} the {Engine}.
|
28
|
-
def context
|
29
|
-
@extension.rootContext
|
30
|
-
end
|
31
|
-
|
32
|
-
# Starts garbage collection on the {Engine}.
|
33
|
-
def collect_garbage
|
34
|
-
@extension.collect_garbage
|
9
|
+
# Evaluates an JavaScript expression
|
10
|
+
# @param [String] str The JavaScript string
|
11
|
+
# @param [String] file The file name
|
12
|
+
# @param [Integer] lineno The line number
|
13
|
+
def evaluate(str, file = '<in QML::Engine#evaluate>', lineno = 1)
|
14
|
+
evaluate_impl(str, file, lineno).tap do |result|
|
15
|
+
raise result.to_error if result.is_a?(JSObject) && result.error?
|
16
|
+
end
|
35
17
|
end
|
36
18
|
|
37
|
-
# Adds an {ImageProvider} to the {Engine}.
|
38
|
-
# @param id [String]
|
39
|
-
# @param provider [ImageProvider]
|
40
|
-
# @return [ImageProvider]
|
41
|
-
# @see ImageProvider
|
42
|
-
def add_image_provider(id, provider)
|
43
|
-
@extension.add_image_provider(id, provider.qt_image_provider)
|
44
|
-
provider
|
45
|
-
end
|
46
|
-
|
47
|
-
# Adds a QML import path to the {Engine}.
|
48
|
-
# @param path [String]
|
49
|
-
# @see http://doc.qt.io/qt-5/qtqml-syntax-imports.html#qml-import-path
|
50
|
-
def add_import_path(path)
|
51
|
-
@extension.add_import_path(path)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Gets an array of QML import paths.
|
55
|
-
# @see add_import_path
|
56
|
-
# @return [Array]
|
57
|
-
def import_paths()
|
58
|
-
@extension.import_paths()
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
# @return [Engine] the instance of {Engine}.
|
64
|
-
# @see Engine.instance
|
65
|
-
def engine
|
66
|
-
Kernel.engine
|
67
19
|
end
|
68
|
-
module_function :engine
|
69
20
|
end
|
data/lib/qml/errors.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
1
|
module QML
|
2
|
-
|
3
|
-
class MethodError < StandardError; end
|
4
|
-
class SignalError < StandardError; end
|
5
|
-
class PropertyError < StandardError; end
|
6
2
|
class PluginError < StandardError; end
|
7
|
-
class QtObjectError < StandardError; end
|
8
|
-
class ConversionError < StandardError; end
|
9
3
|
class QMLError < StandardError; end
|
10
4
|
class AccessError < StandardError; end
|
11
|
-
class ApplicationError < StandardError; end
|
12
|
-
class EngineError < StandardError; end
|
13
|
-
class InvalidThreadError < StandardError; end
|
14
|
-
class UninitializedError < StandardError; end
|
15
|
-
class AlreadyInitializedError < StandardError; end
|
16
|
-
|
17
|
-
class CppError < StandardError
|
18
|
-
attr_reader :class_name, :raw_message
|
19
|
-
|
20
|
-
def initialize(classname, message)
|
21
|
-
super("<#{classname}> #{message}")
|
22
|
-
@class_name = classname
|
23
|
-
@raw_message = message
|
24
|
-
end
|
25
|
-
end
|
26
5
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module QML
|
2
|
+
class Interface
|
3
|
+
|
4
|
+
def self.call_method(obj, name, args)
|
5
|
+
begin
|
6
|
+
obj.__send__ name, *args
|
7
|
+
rescue => error
|
8
|
+
notify_error(error)
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Called when an Ruby error is occured in executing Qt code.
|
14
|
+
# @param error The error (or the exception)
|
15
|
+
def self.notify_error(error)
|
16
|
+
warn "-- An error occured when running Ruby code from Qt --"
|
17
|
+
warn "#{error.class.name}: #{error.message}"
|
18
|
+
warn "Backtrace: \n\t#{error.backtrace.join("\n\t")}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/qml/js_array.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module QML
|
2
|
+
# The JSObject represents JavaScript objects.
|
3
|
+
class JSObject
|
4
|
+
|
5
|
+
alias_method :each, :each_pair
|
6
|
+
|
7
|
+
# @return [Array<String>]
|
8
|
+
def keys
|
9
|
+
each.map { |k, v| k }
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Array]
|
13
|
+
def values
|
14
|
+
each.map { |k, v| v }
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Hash]
|
18
|
+
def to_hash
|
19
|
+
{}.tap do |hash|
|
20
|
+
each do |k, v|
|
21
|
+
hash[k] =v
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Time]
|
27
|
+
def to_time
|
28
|
+
Time.at(getTime.to_i / 1000r).getlocal(-getTimezoneOffset * 60)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [QML::QMLError]
|
32
|
+
def to_error
|
33
|
+
QMLError.new(self['message'])
|
34
|
+
end
|
35
|
+
|
36
|
+
def respond_to?(method)
|
37
|
+
has_key?(method) || super
|
38
|
+
end
|
39
|
+
|
40
|
+
# Gets or sets a JS property, or call it as a method if it is a function.
|
41
|
+
def method_missing(method, *args, &block)
|
42
|
+
if method[-1] == '='
|
43
|
+
# setter
|
44
|
+
key = method.slice(0...-1).to_sym
|
45
|
+
|
46
|
+
unless has_key?(key)
|
47
|
+
super
|
48
|
+
end
|
49
|
+
self[key] = args[0]
|
50
|
+
else
|
51
|
+
unless has_key?(method)
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
prop = self[method]
|
56
|
+
if prop.is_a? JSFunction
|
57
|
+
prop.call_with_instance(self, *args, &block)
|
58
|
+
else
|
59
|
+
prop
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [QML::JSObject] self
|
65
|
+
def to_qml
|
66
|
+
self
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/qml/js_util.rb
ADDED
data/lib/qml/plugin_loader.rb
CHANGED
@@ -6,9 +6,6 @@ module QML
|
|
6
6
|
# @see http://qt-project.org/doc/qt-5/qpluginloader.html QPluginLoader (C++)
|
7
7
|
class PluginLoader
|
8
8
|
|
9
|
-
alias_method :initialize_orig, :initialize
|
10
|
-
private :initialize_orig
|
11
|
-
|
12
9
|
# @overload initialize(path)
|
13
10
|
# @param [String|Pathname] path the library path (may be platform-dependent).
|
14
11
|
# @example
|
@@ -20,18 +17,9 @@ module QML
|
|
20
17
|
# loader = QML::PluginLoader.new('path/to', 'hoge')
|
21
18
|
def initialize(path, libname = nil)
|
22
19
|
path = Pathname(path) + self.class.lib_filename(libname) if libname
|
23
|
-
|
20
|
+
initialize_impl(path.to_s)
|
24
21
|
end
|
25
22
|
|
26
|
-
# @!method instance
|
27
|
-
# Loads the plugin and returns the instance of the plugin.
|
28
|
-
# @return [QtObjectBase]
|
29
|
-
|
30
|
-
# @param [String] libname
|
31
|
-
# @return [String] platform-dependent library file name.
|
32
|
-
# @example
|
33
|
-
# # on Mac
|
34
|
-
# QML::PluginLoader.lib_filename("hoge") #=> "libhoge.dylib"
|
35
23
|
def self.lib_filename(libname)
|
36
24
|
case
|
37
25
|
when Platform::windows?
|