Skip to content

Commit

Permalink
fix cpt-city loading of invalid (non-existent) ramps in Seleections
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed Apr 25, 2013
1 parent 4f41de8 commit 89f34b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion resources/cpt-city-qgis-min/selections/div.xml
Expand Up @@ -35,7 +35,7 @@
<gradient file="Grand_Boucle" dir="jjg/ccolo/vredeling"/>
<gradient file="Optimus_Prime" dir="jjg/ccolo/vredeling"/>
<gradient file="British_Cheer" dir="jjg/ccolo/vredeling"/>
<gradient file="Tubular_Bells" dir="/jjg/ccolo/vredeling"/>
<gradient file="Tubular_Bells" dir="jjg/ccolo/vredeling"/>
<gradient file="xmas_22" dir="ma/xmas"/>
<gradient file="ha_14" dir="ma/postcard"/>
<gradient file="departure" dir="mjf"/>
Expand Down
18 changes: 11 additions & 7 deletions src/core/symbology-ng/qgscptcityarchive.cpp
Expand Up @@ -708,23 +708,25 @@ bool QgsCptCityDataItem::equal( const QgsCptCityDataItem *other )
// ---------------------------------------------------------------------

QgsCptCityColorRampItem::QgsCptCityColorRampItem( QgsCptCityDataItem* parent,
QString name, QString path, QString variantName )
QString name, QString path, QString variantName, bool initialize )
: QgsCptCityDataItem( ColorRamp, parent, name, path ),
mInitialised( false ), mRamp( path, variantName, false )
{
// QgsDebugMsg( "name= " + name + " path= " + path );
mPopulated = true;
//init();
if ( initialize )
init();
}

QgsCptCityColorRampItem::QgsCptCityColorRampItem( QgsCptCityDataItem* parent,
QString name, QString path, QStringList variantList )
QString name, QString path, QStringList variantList, bool initialize )
: QgsCptCityDataItem( ColorRamp, parent, name, path ),
mInitialised( false ), mRamp( path, variantList, QString(), false )
{
// QgsDebugMsg( "name= " + name + " path= " + path );
mPopulated = true;
//init();
if ( initialize )
init();
}

// TODO only load file when icon is requested...
Expand Down Expand Up @@ -878,10 +880,11 @@ QVector< QgsCptCityDataItem* > QgsCptCityCollectionItem::childrenRamps( bool rec
QgsDebugMsg( "invalid item " + childItem->path() );
}
}
// delete items - this is not efficient, but only happens once

// delete invalid items - this is not efficient, but should only happens once
foreach ( QgsCptCityDataItem* deleteItem, deleteItems )
{
QgsDebugMsg( QString( "item %1 is invalid, will be deleted" ).arg( deleteItem->path() ) );
int i = mChildren.indexOf( deleteItem );
if ( i != -1 )
mChildren.remove( i );
Expand Down Expand Up @@ -1215,7 +1218,8 @@ QVector<QgsCptCityDataItem*> QgsCptCitySelectionItem::createChildren()
}
else
{
item = new QgsCptCityColorRampItem( this, childPath, childPath );
// init item to test if is valid after loading file
item = new QgsCptCityColorRampItem( this, childPath, childPath, QString(), true );
if ( item->isValid() )
children << item;
else
Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology-ng/qgscptcityarchive.h
Expand Up @@ -198,10 +198,12 @@ class CORE_EXPORT QgsCptCityColorRampItem : public QgsCptCityDataItem
public:
QgsCptCityColorRampItem( QgsCptCityDataItem* parent,
QString name, QString path,
QString variantName = QString() );
QString variantName = QString(),
bool initialize = false );
QgsCptCityColorRampItem( QgsCptCityDataItem* parent,
QString name, QString path,
QStringList variantList );
QStringList variantList,
bool initialize = false );
~QgsCptCityColorRampItem() {}

// --- reimplemented from QgsCptCityDataItem ---
Expand Down
11 changes: 3 additions & 8 deletions src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp
Expand Up @@ -167,10 +167,6 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*

connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );

// TODO - remove this when basic archive is complete
if ( mArchive->archiveName() == DEFAULT_CPTCITY_ARCHIVE )
tabBar->setCurrentIndex( 1 );

}

QgsCptCityColorRampV2Dialog::~QgsCptCityColorRampV2Dialog()
Expand Down Expand Up @@ -495,7 +491,7 @@ void QgsCptCityColorRampV2Dialog::on_buttonBox_helpRequested()
QString helpText = tr( "You can download a more complete set of cpt-city gradients "
"by installing the \"Color Ramp Manager\" plugin "
"(you must enable Experimental plugins in the plugin manager).\n\n"
);
);
QMessageBox* msg = new QMessageBox( this );
msg->setText( helpText );
msg->exec();
Expand All @@ -510,12 +506,12 @@ bool QgsCptCityColorRampV2Dialog::saveAsGradientRamp() const

void QgsCptCityColorRampV2Dialog::updateListWidget( QgsCptCityDataItem *item )
{
mListWidget->clear();
mListRamps.clear();
QgsCptCityCollectionItem* colItem = dynamic_cast<QgsCptCityCollectionItem*>( item );
if ( colItem )
{
QgsDebugMsg( "path= " + item->path() );
mListWidget->clear();
mListRamps.clear();
// recursively get children ramps
QVector<QgsCptCityDataItem*> childrenRamps = colItem->childrenRamps( true );
for ( int i = 0; i < childrenRamps.count(); i++ )
Expand All @@ -538,7 +534,6 @@ void QgsCptCityColorRampV2Dialog::updateListWidget( QgsCptCityDataItem *item )
else
{
QgsDebugMsg( "invalid item" );
mListWidget->clear();
}
}

Expand Down

0 comments on commit 89f34b2

Please sign in to comment.