Class: Qt::Base

Inherits:
Object show all
Includes:
Observable
Defined in:
lib/rui/toolkits/qtbase/qt.rb

Defined Under Namespace

Classes: ObserverDisconnecter, Signal, SignalDisconnecter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Observable

#fire, #observe, #observe_limited

Class Method Details

.create_signal_map(obj) ⇒ Object



324
325
326
# File 'lib/rui/toolkits/qtbase/qt.rb', line 324

def self.create_signal_map(obj)
  obj.meta_object.create_signal_map
end

.signal_map(obj) ⇒ Object



320
321
322
# File 'lib/rui/toolkits/qtbase/qt.rb', line 320

def self.signal_map(obj)
  @signal_map ||= self.create_signal_map(obj)
end

Instance Method Details

#gui=(g) ⇒ Object



328
329
330
# File 'lib/rui/toolkits/qtbase/qt.rb', line 328

def gui=(g)
  setGUI(g)
end

#in(interval, &blk) ⇒ Object



308
309
310
# File 'lib/rui/toolkits/qtbase/qt.rb', line 308

def in(interval, &blk)
  Qt::Timer.in(interval, self, &blk)
end

#on(sig, types = nil, &blk) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/rui/toolkits/qtbase/qt.rb', line 269

def on(sig, types = nil, &blk)
  sig = Signal.create(sig, types)
  candidates = if is_a? Qt::Object
    signal_map[sig.symbol]
  end
  if candidates
    if types
      # find candidate with the correct argument types
      candidates = candidates.find_all{|s| s[1] == types }
    end
    if candidates.size > 1
      # find candidate with the correct arity
      arity = blk.arity
      if blk.arity == -1
        # take first
        candidates = [candidates.first]
      else
        candidates = candidates.find_all{|s| s[1].size == arity }
      end
    end
    if candidates.size > 1
      raise "Ambiguous overload for #{sig} with arity #{arity}"
    elsif candidates.empty?
      msg = if types
        "with types #{types.join(' ')}"
      else
        "with arity #{blk.arity}"
      end
      raise "No overload for #{sig} #{msg}"
    end
    sign = SIGNAL(candidates.first[0])
    connect(sign, &blk)
    SignalDisconnecter.new(self, sign)
  else
    observer = observe(sig.symbol, &blk)
    ObserverDisconnecter.new(self, observer)
  end
end

#run_later(&blk) ⇒ Object



312
313
314
# File 'lib/rui/toolkits/qtbase/qt.rb', line 312

def run_later(&blk)
  self.in(0, &blk)
end

#signal_mapObject



316
317
318
# File 'lib/rui/toolkits/qtbase/qt.rb', line 316

def signal_map
  self.class.signal_map(self)
end