components: Port Direction enum to c++ to improve load times

According to flame graph testing with qmlprofiler, this caused quite some overhead in QML.
This commit is contained in:
Devin Lin 2022-04-10 13:28:32 -04:00
parent 2d6d0c6789
commit 2deea1b4d0
7 changed files with 39 additions and 30 deletions

View file

@ -13,6 +13,7 @@ set(mobileshellplugin_SRCS
savedquicksettingsmodel.cpp savedquicksettingsmodel.cpp
shellutil.cpp shellutil.cpp
windowutil.cpp windowutil.cpp
components/direction.cpp
notifications/notificationthumbnailer.cpp notifications/notificationthumbnailer.cpp
notifications/notificationfilemenu.cpp notifications/notificationfilemenu.cpp
homescreen/applicationlistmodel.cpp homescreen/applicationlistmodel.cpp

View file

@ -0,0 +1,7 @@
/*
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "direction.h"

View file

@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QObject>
class Direction : public QObject
{
Q_OBJECT
public:
enum Type { None = 0, Up, Down, Left, Right };
Q_ENUM(Type)
};

View file

@ -9,6 +9,8 @@
#include <QQmlContext> #include <QQmlContext>
#include <QQuickItem> #include <QQuickItem>
#include "components/direction.h"
#include "notifications/notificationfilemenu.h" #include "notifications/notificationfilemenu.h"
#include "notifications/notificationthumbnailer.h" #include "notifications/notificationthumbnailer.h"
@ -48,8 +50,8 @@ void MobileShellPlugin::registerTypes(const char *uri)
return WindowUtil::instance(); return WindowUtil::instance();
}); });
// taskswitcher // components
qmlRegisterType<DisplaysModel>(uri, 1, 0, "DisplaysModel"); qmlRegisterType<Direction>(uri, 1, 0, "Direction");
// homescreen // homescreen
qmlRegisterSingletonType<ApplicationListModel>(uri, 1, 0, "ApplicationListModel", [](QQmlEngine *, QJSEngine *) -> QObject * { qmlRegisterSingletonType<ApplicationListModel>(uri, 1, 0, "ApplicationListModel", [](QQmlEngine *, QJSEngine *) -> QObject * {
@ -63,6 +65,9 @@ void MobileShellPlugin::registerTypes(const char *uri)
qmlRegisterType<NotificationThumbnailer>(uri, 1, 0, "NotificationThumbnailer"); qmlRegisterType<NotificationThumbnailer>(uri, 1, 0, "NotificationThumbnailer");
qmlRegisterType<NotificationFileMenu>(uri, 1, 0, "NotificationFileMenu"); qmlRegisterType<NotificationFileMenu>(uri, 1, 0, "NotificationFileMenu");
// taskswitcher
qmlRegisterType<DisplaysModel>(uri, 1, 0, "DisplaysModel");
// qml modules // qml modules
// /actiondrawer // /actiondrawer
@ -72,7 +77,6 @@ void MobileShellPlugin::registerTypes(const char *uri)
// /components // /components
qmlRegisterType(resolvePath("components/BaseItem.qml"), uri, 1, 0, "BaseItem"); 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/StartupFeedback.qml"), uri, 1, 0, "StartupFeedback");
qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator"); qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator");

View file

@ -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.nanoshell 2.0 as NanoShell
import org.kde.plasma.private.mobileshell 1.0 as MobileShell import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import "../components" as Components
Item { Item {
id: root id: root
@ -60,7 +58,7 @@ Item {
/** /**
* Direction the panel is currently moving in. * 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). * The mode of the action drawer (portrait or landscape).
@ -111,8 +109,8 @@ Item {
offset = 0; offset = 0;
} }
root.direction = (oldOffset === offset) root.direction = (oldOffset === offset)
? Components.Direction.None ? MobileShell.Direction.None
: (offset > oldOffset ? Components.Direction.Down : Components.Direction.Up); : (offset > oldOffset ? MobileShell.Direction.Down : MobileShell.Direction.Up);
oldOffset = offset; oldOffset = offset;
@ -152,7 +150,7 @@ Item {
// close immediately, so that we don't have to wait PlasmaCore.Units.longDuration // close immediately, so that we don't have to wait PlasmaCore.Units.longDuration
root.visible = false; root.visible = false;
close(); close();
} else if (root.direction === Components.Direction.None || !root.opened) { } else if (root.direction === MobileShell.Direction.None || !root.opened) {
if (root.offset < openThreshold) { if (root.offset < openThreshold) {
close(); close();
} else { } else {
@ -161,12 +159,12 @@ Item {
} else if (root.offset > contentContainerLoader.maximizedQuickSettingsOffset) { } else if (root.offset > contentContainerLoader.maximizedQuickSettingsOffset) {
expand(); expand();
} else if (root.offset > contentContainerLoader.minimizedQuickSettingsOffset) { } else if (root.offset > contentContainerLoader.minimizedQuickSettingsOffset) {
if (root.direction === Components.Direction.Down) { if (root.direction === MobileShell.Direction.Down) {
expand(); expand();
} else { } else {
open(); open();
} }
} else if (root.direction === Components.Direction.Down) { } else if (root.direction === MobileShell.Direction.Down) {
open(); open();
} else { } else {
close(); close();

View file

@ -1,18 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
QtObject {
enum Type {
None = 0,
Up,
Down,
Left,
Right
}
}

View file

@ -21,7 +21,6 @@
<file>qml/actiondrawer/PortraitContentContainer.qml</file> <file>qml/actiondrawer/PortraitContentContainer.qml</file>
<file>qml/components/BaseItem.qml</file> <file>qml/components/BaseItem.qml</file>
<file>qml/components/Direction.qml</file>
<file>qml/components/StartupFeedback.qml</file> <file>qml/components/StartupFeedback.qml</file>
<file>qml/components/util.js</file> <file>qml/components/util.js</file>
<file>qml/components/VelocityCalculator.qml</file> <file>qml/components/VelocityCalculator.qml</file>