class Vizkit::ConnectorSlot
Public Class Methods
new(widget,signature,options = Hash.new)
click to toggle source
Calls superclass method
Vizkit::ConnectorObject.new
# File lib/vizkit/connector_objects.rb, line 120 def initialize(widget,signature,options = Hash.new) super() @supports_options = false @widget = widget @method_info = if @widget.respond_to? :method_info @widget.method_info else TypelibQtAdapter.new(@widget).method_info end populate_specs(signature) end
Public Instance Methods
argument_types()
click to toggle source
# File lib/vizkit/connector_objects.rb, line 234 def argument_types spec(true) types = @specs.collect each do |spec| spec.argument_types end types.flatten if types.size == 1 end
argument_types=(*value)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 219 def argument_types=(*value) raise ArgumentError,"no siganture has the given arguments #{value}" unless argument_types?(*value) specs.delete_if do |spec| if spec.argument_types.size != value.size true else spec.argument_types.each_with_index do |type,index| break if value[index] != type end or break true false end end self end
argument_types?(*value)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 205 def argument_types?(*value) value.flatten! !!@specs.find do |spec| if spec.argument_types.size != value.size next else spec.argument_types.each_with_index do |type,index| break if value[index] != type end or next true end end end
arity=(value)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 190 def arity=(value) spec(true) raise ArgumentError,"no siganture has an airty of #{value}" unless arity?(value) specs.delete_if do |spec| spec.argument_types.size != value end self end
arity?(value)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 199 def arity?(value) !!@specs.find do |spec| spec.argument_types.size == value end end
find_method_specs(signature,type=nil)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 156 def find_method_specs(signature,type=nil) signature = normalize_signature signature name = method_name(signature) specs = if @method_info.has_key? signature @method_info[signature] elsif @method_info.has_key? name @method_info[name].find_all {|method| method.signature == signature} else [] end if !specs.empty? if type specs.find_all{|s| s.type == type} else specs end else if @widget.respond_to?(name.to_sym) && (!type || type == Qt::MetaMethod::Slot) arguments = Array.new([@widget.method(name).arity,0].max,:ruby) [TypelibQtAdapter::MethodInfo.new(name,name,:ruby,arguments,Qt::MetaMethod::Slot)] else [] end end end
method_name(signature)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 137 def method_name(signature) name = normalize_signature(signature) name =~ /(.*)\(.*\)/ if $1 $1 else signature end end
name()
click to toggle source
# File lib/vizkit/connector_objects.rb, line 246 def name spec(true) @specs.first.name end
normalize_qt_args(*args)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 251 def normalize_qt_args(*args) args.map do |arg| if arg.is_a? Symbol arg.to_s else arg end end end
normalize_signature(signature)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 147 def normalize_signature(signature) name = Qt::MetaObject.normalizedSignature(signature).to_s name =~ /.* (.*)$/ #remove return type name = $1 || name name =~ /(.*)const$/ #remove const $1 || name end
populate_specs(signature)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 132 def populate_specs(signature) @specs = find_method_specs(signature,Qt::MetaMethod::Slot) raise ArgumentError,"#{signature} is not a valid slot signature for widget #{@widget}" if @specs.empty? end
read(options,*args,&block)
click to toggle source
no different in the case of slots and signals
# File lib/vizkit/connector_objects.rb, line 270 def read(options,*args,&block) args = normalize_qt_args *args write(options,*args,&block) end
spec(first = false)
click to toggle source
raises if there is more than one spec for the object filter out first
# File lib/vizkit/connector_objects.rb, line 184 def spec(first = false) raise "there is no spec" if @specs.empty? raise "there are more than one spec" if @specs.size > 1 if !first @specs.first end
specs()
click to toggle source
# File lib/vizkit/connector_objects.rb, line 242 def specs @specs end
write(options,*args,&block)
click to toggle source
# File lib/vizkit/connector_objects.rb, line 261 def write(options,*args,&block) args = normalize_qt_args *args s = spec(false) result = @widget.send(s.name,*args) block.call(result) if block result end