Skip to content

Commit

Permalink
Restore legend atlas behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 2ef3a5f commit 3994c4a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions python/core/layout/qgslayoutitemlegend.sip
Expand Up @@ -490,6 +490,7 @@ Returns the legend's renderer settings object.


public slots: public slots:


void refresh();
virtual void refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties ); virtual void refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );




Expand Down
25 changes: 11 additions & 14 deletions src/app/layout/qgslayoutlegendwidget.cpp
Expand Up @@ -35,6 +35,7 @@
#include "qgsproject.h" #include "qgsproject.h"
#include "qgsvectorlayer.h" #include "qgsvectorlayer.h"
#include "qgslayoutitemlegend.h" #include "qgslayoutitemlegend.h"
#include "qgslayoutatlas.h"


#include <QMessageBox> #include <QMessageBox>
#include <QInputDialog> #include <QInputDialog>
Expand Down Expand Up @@ -136,11 +137,12 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend )
mItemTreeView->setMenuProvider( new QgsLayoutLegendMenuProvider( mItemTreeView, this ) ); mItemTreeView->setMenuProvider( new QgsLayoutLegendMenuProvider( mItemTreeView, this ) );
connect( legend, &QgsLayoutObject::changed, this, &QgsLayoutLegendWidget::setGuiElements ); connect( legend, &QgsLayoutObject::changed, this, &QgsLayoutLegendWidget::setGuiElements );


#if 0 //TODO
// connect atlas state to the filter legend by atlas checkbox // connect atlas state to the filter legend by atlas checkbox
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::toggled, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton ); if ( layoutAtlas() )
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::coverageLayerChanged, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton ); {
#endif connect( layoutAtlas(), &QgsLayoutAtlas::toggled, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
}
connect( &legend->layout()->context(), &QgsLayoutContext::layerChanged, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );


registerDataDefinedButton( mLegendTitleDDBtn, QgsLayoutObject::LegendTitle ); registerDataDefinedButton( mLegendTitleDDBtn, QgsLayoutObject::LegendTitle );
registerDataDefinedButton( mColumnsDDBtn, QgsLayoutObject::LegendColumnCount ); registerDataDefinedButton( mColumnsDDBtn, QgsLayoutObject::LegendColumnCount );
Expand Down Expand Up @@ -900,14 +902,9 @@ void QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled( bool toggled )
Q_UNUSED( toggled ); Q_UNUSED( toggled );
if ( mLegend ) if ( mLegend )
{ {
#if 0 //TODO
mLegend->setLegendFilterOutAtlas( toggled ); mLegend->setLegendFilterOutAtlas( toggled );
// force update of legend when in preview mode // force update of legend when in preview mode
if ( mLegend->composition()->atlasMode() == QgsComposition::PreviewAtlas ) mLegend->refresh();
{
mLegend->composition()->atlasComposition().refreshFeature();
}
#endif
} }
} }


Expand Down Expand Up @@ -1034,10 +1031,10 @@ void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()


void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton() void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton()
{ {
#if 0 //TODO if ( QgsLayoutAtlas *atlas = layoutAtlas() )
const QgsAtlasComposition &atlas = mLegend->composition()->atlasComposition(); {
mFilterLegendByAtlasCheckBox->setEnabled( atlas.enabled() && atlas.coverageLayer() && atlas.coverageLayer()->geometryType() == QgsWkbTypes::PolygonGeometry ); mFilterLegendByAtlasCheckBox->setEnabled( atlas->enabled() && mLegend->layout()->context().layer() && mLegend->layout()->context().layer()->geometryType() == QgsWkbTypes::PolygonGeometry );
#endif }
} }


void QgsLayoutLegendWidget::mItemTreeView_doubleClicked( const QModelIndex &idx ) void QgsLayoutLegendWidget::mItemTreeView_doubleClicked( const QModelIndex &idx )
Expand Down
15 changes: 9 additions & 6 deletions src/core/layout/qgslayoutitemlegend.cpp
Expand Up @@ -40,7 +40,6 @@ QgsLayoutItemLegend::QgsLayoutItemLegend( QgsLayout *layout )
{ {
#if 0 //TODO #if 0 //TODO
connect( &layout->atlasComposition(), &QgsAtlasComposition::renderEnded, this, &QgsLayoutItemLegend::onAtlasEnded ); connect( &layout->atlasComposition(), &QgsAtlasComposition::renderEnded, this, &QgsLayoutItemLegend::onAtlasEnded );
connect( &layout->atlasComposition(), &QgsAtlasComposition::featureChanged, this, &QgsLayoutItemLegend::onAtlasFeature );
#endif #endif


// Connect to the main layertreeroot. // Connect to the main layertreeroot.
Expand Down Expand Up @@ -139,6 +138,12 @@ void QgsLayoutItemLegend::finalizeRestoreFromXml()
} }
} }


void QgsLayoutItemLegend::refresh()
{
QgsLayoutItem::refresh();
onAtlasFeature();
}

void QgsLayoutItemLegend::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * ) void QgsLayoutItemLegend::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * )
{ {
QPainter *painter = context.painter(); QPainter *painter = context.painter();
Expand Down Expand Up @@ -761,9 +766,7 @@ void QgsLayoutItemLegend::doUpdateFilterByMap()
QgsGeometry filterPolygon; QgsGeometry filterPolygon;
if ( mInAtlas ) if ( mInAtlas )
{ {
#if 0 //TODO filterPolygon = mLayout->context().currentGeometry( mMap->crs() );
filterPolygon = composition()->atlasComposition().currentGeometry( mMap->crs() );
#endif
} }
mLegendModel->setLegendFilter( &ms, /* useExtent */ mInAtlas || mLegendFilterByMap, filterPolygon, /* useExpressions */ true ); mLegendModel->setLegendFilter( &ms, /* useExtent */ mInAtlas || mLegendFilterByMap, filterPolygon, /* useExpressions */ true );
} }
Expand All @@ -783,9 +786,9 @@ bool QgsLayoutItemLegend::legendFilterOutAtlas() const
return mFilterOutAtlas; return mFilterOutAtlas;
} }


void QgsLayoutItemLegend::onAtlasFeature( QgsFeature *feat ) void QgsLayoutItemLegend::onAtlasFeature()
{ {
if ( !feat ) if ( !mLayout->context().feature().isValid() )
return; return;
mInAtlas = mFilterOutAtlas; mInAtlas = mFilterOutAtlas;
updateFilterByMap(); updateFilterByMap();
Expand Down
3 changes: 2 additions & 1 deletion src/core/layout/qgslayoutitemlegend.h
Expand Up @@ -446,6 +446,7 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem


public slots: public slots:


void refresh();
void refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties ) override; void refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties ) override;


protected: protected:
Expand All @@ -469,7 +470,7 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem


//! react to atlas //! react to atlas
void onAtlasEnded(); void onAtlasEnded();
void onAtlasFeature( QgsFeature * ); void onAtlasFeature();


void nodeCustomPropertyChanged( QgsLayerTreeNode *node, const QString &key ); void nodeCustomPropertyChanged( QgsLayerTreeNode *node, const QString &key );


Expand Down

0 comments on commit 3994c4a

Please sign in to comment.