forked from qt-creator/qt-creator
Sort projects by displayName in ProjectListWidget.
Change-Id: I5dac445c8868125ec7773479726d065f47e3c48f Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
committed by
Daniel Teske
parent
06010713e2
commit
27809bd748
@@ -47,6 +47,7 @@
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
#include <projectexplorer/deployconfiguration.h>
|
||||
#include <projectexplorer/projectmodels.h>
|
||||
#include <projectexplorer/runconfiguration.h>
|
||||
|
||||
#include <QTimer>
|
||||
@@ -82,6 +83,15 @@ static QIcon createCenteredIcon(const QIcon &icon, const QIcon &overlay)
|
||||
using namespace ProjectExplorer;
|
||||
using namespace ProjectExplorer::Internal;
|
||||
|
||||
static bool projectLesserThan(Project *p1, Project *p2)
|
||||
{
|
||||
int result = caseFriendlyCompare(p1->displayName(), p2->displayName());
|
||||
if (result != 0)
|
||||
return result < 0;
|
||||
else
|
||||
return p1 < p2;
|
||||
}
|
||||
|
||||
////////
|
||||
// TargetSelectorDelegate
|
||||
////////
|
||||
@@ -242,9 +252,10 @@ void ProjectListWidget::addProject(Project *project)
|
||||
int pos = 0;
|
||||
for (int i=0; i < count(); ++i) {
|
||||
Project *p = item(i)->data(Qt::UserRole).value<Project*>();
|
||||
QString itemSortName = fullName(p);
|
||||
if (itemSortName > sortName)
|
||||
if (projectLesserThan(project, p)) {
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool useFullName = false;
|
||||
@@ -319,8 +330,7 @@ void ProjectListWidget::projectDisplayNameChanged(Project *project)
|
||||
int pos = count();
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
Project *p = item(i)->data(Qt::UserRole).value<Project*>();
|
||||
QString itemSortName = fullName(p);
|
||||
if (itemSortName > sortName) {
|
||||
if (projectLesserThan(project, p)) {
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -54,14 +54,6 @@ 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
|
||||
@@ -77,7 +69,7 @@ bool sortNodes(Node *n1, Node *n2)
|
||||
const QString fileName1 = QFileInfo(file1->path()).fileName();
|
||||
const QString fileName2 = QFileInfo(file2->path()).fileName();
|
||||
|
||||
int result = fileNameCompare(fileName1, fileName2);
|
||||
int result = caseFriendlyCompare(fileName1, fileName2);
|
||||
if (result != 0)
|
||||
return result < 0;
|
||||
else
|
||||
@@ -97,7 +89,7 @@ bool sortNodes(Node *n1, Node *n2)
|
||||
ProjectNode *project1 = static_cast<ProjectNode*>(n1);
|
||||
ProjectNode *project2 = static_cast<ProjectNode*>(n2);
|
||||
|
||||
int result = fileNameCompare(project1->displayName(), project2->displayName());
|
||||
int result = caseFriendlyCompare(project1->displayName(), project2->displayName());
|
||||
if (result != 0)
|
||||
return result < 0;
|
||||
else
|
||||
@@ -114,7 +106,7 @@ bool sortNodes(Node *n1, Node *n2)
|
||||
FolderNode *folder1 = static_cast<FolderNode*>(n1);
|
||||
FolderNode *folder2 = static_cast<FolderNode*>(n2);
|
||||
|
||||
int result = fileNameCompare(folder1->path(), folder2->path());
|
||||
int result = caseFriendlyCompare(folder1->path(), folder2->path());
|
||||
if (result != 0)
|
||||
return result < 0;
|
||||
else
|
||||
@@ -134,11 +126,11 @@ bool sortNodes(Node *n1, Node *n2)
|
||||
const QString fileName1 = QFileInfo(filePath1).fileName();
|
||||
const QString fileName2 = QFileInfo(filePath2).fileName();
|
||||
|
||||
int result = fileNameCompare(fileName1, fileName2);
|
||||
int result = caseFriendlyCompare(fileName1, fileName2);
|
||||
if (result != 0) {
|
||||
return result < 0; // sort by filename
|
||||
} else {
|
||||
result = fileNameCompare(filePath1, filePath2);
|
||||
result = caseFriendlyCompare(filePath1, filePath2);
|
||||
if (result != 0) {
|
||||
return result < 0; // sort by filepath
|
||||
} else {
|
||||
@@ -825,3 +817,18 @@ void FlatModel::filesRemoved()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
|
||||
int caseFriendlyCompare(const QString &a, const QString &b)
|
||||
{
|
||||
int result = a.compare(b, Qt::CaseInsensitive);
|
||||
if (result != 0)
|
||||
return result;
|
||||
return a.compare(b, Qt::CaseSensitive);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,6 +122,8 @@ private:
|
||||
friend class FlatModelManager;
|
||||
};
|
||||
|
||||
int caseFriendlyCompare(const QString &a, const QString &b);
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user