28
SortProps::SortProps(vfile *vf, int col, const KrViewProperties * props, bool isDummy, bool asc, int origNdx) {
28
void SortProps::init(vfile *vf, int col, const KrViewProperties * props, bool isDummy, bool asc, int origNdx, QVariant customData) {
31
31
_isdummy = isDummy;
314
313
descending ? &itemGreaterThan : &itemLessThan);
317
QVector<KrSort::SortProps*>::iterator lowerBound(QVector<SortProps*> &sorting, SortProps *item, bool descending)
319
return qLowerBound(sorting.begin(), sorting.end(), item,
320
descending ? &itemGreaterThan : &itemLessThan);
323
}; // namespace KrSort
316
Sorter::Sorter(int reserveItems, const KrViewProperties *viewProperties,
317
LessThanFunc lessThanFunc, LessThanFunc greaterThanFunc) :
318
_viewProperties(viewProperties),
319
_lessThanFunc(lessThanFunc),
320
_greaterThanFunc(greaterThanFunc)
322
_items.reserve(reserveItems);
323
_itemStore.reserve(reserveItems);
326
void Sorter::addItem(vfile *vf, bool isDummy, int idx, QVariant customData)
328
_itemStore << SortProps(vf, _viewProperties->sortColumn, _viewProperties, isDummy, !descending(), idx, customData);
329
_items << &_itemStore.last();
334
qStableSort(_items.begin(), _items.end(),
335
descending() ? _greaterThanFunc : _lessThanFunc);
338
int Sorter::insertIndex(vfile *vf, bool isDummy, QVariant customData)
340
SortProps props(vf, _viewProperties->sortColumn, _viewProperties, isDummy, !descending(), -1, customData);
341
const QVector<SortProps*>::iterator it =
342
qLowerBound(_items.begin(), _items.end(), &props,
343
descending() ? _greaterThanFunc : _lessThanFunc);
345
if(it != _items.end())
346
return _items.indexOf((*it));
348
return _items.count();
351
} // namespace KrSort