Class: Shirka::Qt::TreeController

Inherits:
Controller show all
Defined in:
lib/shirka/qt/tree/controller.rb

Instance Attribute Summary

Attributes inherited from Controller

#app, #components, #data, #parent, #view

Instance Method Summary collapse

Methods inherited from Controller

#add_component, #initialize, #on_component_adding

Methods included from Eventalk

#add_watcher, #fire, #forward, #watch, #watchers

Constructor Details

This class inherits a constructor from Shirka::Controller

Instance Method Details

#add_item(text = '', controller_class = nil) ⇒ Object



21
22
23
24
25
# File 'lib/shirka/qt/tree/controller.rb', line 21

def add_item(text='', controller_class=nil)
  controller_class ||= item_controller_class
  comp = controller_class.new app, self, {text: text, root: self}
  add_component comp
end

#init(data) ⇒ Object



5
6
7
8
# File 'lib/shirka/qt/tree/controller.rb', line 5

def init(data)
  @item_ids = {}        
  data.each { |i| add_item i } if data.respond_to? :each
end

#item_controller_classObject



16
17
18
19
# File 'lib/shirka/qt/tree/controller.rb', line 16

def item_controller_class
  name = self.class.to_s.sub(/Controller$/, 'ItemController')
  Object.const_get name rescue ::Shirka::Qt::TreeItemController
end

#on_component_added(component, data = nil) ⇒ Object



32
33
34
35
36
# File 'lib/shirka/qt/tree/controller.rb', line 32

def on_component_added(component, data=nil)
  id = data
  @item_ids[id] = component
  watch component
end

#on_double_clicked(id) ⇒ Object



27
28
29
30
# File 'lib/shirka/qt/tree/controller.rb', line 27

def on_double_clicked(id)
  controller = @item_ids[id]
  controller.on_double_clicked
end

#view_classObject



10
11
12
13
# File 'lib/shirka/qt/tree/controller.rb', line 10

def view_class
  name = self.class.to_s.sub(/Controller$/, 'View')
  Object.const_get name rescue ::Shirka::Qt::TreeView
end