Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DPlatformTheme::property not work #219

Merged
merged 2 commits into from
Nov 8, 2023
Merged

fix: DPlatformTheme::property not work #219

merged 2 commits into from
Nov 8, 2023

Conversation

kegechen
Copy link
Contributor

@kegechen kegechen commented Nov 6, 2023

buildNativeSettings 之后 metaobject 被替换了
不会走原来的 read 方法了。
这里如果读取时 xsettings 中如果没有 fallback 到
base 对象的 read 方法

Issue: linuxdeepin/dtk#101

deepin-ci-robot added a commit to linuxdeepin/qt6platform-plugins that referenced this pull request Nov 6, 2023
Synchronize source files from linuxdeepin/qt5platform-plugins.

Source-pull-request: linuxdeepin/qt5platform-plugins#219
@kegechen kegechen marked this pull request as draft November 7, 2023 03:12
deepin-ci-robot added a commit to linuxdeepin/qt6platform-plugins that referenced this pull request Nov 7, 2023
Synchronize source files from linuxdeepin/qt5platform-plugins.

Source-pull-request: linuxdeepin/qt5platform-plugins#219
@kegechen kegechen marked this pull request as ready for review November 7, 2023 07:54
deepin-ci-robot added a commit to linuxdeepin/qt6platform-plugins that referenced this pull request Nov 7, 2023
Synchronize source files from linuxdeepin/qt5platform-plugins.

Source-pull-request: linuxdeepin/qt5platform-plugins#219
src/dnativesettings.cpp Outdated Show resolved Hide resolved
@@ -411,7 +411,7 @@ int DNativeSettings::metaCall(QMetaObject::Call _c, int _id, void ** _a)
const int index = p.propertyIndex();
// 对于本地属性,此处应该从m_settings中读写
if (Q_LIKELY(index != m_flagPropertyIndex && index != m_allKeysPropertyIndex
&& index >= m_firstProperty)) {
&& index >= m_firstProperty + m_propertyCount)) {
Copy link
Member

Choose a reason for hiding this comment

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

应该不会有这种低级错误才对,确定这里应该加上 m_propertyCount ?会不会导致原本应该从 m_settings 里读取的属性读不到了?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

问题说的就是调用属性的 read 方法 themeName 可以, 无法通过 property("themeName") 读取到正确的值。

QByteArray DPlatformTheme::themeName() const
{
//    FETCH_PROPERTY("Net/ThemeName", themeName)
    D_DC(DPlatformTheme);
    QVariant value = d->theme->getSetting(QByteArrayLiteral("Net/ThemeName"));
    if (d->fallbackProperty && !value.isValid() && d->parent)
        return d->parent->themeName();

    return value.toByteArray();
}

themeName() 会通过私有成员 d->theme ->getSetting 获取 xsettings 中的 Net/ThemeName,如果直接 property("themeName") 会到 xsettings 中去读 themeName 自然是读不到的无效值。

修改方案就是 如果是原来的属性就 fallback 到源对象的 read 方法,即 m_base->qt_metacall(_c, _id, _a);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
{
    Q_OBJECT
    Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
    Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName WRITE setApplicationDisplayName NOTIFY applicationDisplayNameChanged)
    Q_PROPERTY(QString desktopFileName READ desktopFileName WRITE setDesktopFileName)
    Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
    Q_PROPERTY(QString platformName READ platformName STORED false)
    Q_PROPERTY(bool quitOnLastWindowClosed  READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
    Q_PROPERTY(QScreen *primaryScreen READ primaryScreen NOTIFY primaryScreenChanged STORED false)
}
    const QMetaObject *metaObj = qGuiApp->metaObject();
    QMetaObjectBuilder ob;
    ob.addMetaObject(metaObj);
    int offset = metaObj->propertyOffset();
    int count = ob.propertyCount(); // metaObj->propertyCount();包含了 parent 的 property
    for (int i = offset; i < count + offset; ++i) {
        qInfo() << "[" << i << "]" << metaObj->property(i).name();
    }
[ 6 ] windowIcon
[ 7 ] applicationDisplayName
[ 8 ] desktopFileName
[ 9 ] layoutDirection
[ 10 ] platformName
[ 11 ] quitOnLastWindowClosed
[ 12 ] primaryScreen

deepin-ci-robot added a commit to linuxdeepin/qt6platform-plugins that referenced this pull request Nov 8, 2023
Synchronize source files from linuxdeepin/qt5platform-plugins.

Source-pull-request: linuxdeepin/qt5platform-plugins#219
18202781743
18202781743 previously approved these changes Nov 8, 2023
@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

src/dnativesettings.cpp Outdated Show resolved Hide resolved
 warning: comparison of different enumeration types in switch statement
 ('QVariant::Type' and 'QMetaType::Type')
buildNativeSettings 之后 metaobject 被替换了
不会走原来的 read 方法了。
读写属性时如果是 base 对象原始属性 fallback 到
base 对象的 qt_metacall  方法

Issue: linuxdeepin/dtk#101
deepin-ci-robot added a commit to linuxdeepin/qt6platform-plugins that referenced this pull request Nov 8, 2023
Synchronize source files from linuxdeepin/qt5platform-plugins.

Source-pull-request: linuxdeepin/qt5platform-plugins#219
@kegechen kegechen merged commit 1272c42 into master Nov 8, 2023
23 of 24 checks passed
@kegechen kegechen deleted the fix_101 branch November 8, 2023 03:35
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.

4 participants