@@ -93,8 +93,8 @@ bool TestStyleV2::testValidColor( QgsVectorColorRampV2 *ramp, double value, QCol
93
93
QColor result = ramp->color ( value );
94
94
if ( result != expected )
95
95
{
96
- QWARN ( QString ( " value = %1 result = %2 expected = %3" ).arg ( value ).arg (
97
- result.name () ).arg ( expected.name () ).toLocal8Bit ().data () );
96
+ QWARN ( QString ( " value = %1 result = %2 expected = %3" ).arg ( value ).arg (
97
+ result.name () ).arg ( expected.name () ).toLocal8Bit ().data () );
98
98
return false ;
99
99
}
100
100
return true ;
@@ -118,23 +118,51 @@ void TestStyleV2::testCreateColorRamps()
118
118
QVERIFY ( mStyle ->addColorRamp ( " test_cb1" , cb1Ramp ) == true );
119
119
QgsVectorColorBrewerColorRampV2* cb2Ramp = new QgsVectorColorBrewerColorRampV2 ( " RdYlGn" , 6 );
120
120
QVERIFY ( mStyle ->addColorRamp ( " test_cb2" , cb2Ramp ) == true );
121
+
122
+ // cpt-city ramp - use gradients that are free to distribute
123
+ // set base dir because we are using a test home path - change this if we distribute a minimal set with qgis
124
+ QgsCptCityColorRampV2::setBaseDir ( QDir::homePath () + QString ( " /.qgis/cpt-city" ) );
125
+ QgsCptCityColorRampV2::loadSchemes ( " " );
126
+ if ( QgsCptCityColorRampV2::hasBasicSchemes () )
127
+ {
128
+ QgsCptCityColorRampV2* cc1Ramp = new QgsCptCityColorRampV2 ( " jjg/misc/temperature" , " " );
129
+ QVERIFY ( mStyle ->addColorRamp ( " test_cc1" , cc1Ramp ) == true );
130
+ QgsCptCityColorRampV2* cc2Ramp = new QgsCptCityColorRampV2 ( " cb/div/PiYG" , " _10" );
131
+ QVERIFY ( mStyle ->addColorRamp ( " test_cc2" , cc2Ramp ) == true );
132
+ }
133
+ else
134
+ {
135
+ QWARN ( " cpt-city support files not found - skipping cpt-city color ramp tests" );
136
+ }
121
137
}
122
138
123
139
void TestStyleV2::testLoadColorRamps ()
124
140
{
125
141
QStringList colorRamps = mStyle ->colorRampNames ();
126
- QStringList colorRampsTest = QStringList () << " BrBG" << " Spectral"
127
- << " test_gradient" << " test_random" << " test_cb1" << " test_cb2" ;
142
+ QStringList colorRampsTest = QStringList () << " BrBG" << " Spectral"
143
+ << " test_gradient" << " test_random"
144
+ << " test_cb1" << " test_cb2" ;
128
145
129
146
// values for color tests
130
147
QMultiMap< QString, QPair< double , QColor> > colorTests;
131
- colorTests.insert ( " test_gradient" , qMakePair ( 0.25 , QColor ( " #ff7f7f" ) ) );
132
- colorTests.insert ( " test_gradient" , qMakePair ( 0.66 , QColor ( " #adadff" ) ) );
148
+ colorTests.insert ( " test_gradient" , qMakePair ( 0.25 , QColor ( " #ff7f7f" ) ) );
149
+ colorTests.insert ( " test_gradient" , qMakePair ( 0.66 , QColor ( " #adadff" ) ) );
133
150
// cannot test random colors!
134
- colorTests.insert ( " test_cb1" , qMakePair ( 0.25 , QColor ( " #fdae61" ) ) );
135
- colorTests.insert ( " test_cb1" , qMakePair ( 0.66 , QColor ( " #abdda4" ) ) );
136
- colorTests.insert ( " test_cb2" , qMakePair ( 0.25 , QColor ( " #fc8d59" ) ) );
137
- colorTests.insert ( " test_cb2" , qMakePair ( 0.66 , QColor ( " #d9ef8b" ) ) );
151
+ colorTests.insert ( " test_cb1" , qMakePair ( 0.25 , QColor ( " #fdae61" ) ) );
152
+ colorTests.insert ( " test_cb1" , qMakePair ( 0.66 , QColor ( " #abdda4" ) ) );
153
+ colorTests.insert ( " test_cb2" , qMakePair ( 0.25 , QColor ( " #fc8d59" ) ) );
154
+ colorTests.insert ( " test_cb2" , qMakePair ( 0.66 , QColor ( " #d9ef8b" ) ) );
155
+
156
+ // cpt-city
157
+ if ( QgsCptCityColorRampV2::hasAllSchemes () )
158
+ {
159
+ colorRampsTest << " test_cc1" ;
160
+ colorTests.insert ( " test_cc1" , qMakePair ( 0.25 , QColor ( " #466fcf" ) ) );
161
+ colorTests.insert ( " test_cc1" , qMakePair ( 0.66 , QColor ( " #dbc85b" ) ) );
162
+ colorRampsTest << " test_cc2" ;
163
+ colorTests.insert ( " test_cc2" , qMakePair ( 0.25 , QColor ( " #de77ae" ) ) );
164
+ colorTests.insert ( " test_cc2" , qMakePair ( 0.66 , QColor ( " #b8e186" ) ) );
165
+ }
138
166
139
167
foreach ( QString name, colorRampsTest )
140
168
{
@@ -148,19 +176,19 @@ void TestStyleV2::testLoadColorRamps()
148
176
QList< QPair< double , QColor> > values = colorTests.values ( name );
149
177
for ( int i = 0 ; i < values.size (); ++i )
150
178
{
151
- QVERIFY ( testValidColor ( ramp, values.at (i ).first , values.at (i ).second ) );
179
+ QVERIFY ( testValidColor ( ramp, values.at ( i ).first , values.at ( i ).second ) );
152
180
}
153
181
}
154
182
if ( ramp )
155
- delete ramp;
183
+ delete ramp;
156
184
}
157
185
}
158
186
159
187
void TestStyleV2::testSaveLoad ()
160
188
{
161
189
mStyle ->save ();
162
190
mStyle ->clear ();
163
- mStyle ->load ( QgsApplication::userStyleV2Path () );
191
+ mStyle ->load ( QgsApplication::userStyleV2Path () );
164
192
165
193
QStringList colorRamps = mStyle ->colorRampNames ();
166
194
QStringList colorRampsTest = QStringList () << " test_gradient" ;
@@ -172,7 +200,7 @@ void TestStyleV2::testSaveLoad()
172
200
QgsVectorColorRampV2* ramp = mStyle ->colorRamp ( name );
173
201
QVERIFY ( ramp != 0 );
174
202
if ( ramp )
175
- delete ramp;
203
+ delete ramp;
176
204
}
177
205
}
178
206
0 commit comments