Class: TreeItem

Inherits:
Object show all
Defined in:
lib/Qt/active_item_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, keys, parent = nil, prefix = "") ⇒ TreeItem

Returns a new instance of TreeItem.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/Qt/active_item_model.rb', line 30

def initialize(item, keys, parent = nil, prefix="")
    @keys = keys
    @parentItem = parent
    @childItems = []
    @resource = item
    if @resource.respond_to? :attributes
        @resource.attributes.inject(@itemData = {}) do |data, a|
            if a[1].respond_to? :attributes
                TreeItem.new(a[1], @keys, self, prefix + a[0] + ".")
            else
                data[prefix + a[0]] = a[1]
            end
            data
        end
    else
        @itemData = item
    end

    if @parentItem
        @parentItem.appendChild(self)
    end
end

Instance Attribute Details

#childItemsObject (readonly)

Returns the value of attribute childItems.



28
29
30
# File 'lib/Qt/active_item_model.rb', line 28

def childItems
  @childItems
end

#itemDataObject (readonly)

Returns the value of attribute itemData.



28
29
30
# File 'lib/Qt/active_item_model.rb', line 28

def itemData
  @itemData
end

#resourceObject (readonly)

Returns the value of attribute resource.



28
29
30
# File 'lib/Qt/active_item_model.rb', line 28

def resource
  @resource
end

Instance Method Details

#appendChild(item) ⇒ Object



53
54
55
# File 'lib/Qt/active_item_model.rb', line 53

def appendChild(item)
    @childItems.push(item)
end

#child(row) ⇒ Object



57
58
59
# File 'lib/Qt/active_item_model.rb', line 57

def child(row)
    return @childItems[row]
end

#childCountObject



61
62
63
# File 'lib/Qt/active_item_model.rb', line 61

def childCount
    return @childItems.length
end

#columnCountObject



65
66
67
# File 'lib/Qt/active_item_model.rb', line 65

def columnCount
    return @itemData.length
end

#data(column) ⇒ Object



69
70
71
# File 'lib/Qt/active_item_model.rb', line 69

def data(column)
    return Qt::Variant.new(@itemData[@keys[column]])
end

#parentObject



73
74
75
# File 'lib/Qt/active_item_model.rb', line 73

def parent
    return @parentItem
end

#rowObject



77
78
79
80
81
82
83
# File 'lib/Qt/active_item_model.rb', line 77

def row
    if !@parentItem.nil?
        return @parentItem.childItems.index(self)
    end

    return 0
end