mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-19 00:04:52 -04:00
Fix incorrect draw stacking when drawing rubber bands with
secondary lines enabled
This commit is contained in:
parent
df71901a32
commit
4374c6e475
@ -275,7 +275,7 @@ for tracking the mouse while drawing polylines or polygons.
|
|||||||
\param p The QPainter object
|
\param p The QPainter object
|
||||||
%End
|
%End
|
||||||
|
|
||||||
void drawShape( QPainter *p, QVector<QPointF> &pts );
|
void drawShape( QPainter *p, const QVector<QPointF> &pts );
|
||||||
%Docstring
|
%Docstring
|
||||||
Draws shape of the rubber band.
|
Draws shape of the rubber band.
|
||||||
\param p The QPainter object
|
\param p The QPainter object
|
||||||
|
@ -405,35 +405,47 @@ void QgsRubberBand::setToCanvasRectangle( QRect rect )
|
|||||||
|
|
||||||
void QgsRubberBand::paint( QPainter *p )
|
void QgsRubberBand::paint( QPainter *p )
|
||||||
{
|
{
|
||||||
if ( !mPoints.isEmpty() )
|
if ( mPoints.isEmpty() )
|
||||||
{
|
return;
|
||||||
Q_FOREACH ( const QList<QgsPointXY> &line, mPoints )
|
|
||||||
|
QVector< QVector<QPointF> > shapes;
|
||||||
|
for ( const QList<QgsPointXY> &line : qgsAsConst( mPoints ) )
|
||||||
{
|
{
|
||||||
QVector<QPointF> pts;
|
QVector<QPointF> pts;
|
||||||
Q_FOREACH ( const QgsPointXY &pt, line )
|
for ( const QgsPointXY &pt : line )
|
||||||
{
|
{
|
||||||
const QPointF cur = toCanvasCoordinates( QgsPointXY( pt.x() + mTranslationOffsetX, pt.y() + mTranslationOffsetY ) ) - pos();
|
const QPointF cur = toCanvasCoordinates( QgsPointXY( pt.x() + mTranslationOffsetX, pt.y() + mTranslationOffsetY ) ) - pos();
|
||||||
if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 )
|
if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 )
|
||||||
pts.append( cur );
|
pts.append( cur );
|
||||||
}
|
}
|
||||||
|
shapes << pts;
|
||||||
if ( mSecondaryPen.color().isValid() )
|
|
||||||
{
|
|
||||||
mSecondaryPen.setWidth( mPen.width() + 2 );
|
|
||||||
|
|
||||||
p->setBrush( Qt::NoBrush );
|
|
||||||
p->setPen( mSecondaryPen );
|
|
||||||
drawShape( p, pts );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int iterations = mSecondaryPen.color().isValid() ? 2 : 1;
|
||||||
|
for ( int i = 0; i < iterations; ++i )
|
||||||
|
{
|
||||||
|
if ( i == 0 && iterations > 1 )
|
||||||
|
{
|
||||||
|
// first iteration with multi-pen painting, so use secondary pen
|
||||||
|
mSecondaryPen.setWidth( mPen.width() + 2 );
|
||||||
|
p->setBrush( Qt::NoBrush );
|
||||||
|
p->setPen( mSecondaryPen );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// "top" layer, use primary pen/brush
|
||||||
p->setBrush( mBrush );
|
p->setBrush( mBrush );
|
||||||
p->setPen( mPen );
|
p->setPen( mPen );
|
||||||
drawShape( p, pts );
|
}
|
||||||
|
|
||||||
|
for ( const QVector<QPointF> &shape : qgsAsConst( shapes ) )
|
||||||
|
{
|
||||||
|
drawShape( p, shape );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRubberBand::drawShape( QPainter *p, QVector<QPointF> &pts )
|
void QgsRubberBand::drawShape( QPainter *p, const QVector<QPointF> &pts )
|
||||||
{
|
{
|
||||||
switch ( mGeometryType )
|
switch ( mGeometryType )
|
||||||
{
|
{
|
||||||
|
@ -310,7 +310,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
|
|||||||
* \param p The QPainter object
|
* \param p The QPainter object
|
||||||
* \param pts A list of points used to draw the shape
|
* \param pts A list of points used to draw the shape
|
||||||
*/
|
*/
|
||||||
void drawShape( QPainter *p, QVector<QPointF> &pts );
|
void drawShape( QPainter *p, const QVector<QPointF> &pts );
|
||||||
|
|
||||||
//! Recalculates needed rectangle
|
//! Recalculates needed rectangle
|
||||||
void updateRect();
|
void updateRect();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user