Skip to content

Commit bae03b7

Browse files
committed
colorramp: modify tests for builtin gradients, fix rendering
1 parent e36e4ae commit bae03b7

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

src/core/symbology-ng/qgscolorrampv2data.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,9 @@ static const char* cptCityNames [] =
473473
static const char* cptCitySelectionsMin [] =
474474
{
475475
"",
476-
"cb",
476+
"test",
477477
"cb/",
478+
"grass/",
478479
NULL, NULL
479480
};
480481

src/core/symbology-ng/qgsvectorcolorrampv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ QColor QgsCptCityColorRampV2::color( double value ) const
362362
c1 = mPalette[0].second;
363363
for ( int i = 0; i < numStops; i++ )
364364
{
365-
if ( mPalette[i].first >= value )
365+
if ( mPalette[i].first > value )
366366
{
367367
if ( mGradientType == Discrete )
368368
return c1;

tests/src/core/testqgsrasterlayer.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class TestQgsRasterLayer: public QObject
5858
void colorRamp1();
5959
void colorRamp2();
6060
void colorRamp3();
61+
void colorRamp4();
6162
void landsatBasic();
6263
void landsatBasic875Qml();
6364
void checkDimensions();
@@ -254,10 +255,19 @@ void TestQgsRasterLayer::colorRamp2()
254255

255256
void TestQgsRasterLayer::colorRamp3()
256257
{
257-
// cpt-city ramp, small selection available in <testdir>/cpt-city
258-
QgsCptCityCollection::initCollection( DEFAULT_CPTCITY_COLLECTION, mTestDataDir + "cpt-city" );
258+
// cpt-city ramp, discrete
259+
QgsCptCityCollection::initCollections();
259260
QVERIFY( testColorRamp( "raster_colorRamp3",
260-
new QgsCptCityColorRampV2( "gmt/GMT_panoply", "" ),
261+
new QgsCptCityColorRampV2( "cb/div/BrBG", "_10" ),
262+
QgsColorRampShader::DISCRETE, 10 ) );
263+
}
264+
265+
void TestQgsRasterLayer::colorRamp4()
266+
{
267+
// cpt-city ramp, continuous
268+
QgsCptCityCollection::initCollections();
269+
QVERIFY( testColorRamp( "raster_colorRamp4",
270+
new QgsCptCityColorRampV2( "grass/elevation", "" ),
261271
QgsColorRampShader::DISCRETE, 10 ) );
262272
}
263273

tests/src/core/testqgsstylev2.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void TestStyleV2::initTestCase()
8383
// mStyle->clear();
8484

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

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

127-
// if ( QgsCptCityColorRampV2::hasBasicSchemes() )
128-
// {
129-
QgsCptCityColorRampV2* cc1Ramp = new QgsCptCityColorRampV2( "jjg/misc/temperature", "" );
127+
// discrete ramp with no variant
128+
QgsCptCityColorRampV2* cc1Ramp = new QgsCptCityColorRampV2( "cb/seq/PuBuGn_06", "" );
130129
QVERIFY( mStyle->addColorRamp( "test_cc1", cc1Ramp ) );
130+
// discrete ramp with variant
131131
QgsCptCityColorRampV2* cc2Ramp = new QgsCptCityColorRampV2( "cb/div/PiYG", "_10" );
132132
QVERIFY( mStyle->addColorRamp( "test_cc2", cc2Ramp ) );
133-
// }
134-
// else
135-
// {
136-
// QWARN( "cpt-city support files not found - skipping cpt-city color ramp tests" );
137-
// }
133+
// continuous ramp
134+
QgsCptCityColorRampV2* cc3Ramp = new QgsCptCityColorRampV2( "grass/byr", "" );
135+
QVERIFY( mStyle->addColorRamp( "test_cc3", cc3Ramp ) );
138136
}
139137

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

157155
// cpt-city
158-
// if ( QgsCptCityColorRampV2::hasAllSchemes() )
159-
// {
160156
colorRampsTest << "test_cc1";
161-
colorTests.insert( "test_cc1", qMakePair( 0.25, QColor( "#466fcf" ) ) );
162-
colorTests.insert( "test_cc1", qMakePair( 0.66, QColor( "#dbc85b" ) ) );
157+
colorTests.insert( "test_cc1", qMakePair( 0.25, QColor( "#d0d1e6" ) ) );
158+
colorTests.insert( "test_cc1", qMakePair( 0.66, QColor( "#67a9cf" ) ) );
163159
colorRampsTest << "test_cc2";
164160
colorTests.insert( "test_cc2", qMakePair( 0.25, QColor( "#de77ae" ) ) );
165161
colorTests.insert( "test_cc2", qMakePair( 0.66, QColor( "#b8e186" ) ) );
166-
// }
162+
colorRampsTest << "test_cc3";
163+
colorTests.insert( "test_cc3", qMakePair( 0.25, QColor( "#7f7f7f" ) ) );
164+
colorTests.insert( "test_cc3", qMakePair( 0.66, QColor( "#ffad00" ) ) );
167165

168166
foreach ( QString name, colorRampsTest )
169167
{
@@ -187,7 +185,7 @@ void TestStyleV2::testLoadColorRamps()
187185

188186
void TestStyleV2::testSaveLoad()
189187
{
190-
#if 0
188+
//#if 0
191189
mStyle->save();
192190
mStyle->clear();
193191
mStyle->load( QgsApplication::userStyleV2Path() );
@@ -204,7 +202,9 @@ void TestStyleV2::testSaveLoad()
204202
if ( ramp )
205203
delete ramp;
206204
}
207-
#endif
205+
// test color ramps again
206+
testLoadColorRamps();
207+
//#endif
208208
}
209209

210210

Loading
Loading

0 commit comments

Comments
 (0)