Skip to content
Permalink
Browse files
Remember and revert layer crs change on cancel (#46556)
  • Loading branch information
roya0045 committed Dec 22, 2021
1 parent 35db168 commit f776cf8b8cf06569844a31b6ee7b31b90958ee46
@@ -80,6 +80,8 @@ QgsAnnotationLayerProperties::QgsAnnotationLayerProperties( QgsAnnotationLayer *

buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );

mBackupCrs = mLayer->crs();

if ( !mLayer->styleManager()->isDefault( mLayer->styleManager()->currentStyle() ) )
title += QStringLiteral( " (%1)" ).arg( mLayer->styleManager()->currentStyle() );
restoreOptionsBaseUi( title );
@@ -115,6 +117,8 @@ void QgsAnnotationLayerProperties::apply()
mLayer->setMaximumScale( mScaleRangeWidget->maximumScale() );
mLayer->setMinimumScale( mScaleRangeWidget->minimumScale() );

mBackupCrs = mLayer->crs();

// set the blend mode and opacity for the layer
mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mLayer ) );
mLayer->setBlendMode( mBlendModeComboBox->blendMode() );
@@ -131,6 +135,9 @@ void QgsAnnotationLayerProperties::apply()

void QgsAnnotationLayerProperties::onCancel()
{
if ( mBackupCrs != mLayer->crs() )
mLayer->setCrs( mBackupCrs );

if ( mOldStyle.xmlData() != mLayer->styleManager()->style( mLayer->styleManager()->currentStyle() ).xmlData() )
{
// need to reset style to previous - style applied directly to the layer (not in apply())
@@ -78,6 +78,8 @@ class QgsAnnotationLayerProperties : public QgsOptionsDialogBase, private Ui::Qg

QList<QgsMapLayerConfigWidget *> mConfigWidgets;

QgsCoordinateReferenceSystem mBackupCrs;

};

#endif // QGSANNOTATIONLAYERPROPERTIES_H
@@ -105,6 +105,8 @@ QgsPointCloudLayerProperties::QgsPointCloudLayerProperties( QgsPointCloudLayer *
mStatisticsTableView->setModel( new QgsPointCloudAttributeStatisticsModel( mLayer, mStatisticsTableView ) );
mStatisticsTableView->verticalHeader()->hide();

mBackupCrs = mLayer->crs();

if ( mLayer->dataProvider() && !mLayer->dataProvider()->metadataClasses( QStringLiteral( "Classification" ) ).isEmpty() )
{
mClassificationStatisticsTableView->setModel( new QgsPointCloudClassificationStatisticsModel( mLayer, QStringLiteral( "Classification" ), mStatisticsTableView ) );
@@ -146,6 +148,7 @@ void QgsPointCloudLayerProperties::apply()
mMetadataWidget->acceptMetadata();

mLayer->setName( mLayerOrigNameLineEdit->text() );
mBackupCrs = mLayer->crs();

for ( QgsMapLayerConfigWidget *w : mConfigWidgets )
w->apply();
@@ -155,6 +158,9 @@ void QgsPointCloudLayerProperties::apply()

void QgsPointCloudLayerProperties::onCancel()
{
if ( mBackupCrs != mLayer->crs() )
mLayer->setCrs( mBackupCrs );

if ( mOldStyle.xmlData() != mLayer->styleManager()->style( mLayer->styleManager()->currentStyle() ).xmlData() )
{
// need to reset style to previous - style applied directly to the layer (not in apply())
@@ -139,6 +139,8 @@ class QgsPointCloudLayerProperties : public QgsOptionsDialogBase, private Ui::Qg

QList<QgsMapLayerConfigWidget *> mConfigWidgets;

QgsCoordinateReferenceSystem mBackupCrs;

};

#endif // QGSPOINTCLOUDLAYERPROPERTIES_H
@@ -80,6 +80,7 @@ QgsMeshLayerProperties::QgsMeshLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *
connect( lyr->styleManager(), &QgsMapLayerStyleManager::currentStyleChanged, this, &QgsMeshLayerProperties::syncAndRepaint );

connect( this, &QDialog::accepted, this, &QgsMeshLayerProperties::apply );
connect( this, &QDialog::rejected, this, &QgsMeshLayerProperties::onCancel );
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsMeshLayerProperties::apply );

connect( mMeshLayer, &QgsMeshLayer::dataChanged, this, &QgsMeshLayerProperties::syncAndRepaint );
@@ -104,6 +105,7 @@ QgsMeshLayerProperties::QgsMeshLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *
layout->addWidget( mMetadataWidget );
metadataFrame->setLayout( layout );
mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
mBackupCrs = mMeshLayer->crs();

mTemporalDateTimeStart->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
mTemporalDateTimeEnd->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
@@ -394,6 +396,8 @@ void QgsMeshLayerProperties::apply()

mMetadataWidget->acceptMetadata();

mBackupCrs = mMeshLayer->crs();

if ( needMeshUpdating )
mMeshLayer->reload();

@@ -547,3 +551,9 @@ void QgsMeshLayerProperties::saveMetadataAs()
else
QMessageBox::information( this, tr( "Save Metadata" ), message );
}

void QgsMeshLayerProperties::onCancel()
{
if ( mBackupCrs != mMeshLayer->crs() )
mMeshLayer->setCrs( mBackupCrs );
}
@@ -90,6 +90,8 @@ class GUI_EXPORT QgsMeshLayerProperties : public QgsOptionsDialogBase, private U
void aboutToShowStyleMenu();
//! Reloads temporal properties from the provider
void reloadTemporalProperties();
//! \brief Called when cancel button is pressed
void onCancel();

void onTimeReferenceChange();

@@ -128,6 +130,8 @@ class GUI_EXPORT QgsMeshLayerProperties : public QgsOptionsDialogBase, private U
friend class TestQgsMeshLayerPropertiesDialog;

void showHelp();

QgsCoordinateReferenceSystem mBackupCrs;
};


@@ -234,6 +234,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
return;
}

mBackupCrs = mRasterLayer->crs();

// Handles window modality raising canvas
if ( mMapCanvas && mRasterTransparencyWidget->pixelSelectorTool() )
{
@@ -883,6 +885,7 @@ void QgsRasterLayerProperties::apply()
mRasterLayer->setRenderer( rendererWidget->renderer() );
}

mBackupCrs = mRasterLayer->crs();
mMetadataWidget->acceptMetadata();
mMetadataFilled = false;

@@ -1798,6 +1801,8 @@ void QgsRasterLayerProperties::onCancel()
mRasterLayer->importNamedStyle( doc, myMessage );
syncToLayer();
}
if ( mBackupCrs != mRasterLayer->crs() )
mRasterLayer->setCrs( mBackupCrs );
}

void QgsRasterLayerProperties::showHelp()
@@ -294,5 +294,7 @@ class GUI_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
QgsExpressionContext mContext;

friend class QgsAppScreenShots;

QgsCoordinateReferenceSystem mBackupCrs;
};
#endif
@@ -557,7 +557,7 @@ void QgsVectorLayerProperties::syncToLayer()

// populate the general information
mLayerOrigNameLineEdit->setText( mLayer->name() );

mBackupCrs = mLayer->crs();
//see if we are dealing with a pg layer here
mSubsetGroupBox->setEnabled( true );
txtSubsetSQL->setText( mLayer->subsetString() );
@@ -691,7 +691,7 @@ void QgsVectorLayerProperties::apply()
{
labelingDialog->writeSettingsToLayer();
}

mBackupCrs = mLayer->crs();
// apply legend settings
mLegendWidget->applyToLayer();
mLegendConfigEmbeddedWidget->applyToLayer();
@@ -917,6 +917,9 @@ void QgsVectorLayerProperties::onCancel()
doc.setContent( mOldStyle.xmlData(), false, &myMessage, &errorLine, &errorColumn );
mLayer->importNamedStyle( doc, myMessage );
}

if ( mBackupCrs != mLayer->crs() )
mLayer->setCrs( mBackupCrs );
}

void QgsVectorLayerProperties::urlClicked( const QUrl &url )
@@ -979,6 +982,7 @@ QString QgsVectorLayerProperties::htmlMetadata()

void QgsVectorLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
{

QgsDatumTransformDialog::run( crs, QgsProject::instance()->crs(), this, mCanvas, tr( "Select Transformation for the vector layer" ) );
mLayer->setCrs( crs );
mMetadataFilled = false;
@@ -255,6 +255,8 @@ class GUI_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

QgsProviderSourceWidget *mSourceWidget = nullptr;

QgsCoordinateReferenceSystem mBackupCrs;

private slots:
void openPanel( QgsPanelWidget *panel );

0 comments on commit f776cf8

Please sign in to comment.