From 2deea1b4d02e811c64e9d827e5c9336871ca3219 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Sun, 10 Apr 2022 13:28:32 -0400 Subject: [PATCH] components: Port Direction enum to c++ to improve load times According to flame graph testing with qmlprofiler, this caused quite some overhead in QML. --- components/mobileshell/CMakeLists.txt | 1 + .../mobileshell/components/direction.cpp | 7 +++++++ components/mobileshell/components/direction.h | 18 ++++++++++++++++++ components/mobileshell/mobileshellplugin.cpp | 10 +++++++--- .../qml/actiondrawer/ActionDrawer.qml | 14 ++++++-------- .../mobileshell/qml/components/Direction.qml | 18 ------------------ components/mobileshell/resources.qrc | 1 - 7 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 components/mobileshell/components/direction.cpp create mode 100644 components/mobileshell/components/direction.h delete mode 100644 components/mobileshell/qml/components/Direction.qml diff --git a/components/mobileshell/CMakeLists.txt b/components/mobileshell/CMakeLists.txt index d5d0af64..12bb431e 100644 --- a/components/mobileshell/CMakeLists.txt +++ b/components/mobileshell/CMakeLists.txt @@ -13,6 +13,7 @@ set(mobileshellplugin_SRCS savedquicksettingsmodel.cpp shellutil.cpp windowutil.cpp + components/direction.cpp notifications/notificationthumbnailer.cpp notifications/notificationfilemenu.cpp homescreen/applicationlistmodel.cpp diff --git a/components/mobileshell/components/direction.cpp b/components/mobileshell/components/direction.cpp new file mode 100644 index 00000000..d9ac1b27 --- /dev/null +++ b/components/mobileshell/components/direction.cpp @@ -0,0 +1,7 @@ +/* + * SPDX-FileCopyrightText: 2022 Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "direction.h" diff --git a/components/mobileshell/components/direction.h b/components/mobileshell/components/direction.h new file mode 100644 index 00000000..11375ce8 --- /dev/null +++ b/components/mobileshell/components/direction.h @@ -0,0 +1,18 @@ +/* + * SPDX-FileCopyrightText: 2022 Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#pragma once + +#include + +class Direction : public QObject +{ + Q_OBJECT + +public: + enum Type { None = 0, Up, Down, Left, Right }; + Q_ENUM(Type) +}; diff --git a/components/mobileshell/mobileshellplugin.cpp b/components/mobileshell/mobileshellplugin.cpp index 2545435e..d3444a45 100644 --- a/components/mobileshell/mobileshellplugin.cpp +++ b/components/mobileshell/mobileshellplugin.cpp @@ -9,6 +9,8 @@ #include #include +#include "components/direction.h" + #include "notifications/notificationfilemenu.h" #include "notifications/notificationthumbnailer.h" @@ -48,8 +50,8 @@ void MobileShellPlugin::registerTypes(const char *uri) return WindowUtil::instance(); }); - // taskswitcher - qmlRegisterType(uri, 1, 0, "DisplaysModel"); + // components + qmlRegisterType(uri, 1, 0, "Direction"); // homescreen qmlRegisterSingletonType(uri, 1, 0, "ApplicationListModel", [](QQmlEngine *, QJSEngine *) -> QObject * { @@ -63,6 +65,9 @@ void MobileShellPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 1, 0, "NotificationThumbnailer"); qmlRegisterType(uri, 1, 0, "NotificationFileMenu"); + // taskswitcher + qmlRegisterType(uri, 1, 0, "DisplaysModel"); + // qml modules // /actiondrawer @@ -72,7 +77,6 @@ void MobileShellPlugin::registerTypes(const char *uri) // /components qmlRegisterType(resolvePath("components/BaseItem.qml"), uri, 1, 0, "BaseItem"); - qmlRegisterType(resolvePath("components/Direction.qml"), uri, 1, 0, "Direction"); qmlRegisterType(resolvePath("components/StartupFeedback.qml"), uri, 1, 0, "StartupFeedback"); qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator"); diff --git a/components/mobileshell/qml/actiondrawer/ActionDrawer.qml b/components/mobileshell/qml/actiondrawer/ActionDrawer.qml index 034817ac..97adb547 100644 --- a/components/mobileshell/qml/actiondrawer/ActionDrawer.qml +++ b/components/mobileshell/qml/actiondrawer/ActionDrawer.qml @@ -15,8 +15,6 @@ import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.plasma.private.nanoshell 2.0 as NanoShell import org.kde.plasma.private.mobileshell 1.0 as MobileShell -import "../components" as Components - Item { id: root @@ -60,7 +58,7 @@ Item { /** * Direction the panel is currently moving in. */ - property int direction: Components.Direction.None + property int direction: MobileShell.Direction.None /** * The mode of the action drawer (portrait or landscape). @@ -111,8 +109,8 @@ Item { offset = 0; } root.direction = (oldOffset === offset) - ? Components.Direction.None - : (offset > oldOffset ? Components.Direction.Down : Components.Direction.Up); + ? MobileShell.Direction.None + : (offset > oldOffset ? MobileShell.Direction.Down : MobileShell.Direction.Up); oldOffset = offset; @@ -152,7 +150,7 @@ Item { // close immediately, so that we don't have to wait PlasmaCore.Units.longDuration root.visible = false; close(); - } else if (root.direction === Components.Direction.None || !root.opened) { + } else if (root.direction === MobileShell.Direction.None || !root.opened) { if (root.offset < openThreshold) { close(); } else { @@ -161,12 +159,12 @@ Item { } else if (root.offset > contentContainerLoader.maximizedQuickSettingsOffset) { expand(); } else if (root.offset > contentContainerLoader.minimizedQuickSettingsOffset) { - if (root.direction === Components.Direction.Down) { + if (root.direction === MobileShell.Direction.Down) { expand(); } else { open(); } - } else if (root.direction === Components.Direction.Down) { + } else if (root.direction === MobileShell.Direction.Down) { open(); } else { close(); diff --git a/components/mobileshell/qml/components/Direction.qml b/components/mobileshell/qml/components/Direction.qml deleted file mode 100644 index 64ae70bd..00000000 --- a/components/mobileshell/qml/components/Direction.qml +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021 Devin Lin - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -import QtQuick 2.15 - -QtObject { - enum Type { - None = 0, - Up, - Down, - Left, - Right - } -} - diff --git a/components/mobileshell/resources.qrc b/components/mobileshell/resources.qrc index db01c0cd..23a9f1e8 100644 --- a/components/mobileshell/resources.qrc +++ b/components/mobileshell/resources.qrc @@ -21,7 +21,6 @@ qml/actiondrawer/PortraitContentContainer.qml qml/components/BaseItem.qml - qml/components/Direction.qml qml/components/StartupFeedback.qml qml/components/util.js qml/components/VelocityCalculator.qml