fix: Change the app order in Privacy and Security
Change the app order in Privacy and Security
Log: Change the app order in Privacy and Security pms: BUG-303417
Summary by Sourcery
Fix app ordering in Privacy and Security by categorizing names and inserting apps at the correct sorted position.
Bug Fixes:
- Prefix sort field with a category (digit, ASCII letter, or Chinese/other) before pinyin conversion to ensure correct ordering
- Insert new applications at the computed sorted position instead of always appending to the end
Reviewer's Guide
This PR refactors the app ordering mechanism in Privacy and Security by enhancing the sort field to include a category prefix (digits, letters, others) and updating the model insertion logic to maintain sorted order based on that sort key.
Class diagram for updated ApplicationItem and AppsModel
classDiagram
class ApplicationItem {
- QString m_name
- QString m_sortField
+ void onNameChanged(const QString &name)
+ QString sortField()
}
class AppsModel {
- QList<ApplicationItem*> m_appItems
+ void appendItem(ApplicationItem *appItem)
}
ApplicationItem <.. AppsModel : uses
Flow diagram for new app insertion logic in AppsModel
flowchart TD
A["New ApplicationItem created"] --> B["Calculate sortField (category + pinyin)"]
B --> C["Find insert position in m_appItems based on sortField"]
C --> D["Insert ApplicationItem at correct position"]
D --> E["App list remains sorted"]
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Enhanced application sort key generation with category prefix |
|
src/plugin-privacy/operation/applicationitem.cpp |
| Changed app list insertion to maintain sorted order by sortField |
|
src/plugin-privacy/operation/privacysecuritymodel.cpp |
Tips and commands
Interacting with Sourcery
-
Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
-
Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. -
Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. -
Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. -
Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. -
Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. -
Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
TAG Bot
New tag: 6.1.59 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #2843
TAG Bot
New tag: 6.1.60 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #2844
TAG Bot
New tag: 6.1.61 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #2854
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: caixr23, pengfeixx
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
TAG Bot
New tag: 6.1.62 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #2874
TAG Bot
New tag: 6.1.63 DISTRIBUTION: unstable Suggest: synchronizing this PR through rebase #2888
deepin pr auto review
我来对这段代码的修改进行审查:
- 代码逻辑改进:
- 在 ApplicationItem::onNameChanged() 中,新增了分类逻辑,将应用名按首字符分为数字(0)、字母(1)和其他(2)三类,这是一个合理的分类方式。
- 在 AppsModel::appendItem() 中,改为插入排序而不是简单的追加,这样可以保持列表的有序性。
- 代码质量改进:
- 变量命名清晰,如 category、insertPos 等都有明确的含义
- 代码结构清晰,逻辑分层合理
- 使用了 Qt 的标准命名规范
- 性能优化建议:
- 在 ApplicationItem::onNameChanged() 中,可以提前返回,避免不必要的转换:
if (m_name == name) {
return;
}
- 在 AppsModel::appendItem() 中,可以考虑使用二分查找来优化插入位置的查找,特别是当列表很大时:
int left = 0, right = m_appItems.size();
while (left < right) {
int mid = (left + right) / 2;
if (appItem->sortField() < m_appItems.at(mid)->sortField()) {
right = mid;
} else {
left = mid + 1;
}
}
insertPos = left;
- 安全性考虑:
- 代码中使用了 Qt 的字符串处理函数,这些函数都有良好的边界检查,安全性较好
- 建议在 ApplicationItem::onNameChanged() 中添加对空字符串的处理:
if (name.isEmpty()) {
return;
}
- 其他建议:
- 可以考虑将分类逻辑提取为一个单独的函数,提高代码的可维护性:
int getCategory(const QString& name) {
QString upperName = name.toUpper();
for (const QChar &ch : upperName) {
if (ch.isSpace()) continue;
if (ch.isDigit()) return 0;
if (ch.isLetter() && ch.unicode() < 128) return 1;
return 2;
}
return 2;
}
总体来说,这个修改是合理的,提高了应用列表的排序效果,但还可以在性能和代码组织方面做进一步优化。
/forcemerge
This pr force merged! (status: blocked)