Class: Ui::RelationConfigModel
- Defined in:
- lib/roby/log/gui/relations.rb
Overview
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
Constant Summary collapse
- COL_NAME =
0- COL_COLOR =
1- TASK_ROOT_INDEX =
0- EVENT_ROOT_INDEX =
1- CATEGORIES =
['Task structure']
Instance Attribute Summary collapse
-
#display ⇒ Object
readonly
Returns the value of attribute display.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
Instance Method Summary collapse
- #columnCount(parent) ⇒ Object
- #data(index, role) ⇒ Object
- #event_root_index ⇒ Object
- #flags(index) ⇒ Object
- #hasChildren(parent) ⇒ Object
- #headerData(section, orientation, role) ⇒ Object
- #index(row, column, parent) ⇒ Object
-
#initialize(display) ⇒ RelationConfigModel
constructor
A new instance of RelationConfigModel.
- #parent(index) ⇒ Object
- #rowCount(parent) ⇒ Object
- #setData(index, value, role) ⇒ Object
- #task_root_index ⇒ Object
Constructor Details
#initialize(display) ⇒ RelationConfigModel
Returns a new instance of RelationConfigModel.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/roby/log/gui/relations.rb', line 25 def initialize(display) super() Roby.load_all_relations @current_color = 0 @display = display @relations = [] relations[TASK_ROOT_INDEX] = Roby::TaskStructure.enum_for(:each_relation).to_a end |
Instance Attribute Details
#display ⇒ Object (readonly)
Returns the value of attribute display.
24 25 26 |
# File 'lib/roby/log/gui/relations.rb', line 24 def display @display end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
23 24 25 |
# File 'lib/roby/log/gui/relations.rb', line 23 def relations @relations end |
Instance Method Details
#columnCount(parent) ⇒ Object
50 |
# File 'lib/roby/log/gui/relations.rb', line 50 def columnCount(parent); 2 end |
#data(index, role) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/roby/log/gui/relations.rb', line 62 def data(index, role) return Qt::Variant.new unless index.valid? category = index.internalPointer 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 ⇒ Object
20 |
# File 'lib/roby/log/gui/relations.rb', line 20 def event_root_index; createIndex(TASK_ROOT_INDEX, 0, -1) end |
#flags(index) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/roby/log/gui/relations.rb', line 106 def flags(index) if !index.valid? || index.internalPointer == -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) ⇒ Object
51 |
# File 'lib/roby/log/gui/relations.rb', line 51 def hasChildren(parent); !parent.valid? || parent.internalPointer == -1 end |
#headerData(section, orientation, role) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/roby/log/gui/relations.rb', line 56 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) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/roby/log/gui/relations.rb', line 36 def index(row, column, parent) if parent.valid? && parent.internalPointer == -1 createIndex(row, column, parent.row) elsif row < relations.size createIndex(row, column, -1) else Qt::ModelIndex.new end end |
#parent(index) ⇒ Object
45 46 47 48 49 |
# File 'lib/roby/log/gui/relations.rb', line 45 def parent(index) category = index.internalPointer if !index.valid? || category == -1 then Qt::ModelIndex.new else createIndex(category, 0, -1) end end |
#rowCount(parent) ⇒ Object
52 53 54 55 |
# File 'lib/roby/log/gui/relations.rb', line 52 def rowCount(parent) if !parent.valid? then relations.size else relations[parent.row].size end end |
#setData(index, value, role) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/roby/log/gui/relations.rb', line 88 def setData(index, value, role) category = index.internalPointer 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 ⇒ Object
21 |
# File 'lib/roby/log/gui/relations.rb', line 21 def task_root_index; createIndex(EVENT_ROOT_INDEX, 0, -1) end |