Sha256: 3897898c0b3b155720b15075260b2f7f6c352d0ac8abbddea8b240d13ca5a228

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 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 )
      add_item( text, data.to_variant )
    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

9 entries across 9 versions & 1 rubygems

Version Path
clevic-0.14.6 lib/clevic/qt/qt_combo_box.rb
clevic-0.14.5 lib/clevic/qt/qt_combo_box.rb
clevic-0.14.4 lib/clevic/qt/qt_combo_box.rb
clevic-0.14.3 lib/clevic/qt/qt_combo_box.rb
clevic-0.14.2 lib/clevic/qt/qt_combo_box.rb
clevic-0.14.1 lib/clevic/qt/qt_combo_box.rb
clevic-0.14.0 lib/clevic/qt/qt_combo_box.rb
clevic-0.13.0.b11 lib/clevic/qt/qt_combo_box.rb
clevic-0.13.0.b10 lib/clevic/qt/qt_combo_box.rb