class Vizkit::ItemDelegate

Delegate to select editor for editing tree view items

Attributes

tree_view[R]

Public Class Methods

new(tree_view,parent = nil) click to toggle source
Calls superclass method
# File lib/vizkit/tree_view.rb, line 131
def initialize(tree_view,parent = nil)
    super(parent)
    @tree_view = tree_view
end

Public Instance Methods

createEditor(parent, option,index) click to toggle source
Calls superclass method
# File lib/vizkit/tree_view.rb, line 136
def createEditor (parent, option,index)
    data = index.data(Qt::EditRole)
    if data.type == Qt::Variant::StringList
        Vizkit::EnumEditor.new(parent,data)
    elsif data.to_ruby?
        model = data.to_ruby
        Vizkit::AcknowledgeEditor.new(parent,model,self)
    else
        editor = super
        if editor.is_a? Qt::DoubleSpinBox
            editor.setDecimals 10
        end
        editor
    end
end
setModelData(editor,model,index) click to toggle source
Calls superclass method
# File lib/vizkit/tree_view.rb, line 152
def setModelData(editor,model,index)
    # we cannot use user properties here 
    # there is no way to define some on the ruby side
    if editor.respond_to? :getData
        model.setData(index,Qt::Variant.new(editor.getData),Qt::EditRole)
    elsif editor.is_a? Qt::ComboBox
        model.setData(index,Qt::Variant.new(editor.currentText),Qt::EditRole)
    else
        super
    end

    # show reject and apply buttons if the parent has the options
    # :accept => true
    parent = index
    while (parent = parent.parent).isValid
        item = @tree_view.item_from_index(parent)
        if !!item.options[:accept] && item.modified?
            parent = parent.sibling(parent.row,1)
            break unless parent.isValid
            @tree_view.setCurrentIndex(parent)
            @tree_view.openPersistentEditor(parent)
            break
        end
    end
end