mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-09-17 11:37:10 +03:00
refactor(plasmaapi): use qobject ptr instead of jsvalue
This commit is contained in:
parent
78eff10512
commit
81fc2a0ab6
@ -11,12 +11,12 @@ namespace PlasmaApi
|
||||
{
|
||||
|
||||
PlasmaApi::PlasmaApi(QQmlEngine *engine)
|
||||
: m_engine(engine){};
|
||||
: m_engine(engine)
|
||||
, m_workspace(engine){};
|
||||
|
||||
Workspace PlasmaApi::workspace()
|
||||
Workspace &PlasmaApi::workspace()
|
||||
{
|
||||
auto evalResult = m_engine->globalObject().property("workspace");
|
||||
return Workspace(evalResult, m_engine);
|
||||
return m_workspace;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,10 +16,11 @@ namespace PlasmaApi
|
||||
struct PlasmaApi {
|
||||
explicit PlasmaApi(QQmlEngine *engine);
|
||||
|
||||
Workspace workspace();
|
||||
Workspace &workspace();
|
||||
|
||||
private:
|
||||
QQmlEngine *m_engine;
|
||||
Workspace m_workspace;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,16 +10,15 @@
|
||||
namespace PlasmaApi
|
||||
{
|
||||
|
||||
Workspace::Workspace(const QJSValue &jsRepr, QQmlEngine *engine)
|
||||
: m_jsRepr(jsRepr)
|
||||
, m_engine(engine)
|
||||
Workspace::Workspace(QQmlEngine *engine)
|
||||
: m_engine(engine)
|
||||
, m_kwinImpl(engine->globalObject().property("workspace").toQObject())
|
||||
{
|
||||
}
|
||||
|
||||
int Workspace::currentDesktop()
|
||||
{
|
||||
auto jsResult = m_jsRepr.property("currentDesktop");
|
||||
return jsResult.toInt();
|
||||
return m_kwinImpl->property("currentDesktop").toInt();
|
||||
}
|
||||
|
||||
namespace Test
|
||||
@ -29,6 +28,7 @@ TEST_CASE("Workspace Properties Read")
|
||||
{
|
||||
auto engine = QQmlEngine();
|
||||
auto mockWorkspace = MockWorkspaceJS();
|
||||
mockWorkspace.setCurrentDesktop(42);
|
||||
|
||||
engine.globalObject().setProperty(QStringLiteral("workspace"), engine.newQObject(&mockWorkspace));
|
||||
|
||||
|
@ -3,19 +3,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QJSValue>
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
|
||||
namespace PlasmaApi
|
||||
{
|
||||
struct Workspace {
|
||||
Workspace(const QJSValue &jsRepr, QQmlEngine *engine);
|
||||
Workspace(QQmlEngine *engine);
|
||||
|
||||
int currentDesktop();
|
||||
|
||||
private:
|
||||
QJSValue m_jsRepr;
|
||||
QQmlEngine *m_engine;
|
||||
QObject *m_kwinImpl;
|
||||
};
|
||||
|
||||
namespace Test
|
||||
@ -23,12 +23,19 @@ namespace Test
|
||||
class MockWorkspaceJS : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int currentDesktop READ currentDesktop)
|
||||
Q_PROPERTY(int currentDesktop READ currentDesktop WRITE setCurrentDesktop)
|
||||
public:
|
||||
int currentDesktop()
|
||||
{
|
||||
return 42;
|
||||
return m_currentDesktop;
|
||||
}
|
||||
|
||||
void setCurrentDesktop(int desktop)
|
||||
{
|
||||
m_currentDesktop = desktop;
|
||||
}
|
||||
|
||||
int m_currentDesktop{};
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user