diff qt/core/QList.d @ 298:adae77fdc1ea signals

Native QList implementation is now used throughout QtD
author eldar
date Sun, 06 Dec 2009 17:26:37 +0000
parents bc783e20da2b
children 87db643519a4
line wrap: on
line diff
--- a/qt/core/QList.d	Sun Nov 22 22:18:06 2009 +0000
+++ b/qt/core/QList.d	Sun Dec 06 17:26:37 2009 +0000
@@ -315,6 +315,7 @@
 }
 
 import std.stdio;
+import std.conv;
 
 alias void Dummy; // DMD bug #3538 
 
@@ -323,8 +324,8 @@
     static if (is(Default == Dummy))
         alias QTypeInfo!T TI;
     else
-        alias Default TI; 
-  
+        alias Default TI;
+
     struct Node
     {
         void *v;
@@ -456,7 +457,7 @@
     }
     else
     {
-        ref const (T) at(int i) const
+        const (T) at(int i) const
         {
             assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range");
             return (cast(Node*)(p.at(i))).t();
@@ -528,6 +529,20 @@
                 q_new_at(from++, *cast(T*)(src++));
     }
     
+    T[] toArray()
+    {
+        T[] res;
+        res.length = this.length;
+        for(int i = 0; i < res.length; ++i)
+        {
+            static if (isValueType!T)
+                res[i] = new T(T.__constructNativeCopy(this.at(i).__nativeId)); // Node should probably provide a ptr method to directly extract pointer to the native value stored in the list to avoid creating a dummy D object in t()
+            else
+                res[i] = this.opIndex(i);
+        }
+        return res;
+    }
+    
     void free(QListData.Data* data)
     {
         writeln("QList data destroyed");