class Ui::RelationConfigModel

Manage relations using a two-level tree structure. The relation categories (tasks and events) have a model index of (row, column, nil) while the relations have a model index of (row, column, category), where category is TASK_ROOT_INDEX for task relations and EVENT_ROOT_INDEX for event relations

Constants

CATEGORIES
COL_COLOR
COL_NAME
EVENT_ROOT_INDEX
QTRUBY_INDEX_USING_OBJECTIDS
QTRUBY_INDEX_USING_POINTERS
TASK_ROOT_INDEX

Attributes

display[R]
relations[R]

Public Class Methods

category_from_index(idx) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 44
def self.category_from_index(idx)
    if @@qtruby_behaviour == QTRUBY_INDEX_USING_POINTERS
        idx.internalPointer
    else
        idx.internalId >> 1
    end
end
detect_qtruby_behaviour(idx) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 36
def self.detect_qtruby_behaviour(idx)
    if idx.internalPointer == 0
        @@qtruby_behaviour = QTRUBY_INDEX_USING_POINTERS
    elsif idx.internalId == 1
        @@qtruby_behaviour = QTRUBY_INDEX_USING_OBJECTIDS
    end
end
new(display) click to toggle source
Calls superclass method
# File lib/roby/gui/relations_view/relations_config.rb, line 22
def initialize(display)
    super()

    @current_color = 0
    @display   = display
    @relations = []

    relations[TASK_ROOT_INDEX]  = Roby::TaskStructure.relations.to_a

    RelationConfigModel.detect_qtruby_behaviour(createIndex(0, 0, 0))
end

Public Instance Methods

columnCount(parent) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 67
def columnCount(parent); 2 end
data(index, role) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 79
def data(index, role)
    return Qt::Variant.new unless index.valid?

    category = RelationConfigModel.category_from_index(index)
    value = if category == -1
                if index.column == COL_NAME && role == Qt::DisplayRole
                    CATEGORIES[index.row]
                end
            else
                relation = relations[category][index.row]
                if index.column == COL_NAME && role == Qt::CheckStateRole
                    if    display.relation_enabled?(relation) then Qt::Checked.to_i
                    elsif display.layout_relation?(relation)  then Qt::PartiallyChecked.to_i
                    else Qt::Unchecked.to_i
                    end
                elsif index.column == COL_NAME && role == Qt::DisplayRole
                    relation.name.gsub(/.*Structure::/, '')
                elsif index.column == COL_COLOR && role == Qt::DisplayRole
                    display.relation_color(relation)
                end
            end

    if value then Qt::Variant.new(value)
    else Qt::Variant.new
    end
end
event_root_index() click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 17
def event_root_index; createIndex(EVENT_ROOT_INDEX, 0, -1) end
flags(index) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 123
def flags(index)
    if !index.valid? || RelationConfigModel.category_from_index(index) == -1 then Qt::ItemIsEnabled 
    else 
        flags = Qt::ItemIsSelectable | Qt::ItemIsTristate | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable
        if index.column == 1
            flags = Qt::ItemIsEditable | flags
        end
        flags
    end
end
hasChildren(parent) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 68
def hasChildren(parent); !parent.valid? || RelationConfigModel.category_from_index(parent) == -1 end
headerData(section, orientation, role) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 73
def headerData(section, orientation, role)
    return Qt::Variant.new unless role == Qt::DisplayRole && orientation == Qt::Horizontal
    value = if section == 0 then "Relation"
            else "Color" end
    Qt::Variant.new(value)
end
index(row, column, parent) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 52
def index(row, column, parent)
    if parent.valid? && RelationConfigModel.category_from_index(parent) == -1
        createIndex(row, column, parent.row)
    elsif row < relations.size
        createIndex(row, column, -1)
    else
        Qt::ModelIndex.new
    end
end
parent(index) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 62
def parent(index)
    category = RelationConfigModel.category_from_index(index)
    if !index.valid? || category == -1 then Qt::ModelIndex.new
    else createIndex(category, 0, -1) end
end
rowCount(parent) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 69
def rowCount(parent)
    if !parent.valid? then relations.size
    else relations[parent.row].size end
end
setData(index, value, role) click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 105
def setData(index, value, role)
    category = RelationConfigModel.category_from_index(index)
    relation = relations[category][index.row]
    if role == Qt::CheckStateRole
        case value.to_i
        when Qt::Checked.to_i
            display.enable_relation(relation)
        when Qt::PartiallyChecked.to_i
            display.layout_relation(relation)
        else
            display.ignore_relation(relation)
        end
    else
        display.update_relation_color(relation, value.to_string)
    end
    display.update
    emit dataChanged(index, index)
end
task_root_index() click to toggle source
# File lib/roby/gui/relations_view/relations_config.rb, line 18
def task_root_index;  createIndex(TASK_ROOT_INDEX, 0, -1) end