Skip to content

Commit

Permalink
[layouts] Avoid resetting column selection when restoring project
Browse files Browse the repository at this point in the history
with an atttribute table set to the "atlas feature" source

Fixes #20538
  • Loading branch information
nyalldawson committed May 22, 2019
1 parent fbd3289 commit 810b522
Show file tree
Hide file tree
Showing 3 changed files with 567 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/layout/qgslayoutitemattributetable.cpp
Expand Up @@ -183,10 +183,15 @@ void QgsLayoutItemAttributeTable::atlasLayerChanged( QgsVectorLayer *layer )
disconnect( mCurrentAtlasLayer, &QgsVectorLayer::layerModified, this, &QgsLayoutTable::refreshAttributes );
}

const bool mustRebuildColumns = static_cast< bool >( mCurrentAtlasLayer ) || mColumns.empty();
mCurrentAtlasLayer = layer;

//rebuild column list to match all columns from layer
resetColumns();
if ( mustRebuildColumns )
{
//rebuild column list to match all columns from layer
resetColumns();
}

refreshAttributes();

//listen for modifications to layer and refresh table when they occur
Expand Down
21 changes: 21 additions & 0 deletions tests/src/core/testqgslayouttable.cpp
Expand Up @@ -31,6 +31,9 @@
#include "qgsrelationmanager.h"
#include "qgsreadwritecontext.h"
#include "qgsexpressioncontextutils.h"
#include "qgslayoutmanager.h"
#include "qgsprintlayout.h"
#include "qgslayoutatlas.h"

#include <QObject>
#include "qgstest.h"
Expand Down Expand Up @@ -60,6 +63,7 @@ class TestQgsLayoutTable : public QObject
void attributeTableExtend();
void attributeTableRepeat();
void attributeTableAtlasSource(); //test attribute table in atlas feature mode
void attributeTableRestoreAtlasSource();
void attributeTableRelationSource(); //test attribute table in relation mode
void contentsContainsRow(); //test the contentsContainsRow function
void removeDuplicates(); //test removing duplicate rows
Expand Down Expand Up @@ -610,6 +614,23 @@ void TestQgsLayoutTable::attributeTableAtlasSource()

}

void TestQgsLayoutTable::attributeTableRestoreAtlasSource()
{
const QString projectPath = QStringLiteral( TEST_DATA_DIR ) + "/layout_atlas_table.qgs";
QgsProject p;
p.read( projectPath );

QgsPrintLayout *l = dynamic_cast< QgsPrintLayout *>( p.layoutManager()->layouts().at( 0 ) );
QgsLayoutItemAttributeTable *table = qobject_cast< QgsLayoutItemAttributeTable * >( l->multiFrames().at( 0 ) );
QCOMPARE( table->source(), QgsLayoutItemAttributeTable::AtlasFeature );
QVERIFY( l->atlas()->coverageLayer() );
QVERIFY( l->atlas()->coverageLayer()->isValid() );
QCOMPARE( table->sourceLayer(), l->atlas()->coverageLayer() );
QCOMPARE( table->columns().count(), 2 );
QCOMPARE( table->columns().at( 0 )->attribute(), QStringLiteral( "Heading" ) );
QCOMPARE( table->columns().at( 1 )->attribute(), QStringLiteral( "Staff" ) );
}


void TestQgsLayoutTable::attributeTableRelationSource()
{
Expand Down

0 comments on commit 810b522

Please sign in to comment.