Skip to content

Commit f73b0b6

Browse files
committedSep 16, 2014
Return to previous state of vector joins if the vector props dialog was cancelled
1 parent 8cd5e59 commit f73b0b6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
8484

8585
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
8686
connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
87+
connect( this, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
8788

8889
connect( mOptionsStackedWidget, SIGNAL( currentChanged( int ) ), this, SLOT( mOptionsStackedWidget_CurrentChanged( int ) ) );
8990

@@ -214,6 +215,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
214215
addJoinToTreeWidget( joins[i] );
215216
}
216217

218+
mOldJoins = layer->vectorJoins();
219+
217220
diagramPropertiesDialog = new QgsDiagramProperties( layer, mDiagramFrame );
218221
diagramPropertiesDialog->layout()->setMargin( 0 );
219222
mDiagramFrame->setLayout( new QVBoxLayout( mDiagramFrame ) );
@@ -571,6 +574,8 @@ void QgsVectorLayerProperties::apply()
571574
simplifyMethod.setMaximumScale( 1.0 / mSimplifyMaximumScaleComboBox->scale() );
572575
layer->setSimplifyMethod( simplifyMethod );
573576

577+
mOldJoins = layer->vectorJoins();
578+
574579
// update symbology
575580
emit refreshLegend( layer->id() );
576581

@@ -579,6 +584,21 @@ void QgsVectorLayerProperties::apply()
579584
QgsProject::instance()->dirty( true );
580585
}
581586

587+
void QgsVectorLayerProperties::onCancel()
588+
{
589+
if ( mOldJoins != layer->vectorJoins() )
590+
{
591+
// need to undo changes in vector layer joins - they are applied directly to the layer (not in apply())
592+
// so other parts of the properties dialog can use the fields from the joined layers
593+
594+
foreach ( const QgsVectorJoinInfo& info, layer->vectorJoins() )
595+
layer->removeJoin( info.joinLayerId );
596+
597+
foreach ( const QgsVectorJoinInfo& info, mOldJoins )
598+
layer->addJoin( info );
599+
}
600+
}
601+
582602
void QgsVectorLayerProperties::on_pbnQueryBuilder_clicked()
583603
{
584604
// launch the query builder

‎src/app/qgsvectorlayerproperties.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
9696
/** Called when apply button is pressed or dialog is accepted */
9797
void apply();
9898

99+
/** Called when cancel button is pressed */
100+
void onCancel();
101+
99102
//
100103
//methods reimplemented from qt designer base class
101104
//
@@ -166,6 +169,9 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
166169
/**Fields dialog. If apply is pressed, options are applied to vector's diagrams*/
167170
QgsFieldsProperties* mFieldsPropertiesDialog;
168171

172+
//! List of joins of a layer at the time of creation of the dialog. Used to return joins to previous state if dialog is cancelled
173+
QList< QgsVectorJoinInfo > mOldJoins;
174+
169175
void initDiagramTab();
170176

171177
/**Buffer pixmap which takes the picture of renderers before they are assigned to the vector layer*/

0 commit comments

Comments
 (0)
Please sign in to comment.