Skip to content
Permalink
Browse files

Restore legend atlas behavior

  • Loading branch information
nyalldawson committed Dec 23, 2017
1 parent 2ef3a5f commit 3994c4a4764f499d0596d042cb8590afa83353cf
@@ -490,6 +490,7 @@ Returns the legend's renderer settings object.

public slots:

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


@@ -35,6 +35,7 @@
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgslayoutitemlegend.h"
#include "qgslayoutatlas.h"

#include <QMessageBox>
#include <QInputDialog>
@@ -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 );
@@ -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();
}
}

@@ -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 )
@@ -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.
@@ -139,6 +138,12 @@ void QgsLayoutItemLegend::finalizeRestoreFromXml()
}
}

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

void QgsLayoutItemLegend::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * )
{
QPainter *painter = context.painter();
@@ -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 );
}
@@ -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();
@@ -446,6 +446,7 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem

public slots:

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

protected:
@@ -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 );

0 comments on commit 3994c4a

Please sign in to comment.
You can’t perform that action at this time.