Class: Cosmos::ComboBoxItemDelegate
- Inherits:
 - 
      Qt::StyledItemDelegate
      
        
- Object
 - Qt::StyledItemDelegate
 - Cosmos::ComboBoxItemDelegate
 
 
- Defined in:
 - lib/cosmos/tools/table_manager/table_manager.rb
 
Overview
This class applies to all items in the table but its only purpose is to determine if table cells should be rendered as comboboxes. Any table items with states are rendered as comboboxes.
Instance Method Summary collapse
- 
  
    
      #createEditor(parent, option, index)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Create the combobox widget to display the values.
 - 
  
    
      #setEditorData(editor, index)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Sets the current item in the combobox based on the model data.
 - 
  
    
      #setModelData(editor, model, index)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Gets the current item from the combobox if it exists and writes it back to the model.
 
Instance Method Details
#createEditor(parent, option, index) ⇒ Object
Create the combobox widget to display the values
      44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66  | 
    
      # File 'lib/cosmos/tools/table_manager/table_manager.rb', line 44 def createEditor(parent, option, index) table = TableManager.instance.core.config.table(TableManager.instance.current_table_name) gui_table = TableManager.instance.tabbook.tab(TableManager.instance.current_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.states && 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
Sets the current item in the combobox based on the model data
      84 85 86 87 88 89 90 91 92 93 94 95 96  | 
    
      # File 'lib/cosmos/tools/table_manager/table_manager.rb', line 84 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
Gets the current item from the combobox if it exists and writes it back to the model.
      73 74 75 76 77 78 79  | 
    
      # File 'lib/cosmos/tools/table_manager/table_manager.rb', line 73 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  |