Warning, /plasma-bigscreen/mycroft-skill-installer/app/qml/SortFilterModel.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.9
0002 import QtQml.Models 2.3
0003 
0004 ListModel {
0005     property string sortColumnName: ""
0006     property string order: "desc"
0007 
0008     function swap(a,b) {
0009         if (a<b) {
0010             move(a,b,1);
0011             move (b-1,a,1);
0012         }
0013         else if (a>b) {
0014             move(b,a,1);
0015             move (a-1,b,1);
0016         }
0017     }
0018 
0019     function partition(begin, end, pivot)
0020     {
0021         var piv=get(pivot)[sortColumnName];
0022         swap(pivot, end-1);
0023         var store=begin;
0024         var ix;
0025         for(ix=begin; ix<end-1; ++ix) {
0026             if (order ==="asc"){
0027                 if(get(ix)[sortColumnName] < piv) {
0028                     swap(store,ix);
0029                     ++store;
0030                 }
0031             }else if (order ==="desc"){
0032                 if(get(ix)[sortColumnName] > piv) {
0033                     swap(store,ix);
0034                     ++store;
0035                 }
0036             }
0037         }
0038         swap(end-1, store);
0039 
0040         return store;
0041     }
0042 
0043     function qsort(begin, end)
0044     {
0045         if(end-1>begin) {
0046             var pivot=begin+Math.floor(Math.random()*(end-begin));
0047 
0048             pivot=partition( begin, end, pivot);
0049 
0050             qsort(begin, pivot);
0051             qsort(pivot+1, end);
0052         }
0053     }
0054 
0055     function quick_sort() {
0056         qsort(0,count)
0057         lview.resetCIndex()
0058     }
0059 }