Skip to content

Commit

Permalink
Added Move to ListModel (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyInCorner authored Feb 26, 2021
1 parent 089cd46 commit 5cbc20e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/ListModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,21 @@ Model {
function forEach(callback) {
return this._rows.forEach(callback)
}

function move(from, to) {
while(from < 0) {
from += this._rows.length;
}
while(to < 0) {
to += this._rows.length;
}
if(to >= this._rows.length) {
var k = to - this._rows.length;
while((k--) + 1) {
this._rows.push(undefined);
}
}
this._rows.splice(to, 0, this._rows.splice(from, 1)[0]);
this.reset();
}
}

0 comments on commit 5cbc20e

Please sign in to comment.