Sha256: f3db7b4a1792db27f04e9b283ab954893e309034e1623c6073efd26919baf14b

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require 'clevic/qt/combo_delegate.rb'

module Clevic

# Provide a list of all values in this field,
# and allow new values to be entered.
# :frequency can be set as an option. Boolean. If it's true
# the options are sorted in order of most frequently used first.
class DistinctDelegate < ComboDelegate
  
  def needs_combo?
    # works except when there is a '' in the column
    entity_class.adaptor.count( attribute.to_s, find_options ) > 0
  end
  
  def populate_current( editor, model_index )
    # already done in the SQL query in populate, so don't even check
  end
  
  def populate( editor, model_index )
    # we only use the first column, so use the second
    # column to sort by, since SQL requires the order by clause
    # to be in the select list where distinct is involved
    entity_class.adaptor.attribute_list( attribute, model_index.attribute_value, field.description, field.frequency, find_options ) do |row|
      value = row[attribute]
      editor.add_item( value, value.to_variant )
    end
  end
  
  def translate_from_editor_text( editor, text )
    text
  end
end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
clevic-0.13.0.b3 lib/clevic/qt/distinct_delegate.rb
clevic-0.13.0.b2 lib/clevic/qt/distinct_delegate.rb
clevic-0.13.0.b1 lib/clevic/qt/distinct_delegate.rb