Am Mittwoch, 14. Mai 2008 schrieb Hans-Peter Jansen:
> Am Mittwoch, 14. Mai 2008 schrieb Phil Thompson:
> > On Saturday 10 May 2008 22:43:34 Hans-Peter Jansen wrote:
> > > Hi,
> > >
> > > for optimizing reasons, I'm desperately missing the QRegion.rects()
> > > method. Background is a special double buffering widget, where bitblt
> > > in the paintEvent reimplementation of the full event.rect() is
> > > painfully slow, while only a margin area is really modified. The only
> > > way to really get at the these areas is QRegion.rects(), which is not
> > > implemented in PyQt3. (By the way, even the deactivated signature in
> > > sip/qt/qregion.sip is wrong, QRegion.rects() returns a
> > > QMemArray<QRect>, not a QArray<Rect> (anymore?)).
> >
> > Just pasting in the QList<TYPE> implementation from PyQt4 into PyQt3's
> > qmemarray.sip should work - and change the "QList" etc to "QMemArray".

Phil, as promised, here's the patch. Works like a charm. I'm sure that 
without your help, I wouldn't have managed to solve this on my own. With 
your hints, it was a piece of cake... :-)

Thanks a lot,

Pete
--- PyQt-x11-gpl-3.17.4/sip/qt/qregion.sip.orig	2007-12-06 15:28:07.000000000 +0100
+++ PyQt-x11-gpl-3.17.4/sip/qt/qregion.sip	2008-05-14 23:40:14.659129172 +0200
@@ -100,7 +100,7 @@ public:
 	QRegion eor(const QRegion &) const;
 
 	QRect boundingRect() const;
-//	QArray<QRect> rects() const;
+	QMemArray<QRect> rects() const;
 %If (Qt_2_2_0 -)
 //	void setRects(const QRect *,int);
 %End
--- PyQt-x11-gpl-3.17.4/sip/qt/qmemarray.sip.orig	2007-12-06 15:28:07.000000000 +0100
+++ PyQt-x11-gpl-3.17.4/sip/qt/qmemarray.sip	2008-05-15 00:05:08.247037196 +0200
@@ -89,4 +89,81 @@ converted to and from Python lists of th
 %End
 };
 
+// QMemArray<TYPE> is implemented as a Python list.
+template<TYPE>
+%MappedType QMemArray<TYPE>
+{
+%TypeHeaderCode
+#include <qmemarray.h>
+%End
+
+%ConvertFromTypeCode
+    // Create the list.
+    PyObject *l;
+
+    if ((l = PyList_New(sipCpp->size())) == NULL)
+        return NULL;
+
+    // Set the list elements.
+    for (uint i = 0; i < sipCpp->size(); ++i)
+    {
+        TYPE *t = new TYPE(sipCpp->at(i));
+        PyObject *tobj;
+
+        if ((tobj = sipConvertFromNewInstance(t, sipClass_TYPE, sipTransferObj)) == NULL)
+        {
+            Py_DECREF(l);
+            delete t;
+
+            return NULL;
+        }
+
+        PyList_SET_ITEM(l, i, tobj);
+    }
+
+    return l;
+%End
+
+%ConvertToTypeCode
+    // Check the type if that is all that is required.
+    if (sipIsErr == NULL)
+    {
+        if (!PyList_Check(sipPy))
+            return 0;
+
+        for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
+            if (!sipCanConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, SIP_NOT_NONE))
+                return 0;
+
+        return 1;
+    }
+
+    QMemArray<TYPE> *ql = new QMemArray<TYPE>;
+
+    for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
+    {
+        int state;
+        TYPE *t = reinterpret_cast<TYPE *>(sipConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
+
+        if (*sipIsErr)
+        {
+            sipReleaseInstance(t, sipClass_TYPE, state);
+
+            delete ql;
+            return 0;
+        }
+
+        uint idx = ql->size();
+        ql->resize(idx + 1);
+        (*ql)[idx] = *t;
+
+        sipReleaseInstance(t, sipClass_TYPE, state);
+    }
+
+    *sipCppPtr = ql;
+
+    return sipGetState(sipTransferObj);
+%End
+};
+
 %End
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to