X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f8d47e7e0416d4fd4e7c24e4b2de20ae43dab882..d05ffe96f986bcd33281cb5f97b73c1b4bf2b2ae:/src/kitemviews/kfileitemmodel.cpp diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 70e92eaac..163db8270 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,7 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) : KItemModelBase("name", parent), m_dirLister(dirLister), - m_naturalSorting(true), + m_naturalSorting(KGlobalSettings::naturalSorting()), m_sortFoldersFirst(true), m_sortRole(NameRole), m_roles(), @@ -63,7 +64,7 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) : Q_ASSERT(dirLister); connect(dirLister, SIGNAL(canceled()), this, SLOT(slotCanceled())); - connect(dirLister, SIGNAL(completed()), this, SLOT(slotCompleted())); + connect(dirLister, SIGNAL(completed(KUrl)), this, SLOT(slotCompleted())); connect(dirLister, SIGNAL(newItems(KFileItemList)), this, SLOT(slotNewItems(KFileItemList))); connect(dirLister, SIGNAL(itemsDeleted(KFileItemList)), this, SLOT(slotItemsDeleted(KFileItemList))); connect(dirLister, SIGNAL(refreshItems(QList >)), this, SLOT(slotRefreshItems(QList >))); @@ -95,6 +96,8 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) : connect(m_resortAllItemsTimer, SIGNAL(timeout()), this, SLOT(resortAllItems())); Q_ASSERT(m_minimumUpdateIntervalTimer->interval() <= m_maximumUpdateIntervalTimer->interval()); + + connect(KGlobalSettings::self(), SIGNAL(naturalSortingChanged()), this, SLOT(slotNaturalSortingChanged())); } KFileItemModel::~KFileItemModel() @@ -183,6 +186,20 @@ bool KFileItemModel::showHiddenFiles() const return dirLister ? dirLister->showingDotFiles() : false; } +void KFileItemModel::setShowFoldersOnly(bool enabled) +{ + KDirLister* dirLister = m_dirLister.data(); + if (dirLister) { + dirLister->setDirOnlyMode(enabled); + } +} + +bool KFileItemModel::showFoldersOnly() const +{ + KDirLister* dirLister = m_dirLister.data(); + return dirLister ? dirLister->dirOnlyMode() : false; +} + QMimeData* KFileItemModel::createMimeData(const QSet& indexes) const { QMimeData* data = new QMimeData(); @@ -367,6 +384,7 @@ void KFileItemModel::setRoles(const QSet& roles) } } + m_groups.clear(); resetRoles(); QSetIterator it(roles); @@ -467,7 +485,7 @@ void KFileItemModel::setExpanded(const QSet& urls) return; } - const int pos = dirLister->url().url().length(); + const int pos = dirLister->url().path().length(); // Assure that each sub-path of the URLs that should be // expanded is added to m_urlsToExpand too. KDirLister @@ -478,7 +496,7 @@ void KFileItemModel::setExpanded(const QSet& urls) const KUrl& url = it1.next(); KUrl urlToExpand = dirLister->url(); - const QStringList subDirs = url.url().mid(pos).split(QDir::separator()); + const QStringList subDirs = url.path().mid(pos).split(QDir::separator()); for (int i = 0; i < subDirs.count(); ++i) { urlToExpand.addPath(subDirs.at(i)); m_urlsToExpand.insert(urlToExpand); @@ -606,20 +624,19 @@ void KFileItemModel::resortAllItems() } // Determine the indexes that have been moved - bool emitItemsMoved = false; QList movedToIndexes; movedToIndexes.reserve(itemCount); for (int i = 0; i < itemCount; i++) { const int newIndex = m_items.value(oldUrls.at(i).url()); movedToIndexes.append(newIndex); - if (!emitItemsMoved && newIndex != i) { - emitItemsMoved = true; - } } - if (emitItemsMoved) { - emit itemsMoved(KItemRange(0, itemCount), movedToIndexes); - } + // Don't check whether items have really been moved and always emit a + // itemsMoved() signal after resorting: In case of grouped items + // the groups might change even if the items themselves don't change their + // 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(); @@ -848,6 +865,12 @@ void KFileItemModel::slotClear(const KUrl& url) Q_UNUSED(url); } +void KFileItemModel::slotNaturalSortingChanged() +{ + m_naturalSorting = KGlobalSettings::naturalSorting(); + resortAllItems(); +} + void KFileItemModel::dispatchPendingItemsToInsert() { if (!m_pendingItemsToInsert.isEmpty()) { @@ -1188,12 +1211,8 @@ QHash KFileItemModel::retrieveData(const KFileItem& item) if (forceRootExpansionLevel) { m_rootExpansionLevel = ForceRootExpansionLevel; } else { - const QString rootDir = rootUrl.directory(KUrl::AppendTrailingSlash); + const QString rootDir = rootUrl.path(KUrl::AddTrailingSlash); m_rootExpansionLevel = rootDir.count('/'); - if (m_rootExpansionLevel == 1) { - // Special case: The root is already reached and no parent is available - --m_rootExpansionLevel; - } } } @@ -1201,7 +1220,7 @@ QHash KFileItemModel::retrieveData(const KFileItem& item) data.insert("expansionLevel", -1); } else { const QString dir = item.url().directory(KUrl::AppendTrailingSlash); - const int level = dir.count('/') - m_rootExpansionLevel - 1; + const int level = dir.count('/') - m_rootExpansionLevel; data.insert("expansionLevel", level); } } @@ -1531,16 +1550,16 @@ int KFileItemModel::expansionLevelsCompare(const ItemData* a, const ItemData* b) // Compare the items of the parents that represent the first // different path after the common path. - const KUrl parentUrlA(pathA.left(index) + subPathA); - const KUrl parentUrlB(pathB.left(index) + subPathB); + const QString parentPathA = pathA.left(index) + subPathA; + const QString parentPathB = pathB.left(index) + subPathB; const ItemData* parentA = a; - while (parentA && parentA->item.url() != parentUrlA) { + while (parentA && parentA->item.url().path() != parentPathA) { parentA = parentA->parent; } const ItemData* parentB = b; - while (parentB && parentB->item.url() != parentUrlB) { + while (parentB && parentB->item.url().path() != parentPathB) { parentB = parentB->parent; } @@ -1845,12 +1864,12 @@ QList > KFileItemModel::ratingRoleGroups() const const int maxIndex = count() - 1; QList > groups; - int groupValue; + int groupValue = -1; for (int i = 0; i <= maxIndex; ++i) { if (isChildItem(i)) { continue; } - const int newGroupValue = m_itemData.at(i)->values.value("rating").toInt(); + const int newGroupValue = m_itemData.at(i)->values.value("rating", 0).toInt(); if (newGroupValue != groupValue) { groupValue = newGroupValue; groups.append(QPair(i, newGroupValue)); @@ -1867,15 +1886,17 @@ QList > KFileItemModel::genericStringRoleGroups(const QByte const int maxIndex = count() - 1; QList > groups; + bool isFirstGroupValue = true; QString groupValue; for (int i = 0; i <= maxIndex; ++i) { if (isChildItem(i)) { continue; } const QString newGroupValue = m_itemData.at(i)->values.value(role).toString(); - if (newGroupValue != groupValue) { + if (newGroupValue != groupValue || isFirstGroupValue) { groupValue = newGroupValue; groups.append(QPair(i, newGroupValue)); + isFirstGroupValue = false; } }