[Kde-bindings] KDE/kdebindings/ruby/krossruby

Cyrille Berger cyb at lepi.org
Sun Jul 13 12:15:14 UTC 2008


SVN commit 831836 by berger:

add function to detect if a VALUE is Qt::Object, and then cast it into a QVariant

CCMAIL: kde-bindings at kde.org

 M  +13 -1     rubyvariant.cpp  


--- trunk/KDE/kdebindings/ruby/krossruby/rubyvariant.cpp #831835:831836
@@ -1,7 +1,7 @@
 /***************************************************************************
  * rubyvariant.cpp
  * This file is part of the KDE project
- * copyright (C)2005 by Cyrille Berger (cberger at cberger.net)
+ * copyright (C)2005,2008 by Cyrille Berger (cberger at cberger.net)
  * copyright (C)2006 by Sebastian Sauer (mail at dipe.org)
  *
  * This program is free software; you can redistribute it and/or
@@ -174,6 +174,18 @@
         case T_DATA: {
             RubyExtension* extension = RubyExtension::toExtension(value);
             if(! extension) {
+                VALUE qt_module = rb_define_module("Qt");
+                VALUE qt_base_class = rb_define_class_under(qt_module, "Base", rb_cObject);
+
+                if ( rb_funcall(value, rb_intern("kind_of?"), 1, qt_base_class) == Qtrue ) {
+                    VALUE value_methods = rb_funcall( value, rb_intern("methods"), 0);
+                    if( rb_funcall( value_methods, rb_intern("include?"), 1, rb_str_new2("metaObject") ) )
+                    { // Then it's a QtRuby object
+                      QObject** qobj = 0;
+                      Data_Get_Struct(value, QObject*, qobj);
+                      return qVariantFromValue( *qobj );
+                    }
+                }
                 #ifdef KROSS_RUBY_VARIANT_DEBUG
                     krosswarning("Cannot yet convert standard ruby type to Kross::RubyExtension object.");
                 #endif



More information about the Kde-bindings mailing list