Skip to content

Commit ce95c59

Browse files
committed
style manager: avoid name duplication (fixes #11015)
1 parent 9a99d2f commit ce95c59

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/core/symbology-ng/qgsstylev2.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ bool QgsStyleV2::save( QString filename )
405405

406406
bool QgsStyleV2::renameSymbol( QString oldName, QString newName )
407407
{
408+
if ( mSymbols.contains( newName ) )
409+
{
410+
QgsDebugMsg( "Symbol of new name already exists" );
411+
return false;
412+
}
413+
408414
QgsSymbolV2 *symbol = mSymbols.take( oldName );
409415
if ( !symbol )
410416
return false;
@@ -431,6 +437,12 @@ bool QgsStyleV2::renameSymbol( QString oldName, QString newName )
431437

432438
bool QgsStyleV2::renameColorRamp( QString oldName, QString newName )
433439
{
440+
if ( mColorRamps.contains( newName ) )
441+
{
442+
QgsDebugMsg( "Color ramp of new name already exists." );
443+
return false;
444+
}
445+
434446
QgsVectorColorRampV2 *ramp = mColorRamps.take( oldName );
435447
if ( !ramp )
436448
return false;

src/gui/symbology-ng/qgsstylev2managerdialog.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void QgsStyleV2ManagerDialog::populateSymbols( QStringList symbolNames, bool che
242242
{
243243
QString name = symbolNames[i];
244244
QgsSymbolV2* symbol = mStyle->symbol( name );
245-
if ( symbol->type() == type )
245+
if ( symbol && symbol->type() == type )
246246
{
247247
QStandardItem* item = new QStandardItem( name );
248248
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( symbol, listItems->iconSize() );
@@ -726,7 +726,12 @@ void QgsStyleV2ManagerDialog::itemChanged( QStandardItem* item )
726726
populateList();
727727
mModified = true;
728728
}
729-
729+
else
730+
{
731+
QMessageBox::critical( this, tr( "Cannot rename item" ),
732+
tr( "Name is already taken by another item. Choose a different name." ) );
733+
item->setText( oldName );
734+
}
730735
}
731736

732737
void QgsStyleV2ManagerDialog::exportItems()

0 commit comments

Comments
 (0)