fix(appdata):调整应用列表排序相同时,同一组的排序方式

This commit is contained in:
qiqi49 2024-10-30 16:05:43 +08:00 committed by iaom
parent df9a2c1820
commit 6dac5a3fc2
1 changed files with 8 additions and 11 deletions

View File

@ -87,23 +87,20 @@ bool AppCategoryModel::filterAcceptsRow(int source_row, const QModelIndex &sourc
bool AppCategoryModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const bool AppCategoryModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{ {
int result = 0; int result = 0;
if (m_mode == FirstLatter) { if (m_mode == Category) {
QString leftKey = AppCategoryModel::getFirstLatterUpper(source_left.data(DataEntity::FirstLetter).toString()); // 按功能分类进行排序
QString rightKey = AppCategoryModel::getFirstLatterUpper(source_right.data(DataEntity::FirstLetter).toString());
result = leftKey.compare(rightKey);
} else {
// 按分类进行排序
int leftIndex = getCategoryIndex(source_left.data(DataEntity::Category).toString()); int leftIndex = getCategoryIndex(source_left.data(DataEntity::Category).toString());
int rightIndex = getCategoryIndex(source_right.data(DataEntity::Category).toString()); int rightIndex = getCategoryIndex(source_right.data(DataEntity::Category).toString());
result = (leftIndex < rightIndex) ? -1 : (leftIndex > rightIndex) ? 1 : 0; result = (leftIndex < rightIndex) ? -1 : (leftIndex > rightIndex) ? 1 : 0;
} }
if (result == 0) { // 功能分类相同时,也按字母排序
// 分类相同时,按打开次数排序; model使用的升序排序为了保持使用次数多的在前所以此处使用 > 比较符, if ((result == 0) || (m_mode == FirstLatter)) {
return source_left.data(DataEntity::LaunchTimes).toInt() > source_right.data(DataEntity::LaunchTimes).toInt(); QString leftKey = source_left.data(DataEntity::FirstLetter).toString();
QString rightKey = source_right.data(DataEntity::FirstLetter).toString();
result = leftKey.compare(rightKey, Qt::CaseInsensitive);
} }
return result < 0; return result < 0;