Sha256: 76850b4605e0fa3cd5801f032f0e0b921d56373aed9c36dced692f807630b735

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module Qt
  # Implement the methods needed for ComboBox to work with the
  # various Clevic::Delegate classes.
  class ComboBox
    def no_insert=( bool )
      self.insert_policy = Qt::ComboBox::NoInsert if bool
    end

    def <<( item )
      text, data = item_to_editor( item )
      if data.is_a?( Qt::Variant )
        add_item( text, data )
      else
        puts "#{__FILE__}:#{__LINE__}:warning: #{data} is not a variant"
        add_item( text, data.to_variant )
      end
    end

    def include?( item )
      text, data = item_to_editor( item )
      find_data( data.to_variant ) != -1
    end

    def selected_item=( item )
      text, data = item_to_editor( item )
      self.current_index = find_data( data.to_variant )
    end

    def selected_item
      delegate.editor_to_item( item_data( self.current_index ).value )
    end

    # wrapper for the delegate method so we don't have
    # to keep checking for nil values
    def item_to_editor( item )
      if item
        delegate.item_to_editor( item )
      else
        ['', nil ]
      end
    end

    # wrapper for the delegate method so we don't have
    # to keep checking for nil values
    def editor_to_item( data )
      if data
        delegate.editor_to_item( data )
      else
        nil
      end
    end
  end

  # Adding these to Qt::Widget as the superclass
  # doesn't work for some reason.
  class ComboBox
    attr_accessor :delegate
  end

  class LineEdit
    attr_accessor :delegate
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clevic-0.13.0.b12 lib/clevic/qt/qt_combo_box.rb