diff generator/typesystem_core-java.java @ 248:7664de4a55e5

Fixed #23. QtD_QObjectEntity is not created dynamically for shell classes any more. Class initialization is now performed by static constructors. When wrapping QObjects returned from functions, their run-time types are now taken into account. QObjects are allocated on GC heap, a doubly-linked list is used to prevent them from been collected (arguably a better solution than allocating on C heap and adding GC ranges) Minor changes (including unnecessary).
author maxter
date Thu, 20 Aug 2009 14:47:17 +0000
parents 7dd099050621
children 37eed70de029
line wrap: on
line diff
--- a/generator/typesystem_core-java.java	Fri Jul 31 11:05:22 2009 +0000
+++ b/generator/typesystem_core-java.java	Thu Aug 20 14:47:17 2009 +0000
@@ -22,7 +22,7 @@
 * exception, Nokia gives you certain additional rights. These rights
 * are described in the Nokia Qt GPL Exception version 1.2, included in
 * the file GPL_EXCEPTION.txt in this package.
-* 
+*
 * Qt for Windows(R) Licensees
 * As a special exception, Nokia, as the sole copyright holder for Qt
 * Designer, grants users of the Qt/Eclipse Integration plug-in the
@@ -46,10 +46,9 @@
 
 class QObject___ extends QObject {
     
+    /* TODO: test whether the linked list is really a better solution
     public bool __stackAllocated = false;
     
-    public bool __qobject_is_deleting = false;
-    
     new(size_t size, void* p = null)
     {
         if (!p)
@@ -72,12 +71,64 @@
             }
         }
     }
+    */
     
-    // list of QObjects references to prevent them from garbage collecting if they are managed by Qt
-    private static QObject[] __gc_ref_list;
+    private
+    {
+        static QObject __root;
+        QObject __next;
+        QObject __prev;
+    }
+    
+    ~this()
+    {
+        if (__prev)
+            __prev.__next = __next;
+        else
+            __root = __next;
+        
+        if (__next)      
+            __next.__prev = __prev;        
+    }
     
-    // this flag needs to be set false when QObject is deleted from inside Qt so when deleting it from D it won't delete C++ object
-    public bool __no_real_delete = false;
+    /**
+    */
+    T findChild(T : QObject = QObject)(string name = null)
+    {
+        foreach (obj; children)
+        {
+            auto tmp = cast(T)obj;
+            if (tmp && (!name.length || tmp.objectName == name))
+                return tmp;
+            
+            tmp = obj.findChild!(T)(name);
+            if (tmp)
+                return tmp;
+        }
+        
+        return null;
+    }
+    
+    /**
+    */
+    T[] findChildren(T : QObject = QObject)(string name = null)
+    {
+        T[] result;
+        
+        void find(QObject[] objects)
+        {        
+            foreach (obj; objects)
+            {
+                auto tmp = cast(T)obj;
+                if (tmp && (!name.length || tmp.objectName == name))
+                    result ~= tmp;
+                find(obj.children);
+            }
+        }
+        
+        find(children);
+        return result;
+    }
 }// class
 
 abstract class QAbstractItemModel___ extends QAbstractItemModel {
@@ -141,14 +192,14 @@
 	{
 //        if (m_instance != null)
 //            throw new RuntimeException("QCoreApplication can only be initialized once");
-            
+
 		argc = args.length;
 		argv = toStringzArray(args);
 		this(&argc, argv);
 
 //        m_instance.aboutToQuit.connect(m_instance, "disposeOfMyself()");
 	}
-	
+
 	private int argc;
 	private char **argv;
 /*
@@ -489,7 +540,7 @@
 
     public final long write(string str) {
 	return write(str.ptr, str.length);
-    } 
+    }
 }// class
 
 class QCryptographicHash___ extends QCryptographicHash {