Class: RubyQt6::QtCore::Private::MetaObject

Inherits:
Object
  • Object
show all
Defined in:
lib/qt6/qtcore/private/metaobject.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qlass) ⇒ MetaObject

Returns a new instance of MetaObject.



31
32
33
34
35
36
# File 'lib/qt6/qtcore/private/metaobject.rb', line 31

def initialize(qlass)
  @qlass = qlass
  @qlass_underlying = @qlass.name.start_with?("RubyQt6::") ? :libQt6 : :ruby
  @classinfo = {}
  @metamethods = []
end

Instance Attribute Details

#metamethodsObject (readonly)

Returns the value of attribute metamethods.



7
8
9
# File 'lib/qt6/qtcore/private/metaobject.rb', line 7

def metamethods
  @metamethods
end

Class Method Details

.find_receiver_metamethod!(receiver, method, signal = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/qt6/qtcore/private/metaobject.rb', line 9

def self.find_receiver_metamethod!(receiver, method, signal = nil)
  if signal.nil?
    signature = "anonymous()"
    signal = QtCore::Private::MetaMethod.new(signature, :signal, :ruby)
  end

  name = QtCore::Private::MetaMethod.normalized_name(method.to_s)
  compatible_methods = signal.parameters.count.downto(0).map do |n|
    QtCore::Private::MetaMethod.normalized_signature(name, signal.parameters[0...n])
  end

  mo = receiver.class._rubyqt6_metaobject
  until mo.nil?
    mo.metamethods.each { |meth| return meth if compatible_methods.include?(meth.signature) }
    mo.metamethods.each { |meth| return meth if name == meth.name } if mo.ruby?
    mo = mo.super_class
  end

  qlass = receiver.class.name.split("::").last
  raise "No compatible metamethod: #{qlass}##{name}"
end

Instance Method Details

#add_classinfo(name, value) ⇒ Object Also known as: classinfo



38
39
40
# File 'lib/qt6/qtcore/private/metaobject.rb', line 38

def add_classinfo(name, value)
  @classinfo[name] = value
end

#add_signal(signature) ⇒ Object Also known as: signal



43
44
45
# File 'lib/qt6/qtcore/private/metaobject.rb', line 43

def add_signal(signature)
  @metamethods << QtCore::Private::MetaMethod.new(signature, :signal, @qlass_underlying)
end

#add_slot(signature) ⇒ Object Also known as: slot



48
49
50
# File 'lib/qt6/qtcore/private/metaobject.rb', line 48

def add_slot(signature)
  @metamethods << QtCore::Private::MetaMethod.new(signature, :slot, @qlass_underlying)
end

#class_nameObject



53
54
55
# File 'lib/qt6/qtcore/private/metaobject.rb', line 53

def class_name
  @qlass.name
end

#ruby?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/qt6/qtcore/private/metaobject.rb', line 62

def ruby?
  @qlass_underlying == :ruby
end

#super_classObject



57
58
59
60
# File 'lib/qt6/qtcore/private/metaobject.rb', line 57

def super_class
  return nil if @qlass == QtCore::QObject
  @qlass.superclass._rubyqt6_metaobject
end

#to_qmetaobjectObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/qt6/qtcore/private/metaobject.rb', line 66

def to_qmetaobject
  return @qlass._static_meta_object unless ruby?

  builder = QtCore::QMetaObjectBuilder.new
  builder.set_class_name(@qlass.name)
  builder.set_super_class(@qlass.superclass._qmetaobject)
  @classinfo.each { |name, value| builder.add_class_info(name, value) }
  @metamethods.each { |meth| _to_qmetaobject_method(builder, meth) }
  builder.to_meta_object
end