changeset 293:8627891e4556 signals

QList updates
author eldar
date Fri, 13 Nov 2009 19:09:28 +0000
parents 19498f420252
children bb37b0ed94c9
files build/core.txt generator/abstractmetalang.cpp generator/abstractmetalang.h generator/cppimplgenerator.cpp generator/cppimplgenerator.h generator/dgenerator.cpp qt/core/QList.d qt/d2/qt/Signal.d qt/qtd/MOC.d qt/qtd/MetaMarshall.d
diffstat 10 files changed, 163 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/build/core.txt	Tue Nov 10 19:29:42 2009 +0000
+++ b/build/core.txt	Fri Nov 13 19:09:28 2009 +0000
@@ -12,7 +12,7 @@
 ## Module specific d files.
 set (d_files
     QGlobal
-    qtd/Array
+    qtd/Array  
     qtd/ArrayOpsPrimitive   
     qtd/Traits
     core/QString
@@ -49,15 +49,35 @@
     QTimerEvent
     QTranslator
     QByteArray
+    QLocale
     QDataStream
-    QUrl
-    
-    QTime
-    QRegExp
-    QLocale
+    QMimeData
+    QIODevice
     QDateTime
     QDate
+    QTime
     QBitArray
-    QIODevice
+    QRegExp
+    QUrl
+    QAbstractItemModel
+    QAbstractFileEngine
+    QFile
+    QDir
+    QFileInfo
+    QTextStream
+    QTimer
+    QTextCodec
+    QTextCodec_ConverterState
+    QTextEncoder
+    QTextDecoder
+    QTimeLine
+    QAbstractFactory
+    QAbstractListModel
+    QCryptographicHash
+    QSettings
+    QProcess
+    QBuffer
+    QLibraryInfo
+    QXmlStreamEntityResolver
     )
 	
--- a/generator/abstractmetalang.cpp	Tue Nov 10 19:29:42 2009 +0000
+++ b/generator/abstractmetalang.cpp	Fri Nov 13 19:09:28 2009 +0000
@@ -1194,7 +1194,19 @@
     return 0;
 }
 
+AbstractMetaFunction* AbstractMetaClass::copyConstructor() const
+{
+    AbstractMetaFunctionList ctors = queryFunctions(Constructors);
+    for(int i = 0; i < ctors.size(); i++)
+    {
+        AbstractMetaFunction *ctor = ctors.at(i);
+        if (ctor->arguments().size() > 0)
+            if(ctor->arguments().at(0)->type()->typeEntry() == typeEntry())
+                return ctor;
+    }
 
+    return NULL;
+}
 
 static bool functions_contains(const AbstractMetaFunctionList &l, const AbstractMetaFunction *func)
 {
--- a/generator/abstractmetalang.h	Tue Nov 10 19:29:42 2009 +0000
+++ b/generator/abstractmetalang.h	Fri Nov 13 19:09:28 2009 +0000
@@ -713,6 +713,7 @@
     bool hasSignal(const AbstractMetaFunction *f) const;
 
     bool hasConstructors() const;
+    AbstractMetaFunction *copyConstructor() const;
 
     void addDefaultConstructor();
 
--- a/generator/cppimplgenerator.cpp	Tue Nov 10 19:29:42 2009 +0000
+++ b/generator/cppimplgenerator.cpp	Fri Nov 13 19:09:28 2009 +0000
@@ -721,6 +721,22 @@
           << "}" << endl;
     }
 
+    if (java_class->typeEntry()->isValue() && java_class->hasCloneOperator())
+    {
+        AbstractMetaFunction *ctor = java_class->copyConstructor();
+        if(ctor)
+        {
+            QString argName = ctor->arguments().at(0)->indexedName();
+            s << endl << endl
+              << "extern \"C\" DLL_PUBLIC void* qtd_" << java_class->name() << "_placed_copy(void* "
+              << argName << ", " << "void* place) {" << endl
+              << QString("    const %1&  __qt_%2 = (const %1& ) *(%1 *)%2;").arg(java_class->name()).arg(argName) << endl;
+
+            writeFinalConstructor(s, ctor, "result", "original", "(place)");
+            s << "}";
+        }
+    }
+    
     s << endl << endl;
 
     priGenerator->addSource(java_class->package(), fileNameForClass(java_class));
@@ -2340,7 +2356,8 @@
 void CppImplGenerator::writeFinalConstructor(QTextStream &s,
                                          const AbstractMetaFunction *java_function,
                                          const QString &qt_object_name,
-                                         const QString &java_object_name)
+                                         const QString &java_object_name,
+                                         const QString &place)
 {
     const AbstractMetaClass *cls = java_function->ownerClass();
     AbstractMetaArgumentList arguments = java_function->arguments();
@@ -2349,7 +2366,7 @@
     bool hasShellClass = cls->generateShellClass();
 
     s << INDENT << shellClassName(cls) << " *" << qt_object_name
-      << " = new " << shellClassName(cls)
+      << " = new " << place << shellClassName(cls)
       << "(";
     writeFunctionCallArguments(s, java_function, "__qt_");
     s << ");" << endl;
--- a/generator/cppimplgenerator.h	Tue Nov 10 19:29:42 2009 +0000
+++ b/generator/cppimplgenerator.h	Fri Nov 13 19:09:28 2009 +0000
@@ -109,7 +109,8 @@
     void writeFinalConstructor(QTextStream &s,
                                const AbstractMetaFunction *java_function,
                                const QString &qt_object_name,
-                               const QString &java_object_name);
+                               const QString &java_object_name,
+                               const QString &place = "");
     void writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *java_class);
     void writeFunctionCall(QTextStream &s,
                            const QString &variable_name,
--- a/generator/dgenerator.cpp	Tue Nov 10 19:29:42 2009 +0000
+++ b/generator/dgenerator.cpp	Fri Nov 13 19:09:28 2009 +0000
@@ -1716,8 +1716,6 @@
     foreach(AbstractMetaFunction *signal, signal_funcs) {
         QString sigExternName = signalExternName(d_class, signal);
 
-        s << "private " << attr << "extern(C) void " << sigExternName << "_connect(void* native_id);" << endl;
-        s << "private " << attr << "extern(C) void " << sigExternName << "_disconnect(void* native_id);" << endl;
 /*
         QString extra_args;
 
@@ -1732,7 +1730,7 @@
 */
         AbstractMetaArgumentList arguments = signal->arguments();
 
-        s << "private extern(C) void " << sigExternName << "_handle(void* d_entity, void** args) {" << endl;
+        s << "/*private extern(C) void " << sigExternName << "_handle(void* d_entity, void** args) {" << endl;
         {
             Indentation indent(INDENT);
             s << INDENT << "auto d_object = cast(" << d_class->name() << ") d_entity;" << endl;
@@ -1781,7 +1779,7 @@
 
             s << ");" << endl;
         }
-        s << "}" << endl;
+        s << "}*/" << endl;
     }
 }
 
@@ -2167,7 +2165,7 @@
     }
 */
 
-    // Enums aliaases
+    // Enums aliases
     foreach (AbstractMetaEnum *d_enum, d_class->enums())
         writeEnumAlias(s, d_enum);
 
@@ -2224,39 +2222,20 @@
             writeFieldAccessors(s, field);
     }
 
-/* qtd
-
-    // the static fromNativePointer function...
-    if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) {
-        s << endl
-          << INDENT << "public static native " << d_class->name() << " fromNativePointer("
-          << "QNativePointer nativePointer);" << endl;
-    }
-
-    if (d_class->isQObject()) {
-        s << endl;
-        if (TypeDatabase::instance()->includeEclipseWarnings())
-            s << INDENT << "@SuppressWarnings(\"unused\")" << endl;
-
-        s << INDENT << "private static native long originalMetaObject();" << endl;
-    }
-
-    // The __qt_signalInitialization() function
-    if (signal_funcs.size() > 0) {
-        s << endl
-          << INDENT << "@Override" << endl
-          << INDENT << "@QtBlockedSlot protected boolean __qt_signalInitialization(String name) {" << endl
-          << INDENT << "    return (__qt_signalInitialization(nativeId(), name)" << endl
-          << INDENT << "            || super.__qt_signalInitialization(name));" << endl
-          << INDENT << "}" << endl
-          << endl
-          << INDENT << "@QtBlockedSlot" << endl
-          << INDENT << "private native boolean __qt_signalInitialization(long ptr, String name);" << endl;
-    }
-*/
     if (d_class->isQObject())
         writeQObjectFunctions(s, d_class);
 
+    if (ctype->isObject() && !ctype->isQObject()) // conversion function wrapper to be consistent with QObject
+    { // some code duplication, remove when there is a better mechanism for Object type conversions
+        QString class_name = ctype->name();
+        QString return_type_name = class_name;
+        if(ctype->designatedInterface())
+            return_type_name = ctype->designatedInterface()->name();
+        s << "    static " << return_type_name << " __getObject(void* nativeId) {" << endl
+          << "        return qtd_" << class_name << "_from_ptr(nativeId);" << endl
+          << "    }" << endl << endl;
+    }
+
     // flag to mark the type of class (to use in templates to convert arguments)
     if (d_class->baseClassName().isEmpty())
     {
@@ -2270,6 +2249,20 @@
 
     s << INDENT << "public alias void __isQtType_" << d_class->name() << ";" << endl << endl;
 
+    // construction of a native copy of a Value
+    if (d_class->typeEntry()->isValue() && d_class->hasCloneOperator())
+    {
+        AbstractMetaFunction *copyCtor = d_class->copyConstructor();
+        if(copyCtor)
+            s << INDENT << "static void* __constructNativeCopy(const void* orig) {" << endl
+              << INDENT << "    return " << copyCtor->marshalledName() << "(cast(void*)orig);" << endl
+              << INDENT << "}" << endl << endl
+
+              << INDENT << "static void* __constructPlacedNativeCopy(const void* orig, void* place) {" << endl
+              << INDENT << "    return qtd_" << d_class->name() << "_placed_copy(orig, place);" << endl
+              << INDENT << "}" << endl << endl;
+    }
+
     // Add dummy constructor for use when constructing subclasses
     if (!d_class->isNamespace() && !d_class->isInterface() && !fakeClass) {
         s << endl
@@ -2531,6 +2524,12 @@
         s << endl << "extern (C) void *__" << d_class->name() << "_entity(void *q_ptr);" << endl << endl;
     }
 
+    if (d_class->typeEntry()->isValue() && d_class->hasCloneOperator())
+    {
+        AbstractMetaFunction *copyCtor = d_class->copyConstructor();
+        if(copyCtor)
+            s << "private extern(C) void* qtd_" << d_class->name() << "_placed_copy(const void* orig, void* place);" << endl << endl;
+    }
 
 //    if (d_class->needsConversionFunc)
         writeConversionFunction(s, d_class);
--- a/qt/core/QList.d	Tue Nov 10 19:29:42 2009 +0000
+++ b/qt/core/QList.d	Fri Nov 13 19:09:28 2009 +0000
@@ -1,11 +1,11 @@
 module qt.core.QList;
 
 import qt.QGlobal;
+import qt.QtdObject;
 import qt.qtd.Atomic;
+import qt.qtd.MetaMarshall;
 //import qt.core.QTypeInfo;
 
-import qt.qtd.MetaMarshall;
-
 import core.stdc.stdlib : qRealloc = realloc, qFree = free, qMalloc = malloc;
 import core.stdc.string : memcpy, memmove;
 
@@ -14,24 +14,23 @@
 enum INT_MAX = int.max;
 
 bool isComplex(T)()
-    if (is(typeof(T.QTypeInfo)))
+    if (is(T.QTypeInfo))
 {
-    return T.QTypeInfo.isComplex();
+    return T.QTypeInfo.isComplex;
 }
 
 bool isStatic(T)()
-    if (is(typeof(T.QTypeInfo)))
+    if (is(T.QTypeInfo))
 {
-    return T.QTypeInfo.isStatic();
+    return T.QTypeInfo.isStatic;
 }
 
 bool isLarge(T)()
-    if (is(typeof(T.QTypeInfo)))
+    if (is(T.QTypeInfo))
 {
-    return T.QTypeInfo.isLarge();
+    return T.QTypeInfo.isLarge;
 }
 
-
 int qAllocMore(int alloc, int extra)
 {
     if (alloc == 0 && extra == 0)
@@ -296,17 +295,30 @@
     {
         void *v;
         
-        static if (isQObjectType!T)
+        static if (isQObjectType!T || isObjectType!T || isValueType!T) // binded Qt types
         {
             T t()
             {
-                return T.__getObject( *cast(void**)(&this) );
+                static if (isValueType!T)
+                {
+                    pragma(msg, "value " ~ T.stringof);
+                    void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this);
+                    return new T(ptr, QtdObjectFlags.nativeOwnership);
+                }
+                else
+                {
+                    pragma(msg, T.stringof);
+
+                    return T.__getObject( *cast(void**)(&this) );
+                }
             }
         }
-        else
+        else // native types
         {    
             ref T t()
             {
+                pragma(msg, "native " ~ T.stringof);
+
                 return *cast(T*)(&this);
             }
     //        { return *cast(T*)(QTypeInfo!T.isLarge || QTypeInfo!T.isStatic
@@ -379,18 +391,14 @@
             free(x);
     }
     
+   
     void append(const T t) // fix to const ref for complex types TODO
     {
         detach();
-/*        static if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic)
+        static if (isQObjectType!T || isObjectType!T || isValueType!T)
         {
             node_construct(cast(Node*)(p.append()), t);
         }
-        else*/ static if (isQObjectType!T)
-        {
-            auto n = cast(Node*)(p.append());
-            *cast(void**)(n) = cast(Node*) t.__nativeId;
-        }
         else
         {
             const T cpy = t;
@@ -398,7 +406,7 @@
         }
     }
 
-    static if (isQObjectType!T)
+    static if (isQObjectType!T || isObjectType!T || isValueType!T)
     {
         T at(int i) const
         {
@@ -415,9 +423,22 @@
         }
     }   
     
-    static if (isQObjectType!T)
-        { }
-    else
+    static if (isQObjectType!T || isObjectType!T || isValueType!T) //binded types
+        void node_construct(Node *n, const T t)
+        {
+            static if (isValueType!T)
+                {
+                    if (isLarge!T() || isStatic!T()) // TODO should be static if
+                        n.v = T.__constructNativeCopy(t.__nativeId);
+                    else if (isComplex!T())
+                        T.__constructPlacedNativeCopy(t.__nativeId, n);
+                    else
+                        T.__constructPlacedNativeCopy(t.__nativeId, n); // TODO should be *cast(T*)(n) = cast(T)(t); as it is a primitive type. not until they are implemented with structs
+                }
+            else // in case of QObject or Object Qt types we place a pointer to a native object in the node
+                n = cast(Node*) t.__nativeId;
+        }
+    else // native types
         void node_construct(Node *n, const ref T t)
         {
     /* TODO       static if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic)
@@ -425,7 +446,7 @@
             else static if (QTypeInfo!T.isComplex)
                 new (n) T(t);
             else*/
-                { *cast(T*)(n) = cast(T)(t); }
+                *cast(T*)(n) = cast(T)(t);
         }
     
     void node_copy(Node *from, Node *to, Node *src)
@@ -445,16 +466,29 @@
         node_destruct(cast(Node*)(data.array.ptr + data.begin),
                       cast(Node*)(data.array.ptr + data.end));
         if (data.ref_.load() == 0)
-            {} // qFree(data); TODO
+            qFree(data);
     }
     
     void node_destruct(Node *from, Node *to)
-    {/* TODO
-        if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic)
-            while (from != to) --to, delete cast(T*)(to->v);
-        else if (QTypeInfo!T.isComplex)
-            while (from != to) --to, cast(T*)(to).~T();
+    {
+        static if (isQObjectType!T || isObjectType!T) //binded types
+            {} // removing just pointers, do nothing
+        static if (isValueType!T) //binded value types
+        {
+            if (isLarge!T() || isStatic!T()) // TODO should be static if
+                while (from != to)
+                    --to, delete cast(T*)(to->v);
+            else if (QTypeInfo!T.isComplex)
+                while (from != to) --to, cast(T*)(to).~T();
+        }
+        else
+        { /*
+            if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic)
+                while (from != to) --to, delete cast(T*)(to->v);
+            else if (QTypeInfo!T.isComplex)
+                while (from != to) --to, cast(T*)(to).~T();
             */
+        }
     }
 }
 
--- a/qt/d2/qt/Signal.d	Tue Nov 10 19:29:42 2009 +0000
+++ b/qt/d2/qt/Signal.d	Fri Nov 13 19:09:28 2009 +0000
@@ -463,7 +463,7 @@
             
             static if (signalType == SignalType.NewSignal)
             {
-                pragma (msg, SignalEmitter!(ArgTypes)(SignalType.NewSignal, getFunc!_Name(fullName), defVals, localIndex));
+//                pragma (msg, SignalEmitter!(ArgTypes)(SignalType.NewSignal, getFunc!_Name(fullName), defVals, localIndex));
                 mixin (SignalEmitter!(ArgTypes)(SignalType.NewSignal, getFunc!_Name(fullName), defVals, localIndex));
             }
         }
--- a/qt/qtd/MOC.d	Tue Nov 10 19:29:42 2009 +0000
+++ b/qt/qtd/MOC.d	Fri Nov 13 19:09:28 2009 +0000
@@ -529,6 +529,6 @@
     
     alias TupleWrapper!(findSymbols!(slotPrefix,   typeof(this), ByOwner!(typeof(this)))) Slots;
     alias TupleWrapper!(findSymbols!(signalPrefix, typeof(this), ByOwner!(typeof(this)))) Signals;
-    pragma(msg, generateMetaInfo!((typeof(this)).stringof, Signals, Slots)());
+//    pragma(msg, generateMetaInfo!((typeof(this)).stringof, Signals, Slots)());
     mixin(generateMetaInfo!((typeof(this)).stringof, Signals, Slots)());
 }
--- a/qt/qtd/MetaMarshall.d	Tue Nov 10 19:29:42 2009 +0000
+++ b/qt/qtd/MetaMarshall.d	Fri Nov 13 19:09:28 2009 +0000
@@ -7,14 +7,14 @@
     enum isQObjectType = is(T.__isQObjectType);
 }
 
-template isObjectType(T) // is a QObject type that belongs to the library
+template isObjectType(T) // is a Qt Object type that belongs to the library
 {
     enum isObjectType = is(T.__isObjectType);
 }
 
-template isValueType(T) // is a QObject type that belongs to the library
+template isValueType(T) // is a Qt Value type that belongs to the library
 {
-    enum isQObjectType = is(typeof(mixin("T." ~ "__isValueType")));
+    enum isValueType = is(T.__isValueType);
 }
 
 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D