From 2aeecda9ad79d35ed44c5e94b19af73050c9c3e3 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Fri, 24 Jan 2014 23:54:21 +0100 Subject: [PATCH] Controllers Naming: Prevent duplicate names For this, iterate through all given names and use the next name that's available. --- src/core/Controller.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 41bff4dcc..d1260fd35 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -3,6 +3,7 @@ * remote-control of AutomatableModels * * Copyright (c) 2008 Paul Giblock + * Copyright (c) 2014 Lukas W * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -53,8 +54,30 @@ Controller::Controller( ControllerTypes _type, Model * _parent, if( _type != DummyController && _type != MidiController ) { s_controllers.append( this ); - m_name = QString( tr( "Controller %1" ) ) - .arg( s_controllers.size() ); + // Determine which name to use + for ( uint i=s_controllers.size(); ; i++ ) + { + QString new_name = QString( tr( "Controller %1" ) ) + .arg( i ); + + // Check if name is already in use + bool name_used = false; + QVector::const_iterator it; + for ( it = s_controllers.constBegin(); + it != s_controllers.constEnd(); ++it ) + { + if ( (*it)->name() == new_name ) + { + name_used = true; + break; + } + } + if ( ! name_used ) + { + m_name = new_name; + break; + } + } } }