Skip to content

Commit c5b2858

Browse files
committedAug 7, 2012
add preview icon to all items
1 parent fbbb71a commit c5b2858

File tree

2 files changed

+75
-22
lines changed

2 files changed

+75
-22
lines changed
 

‎src/core/symbology-ng/qgsvectorcolorrampv2.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,23 @@ QStringList QgsCptCityColorRampV2::listSchemeNames( QString collectionName )
432432

433433
QString QgsCptCityColorRampV2::getBaseDir()
434434
{
435-
// currently hard-coded, but could be also in QGis install path and/or configurable
436-
if ( mBaseDir.isNull() )
437-
return QgsApplication::qgisSettingsDirPath() + "/" + "cpt-city";
438-
else
439-
return mBaseDir;
435+
// if was set with setBaseDir, return that value
436+
QString baseDir = mBaseDir;
437+
438+
// use CptCity/baseDir setting if set
439+
if ( baseDir.isNull() )
440+
{
441+
QSettings settings;
442+
baseDir = settings.value( "CptCity/baseDir", QString() ).toString();
443+
if ( ! baseDir.isNull() )
444+
baseDir += "/cpt-city";
445+
}
446+
447+
// fallback to user setting dir
448+
if ( baseDir.isNull() )
449+
baseDir = QgsApplication::qgisSettingsDirPath() + "/" + "cpt-city";
450+
451+
return baseDir;
440452
}
441453

442454
QString QgsCptCityColorRampV2::getFilename() const

‎src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
4848
edit->setReadOnly( true );
4949
// not sure if we want this long string to be translated
5050
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) "
5256
"and unzip it to your QGis settings directory [%1] .\n\n"
5357
"This file can be found at [%2]\nand current file is [%3]"
5458
).arg( QgsApplication::qgisSettingsDirPath()
@@ -61,6 +65,8 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
6165
return;
6266
}
6367

68+
treeWidget->setIconSize( QSize( 100, 15 ) );
69+
6470
populateSchemes( "author" );
6571
treeWidget->setCurrentItem( findPath( ramp->schemeName() ) );
6672
populateVariants();
@@ -249,31 +255,66 @@ void QgsCptCityColorRampV2Dialog::on_treeWidget_itemExpanded( QTreeWidgetItem *
249255
// set color count when item is expanded
250256
QgsCptCityColorRampV2 ramp( "", "" );
251257
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 );
253263

254264
for ( int i = 0; i < item->childCount(); i++ )
255265
{
256266
childItem = item->child( i );
257267

268+
//skip invalid items or collection items
269+
if ( ! childItem || childItem->data( 0, Qt::UserRole ).toString().endsWith( "/" ) )
270+
continue;
271+
258272
// items with null description need information, those with "" (i.e. unnamed collections) not be checked
259273
// TODO set type when there are variants - based on the first file
260274
if ( childItem && childItem->text( 1 ).isNull() )
261275
{
262276
itemPath = childItem->data( 0, Qt::UserRole ).toString();
263277
itemDesc = "";
264278
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
265292
if ( ramp.loadFile() )
266293
{
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, "" );
275317
}
276-
childItem->setText( 1, " " + itemDesc );
277318
}
278319
}
279320
}
@@ -377,17 +418,17 @@ void QgsCptCityColorRampV2Dialog::makeSchemeItem( QTreeWidgetItem *item, const Q
377418
{
378419
QString descStr, descData;//, variantStr;
379420
QString curName, curVariant;
380-
QStringList listVariant;
421+
QStringList listVariants;
381422
QTreeWidgetItem *childItem;
382423

383424
// // descStr = schemeName;
384-
listVariant = QgsCptCityColorRampV2::schemeVariants().value( path + "/" + schemeName );
425+
listVariants = QgsCptCityColorRampV2::schemeVariants().value( path + "/" + schemeName );
385426

386-
if ( listVariant.count() > 1 )
427+
if ( listVariants.count() > 1 )
387428
{
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( " " );
391432
}
392433

393434
childItem = new QTreeWidgetItem( QStringList() << schemeName << descStr );

0 commit comments

Comments
 (0)
Please sign in to comment.