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
data/lib/qml/component.rb
CHANGED
|
@@ -1,57 +1,65 @@
|
|
|
1
1
|
require 'qml/engine'
|
|
2
2
|
|
|
3
3
|
module QML
|
|
4
|
-
# @!parse class Component < QtObjectBase; end
|
|
5
|
-
|
|
6
4
|
# The Component class is used to instantiate objects like Window / ApplicationWindow objects from QML files.
|
|
7
5
|
#
|
|
8
6
|
# You usually do not need to use this class because Application#load, #load_path, #load_data do same
|
|
9
7
|
# for the application top-level objects such as main windows.
|
|
10
8
|
# @example
|
|
11
|
-
# component = Component.new(path: path_to_qml_file)
|
|
9
|
+
# component = Component.new(engine: engine, path: path_to_qml_file)
|
|
12
10
|
# root_object = component.create
|
|
13
11
|
# @see http://qt-project.org/doc/qt-5/qqmlcomponent.html QQmlComponent (C++)
|
|
14
12
|
class Component
|
|
15
|
-
attr_reader :data, :path
|
|
13
|
+
attr_reader :data, :path
|
|
16
14
|
|
|
17
15
|
# Creates an component. Either data or path must be specified.
|
|
18
|
-
# @param
|
|
19
|
-
# @
|
|
20
|
-
# @option opts [String] :data the QML file data.
|
|
21
|
-
# @option opts [#to_s] :path the QML file path.
|
|
16
|
+
# @param [String] data the QML file data.
|
|
17
|
+
# @param [#to_s] path the QML file path.
|
|
22
18
|
# @return QML::Component
|
|
23
|
-
def
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
self
|
|
19
|
+
def initialize(data: nil, path: nil)
|
|
20
|
+
fail TypeError, "neither data nor path privided" unless data || path
|
|
21
|
+
|
|
22
|
+
initialize_impl
|
|
23
|
+
|
|
24
|
+
case
|
|
25
|
+
when data
|
|
26
|
+
load_data(data)
|
|
27
|
+
when path
|
|
28
|
+
load_path(path)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def load_path(path)
|
|
33
|
+
path = path.to_s
|
|
34
|
+
check_error_string do
|
|
35
|
+
@path = Pathname.new(path)
|
|
36
|
+
load_path_impl(path)
|
|
42
37
|
end
|
|
38
|
+
self
|
|
43
39
|
end
|
|
44
40
|
|
|
45
|
-
def
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
def load_data(data)
|
|
42
|
+
check_error_string do
|
|
43
|
+
@data = data
|
|
44
|
+
load_data_impl(data, "<<STRING>>")
|
|
45
|
+
end
|
|
46
|
+
self
|
|
49
47
|
end
|
|
50
48
|
|
|
51
49
|
# Instantiates a object from the QML file.
|
|
52
|
-
# @return [
|
|
50
|
+
# @return [QML::JSObject] The created object
|
|
53
51
|
def create
|
|
54
|
-
|
|
52
|
+
check_error_string do
|
|
53
|
+
create_impl
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def check_error_string
|
|
60
|
+
yield.tap do
|
|
61
|
+
fail QMLError, error_string if error_string
|
|
62
|
+
end
|
|
55
63
|
end
|
|
56
64
|
end
|
|
57
65
|
end
|
data/lib/qml/core_ext.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'qml/core_ext/to_qml'
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
class Numeric
|
|
3
|
+
def to_qml
|
|
4
|
+
to_f
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class String
|
|
9
|
+
def to_qml
|
|
10
|
+
self
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Symbol
|
|
15
|
+
def to_qml
|
|
16
|
+
to_s
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class TrueClass
|
|
21
|
+
def to_qml
|
|
22
|
+
self
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class FalseClass
|
|
27
|
+
def to_qml
|
|
28
|
+
self
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class NilClass
|
|
33
|
+
def to_qml
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class Array
|
|
39
|
+
def to_qml
|
|
40
|
+
QML.engine.new_array(self.size).tap do |jsarray|
|
|
41
|
+
self.each_with_index do |x, i|
|
|
42
|
+
jsarray[i] = x
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class Hash
|
|
49
|
+
def to_qml
|
|
50
|
+
QML.engine.new_object.tap do |jsobj|
|
|
51
|
+
self.each do |key, value|
|
|
52
|
+
jsobj[key] = value
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class Time
|
|
59
|
+
def to_qml
|
|
60
|
+
QML::JSUtil.classes['Date'].new(year, month, day, hour, min, sec, nsec / 1000000).tap do |date|
|
|
61
|
+
date.setTime((to_r * 1000).floor)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class Proc
|
|
67
|
+
def to_qml
|
|
68
|
+
QML::ProcAccess.wrap_proc(self)
|
|
69
|
+
end
|
|
70
|
+
end
|
data/lib/qml/data.rb
CHANGED
data/lib/qml/data/array_model.rb
CHANGED
|
@@ -1,124 +1,122 @@
|
|
|
1
1
|
module QML
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class ArrayModel < ListModel
|
|
2
|
+
# {ArrayModel} is one of ruby-qml's list models and it stores data in Array simply.
|
|
3
|
+
class ArrayModel < ListModel
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
# @param [Array<Symbol|String>] columns
|
|
6
|
+
def initialize(*columns)
|
|
7
|
+
super
|
|
8
|
+
@array = []
|
|
9
|
+
end
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
# Duplicates the internal array and returns it.
|
|
12
|
+
# @return [Array]
|
|
13
|
+
def to_a
|
|
14
|
+
@array.dup
|
|
15
|
+
end
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
# @return [Integer] the number of the items.
|
|
18
|
+
def count
|
|
19
|
+
@array.count
|
|
20
|
+
end
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
# Returns an item.
|
|
23
|
+
# @param [Integer] index the index of the item.
|
|
24
|
+
# @return the item.
|
|
25
|
+
def [](index)
|
|
26
|
+
@array[index]
|
|
27
|
+
end
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
# Updates an item.
|
|
30
|
+
# @param [Integer] index
|
|
31
|
+
# @param item
|
|
32
|
+
# @return the item.
|
|
33
|
+
def []=(index, item)
|
|
34
|
+
@array[index] = item
|
|
35
|
+
update(index .. index)
|
|
36
|
+
item
|
|
37
|
+
end
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
self
|
|
39
|
+
# Inserts items.
|
|
40
|
+
# @param [Integer] index
|
|
41
|
+
# @return [self]
|
|
42
|
+
def insert(index, *items)
|
|
43
|
+
inserting(index ... index + items.size) do
|
|
44
|
+
@array.insert(index, *items)
|
|
48
45
|
end
|
|
46
|
+
self
|
|
47
|
+
end
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
end
|
|
49
|
+
# @overload delete_at(index)
|
|
50
|
+
# Deletes an item.
|
|
51
|
+
# @param [Integer] index
|
|
52
|
+
# @return the deleted item.
|
|
53
|
+
# @overload delete_at(index, count)
|
|
54
|
+
# Deletes items.
|
|
55
|
+
# @param [Integer] index
|
|
56
|
+
# @return [Array] the deleted items.
|
|
57
|
+
def delete_at(index, count = nil)
|
|
58
|
+
if count
|
|
59
|
+
removing(index ... index + count) do
|
|
60
|
+
count.times.map { @array.delete_at(index) }
|
|
61
|
+
end
|
|
62
|
+
else
|
|
63
|
+
removing(index .. index) do
|
|
64
|
+
@array.delete_at(index)
|
|
67
65
|
end
|
|
68
66
|
end
|
|
67
|
+
end
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
# Prepend items.
|
|
70
|
+
# @return [self]
|
|
71
|
+
def unshift(*items)
|
|
72
|
+
insert(0, *items)
|
|
73
|
+
end
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
# @overload shift
|
|
76
|
+
# Deletes the first item.
|
|
77
|
+
# @return the deleted item.
|
|
78
|
+
# @overload shift(count)
|
|
79
|
+
# Deletes the first items.
|
|
80
|
+
# @return [Array] the deleted items.
|
|
81
|
+
def shift(count = nil)
|
|
82
|
+
delete_at(0, count)
|
|
83
|
+
end
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
# Append items.
|
|
86
|
+
# @return [self]
|
|
87
|
+
def push(*items)
|
|
88
|
+
insert(@array.size, *items)
|
|
89
|
+
end
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
alias_method :<<, :push
|
|
93
92
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
93
|
+
# @overload pop
|
|
94
|
+
# Deletes the last item.
|
|
95
|
+
# @return the deleted item.
|
|
96
|
+
# @overload pop(count)
|
|
97
|
+
# Deletes the last items.
|
|
98
|
+
# @return [Array] the deleted items.
|
|
99
|
+
def pop(count = nil)
|
|
100
|
+
delete_at(@array.size - count, count)
|
|
101
|
+
end
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
self
|
|
103
|
+
# Deletes all items.
|
|
104
|
+
# @return [self]
|
|
105
|
+
def clear
|
|
106
|
+
removing(0 ... count) do
|
|
107
|
+
@array.clear
|
|
111
108
|
end
|
|
109
|
+
self
|
|
110
|
+
end
|
|
112
111
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
end
|
|
120
|
-
self
|
|
112
|
+
# Replaces entire array with given array.
|
|
113
|
+
# @param [Array] ary
|
|
114
|
+
# @return [self]
|
|
115
|
+
def replace(ary)
|
|
116
|
+
resetting do
|
|
117
|
+
@array = ary.dup
|
|
121
118
|
end
|
|
119
|
+
self
|
|
122
120
|
end
|
|
123
121
|
end
|
|
124
122
|
end
|
data/lib/qml/data/list_model.rb
CHANGED
|
@@ -1,146 +1,122 @@
|
|
|
1
|
-
require 'qml/data/error'
|
|
2
|
-
require 'qml/wrappable'
|
|
3
|
-
require 'qml/dispatchable'
|
|
4
|
-
|
|
5
1
|
module QML
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# @param [Array<Symbol|String>] columns the column names of the model.
|
|
23
|
-
def initialize(*columns)
|
|
24
|
-
@columns = columns
|
|
25
|
-
@qt_models = []
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Iterates each item.
|
|
29
|
-
# @overload each
|
|
30
|
-
# @return [Enumerator]
|
|
31
|
-
# @overload each
|
|
32
|
-
# @yield [item]
|
|
33
|
-
# @return [self]
|
|
34
|
-
def each
|
|
35
|
-
return to_enum unless block_given?
|
|
36
|
-
count.times do |i|
|
|
37
|
-
yield self[i]
|
|
38
|
-
end
|
|
39
|
-
self
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# @abstract
|
|
43
|
-
# @return [Integer] the number of the items.
|
|
44
|
-
def count
|
|
45
|
-
fail ::NotImplementedError
|
|
46
|
-
end
|
|
2
|
+
# {ListModel} is the base class of list models which provides data to QML list views.
|
|
3
|
+
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html QAbstractItemModel (C++)
|
|
4
|
+
# @see http://qt-project.org/doc/qt-5/qabstractlistmodel.html QAbstractListModel (C++)
|
|
5
|
+
class ListModel
|
|
6
|
+
include Enumerable
|
|
7
|
+
|
|
8
|
+
# @return [Array<Symbol|String>]
|
|
9
|
+
attr_reader :columns
|
|
10
|
+
|
|
11
|
+
# @param [Array<Symbol|String>] columns the column names of the model.
|
|
12
|
+
def initialize(*columns)
|
|
13
|
+
@columns = columns
|
|
14
|
+
@access = ListModelAccess.create(self)
|
|
15
|
+
@qml_model = QML::Plugins.rubyqml.createListModel(@access)
|
|
16
|
+
end
|
|
47
17
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
18
|
+
# Iterates each item.
|
|
19
|
+
# @overload each
|
|
20
|
+
# @return [Enumerator]
|
|
21
|
+
# @overload each
|
|
22
|
+
# @yield [item]
|
|
23
|
+
# @return [self]
|
|
24
|
+
def each
|
|
25
|
+
return to_enum unless block_given?
|
|
26
|
+
count.times do |i|
|
|
27
|
+
yield self[i]
|
|
54
28
|
end
|
|
29
|
+
self
|
|
30
|
+
end
|
|
55
31
|
|
|
56
|
-
|
|
32
|
+
# @abstract
|
|
33
|
+
# @return [Integer] the number of the items.
|
|
34
|
+
def count
|
|
35
|
+
fail ::NotImplementedError
|
|
36
|
+
end
|
|
57
37
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
# Returns an item.
|
|
39
|
+
# @abstract
|
|
40
|
+
# @param [Integer] index the index of the item.
|
|
41
|
+
# @return the item.
|
|
42
|
+
def [](index)
|
|
43
|
+
fail ::NotImplementedError
|
|
44
|
+
end
|
|
65
45
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# @return the result of given block.
|
|
71
|
-
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#beginMoveRows QAbstractItemModel::beginMoveRows
|
|
72
|
-
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#endMoveRows QAbstractItemModel::endMoveRows
|
|
73
|
-
# @see #inserting
|
|
74
|
-
# @see #removing
|
|
75
|
-
def moving(range, destination)
|
|
76
|
-
return if range.count == 0
|
|
46
|
+
# @return [QML::JSObject]
|
|
47
|
+
def to_qml
|
|
48
|
+
@qml_model
|
|
49
|
+
end
|
|
77
50
|
|
|
78
|
-
|
|
79
|
-
qt_model.begin_move(range.min, range.max, destination)
|
|
80
|
-
end
|
|
81
|
-
ret = yield
|
|
82
|
-
@qt_models.each do |qt_model|
|
|
83
|
-
qt_model.end_move
|
|
84
|
-
end
|
|
85
|
-
ret
|
|
86
|
-
end
|
|
51
|
+
protected
|
|
87
52
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
# inserting(index ... index + items.size) do
|
|
94
|
-
# @array.insert(index, *items)
|
|
95
|
-
# end
|
|
96
|
-
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#beginInsertRows QAbstractItemModel::beginInsertRows
|
|
97
|
-
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#endInsertRows QAbstractItemModel::endInsertRows
|
|
98
|
-
# @see #removing
|
|
99
|
-
# @see #moving
|
|
100
|
-
def inserting(range, &block)
|
|
101
|
-
return if range.count == 0
|
|
53
|
+
# Notifies the list views that the data of the items was changed.
|
|
54
|
+
# @param [Range<Integer>] range the index range of changed items.
|
|
55
|
+
def update(range)
|
|
56
|
+
@access.update(range.min, range.max)
|
|
57
|
+
end
|
|
102
58
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
59
|
+
# Notifies the list views that items are about to be and were moved.
|
|
60
|
+
# @param [Range<Integer>] range the index range of the item being moved.
|
|
61
|
+
# @param [Integer] destination the first index of the items after moved.
|
|
62
|
+
# @yield the block that actually do moving operation of the items.
|
|
63
|
+
# @return the result of given block.
|
|
64
|
+
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#beginMoveRows QAbstractItemModel::beginMoveRows
|
|
65
|
+
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#endMoveRows QAbstractItemModel::endMoveRows
|
|
66
|
+
# @see #inserting
|
|
67
|
+
# @see #removing
|
|
68
|
+
def moving(range, destination)
|
|
69
|
+
return if range.count == 0
|
|
70
|
+
|
|
71
|
+
@access.begin_move(range.min, range.max, destination)
|
|
72
|
+
ret = yield
|
|
73
|
+
@access.end_move
|
|
74
|
+
ret
|
|
75
|
+
end
|
|
112
76
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
77
|
+
# Notifies the list views that items are about to be and were inserted.
|
|
78
|
+
# @param [Range<Integer>] range the index range of the items after inserted.
|
|
79
|
+
# @yield the block that actually do insertion of the items.
|
|
80
|
+
# @return the result of give block.
|
|
81
|
+
# @example
|
|
82
|
+
# inserting(index ... index + items.size) do
|
|
83
|
+
# @array.insert(index, *items)
|
|
84
|
+
# end
|
|
85
|
+
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#beginInsertRows QAbstractItemModel::beginInsertRows
|
|
86
|
+
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#endInsertRows QAbstractItemModel::endInsertRows
|
|
87
|
+
# @see #removing
|
|
88
|
+
# @see #moving
|
|
89
|
+
def inserting(range, &block)
|
|
90
|
+
return if range.count == 0
|
|
91
|
+
|
|
92
|
+
@access.begin_insert(range.min, range.max)
|
|
93
|
+
ret = yield
|
|
94
|
+
@access.end_insert
|
|
95
|
+
ret
|
|
96
|
+
end
|
|
123
97
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
98
|
+
# Notifies the list views that items are about to be and were removed.
|
|
99
|
+
# @param [Range<Integer>] range the index range of the items before removed.
|
|
100
|
+
# @yield the block that actually do removal of the items.
|
|
101
|
+
# @return the result of give block.
|
|
102
|
+
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#beginRemoveRows QAbstractItemModel::beginRemoveRows
|
|
103
|
+
# @see http://qt-project.org/doc/qt-5/qabstractitemmodel.html#endRemoveRows QAbstractItemModel::endRemoveRows
|
|
104
|
+
# @see #inserting
|
|
105
|
+
# @see #moving
|
|
106
|
+
def removing(range, &block)
|
|
107
|
+
return if range.count == 0
|
|
108
|
+
|
|
109
|
+
@access.begin_remove(range.min, range.max)
|
|
110
|
+
ret = yield
|
|
111
|
+
@access.end_remove
|
|
112
|
+
ret
|
|
113
|
+
end
|
|
133
114
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
@qt_models.each do |qt_model|
|
|
140
|
-
qt_model.end_reset
|
|
141
|
-
end
|
|
142
|
-
ret
|
|
143
|
-
end
|
|
115
|
+
def resetting(&block)
|
|
116
|
+
@access.begin_reset
|
|
117
|
+
ret = yield
|
|
118
|
+
@access.end_reset
|
|
119
|
+
ret
|
|
144
120
|
end
|
|
145
121
|
end
|
|
146
122
|
end
|