-
Notifications
You must be signed in to change notification settings - Fork 148
refactor: optimize plugin loading and QML registration #3136
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd. | ||
| // SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #ifndef DCCFACTORY_H | ||
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| namespace dccV25 { | ||
| #define DccFactory_iid "org.deepin.dde.dcc-factory/v1.0" | ||
| #define QML_ENGINE_PROPERTY "QmlEngin" | ||
| class DccObject; | ||
|
|
||
| class DccFactory : public QObject | ||
|
|
@@ -16,28 +17,36 @@ class DccFactory : public QObject | |
| public: | ||
| using QObject::QObject; | ||
|
|
||
| // 作为数据返回,会导出为dccData供main.qml使用 | ||
| // 作为数据返回,会导出为dccData供main.qml使用(在子线程执行) | ||
| virtual QObject *create(QObject * = nullptr) { return nullptr; } | ||
|
|
||
| // 未提供qml的,可在此自己加载qml返回DccObject对象 | ||
| virtual DccObject *dccObject(QObject * = nullptr) { return nullptr; } | ||
| // 未提供qml的,可在此自己加载qml返回DccObject对象,qml相关操作,如注册qml类型(在主线程中执行) | ||
| virtual QObject *dccObject(QObject * = nullptr) { return nullptr; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加个虚函数吧,在创建dccData之前,保证在主线程中被调用,这样代码也容易维护, |
||
| }; | ||
| } // namespace dccV25 | ||
| Q_DECLARE_INTERFACE(dccV25::DccFactory, DccFactory_iid) | ||
|
|
||
| #define DCC_FACTORY_CLASS(classname) \ | ||
| namespace { \ | ||
| class Q_DECL_EXPORT classname##DccFactory : public dccV25::DccFactory \ | ||
| { \ | ||
| Q_OBJECT \ | ||
| Q_PLUGIN_METADATA(IID DccFactory_iid) \ | ||
| Q_INTERFACES(dccV25::DccFactory) \ | ||
| public: \ | ||
| using dccV25::DccFactory::DccFactory; \ | ||
| QObject *create(QObject *parent = nullptr) override \ | ||
| { \ | ||
| return new classname(parent); \ | ||
| } \ | ||
| }; \ | ||
| #define DCC_FACTORY_CLASS(classname, ...) \ | ||
| namespace { \ | ||
| class classname##DccFactory : public dccV25::DccFactory \ | ||
| { \ | ||
| Q_OBJECT \ | ||
| Q_PLUGIN_METADATA(IID DccFactory_iid) \ | ||
| Q_INTERFACES(dccV25::DccFactory) \ | ||
| public: \ | ||
| using dccV25::DccFactory::DccFactory; \ | ||
| QObject *create(QObject *parent = nullptr) override \ | ||
|
Comment on lines
+29
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: The variadic macro relies on call sites passing Inside Suggested implementation: /*
* DCC_FACTORY_CLASS
*
* Variadic arguments (`__VA_ARGS__`) are intended to be *statements* terminated
* with semicolons. They are injected into an implementation lambda as a
* statement block. Do not rely on comma-expressions here; always write
* normal statements, e.g.:
*
* DCC_FACTORY_CLASS(Foo,
* auto w = new FooWidget(parent);
* configureFoo(w);
* return w;
* )
*/
#define DCC_FACTORY_CLASS(classname, ...) \
namespace { \
class classname##DccFactory : public dccV25::DccFactory \
{ \
Q_OBJECT \
Q_PLUGIN_METADATA(IID DccFactory_iid) \
Q_INTERFACES(dccV25::DccFactory) \
public: \
using dccV25::DccFactory::DccFactory; \
QObject *create(QObject *parent = nullptr) override \
{ \ QObject *create(QObject *parent = nullptr) override \
{ \
/* Ensure __VA_ARGS__ are always treated as a statement block */ \
do { __VA_ARGS__; } while (0); \I only see the beginning of the macro and not the full body. The intent is that wherever auto impl = [&]() {
do { __VA_ARGS__; } while (0);
};
return impl();so that the block form remains compatible. Please adjust the placement of the |
||
| { \ | ||
| return new classname(parent); \ | ||
| } \ | ||
| QObject *dccObject(QObject * = nullptr) override \ | ||
| { \ | ||
| auto executeQmlRegisters = []() { \ | ||
| __VA_ARGS__; \ | ||
| }; \ | ||
| executeQmlRegisters(); \ | ||
| return nullptr; \ | ||
| } \ | ||
| }; \ | ||
| } | ||
| #endif // DCCFACTORY_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): The QML_ENGINE_PROPERTY string looks misspelled, which risks mismatches wherever it is read.
The macro value is "QmlEngin" (missing the final 'e'). Any code expecting "QmlEngine" will fail to read this property. Please either correct the spelling or verify that all existing usages intentionally match this exact string.