Commit e6cdba31 authored by Volker Krause's avatar Volker Krause
Browse files

Access the owner JNI handle from property wrappers via a method

This matches the canonical interface all the QAndroidX types have in Qt.
parent 3a6a6f6b
......@@ -24,7 +24,8 @@ class TestClass : android::content::Intent
JNI_PROPERTY(int, myIntField)
JNI_PROPERTY(android::net::Uri, myUriField)
public:
inline QAndroidJniObject handle() const { return m_handle; }
private:
QAndroidJniObject m_handle;
};
......@@ -61,13 +62,13 @@ private Q_SLOTS:
const QAndroidJniObject bla = obj.myUriField;
obj.myUriField = bla;
QCOMPARE(obj.m_handle.protocol().size(), 6);
QCOMPARE(obj.m_handle.protocol().at(0), QLatin1String("getObjectField: myStringField Ljava/lang/String;"));
QCOMPARE(obj.m_handle.protocol().at(1), QLatin1String("setField: myStringField Ljava/lang/String;"));
QCOMPARE(obj.m_handle.protocol().at(2), QLatin1String("getField: myIntField I"));
QCOMPARE(obj.m_handle.protocol().at(3), QLatin1String("setField: myIntField I"));
QCOMPARE(obj.m_handle.protocol().at(4), QLatin1String("getObjectField: myUriField Landroid/net/Uri;"));
QCOMPARE(obj.m_handle.protocol().at(5), QLatin1String("setField: myUriField Landroid/net/Uri;"));
QCOMPARE(obj.handle().protocol().size(), 6);
QCOMPARE(obj.handle().protocol().at(0), QLatin1String("getObjectField: myStringField Ljava/lang/String;"));
QCOMPARE(obj.handle().protocol().at(1), QLatin1String("setField: myStringField Ljava/lang/String;"));
QCOMPARE(obj.handle().protocol().at(2), QLatin1String("getField: myIntField I"));
QCOMPARE(obj.handle().protocol().at(3), QLatin1String("setField: myIntField I"));
QCOMPARE(obj.handle().protocol().at(4), QLatin1String("getObjectField: myUriField Landroid/net/Uri;"));
QCOMPARE(obj.handle().protocol().at(5), QLatin1String("setField: myUriField Landroid/net/Uri;"));
#endif
}
};
......
......@@ -72,7 +72,7 @@ class PropertyBase {
protected:
inline QAndroidJniObject handle() const {
const auto owner = reinterpret_cast<const ClassType*>(reinterpret_cast<const char*>(this) - OffsetHolder::offset());
return owner->m_handle;
return owner->handle();
}
};
......@@ -167,6 +167,7 @@ public: \
private: \
struct _jni_ ## name ## __NameHolder { static constexpr const char* jniName() { return "" #name; } }; \
struct _jni_ ## name ## __OffsetHolder { static constexpr std::size_t offset() { return offsetof(_jni_ThisType, name); } }; \
friend class KAndroidExtras::Jni::PropertyBase<_jni_ThisType, _jni_ ## name ## __OffsetHolder>; \
public: \
[[no_unique_address]] Jni::Property<type, _jni_ThisType, _jni_ ## name ## __NameHolder, _jni_ ## name ## __OffsetHolder, Jni::is_basic_type<type>::value> name;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment