~ubuntu-branches/ubuntu/trusty/krusader/trusty

« back to all changes in this revision

Viewing changes to krusader/Panel/krsort.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-08-08 13:47:36 UTC
  • mfrom: (1.2.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20110808134736-8e630ivgd2c3sgg5
Tags: 1:2.4.0~beta1-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
namespace KrSort {
27
27
 
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) {
29
29
    _col = col;
30
30
    _prop = props;
31
31
    _isdummy = isDummy;
33
33
    _vfile = vf;
34
34
    _index = origNdx;
35
35
    _name = vf->vfile_getName();
 
36
    _customData = customData;
36
37
 
37
38
    if(_prop->sortOptions & KrViewProperties::IgnoreCase)
38
39
        _name = _name.toLower();
107
108
}
108
109
 
109
110
 
110
 
 
111
111
// compares numbers within two strings
112
112
int compareNumbers(QString& aS1, int& aPos1, QString& aS2, int& aPos2)
113
113
{
130
130
    return res;
131
131
}
132
132
 
133
 
 
134
133
bool compareTextsAlphabetical(QString& aS1, QString& aS2, const KrViewProperties * _viewProperties, bool aNumbers)
135
134
{
136
135
    int lPositionS1 = 0;
314
313
                descending ? &itemGreaterThan : &itemLessThan);
315
314
}
316
315
 
317
 
QVector<KrSort::SortProps*>::iterator lowerBound(QVector<SortProps*> &sorting, SortProps *item, bool descending)
318
 
{
319
 
    return qLowerBound(sorting.begin(), sorting.end(), item,
320
 
                        descending ? &itemGreaterThan : &itemLessThan);
321
 
}
322
 
 
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)
 
321
 {
 
322
    _items.reserve(reserveItems);
 
323
    _itemStore.reserve(reserveItems);
 
324
 }
 
325
 
 
326
void Sorter::addItem(vfile *vf, bool isDummy, int idx, QVariant customData)
 
327
{
 
328
    _itemStore << SortProps(vf, _viewProperties->sortColumn, _viewProperties, isDummy, !descending(), idx, customData);
 
329
    _items << &_itemStore.last();
 
330
}
 
331
 
 
332
void Sorter::sort()
 
333
{
 
334
    qStableSort(_items.begin(), _items.end(),
 
335
                descending() ? _greaterThanFunc : _lessThanFunc);
 
336
}
 
337
 
 
338
int Sorter::insertIndex(vfile *vf, bool isDummy, QVariant customData)
 
339
{
 
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);
 
344
 
 
345
    if(it != _items.end())
 
346
         return _items.indexOf((*it));
 
347
    else
 
348
        return _items.count();
 
349
}
 
350
 
 
351
} // namespace KrSort