[Kde-bindings] playground/bindings/kimono
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Wed Jan 24 19:52:40 UTC 2007
SVN commit 626859 by rdale:
* Implemented callbacks to construct QVariants and to get values via
QVariant.FromValue() and QVariant.Value() when the type is greater
than QVariant::LastCoreType
CCMAIL: kde-bindings at kde.org
M +3 -0 ChangeLog
M +19 -0 core/QVariantExtras.cs
M +25 -0 qyoto.cpp
--- trunk/playground/bindings/kimono/ChangeLog #626858:626859
@@ -8,6 +8,9 @@
* The Enums in properties are now fully qualified with the classname
* Fixed up the code for the t11 example
* Added some more CMakeLists.txt files
+ * Implemented callbacks to construct QVariants and to get values via
+ QVariant.FromValue() and QVariant.Value() when the type is greater
+ than QVariant::LastCoreType
2007-22-01 Arno Rehn <arno at arnorehn.de>
--- trunk/playground/bindings/kimono/core/QVariantExtras.cs #626858:626859
@@ -4,9 +4,16 @@
using System.Collections;
using System.Collections.Generic;
using System.Text;
+ using System.Runtime.InteropServices;
public partial class QVariant : MarshalByRefObject, IDisposable {
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr QVariantValue(string typeName, IntPtr variant);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr QVariantFromValue(int type, IntPtr value);
+
public T Value<T>() {
if (typeof(T) == typeof(bool)) {
return (T) (object) ToBool();
@@ -55,6 +62,12 @@
} else if (typeof(T).IsEnum) {
return (T) (object) ToInt();
} else {
+ string typeName = typeof(T).ToString().Replace("Qyoto.", "");
+ if (NameToType(typeName) > E_Type.LastCoreType) {
+ IntPtr instancePtr = QVariantValue(typeName, (IntPtr) GCHandle.Alloc(this));
+ return (T) ((GCHandle) instancePtr).Target;
+ }
+
return (T) (object) default(T);
}
}
@@ -107,6 +120,12 @@
} else if (typeof(T).IsEnum) {
return new QVariant((int) value);
} else {
+ string typeName = typeof(T).ToString().Replace("Qyoto.", "");
+ if (NameToType(typeName) > E_Type.LastCoreType) {
+ IntPtr instancePtr = QVariantFromValue((int) NameToType(typeName), (IntPtr) GCHandle.Alloc(value));
+ return (QVariant) ((GCHandle) instancePtr).Target;
+ }
+
return new QVariant();
}
}
--- trunk/playground/bindings/kimono/qyoto.cpp #626858:626859
@@ -924,6 +924,31 @@
return -1;
}
+void *
+QVariantValue(char * typeName, void * variant)
+{
+ printf("ENTER QVariantValue(typeName: %s variant: 0x%8.8x)\n", typeName, variant);
+ smokeqyoto_object *o = value_obj_info(variant);
+ void * value = QMetaType::construct( QMetaType::type(typeName),
+ (void *) ((QVariant *)o->ptr)->constData() );
+ int id = o->smoke->idClass(typeName);
+ smokeqyoto_object * vo = alloc_smokeqyoto_object(true, o->smoke, id, (void *) value);
+ (*FreeGCHandle)(variant);
+ return set_obj_info((QString("Qyoto.") + typeName).toLatin1(), vo);
+}
+
+void *
+QVariantFromValue(int type, void * value)
+{
+ printf("ENTER QVariantFromValue(type: %d value: 0x%8.8x)\n", type, value);
+ smokeqyoto_object *o = value_obj_info(value);
+ QVariant * v = new QVariant(type, o->ptr);
+ int id = o->smoke->idClass("QVariant");
+ smokeqyoto_object * vo = alloc_smokeqyoto_object(true, o->smoke, id, (void *) v);
+ (*FreeGCHandle)(value);
+ return set_obj_info("Qyoto.QVariant", vo);
+}
+
void
InstallFreeGCHandle(FromIntPtr callback)
{
More information about the Kde-bindings
mailing list