Commit 216bdca7 authored by dt's avatar dt Committed by con

ProjectExplorer, FlatModel: Crash fix

sortNodes only ensured a partial ordering, we need a total ordering.

Reviewed-By: con

Task-Nr: QTCREATORBUG-3317
Task-Nr: QTCREATORBUG-3302
parent d2031d5c
...@@ -52,6 +52,15 @@ using Core::FileIconProvider; ...@@ -52,6 +52,15 @@ using Core::FileIconProvider;
namespace { namespace {
// sorting helper function // sorting helper function
int fileNameCompare(const QString &a, const QString &b)
{
int result = a.compare(b, Qt::CaseInsensitive);
if (result != 0)
return result;
return a.compare(b, Qt::CaseSensitive);
}
bool sortNodes(Node *n1, Node *n2) bool sortNodes(Node *n1, Node *n2)
{ {
// Ordering is: project files, project, folder, file // Ordering is: project files, project, folder, file
...@@ -67,8 +76,9 @@ bool sortNodes(Node *n1, Node *n2) ...@@ -67,8 +76,9 @@ bool sortNodes(Node *n1, Node *n2)
const QString fileName1 = QFileInfo(file1->path()).fileName(); const QString fileName1 = QFileInfo(file1->path()).fileName();
const QString fileName2 = QFileInfo(file2->path()).fileName(); const QString fileName2 = QFileInfo(file2->path()).fileName();
if (fileName1 != fileName2) int result = fileNameCompare(fileName1, fileName2);
return fileName1.compare(fileName2, Qt::CaseInsensitive) < 0; if (result != 0)
return result;
else else
return file1 < file2; return file1 < file2;
} else { } else {
...@@ -86,8 +96,9 @@ bool sortNodes(Node *n1, Node *n2) ...@@ -86,8 +96,9 @@ bool sortNodes(Node *n1, Node *n2)
ProjectNode *project1 = static_cast<ProjectNode*>(n1); ProjectNode *project1 = static_cast<ProjectNode*>(n1);
ProjectNode *project2 = static_cast<ProjectNode*>(n2); ProjectNode *project2 = static_cast<ProjectNode*>(n2);
if (project1->displayName() != project2->displayName()) int result = fileNameCompare(project1->displayName(), project2->displayName());
return project1->displayName().compare(project2->displayName(), Qt::CaseInsensitive) < 0; // sort by name if (result != 0)
return result;
else else
return project1 < project2; // sort by pointer value return project1 < project2; // sort by pointer value
} else { } else {
...@@ -102,8 +113,9 @@ bool sortNodes(Node *n1, Node *n2) ...@@ -102,8 +113,9 @@ bool sortNodes(Node *n1, Node *n2)
FolderNode *folder1 = static_cast<FolderNode*>(n1); FolderNode *folder1 = static_cast<FolderNode*>(n1);
FolderNode *folder2 = static_cast<FolderNode*>(n2); FolderNode *folder2 = static_cast<FolderNode*>(n2);
if (folder1->path() != folder2->path()) int result = fileNameCompare(folder1->path(), folder2->path());
return folder1->path().compare(folder2->path(), Qt::CaseInsensitive) < 0; if (result != 0)
return result;
else else
return folder1 < folder2; return folder1 < folder2;
} else { } else {
...@@ -121,11 +133,13 @@ bool sortNodes(Node *n1, Node *n2) ...@@ -121,11 +133,13 @@ bool sortNodes(Node *n1, Node *n2)
const QString fileName1 = QFileInfo(filePath1).fileName(); const QString fileName1 = QFileInfo(filePath1).fileName();
const QString fileName2 = QFileInfo(filePath2).fileName(); const QString fileName2 = QFileInfo(filePath2).fileName();
if (fileName1 != fileName2) { int result = fileNameCompare(fileName1, fileName2);
return fileName1.compare(fileName2, Qt::CaseInsensitive) < 0; // sort by file names if (result != 0) {
return result; // sort by filename
} else { } else {
if (filePath1 != filePath2) { result = fileNameCompare(filePath1, filePath2);
return filePath1.compare(filePath2, Qt::CaseInsensitive) < 0; // sort by path names if (result != 0) {
return result; // sort by filepath
} else { } else {
return n1 < n2; // sort by pointer value return n1 < n2; // sort by pointer value
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment