From 5cbc20e9a84996dbe76cdef2f14e380e050e8bd1 Mon Sep 17 00:00:00 2001 From: Keith <61481372+GuyInCorner@users.noreply.github.com> Date: Fri, 26 Feb 2021 04:37:15 -0700 Subject: [PATCH] Added Move to ListModel (#195) --- core/ListModel.qml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/ListModel.qml b/core/ListModel.qml index 26c606a56..4a2922caf 100644 --- a/core/ListModel.qml +++ b/core/ListModel.qml @@ -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(); + } }