m_maximumUpdateIntervalTimer->setInterval(2000);
m_maximumUpdateIntervalTimer->setSingleShot(true);
connect(m_maximumUpdateIntervalTimer, SIGNAL(timeout()), this, SLOT(dispatchPendingItemsToInsert()));
-
+
// When changing the value of an item which represents the sort-role a resorting must be
// triggered. Especially in combination with KFileItemModelRolesUpdater this might be done
// for a lot of items within a quite small timeslot. To prevent expensive resortings the
connect(m_resortAllItemsTimer, SIGNAL(timeout()), this, SLOT(resortAllItems()));
Q_ASSERT(m_minimumUpdateIntervalTimer->interval() <= m_maximumUpdateIntervalTimer->interval());
-
+
connect(KGlobalSettings::self(), SIGNAL(naturalSortingChanged()), this, SLOT(slotNaturalSortingChanged()));
}
if (changedRoles.contains(sortRole())) {
m_resortAllItemsTimer->start();
}
-
+
return true;
}
{
Q_UNUSED(current);
Q_UNUSED(previous);
- resortAllItems();
+ resortAllItems();
}
void KFileItemModel::resortAllItems()
{
m_resortAllItemsTimer->stop();
-
+
const int itemCount = count();
if (itemCount <= 0) {
return;
foreach (const ItemData* itemData, m_itemData) {
oldUrls.append(itemData->item.url());
}
-
+
m_groups.clear();
m_items.clear();
-
+
// Resort the items
- sort(m_itemData.begin(), m_itemData.end());
+ sort(m_itemData.begin(), m_itemData.end());
for (int i = 0; i < itemCount; ++i) {
m_items.insert(m_itemData.at(i)->item.url(), i);
}
-
+
// Determine the indexes that have been moved
QList<int> movedToIndexes;
movedToIndexes.reserve(itemCount);
for (int i = 0; i < itemCount; i++) {
const int newIndex = m_items.value(oldUrls.at(i).url());
movedToIndexes.append(newIndex);
- }
+ }
// Don't check whether items have really been moved and always emit a
// itemsMoved() signal after resorting: In case of grouped items
// position. Let the receiver of the signal decide whether a check for moved
// items makes sense.
emit itemsMoved(KItemRange(0, itemCount), movedToIndexes);
-
+
#ifdef KFILEITEMMODEL_DEBUG
kDebug() << "[TIME] Resorting of" << itemCount << "items:" << timer.elapsed();
-#endif
+#endif
}
void KFileItemModel::slotCompleted()
// Insert item at the position targetIndex by transfering
// the ownership of the item-data from sortedItems to m_itemData.
// m_items will be inserted after the loop (see comment below)
- m_itemData.insert(targetIndex, sortedItems.at(sourceIndex));
+ m_itemData.insert(targetIndex, sortedItems.at(sourceIndex));
++insertedCount;
if (insertedAtIndex < 0) {
int targetIndex = 0;
foreach (const ItemData* itemData, sortedItems) {
const KFileItem& itemToRemove = itemData->item;
-
+
const int previousTargetIndex = targetIndex;
while (targetIndex < m_itemData.count()) {
if (m_itemData.at(targetIndex)->item.url() == itemToRemove.url()) {
itemDataList.append(itemData);
}
-
+
return itemDataList;
}
}
QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item) const
-{
+{
// It is important to insert only roles that are fast to retrieve. E.g.
// KFileItem::iconName() can be very expensive if the MIME-type is unknown
// and hence will be retrieved asynchronously by KFileItemModelRolesUpdater.
case NameRole:
// The name role is handled as default fallback after the switch
break;
-
+
case SizeRole: {
if (itemA.isDir()) {
// See "if (m_sortFoldersFirst || m_sortRole == SizeRole)" in KFileItemModel::lessThan():
}
break;
}
-
+
case RatingRole: {
result = a->values.value("rating").toInt() - b->values.value("rating").toInt();
break;
}
-
+
case PermissionsRole:
case OwnerRole:
case GroupRole:
b->values.value(role).toString());
break;
}
-
+
default:
break;
}
void KFileItemModel::sort(QList<ItemData*>::iterator begin,
QList<ItemData*>::iterator end)
-{
+{
// The implementation is based on qStableSortHelper() from qalgorithms.h
// Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
// In opposite to qStableSort() it allows to use a member-function for the comparison of elements.
-
+
const int span = end - begin;
if (span < 2) {
return;
}
-
+
const QList<ItemData*>::iterator middle = begin + span / 2;
sort(begin, middle);
sort(middle, end);
{
// The implementation is based on qMerge() from qalgorithms.h
// Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-
+
const int len1 = pivot - begin;
const int len2 = end - pivot;
-
+
if (len1 == 0 || len2 == 0) {
return;
}
-
+
if (len1 + len2 == 2) {
if (lessThan(*(begin + 1), *(begin))) {
qSwap(*begin, *(begin + 1));
}
return;
}
-
+
QList<ItemData*>::iterator firstCut;
QList<ItemData*>::iterator secondCut;
int len2Half;
secondCut = pivot + len2Half;
firstCut = upperBound(begin, pivot, *secondCut);
}
-
+
reverse(firstCut, pivot);
reverse(pivot, secondCut);
reverse(firstCut, secondCut);
-
+
const QList<ItemData*>::iterator newPivot = firstCut + len2Half;
merge(begin, firstCut, newPivot);
merge(newPivot, secondCut, end);
{
// The implementation is based on qLowerBound() from qalgorithms.h
// Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-
+
QList<ItemData*>::iterator middle;
int n = int(end - begin);
int half;
{
// The implementation is based on qUpperBound() from qalgorithms.h
// Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-
+
QList<ItemData*>::iterator middle;
int n = end - begin;
int half;
{
// The implementation is based on qReverse() from qalgorithms.h
// Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-
+
--end;
while (begin < end) {
qSwap(*begin++, *end--);
- }
+ }
}
int KFileItemModel::stringCompare(const QString& a, const QString& b) const