Skip to content

Commit

Permalink
Return to previous state of vector joins if the vector props dialog w…
Browse files Browse the repository at this point in the history
…as cancelled
  • Loading branch information
wonder-sk committed Sep 16, 2014
1 parent 8cd5e59 commit f73b0b6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -84,6 +84,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(

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

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

Expand Down Expand Up @@ -214,6 +215,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
addJoinToTreeWidget( joins[i] );
}

mOldJoins = layer->vectorJoins();

diagramPropertiesDialog = new QgsDiagramProperties( layer, mDiagramFrame );
diagramPropertiesDialog->layout()->setMargin( 0 );
mDiagramFrame->setLayout( new QVBoxLayout( mDiagramFrame ) );
Expand Down Expand Up @@ -571,6 +574,8 @@ void QgsVectorLayerProperties::apply()
simplifyMethod.setMaximumScale( 1.0 / mSimplifyMaximumScaleComboBox->scale() );
layer->setSimplifyMethod( simplifyMethod );

mOldJoins = layer->vectorJoins();

// update symbology
emit refreshLegend( layer->id() );

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

void QgsVectorLayerProperties::onCancel()
{
if ( mOldJoins != layer->vectorJoins() )
{
// need to undo changes in vector layer joins - they are applied directly to the layer (not in apply())
// so other parts of the properties dialog can use the fields from the joined layers

foreach ( const QgsVectorJoinInfo& info, layer->vectorJoins() )
layer->removeJoin( info.joinLayerId );

foreach ( const QgsVectorJoinInfo& info, mOldJoins )
layer->addJoin( info );
}
}

void QgsVectorLayerProperties::on_pbnQueryBuilder_clicked()
{
// launch the query builder
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -96,6 +96,9 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
/** Called when apply button is pressed or dialog is accepted */
void apply();

/** Called when cancel button is pressed */
void onCancel();

//
//methods reimplemented from qt designer base class
//
Expand Down Expand Up @@ -166,6 +169,9 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
/**Fields dialog. If apply is pressed, options are applied to vector's diagrams*/
QgsFieldsProperties* mFieldsPropertiesDialog;

//! 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
QList< QgsVectorJoinInfo > mOldJoins;

void initDiagramTab();

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

0 comments on commit f73b0b6

Please sign in to comment.