class Vizkit::PropertyItem

Attributes

listener[R]
property[R]

Public Class Methods

new(property,options = Hash.new) click to toggle source
Calls superclass method Vizkit::TypelibItem.new
# File lib/vizkit/vizkit_items.rb, line 737
def initialize(property,options = Hash.new)
    options[:item_type] ||= :label
    options[:editable] = true unless options.has_key?(:editable)
    options[:text] = property.name if options[:item_type] == :label
    options,other_options = Kernel.filter_options options,:accept => true
    super(nil,other_options)
    @options.merge! options

    @property = property
    @listener = @property.on_raw_change do |data|
        # depending on the type we receive none typelip objects
        # therefore if have to initialize it with a new sample
        begin
            unless typelib_val
                update property.new_sample.zero!
                setEditable @options[:editable] if @options[:item_type] != :label
            end
            update data if !modified?
        rescue Orocos::NotFound
        end
    end
    @listener.stop
    @stop_propagated = false

    if @options[:item_type] != :label
        @error_listener = property.on_error do |error|
            @options[:text] = error.to_s
            emitDataChanged
        end
        @reachable_listener = property.on_reachable do
            @options.delete :text
            emitDataChanged
        end
    end
end

Public Instance Methods

collapse(propagated = false) click to toggle source
# File lib/vizkit/vizkit_items.rb, line 773
def collapse(propagated = false)
    @expanded = false
    if @listener.listening?
        @stop_propagated = propagated
        @listener.stop
    end
end
context_menu(pos,parent_widget,items = []) click to toggle source
# File lib/vizkit/vizkit_items.rb, line 786
def context_menu(pos,parent_widget,items = [])
end
data(role = Qt::UserRole+1) click to toggle source
Calls superclass method Vizkit::TypelibItem#data
# File lib/vizkit/vizkit_items.rb, line 789
def data(role = Qt::UserRole+1)
    if role == Qt::EditRole && !direct_type?
        # we have to use the one from the first row
        # the other one has a copy which was not changed
        i = index.sibling(row,0)
        if i.isValid
            # workaround memeroy leak qt-ruby
            # the returned Qt::Variant is never be deleted
            @last_value.dispose if @last_value
            @last_value = Qt::Variant.from_ruby i.model.itemFromIndex(i)
        else
            super
        end
    else
        super
    end
end
expand(propagated = false) click to toggle source
# File lib/vizkit/vizkit_items.rb, line 781
def expand(propagated = false)
    @expanded = true
    @listener.start if !propagated || @stop_propagated
end
modified!(value = true, items = [],update_parent = false) click to toggle source
Calls superclass method Vizkit::VizkitItem#modified!
# File lib/vizkit/vizkit_items.rb, line 807
def modified!(value = true, items = [],update_parent = false)
    return if value == @modified
    super(value,items,false)
    if !value
        update @property.raw_read
    elsif direct_type?
        write
    end
    if column == 0 && !direct_type?
        i = index.sibling(row,1)
        if i.isValid
            item = i.model.itemFromIndex i
            item.modified!(value,items)
        end
    end
end
write(&block) click to toggle source
# File lib/vizkit/vizkit_items.rb, line 824
def write(&block)
    begin
        if (column == 1 && direct_type?) || (column == 0 && !direct_type?)
            @property.write(typelib_val,&block)
        end
        modified!(false)
    rescue Orocos::NotFound
    end
end