Skip to content

Commit

Permalink
Fix display of rubber band and geometry highlight on rotated canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and github-actions[bot] committed Oct 29, 2023
1 parent e2f41f8 commit 694a75c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/core/linepolygonhighlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ QSGNode *LinePolygonHighlight::updatePaintNode( QSGNode *n, QQuickItem::UpdatePa
geometry.transform( ct );
}

const QgsRectangle extent = mMapSettings->visibleExtent();
mGeometryCorner = QgsPoint( extent.xMinimum(), extent.yMaximum() );
mGeometryMUPP = mMapSettings->mapUnitsPerPoint();
QgsSGGeometry *gn = new QgsSGGeometry( geometry, mColor, mWidth * mMapSettings->devicePixelRatio(), mMapSettings->visibleExtent(), 1.0 / mMapSettings->mapUnitsPerPoint() );
gn->setFlag( QSGNode::OwnedByParent );
n->appendChildNode( gn );
Expand Down Expand Up @@ -130,11 +127,18 @@ void LinePolygonHighlight::updateTransform()
if ( !mMapSettings )
return;

if ( mDirty )
{
const QgsRectangle extent = mMapSettings->visibleExtent();
mGeometryCorner = QgsPoint( extent.xMinimum(), extent.yMaximum() );
mGeometryMUPP = mMapSettings->mapUnitsPerPoint();
}

const QgsPointXY pixelCorner = mMapSettings->coordinateToScreen( mGeometryCorner );

setX( mDirty ? 0 : pixelCorner.x() );
setY( mDirty ? 0 : pixelCorner.y() );
setScale( mDirty ? 1.0 : mGeometryMUPP / mMapSettings->mapUnitsPerPoint() );
setX( pixelCorner.x() );
setY( pixelCorner.y() );
setScale( mGeometryMUPP / mMapSettings->mapUnitsPerPoint() );
setRotation( mMapSettings->rotation() );

update();
Expand All @@ -148,7 +152,7 @@ void LinePolygonHighlight::rotationChanged()
void LinePolygonHighlight::visibleExtentChanged()
{
const double scaleChange = mGeometryMUPP / mMapSettings->mapUnitsPerPoint();
mDirty = mGeometryMUPP == 0.0 || scaleChange > 1.75 || scaleChange < 0.25;
mDirty = mDirty || mGeometryMUPP == 0.0 || scaleChange > 1.75 || scaleChange < 0.25;
updateTransform();
}

Expand Down
16 changes: 10 additions & 6 deletions src/core/rubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,18 @@ void Rubberband::updateTransform()
if ( !mMapSettings )
return;

if ( mDirty )
{
const QgsRectangle extent = mMapSettings->visibleExtent();
mGeometryCorner = QgsPoint( extent.xMinimum(), extent.yMaximum() );
mGeometryMUPP = mMapSettings->mapUnitsPerPoint();
}

const QgsPointXY pixelCorner = mMapSettings->coordinateToScreen( mGeometryCorner );

setX( mDirty ? 0 : pixelCorner.x() );
setY( mDirty ? 0 : pixelCorner.y() );
setScale( mDirty ? 1.0 : mGeometryMUPP / mMapSettings->mapUnitsPerPoint() );
setX( pixelCorner.x() );
setY( pixelCorner.y() );
setScale( mGeometryMUPP / mMapSettings->mapUnitsPerPoint() );
setRotation( mMapSettings->rotation() );

update();
Expand Down Expand Up @@ -216,9 +223,6 @@ QSGNode *Rubberband::updatePaintNode( QSGNode *n, QQuickItem::UpdatePaintNodeDat
n->appendChildNode( rbCurrentPoint );
}
}
const QgsRectangle extent = mMapSettings->visibleExtent();
mGeometryCorner = QgsPoint( extent.xMinimum(), extent.yMaximum() );
mGeometryMUPP = mMapSettings->mapUnitsPerPoint();

mDirty = false;
}
Expand Down

0 comments on commit 694a75c

Please sign in to comment.