Class: QML::Component

Inherits:
QtObjectBase show all
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.

Examples:

component = Component.new(path: path_to_qml_file)
root_object = component.create

See Also:

Instance Attribute Summary collapse

Attributes inherited from QtObjectBase

#pointer

Class Method Summary collapse

Instance Method Summary collapse

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

#later

Constructor Details

#initializeComponent

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

#contextObject (readonly)

Returns the value of attribute context.



15
16
17
# File 'lib/qml/component.rb', line 15

def context
  @context
end

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/qml/component.rb', line 15

def data
  @data
end

#pathObject (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.

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :context (QML::Context)

    the context that the created objects will depend on (default to the root context of the application engine).

  • :data (String)

    the QML file data.

  • :path (#to_s)

    the QML file path.

Returns:

  • QML::Component



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

#createQtObjectBase

Instantiates a object from the QML file.

Returns:



53
54
55
# File 'lib/qml/component.rb', line 53

def create
  @extension.create(@context)
end