src/gui/painting/qregion.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
--- a/src/gui/painting/qregion.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/gui/painting/qregion.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -690,7 +690,7 @@
 
     if (!rect_intersects(boundingRect(), region.boundingRect()))
         return false;
-    if (numRects() == 1 && region.numRects() == 1)
+    if (rectCount() == 1 && region.rectCount() == 1)
         return true;
 
     const QVector<QRect> myRects = rects();
@@ -717,7 +717,7 @@
     const QRect r = rect.normalized();
     if (!rect_intersects(boundingRect(), r))
         return false;
-    if (numRects() == 1)
+    if (rectCount() == 1)
         return true;
 
     const QVector<QRect> myRects = rects();
@@ -739,6 +739,7 @@
 #endif
 
 /*!
+    \obsolete
     \fn int QRegion::numRects() const
     \since 4.4
 
@@ -746,6 +747,13 @@
 */
 
 /*!
+    \fn int QRegion::rectCount() const
+    \since 4.6
+
+    Returns the number of rectangles that will be returned in rects().
+*/
+
+/*!
     \fn bool QRegion::isEmpty() const
 
     Returns true if the region is empty; otherwise returns false. An
@@ -1027,7 +1035,7 @@
 Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath(const QRegion &region)
 {
     QPainterPath result;
-    if (region.numRects() == 1) {
+    if (region.rectCount() == 1) {
         result.addRect(region.boundingRect());
         return result;
     }
@@ -3859,23 +3867,28 @@
 QRegion::QRegion(const QPolygon &a, Qt::FillRule fillRule)
 {
     if (a.count() > 2) {
-        d =  new QRegionData;
-        d->ref = 1;
+        QRegionPrivate *qt_rgn = PolygonRegion(a.constData(), a.size(),
+                                               fillRule == Qt::WindingFill ? WindingRule : EvenOddRule);
+        if (qt_rgn) {
+            d =  new QRegionData;
+            d->ref = 1;
 #if defined(Q_WS_X11)
-        d->rgn = 0;
-        d->xrectangles = 0;
+            d->rgn = 0;
+            d->xrectangles = 0;
 #elif defined(Q_WS_WIN)
-        d->rgn = 0;
+            d->rgn = 0;
 #endif
-        d->qt_rgn = PolygonRegion(a.constData(), a.size(),
-                                  fillRule == Qt::WindingFill ? WindingRule : EvenOddRule);
+            d->qt_rgn = qt_rgn;
+        } else {
+            d = &shared_empty;
+            d->ref.ref();
+        }
     } else {
         d = &shared_empty;
         d->ref.ref();
     }
 }
 
-
 QRegion::QRegion(const QRegion &r)
 {
     d = r.d;
@@ -4317,6 +4330,12 @@
     return (d->qt_rgn ? d->qt_rgn->numRects : 0);
 }
 
+int QRegion::rectCount() const
+{
+    return (d->qt_rgn ? d->qt_rgn->numRects : 0);
+}
+
+
 bool QRegion::operator==(const QRegion &r) const
 {
     if (!d->qt_rgn)