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;
namespace {
// 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)
{
// Ordering is: project files, project, folder, file
......@@ -67,8 +76,9 @@ bool sortNodes(Node *n1, Node *n2)
const QString fileName1 = QFileInfo(file1->path()).fileName();
const QString fileName2 = QFileInfo(file2->path()).fileName();
if (fileName1 != fileName2)
return fileName1.compare(fileName2, Qt::CaseInsensitive) < 0;
int result = fileNameCompare(fileName1, fileName2);
if (result != 0)
return result;
else
return file1 < file2;
} else {
......@@ -86,8 +96,9 @@ bool sortNodes(Node *n1, Node *n2)
ProjectNode *project1 = static_cast<ProjectNode*>(n1);
ProjectNode *project2 = static_cast<ProjectNode*>(n2);
if (project1->displayName() != project2->displayName())
return project1->displayName().compare(project2->displayName(), Qt::CaseInsensitive) < 0; // sort by name
int result = fileNameCompare(project1->displayName(), project2->displayName());
if (result != 0)
return result;
else
return project1 < project2; // sort by pointer value
} else {
......@@ -102,8 +113,9 @@ bool sortNodes(Node *n1, Node *n2)
FolderNode *folder1 = static_cast<FolderNode*>(n1);
FolderNode *folder2 = static_cast<FolderNode*>(n2);
if (folder1->path() != folder2->path())
return folder1->path().compare(folder2->path(), Qt::CaseInsensitive) < 0;
int result = fileNameCompare(folder1->path(), folder2->path());
if (result != 0)
return result;
else
return folder1 < folder2;
} else {
......@@ -121,11 +133,13 @@ bool sortNodes(Node *n1, Node *n2)
const QString fileName1 = QFileInfo(filePath1).fileName();
const QString fileName2 = QFileInfo(filePath2).fileName();
if (fileName1 != fileName2) {
return fileName1.compare(fileName2, Qt::CaseInsensitive) < 0; // sort by file names
int result = fileNameCompare(fileName1, fileName2);
if (result != 0) {
return result; // sort by filename
} else {
if (filePath1 != filePath2) {
return filePath1.compare(filePath2, Qt::CaseInsensitive) < 0; // sort by path names
result = fileNameCompare(filePath1, filePath2);
if (result != 0) {
return result; // sort by filepath
} else {
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