forked from qt-creator/qt-creator
ProjectExplorer: Fix crash in toolchain widget
Amends d73d5fe0b1
Fixes: QTCREATORBUG-27696
Change-Id: Id94f39cd4fc6768af3f66039f808ed7c974cfeed
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -76,6 +76,8 @@ bool allOf(const T &container, F predicate);
|
|||||||
/////////////////////////
|
/////////////////////////
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
void erase(T &container, F predicate);
|
void erase(T &container, F predicate);
|
||||||
|
template<typename T, typename F>
|
||||||
|
bool eraseOne(T &container, F predicate);
|
||||||
|
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
// contains
|
// contains
|
||||||
@@ -442,7 +444,15 @@ void erase(T &container, F predicate)
|
|||||||
container.erase(std::remove_if(std::begin(container), std::end(container), predicate),
|
container.erase(std::remove_if(std::begin(container), std::end(container), predicate),
|
||||||
std::end(container));
|
std::end(container));
|
||||||
}
|
}
|
||||||
|
template<typename T, typename F>
|
||||||
|
bool eraseOne(T &container, F predicate)
|
||||||
|
{
|
||||||
|
const auto it = std::find_if(std::begin(container), std::end(container), predicate);
|
||||||
|
if (it == std::end(container))
|
||||||
|
return false;
|
||||||
|
container.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////
|
//////////////////
|
||||||
// contains
|
// contains
|
||||||
|
|||||||
@@ -363,27 +363,24 @@ ToolChainTreeItem *ToolChainOptionsWidget::insertToolChain(ToolChain *tc, bool c
|
|||||||
|
|
||||||
void ToolChainOptionsWidget::addToolChain(ToolChain *tc)
|
void ToolChainOptionsWidget::addToolChain(ToolChain *tc)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_toAddList.size(); ++i) {
|
if (Utils::eraseOne(m_toAddList, [tc](const ToolChainTreeItem *item) {
|
||||||
if (m_toAddList.at(i)->toolChain == tc) {
|
return item->toolChain == tc; })) {
|
||||||
// do not delete i element: Still used elsewhere!
|
// do not delete here!
|
||||||
m_toAddList.removeAt(i);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
insertToolChain(tc);
|
insertToolChain(tc);
|
||||||
|
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolChainOptionsWidget::removeToolChain(ToolChain *tc)
|
void ToolChainOptionsWidget::removeToolChain(ToolChain *tc)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_toRemoveList.size(); ++i) {
|
if (auto it = std::find_if(m_toRemoveList.begin(), m_toRemoveList.end(),
|
||||||
if (m_toRemoveList.at(i)->toolChain == tc) {
|
[tc](const ToolChainTreeItem *item) { return item->toolChain == tc; });
|
||||||
m_toRemoveList.removeAt(i);
|
it != m_toRemoveList.end()) {
|
||||||
delete m_toRemoveList.at(i);
|
m_toRemoveList.erase(it);
|
||||||
return;
|
delete *it;
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticTreeItem *parent = parentForToolChain(tc);
|
StaticTreeItem *parent = parentForToolChain(tc);
|
||||||
|
|||||||
Reference in New Issue
Block a user