- Fix encoding function to iterate reversed list
authorunc0rr
Fri, 24 Dec 2010 20:33:17 +0300
changeset 4666 34551d8639cf
parent 4665 fa7ad5f3725f
child 4667 436b3aafcb0c
- Fix encoding function to iterate reversed list - Fix decoding routine to not loose last point
QTfrontend/drawmapscene.cpp
--- a/QTfrontend/drawmapscene.cpp	Fri Dec 24 11:54:34 2010 -0500
+++ b/QTfrontend/drawmapscene.cpp	Fri Dec 24 20:33:17 2010 +0300
@@ -87,9 +87,10 @@
 {
     QByteArray b;
 
-    foreach(QList<QPoint> points, paths)
+    for(int i = paths.size() - 1; i >= 0; --i)
     {
         int cnt = 0;
+        QList<QPoint> points = paths.at(i);
         foreach(QPoint point, points)
         {
             qint16 px = qToBigEndian((qint16)point.x());
@@ -124,19 +125,21 @@
         quint8 flags = *(quint8 *)data.data();
         data.remove(0, 1);
 
-	if (data.size() < 5) points.append(QPoint(px, py));
-        //last chunk or first point
-        if((data.size() < 5) || (flags & 0x80))
+        if((flags & 0x80) && points.size())
         {
-            if(points.size())
-            {
-                addPath(pointsToPath(points), m_pen);
-                paths.append(points);
+            addPath(pointsToPath(points), m_pen);
+            paths.prepend(points);
+
+            points.clear();
+        }
 
-                points.clear();
-            }
-        }
-	if (data.size() >= 5) points.append(QPoint(px, py));
+        points.append(QPoint(px, py));
+    }
+
+    if(points.size())
+    {
+        addPath(pointsToPath(points), m_pen);
+        paths.prepend(points);
     }
 
     emit pathChanged();