diff options
Diffstat (limited to 'src/widgets/dialogs/qfilesystemmodel.cpp')
-rw-r--r-- | src/widgets/dialogs/qfilesystemmodel.cpp | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index 5446eca383..a7ae4b366b 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -48,6 +48,8 @@ #include <qmessagebox.h> #include <qapplication.h> +#include <algorithm> + #ifdef Q_OS_WIN # include <QtCore/QVarLengthArray> # include <qt_windows.h> @@ -127,7 +129,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn bool QFileSystemModel::rmdir(const QModelIndex &index) const + \fn bool QFileSystemModel::rmdir(const QModelIndex &index) Removes the directory corresponding to the model item \a index in the file system model and \b{deletes the corresponding directory from the @@ -183,7 +185,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn bool QFileSystemModel::remove(const QModelIndex &index) const + \fn bool QFileSystemModel::remove(const QModelIndex &index) Removes the model item \a index from the file system model and \b{deletes the corresponding file from the file system}, returning true if successful. If the @@ -195,7 +197,7 @@ QT_BEGIN_NAMESPACE \sa rmdir() */ -bool QFileSystemModel::remove(const QModelIndex &aindex) const +bool QFileSystemModel::remove(const QModelIndex &aindex) { //### TODO optim QString path = filePath(aindex); @@ -1081,15 +1083,35 @@ public: r->fileName, Qt::CaseInsensitive) < 0; } case 1: + { // Directories go first - if (l->isDir() && !r->isDir()) - return true; - return l->size() < r->size(); + bool left = l->isDir(); + bool right = r->isDir(); + if (left ^ right) + return left; + + qint64 sizeDifference = l->size() - r->size(); + if (sizeDifference == 0) + return QFileSystemModelPrivate::naturalCompare(l->fileName, r->fileName, Qt::CaseInsensitive) < 0; + + return sizeDifference < 0; + } case 2: - return l->type() < r->type(); + { + int compare = QString::localeAwareCompare(l->type(), r->type()); + if (compare == 0) + return QFileSystemModelPrivate::naturalCompare(l->fileName, r->fileName, Qt::CaseInsensitive) < 0; + + return compare < 0; + } case 3: + { + if (l->lastModified() == r->lastModified()) + return QFileSystemModelPrivate::naturalCompare(l->fileName, r->fileName, Qt::CaseInsensitive) < 0; + return l->lastModified() < r->lastModified(); } + } Q_ASSERT(false); return false; } @@ -1129,7 +1151,7 @@ void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent i++; } QFileSystemModelSorter ms(column); - qStableSort(values.begin(), values.end(), ms); + std::sort(values.begin(), values.end(), ms); // First update the new visible list indexNode->visibleChildren.clear(); //No more dirty item we reset our internal dirty index @@ -1631,7 +1653,7 @@ bool QFileSystemModel::event(QEvent *event) return QAbstractItemModel::event(event); } -bool QFileSystemModel::rmdir(const QModelIndex &aindex) const +bool QFileSystemModel::rmdir(const QModelIndex &aindex) { QString path = filePath(aindex); QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func()); @@ -1963,8 +1985,7 @@ bool QFileSystemModelPrivate::filtersAcceptsNode(const QFileSystemNode *node) co const bool hideDot = (filters & QDir::NoDot); const bool hideDotDot = (filters & QDir::NoDotDot); - // Note that we match the behavior of entryList and not QFileInfo on this and this - // incompatibility won't be fixed until Qt 5 at least + // Note that we match the behavior of entryList and not QFileInfo on this. bool isDot = (node->fileName == QLatin1String(".")); bool isDotDot = (node->fileName == QLatin1String("..")); if ( (hideHidden && !(isDot || isDotDot) && node->isHidden()) |