Class: Ui::RelationConfigModel
- Defined in:
- lib/roby/gui/relations_view/relations_config.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']
- QTRUBY_INDEX_USING_POINTERS =
1- QTRUBY_INDEX_USING_OBJECTIDS =
2
Instance Attribute Summary collapse
-
#display ⇒ Object
readonly
Returns the value of attribute display.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
Class Method Summary collapse
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
22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#display ⇒ Object (readonly)
Returns the value of attribute display.
21 22 23 |
# File 'lib/roby/gui/relations_view/relations_config.rb', line 21 def display @display end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
20 21 22 |
# File 'lib/roby/gui/relations_view/relations_config.rb', line 20 def relations @relations end |
Class Method Details
.category_from_index(idx) ⇒ Object
44 45 46 47 48 49 50 |
# 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) ⇒ Object
36 37 38 39 40 41 42 |
# 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 |
Instance Method Details
#columnCount(parent) ⇒ Object
67 |
# File 'lib/roby/gui/relations_view/relations_config.rb', line 67 def columnCount(parent); 2 end |
#data(index, role) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# 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 ⇒ Object
17 |
# File 'lib/roby/gui/relations_view/relations_config.rb', line 17 def event_root_index; createIndex(EVENT_ROOT_INDEX, 0, -1) end |
#flags(index) ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# 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) ⇒ Object
68 |
# 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) ⇒ Object
73 74 75 76 77 78 |
# 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) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# 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) ⇒ Object
62 63 64 65 66 |
# 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) ⇒ Object
69 70 71 72 |
# 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) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# 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 ⇒ Object
18 |
# File 'lib/roby/gui/relations_view/relations_config.rb', line 18 def task_root_index; createIndex(TASK_ROOT_INDEX, 0, -1) end |