Skip to content

Commit

Permalink
make QgsProcessingContext member variable in vector tile layers wrapper
Browse files Browse the repository at this point in the history
to avoid dangling pointers
  • Loading branch information
alexbruy authored and nyalldawson committed Nov 1, 2020
1 parent 5271ca2 commit c79ebcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Expand Up @@ -24,7 +24,6 @@

#include "qgspanelwidget.h"

#include "qgsprocessingcontext.h"
#include "qgsvectortilewriter.h"

#include "qgsprocessingparametervectortilewriterlayers.h"
Expand All @@ -39,10 +38,9 @@ QgsProcessingVectorTileWriteLayerDetailsWidget::QgsProcessingVectorTileWriteLaye
{
setupUi( this );

QgsProcessingContext context;
context.setProject( project );
mContext.setProject( project );

QgsVectorTileWriter::Layer layer = QgsProcessingParameterVectorTileWriterLayers::variantMapAsLayer( value.toMap(), context );
QgsVectorTileWriter::Layer layer = QgsProcessingParameterVectorTileWriterLayers::variantMapAsLayer( value.toMap(), mContext );
mLayer = layer.layer();

if ( !mLayer )
Expand Down Expand Up @@ -99,15 +97,13 @@ QgsProcessingVectorTileWriterLayersPanelWidget::QgsProcessingVectorTileWriterLay
buttonBox()->addButton( copyLayerButton, QDialogButtonBox::ActionRole );

// populate the list: first layers already selected, then layers from project not yet selected

QgsProcessingContext context;
context.setProject( project );
mContext.setProject( project );

QSet<const QgsVectorLayer *> seenVectorLayers;
const QVariantList valueList = value.toList();
for ( const QVariant &v : valueList )
{
QgsVectorTileWriter::Layer layer = QgsProcessingParameterVectorTileWriterLayers::variantMapAsLayer( v.toMap(), context );
QgsVectorTileWriter::Layer layer = QgsProcessingParameterVectorTileWriterLayers::variantMapAsLayer( v.toMap(), mContext );
if ( !layer.layer() )
continue; // skip any invalid layers

Expand All @@ -131,7 +127,6 @@ QgsProcessingVectorTileWriterLayersPanelWidget::QgsProcessingVectorTileWriterLay
}
}


void QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer()
{
const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
Expand Down Expand Up @@ -172,7 +167,6 @@ void QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer()
setItemValue( item, widget->value() );
}
}

}

void QgsProcessingVectorTileWriterLayersPanelWidget::copyLayer()
Expand All @@ -191,10 +185,9 @@ void QgsProcessingVectorTileWriterLayersPanelWidget::copyLayer()

void QgsProcessingVectorTileWriterLayersPanelWidget::setItemValue( QStandardItem *item, const QVariant &value )
{
QgsProcessingContext context;
context.setProject( mProject );
mContext.setProject( mProject );

QgsVectorTileWriter::Layer layer = QgsProcessingParameterVectorTileWriterLayers::variantMapAsLayer( value.toMap(), context );
QgsVectorTileWriter::Layer layer = QgsProcessingParameterVectorTileWriterLayers::variantMapAsLayer( value.toMap(), mContext );

item->setText( titleForLayer( layer ) );
item->setData( value, Qt::UserRole );
Expand Down
Expand Up @@ -18,6 +18,7 @@

#define SIP_NO_FILE

#include "qgsprocessingcontext.h"
#include "qgsprocessingwidgetwrapper.h"
#include "qgsprocessingmultipleselectiondialog.h"
#include "qgsvectortilewriter.h"
Expand All @@ -41,6 +42,7 @@ class QgsProcessingVectorTileWriteLayerDetailsWidget : public QgsPanelWidget, pr

private:
QgsVectorLayer *mLayer = nullptr;
QgsProcessingContext mContext;
};


Expand Down Expand Up @@ -68,6 +70,7 @@ class QgsProcessingVectorTileWriterLayersPanelWidget : public QgsProcessingMulti
QString titleForLayer( const QgsVectorTileWriter::Layer &layer );

QgsProject *mProject = nullptr;
QgsProcessingContext mContext;
};


Expand Down

0 comments on commit c79ebcd

Please sign in to comment.