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: [framework] improve appletitem management #2026

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions cmake/install_plugin_quick_module.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# Install all plugin qml component file to

# Install all plugin qml component file to ${DST_PATH}
function(INSTALL_PLUGIN_QUICK_MODULE DST_PATH)
file(GLOB_RECURSE QMLS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.qml")

if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
# Support relative path, work on build
file(GLOB_RECURSE QMLS
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.qml")
set(QML_BUILD_INSTALL_PATH ${PROJECT_BINARY_DIR}/../../${PROJECT_NAME})
EXECUTE_PROCESS(COMMAND mkdir -p ${QML_BUILD_INSTALL_PATH})
EXECUTE_PROCESS(COMMAND cp -f ${QMLS} ${QML_BUILD_INSTALL_PATH})
add_custom_target(${PROJECT_NAME}_QML_INSTALL ALL
COMMAND mkdir -p ${QML_BUILD_INSTALL_PATH}
COMMAND cp --parents -f ${QMLS} ${QML_BUILD_INSTALL_PATH}
COMMAND echo "Copy qml file to ${QML_BUILD_INSTALL_PATH}"
COMMENT "Run automatically for each build"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
)
message("--- Copy qml file to ${QML_BUILD_INSTALL_PATH}")

else()
file(GLOB_RECURSE QMLS
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.qml")
install(FILES ${QMLS} DESTINATION ${DST_PATH}/${PROJECT_NAME})
message("--- Copy qml file to ${DST_PATH}/${PROJECT_NAME}")
endif()
Expand Down
1 change: 1 addition & 0 deletions include/dfm-framework/lifecycle/pluginquickmetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class PluginQuickMetaDataCreator final
QT_BEGIN_NAMESPACE
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug, const DPF_NAMESPACE::PluginQuickMetaData &);
Q_CORE_EXPORT QDebug operator<<(QDebug, const DPF_NAMESPACE::PluginQuickMetaPtr &);
#endif // QT_NO_DEBUG_STREAM
QT_END_NAMESPACE

Expand Down
2 changes: 2 additions & 0 deletions include/dfm-gui/applet.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Applet : public QObject
void setComponentUrl(const QUrl &url);
Q_SIGNAL void componentUrlChanged(const QUrl &url);

void dumpAppletTree();

protected:
explicit Applet(AppletPrivate &dd, QObject *parent = nullptr);
QScopedPointer<AppletPrivate> dptr;
Expand Down
2 changes: 2 additions & 0 deletions include/dfm-gui/appletitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class AppletItem : public QQuickItem
Applet *applet() const;
void setApplet(Applet *applet);

bool isCreateComplete() const;

Q_INVOKABLE QQuickWindow *itemWindow() const;
Q_SIGNAL void itemWindowChanged(QQuickWindow *window);

Expand Down
4 changes: 2 additions & 2 deletions include/dfm-gui/windowhandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class QQuickWindow;
DFMGUI_BEGIN_NAMESPACE

class Panel;
class FileManagerWindowHandleData;
class WindowHandleData;

class WindowHandle
{
Expand All @@ -32,7 +32,7 @@ class WindowHandle

private:
Q_DISABLE_COPY(WindowHandle);
QScopedPointer<FileManagerWindowHandleData> data;
QScopedPointer<WindowHandleData> data;
};

using WindowHandlePtr = QSharedPointer<WindowHandle>;
Expand Down
2 changes: 1 addition & 1 deletion src/dfm-base/utils/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void onClipboardDataChanged()
return;
}
const QString &data = mimeData->data(kGnomeCopyKey);
const static QRegExp regCut("cut\nfile://"), regCopy("copy\nfile://");
const static QRegularExpression regCut("cut\nfile://"), regCopy("copy\nfile://");
if (data.contains(regCut)) {
clipboardAction = ClipBoard::kCutAction;
} else if (data.contains(regCopy)) {
Expand Down
25 changes: 17 additions & 8 deletions src/dfm-framework/lifecycle/pluginmetaobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,20 @@ Q_CORE_EXPORT QDebug operator<<(QDebug out, const DPF_NAMESPACE::PluginMetaObjec
}

/*!
* \brief 重定向全局Debug打印 PluginQuickInfo 对象的函数
* \brief operator <<
* 重定向全局Debug入口函数
* \param out
* \param pointer
* \return
*/
Q_CORE_EXPORT QDebug operator<<(QDebug out, const DPF_NAMESPACE::PluginMetaObjectPointer &pointer)
{
out << *pointer;
return out;
}

/*!
* \brief 重定向全局Debug打印 PluginQuickMetaData 对象的函数
*/
Q_CORE_EXPORT QDebug operator<<(QDebug out, const DPF_NAMESPACE::PluginQuickMetaData &quickMeta)
{
Expand All @@ -237,15 +250,11 @@ Q_CORE_EXPORT QDebug operator<<(QDebug out, const DPF_NAMESPACE::PluginQuickMeta
}

/*!
* \brief operator <<
* 重定向全局Debug入口函数
* \param out
* \param pointer
* \return
* \brief 重定向全局Debug打印 PluginQuickMetaPtr 的函数
*/
Q_CORE_EXPORT QDebug operator<<(QDebug out, const DPF_NAMESPACE::PluginMetaObjectPointer &pointer)
Q_CORE_EXPORT QDebug operator<<(QDebug out, const DPF_NAMESPACE::PluginQuickMetaPtr &quickMetaPtr)
{
out << *pointer;
out << *quickMetaPtr;
return out;
}

Expand Down
42 changes: 32 additions & 10 deletions src/dfm-gui/applet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <dfm-gui/applet.h>
#include <dfm-gui/containment.h>
#include "applet_p.h"
#include "containment_p.h"

#include <QJSEngine>

Expand All @@ -19,6 +20,7 @@ AppletPrivate::~AppletPrivate()
{
// 释放关联的 QQuickItem
if (rootObject && QJSEngine::CppOwnership == QJSEngine::objectOwnership(rootObject)) {
Q_ASSERT_X(rootObject->parent() == q_ptr, "AppletItem memory management", "Undefined behaviour, unmanaged QQuickItem");
rootObject->deleteLater();
}
}
Expand All @@ -34,6 +36,24 @@ void AppletPrivate::setRootObject(QObject *item)
Q_EMIT q_func()->rootObjectChanged(item);
}

/*!
* \brief 按层级递归打印当前 Applet 树信息
*/
void AppletPrivate::dumpAppletTreeImpl(int level)
{
QString indent = QString(' ').repeated(level * 4);
qCDebug(logDFMGui) << indent << metaPtr;

if (flag.testFlag(Applet::kContainment)) {
if (auto containment = dynamic_cast<ContainmentPrivate *>(this)) {
qCDebug(logDFMGui) << indent << QStringLiteral("Applet chiledren:");
for (Applet *child : containment->applets) {
child->dptr->dumpAppletTreeImpl(level + 1);
}
}
}
}

/*!
* \class Applet
* \brief 管理插件 QML 组件的最小单元,包含基础的组件信息.
Expand Down Expand Up @@ -94,22 +114,16 @@ QObject *Applet::rootObject() const
}

/*!
* \brief 返回当前 Applet 的容器 Containment , 若自身是容器则会返回当前对象
* \return 容器指针
* \brief 返回当前 Applet 的容器 Containment , 会递归向上查找
* \return 容器指针,若父对象没有容器,返回 nullptr
*/
Containment *Applet::containment() const
{
Containment *contain = qobject_cast<Containment *>(const_cast<Applet *>(this));
if (contain) {
return contain;
}
contain = nullptr;

Containment *contain = nullptr;
QObject *parent = this->parent();

while (parent) {
Containment *tmp = qobject_cast<Containment *>(parent);
if (tmp) {
if (Containment *tmp = qobject_cast<Containment *>(parent)) {
contain = tmp;
break;
}
Expand Down Expand Up @@ -155,4 +169,12 @@ void Applet::setComponentUrl(const QUrl &url)
}
}

/*!
* \brief 打印当前 Applet 树信息
*/
void Applet::dumpAppletTree()
{
d_func()->dumpAppletTreeImpl();
}

DFMGUI_END_NAMESPACE
1 change: 1 addition & 0 deletions src/dfm-gui/applet_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AppletPrivate
virtual ~AppletPrivate();

void setRootObject(QObject *item);
void dumpAppletTreeImpl(int level = 0);

Applet *q_ptr;
QUrl currentUrl; // 当前 Applet 操作的文件 Url
Expand Down
11 changes: 11 additions & 0 deletions src/dfm-gui/appletitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ void AppletItem::setApplet(Applet *applet)
d_func()->applet = applet;
}

/*!
* \return 返回当前 Item 是否被初始化完成,目前是对 QQuickItem::isComponentComplete
* 的封装,用于判断是否被 QQmlEngine 完成创建
*/
bool AppletItem::isCreateComplete() const
{
Q_D(const AppletItem);
return isComponentComplete() && d->applet;
}

/*!
* \return 当前 Item 所在的顶层窗体
*/
Expand Down Expand Up @@ -81,6 +91,7 @@ AppletItem *AppletItem::itemForApplet(Applet *applet)
QObject *rootObject = engine.rootObject();
if (rootObject) {
if (auto item = qobject_cast<AppletItem *>(rootObject)) {
item->setApplet(applet);
applet->dptr->setRootObject(item);
return item;
}
Expand Down
8 changes: 6 additions & 2 deletions src/dfm-gui/appletmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ Applet *AppletManagerPrivate::createAppletFromNode(const AppletTemplateNode::Ptr
}

if (applet->flags().testFlag(Applet::kContainment) && !node->childNode.isEmpty()) {
Containment *cotainment = applet->containment();
Containment *containment = qobject_cast<Containment *>(applet);
if (!containment) {
return nullptr;
}

for (auto childNode : std::as_const(node->childNode)) {
Applet *childApplet = createAppletFromNode(childNode, nullptr);
cotainment->appendApplet(childApplet);
containment->appendApplet(childApplet);
}
}

Expand Down
21 changes: 2 additions & 19 deletions src/dfm-gui/attachedproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ AppletAttached::~AppletAttached() { }

Applet *AppletAttached::qmlAttachedProperties(QObject *object)
{
AppletItem *item = qobject_cast<AppletItem *>(object);
if (item) {
return item->applet();
}
Applet *applet = qobject_cast<Applet *>(object);
if (applet) {
return applet;
}

QObject *parent = object->parent();
while (parent) {
if (auto parItem = qobject_cast<AppletItem *>(parent)) {
return parItem->applet();
}

parent = parent->parent();
}

if (auto context = qmlContext(object)) {
return context->contextProperty("_dfm_applet").value<Applet *>();
}
Expand All @@ -62,7 +44,8 @@ ContainmentAttached::~ContainmentAttached() { }

Containment *ContainmentAttached::qmlAttachedProperties(QObject *object)
{
return qobject_cast<Containment *>(AppletAttached::qmlAttachedProperties(object));
auto contain = qobject_cast<Containment *>(AppletAttached::qmlAttachedProperties(object));
return contain;
}

DFMGUI_END_NAMESPACE
8 changes: 4 additions & 4 deletions src/dfm-gui/windowhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

DFMGUI_BEGIN_NAMESPACE

class FileManagerWindowHandleData : public QSharedData
class WindowHandleData : public QSharedData
{
public:
QPointer<Panel> panel;
Expand All @@ -22,18 +22,18 @@ class FileManagerWindowHandleData : public QSharedData
* \brief 提供用于操作的窗口和Applet指针
*/
WindowHandle::WindowHandle()
: data(new FileManagerWindowHandleData)
: data(new WindowHandleData)
{
}

WindowHandle::WindowHandle(const QString &error)
: data(new FileManagerWindowHandleData)
: data(new WindowHandleData)
{
data->errorString = error;
}

WindowHandle::WindowHandle(Panel *p, QQuickWindow *w)
: data(new FileManagerWindowHandleData)
: data(new WindowHandleData)
{
data->panel = p;
data->window = w;
Expand Down
1 change: 1 addition & 0 deletions src/dfm-gui/windowmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void WindowManagerPrivate::asyncLoadQuickItem(Applet *applet)
tmpEngine->completeCreation();
QObject *rootObject = tmpEngine->rootObject();
if (AppletItem *item = qobject_cast<AppletItem *>(rootObject)) {
item->setApplet(applet);
applet->dptr->setRootObject(item);

if (auto containment = applet->containment()) {
Expand Down
11 changes: 3 additions & 8 deletions src/plugins/filemanager/core/dfmplugin-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ project(dfmplugin-core)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

FILE(GLOB CORE_FILES
FILE(GLOB_RECURSE CORE_FILES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.json"
"${CMAKE_CURRENT_SOURCE_DIR}/events/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/events/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/*.cpp"
)

"${CMAKE_CURRENT_SOURCE_DIR}/*.qml"
)

find_package(Dtk6 COMPONENTS Widget REQUIRED)

add_library(${PROJECT_NAME}
SHARED
${CORE_FILES}
FileWindow.qml
)

set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../../)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ project(dfmplugin-detailspace)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

FILE(GLOB DETAILSPCE_FILES
FILE(GLOB_RECURSE DETAILSPCE_FILES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"

"${CMAKE_CURRENT_SOURCE_DIR}/*/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/*/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.json"
)
"${CMAKE_CURRENT_SOURCE_DIR}/*.qml"
)

find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget REQUIRED)

add_library(${PROJECT_NAME}
SHARED
${DETAILSPCE_FILES}
DetailSpace.qml
)

set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../../)
Expand Down
Loading
Loading