Skip to content

Commit 5cbc20e

Browse files
authored
Added Move to ListModel (#195)
1 parent 089cd46 commit 5cbc20e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

core/ListModel.qml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,21 @@ Model {
113113
function forEach(callback) {
114114
return this._rows.forEach(callback)
115115
}
116+
117+
function move(from, to) {
118+
while(from < 0) {
119+
from += this._rows.length;
120+
}
121+
while(to < 0) {
122+
to += this._rows.length;
123+
}
124+
if(to >= this._rows.length) {
125+
var k = to - this._rows.length;
126+
while((k--) + 1) {
127+
this._rows.push(undefined);
128+
}
129+
}
130+
this._rows.splice(to, 0, this._rows.splice(from, 1)[0]);
131+
this.reset();
132+
}
116133
}

0 commit comments

Comments
 (0)