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
  • Loading branch information
alexbruy committed Apr 9, 2016
1 parent 156721b commit 25a162c
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 @@ -1713,6 +1714,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 @@ -1782,4 +1785,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 @@ -650,6 +649,17 @@ void QgsVectorLayerProperties::onCancel()

mLayer->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 @@ -816,6 +826,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 @@ -189,6 +190,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();

/** Adds a new join to mJoinTreeWidget*/
Expand Down

0 comments on commit 25a162c

Please sign in to comment.