Skip to content

Commit b594ecd

Browse files
committed
Fix missing page shadows
1 parent 54acc80 commit b594ecd

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

python/core/layout/qgslayoutitempage.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ will be set to true if string could be successfully interpreted as a
9191
page orientation.
9292
%End
9393

94-
virtual void attemptResize( const QgsLayoutSize &size, bool includesFrame = false );
94+
virtual QRectF boundingRect() const;
9595

96+
virtual void attemptResize( const QgsLayoutSize &size, bool includesFrame = false );
9697

9798
virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = 0 ) /Factory/;
9899

src/core/layout/qgslayoutitempage.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ QgsLayoutItemPage::QgsLayoutItemPage( QgsLayout *layout )
3232
setFlag( QGraphicsItem::ItemIsMovable, false );
3333
setZValue( QgsLayout::ZPage );
3434

35-
// use a hidden pen to specify the amount the page "bleeds" outside it's scene bounds,
36-
// (it's a lot easier than reimplementing boundingRect() just to handle this)
37-
QPen shadowPen( QBrush( Qt::transparent ), layout->pageCollection()->pageShadowWidth() * 2 );
38-
setPen( shadowPen );
35+
connect( this, &QgsLayoutItem::sizePositionChanged, this, [ = ]
36+
{
37+
mBoundingRect = QRectF();
38+
prepareGeometryChange();
39+
} );
3940

4041
QFont font;
4142
QFontMetrics fm( font );
@@ -123,6 +124,17 @@ QgsLayoutItemPage::Orientation QgsLayoutItemPage::decodePageOrientation( const Q
123124
return Landscape;
124125
}
125126

127+
QRectF QgsLayoutItemPage::boundingRect() const
128+
{
129+
if ( mBoundingRect.isNull() )
130+
{
131+
double shadowWidth = mLayout->pageCollection()->pageShadowWidth();
132+
mBoundingRect = rect();
133+
mBoundingRect.adjust( 0, 0, shadowWidth, shadowWidth );
134+
}
135+
return mBoundingRect;
136+
}
137+
126138
void QgsLayoutItemPage::attemptResize( const QgsLayoutSize &size, bool includesFrame )
127139
{
128140
QgsLayoutItem::attemptResize( size, includesFrame );

src/core/layout/qgslayoutitempage.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class CORE_EXPORT QgsLayoutItemPage : public QgsLayoutItem
121121
*/
122122
static QgsLayoutItemPage::Orientation decodePageOrientation( const QString &string, bool *ok SIP_OUT = nullptr );
123123

124+
QRectF boundingRect() const override;
124125
void attemptResize( const QgsLayoutSize &size, bool includesFrame = false ) override;
125-
126126
QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
127127

128128
public slots:
@@ -140,6 +140,7 @@ class CORE_EXPORT QgsLayoutItemPage : public QgsLayoutItem
140140
double mMaximumShadowWidth = -1;
141141

142142
std::unique_ptr< QgsLayoutItemPageGrid > mGrid;
143+
mutable QRectF mBoundingRect;
143144

144145
friend class TestQgsLayoutPage;
145146
};

0 commit comments

Comments
 (0)