diff --git a/python/core/auto_generated/layout/qgslayoutitemlabel.sip.in b/python/core/auto_generated/layout/qgslayoutitemlabel.sip.in index 0b9bab8e41fc..dd550a5825e8 100644 --- a/python/core/auto_generated/layout/qgslayoutitemlabel.sip.in +++ b/python/core/auto_generated/layout/qgslayoutitemlabel.sip.in @@ -233,13 +233,6 @@ Returns the label font color. virtual QRectF boundingRect() const; - virtual void setFrameEnabled( bool drawFrame ); - - - virtual void setFrameStrokeWidth( QgsLayoutMeasurement strokeWidth ); - - - QgsTextFormat textFormat() const; %Docstring Returns the text format used for drawing text in the label. diff --git a/src/core/layout/qgslayoutitemlabel.cpp b/src/core/layout/qgslayoutitemlabel.cpp index d8c90de3c7ec..80a7693792b8 100644 --- a/src/core/layout/qgslayoutitemlabel.cpp +++ b/src/core/layout/qgslayoutitemlabel.cpp @@ -219,6 +219,29 @@ void QgsLayoutItemLabel::refreshExpressionContext() update(); } +void QgsLayoutItemLabel::updateBoundingRect() +{ + QRectF rectangle = rect(); + const double frameExtension = frameEnabled() ? pen().widthF() / 2.0 : 0.0; + if ( frameExtension > 0 ) + rectangle.adjust( -frameExtension, -frameExtension, frameExtension, frameExtension ); + + if ( mMarginX < 0 ) + { + rectangle.adjust( mMarginX, 0, -mMarginX, 0 ); + } + if ( mMarginY < 0 ) + { + rectangle.adjust( 0, mMarginY, 0, -mMarginY ); + } + + if ( rectangle != mCurrentRectangle ) + { + prepareGeometryChange(); + mCurrentRectangle = rectangle; + } +} + QString QgsLayoutItemLabel::currentText() const { QString displayText = mText; @@ -275,19 +298,19 @@ void QgsLayoutItemLabel::setMargin( const double m ) { mMarginX = m; mMarginY = m; - prepareGeometryChange(); + updateBoundingRect(); } void QgsLayoutItemLabel::setMarginX( const double margin ) { mMarginX = margin; - prepareGeometryChange(); + updateBoundingRect(); } void QgsLayoutItemLabel::setMarginY( const double margin ) { mMarginY = margin; - prepareGeometryChange(); + updateBoundingRect(); } void QgsLayoutItemLabel::adjustSizeToText() @@ -413,6 +436,8 @@ bool QgsLayoutItemLabel::readPropertiesFromElement( const QDomElement &itemElem, } } + updateBoundingRect(); + return true; } @@ -452,32 +477,7 @@ QString QgsLayoutItemLabel::displayName() const QRectF QgsLayoutItemLabel::boundingRect() const { - QRectF rectangle = rect(); - const double penWidth = frameEnabled() ? ( pen().widthF() / 2.0 ) : 0; - rectangle.adjust( -penWidth, -penWidth, penWidth, penWidth ); - - if ( mMarginX < 0 ) - { - rectangle.adjust( mMarginX, 0, -mMarginX, 0 ); - } - if ( mMarginY < 0 ) - { - rectangle.adjust( 0, mMarginY, 0, -mMarginY ); - } - - return rectangle; -} - -void QgsLayoutItemLabel::setFrameEnabled( const bool drawFrame ) -{ - QgsLayoutItem::setFrameEnabled( drawFrame ); - prepareGeometryChange(); -} - -void QgsLayoutItemLabel::setFrameStrokeWidth( const QgsLayoutMeasurement strokeWidth ) -{ - QgsLayoutItem::setFrameStrokeWidth( strokeWidth ); - prepareGeometryChange(); + return mCurrentRectangle; } void QgsLayoutItemLabel::refresh() diff --git a/src/core/layout/qgslayoutitemlabel.h b/src/core/layout/qgslayoutitemlabel.h index 16bbc4c34b3d..79a7f203dbbb 100644 --- a/src/core/layout/qgslayoutitemlabel.h +++ b/src/core/layout/qgslayoutitemlabel.h @@ -212,13 +212,6 @@ class CORE_EXPORT QgsLayoutItemLabel: public QgsLayoutItem // label's frame QRectF boundingRect() const override; - // Reimplemented to call prepareGeometryChange after toggling frame - void setFrameEnabled( bool drawFrame ) override; - - // Reimplemented to call prepareGeometryChange after changing stroke width - void setFrameStrokeWidth( QgsLayoutMeasurement strokeWidth ) override; - - /** * Returns the text format used for drawing text in the label. * \see setTextFormat() @@ -253,6 +246,8 @@ class CORE_EXPORT QgsLayoutItemLabel: public QgsLayoutItem private slots: void refreshExpressionContext(); + //! Updates the bounding rect of this item + void updateBoundingRect(); private: bool mFirstRender = true; @@ -297,6 +292,8 @@ class CORE_EXPORT QgsLayoutItemLabel: public QgsLayoutItem std::unique_ptr< QgsDistanceArea > mDistanceArea; + QRectF mCurrentRectangle; + friend class QgsLayoutItemHtml; }; diff --git a/src/core/layout/qgslayoutitemnodeitem.cpp b/src/core/layout/qgslayoutitemnodeitem.cpp index a54e6cd0c80f..696754e1eec6 100644 --- a/src/core/layout/qgslayoutitemnodeitem.cpp +++ b/src/core/layout/qgslayoutitemnodeitem.cpp @@ -344,10 +344,10 @@ void QgsLayoutNodesItem::updateBoundingRect() { QRectF br = rect(); br.adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed ); + prepareGeometryChange(); mCurrentRectangle = br; // update - prepareGeometryChange(); update(); } diff --git a/src/core/layout/qgslayoutitempage.cpp b/src/core/layout/qgslayoutitempage.cpp index c8e5e20d0a00..1c37ae9947b8 100644 --- a/src/core/layout/qgslayoutitempage.cpp +++ b/src/core/layout/qgslayoutitempage.cpp @@ -38,8 +38,8 @@ QgsLayoutItemPage::QgsLayoutItemPage( QgsLayout *layout ) connect( this, &QgsLayoutItem::sizePositionChanged, this, [ = ] { - mBoundingRect = QRectF(); prepareGeometryChange(); + mBoundingRect = QRectF(); } ); const QFont font; diff --git a/src/core/layout/qgslayoutitempolyline.cpp b/src/core/layout/qgslayoutitempolyline.cpp index 0eaedbdbb5e1..9d8b32e2a03e 100644 --- a/src/core/layout/qgslayoutitempolyline.cpp +++ b/src/core/layout/qgslayoutitempolyline.cpp @@ -467,10 +467,10 @@ void QgsLayoutItemPolyline::updateBoundingRect() margin += 0.5 * mArrowHeadWidth; } br.adjust( -margin, -margin, margin, margin ); + prepareGeometryChange(); mCurrentRectangle = br; // update - prepareGeometryChange(); update(); }