Results 1 to 2 of 2

Thread: how would you drawPolyLine that has missing segments

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default how would you drawPolyLine that has missing segments

    I have a QVector, "wellData", of QPoints that I render on a subclassed QWidget like so:

    Qt Code:
    1. void SkiggleLinePanel::paintEvent(QPaintEvent *e)
    2. {
    3.  
    4. // QVector<QPoint> wellData;
    5.  
    6. QPainter painter(this);
    7.  
    8. painter.drawPolyline(wellData.data(), wellData.size());
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    This works as expected. Suppose, however, that I have 7 QPoints with values like so:

    0 1
    2 2
    1 3
    3 -9
    7 5
    6 6
    2 3

    These are X and Y values, *except* -9 is actually a NULL data value, and this particular x,y coordinate pair should be thrown out... So instead of one longish line of 7 points, I would want 2 shorter lines of 3 points each. How to do this?

    One obvious fix: use QVector's members to find -9, then split it into 2 QVectors, and draw both of these. BUT: the actual problem involves a very long Polyline consisting of thousands of QPoints with many NULL values scattered throughout... so doing this would be very cumbersome. Are there other options here?
    Last edited by vonCZ; 6th May 2009 at 13:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how would you drawPolyLine that has missing segments

    QPainter::drawPolyline() takes an array of points and the number of points to draw so you can obtain what you want using this simple loop:

    Qt Code:
    1. QVector<QPoint> points;
    2. // fillWithData(points);
    3. //...
    4. int start = 0;
    5. for(int i=0;i<points.size();i++){
    6. QPoint pt = points.at(i);
    7. if(pt.x()==-9 || pt.y()==-9){
    8. // draw from start to the current point
    9. if(start!=i){
    10. painter.drawPolyline(points.constData()+start, i-start);
    11. }
    12. start = i;
    13. }
    14. }
    15. if(start!=points.size()-1){
    16. painter.drawPolyline(points.constData()+start, points.size()-1-start);
    17. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.