UI: Programs: Improve sorting

This commit is contained in:
Nodir Temirkhodjaev 2024-01-17 13:24:05 +03:00
parent 118b431245
commit 51cd76d561
2 changed files with 15 additions and 6 deletions

View File

@ -428,15 +428,20 @@ QString AppListModel::sqlWhere() const
QString AppListModel::sqlOrderColumn() const
{
QString columnsStr;
bool orderApplied = false;
switch (sortColumn()) {
case 0: // Name
columnsStr = "t.name " + sqlOrderAsc() + ", t.path";
columnsStr = "t.name" + sqlOrderAsc() + ", t.path";
orderApplied = true;
break;
case 1: // Action
columnsStr = "alerted DESC, t.kill_process, t.blocked " + sqlOrderAsc() + ", t.app_id";
columnsStr = "alerted DESC, t.kill_process, t.blocked" + sqlOrderAsc() + ", t.name";
orderApplied = true;
break;
case 2: // Group
columnsStr = "group_index";
columnsStr = "group_index" + sqlOrderAsc() + ", t.name";
orderApplied = true;
break;
case 3: // File Path
columnsStr = "t.path";
@ -446,5 +451,9 @@ QString AppListModel::sqlOrderColumn() const
break;
}
if (!orderApplied) {
columnsStr += sqlOrderAsc();
}
return columnsStr;
}

View File

@ -68,17 +68,17 @@ QString TableSqlModel::sqlOrder() const
if (sortColumn() == -1)
return QString();
return QString(" ORDER BY %1 %2").arg(sqlOrderColumn(), sqlOrderAsc());
return " ORDER BY " + sqlOrderColumn();
}
QString TableSqlModel::sqlOrderAsc() const
{
return (sortOrder() == Qt::AscendingOrder) ? "ASC" : "DESC";
return (sortOrder() == Qt::AscendingOrder) ? " ASC" : " DESC";
}
QString TableSqlModel::sqlOrderColumn() const
{
return QString::number(sortColumn());
return QString::number(sortColumn()) + sqlOrderAsc();
}
QString TableSqlModel::sqlLimitOffset() const