|
@@ -221,32 +221,35 @@ void QgsHighlight::paintLine( QPainter *p, QgsPolylineXY line ) |
|
|
p->drawPolyline( polygon ); |
|
|
} |
|
|
|
|
|
void QgsHighlight::paintPolygon( QPainter *p, QgsPolygonXY polygon ) |
|
|
void QgsHighlight::paintPolygon( QPainter *p, const QgsPolygonXY &polygon ) |
|
|
{ |
|
|
// OddEven fill rule by default |
|
|
QPainterPath path; |
|
|
|
|
|
p->setPen( mPen ); |
|
|
p->setBrush( mBrush ); |
|
|
|
|
|
for ( int i = 0; i < polygon.size(); i++ ) |
|
|
for ( const auto &sourceRing : polygon ) |
|
|
{ |
|
|
if ( polygon[i].empty() ) continue; |
|
|
if ( sourceRing.empty() ) |
|
|
continue; |
|
|
|
|
|
QPolygonF ring; |
|
|
ring.reserve( polygon[i].size() + 1 ); |
|
|
ring.reserve( sourceRing.size() + 1 ); |
|
|
|
|
|
for ( int j = 0; j < polygon[i].size(); j++ ) |
|
|
QPointF lastVertex; |
|
|
for ( const auto &sourceVertex : sourceRing ) |
|
|
{ |
|
|
//adding point only if it is more than a pixel apart from the previous one |
|
|
const QPointF cur = toCanvasCoordinates( polygon[i][j] ) - pos(); |
|
|
if ( 0 == j || std::abs( ring.back().x() - cur.x() ) > 1 || std::abs( ring.back().y() - cur.y() ) > 1 ) |
|
|
const QPointF curVertex = toCanvasCoordinates( sourceVertex ) - pos(); |
|
|
if ( std::abs( ring.back().x() - curVertex.x() ) > 1 || std::abs( ring.back().y() - curVertex.y() ) > 1 ) |
|
|
{ |
|
|
ring.push_back( cur ); |
|
|
ring.push_back( curVertex ); |
|
|
} |
|
|
lastVertex = curVertex; |
|
|
} |
|
|
|
|
|
ring.push_back( ring[ 0 ] ); |
|
|
ring.push_back( ring.at( 0 ) ); |
|
|
|
|
|
path.addPolygon( ring ); |
|
|
} |
|
|