Skip to content
Permalink
Browse files

make QgsProcessingContext member variable in vector tile layers wrapper

to avoid dangling pointers
  • Loading branch information
alexbruy authored and nyalldawson committed Nov 1, 2020
1 parent 5271ca2 commit c79ebcd3ae8f9bd1130cd6ae2e7b6e71adde4c60
@@ -24,7 +24,6 @@

#include "qgspanelwidget.h"

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

#include "qgsprocessingparametervectortilewriterlayers.h"
@@ -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 )
@@ -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

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


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

}

void QgsProcessingVectorTileWriterLayersPanelWidget::copyLayer()
@@ -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 );
@@ -18,6 +18,7 @@

#define SIP_NO_FILE

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

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


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

QgsProject *mProject = nullptr;
QgsProcessingContext mContext;
};


0 comments on commit c79ebcd

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