Skip to content

Commit

Permalink
Remember and revert layer crs change on cancel (#46556)
Browse files Browse the repository at this point in the history
  • Loading branch information
roya0045 committed Dec 22, 2021
1 parent 35db168 commit f776cf8
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/app/annotations/qgsannotationlayerproperties.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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() );
Expand All @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions src/app/annotations/qgsannotationlayerproperties.h
Expand Up @@ -78,6 +78,8 @@ class QgsAnnotationLayerProperties : public QgsOptionsDialogBase, private Ui::Qg

QList<QgsMapLayerConfigWidget *> mConfigWidgets;

QgsCoordinateReferenceSystem mBackupCrs;

};

#endif // QGSANNOTATIONLAYERPROPERTIES_H
6 changes: 6 additions & 0 deletions src/app/pointcloud/qgspointcloudlayerproperties.cpp
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -146,6 +148,7 @@ void QgsPointCloudLayerProperties::apply()
mMetadataWidget->acceptMetadata();

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

for ( QgsMapLayerConfigWidget *w : mConfigWidgets )
w->apply();
Expand All @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions src/app/pointcloud/qgspointcloudlayerproperties.h
Expand Up @@ -139,6 +139,8 @@ class QgsPointCloudLayerProperties : public QgsOptionsDialogBase, private Ui::Qg

QList<QgsMapLayerConfigWidget *> mConfigWidgets;

QgsCoordinateReferenceSystem mBackupCrs;

};

#endif // QGSPOINTCLOUDLAYERPROPERTIES_H
10 changes: 10 additions & 0 deletions src/gui/mesh/qgsmeshlayerproperties.cpp
Expand Up @@ -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 );
Expand All @@ -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" );
Expand Down Expand Up @@ -394,6 +396,8 @@ void QgsMeshLayerProperties::apply()

mMetadataWidget->acceptMetadata();

mBackupCrs = mMeshLayer->crs();

if ( needMeshUpdating )
mMeshLayer->reload();

Expand Down Expand Up @@ -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 );
}
4 changes: 4 additions & 0 deletions src/gui/mesh/qgsmeshlayerproperties.h
Expand Up @@ -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();

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

void showHelp();

QgsCoordinateReferenceSystem mBackupCrs;
};


Expand Down
5 changes: 5 additions & 0 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -234,6 +234,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
return;
}

mBackupCrs = mRasterLayer->crs();

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

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

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

void QgsRasterLayerProperties::showHelp()
Expand Down
2 changes: 2 additions & 0 deletions src/gui/raster/qgsrasterlayerproperties.h
Expand Up @@ -294,5 +294,7 @@ class GUI_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
QgsExpressionContext mContext;

friend class QgsAppScreenShots;

QgsCoordinateReferenceSystem mBackupCrs;
};
#endif
8 changes: 6 additions & 2 deletions src/gui/vector/qgsvectorlayerproperties.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -691,7 +691,7 @@ void QgsVectorLayerProperties::apply()
{
labelingDialog->writeSettingsToLayer();
}

mBackupCrs = mLayer->crs();
// apply legend settings
mLegendWidget->applyToLayer();
mLegendConfigEmbeddedWidget->applyToLayer();
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/vector/qgsvectorlayerproperties.h
Expand Up @@ -255,6 +255,8 @@ class GUI_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

QgsProviderSourceWidget *mSourceWidget = nullptr;

QgsCoordinateReferenceSystem mBackupCrs;

private slots:
void openPanel( QgsPanelWidget *panel );

Expand Down

0 comments on commit f776cf8

Please sign in to comment.