Skip to content

Commit 4a7813b

Browse files
committedJan 5, 2018
Restore picture atlas handling
1 parent fee1c21 commit 4a7813b

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed
 

‎python/core/layout/qgslayoutcontext.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ Emitted when the context's ``layer`` is changed.
235235
%Docstring
236236
Emitted certain settings in the context is changed, e.g. by setting a new feature or vector layer
237237
for the context.
238+
%End
239+
240+
void dpiChanged();
241+
%Docstring
242+
Emitted when the context's DPI is changed.
238243
%End
239244

240245
};

‎src/core/layout/qgslayoutcontext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ void QgsLayoutContext::setLayer( QgsVectorLayer *layer )
8989

9090
void QgsLayoutContext::setDpi( double dpi )
9191
{
92+
if ( dpi == mMeasurementConverter.dpi() )
93+
return;
94+
9295
mMeasurementConverter.setDpi( dpi );
96+
emit dpiChanged();
9397
}
9498

9599
double QgsLayoutContext::dpi() const

‎src/core/layout/qgslayoutcontext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ class CORE_EXPORT QgsLayoutContext : public QObject
236236
*/
237237
void changed();
238238

239+
/**
240+
* Emitted when the context's DPI is changed.
241+
*/
242+
void dpiChanged();
243+
239244
private:
240245

241246
Flags mFlags = nullptr;

‎src/core/layout/qgslayoutitempicture.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@ QgsLayoutItemPicture::QgsLayoutItemPicture( QgsLayout *layout )
5454

5555
//connect some signals
5656

57-
#if 0 //TODO
5857
//connect to atlas feature changing
5958
//to update the picture source expression
60-
connect( &mComposition->atlasComposition(), &QgsAtlasComposition::featureChanged, this, [ = ] { refreshPicture(); } );
59+
connect( &layout->context(), &QgsLayoutContext::changed, this, [ = ] { refreshPicture(); } );
6160

6261
//connect to layout print resolution changing
63-
connect( layout->context(), &QgsLayoutContext::printResolutionChanged, this, &QgsLayoutItemPicture::recalculateSize );
64-
#endif
62+
connect( &layout->context(), &QgsLayoutContext::dpiChanged, this, &QgsLayoutItemPicture::recalculateSize );
6563

6664
connect( this, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPicture::shapeChanged );
6765
}

‎tests/src/core/testqgslayoutcontext.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,17 @@ void TestQgsLayoutContext::layer()
145145
void TestQgsLayoutContext::dpi()
146146
{
147147
QgsLayoutContext context;
148+
149+
QSignalSpy spyDpiChanged( &context, &QgsLayoutContext::dpiChanged );
148150
context.setDpi( 600 );
149151
QCOMPARE( context.dpi(), 600.0 );
150152
QCOMPARE( context.measurementConverter().dpi(), 600.0 );
153+
QCOMPARE( spyDpiChanged.count(), 1 );
154+
155+
context.setDpi( 600 );
156+
QCOMPARE( spyDpiChanged.count(), 1 );
157+
context.setDpi( 6000 );
158+
QCOMPARE( spyDpiChanged.count(), 2 );
151159
}
152160

153161
void TestQgsLayoutContext::renderContextFlags()

0 commit comments

Comments
 (0)
Please sign in to comment.