[Kde-bindings] KDE/kdebindings/php/phpqt

Thomas Moenicke tm at php-qt.org
Tue Nov 11 23:52:58 UTC 2008


SVN commit 883060 by moenicke:

* added a global function qstatic_cast that can be used to force a cast to a child class
* fixed eventFilter in the calculator example with casting the event to the right type

Thanks hardcorelamer.

CCMAIL: kde-bindings at kde.org



 M  +3 -3      examples/calculator/calculator.php  
 M  +30 -0     src/functions.cpp  
 M  +6 -5      src/php_qt.cpp  
 M  +1 -0      src/zend_extension.h  


--- trunk/KDE/kdebindings/php/phpqt/examples/calculator/calculator.php #883059:883060
@@ -156,8 +156,8 @@
                     || $event->type() == QEvent::MouseButtonRelease
                     || $event->type() == QEvent::ContextMenu) {
 
-                    $mouseEvent = $event;
-                    if ($mouseEvent->buttons() & Qt::LeftButton) {
+                    qstatic_cast( $event, "QMouseEvent");
+                    if ($event->buttons() & Qt::LeftButton) {
                         $newPalette = $this->palette();
                         $newPalette->setColor(QPalette::Base,
                             $this->display->palette()->color(QPalette::Text));
@@ -165,7 +165,7 @@
                             $this->display->palette()->color(QPalette::Base));
                         $this->display->setPalette($newPalette);
                     } else {
-                        $this->display->setPalette($palette());
+                        $this->display->setPalette($this->palette());
                     }
                     return true;
                 }
--- trunk/KDE/kdebindings/php/phpqt/src/functions.cpp #883059:883060
@@ -840,3 +840,33 @@
     TestPHPQt test( PQ::binding(), *args[0] );
     QTest::qExec( &test );
 }
+
+/**
+ * required to down cast some objects to known sub-classes
+ */
+extern "C" PHP_FUNCTION(qstatic_cast)
+{
+  Q_UNUSED(return_value_ptr);
+  Q_UNUSED(this_ptr);
+  Q_UNUSED(return_value_used);
+  Q_UNUSED(return_value);
+
+  zval *obj;
+  zval *z_cast_type;
+
+  if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &obj, &z_cast_type) == FAILURE) {
+    php_error(E_WARNING,"error while casting object, wrong parameters");
+    return;
+  }
+  zend_class_entry **cast_ce;
+  char *lowercase_name = zend_str_tolower_dup( z_cast_type->value.str.val, z_cast_type->value.str.len );
+
+  if (zend_hash_find(EG(class_table), lowercase_name, strlen(lowercase_name)+1, (void **) &cast_ce)==FAILURE) {
+    php_error(E_ERROR, "cannot find class for request cast of type %s ", lowercase_name );
+  }
+
+  zend_object *zobj;
+  zobj = zend_objects_get_address(obj TSRMLS_CC);
+  zobj->ce = *cast_ce;
+  return;
+}
--- trunk/KDE/kdebindings/php/phpqt/src/php_qt.cpp #883059:883060
@@ -102,6 +102,7 @@
 	PHP_FE(tr,	NULL)
 	PHP_FE(check_qobject,	NULL)
 	PHP_FE(Q_UNUSED,	NULL)
+	PHP_FE(qstatic_cast,    NULL)
 	PHP_FE(__phpqt_unittest_invoke,  NULL)
 	{NULL, NULL, NULL}	/* Must be the last line in php_qt_functions[] */
 };
@@ -396,10 +397,10 @@
 
     	// register zend class
     	zend_class_entry ce;
-    	INIT_CLASS_ENTRY( ce, PQ::smoke()->classes[i].className, p );
+	INIT_CLASS_ENTRY( ce, PQ::smoke()->classes[i].className, p );
     	ce.name_length = strlen( PQ::smoke()->classes[i].className );
     	zend_class_entry* ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
-    	tmpCeTable[ PQ::smoke()->classes[i].className ] = ce_ptr;
+	tmpCeTable[ PQ::smoke()->classes[i].className ] = ce_ptr;
 
     	if(cachedQObjectSmokeId == i) // cache
     		qobject_ce = ce_ptr;
@@ -407,11 +408,11 @@
 
     // do inheritance, all classes must be defined before
     for( Smoke::Index i=1; i < PQ::smoke()->numClasses; i++ ) {
-        zend_class_entry* ce = tmpCeTable[ PQ::smoke()->classes[i].className ];
+      zend_class_entry* ce = tmpCeTable[ PQ::smoke()->classes[i].className ];
         for( Smoke::Index *p = PQ::smoke()->inheritanceList + PQ::smoke()->classes[i].parents; *p; p++ ) {
             if( PQ::smoke()->classes[*p].className != 0 ) {
-                zend_class_entry *parent_ce = tmpCeTable[PQ::smoke()->classes[*p].className];
-                zend_do_inheritance(ce, parent_ce TSRMLS_CC);
+	      zend_class_entry *parent_ce = tmpCeTable[PQ::smoke()->classes[*p].className];
+		zend_do_inheritance(ce, parent_ce TSRMLS_CC);
             }
         }
     }
--- trunk/KDE/kdebindings/php/phpqt/src/zend_extension.h #883059:883060
@@ -69,6 +69,7 @@
 PHP_FUNCTION(Q_ASSERT_X);
 PHP_FUNCTION(qt_check_pointer);
 PHP_FUNCTION(qobject_cast);
+PHP_FUNCTION(qstatic_cast);
 PHP_FUNCTION(tr);
 PHP_FUNCTION(check_qobject);
 PHP_FUNCTION(Q_UNUSED);



More information about the Kde-bindings mailing list