Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[color ramp] do not automatically save new ramps
  • Loading branch information
nirvn committed Dec 3, 2016
1 parent 4a58768 commit 137a211
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions src/gui/qgscolorrampbutton.cpp
Expand Up @@ -20,7 +20,6 @@
#include "qgssymbollayerutils.h"
#include "qgsstyle.h"

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

#include <QAction>
#include <QInputDialog>
#include <QMessageBox>
#include <QMouseEvent>
#include <QMenu>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 137a211

Please sign in to comment.