@@ -51,7 +51,6 @@ bool QgsComposerAttributeTableCompareV2::operator()( const QgsComposerTableRow &
51
51
QgsComposerAttributeTableV2::QgsComposerAttributeTableV2 ( QgsComposition *composition, bool createUndoCommands )
52
52
: QgsComposerTableV2( composition, createUndoCommands )
53
53
, mSource( LayerAttributes )
54
- , mVectorLayer( nullptr )
55
54
, mCurrentAtlasLayer( nullptr )
56
55
, mComposerMap( nullptr )
57
56
, mMaximumNumberOfFeatures( 30 )
@@ -69,15 +68,15 @@ QgsComposerAttributeTableV2::QgsComposerAttributeTableV2( QgsComposition *compos
69
68
QgsVectorLayer *vl = dynamic_cast <QgsVectorLayer *>( mapIt.value () );
70
69
if ( vl )
71
70
{
72
- mVectorLayer = vl ;
71
+ mVectorLayer . setLayer ( vl ) ;
73
72
break ;
74
73
}
75
74
}
76
75
if ( mVectorLayer )
77
76
{
78
77
resetColumns ();
79
78
// listen for modifications to layer and refresh table when they occur
80
- connect ( mVectorLayer , &QgsVectorLayer::layerModified, this , &QgsComposerTableV2::refreshAttributes );
79
+ connect ( & mVectorLayer , &QgsVectorLayer::layerModified, this , &QgsComposerTableV2::refreshAttributes );
81
80
}
82
81
83
82
if ( mComposition )
@@ -103,14 +102,14 @@ QString QgsComposerAttributeTableV2::displayName() const
103
102
104
103
void QgsComposerAttributeTableV2::setVectorLayer ( QgsVectorLayer *layer )
105
104
{
106
- if ( layer == mVectorLayer )
105
+ if ( layer == & mVectorLayer )
107
106
{
108
107
// no change
109
108
return ;
110
109
}
111
110
112
111
QgsVectorLayer *prevLayer = sourceLayer ();
113
- mVectorLayer = layer;
112
+ mVectorLayer . setLayer ( layer ) ;
114
113
115
114
if ( mSource == QgsComposerAttributeTableV2::LayerAttributes && layer != prevLayer )
116
115
{
@@ -124,7 +123,7 @@ void QgsComposerAttributeTableV2::setVectorLayer( QgsVectorLayer *layer )
124
123
resetColumns ();
125
124
126
125
// listen for modifications to layer and refresh table when they occur
127
- connect ( mVectorLayer , &QgsVectorLayer::layerModified, this , &QgsComposerTableV2::refreshAttributes );
126
+ connect ( & mVectorLayer , &QgsVectorLayer::layerModified, this , &QgsComposerTableV2::refreshAttributes );
128
127
}
129
128
130
129
refreshAttributes ();
@@ -539,7 +538,7 @@ QgsExpressionContext QgsComposerAttributeTableV2::createExpressionContext() cons
539
538
540
539
if ( mSource == LayerAttributes )
541
540
{
542
- context.appendScope ( QgsExpressionContextUtils::layerScope ( mVectorLayer ) );
541
+ context.appendScope ( QgsExpressionContextUtils::layerScope ( & mVectorLayer ) );
543
542
}
544
543
545
544
return context;
@@ -563,7 +562,7 @@ QgsVectorLayer *QgsComposerAttributeTableV2::sourceLayer()
563
562
case QgsComposerAttributeTableV2::AtlasFeature:
564
563
return mComposition ->atlasComposition ().coverageLayer ();
565
564
case QgsComposerAttributeTableV2::LayerAttributes:
566
- return mVectorLayer ;
565
+ return & mVectorLayer ;
567
566
case QgsComposerAttributeTableV2::RelationChildren:
568
567
{
569
568
QgsRelation relation = mComposition ->project ()->relationManager ()->relation ( mRelationId );
@@ -579,7 +578,7 @@ void QgsComposerAttributeTableV2::removeLayer( const QString &layerId )
579
578
{
580
579
if ( layerId == mVectorLayer ->id () )
581
580
{
582
- mVectorLayer = nullptr ;
581
+ mVectorLayer . setLayer ( nullptr ) ;
583
582
// remove existing columns
584
583
qDeleteAll ( mColumns );
585
584
mColumns .clear ();
@@ -657,7 +656,10 @@ bool QgsComposerAttributeTableV2::writeXml( QDomElement &elem, QDomDocument &doc
657
656
}
658
657
if ( mVectorLayer )
659
658
{
660
- composerTableElem.setAttribute ( QStringLiteral ( " vectorLayer" ), mVectorLayer ->id () );
659
+ composerTableElem.setAttribute ( QStringLiteral ( " vectorLayer" ), mVectorLayer .layerId );
660
+ composerTableElem.setAttribute ( QStringLiteral ( " vectorLayerName" ), mVectorLayer .name );
661
+ composerTableElem.setAttribute ( QStringLiteral ( " vectorLayerSource" ), mVectorLayer .source );
662
+ composerTableElem.setAttribute ( QStringLiteral ( " vectorLayerProvider" ), mVectorLayer .provider );
661
663
}
662
664
663
665
bool ok = QgsComposerTableV2::writeXml ( composerTableElem, doc, ignoreFrames );
@@ -726,19 +728,12 @@ bool QgsComposerAttributeTableV2::readXml( const QDomElement &itemElem, const QD
726
728
}
727
729
728
730
// vector layer
729
- QString layerId = itemElem.attribute ( QStringLiteral ( " vectorLayer" ), QStringLiteral ( " not_existing" ) );
730
- if ( layerId == QLatin1String ( " not_existing" ) )
731
- {
732
- mVectorLayer = nullptr ;
733
- }
734
- else
735
- {
736
- QgsMapLayer *ml = mComposition ->project ()->mapLayer ( layerId );
737
- if ( ml )
738
- {
739
- mVectorLayer = dynamic_cast <QgsVectorLayer *>( ml );
740
- }
741
- }
731
+ QString layerId = itemElem.attribute ( QStringLiteral ( " vectorLayer" ) );
732
+ QString layerName = itemElem.attribute ( QStringLiteral ( " vectorLayerName" ) );
733
+ QString layerSource = itemElem.attribute ( QStringLiteral ( " vectorLayerSource" ) );
734
+ QString layerProvider = itemElem.attribute ( QStringLiteral ( " vectorLayerProvider" ) );
735
+ mVectorLayer = QgsVectorLayerRef ( layerId, layerName, layerSource, layerProvider );
736
+ mVectorLayer .resolveWeakly ( mComposition ->project () );
742
737
743
738
// connect to new layer
744
739
connect ( sourceLayer (), &QgsVectorLayer::layerModified, this , &QgsComposerTableV2::refreshAttributes );
0 commit comments