Skip to content

feat: add qvariantToCmd helper function#114

Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:master
Jun 27, 2025
Merged

feat: add qvariantToCmd helper function#114
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Jun 27, 2025

  1. Added new helper function qvariantToCmd to properly format QVariant
    values for command line usage
  2. Modified context menu handling to use the new helper when copying
    values
  3. Ensures boolean and numeric values are copied without quotes while
    strings remain quoted
  4. Fixes issue where raw QVariant values could cause syntax errors in
    command usage

feat: 添加 qvariantToCmd 辅助函数

  1. 新增 qvariantToCmd 辅助函数,用于将 QVariant 值格式化为适合命令行使用
    的格式
  2. 修改上下文菜单处理逻辑,使用新辅助函数复制值
  3. 确保布尔值和数值不加引号复制,而字符串保持引号包裹
  4. 修复原始 QVariant 值可能导致命令语法错误的问题

Summary by Sourcery

Introduce qvariantToCmd helper to format QVariant values for command-line use and update context menu actions to use it, ensuring correct quoting behavior and preventing syntax errors.

New Features:

  • Add qvariantToCmd helper function for formatting QVariant values as command arguments.

Bug Fixes:

  • Fix syntax errors in command usage caused by raw QVariant values.

Enhancements:

  • Use qvariantToCmd in context menu copy actions to format values correctly based on type (booleans and numbers unquoted, strings quoted).

1. Added new helper function qvariantToCmd to properly format QVariant
values for command line usage
2. Modified context menu handling to use the new helper when copying
values
3. Ensures boolean and numeric values are copied without quotes while
strings remain quoted
4. Fixes issue where raw QVariant values could cause syntax errors in
command usage

feat: 添加 qvariantToCmd 辅助函数

1. 新增 qvariantToCmd 辅助函数,用于将 QVariant 值格式化为适合命令行使用
的格式
2. 修改上下文菜单处理逻辑,使用新辅助函数复制值
3. 确保布尔值和数值不加引号复制,而字符串保持引号包裹
4. 修复原始 QVariant 值可能导致命令语法错误的问题
@deepin-ci-robot
Copy link

deepin pr auto review

关键摘要:

  • qvariantToCmd 函数中使用了 QJsonValue::fromVariant,但未处理 QVariantQMetaType::User 类型的情况,可能会导致未预期的行为。
  • qvariantToCmd 函数中对于 jsonValue.isBool()jsonValue.isDouble() 的判断,可能需要考虑其他类型的 QVariant,例如 QVariant::String
  • Content::onCustomContextMenuRequested 函数中,value 变量被直接转换为 const QString &,这可能会导致潜在的内存泄漏,因为 value 是一个局部变量。
  • Content::onCustomContextMenuRequested 函数中,copyActiontriggered 信号连接使用了 lambda 表达式,但没有使用 std::move 来避免不必要的拷贝。

是否建议立即修改:

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 27, 2025

Reviewer's Guide

Introduces a "qvariantToCmd" helper to format QVariant values for shell commands—unquoted for booleans and numbers, quoted for strings—and updates context-menu copy actions to use it, thereby preventing syntax errors when copying raw QVariant values.

Sequence diagram for context menu copy value action update

sequenceDiagram
    actor User
    participant Content
    participant ValueHandler
    participant ConfigGetter
    participant QApplication
    participant QClipboard

    User->>Content: Right-click (custom context menu)
    Content->>ValueHandler: new ValueHandler(appid, resource, subpath)
    Content->>ConfigGetter: createManager()
    Content->>ConfigGetter: value(key)
    ConfigGetter-->>Content: QVariant value
    Content->>Helper: qvariantToCmd(QVariant value)
    Helper-->>Content: QString formattedValue
    Content->>QApplication: clipboard()
    Content->>QClipboard: setText(formattedValue) (on copy action)
Loading

Class diagram for qvariantToCmd helper addition

classDiagram
    class Helper {
        +static QString qvariantToCmd(const QVariant &v)
    }
    Helper : static QString qvariantToCmd(const QVariant &v)
    Helper : static QVariant stringToQVariant(const QString &s)
    Helper : static QStringList translationDirs()
Loading

File-Level Changes

Change Details Files
Add qvariantToCmd helper for CLI formatting of QVariant
  • Implement qvariantToCmd using qvariantToStringCompact and QJsonValue
  • Check for bool/double to determine quoting
  • Wrap non-numeric/non-boolean values in single quotes
dconfig-center/common/helper.hpp
Apply qvariantToCmd in context-menu copy logic
  • Replace direct toString() call with qvariantToCmd(manager.get()->value(key))
  • Adjust copyAction lambda to capture and copy formatted 'value' instead of 'key'
dconfig-center/dde-dconfig-editor/mainwindow.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on 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 issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on 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 dismiss on 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 review to 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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @18202781743 - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743 18202781743 merged commit f1be413 into linuxdeepin:master Jun 27, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants