From bae03b711512da260f48d96f85968912e4135c27 Mon Sep 17 00:00:00 2001 From: Etienne Tourigny Date: Sat, 18 Aug 2012 12:02:55 -0300 Subject: [PATCH] colorramp: modify tests for builtin gradients, fix rendering --- src/core/symbology-ng/qgscolorrampv2data.h | 3 +- .../symbology-ng/qgsvectorcolorrampv2.cpp | 2 +- tests/src/core/testqgsrasterlayer.cpp | 16 +++++++-- tests/src/core/testqgsstylev2.cpp | 32 +++++++++--------- .../expected_raster_colorRamp3.png | Bin 30240 -> 30240 bytes .../expected_raster_colorRamp4.png | Bin 0 -> 30240 bytes 6 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 tests/testdata/control_images/expected_raster_colorRamp4/expected_raster_colorRamp4.png diff --git a/src/core/symbology-ng/qgscolorrampv2data.h b/src/core/symbology-ng/qgscolorrampv2data.h index 3163a5b59a3..56f949303b8 100644 --- a/src/core/symbology-ng/qgscolorrampv2data.h +++ b/src/core/symbology-ng/qgscolorrampv2data.h @@ -473,8 +473,9 @@ static const char* cptCityNames [] = static const char* cptCitySelectionsMin [] = { "", - "cb", + "test", "cb/", + "grass/", NULL, NULL }; diff --git a/src/core/symbology-ng/qgsvectorcolorrampv2.cpp b/src/core/symbology-ng/qgsvectorcolorrampv2.cpp index 0e10016f514..468446939b2 100644 --- a/src/core/symbology-ng/qgsvectorcolorrampv2.cpp +++ b/src/core/symbology-ng/qgsvectorcolorrampv2.cpp @@ -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; diff --git a/tests/src/core/testqgsrasterlayer.cpp b/tests/src/core/testqgsrasterlayer.cpp index 8e18948ae8b..aa9f79ee60a 100644 --- a/tests/src/core/testqgsrasterlayer.cpp +++ b/tests/src/core/testqgsrasterlayer.cpp @@ -58,6 +58,7 @@ class TestQgsRasterLayer: public QObject void colorRamp1(); void colorRamp2(); void colorRamp3(); + void colorRamp4(); void landsatBasic(); void landsatBasic875Qml(); void checkDimensions(); @@ -254,10 +255,19 @@ void TestQgsRasterLayer::colorRamp2() void TestQgsRasterLayer::colorRamp3() { - // cpt-city ramp, small selection available in /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 ) ); } diff --git a/tests/src/core/testqgsstylev2.cpp b/tests/src/core/testqgsstylev2.cpp index 35a4f135bc4..9ae0c9c0a3b 100644 --- a/tests/src/core/testqgsstylev2.cpp +++ b/tests/src/core/testqgsstylev2.cpp @@ -83,7 +83,7 @@ void TestStyleV2::initTestCase() // mStyle->clear(); // cpt-city ramp, small selection available in /cpt-city - QgsCptCityCollection::initCollection( DEFAULT_CPTCITY_COLLECTION, mTestDataDir + "cpt-city" ); + QgsCptCityCollection::initCollections(); } void TestStyleV2::cleanupTestCase() @@ -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() @@ -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 ) { @@ -187,7 +185,7 @@ void TestStyleV2::testLoadColorRamps() void TestStyleV2::testSaveLoad() { -#if 0 + //#if 0 mStyle->save(); mStyle->clear(); mStyle->load( QgsApplication::userStyleV2Path() ); @@ -204,7 +202,9 @@ void TestStyleV2::testSaveLoad() if ( ramp ) delete ramp; } -#endif + // test color ramps again + testLoadColorRamps(); + //#endif } diff --git a/tests/testdata/control_images/expected_raster_colorRamp3/expected_raster_colorRamp3.png b/tests/testdata/control_images/expected_raster_colorRamp3/expected_raster_colorRamp3.png index 979517f69ace385e3f1b0e60a2e427494923ec20..47f164cbc0998f2222df8fc6d8516a0d5db1ba27 100644 GIT binary patch delta 133 zcmZ4RhH=3g#tEU!AqK3IA2LfbTPQ+kV*_O{U%@c|OpB|zf$57(N?>~D<2zt_>#1{K z`po(BVEX^HOCWl40pDH0$sd?M0~vp~SvEiLSh6`#VRxv=!)<&fo(Y@07=Xaj)z4*} HQ$iB}+e|Y_ delta 124 zcmZ4RhH=3g#tEU!EPOX6Ph^y4mT^)C(M-ODKuU&5QUXkA%77_(E)d0R_=XWgGcE;^ zvWz>xQrE!L<^sOEf|D08eg-oBaI?HRe){_6K!x3*B5O~v&)waa@{a)sJYD@<);T3K F0RX-kD?0!H diff --git a/tests/testdata/control_images/expected_raster_colorRamp4/expected_raster_colorRamp4.png b/tests/testdata/control_images/expected_raster_colorRamp4/expected_raster_colorRamp4.png new file mode 100644 index 0000000000000000000000000000000000000000..df6979112c1707d41fbb1241700c0bde48b72777 GIT binary patch literal 30240 zcmeI*F-rnr0Eh8cT};r;rH0)56p4|yScFT^(9qTrNDwq6ZM9Z3RuB zsHwTu>TYQC@R5eJ=fFhXNAiCCN1=n|#$vHBT?io*qk3&6e%?qP`E302tDVioPq|h# zYUcC#r{|@9{BmlmzS;_*be}vjCv&Bl5Go<6%{O;4nd9xv!%XOQ<8I(pIUjfwA5<<< zPWMvILTIO+hP%|`)YE>LO?h)azW>43_2b*%!;m<84JjbjkWfh`mRLXlq%KP=AOKRA zB^D3>sml@z2!PaOi3J2e>axTF0w8r+VgUh=x-7AP07zYySU>=zE=w#R08*DF77zfb z%MuF+fOPa_9etE;f4&OZv48+bU6xot0HiKU zEFb_87rn