@@ -48,7 +48,11 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
48
48
edit->setReadOnly ( true );
49
49
// not sure if we want this long string to be translated
50
50
QString helpText = tr ( " Error - cpt-city gradient files not found.\n\n "
51
- " Please download the complete collection (in svg format) "
51
+ " You have two means of installing them:\n\n "
52
+ " 1) Install the \" Color Ramp Manager\" python plugin "
53
+ " (you must enable Experimental plugins in the plugin manager) "
54
+ " and use it to download latest cpt-city package.\n\n "
55
+ " 2) Download the complete collection (in svg format) "
52
56
" and unzip it to your QGis settings directory [%1] .\n\n "
53
57
" This file can be found at [%2]\n and current file is [%3]"
54
58
).arg ( QgsApplication::qgisSettingsDirPath ()
@@ -61,6 +65,8 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
61
65
return ;
62
66
}
63
67
68
+ treeWidget->setIconSize ( QSize ( 100 , 15 ) );
69
+
64
70
populateSchemes ( " author" );
65
71
treeWidget->setCurrentItem ( findPath ( ramp->schemeName () ) );
66
72
populateVariants ();
@@ -249,31 +255,66 @@ void QgsCptCityColorRampV2Dialog::on_treeWidget_itemExpanded( QTreeWidgetItem *
249
255
// set color count when item is expanded
250
256
QgsCptCityColorRampV2 ramp ( " " , " " );
251
257
QTreeWidgetItem* childItem = 0 ;
252
- QString itemPath, itemDesc;
258
+ QString itemPath, itemDesc, itemVariants;
259
+ QStringList listVariants;
260
+ QPixmap blankPixmap ( treeWidget->iconSize () );
261
+ blankPixmap.fill ( Qt::white );
262
+ QIcon blankIcon ( blankPixmap );
253
263
254
264
for ( int i = 0 ; i < item->childCount (); i++ )
255
265
{
256
266
childItem = item->child ( i );
257
267
268
+ // skip invalid items or collection items
269
+ if ( ! childItem || childItem->data ( 0 , Qt::UserRole ).toString ().endsWith ( " /" ) )
270
+ continue ;
271
+
258
272
// items with null description need information, those with "" (i.e. unnamed collections) not be checked
259
273
// TODO set type when there are variants - based on the first file
260
274
if ( childItem && childItem->text ( 1 ).isNull () )
261
275
{
262
276
itemPath = childItem->data ( 0 , Qt::UserRole ).toString ();
263
277
itemDesc = " " ;
264
278
ramp.setSchemeName ( itemPath );
279
+ ramp.setVariantName ( " " );
280
+
281
+ // if item has variants, use middle item for preview
282
+ itemVariants = childItem->data ( 1 , Qt::UserRole ).toString ();
283
+ if ( ! itemVariants.isNull () )
284
+ {
285
+ listVariants = itemVariants.split ( " " , QString::SkipEmptyParts );
286
+ if ( ! listVariants.isEmpty () )
287
+ ramp.setVariantName ( listVariants[ listVariants.count () / 2 ] );
288
+ else
289
+ itemVariants = QString ();
290
+ }
291
+ // load file and set info
265
292
if ( ramp.loadFile () )
266
293
{
267
- itemDesc = QString::number ( ramp.count () ) + " " + tr ( " colors" ) + " - " ;
268
- QgsCptCityColorRampV2::GradientType type = ramp.gradientType ();
269
- if ( type == QgsCptCityColorRampV2::Continuous )
270
- itemDesc += tr ( " continuous" );
271
- else if ( type == QgsCptCityColorRampV2::ContinuousMulti )
272
- itemDesc += tr ( " continuous (multi)" );
273
- else if ( type == QgsCptCityColorRampV2::Discrete )
274
- itemDesc += tr ( " discrete" );
294
+ if ( itemVariants.isNull () )
295
+ {
296
+ itemDesc = QString::number ( ramp.count () ) + " " + tr ( " colors" ) + " - " ;
297
+ QgsCptCityColorRampV2::GradientType type = ramp.gradientType ();
298
+ if ( type == QgsCptCityColorRampV2::Continuous )
299
+ itemDesc += tr ( " continuous" );
300
+ else if ( type == QgsCptCityColorRampV2::ContinuousMulti )
301
+ itemDesc += tr ( " continuous (multi)" );
302
+ else if ( type == QgsCptCityColorRampV2::Discrete )
303
+ itemDesc += tr ( " discrete" );
304
+ }
305
+ else
306
+ {
307
+ itemDesc = QString::number ( listVariants.count () ) + " " + tr ( " variants" );
308
+ }
309
+ childItem->setText ( 1 , " " + itemDesc );
310
+ QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon ( &ramp, treeWidget->iconSize () );
311
+ childItem->setIcon ( 1 , icon );
312
+ }
313
+ else
314
+ {
315
+ childItem->setIcon ( 1 , blankIcon );
316
+ childItem->setText ( 1 , " " );
275
317
}
276
- childItem->setText ( 1 , " " + itemDesc );
277
318
}
278
319
}
279
320
}
@@ -377,17 +418,17 @@ void QgsCptCityColorRampV2Dialog::makeSchemeItem( QTreeWidgetItem *item, const Q
377
418
{
378
419
QString descStr, descData;// , variantStr;
379
420
QString curName, curVariant;
380
- QStringList listVariant ;
421
+ QStringList listVariants ;
381
422
QTreeWidgetItem *childItem;
382
423
383
424
// // descStr = schemeName;
384
- listVariant = QgsCptCityColorRampV2::schemeVariants ().value ( path + " /" + schemeName );
425
+ listVariants = QgsCptCityColorRampV2::schemeVariants ().value ( path + " /" + schemeName );
385
426
386
- if ( listVariant .count () > 1 )
427
+ if ( listVariants .count () > 1 )
387
428
{
388
- // variantStr = QString::number( listVariant .count() ) + " " + tr( "variants" );
389
- descStr = " " + QString::number ( listVariant .count () ) + " " + tr ( " variants" );
390
- descData = listVariant .join ( " " );
429
+ // variantStr = QString::number( listVariants .count() ) + " " + tr( "variants" );
430
+ // descStr = " " + QString::number( listVariants .count() ) + " " + tr( "variants" );
431
+ descData = listVariants .join ( " " );
391
432
}
392
433
393
434
childItem = new QTreeWidgetItem ( QStringList () << schemeName << descStr );
0 commit comments