Class: QML::ListModel

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/qml/data/list_model.rb

Overview

ListModel is the base class of list models which provides data to QML list views.

Direct Known Subclasses

ArrayModel, QueryModel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*columns) ⇒ ListModel

Returns a new instance of ListModel.

Parameters:



12
13
14
15
16
# File 'lib/qml/data/list_model.rb', line 12

def initialize(*columns)
  @columns = columns
  @access = ListModelAccess.create(self)
  @qml_model = QML::Plugins.rubyqml.createListModel(@access)
end

Instance Attribute Details

#columnsArray<Symbol|String> (readonly)

Returns:



9
10
11
# File 'lib/qml/data/list_model.rb', line 9

def columns
  @columns
end

Instance Method Details

#[](index) ⇒ Object

This method is abstract.

Returns an item.

Parameters:

  • index (Integer)

    the index of the item.

Returns:

  • the item.



42
43
44
# File 'lib/qml/data/list_model.rb', line 42

def [](index)
  fail ::NotImplementedError
end

#countInteger

This method is abstract.

Returns the number of the items.

Returns:

  • (Integer)

    the number of the items.



34
35
36
# File 'lib/qml/data/list_model.rb', line 34

def count
  fail ::NotImplementedError
end

#eachEnumerator #each {|item| ... } ⇒ self

Iterates each item.

Overloads:

  • #eachEnumerator

    Returns:

    • (Enumerator)
  • #each {|item| ... } ⇒ self

    Yields:

    • (item)

    Returns:

    • (self)


24
25
26
27
28
29
30
# File 'lib/qml/data/list_model.rb', line 24

def each
  return to_enum unless block_given?
  count.times do |i|
    yield self[i]
  end
  self
end

#inserting(range) { ... } ⇒ Object (protected)

Notifies the list views that items are about to be and were inserted.

Examples:

inserting(index ... index + items.size) do
  @array.insert(index, *items)
end

Parameters:

  • range (Range<Integer>)

    the index range of the items after inserted.

Yields:

  • the block that actually do insertion of the items.

Returns:

  • the result of give block.

See Also:



89
90
91
92
93
94
95
96
# File 'lib/qml/data/list_model.rb', line 89

def inserting(range, &block)
  return if range.count == 0

  @access.begin_insert(range.min, range.max)
  ret = yield
  @access.end_insert
  ret
end

#moving(range, destination) { ... } ⇒ Object (protected)

Notifies the list views that items are about to be and were moved.

Parameters:

  • range (Range<Integer>)

    the index range of the item being moved.

  • destination (Integer)

    the first index of the items after moved.

Yields:

  • the block that actually do moving operation of the items.

Returns:

  • the result of given block.

See Also:



68
69
70
71
72
73
74
75
# File 'lib/qml/data/list_model.rb', line 68

def moving(range, destination)
  return if range.count == 0

  @access.begin_move(range.min, range.max, destination)
  ret = yield
  @access.end_move
  ret
end

#removing(range) { ... } ⇒ Object (protected)

Notifies the list views that items are about to be and were removed.

Parameters:

  • range (Range<Integer>)

    the index range of the items before removed.

Yields:

  • the block that actually do removal of the items.

Returns:

  • the result of give block.

See Also:



106
107
108
109
110
111
112
113
# File 'lib/qml/data/list_model.rb', line 106

def removing(range, &block)
  return if range.count == 0

  @access.begin_remove(range.min, range.max)
  ret = yield
  @access.end_remove
  ret
end

#resetting(&block) ⇒ Object (protected)



115
116
117
118
119
120
# File 'lib/qml/data/list_model.rb', line 115

def resetting(&block)
  @access.begin_reset
  ret = yield
  @access.end_reset
  ret
end

#to_qmlQML::JSObject

Returns:



47
48
49
# File 'lib/qml/data/list_model.rb', line 47

def to_qml
  @qml_model
end

#update(range) ⇒ Object (protected)

Notifies the list views that the data of the items was changed.

Parameters:

  • range (Range<Integer>)

    the index range of changed items.



55
56
57
# File 'lib/qml/data/list_model.rb', line 55

def update(range)
  @access.update(range.min, range.max)
end