Skip to content
Permalink
Browse files

[color ramp] do not automatically save new ramps

  • Loading branch information
nirvn committed Dec 3, 2016
1 parent 4a58768 commit 137a211bae0a0e836935d6d14eda50af2143eeae
Showing with 48 additions and 13 deletions.
  1. +48 −13 src/gui/qgscolorrampbutton.cpp
@@ -20,7 +20,6 @@
#include "qgssymbollayerutils.h"
#include "qgsstyle.h"

#include "qgsstylemanagerdialog.h"
#include "qgsstylesavedialog.h"
#include "qgsgradientcolorrampdialog.h"
#include "qgslimitedrandomcolorrampdialog.h"
@@ -29,6 +28,7 @@
#include "qgspresetcolorrampdialog.h"

#include <QAction>
#include <QInputDialog>
#include <QMessageBox>
#include <QMouseEvent>
#include <QMenu>
@@ -338,23 +338,56 @@ void QgsColorRampButton::loadColorRamp()

void QgsColorRampButton::createColorRamp()
{
QString name;
if ( !mShowGradientOnly )
QStringList rampTypes;
QString rampType;
bool ok = true;

if ( mShowGradientOnly )
{
name = QgsStyleManagerDialog::addColorRampStatic( this, mStyle );
rampTypes << tr( "Gradient" ) << tr( "Catalog: cpt-city" );
}
else
{
name = QgsStyleManagerDialog::addColorRampStatic( this, mStyle, QStringLiteral( "Gradient" ) );
rampTypes << tr( "Gradient" ) << tr( "Color presets" ) << tr( "Random" ) << tr( "Catalog: cpt-city" );
rampTypes << tr( "Catalog: ColorBrewer" );
}
rampType = QInputDialog::getItem( this, tr( "Color ramp type" ),
tr( "Please select color ramp type:" ), rampTypes, 0, false, &ok );

if ( !ok || rampType.isEmpty() )
return;

QgsColorRamp* ramp;
if ( rampType == tr( "Gradient" ) )
{
ramp = new QgsGradientColorRamp();
}
else if ( rampType == tr( "Random" ) )
{
ramp = new QgsLimitedRandomColorRamp();
}
else if ( rampType == tr( "Catalog: ColorBrewer" ) )
{
ramp = new QgsColorBrewerColorRamp();
}
else if ( rampType == tr( "Color presets" ) )
{
ramp = new QgsPresetSchemeColorRamp();
}
else if ( rampType == tr( "Catalog: cpt-city" ) )
{
ramp = new QgsCptCityColorRamp( QLatin1String( "" ), QLatin1String( "" ) );
}
if ( name.isEmpty() )
else
{
QgsDebugMsg( "invalid ramp type " + rampType );
return;
}

// make sure the color ramp is stored
mStyle->save();
setColorRamp( ramp );
delete ramp;

setColorRampName( name );
setColorRampFromName( name );
showColorRampDialog();
}

void QgsColorRampButton::saveColorRamp()
@@ -382,9 +415,11 @@ void QgsColorRampButton::saveColorRamp()
QStringList colorRampTags = saveDlg.tags().split( ',' );

// add new symbol to style and re-populate the list
QgsColorRamp* savedColorRamp = colorRamp();
mStyle->addColorRamp( saveDlg.name(), savedColorRamp );
mStyle->saveColorRamp( saveDlg.name(), savedColorRamp, saveDlg.isFavorite(), colorRampTags );
QgsColorRamp* ramp = colorRamp();
mStyle->addColorRamp( saveDlg.name(), ramp );
mStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );

setColorRampName( saveDlg.name() );
}

void QgsColorRampButton::invertColorRamp()

0 comments on commit 137a211

Please sign in to comment.
You can’t perform that action at this time.