Skip to content

Commit

Permalink
Restore picture atlas handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent fee1c21 commit 4a7813b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions python/core/layout/qgslayoutcontext.sip
Expand Up @@ -235,6 +235,11 @@ Emitted when the context's ``layer`` is changed.
%Docstring
Emitted certain settings in the context is changed, e.g. by setting a new feature or vector layer
for the context.
%End

void dpiChanged();
%Docstring
Emitted when the context's DPI is changed.
%End

};
Expand Down
4 changes: 4 additions & 0 deletions src/core/layout/qgslayoutcontext.cpp
Expand Up @@ -89,7 +89,11 @@ void QgsLayoutContext::setLayer( QgsVectorLayer *layer )

void QgsLayoutContext::setDpi( double dpi )
{
if ( dpi == mMeasurementConverter.dpi() )
return;

mMeasurementConverter.setDpi( dpi );
emit dpiChanged();
}

double QgsLayoutContext::dpi() const
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutcontext.h
Expand Up @@ -236,6 +236,11 @@ class CORE_EXPORT QgsLayoutContext : public QObject
*/
void changed();

/**
* Emitted when the context's DPI is changed.
*/
void dpiChanged();

private:

Flags mFlags = nullptr;
Expand Down
6 changes: 2 additions & 4 deletions src/core/layout/qgslayoutitempicture.cpp
Expand Up @@ -54,14 +54,12 @@ QgsLayoutItemPicture::QgsLayoutItemPicture( QgsLayout *layout )

//connect some signals

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

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

connect( this, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPicture::shapeChanged );
}
Expand Down
8 changes: 8 additions & 0 deletions tests/src/core/testqgslayoutcontext.cpp
Expand Up @@ -145,9 +145,17 @@ void TestQgsLayoutContext::layer()
void TestQgsLayoutContext::dpi()
{
QgsLayoutContext context;

QSignalSpy spyDpiChanged( &context, &QgsLayoutContext::dpiChanged );
context.setDpi( 600 );
QCOMPARE( context.dpi(), 600.0 );
QCOMPARE( context.measurementConverter().dpi(), 600.0 );
QCOMPARE( spyDpiChanged.count(), 1 );

context.setDpi( 600 );
QCOMPARE( spyDpiChanged.count(), 1 );
context.setDpi( 6000 );
QCOMPARE( spyDpiChanged.count(), 2 );
}

void TestQgsLayoutContext::renderContextFlags()
Expand Down

0 comments on commit 4a7813b

Please sign in to comment.