Skip to content

Commit

Permalink
Restore attribute table atlas handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent b602b3d commit e72e20b
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 111 deletions.
5 changes: 5 additions & 0 deletions python/core/layout/qgslayoutcontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ If ``layer`` is -1, all item layers should be rendered.
Emitted whenever the context's ``flags`` change.

.. seealso:: :py:func:`setFlags()`
%End

void layerChanged( QgsVectorLayer *layer );
%Docstring
Emitted when the context's ``layer`` is changed.
%End

void changed();
Expand Down
9 changes: 8 additions & 1 deletion python/gui/layout/qgslayoutitemwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Updates a data defined button to reflect the item's current properties.
Returns the current layout context coverage layer (if set).
%End

QgsLayoutAtlas *layoutAtlas() const;
%Docstring
Returns the atlas for the layout, if available
%End

};

Expand Down Expand Up @@ -117,7 +121,10 @@ Implementations must return true if the item was accepted and
the widget was updated.
%End


QgsLayoutAtlas *layoutAtlas() const;
%Docstring
Returns the atlas for the layout (if available)
%End

};

Expand Down
35 changes: 14 additions & 21 deletions src/app/layout/qgslayoutattributetablewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
***************************************************************************/

#include "qgslayoutattributetablewidget.h"
#include "qgsatlascomposition.h"
#include "qgslayoutatlas.h"
#include "qgslayout.h"
#include "qgslayoutframe.h"
#include "qgslayoutattributeselectiondialog.h"
Expand Down Expand Up @@ -87,10 +87,7 @@ QgsLayoutAttributeTableWidget::QgsLayoutAttributeTableWidget( QgsLayoutFrame *fr
mWrapBehaviorComboBox->addItem( tr( "Truncate text" ), QgsLayoutTable::TruncateText );
mWrapBehaviorComboBox->addItem( tr( "Wrap text" ), QgsLayoutTable::WrapText );

bool atlasEnabled = false;
#if 0 //TODO
atlasComposition() &&atlasComposition()->enabled();
#endif
bool atlasEnabled = layoutAtlas() && layoutAtlas()->enabled();
mSourceComboBox->addItem( tr( "Layer features" ), QgsLayoutItemAttributeTable::LayerAttributes );
toggleAtlasSpecificControls( atlasEnabled );

Expand Down Expand Up @@ -126,16 +123,14 @@ QgsLayoutAttributeTableWidget::QgsLayoutAttributeTableWidget( QgsLayoutFrame *fr
{
connect( mTable, &QgsLayoutMultiFrame::changed, this, &QgsLayoutAttributeTableWidget::updateGuiElements );

#if 0 //TODO
QgsAtlasComposition *atlas = atlasComposition();
if ( atlas )
// repopulate relations combo box if atlas layer changes
connect( &mTable->layout()->context(), &QgsLayoutContext::layerChanged,
this, &QgsLayoutAttributeTableWidget::updateRelationsCombo );

if ( QgsLayoutAtlas *atlas = layoutAtlas() )
{
// repopulate relations combo box if atlas layer changes
connect( atlas, &QgsAtlasComposition::coverageLayerChanged,
this, &QgsLayoutAttributeTableWidget::updateRelationsCombo );
connect( atlas, &QgsAtlasComposition::toggled, this, &QgsLayoutAttributeTableWidget::atlasToggled );
connect( atlas, &QgsLayoutAtlas::toggled, this, &QgsLayoutAttributeTableWidget::atlasToggled );
}
#endif
}

//embed widget for general options
Expand Down Expand Up @@ -486,9 +481,8 @@ void QgsLayoutAttributeTableWidget::updateGuiElements()

void QgsLayoutAttributeTableWidget::atlasToggled()
{
#if 0 //TODO
//display/hide atlas options in source combobox depending on atlas status
bool atlasEnabled = atlasComposition() && atlasComposition()->enabled();
bool atlasEnabled = layoutAtlas() && layoutAtlas()->enabled();
toggleAtlasSpecificControls( atlasEnabled );

if ( !mTable )
Expand All @@ -500,19 +494,18 @@ void QgsLayoutAttributeTableWidget::atlasToggled()
{
mTable->setFilterToAtlasFeature( false );
}
#endif
}

void QgsLayoutAttributeTableWidget::updateRelationsCombo()
{
mRelationsComboBox->blockSignals( true );
mRelationsComboBox->clear();
#if 0 //TODO
QgsVectorLayer *atlasLayer = atlasCoverageLayer();

QgsVectorLayer *atlasLayer = coverageLayer();
if ( atlasLayer )
{
QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( atlasLayer );
Q_FOREACH ( const QgsRelation &relation, relations )
const QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( atlasLayer );
for ( const QgsRelation &relation : relations )
{
mRelationsComboBox->addItem( relation.name(), relation.id() );
}
Expand All @@ -521,7 +514,7 @@ void QgsLayoutAttributeTableWidget::updateRelationsCombo()
mRelationsComboBox->setCurrentIndex( mRelationsComboBox->findData( mTable->relationId() ) );
}
}
#endif

mRelationsComboBox->blockSignals( false );
}

Expand Down
7 changes: 2 additions & 5 deletions src/app/layout/qgslayoutlabelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,10 @@ void QgsLayoutLabelWidget::mInsertExpressionButton_clicked()
selText = selText.mid( 2, selText.size() - 4 );

// use the atlas coverage layer, if any
#if 0 //TODO
QgsVectorLayer *coverageLayer = atlasCoverageLayer();
#endif
QgsVectorLayer *coverageLayer = nullptr;
QgsVectorLayer *layer = coverageLayer();

QgsExpressionContext context = mLabel->createExpressionContext();
QgsExpressionBuilderDialog exprDlg( coverageLayer, selText, this, QStringLiteral( "generic" ), context );
QgsExpressionBuilderDialog exprDlg( layer, selText, this, QStringLiteral( "generic" ), context );

exprDlg.setWindowTitle( tr( "Insert Expression" ) );
if ( exprDlg.exec() == QDialog::Accepted )
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutatlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ bool QgsLayoutAtlas::readXml( const QDomElement &atlasElem, const QDomDocument &

mCoverageLayer = QgsVectorLayerRef( layerId, layerName, layerSource, layerProvider );
mCoverageLayer.resolveWeakly( mLayout->project() );
mLayout->context().setLayer( mCoverageLayer.get() );

mPageNameExpression = atlasElem.attribute( QStringLiteral( "pageNameExpression" ), QString() );
QString error;
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ QgsVectorLayer *QgsLayoutContext::layer() const
void QgsLayoutContext::setLayer( QgsVectorLayer *layer )
{
mLayer = layer;
emit layerChanged( layer );
emit changed();
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ class CORE_EXPORT QgsLayoutContext : public QObject
*/
void flagsChanged( QgsLayoutContext::Flags flags );

/**
* Emitted when the context's \a layer is changed.
*/
void layerChanged( QgsVectorLayer *layer );

/**
* Emitted certain settings in the context is changed, e.g. by setting a new feature or vector layer
* for the context.
Expand Down
52 changes: 8 additions & 44 deletions src/core/layout/qgslayoutitemattributetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,8 @@ QgsLayoutItemAttributeTable::QgsLayoutItemAttributeTable( QgsLayout *layout )
{
connect( mLayout->project(), static_cast < void ( QgsProject::* )( const QString & ) >( &QgsProject::layerWillBeRemoved ), this, &QgsLayoutItemAttributeTable::removeLayer );

#if 0 //TODO
//connect to atlas feature changes to update table rows
connect( &mComposition->atlasComposition(), &QgsAtlasComposition::featureChanged, this, &QgsLayoutTable::refreshAttributes );

//atlas coverage layer change = regenerate columns
connect( &mComposition->atlasComposition(), &QgsAtlasComposition::coverageLayerChanged, this, &QgsLayoutItemAttributeTable::atlasLayerChanged );
#endif
//coverage layer change = regenerate columns
connect( &mLayout->context(), &QgsLayoutContext::layerChanged, this, &QgsLayoutItemAttributeTable::atlasLayerChanged );
}
refreshAttributes();
}
Expand Down Expand Up @@ -394,17 +389,7 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
{
contents.clear();

if ( ( mSource == QgsLayoutItemAttributeTable::AtlasFeature || mSource == QgsLayoutItemAttributeTable::RelationChildren ) )
#if 0 //TODO
// && !mComposition->atlasComposition().enabled() )
#endif
{
//source mode requires atlas, but atlas disabled
return false;
}

QgsVectorLayer *layer = sourceLayer();

if ( !layer )
{
//no source layer
Expand Down Expand Up @@ -451,10 +436,7 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
if ( mSource == QgsLayoutItemAttributeTable::RelationChildren )
{
QgsRelation relation = mLayout->project()->relationManager()->relation( mRelationId );
QgsFeature atlasFeature;
#if 0 //TODO
= mLayout->atlasComposition().feature();
#endif
QgsFeature atlasFeature = mLayout->context().feature();
req = relation.getRelatedFeaturesRequest( atlasFeature );
}

Expand All @@ -464,15 +446,9 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );

if ( mSource == QgsLayoutItemAttributeTable::AtlasFeature )
#if 0 // TODO
&& mComposition->atlasComposition().enabled() )
#endif
{
//source mode is current atlas feature
QgsFeature atlasFeature;
#if 0 //TODO
= mLayout->atlasComposition().feature();
#endif
QgsFeature atlasFeature = mLayout->context().feature();
req.setFilterFid( atlasFeature.id() );
}

Expand All @@ -497,18 +473,12 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
if ( mFilterToAtlasIntersection )
{
if ( !f.hasGeometry() )
#if 0 //TODO
|| ! mComposition->atlasComposition().enabled() )
#endif
{
continue;
}
QgsFeature atlasFeature;
#if 0 //TODO
= mComposition->atlasComposition().feature();
#endif
QgsFeature atlasFeature = mLayout->context().feature();
if ( !atlasFeature.hasGeometry() ||
!f.geometry().intersects( atlasFeature.geometry() ) )
!f.geometry().intersects( atlasFeature.geometry() ) )
{
//feature falls outside current atlas feature
continue;
Expand Down Expand Up @@ -584,10 +554,7 @@ QgsVectorLayer *QgsLayoutItemAttributeTable::sourceLayer()
switch ( mSource )
{
case QgsLayoutItemAttributeTable::AtlasFeature:
#if 0 //TODO
return mComposition->atlasComposition().coverageLayer();
#endif
return nullptr;
return mLayout->context().layer();
case QgsLayoutItemAttributeTable::LayerAttributes:
return mVectorLayer.get();
case QgsLayoutItemAttributeTable::RelationChildren:
Expand Down Expand Up @@ -704,10 +671,7 @@ bool QgsLayoutItemAttributeTable::readPropertiesFromElement( const QDomElement &

if ( mSource == QgsLayoutItemAttributeTable::AtlasFeature )
{
mCurrentAtlasLayer = nullptr;
#if 0 //TODO
mComposition->atlasComposition().coverageLayer();
#endif
mCurrentAtlasLayer = mLayout->context().layer();
}

mShowUniqueRowsOnly = itemElem.attribute( QStringLiteral( "showUniqueRowsOnly" ), QStringLiteral( "0" ) ).toInt();
Expand Down
44 changes: 20 additions & 24 deletions src/gui/layout/qgslayoutitemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "qgslayout.h"
#include "qgsproject.h"
#include "qgslayoutundostack.h"
#include "qgsprintlayout.h"
#include "qgslayoutatlas.h"

//
// QgsLayoutConfigObject
Expand All @@ -27,11 +29,15 @@ QgsLayoutConfigObject::QgsLayoutConfigObject( QWidget *parent, QgsLayoutObject *
: QObject( parent )
, mLayoutObject( layoutObject )
{
#if 0 //TODO
connect( atlasComposition(), &QgsAtlasComposition::coverageLayerChanged,
this, [ = ] { updateDataDefinedButtons(); } );
connect( atlasComposition(), &QgsAtlasComposition::toggled, this, &QgsComposerConfigObject::updateDataDefinedButtons );
#endif
if ( mLayoutObject->layout() )
{
connect( &mLayoutObject->layout()->context(), &QgsLayoutContext::layerChanged,
this, [ = ] { updateDataDefinedButtons(); } );
}
if ( layoutAtlas() )
{
connect( layoutAtlas(), &QgsLayoutAtlas::toggled, this, &QgsLayoutConfigObject::updateDataDefinedButtons );
}
}

void QgsLayoutConfigObject::updateDataDefinedProperty()
Expand Down Expand Up @@ -62,12 +68,11 @@ void QgsLayoutConfigObject::updateDataDefinedProperty()

void QgsLayoutConfigObject::updateDataDefinedButtons()
{
#if 0 //TODO
Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
for ( QgsPropertyOverrideButton *button : buttons )
{
button->setVectorLayer( atlasCoverageLayer() );
button->setVectorLayer( coverageLayer() );
}
#endif
}

void QgsLayoutConfigObject::initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty key )
Expand All @@ -91,24 +96,22 @@ void QgsLayoutConfigObject::updateDataDefinedButton( QgsPropertyOverrideButton *
whileBlocking( button )->setToProperty( mLayoutObject->dataDefinedProperties().property( key ) );
}

#if 0 // TODO
QgsAtlasComposition *QgsLayoutConfigObject::atlasComposition() const
QgsLayoutAtlas *QgsLayoutConfigObject::layoutAtlas() const
{
if ( !mLayoutObject )
{
return nullptr;
}

QgsComposition *composition = mComposerObject->composition();
QgsPrintLayout *printLayout = qobject_cast< QgsPrintLayout * >( mLayoutObject->layout() );

if ( !composition )
if ( !printLayout )
{
return nullptr;
}

return &composition->atlasComposition();
return printLayout->atlas();
}
#endif

QgsVectorLayer *QgsLayoutConfigObject::coverageLayer() const
{
Expand Down Expand Up @@ -171,13 +174,10 @@ bool QgsLayoutItemBaseWidget::setNewItem( QgsLayoutItem * )
return false;
}

#if 0 //TODO
QgsAtlasComposition *QgsLayoutItemBaseWidget::atlasComposition() const
QgsLayoutAtlas *QgsLayoutItemBaseWidget::layoutAtlas() const
{
return mConfigObject->atlasComposition();
return mConfigObject->layoutAtlas();
}
#endif


//

Expand Down Expand Up @@ -259,10 +259,6 @@ QgsLayoutItemPropertiesWidget::QgsLayoutItemPropertiesWidget( QWidget *parent, Q

initializeDataDefinedButtons();

#if 0 //TODO
connect( mItem->composition(), &QgsComposition::paperSizeChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
#endif

setItem( item );

connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsLayoutItemPropertiesWidget::opacityChanged );
Expand Down

0 comments on commit e72e20b

Please sign in to comment.