Class: Clevic::RelationalDelegate
- Inherits:
-
ComboDelegate
- Object
- Qt::ItemDelegate
- Delegate
- ComboDelegate
- Clevic::RelationalDelegate
- Defined in:
- lib/clevic/qt/relational_delegate.rb,
lib/clevic/swing/relational_delegate.rb,
lib/clevic/delegates/relational_delegate.rb
Overview
Display a collection of possible related entities in the combo box. TODO this should be a module
Instance Attribute Summary
Attributes inherited from ComboDelegate
Attributes inherited from Delegate
Instance Method Summary collapse
-
#combo_class ⇒ Object
use the Clevic::ComboBox class because JCombobox is remarkably stupid about far too many things.
- #editor_to_item(data) ⇒ Object
- #empty_set_message ⇒ Object
-
#initialize(field) ⇒ RelationalDelegate
constructor
A new instance of RelationalDelegate.
- #item_to_editor(item) ⇒ Object
- #needs_combo? ⇒ Boolean
- #population ⇒ Object
-
#restricted? ⇒ Boolean
don’t allow new values.
-
#setEditorData(editor_widget, model_index) ⇒ Object
called by Qt when it wants to give the delegate an index to edit.
-
#translate_from_editor_text(editor_widget, text) ⇒ Object
return an entity object, given a text selection.
Methods inherited from ComboDelegate
#allow_null?, #autocomplete, #configure_editable, #configure_prefix, #createEditor, #create_combo_box, #display_for, #dump_editor_state, #empty_set?, #filter_prefix, #framework_setup, #full_edit, #getListCellRendererComponent, #hint_string, #if_empty_message, #init_component, #is_combo?, #line_editor, #minimal_edit, #needs_pre_selection?, #repopulate, #setModelData, #updateEditorGeometry, #value
Methods inherited from Delegate
#attribute, #editorEvent, #entity_class, #full_edit, #inspect, #is_combo?, #minimal_edit, #native, #needs_pre_selection?, #show_message, #updateEditorGeometry
Methods included from FieldValuer
#attribute_value, #attribute_value=, #display_value, #edit_value, #edit_value=, #find_related, #raw_value, #text_value=, #tooltip, valuer, #valuer, #writer
Constructor Details
#initialize(field) ⇒ RelationalDelegate
Returns a new instance of RelationalDelegate.
12 13 14 |
# File 'lib/clevic/swing/relational_delegate.rb', line 12 def initialize( field ) super end |
Instance Method Details
#combo_class ⇒ Object
use the Clevic::ComboBox class because JCombobox is remarkably stupid about far too many things.
18 19 20 |
# File 'lib/clevic/swing/relational_delegate.rb', line 18 def combo_class ComboBox end |
#editor_to_item(data) ⇒ Object
16 17 18 |
# File 'lib/clevic/qt/relational_delegate.rb', line 16 def editor_to_item( data ) entity.[ data ] end |
#empty_set_message ⇒ Object
13 14 15 |
# File 'lib/clevic/delegates/relational_delegate.rb', line 13 def "There must be records in #{field.} for this field to be editable." end |
#item_to_editor(item) ⇒ Object
12 13 14 |
# File 'lib/clevic/qt/relational_delegate.rb', line 12 def item_to_editor( item ) [ field.transform_attribute( item ), item.pk.to_variant ] end |
#needs_combo? ⇒ Boolean
9 10 11 |
# File 'lib/clevic/delegates/relational_delegate.rb', line 9 def needs_combo? dataset.count > 0 end |
#population ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/clevic/delegates/relational_delegate.rb', line 17 def population # dataset contains the set of all possible related entities, # dataset is defined in Delegate # entity is set in init_component # field and entity are used by FieldValuer # including the current entity. # Could also use # dataset.or( entity_class.primary_key => entity_key.pk ) # but that would put current entity in the list somewhere # other than the top, which seems to be the most sensible # place for it. Could also create a special enumerator # which gives back the entity first, followed by the dataset. dataset.all.with do |values| # make sure there's only one instance of the current value, # and make sure it's at the top of the list values.delete( attribute_value ) values.unshift( attribute_value ) end end |
#restricted? ⇒ Boolean
don’t allow new values
23 24 25 |
# File 'lib/clevic/swing/relational_delegate.rb', line 23 def restricted? true end |
#setEditorData(editor_widget, model_index) ⇒ Object
called by Qt when it wants to give the delegate an index to edit
21 22 23 24 25 26 27 28 |
# File 'lib/clevic/qt/relational_delegate.rb', line 21 def setEditorData( , model_index ) if is_combo?( ) unless model_index.attribute_value.nil? .selected_item = model_index.attribute_value end .line_edit.andand.select_all end end |
#translate_from_editor_text(editor_widget, text) ⇒ Object
return an entity object, given a text selection
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/clevic/qt/relational_delegate.rb', line 31 def translate_from_editor_text( , text ) item_index = .find_text( text ) # fetch record id from editor_widget item_data item_data = .item_data( item_index ) if item_data.valid? # get the entity it refers to, if there is one # return nil if nil was passed or the entity wasn't found field.[ item_data.to_int ] end end |