aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qtquickview/basic/android/qml/testactivitycommunicator.cpp
blob: bba3cebc135c8a5ce58134c066f17d0e6425135d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "testactivitycommunicator.h"

using namespace QtJniTypes;

TestActivityCommunicator::TestActivityCommunicator(QObject *parent)
    : QObject{ parent },
      m_activity(TestActivity::callStaticMethod<TestActivity>("instance")),
      m_view(m_activity.callMethod<TestView>("testView"))
{
}

bool TestActivityCommunicator::getBoolProperty(const QString &name)
{
    return m_view.callMethod<Boolean>(getPropertyGetterName(name)).callMethod<bool>("booleanValue");
}

int TestActivityCommunicator::getIntProperty(const QString &name)
{
    return m_view.callMethod<Integer>(getPropertyGetterName(name)).callMethod<int>("intValue");
}

double TestActivityCommunicator::getDoubleProperty(const QString &name)
{
    return m_view.callMethod<Double>(getPropertyGetterName(name)).callMethod<double>("doubleValue");
}

QString TestActivityCommunicator::getStringProperty(const QString &name)
{
    return m_view.callMethod<String>(getPropertyGetterName(name)).toString();
}

void TestActivityCommunicator::setBoolProperty(const QString &name, bool value)
{
    m_view.callMethod<void>(getPropertySetterName(name), Boolean::construct(value));
}

void TestActivityCommunicator::setIntProperty(const QString &name, int value)
{
    m_view.callMethod<void>(getPropertySetterName(name), Integer::construct(value));
}

void TestActivityCommunicator::setDoubleProperty(const QString &name, double value)
{
    m_view.callMethod<void>(getPropertySetterName(name), Double::construct(value));
}

void TestActivityCommunicator::setStringProperty(const QString &name, const QString &value)
{
    m_view.callMethod<void>(getPropertySetterName(name), value);
}

QByteArray TestActivityCommunicator::getPropertyGetterName(const QString &name)
{
    return QByteArray("get") + name.at(0).toUpper().toLatin1() + name.mid(1).toLatin1();
}

QByteArray TestActivityCommunicator::getPropertySetterName(const QString &name)
{
    return QByteArray("set") + name.at(0).toUpper().toLatin1() + name.mid(1).toLatin1();
}