Skip to content

Commit

Permalink
When changing rect text annotation to fixed size mode, use current size
Browse files Browse the repository at this point in the history
Instead of resetting the size to a default size, use the actual size
of the annotation item at the current map scale as the initial fixed
size.

Fixes #59189
  • Loading branch information
nyalldawson committed Feb 5, 2025
1 parent 42990de commit a248472
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/annotations/qgsannotationitempropertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ void QgsAnnotationItemPropertiesWidget::setItemId( const QString &itemId )
mItemWidget->setItemId( itemId );
}
}
else
{
mItemWidget->setItemId( itemId );
}
}

if ( !setItem )
Expand Down
24 changes: 24 additions & 0 deletions src/gui/annotations/qgsannotationitemwidget_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,30 @@ void QgsAnnotationRectangleTextItemWidget::sizeModeChanged()
break;

case Qgis::AnnotationPlacementMode::FixedSize:
if ( const QgsRenderedAnnotationItemDetails *details = renderedItemDetails() )
{
const QgsRectangle itemBoundsMapUnits = details->boundingBox();
if ( QgsMapCanvas *canvas = context().mapCanvas() )
{
const QgsPointXY topLeftPixels = canvas->mapSettings().mapToPixel().transform( itemBoundsMapUnits.xMinimum(), itemBoundsMapUnits.yMinimum() );
const QgsPointXY bottomRightPixels = canvas->mapSettings().mapToPixel().transform( itemBoundsMapUnits.xMaximum(), itemBoundsMapUnits.yMaximum() );
const double widthPixels = std::abs( bottomRightPixels.x() - topLeftPixels.x() );
const double heightPixels = std::abs( bottomRightPixels.y() - topLeftPixels.y() );

// convert width/height in pixels to mm
const double pixelsPerMm = canvas->mapSettings().outputDpi() / 25.4;
mItem->setFixedSizeUnit( Qgis::RenderUnit::Millimeters );
mItem->setFixedSize( QSizeF( widthPixels / pixelsPerMm, heightPixels / pixelsPerMm ) );

// and update widget UI accordingly
whileBlocking( mWidthSpinBox )->setValue( mItem->fixedSize().width() );
whileBlocking( mHeightSpinBox )->setValue( mItem->fixedSize().height() );
whileBlocking( mSizeUnitWidget )->setUnit( mItem->fixedSizeUnit() );

mUpdateItemPosition = true;
}
}

mWidgetFixedSize->show();
break;

Expand Down

0 comments on commit a248472

Please sign in to comment.