Class: QML::Data::ListModel

Inherits:
Object
  • Object
show all
Includes:
Enumerable, QML::Dispatchable, Wrappable
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

Methods included from QML::Dispatchable

#later

Methods included from Wrappable

#create_wrapper

Constructor Details

#initialize(*columns) ⇒ ListModel

Returns a new instance of ListModel.

Parameters:

  • columns (Array<Symbol|String>)

    the column names of the model.



23
24
25
26
# File 'lib/qml/data/list_model.rb', line 23

def initialize(*columns)
  @columns = columns
  @qt_models = []
end

Instance Attribute Details

#columnsArray<Symbol|String> (readonly)

Returns:

  • (Array<Symbol|String>)


20
21
22
# File 'lib/qml/data/list_model.rb', line 20

def columns
  @columns
end

#qt_modelsArray<QtObjectBase> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



17
18
19
# File 'lib/qml/data/list_model.rb', line 17

def qt_models
  @qt_models
end

Instance Method Details

#[](index) ⇒ Object

This method is abstract.

Returns an item.

Parameters:

  • index (Integer)

    the index of the item.

Returns:

  • the item.



52
53
54
# File 'lib/qml/data/list_model.rb', line 52

def [](index)
  fail ::NotImplementedError
end

#countInteger

This method is abstract.

Returns the number of the items.

Returns:

  • (Integer)

    the number of the items.



44
45
46
# File 'lib/qml/data/list_model.rb', line 44

def count
  fail ::NotImplementedError
end

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

Iterates each item.

Overloads:

  • #eachEnumerator

    Returns:

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

    Yields:

    • (item)

    Returns:

    • (self)


34
35
36
37
38
39
40
# File 'lib/qml/data/list_model.rb', line 34

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:



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/qml/data/list_model.rb', line 100

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

  @qt_models.each do |qt_model|
    qt_model.begin_insert(range.min, range.max)
  end
  ret = yield
  @qt_models.each do |qt_model|
    qt_model.end_insert
  end
  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:



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/qml/data/list_model.rb', line 75

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

  @qt_models.each do |qt_model|
    qt_model.begin_move(range.min, range.max, destination)
  end
  ret = yield
  @qt_models.each do |qt_model|
    qt_model.end_move
  end
  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:



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/qml/data/list_model.rb', line 121

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

  @qt_models.each do |qt_model|
    qt_model.begin_remove(range.min, range.max)
  end
  ret = yield
  @qt_models.each do |qt_model|
    qt_model.end_remove
  end
  ret
end

#resetting(&block) ⇒ Object (protected)



134
135
136
137
138
139
140
141
142
143
# File 'lib/qml/data/list_model.rb', line 134

def resetting(&block)
  @qt_models.each do |qt_model|
    qt_model.begin_reset
  end
  ret = yield
  @qt_models.each do |qt_model|
    qt_model.end_reset
  end
  ret
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.



60
61
62
63
64
# File 'lib/qml/data/list_model.rb', line 60

def update(range)
  @qt_models.each do |qt_model|
    qt_model.update(range.min, range.max)
  end
end