Allow updating gpl based color schemes which are set to the

default random color scheme

Allows users to edit the color scheme inside QGIS and see the
effects immediately on next layer load
This commit is contained in:
Nyall Dawson 2018-02-05 15:13:18 +10:00
parent bc449c401b
commit 149b23e08b

View File

@ -16,6 +16,7 @@
***************************************************************************/
#include "qgscolorscheme.h"
#include "qgscolorschemeregistry.h"
#include "qgsproject.h"
#include "qgssymbollayerutils.h"
@ -278,7 +279,19 @@ bool QgsGplColorScheme::setColors( const QgsNamedColorList &colors, const QStrin
}
QFile destFile( destFilePath );
return QgsSymbolLayerUtils::saveColorsToGpl( destFile, schemeName(), colors );
if ( QgsSymbolLayerUtils::saveColorsToGpl( destFile, schemeName(), colors ) )
{
if ( QgsApplication::colorSchemeRegistry()->randomStyleColorScheme() == this )
{
// force a re-generation of the random style color list, since the color list has changed
QgsApplication::colorSchemeRegistry()->setRandomStyleColorScheme( this );
}
return true;
}
else
{
return false;
}
}
@ -315,6 +328,12 @@ QgsUserColorScheme::QgsUserColorScheme( const QString &filename )
{
mName = mFilename;
}
// we consider this scheme writable if the user has permission, OR
// if it DOESN'T already exist (since new schemes are only created when
// first written to)
QFileInfo sourceFileInfo( gplFilePath() );
mEditable = !sourceFileInfo.exists() || sourceFileInfo.isWritable();
}
QString QgsUserColorScheme::schemeName() const