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
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ Returns the legend's renderer settings object.

public slots:

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


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

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

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

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

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

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

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

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

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

public slots:

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

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

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

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

Expand Down

0 comments on commit 3994c4a

Please sign in to comment.