qml 0.0.3 → 0.0.4
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/README.md +4 -1
- data/changes.md +4 -0
- data/examples/twitter/twitter.rb +1 -2
- data/ext/qml/{ext_accesssupport.cpp → ext_accesswrapperfactory.cpp} +17 -19
- data/ext/qml/{ext_accesssupport.h → ext_accesswrapperfactory.h} +3 -6
- data/ext/qml/ext_anywrapper.cpp +6 -8
- data/ext/qml/ext_anywrapper.h +2 -5
- data/ext/qml/ext_kernel.cpp +27 -8
- data/ext/qml/ext_kernel.h +1 -3
- data/ext/qml/ext_metaobject.cpp +47 -49
- data/ext/qml/ext_metaobject.h +2 -4
- data/ext/qml/ext_pluginloader.cpp +10 -12
- data/ext/qml/ext_pluginloader.h +3 -5
- data/ext/qml/ext_pointer.cpp +23 -25
- data/ext/qml/ext_pointer.h +3 -5
- data/ext/qml/ext_testutil.cpp +1 -3
- data/ext/qml/ext_testutil.h +1 -3
- data/ext/qml/init.cpp +10 -10
- data/ext/qml/kernel.cpp +39 -0
- data/ext/qml/kernel.h +32 -0
- data/ext/qml/plugins/core/applicationextension.cpp +0 -5
- data/ext/qml/plugins/core/applicationextension.h +0 -3
- data/ext/qml/rubyvalue.cpp +10 -10
- data/ext/qml/weakvaluereference.cpp +2 -2
- data/lib/qml.rb +1 -22
- data/lib/qml/application.rb +0 -8
- data/lib/qml/dispatcher.rb +10 -1
- data/lib/qml/init.rb +29 -0
- data/lib/qml/version.rb +1 -1
- data/spec/qml/dispatchable_spec.rb +1 -0
- data/spec/qml/dispatcher_spec.rb +26 -2
- metadata +7 -6
- data/ext/qml/application.cpp +0 -54
- data/ext/qml/application.h +0 -17
@@ -13,7 +13,7 @@ struct WeakValueReference::Data
|
|
13
13
|
|
14
14
|
static VALUE finalize(VALUE args, VALUE data) {
|
15
15
|
Q_UNUSED(args);
|
16
|
-
auto variant = wrapperRubyClass<
|
16
|
+
auto variant = wrapperRubyClass<Ext_AnyWrapper>().unwrap(data)->value();
|
17
17
|
auto sp = variant.value<std::shared_ptr<Data>>();
|
18
18
|
sp->invalidiate();
|
19
19
|
return Qnil;
|
@@ -33,7 +33,7 @@ WeakValueReference::WeakValueReference(RubyValue value) :
|
|
33
33
|
d->mValue = value;
|
34
34
|
static auto objspace = RubyModule::fromPath("ObjectSpace");
|
35
35
|
protect([&] {
|
36
|
-
auto proc = rb_proc_new((VALUE (*)(...))&Data::finalize,
|
36
|
+
auto proc = rb_proc_new((VALUE (*)(...))&Data::finalize, Ext_AnyWrapper::create(QVariant::fromValue(d)));
|
37
37
|
VALUE args[] = { value };
|
38
38
|
rb_funcall_with_block(objspace, RUBYQML_INTERN("define_finalizer"), 1, args, proc);
|
39
39
|
});
|
data/lib/qml.rb
CHANGED
@@ -4,6 +4,7 @@ require 'qml/qml'
|
|
4
4
|
require 'qml/geometry'
|
5
5
|
require 'qml/reactive'
|
6
6
|
|
7
|
+
require 'qml/init'
|
7
8
|
require 'qml/meta_object'
|
8
9
|
require 'qml/plugin_loader'
|
9
10
|
require 'qml/component'
|
@@ -19,25 +20,3 @@ require 'qml/dispatchable'
|
|
19
20
|
|
20
21
|
require 'qml/data'
|
21
22
|
require 'qml/test_util'
|
22
|
-
|
23
|
-
module QML
|
24
|
-
|
25
|
-
def initialized?
|
26
|
-
Kernel.initialized?
|
27
|
-
end
|
28
|
-
|
29
|
-
# Initializes ruby-qml.
|
30
|
-
# @param [Hash] opts
|
31
|
-
# @option opts [Boolean] :offscreen (false) set this to true to run application offscreen (without GUI)
|
32
|
-
def init(opts = {})
|
33
|
-
opts = {offscreen: false}.merge opts
|
34
|
-
fail AlreadyInitializedError, "ruby-qml already initialized" if initialized?
|
35
|
-
argv = [$PROGRAM_NAME]
|
36
|
-
argv += %w{-platform offscreen} if opts[:offscreen]
|
37
|
-
Kernel.init(argv)
|
38
|
-
application.events_processed.each do
|
39
|
-
Dispatcher.instance.run_tasks
|
40
|
-
end
|
41
|
-
end
|
42
|
-
module_function :initialized?, :init
|
43
|
-
end
|
data/lib/qml/application.rb
CHANGED
@@ -23,17 +23,9 @@ module QML
|
|
23
23
|
fail ApplicationError, "cannot create Application instance manually"
|
24
24
|
end
|
25
25
|
|
26
|
-
# @!method events_processed
|
27
|
-
# This signal is emitted every time events are processed in the event loop.
|
28
|
-
# @return [Reactive::Signal]
|
29
|
-
signal :events_processed, []
|
30
|
-
|
31
26
|
def initialize
|
32
27
|
super()
|
33
28
|
@extension = Plugins.core.createApplicationExtension(self)
|
34
|
-
@extension.events_processed.each do
|
35
|
-
events_processed.call
|
36
|
-
end
|
37
29
|
end
|
38
30
|
|
39
31
|
# @return [Engine] The engine of the application.
|
data/lib/qml/dispatcher.rb
CHANGED
@@ -10,12 +10,13 @@ module QML
|
|
10
10
|
MAX_DURATION = 1/10.to_r
|
11
11
|
|
12
12
|
def initialize
|
13
|
-
@tasks = []
|
14
13
|
super
|
14
|
+
@tasks = []
|
15
15
|
end
|
16
16
|
|
17
17
|
def add_task(&task)
|
18
18
|
synchronize do
|
19
|
+
Kernel.set_event_loop_hook_enabled_later true if @tasks.empty?
|
19
20
|
@tasks << task
|
20
21
|
end
|
21
22
|
end
|
@@ -35,10 +36,18 @@ module QML
|
|
35
36
|
task = @tasks.shift
|
36
37
|
task.call
|
37
38
|
end
|
39
|
+
Kernel.set_event_loop_hook_enabled_later false if @tasks.empty?
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
44
|
+
on_init do
|
45
|
+
Kernel.event_loop_hook_timer.timeout.connect do
|
46
|
+
puts "======== run tasks"
|
47
|
+
Dispatcher.instance.run_tasks
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
42
51
|
# Runs a block asynchronously within the event loop.
|
43
52
|
#
|
44
53
|
# QML UI is not thread-safe and can only be accessed from the main thread.
|
data/lib/qml/init.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module QML
|
2
|
+
|
3
|
+
# @return [Boolean] whether {#init} is already called.
|
4
|
+
def initialized?
|
5
|
+
Kernel.initialized?
|
6
|
+
end
|
7
|
+
|
8
|
+
# Initializes ruby-qml.
|
9
|
+
# @param [Hash] opts
|
10
|
+
# @option opts [Boolean] :offscreen (false) set this to true to run application offscreen (without GUI)
|
11
|
+
def init(opts = {})
|
12
|
+
opts = {offscreen: false}.merge opts
|
13
|
+
fail AlreadyInitializedError, "ruby-qml already initialized" if initialized?
|
14
|
+
argv = [$PROGRAM_NAME]
|
15
|
+
argv += %w{-platform offscreen} if opts[:offscreen]
|
16
|
+
Kernel.init(argv)
|
17
|
+
@on_init.each(&:call)
|
18
|
+
end
|
19
|
+
|
20
|
+
@on_init = []
|
21
|
+
|
22
|
+
# Registers a block to be called just after {#init} is called.
|
23
|
+
# @yield
|
24
|
+
def on_init(&block)
|
25
|
+
@on_init << block
|
26
|
+
end
|
27
|
+
|
28
|
+
module_function :initialized?, :init, :on_init
|
29
|
+
end
|
data/lib/qml/version.rb
CHANGED
@@ -10,6 +10,7 @@ describe QML::Dispatchable do
|
|
10
10
|
it 'queues a method call as a task to the dispatcher' do
|
11
11
|
foo = DispatchableFoo.new
|
12
12
|
foo.later.value = 'hoge'
|
13
|
+
QML.application.process_events # wait for event loop hook to be enabled
|
13
14
|
expect(foo.value).to be_nil
|
14
15
|
QML.application.process_events
|
15
16
|
expect(foo.value).to eq 'hoge'
|
data/spec/qml/dispatcher_spec.rb
CHANGED
@@ -19,17 +19,40 @@ describe QML::Dispatcher do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe '#add_task' do
|
23
|
+
before do
|
24
|
+
dispatcher.add_task {}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'adds a task' do
|
28
|
+
expect(dispatcher.empty?).to eq false
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sets the event loop hook enabled later' do
|
32
|
+
QML.application.process_events
|
33
|
+
expect(QML::Kernel.event_loop_hook_timer.active).to eq true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
22
37
|
describe '#run_tasks' do
|
23
|
-
|
24
|
-
|
38
|
+
let(:finished) { [] }
|
39
|
+
before do
|
25
40
|
2.times.each do |i|
|
26
41
|
dispatcher.add_task do
|
27
42
|
finished[i] = true
|
28
43
|
end
|
29
44
|
end
|
30
45
|
dispatcher.run_tasks until dispatcher.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'runs queued tasks' do
|
31
49
|
expect(finished).to eq [true, true]
|
32
50
|
end
|
51
|
+
|
52
|
+
it 'sets the event loop hook disabled when finished later' do
|
53
|
+
QML.application.process_events
|
54
|
+
expect(QML::Kernel.event_loop_hook_timer.active).to eq false
|
55
|
+
end
|
33
56
|
end
|
34
57
|
end
|
35
58
|
|
@@ -40,6 +63,7 @@ describe QML do
|
|
40
63
|
QML.later do
|
41
64
|
finished = true
|
42
65
|
end
|
66
|
+
QML.application.process_events # wait for event loop hook to be enabled
|
43
67
|
expect(finished).to eq false
|
44
68
|
QML.application.process_events
|
45
69
|
expect(finished).to eq true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryohei Ikegami
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -159,11 +159,9 @@ files:
|
|
159
159
|
- ext/qml/accessclass.h
|
160
160
|
- ext/qml/accessobject.cpp
|
161
161
|
- ext/qml/accessobject.h
|
162
|
-
- ext/qml/application.cpp
|
163
|
-
- ext/qml/application.h
|
164
162
|
- ext/qml/common.h
|
165
|
-
- ext/qml/
|
166
|
-
- ext/qml/
|
163
|
+
- ext/qml/ext_accesswrapperfactory.cpp
|
164
|
+
- ext/qml/ext_accesswrapperfactory.h
|
167
165
|
- ext/qml/ext_anywrapper.cpp
|
168
166
|
- ext/qml/ext_anywrapper.h
|
169
167
|
- ext/qml/ext_kernel.cpp
|
@@ -185,6 +183,8 @@ files:
|
|
185
183
|
- ext/qml/foreignobject.h
|
186
184
|
- ext/qml/functioninfo.h
|
187
185
|
- ext/qml/init.cpp
|
186
|
+
- ext/qml/kernel.cpp
|
187
|
+
- ext/qml/kernel.h
|
188
188
|
- ext/qml/listmodel.cpp
|
189
189
|
- ext/qml/listmodel.h
|
190
190
|
- ext/qml/markable.h
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- lib/qml/geometry/rectangle.rb
|
256
256
|
- lib/qml/geometry/size.rb
|
257
257
|
- lib/qml/image_provider.rb
|
258
|
+
- lib/qml/init.rb
|
258
259
|
- lib/qml/meta_object.rb
|
259
260
|
- lib/qml/models.rb
|
260
261
|
- lib/qml/name_helper.rb
|
data/ext/qml/application.cpp
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
#include "application.h"
|
2
|
-
#include "util.h"
|
3
|
-
|
4
|
-
namespace RubyQml {
|
5
|
-
namespace Application {
|
6
|
-
|
7
|
-
namespace {
|
8
|
-
|
9
|
-
int argc;
|
10
|
-
QList<QByteArray> argData;
|
11
|
-
char **argv;
|
12
|
-
|
13
|
-
QApplication *application_;
|
14
|
-
QQmlEngine *engine_;
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
void failIfUninitialized()
|
19
|
-
{
|
20
|
-
if (!initialized()) {
|
21
|
-
fail("QML::UninitializedError", "ruby-qml not yet initialized");
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
QApplication *application()
|
26
|
-
{
|
27
|
-
failIfUninitialized();
|
28
|
-
return application_;
|
29
|
-
}
|
30
|
-
|
31
|
-
QQmlEngine *engine()
|
32
|
-
{
|
33
|
-
failIfUninitialized();
|
34
|
-
return engine_;
|
35
|
-
}
|
36
|
-
|
37
|
-
bool initialized()
|
38
|
-
{
|
39
|
-
return application_;
|
40
|
-
}
|
41
|
-
|
42
|
-
void init(const QList<QByteArray> &args)
|
43
|
-
{
|
44
|
-
argc = args.size();
|
45
|
-
argData = args;
|
46
|
-
argv = new char*[argc];
|
47
|
-
std::transform(argData.begin(), argData.end(), argv, [](QByteArray &ba) { return ba.data(); });
|
48
|
-
|
49
|
-
application_ = new QApplication(argc, argv);
|
50
|
-
engine_ = new QQmlEngine();
|
51
|
-
}
|
52
|
-
|
53
|
-
}
|
54
|
-
} // namespace RubyQml
|
data/ext/qml/application.h
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#include <QList>
|
4
|
-
#include <QApplication>
|
5
|
-
#include <QQmlEngine>
|
6
|
-
|
7
|
-
namespace RubyQml {
|
8
|
-
namespace Application {
|
9
|
-
|
10
|
-
QApplication *application();
|
11
|
-
QQmlEngine *engine();
|
12
|
-
bool initialized();
|
13
|
-
|
14
|
-
void init(const QList<QByteArray> &args);
|
15
|
-
|
16
|
-
}
|
17
|
-
} // namespace RubyQml
|