Skip to content
Permalink
Browse files
[color ramp] save/restore invert state for cpt-city ramps
  • Loading branch information
nirvn committed Dec 5, 2016
1 parent c8266a2 commit ab4a37f760a2957bdd23194c331ebada62645c68
Showing with 73 additions and 11 deletions.
  1. +4 −0 doc/api_break.dox
  2. +16 −2 python/core/qgscolorramp.sip
  3. +32 −8 src/core/qgscolorramp.cpp
  4. +21 −1 src/core/qgscolorramp.h
@@ -647,6 +647,10 @@ QgsCoordinateTransformCache {#qgis_api_break_3_0_QgsCoordinateTransformCa
- transform() now returns a QgsCoordinateTransform object, not a pointer. An invalid QgsCoordinateTransform will
be returned in place of a null pointer.

QgsCptCityColorRamp {#qgis_api_break_3_0_QgsCptCityColorRamp}
-------------------

- The constructor's doLoadFile parameter order has changed due to the addition of an inverted parameter

QgsCptCityColorRampDialog {#qgis_api_break_3_0_QgsCptCityColorRampDialog}
-------------------------
@@ -401,11 +401,25 @@ class QgsCptCityColorRamp : QgsGradientColorRamp
#include <qgscolorramp.h>
%End
public:
/** Constructor for QgsCptCityColorRamp
* @param schemeName cpt-city scheme name
* @param variantName cpt-city variant name
* @param inverted invert ramp ordering
* @param doLoadFile load cpt-city ramp from file
*/
QgsCptCityColorRamp( const QString& schemeName = DEFAULT_CPTCITY_SCHEMENAME,
const QString& variantName = DEFAULT_CPTCITY_VARIANTNAME,
bool doLoadFile = true );
bool inverted = false, bool doLoadFile = true );
/** Constructor for QgsCptCityColorRamp
* @param schemeName cpt-city scheme name
* @param variantList cpt-city variant list
* @param variantName cpt-city variant name
* @param inverted invert ramp ordering
* @param doLoadFile load cpt-city ramp from file
*/
QgsCptCityColorRamp( const QString& schemeName, const QStringList& variantList,
const QString& variantName = QString(), bool doLoadFile = true );
const QString& variantName = QString(), bool inverted = false,
bool doLoadFile = true );

static QgsColorRamp* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;

@@ -595,10 +595,14 @@ QgsStringMap QgsColorBrewerColorRamp::properties() const


QgsCptCityColorRamp::QgsCptCityColorRamp( const QString& schemeName, const QString& variantName,
bool doLoadFile )
bool inverted, bool doLoadFile )
: QgsGradientColorRamp()
, mSchemeName( schemeName ), mVariantName( variantName )
, mVariantList( QStringList() ), mFileLoaded( false ), mMultiStops( false )
, mSchemeName( schemeName )
, mVariantName( variantName )
, mVariantList( QStringList() )
, mFileLoaded( false )
, mMultiStops( false )
, mInverted( inverted )
{
// TODO replace this with hard-coded data in the default case
// don't load file if variant is missing
@@ -607,10 +611,14 @@ QgsCptCityColorRamp::QgsCptCityColorRamp( const QString& schemeName, const QStri
}

QgsCptCityColorRamp::QgsCptCityColorRamp( const QString& schemeName, const QStringList& variantList,
const QString& variantName, bool doLoadFile )
const QString& variantName, bool inverted, bool doLoadFile )
: QgsGradientColorRamp()
, mSchemeName( schemeName ), mVariantName( variantName )
, mVariantList( variantList ), mFileLoaded( false ), mMultiStops( false )
, mSchemeName( schemeName )
, mVariantName( variantName )
, mVariantList( variantList )
, mFileLoaded( false )
, mMultiStops( false )
, mInverted( inverted )
{
mVariantList = variantList;

@@ -624,18 +632,27 @@ QgsColorRamp* QgsCptCityColorRamp::create( const QgsStringMap& props )
{
QString schemeName = DEFAULT_CPTCITY_SCHEMENAME;
QString variantName = DEFAULT_CPTCITY_VARIANTNAME;
bool inverted = false;

if ( props.contains( QStringLiteral( "schemeName" ) ) )
schemeName = props[QStringLiteral( "schemeName" )];
if ( props.contains( QStringLiteral( "variantName" ) ) )
variantName = props[QStringLiteral( "variantName" )];
if ( props.contains( QStringLiteral( "inverted" ) ) )
inverted = props[QStringLiteral( "inverted" )].toInt();

return new QgsCptCityColorRamp( schemeName, variantName, inverted );
}

return new QgsCptCityColorRamp( schemeName, variantName );
void QgsCptCityColorRamp::invert()
{
mInverted = !mInverted;
QgsGradientColorRamp::invert();
}

QgsCptCityColorRamp* QgsCptCityColorRamp::clone() const
{
QgsCptCityColorRamp* ramp = new QgsCptCityColorRamp( QLatin1String( "" ), QLatin1String( "" ), false );
QgsCptCityColorRamp* ramp = new QgsCptCityColorRamp( QLatin1String( "" ), QLatin1String( "" ), mInverted, false );
ramp->copy( this );
return ramp;
}
@@ -652,6 +669,7 @@ void QgsCptCityColorRamp::copy( const QgsCptCityColorRamp* other )
mVariantName = other->mVariantName;
mVariantList = other->mVariantList;
mFileLoaded = other->mFileLoaded;
mInverted = other->mInverted;
}

QgsGradientColorRamp* QgsCptCityColorRamp::cloneGradientRamp() const
@@ -675,6 +693,7 @@ QgsStringMap QgsCptCityColorRamp::properties() const
QgsStringMap map;
map[QStringLiteral( "schemeName" )] = mSchemeName;
map[QStringLiteral( "variantName" )] = mVariantName;
map[QStringLiteral( "inverted" )] = QString::number( mInverted );
map[QStringLiteral( "rampType" )] = type();
return map;
}
@@ -788,6 +807,11 @@ bool QgsCptCityColorRamp::loadFile()
if ( ! mStops.isEmpty() && mStops.last().offset == 1.0 )
mColor2 = mStops.takeLast().color;

if ( mInverted )
{
QgsGradientColorRamp::invert();
}

mFileLoaded = true;
return true;
}
@@ -540,16 +540,35 @@ class CORE_EXPORT QgsColorBrewerColorRamp : public QgsColorRamp
class CORE_EXPORT QgsCptCityColorRamp : public QgsGradientColorRamp
{
public:

/** Constructor for QgsCptCityColorRamp
* @param schemeName cpt-city scheme name
* @param variantName cpt-city variant name
* @param inverted invert ramp ordering
* @param doLoadFile load cpt-city ramp from file
*/
QgsCptCityColorRamp( const QString& schemeName = DEFAULT_CPTCITY_SCHEMENAME,
const QString& variantName = DEFAULT_CPTCITY_VARIANTNAME,
bool inverted = false,
bool doLoadFile = true );

/** Constructor for QgsCptCityColorRamp
* @param schemeName cpt-city scheme name
* @param variantList cpt-city variant list
* @param variantName cpt-city variant name
* @param inverted invert ramp ordering
* @param doLoadFile load cpt-city ramp from file
*/
QgsCptCityColorRamp( const QString& schemeName, const QStringList& variantList,
const QString& variantName = QString(), bool doLoadFile = true );
const QString& variantName = QString(), bool inverted = false,
bool doLoadFile = true );

static QgsColorRamp* create( const QgsStringMap& properties = QgsStringMap() );

virtual QString type() const override { return QStringLiteral( "cpt-city" ); }

virtual void invert() override;

virtual QgsCptCityColorRamp* clone() const override;
void copy( const QgsCptCityColorRamp* other );
QgsGradientColorRamp* cloneGradientRamp() const;
@@ -585,6 +604,7 @@ class CORE_EXPORT QgsCptCityColorRamp : public QgsGradientColorRamp
QStringList mVariantList;
bool mFileLoaded;
bool mMultiStops;
bool mInverted;
};


0 comments on commit ab4a37f

Please sign in to comment.