Class: Cosmos::ComboBoxItemDelegate

Inherits:
Qt::StyledItemDelegate
  • Object
show all
Defined in:
lib/cosmos/tools/table_manager/table_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ ComboBoxItemDelegate

Returns a new instance of ComboBoxItemDelegate.



38
39
40
41
# File 'lib/cosmos/tools/table_manager/table_manager.rb', line 38

def initialize(parent)
  @table = parent
  super(parent)
end

Instance Method Details

#createEditor(parent, option, index) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cosmos/tools/table_manager/table_manager.rb', line 43

def createEditor(parent, option, index)
  table = TableManager.instance.core.table_def.get_table(TableManager.instance.currently_displayed_table_name)
  gui_table = TableManager.instance.gui_tables[TableManager.instance.currently_displayed_table_name]
  if table.type == :TWO_DIMENSIONAL
    item_name = gui_table.horizontalHeaderItem(index.column).text + index.row.to_s
    item = table.get_item(item_name)
  else
    item_name = gui_table.verticalHeaderItem(index.row).text
    item = table.get_item(item_name)
  end
  if item.display_type == :STATE and item.editable
    combo = Qt::ComboBox.new(parent)
    combo.addItems(item.states.keys.sort)
    combo.setCurrentText(table.read(item.name).to_s)
    connect(combo, SIGNAL('activated(int)')) do
      emit commitData(combo)
      gui_table.closeEditor(combo, 0)
    end
    return combo
  else
    return super(parent, option, index)
  end
end

#setEditorData(editor, index) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cosmos/tools/table_manager/table_manager.rb', line 75

def setEditorData(editor, index)
  if Qt::ComboBox === editor
    v = index.data(Qt::EditRole)
    combo_index = editor.findText(v.toString)
    if combo_index >= 0
      editor.setCurrentIndex(combo_index)
    else
      editor.setCurrentIndex(0)
    end
  else
    super(editor, index)
  end
end

#setModelData(editor, model, index) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/cosmos/tools/table_manager/table_manager.rb', line 67

def setModelData(editor, model, index)
  if Qt::ComboBox === editor
    model.setData(index, Qt::Variant.new(editor.currentText), Qt::EditRole)
  else
    super(editor, model, index)
  end
end