From a15a7052c44d22e8cbb51b9456e1899ed8d064da Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 29 Jun 2018 13:53:08 +0200 Subject: [PATCH] CMake: Simplify CMakeTool registration in CMakeToolManager Change-Id: Ida5e6aea8c39ef21f535e06c8fed11b130f875e9 Reviewed-by: Eike Ziller --- .../cmakeprojectmanager/cmaketoolmanager.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp b/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp index 19e3c7d5488..4249cd99651 100644 --- a/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp @@ -242,11 +242,10 @@ QList CMakeToolManager::cmakeTools() Id CMakeToolManager::registerOrFindCMakeTool(const FileName &command) { - CMakeTool *cmake = findByCommand(command); - if (cmake) + if (CMakeTool *cmake = findByCommand(command)) return cmake->id(); - cmake = new CMakeTool(CMakeTool::ManualDetection, CMakeTool::createId()); + CMakeTool *cmake = new CMakeTool(CMakeTool::ManualDetection, CMakeTool::createId()); cmake->setCMakeExecutable(command); cmake->setDisplayName(tr("CMake at %1").arg(command.toUserOutput())); @@ -259,21 +258,21 @@ bool CMakeToolManager::registerCMakeTool(CMakeTool *tool) if (!tool || d->m_cmakeTools.contains(tool)) return true; - QTC_ASSERT(tool->id().isValid(),return false); + const Core::Id toolId = tool->id(); + QTC_ASSERT(toolId.isValid(),return false); //make sure the same id was not used before - foreach (CMakeTool *current, d->m_cmakeTools) { - if (tool->id() == current->id()) - return false; - } + QTC_ASSERT(!Utils::contains(d->m_cmakeTools, [toolId](const CMakeTool *known) { + return toolId == known->id(); + }), return false); d->m_cmakeTools.append(tool); - emit CMakeToolManager::m_instance->cmakeAdded(tool->id()); + emit CMakeToolManager::m_instance->cmakeAdded(toolId); //set the first registered cmake tool as default if there is not already one if (!d->m_defaultCMake.isValid()) - CMakeToolManager::setDefaultCMakeTool(tool->id()); + CMakeToolManager::setDefaultCMakeTool(toolId); return true; }