Class: QML::Data::ListModel
- Inherits:
-
Object
- Object
- QML::Data::ListModel
- 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
Instance Attribute Summary collapse
- #columns ⇒ Array<Symbol|String> readonly
- #qt_models ⇒ Array<QtObjectBase> readonly private
Instance Method Summary collapse
-
#[](index) ⇒ Object
abstract
Returns an item.
-
#count ⇒ Integer
abstract
The number of the items.
-
#each ⇒ Object
Iterates each item.
-
#initialize(*columns) ⇒ ListModel
constructor
A new instance of ListModel.
-
#inserting(range) { ... } ⇒ Object
protected
Notifies the list views that items are about to be and were inserted.
-
#moving(range, destination) { ... } ⇒ Object
protected
Notifies the list views that items are about to be and were moved.
-
#removing(range) { ... } ⇒ Object
protected
Notifies the list views that items are about to be and were removed.
- #resetting(&block) ⇒ Object protected
-
#update(range) ⇒ Object
protected
Notifies the list views that the data of the items was changed.
Methods included from QML::Dispatchable
Methods included from Wrappable
Constructor Details
#initialize(*columns) ⇒ ListModel
Returns a new instance of ListModel.
23 24 25 26 |
# File 'lib/qml/data/list_model.rb', line 23 def initialize(*columns) @columns = columns @qt_models = [] end |
Instance Attribute Details
#columns ⇒ Array<Symbol|String> (readonly)
20 21 22 |
# File 'lib/qml/data/list_model.rb', line 20 def columns @columns end |
#qt_models ⇒ Array<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.
17 18 19 |
# File 'lib/qml/data/list_model.rb', line 17 def qt_models @qt_models end |
Instance Method Details
#[](index) ⇒ Object
Returns an item.
52 53 54 |
# File 'lib/qml/data/list_model.rb', line 52 def [](index) fail ::NotImplementedError end |
#count ⇒ Integer
Returns the number of the items.
44 45 46 |
# File 'lib/qml/data/list_model.rb', line 44 def count fail ::NotImplementedError end |
#each ⇒ Enumerator #each {|item| ... } ⇒ self
Iterates each item.
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.
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.
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.
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.
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 |