[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/3.5/kdebindings/qtruby/rubylib/qtruby
From:       Richard Dale <Richard_Dale () tipitina ! demon ! co ! uk>
Date:       2005-10-05 14:20:19
Message-ID: 1128522019.636113.10048.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 467536 by rdale:

* Some fixes from the Qt4 version
* The Qt::ByteArray class is now a normal Smoke class, 
  rather than a special case, as it's easier to make a
  Qt::ByteArray look like a ruby String, than the other way
  round.
* The overloaded method resolution for enum arg types has been 
  improved
* Added missing relational operators to Qt::Integer



 M  +20 -6     Qt.cpp  
 M  +0 -61     handlers.cpp  
 MM            lib/Qt/qtruby.rb  


--- branches/KDE/3.5/kdebindings/qtruby/rubylib/qtruby/Qt.cpp #467535:467536
@@ -33,6 +33,7 @@
 #include <qcursor.h>
 #include <qobjectlist.h>
 #include <qsignalslotimp.h>
+#include <qcstring.h>
 
 #undef DEBUG
 #ifndef __USE_POSIX
@@ -917,8 +918,6 @@
 	r = "n";
     else if(TYPE(ruby_value) == T_STRING)
 	r = "s";
-    else if(strcmp(classname, "Qt::ByteArray") == 0)
-	r = "b";
     else if(ruby_value == Qtrue || ruby_value == Qfalse || strcmp(classname, \
"Qt::Boolean") == 0)  r = "B";
     else if(strcmp(classname, "Qt::Enum") == 0) {
@@ -1804,6 +1803,17 @@
 	}
 }
 
+static VALUE
+qbytearray_data(VALUE self)
+{
+	smokeruby_object *o = value_obj_info(self);
+	if (o == 0 || o->ptr == 0) {
+		return Qnil;
+	}
+	QByteArray * dataArray = (QByteArray*) o->ptr;
+	return rb_str_new(dataArray->data(), (long) dataArray->size());
+}
+
 static void
 mocargs_free(void * ptr)
 {
@@ -1883,10 +1893,12 @@
 {
     char *enumName = StringValuePtr(enumName_value);
     Smoke::Index typeId = qt_Smoke->idType(enumName);
-    Smoke::Index classId = qt_Smoke->idClass(enumName);
-	// If something is a smoke type but not a class it must be an enum.
-	// Note this is true iff this function is called from qtruby.rb/checkarg()
-	return (typeId > 0 && classId == 0 ? Qtrue : Qfalse);
+	return	typeId > 0 
+			&& (	(qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_enum
+					|| (qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_ulong
+					|| (qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_long
+					|| (qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_uint
+					|| (qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_int ) ? Qtrue : \
Qfalse;  }
 
 static VALUE
@@ -2521,6 +2533,8 @@
 
 	if (strcmp(package, "Qt::MetaObject") == 0) {
 		qt_qmetaobject_class = klass;
+	} else if (strcmp(package, "Qt::ByteArray") == 0) {
+		rb_define_method(klass, "data", (VALUE (*) (...)) qbytearray_data, 0);
 	} else if (strcmp(package, "Qt::Char") == 0) {
 		rb_define_method(klass, "to_s", (VALUE (*) (...)) qchar_to_s, 0);
 	}
--- branches/KDE/3.5/kdebindings/qtruby/rubylib/qtruby/handlers.cpp #467535:467536
@@ -894,65 +894,6 @@
 	return rstringFromQString(&s);
 }
 
-static void marshall_QByteArray(Marshall *m) {
-    switch(m->action()) {
-      case Marshall::FromVALUE:
-	{
-	    VALUE rv = *(m->var());
-	    QByteArray *s = 0;
-		VALUE data = Qnil;
-	    if(rv != Qnil) {
-			if (rb_respond_to(rv, rb_intern("data")) != 0) {
-				// Qt::ByteArray - use the contents of the 'data' instance var
-				data = rb_funcall(qt_internal_module, rb_intern("get_qbytearray"), 1, rv);
-				if (TYPE(data) == T_DATA) {
-					// A C++ QByteArray inside the Qt::ByteArray
-					Data_Get_Struct(data, QByteArray, s);
-				} else {
-					// Or a ruby String inside
-						s = new QByteArray(RSTRING(data)->len);
-						memcpy((void*)s->data(), StringValuePtr(data), RSTRING(data)->len);
-						VALUE data = Data_Wrap_Struct(rb_cObject, 0, 0, s);
-						rb_funcall(qt_internal_module, rb_intern("set_qbytearray"), 2, rv, data);
-				}
-			} else {
-				// Ordinary ruby String - use the contents of the string
-				s = new QByteArray(RSTRING(rv)->len);
-				memcpy((void*)s->data(), StringValuePtr(rv), RSTRING(rv)->len);
-			}
-        } else {
-			s = new QByteArray(0);
-	    }
-	    m->item().s_voidp = s;
-	    
-		m->next();
-	    
-		if(s && m->cleanup() && data == Qnil)
-		delete s;
-	}
-	break;
-      case Marshall::ToVALUE:
-	{
-		VALUE result;
-	    QByteArray *s = (QByteArray*)m->item().s_voidp;
-	    if(s) {
-			VALUE string = rb_str_new2("");
-			rb_str_cat(string, (const char *)s->data(), s->size());
-			result = rb_funcall(qt_internal_module, rb_intern("create_qbytearray"), 2, \
                string, Data_Wrap_Struct(rb_cObject, 0, 0, s));
-        } else {
-			result = Qnil;
-		}
-		*(m->var()) = result;
-	    if(m->cleanup())
-		delete s;
-	}
-	break;
-      default:
-	m->unsupported();
-	break;
-    }
-}
-
 #if 0
 static const char *not_ascii(const char *s, uint &len)
 {
@@ -1915,8 +1856,6 @@
     { "QUObject*", marshall_QUObject },
     { "const QCOORD*", marshall_QCOORD_array },
     { "void", marshall_void },
-    { "QByteArray", marshall_QByteArray },
-    { "QByteArray&", marshall_QByteArray },
     { "QValueList<int>", marshall_QValueListInt },
     { "QValueList<int>&", marshall_QValueListInt },
     { "QValueList<QVariant>", marshall_QVariantList },
** branches/KDE/3.5/kdebindings/qtruby/rubylib/qtruby/lib/Qt/qtruby.rb #property \
                svn:mime-type
   - application/x-ruby


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic