Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qandroidtypeconverter_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QANDROIDTYPECONVERTER_P_H
5#define QANDROIDTYPECONVERTER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16
17#include <QtQuick/private/qandroidtypes_p.h>
18#include <QtQuick/private/qandroiditemmodelproxy_p.h>
19
20#include <QtCore/qjniobject.h>
21#include <QtCore/qjnienvironment.h>
22#include <QtCore/qjnitypes.h>
23
25
27{
28 [[maybe_unused]] static QVariant toQVariant(const QJniObject &object)
29 {
30 using namespace QtJniTypes;
31 if (!object.isValid())
32 return QVariant{};
33 const QByteArray classname(object.className());
34
35 if (classname == Traits<String>::className())
36 return object.toString();
37 else if (classname == Traits<Integer>::className())
38 return object.callMethod<jint>("intValue");
39 else if (classname == Traits<Long>::className())
40 return QVariant::fromValue<long>(object.callMethod<jlong>("longValue"));
41 else if (classname == Traits<Double>::className())
42 return object.callMethod<jdouble>("doubleValue");
43 else if (classname == Traits<Float>::className())
44 return object.callMethod<jfloat>("floatValue");
45 else if (classname == Traits<Boolean>::className())
46 return QVariant::fromValue<bool>(object.callMethod<jboolean>("booleanValue"));
47 else {
49 const jclass className = env.findClass(Traits<JQtAbstractItemModel>::className());
50 if (env->IsInstanceOf(object.object(), className))
52 }
53
54 return QVariant{};
55 }
56
57 [[maybe_unused]] Q_REQUIRED_RESULT static jobject toJavaObject(const QVariant &var, JNIEnv *env)
58 {
59 Q_ASSERT(env);
60 switch (var.typeId()) {
61 case QMetaType::Type::Int:
62 return env->NewLocalRef(QJniObject::construct<QtJniTypes::Integer>(
63 get<int>(var))
64 .object());
65 case QMetaType::Type::Long:
66 case QMetaType::Type::LongLong:
67 return env->NewLocalRef(QJniObject::construct<QtJniTypes::Long>(
68 get<jlong>(var))
69 .object());
70 case QMetaType::Type::Double:
71 return env->NewLocalRef(QJniObject::construct<QtJniTypes::Double>(
72 get<double>(var))
73 .object());
74 case QMetaType::Type::Float:
75 return env->NewLocalRef(QJniObject::construct<QtJniTypes::Float>(
76 get<float>(var))
77 .object());
78 case QMetaType::Type::Bool:
79 return env->NewLocalRef(QJniObject::construct<QtJniTypes::Boolean>(
80 get<bool>(var))
81 .object());
82 case QMetaType::Type::QString:
83 return env->NewLocalRef(
84 QJniObject::fromString(get<QString>(var)).object());
85 default:
87 return env->NewLocalRef(
89 .object());
90 } else
91 return nullptr;
92 }
93 return nullptr;
94 }
95};
96
98
99#endif // QANDROIDTYPECONVERTER_P_H
static QJniObject createProxy(QAbstractItemModel *abstractClass)
static Q_REQUIRED_RESULT QAbstractItemModel * createNativeProxy(QJniObject itemModel)
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qvariant.h:65
T value() const &
Definition qvariant.h:517
int typeId() const
Returns the storage type of the value stored in the variant.
Definition qvariant.h:340
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:537
bool canConvert(QMetaType targetType) const
Definition qvariant.h:345
static QVariant toQVariant(const QJniObject &object)
static Q_REQUIRED_RESULT jobject toJavaObject(const QVariant &var, JNIEnv *env)
Combined button and popup list for selecting options.
#define Q_REQUIRED_RESULT
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
const char className[16]
[1]
Definition qwizard.cpp:99