Skip to content
Permalink
Browse files

Restore attribute table atlas handling

  • Loading branch information
nyalldawson committed Dec 20, 2017
1 parent b602b3d commit e72e20b8e07ca42bf820de2e93708dbd5c1e88c7
@@ -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();
@@ -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

};

@@ -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

};

@@ -16,7 +16,7 @@
***************************************************************************/

#include "qgslayoutattributetablewidget.h"
#include "qgsatlascomposition.h"
#include "qgslayoutatlas.h"
#include "qgslayout.h"
#include "qgslayoutframe.h"
#include "qgslayoutattributeselectiondialog.h"
@@ -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 );

@@ -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
@@ -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 )
@@ -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() );
}
@@ -521,7 +514,7 @@ void QgsLayoutAttributeTableWidget::updateRelationsCombo()
mRelationsComboBox->setCurrentIndex( mRelationsComboBox->findData( mTable->relationId() ) );
}
}
#endif

mRelationsComboBox->blockSignals( false );
}

@@ -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 )
@@ -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;
@@ -83,6 +83,7 @@ QgsVectorLayer *QgsLayoutContext::layer() const
void QgsLayoutContext::setLayer( QgsVectorLayer *layer )
{
mLayer = layer;
emit layerChanged( layer );
emit changed();
}

@@ -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.
@@ -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();
}
@@ -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
@@ -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 );
}

@@ -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() );
}

@@ -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;
@@ -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:
@@ -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();
@@ -18,6 +18,8 @@
#include "qgslayout.h"
#include "qgsproject.h"
#include "qgslayoutundostack.h"
#include "qgsprintlayout.h"
#include "qgslayoutatlas.h"

//
// QgsLayoutConfigObject
@@ -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()
@@ -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 )
@@ -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
{
@@ -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


//

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

0 comments on commit e72e20b

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