Skip to content

Conversation

@deepin-ci-robot
Copy link
Contributor

@deepin-ci-robot deepin-ci-robot commented Mar 6, 2025

Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#474

Summary by Sourcery

Refactors SettingsOption and SettingsGroup to use QObject instead of DConfigWrapper for configuration, improving flexibility. It also modifies the signal emission for value changes to include the new value.

Enhancements:

  • Refactor SettingsOption and SettingsGroup to use QObject instead of DConfigWrapper for configuration.
  • Modify the valueChanged signal to include the new value.
  • Add logging category for settings.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 6, 2025

Reviewer's Guide by Sourcery

This pull request synchronizes source files from linuxdeepin/dtkdeclarative. The key changes involve replacing DConfigWrapper with QObject for settings management, implementing signal connections for value changes, improving the resetValue function, adding a logging category, and refactoring value setting to emit the valueChanged signal only when the value has changed.

Sequence diagram for SettingsOption value change

sequenceDiagram
    participant User
    participant SettingsOption
    participant Config

    User->>SettingsOption: setValue(newValue)
    SettingsOption->>SettingsOption: setValue(newValue, updateConfig=true)
    alt updateConfig is true and m_config is not null
        SettingsOption->>Config: setProperty(key, newValue)
    end
    Config-->>SettingsOption: valueChanged(key, newValue)
    alt key == m_key and value.isValid()
        SettingsOption->>SettingsOption: setValue(value, updateConfig=false)
        SettingsOption-->>User: valueChanged(value)
    end
Loading

Sequence diagram for SettingsOption resetValue

sequenceDiagram
    participant User
    participant SettingsOption
    participant Config

    User->>SettingsOption: resetValue()
    SettingsOption->>SettingsOption: indexOfProperty(m_config, m_key)
    alt index >= 0
        SettingsOption->>Config: p.reset(m_config)
    else index < 0
        SettingsOption->>SettingsOption: qCWarning << "The key" << m_key << "not found in the Config object:" << m_config
    end
Loading

File-Level Changes

Change Details Files
Replaced DConfigWrapper with QObject for greater flexibility and compatibility.
  • Updated SettingsContainer::config() to return QObject* instead of DConfigWrapper*.
  • Updated SettingsContainer::setConfig() to accept QObject* instead of DConfigWrapper*.
  • Updated SettingsOption::setConfig() to accept QObject* instead of DConfigWrapper*.
  • Updated SettingsGroup::setConfig() to accept QObject* instead of DConfigWrapper*.
  • Modified SettingsOption to use QObject::property() and QObject::setProperty() for value access and modification.
  • Removed include of dconfigwrapper_p.h.
src/private/dsettingscontainer.cpp
src/private/dsettingscontainer_p.h
src/private/dsettingscontainer_p.h
src/private/dconfigwrapper.cpp
Implemented signal connection for value changes in SettingsOption when the property is not defined in QML.
  • Added a new slot SettingsOption::onValueChanged to handle the valueChanged signal from the config object.
  • Connected the valueChanged signal from DConfigWrapper to the onValueChanged slot in SettingsOption when the property is not defined in QML.
  • Added a check to ensure the signal connection is successful and log a warning if it fails.
src/private/dsettingscontainer.cpp
Improved SettingsOption::resetValue() to handle cases where the property is not resettable.
  • Added a check to ensure the property is resettable before attempting to reset it.
  • Added logging to provide warnings or debug information when the key is not found or cannot be reset.
src/private/dsettingscontainer.cpp
Added logging category for settings.
  • Added logging category dtk.dsg.settings.
src/private/dsettingscontainer.cpp
Refactor value setting in DConfigWrapper to emit valueChanged signal only when the value has changed.
  • Added a check to ensure the value has changed before emitting the valueChanged signal.
src/private/dconfigwrapper.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@deepin-ci-robot
Copy link
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

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

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 @deepin-ci-robot - I've reviewed your changes - here's some feedback:

Overall Comments:

  • It looks like DConfigWrapper is being replaced with QObject, which is a good change to reduce custom classes.
  • Consider using QMetaProperty::write instead of QObject::setProperty for better type safety.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

m_valueInitialized = true;
}
});
const auto ok = connect(m_config, SIGNAL(valueChanged(QString, QVariant)),
Copy link

Choose a reason for hiding this comment

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

suggestion: Using old signal-slot syntax.

Switching to the new function pointer based connection syntax could provide compile-time checking and improve code clarity.

Suggested implementation:

        const auto ok = connect(m_config, &Config::valueChanged,
                                this, &SettingsOption::onValueChanged);

If m_config is not of type Config*, replace "Config" in the new connection call with the appropriate class name that declares the valueChanged signal.

Q_EMIT valueChanged(value);
}

void SettingsOption::resetValue()
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the repeated meta-object handling and validity checks into helper functions to reduce nesting and improve readability without changing functionality.

Consider refactoring the repeated meta-object handling and validity checks into small helper functions. This will reduce nesting and condense the logic without changing functionality. For example:

static QVariant fetchValidProperty(QObject *config, const QString &key) {
    const auto value = config->property(key.toLocal8Bit());
    return value.isValid() ? value : QVariant{};
}

static bool resetConfigKey(QObject *config, const QString &key) {
    const int index = indexOfProperty(config, key);
    if (index < 0)
        return false;
    const auto mo = config->metaObject();
    QMetaProperty prop = mo->property(index);
    if (!prop.isResettable())
        return false;
    return prop.reset(config);
}

Then update your slot and reset methods:

void SettingsOption::onConfigValueChanged() {
    const auto value = fetchValidProperty(m_config, m_key);
    if (value.isValid()) {
        setValue(value, false);
        m_valueInitialized = true;
    }
}

void SettingsOption::resetValue() {
    if (!resetConfigKey(m_config, m_key)) {
        qCWarning(settingLog) << "Failed to reset the key" << m_key << "on Config object:" << m_config;
    }
}

This consolidates the logic into concise, reusable functions and reduces the complexity of your conditional branches.

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Mar 20, 2025

TAG Bot

New tag: 6.0.33
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #246

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Apr 17, 2025

TAG Bot

New tag: 6.0.34
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #250

Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#474
@deepin-ci-robot
Copy link
Contributor Author

deepin pr auto review

关键摘要:

  • SettingsDialog.qml文件中,config属性的类型从D.Config更改为QtObject,需要确认这一更改是否与整个项目的其他部分兼容。
  • dconfigwrapper.cpp文件中,callInGuiThread函数的lambda表达式增加了currentValue参数,但未在函数体内使用。如果不需要,应移除以简化代码。
  • dconfigwrapper.cpp文件中,wrapper->mo->setValue调用时使用了key.toLocal8Bit(),这可能会导致在非UTF-8编码的系统上出现问题。建议检查并确保键值是UTF-8编码的。
  • dsettingscontainer.cpp文件中,SettingsOption::setConfig函数中增加了对m_config的空指针检查,这是一个好的做法,可以避免潜在的空指针解引用问题。
  • dsettingscontainer.cpp文件中,SettingsOption::onValueChanged函数中增加了对value.isValid()的检查,这是一个好的做法,可以避免无效值被处理。
  • dsettingscontainer.cpp文件中,SettingsOption::resetValue函数中增加了对属性是否可重置的检查,这是一个好的做法,可以避免不必要的错误处理。
  • dsettingscontainer.cpp文件中,SettingsOption::resetValue函数中增加了对重置失败的日志记录,这有助于调试和问题追踪。
  • dsettingscontainer.cpp文件中,SettingsGroup::setConfig函数中增加了对子组的配置设置,这是一个好的做法,可以确保所有子组都正确配置。
  • dsettingscontainer_p.hdsettingscontainer.cpp文件中,config属性的类型从DConfigWrapper更改为QObject,需要确认这一更改是否与整个项目的其他部分兼容。

是否建议立即修改:

  • 确认类型更改是否兼容,并确保所有相关部分都已更新。
  • 移除不必要的参数currentValue以简化代码。
  • 确保键值是UTF-8编码的,以避免潜在的问题。
  • 增加对空指针和无效值的检查,以增强代码的健壮性。
  • 增加日志记录,以帮助调试和问题追踪。
  • 确保所有子组都正确配置,以保持设置的一致性。

@18202781743 18202781743 merged commit f3b2241 into master Apr 25, 2025
12 of 14 checks passed
@18202781743 18202781743 deleted the sync-pr-474-nosync branch April 25, 2025 03:30
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