Skip to content
Permalink
Browse files

[FEATURE] save existing color ramp function

  • Loading branch information
nirvn committed Dec 3, 2016
1 parent 37c43df commit 04c6007e17f69ae1f74609de71453db0f648978f
Showing with 42 additions and 1 deletion.
  1. +37 −0 src/gui/qgscolorrampbutton.cpp
  2. +4 −0 src/gui/qgscolorrampbutton.h
  3. +1 −1 src/gui/symbology-ng/qgsstylemanagerdialog.cpp
@@ -21,13 +21,15 @@
#include "qgsstyle.h"

#include "qgsstylemanagerdialog.h"
#include "qgsstylesavedialog.h"
#include "qgsgradientcolorrampdialog.h"
#include "qgslimitedrandomcolorrampdialog.h"
#include "qgscolorbrewercolorrampdialog.h"
#include "qgscptcitycolorrampdialog.h"
#include "qgspresetcolorrampdialog.h"

#include <QAction>
#include <QMessageBox>
#include <QMouseEvent>
#include <QMenu>
#include <QPainter>
@@ -316,6 +318,11 @@ void QgsColorRampButton::prepareMenu()
editColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
connect( editColorRampAction, &QAction::triggered, this, &QgsColorRampButton::showColorRampDialog );
mMenu->addAction( editColorRampAction );

QAction* saveColorRampAction = new QAction( tr( "Save color ramp..." ), this );
saveColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
connect( saveColorRampAction, &QAction::triggered, this, &QgsColorRampButton::saveColorRamp );
mMenu->addAction( saveColorRampAction );
}

void QgsColorRampButton::loadColorRamp()
@@ -350,6 +357,36 @@ void QgsColorRampButton::createColorRamp()
setColorRampFromName( name );
}

void QgsColorRampButton::saveColorRamp()
{
QgsStyleSaveDialog saveDlg( this, QgsStyle::ColorrampEntity );
if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
{
return;
}

// check if there is no symbol with same name
if ( mStyle->symbolNames().contains( saveDlg.name() ) )
{
int res = QMessageBox::warning( this, tr( "Save color ramp" ),
tr( "Color ramp with name '%1' already exists. Overwrite?" )
.arg( saveDlg.name() ),
QMessageBox::Yes | QMessageBox::No );
if ( res != QMessageBox::Yes )
{
return;
}
mStyle->removeColorRamp( saveDlg.name() );
}

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 );
}

void QgsColorRampButton::invertColorRamp()
{
mColorRamp->invert();
@@ -286,6 +286,10 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
*/
void createColorRamp();

/** Creates a new color ramp
*/
void saveColorRamp();

/** Inverts the current color ramp
*/
void invertColorRamp();
@@ -469,7 +469,7 @@ QString QgsStyleManagerDialog::addColorRampStatic( QWidget* parent, QgsStyle* st
{
QStringList rampTypes;
rampTypes << tr( "Gradient" ) << tr( "Random" ) << tr( "ColorBrewer" ) << tr( "Preset colors" );
rampTypes << tr( "cpt-city" ); // todo, only for rasters?
rampTypes << tr( "cpt-city" );
rampType = QInputDialog::getItem( parent, tr( "Color ramp type" ),
tr( "Please select color ramp type:" ), rampTypes, 0, false, &ok );
}

0 comments on commit 04c6007

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