Class: QML::Context
- Inherits:
-
QtObjectBase
- Object
- QtObjectBase
- QML::Context
- Defined in:
- lib/qml/context.rb,
lib/qml/context.rb
Overview
Context represents QML contexts and used to expose Ruby values to QML. Each context has values that is called “context properties” that can be accessed in QML by their names.
This class is automatically created from QQmlContext (C++).
Instance Attribute Summary
Attributes inherited from QtObjectBase
Class Method Summary collapse
-
.for_object(obj) ⇒ Context|nil
Gets a context that an object belongs to.
-
.new ⇒ Object
Creates a new instance of Context.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Gets a context property.
-
#[]=(key, value) ⇒ Object
Sets a context property.
-
#eval(obj, str) ⇒ Object
Evaluates an JavaScript expression on the object in this context.
-
#initialize ⇒ Context
constructor
A new instance of Context.
Methods inherited from QtObjectBase
#inspect, #managed=, #managed?, #prefer_managed, #qml_eval
Methods included from Reactive::Object
included, #properties, #property, #signal, #signals
Methods included from Reactive::Object::ClassMethods
#alias_property, #alias_signal, #instance_properties, #instance_property, #instance_signal, #instance_signals, #on, #on_changed, #property, #signal, #variadic_signal
Methods included from Dispatchable
Constructor Details
Class Method Details
.for_object(obj) ⇒ Context|nil
Gets a context that an object belongs to. If the object belongs to no context, returns nil.
65 66 67 68 69 |
# File 'lib/qml/context.rb', line 65 def self.for_object(obj) Plugins.core.contextForObject(obj).tap do |context| context.managed = false if context end end |
.new ⇒ Object
Creates a new instance of QML::Context.
21 22 23 |
# File 'lib/qml/context.rb', line 21 def self.new Plugins.core.createContext(Engine.instance) end |
Instance Method Details
#[](key) ⇒ Object
Gets a context property.
58 59 60 |
# File 'lib/qml/context.rb', line 58 def [](key) @extension.contextProperty(key) end |
#[]=(key, value) ⇒ Object
Sets a context property.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/qml/context.rb', line 43 def []=(key, value) # be sure that the value is managed when it is a QObject value = value.create_wrapper if value.is_a? Wrappable value.prefer_managed true if value.is_a? QtObjectBase # hold referenece because QQmlContext::setContextProperty does not take ownership of objects @context_properties[key] = value @extension.setContextProperty(key, value) value end |
#eval(obj, str) ⇒ Object
Evaluates an JavaScript expression on the object in this context.
35 36 37 |
# File 'lib/qml/context.rb', line 35 def eval(obj, str) @extension.evaluate(obj, str) end |