Skip to content

Commit

Permalink
colorramp: modify tests for builtin gradients, fix rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed Aug 18, 2012
1 parent e36e4ae commit bae03b7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/core/symbology-ng/qgscolorrampv2data.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ static const char* cptCityNames [] =
static const char* cptCitySelectionsMin [] =
{
"",
"cb",
"test",
"cb/",
"grass/",
NULL, NULL
};

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsvectorcolorrampv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ QColor QgsCptCityColorRampV2::color( double value ) const
c1 = mPalette[0].second;
for ( int i = 0; i < numStops; i++ )
{
if ( mPalette[i].first >= value )
if ( mPalette[i].first > value )
{
if ( mGradientType == Discrete )
return c1;
Expand Down
16 changes: 13 additions & 3 deletions tests/src/core/testqgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TestQgsRasterLayer: public QObject
void colorRamp1();
void colorRamp2();
void colorRamp3();
void colorRamp4();
void landsatBasic();
void landsatBasic875Qml();
void checkDimensions();
Expand Down Expand Up @@ -254,10 +255,19 @@ void TestQgsRasterLayer::colorRamp2()

void TestQgsRasterLayer::colorRamp3()
{
// cpt-city ramp, small selection available in <testdir>/cpt-city
QgsCptCityCollection::initCollection( DEFAULT_CPTCITY_COLLECTION, mTestDataDir + "cpt-city" );
// cpt-city ramp, discrete
QgsCptCityCollection::initCollections();
QVERIFY( testColorRamp( "raster_colorRamp3",
new QgsCptCityColorRampV2( "gmt/GMT_panoply", "" ),
new QgsCptCityColorRampV2( "cb/div/BrBG", "_10" ),
QgsColorRampShader::DISCRETE, 10 ) );
}

void TestQgsRasterLayer::colorRamp4()
{
// cpt-city ramp, continuous
QgsCptCityCollection::initCollections();
QVERIFY( testColorRamp( "raster_colorRamp4",
new QgsCptCityColorRampV2( "grass/elevation", "" ),
QgsColorRampShader::DISCRETE, 10 ) );
}

Expand Down
32 changes: 16 additions & 16 deletions tests/src/core/testqgsstylev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void TestStyleV2::initTestCase()
// mStyle->clear();

// cpt-city ramp, small selection available in <testdir>/cpt-city
QgsCptCityCollection::initCollection( DEFAULT_CPTCITY_COLLECTION, mTestDataDir + "cpt-city" );
QgsCptCityCollection::initCollections();
}

void TestStyleV2::cleanupTestCase()
Expand Down Expand Up @@ -124,17 +124,15 @@ void TestStyleV2::testCreateColorRamps()
QgsVectorColorBrewerColorRampV2* cb2Ramp = new QgsVectorColorBrewerColorRampV2( "RdYlGn", 6 );
QVERIFY( mStyle->addColorRamp( "test_cb2", cb2Ramp ) );

// if ( QgsCptCityColorRampV2::hasBasicSchemes() )
// {
QgsCptCityColorRampV2* cc1Ramp = new QgsCptCityColorRampV2( "jjg/misc/temperature", "" );
// discrete ramp with no variant
QgsCptCityColorRampV2* cc1Ramp = new QgsCptCityColorRampV2( "cb/seq/PuBuGn_06", "" );
QVERIFY( mStyle->addColorRamp( "test_cc1", cc1Ramp ) );
// discrete ramp with variant
QgsCptCityColorRampV2* cc2Ramp = new QgsCptCityColorRampV2( "cb/div/PiYG", "_10" );
QVERIFY( mStyle->addColorRamp( "test_cc2", cc2Ramp ) );
// }
// else
// {
// QWARN( "cpt-city support files not found - skipping cpt-city color ramp tests" );
// }
// continuous ramp
QgsCptCityColorRampV2* cc3Ramp = new QgsCptCityColorRampV2( "grass/byr", "" );
QVERIFY( mStyle->addColorRamp( "test_cc3", cc3Ramp ) );
}

void TestStyleV2::testLoadColorRamps()
Expand All @@ -155,15 +153,15 @@ void TestStyleV2::testLoadColorRamps()
colorTests.insert( "test_cb2", qMakePair( 0.66, QColor( "#d9ef8b" ) ) );

// cpt-city
// if ( QgsCptCityColorRampV2::hasAllSchemes() )
// {
colorRampsTest << "test_cc1";
colorTests.insert( "test_cc1", qMakePair( 0.25, QColor( "#466fcf" ) ) );
colorTests.insert( "test_cc1", qMakePair( 0.66, QColor( "#dbc85b" ) ) );
colorTests.insert( "test_cc1", qMakePair( 0.25, QColor( "#d0d1e6" ) ) );
colorTests.insert( "test_cc1", qMakePair( 0.66, QColor( "#67a9cf" ) ) );
colorRampsTest << "test_cc2";
colorTests.insert( "test_cc2", qMakePair( 0.25, QColor( "#de77ae" ) ) );
colorTests.insert( "test_cc2", qMakePair( 0.66, QColor( "#b8e186" ) ) );
// }
colorRampsTest << "test_cc3";
colorTests.insert( "test_cc3", qMakePair( 0.25, QColor( "#7f7f7f" ) ) );
colorTests.insert( "test_cc3", qMakePair( 0.66, QColor( "#ffad00" ) ) );

foreach ( QString name, colorRampsTest )
{
Expand All @@ -187,7 +185,7 @@ void TestStyleV2::testLoadColorRamps()

void TestStyleV2::testSaveLoad()
{
#if 0
//#if 0
mStyle->save();
mStyle->clear();
mStyle->load( QgsApplication::userStyleV2Path() );
Expand All @@ -204,7 +202,9 @@ void TestStyleV2::testSaveLoad()
if ( ramp )
delete ramp;
}
#endif
// test color ramps again
testLoadColorRamps();
//#endif
}


Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bae03b7

Please sign in to comment.