Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/plugin-privacy/operation/applicationitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,24 @@ void ApplicationItem::onNameChanged(const QString &name)
return;
m_name = name;
// 不区分大小写,中文按拼音排序排后面
m_sortField = DTK_CORE_NAMESPACE::Chinese2Pinyin(m_name.toUpper());
QString upperName = m_name.toUpper();

int category = 2;
for (const QChar &ch : upperName) {
if (ch.isSpace())
continue;
if (ch.isDigit()) {
category = 0;
} else if (ch.isLetter() && ch.unicode() < 128) {
category = 1;
} else {
category = 2;
}
break;
}

QString pinyin = DTK_CORE_NAMESPACE::Chinese2Pinyin(upperName);
m_sortField = QString::number(category) + pinyin;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding a separator between category and pinyin for sortField.

Directly joining category and pinyin may cause ambiguity if pinyin begins with a digit. Adding a separator, such as an underscore, will clarify the sortField format.

Suggested change
m_sortField = QString::number(category) + pinyin;
m_sortField = QString::number(category) + "_" + pinyin;

emitDataChanged();
}

Expand Down
12 changes: 10 additions & 2 deletions src/plugin-privacy/operation/privacysecuritymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ void AppsModel::reset(ApplicationItemListPtr appList)

void AppsModel::appendItem(ApplicationItem *appItem)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_appItems.append(appItem);
int insertPos = m_appItems.size();
for (int i = 0; i < m_appItems.size(); ++i) {
if (appItem->sortField() < m_appItems.at(i)->sortField()) {
insertPos = i;
break;
}
}

beginInsertRows(QModelIndex(), insertPos, insertPos);
m_appItems.insert(insertPos, appItem);
endInsertRows();
}

Expand Down