Class: QML::Component
- Inherits:
-
QtObjectBase
- Object
- QtObjectBase
- QML::Component
- Defined in:
- lib/qml/component.rb,
lib/qml/component.rb
Overview
The Component class is used to instantiate objects like Window / ApplicationWindow objects from QML files.
You usually do not need to use this class because Application#load, #load_path, #load_data do same for the application top-level objects such as main windows.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from QtObjectBase
Class Method Summary collapse
-
.new(opts) ⇒ Object
Creates an component.
Instance Method Summary collapse
-
#create ⇒ QtObjectBase
Instantiates a object from the QML file.
-
#initialize ⇒ Component
constructor
A new instance of Component.
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
#initialize ⇒ Component
Returns a new instance of Component.
45 46 47 48 49 |
# File 'lib/qml/component.rb', line 45 def initialize super() Access.register_classes @extension = Plugins.core.createComponentExtension(self) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
15 16 17 |
# File 'lib/qml/component.rb', line 15 def context @context end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
15 16 17 |
# File 'lib/qml/component.rb', line 15 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/qml/component.rb', line 15 def path @path end |
Class Method Details
.new(opts) ⇒ Object
Creates an component. Either data or path must be specified.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/qml/component.rb', line 23 def self.new(opts) context = opts[:context] data = opts[:data] path = opts[:path] context ||= Engine.instance.context Plugins.core.createComponent(Engine.instance).instance_eval do @data = data @path = path @context = context if data @extension.loadString(data, (path && path.to_s) || '') elsif path @extension.loadFile(path.to_s) else fail QMLError, 'neither data nor path specified' end self end end |
Instance Method Details
#create ⇒ QtObjectBase
Instantiates a object from the QML file.
53 54 55 |
# File 'lib/qml/component.rb', line 53 def create @extension.create(@context) end |