Skip to content

Commit

Permalink
style manager: avoid name duplication (fixes #11015)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 16, 2015
1 parent 9a99d2f commit ce95c59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/core/symbology-ng/qgsstylev2.cpp
Expand Up @@ -405,6 +405,12 @@ bool QgsStyleV2::save( QString filename )

bool QgsStyleV2::renameSymbol( QString oldName, QString newName )
{
if ( mSymbols.contains( newName ) )
{
QgsDebugMsg( "Symbol of new name already exists" );
return false;
}

QgsSymbolV2 *symbol = mSymbols.take( oldName );
if ( !symbol )
return false;
Expand All @@ -431,6 +437,12 @@ bool QgsStyleV2::renameSymbol( QString oldName, QString newName )

bool QgsStyleV2::renameColorRamp( QString oldName, QString newName )
{
if ( mColorRamps.contains( newName ) )
{
QgsDebugMsg( "Color ramp of new name already exists." );
return false;
}

QgsVectorColorRampV2 *ramp = mColorRamps.take( oldName );
if ( !ramp )
return false;
Expand Down
9 changes: 7 additions & 2 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -242,7 +242,7 @@ void QgsStyleV2ManagerDialog::populateSymbols( QStringList symbolNames, bool che
{
QString name = symbolNames[i];
QgsSymbolV2* symbol = mStyle->symbol( name );
if ( symbol->type() == type )
if ( symbol && symbol->type() == type )
{
QStandardItem* item = new QStandardItem( name );
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( symbol, listItems->iconSize() );
Expand Down Expand Up @@ -726,7 +726,12 @@ void QgsStyleV2ManagerDialog::itemChanged( QStandardItem* item )
populateList();
mModified = true;
}

else
{
QMessageBox::critical( this, tr( "Cannot rename item" ),
tr( "Name is already taken by another item. Choose a different name." ) );
item->setText( oldName );
}
}

void QgsStyleV2ManagerDialog::exportItems()
Expand Down

0 comments on commit ce95c59

Please sign in to comment.