Skip to content

Commit

Permalink
don't apply loaded style when layer properties dialog is cancelled
Browse files Browse the repository at this point in the history
(cherry picked from commit 25a162c)
  • Loading branch information
alexbruy committed Apr 13, 2016
1 parent 5c24d1a commit ca9f267
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -30,7 +30,6 @@
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsmaprenderer.h"
#include "qgsmaptoolemitpoint.h"
#include "qgsmaptopixel.h"
Expand Down Expand Up @@ -106,6 +105,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
connect( lyr->styleManager(), SIGNAL( currentStyleChanged( QString ) ), this, SLOT( syncToLayer() ) );

connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( this, SIGNAL( rejected() ), this, SLOT( onCancel() ) );

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

connect( mOptionsStackedWidget, SIGNAL( currentChanged( int ) ), this, SLOT( mOptionsStackedWidget_CurrentChanged( int ) ) );
Expand Down Expand Up @@ -1707,6 +1708,8 @@ void QgsRasterLayerProperties::loadStyle_clicked()
if ( !fileName.endsWith( ".qml", Qt::CaseInsensitive ) )
fileName += ".qml";

mOldStyle = mRasterLayer->styleManager()->style( mRasterLayer->styleManager()->currentStyle() );

bool defaultLoadedFlag = false;
QString message = mRasterLayer->loadNamedStyle( fileName, defaultLoadedFlag );
if ( defaultLoadedFlag )
Expand Down Expand Up @@ -1776,4 +1779,16 @@ bool QgsRasterLayerProperties::rasterIsMultiBandColor()
return mRasterLayer && nullptr != dynamic_cast<QgsMultiBandColorRenderer*>( mRasterLayer->renderer() );
}


void QgsRasterLayerProperties::onCancel()
{
if ( mOldStyle.xmlData() != mRasterLayer->styleManager()->style( mRasterLayer->styleManager()->currentStyle() ).xmlData() )
{
// need to reset style to previous - style applied directly to the layer (not in apply())
QString myMessage;
QDomDocument doc( "qgis" );
int errorLine, errorColumn;
doc.setContent( mOldStyle.xmlData(), false, &myMessage, &errorLine, &errorColumn );
mRasterLayer->importNamedStyle( doc, myMessage );
syncToLayer();
}
}
7 changes: 7 additions & 0 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -25,6 +25,7 @@
#include "qgsmaptool.h"
#include "qgscolorrampshader.h"
#include "qgscontexthelp.h"
#include "qgsmaplayerstylemanager.h"

class QgsMapLayer;
class QgsMapCanvas;
Expand Down Expand Up @@ -57,6 +58,8 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
//TODO: Verify that these all need to be public
/** \brief Applies the settings made in the dialog without closing the box */
void apply();
/** Called when cancel button is pressed */
void onCancel();
/** \brief Slot to update layer display name as original is edited. */
void on_mLayerOrigNameLineEd_textEdited( const QString& text );
/** \brief this slot asks the rasterlayer to construct pyramids */
Expand Down Expand Up @@ -186,5 +189,9 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
QgsRasterHistogramWidget* mHistogramWidget;

QVector<bool> mTransparencyToEdited;

/** Previous layer style. Used to reset style to previous state if new style
* was loaded but dialog is cancelled */
QgsMapLayerStyle mOldStyle;
};
#endif
14 changes: 13 additions & 1 deletion src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -37,7 +37,6 @@
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmaplayerstylemanager.h"
#include "qgspluginmetadata.h"
#include "qgspluginregistry.h"
#include "qgsproject.h"
Expand Down Expand Up @@ -660,6 +659,17 @@ void QgsVectorLayerProperties::onCancel()

layer->setSubsetString( mOriginalSubsetSQL );
}

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())
QString myMessage;
QDomDocument doc( "qgis" );
int errorLine, errorColumn;
doc.setContent( mOldStyle.xmlData(), false, &myMessage, &errorLine, &errorColumn );
mLayer->importNamedStyle( doc, myMessage );
syncToLayer();
}
}

void QgsVectorLayerProperties::on_pbnQueryBuilder_clicked()
Expand Down Expand Up @@ -826,6 +836,8 @@ void QgsVectorLayerProperties::loadStyle_clicked()
return;
}

mOldStyle = mLayer->styleManager()->style( mLayer->styleManager()->currentStyle() );

QString myMessage;
bool defaultLoadedFlag = false;

Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -30,6 +30,7 @@
#include "qgsmapcanvas.h"
#include "qgscontexthelp.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsmaplayerstylemanager.h"

class QgsMapLayer;

Expand Down Expand Up @@ -187,6 +188,10 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
//! 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;

/** Previous layer style. Used to reset style to previous state if new style
* was loaded but dialog is cancelled */
QgsMapLayerStyle mOldStyle;

void initDiagramTab();

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

0 comments on commit ca9f267

Please sign in to comment.