Qt3 to Qt4, drawing maps with QPainterPath, Qt joining QPainterPath's together?

  • Hi

    I am converting an application from Qt3 to Qt4 and i am having trouble with drawing. Use to use QPointArray's to do the drawing, but now have to use QPainterPath.

    I have a 17 sided closed shape (which looks a bit like a hexagon) which display using QPainterPath on a QPainter on a QWidget. When the shape is drawn in the centre of the screen it displays ok. When I pan the shape up, down, left and right the shape moves out of the window coordinates and it is clipped and correctly displayed.
    When i move the shape so that it is half out of the screen on the left and half off the screen to the bottom it draws a line from the last clipped point at the bottom of the screen to the first clipped point that is now visible on the left hand side of the screen, i don't want it to do this!!

    In the first block of code (not the struct) it recognises that the closed polgon is broken when panned to bottom left corner and that point p2 has been clipped and a new Arc is created so ring->ArcList.size() is now 2. But somewhere it is joining all the ring->ArcLists together to become closed, and i don't know where, could drawpath be doing it?
    I have tried using moveTo() and closeSubPath() but that doesn't fix it, unless i am doing it in the wrong place?

    I would like to attached a jpeg picture but can't.

    @struct MapRing
    Q_GeoPoint centre;
    double internal_radius;
    double external_radius;
    double start_angle;
    double end_angle;
    int surface_pattern;
    int thickness;
    int dash;
    int expand;
    int border_display;
    int surface_display;
    QPainterPath ExternalPoints;
    QList<QPainterPath*> ArcList;
    QPainterPath SurfPoints; // Invisible outline for fill

    @ MapRing ring;
    int ArcIndex;
    bool first;
    bool p1Clipped;
    bool p2Clipped;

        QPoint start;
        QPoint end;
        QPoint p1;
        QPoint p2;
        QPainterPath *Arc;
        QPolygon polygonF;
        first = true;       
        for(uint i = 2; i < internal_points.elementCount(); i++)
          p1 = start;
          p2 = end;
          if(clip_rect.clipLine(p1, p2, p1Clipped, p2Clipped))
            if(first == true)
              // Start a new line  
              Arc = new QPainterPath;
              ArcIndex = 0;
              polygonF << QPoint(p1.x(), p1.y());
              first = false;
            polygonF << QPoint(p2.x(), p2.y());
            if(p2Clipped == true)
              first = true;
          start = end;
         To draw the map rings to the window i do the following

    @ MapRing *ring;

    for(int i = 0; i < RingList.size(); ++i)
      ring = RingList.at(i);
        SetPenStyle(ring->dash, ring->thickness, &pen;);
        if(ring->InternalPoints.elementCount() > 2)
        if(ring->ExternalPoints.elementCount() > 2)
          window->paint.drawPath(ring->ExternalPoints); //drawPolygon
        qDebug("ring->ArcList.size() %d", ring->ArcList.size());
        for(int i = 0; i < ring->ArcList.size(); ++i)
          if(ring->ArcList.at(i)->elementCount() > 0)
            window->paint.drawPath(*ring->ArcList.at(i));//was drawPolyline(*arc); in qt3


    I have been working on this for days now. I was not the original writer of the Qt3 code so am not expert in drawing.

    Thank you very much!

Log in to reply