Skip to content
Snippets Groups Projects
Commit 572b5887 authored by Pierre Lamot's avatar Pierre Lamot Committed by Jean-Baptiste Kempf
Browse files

qt: fix deleting/updating items in cache before it's loaded

parent 3035fa4e
No related branches found
No related tags found
1 merge request!1707qt: fix deleting/updating items in cache before it's loaded
Pipeline #207502 passed with stages
in 35 minutes and 51 seconds
......@@ -143,6 +143,10 @@ int MLListCache::updateItem(std::unique_ptr<MLItem>&& newItem)
if (m_oldData)
return -1;
//we can't update an item before we have any cache
if (unlikely(!m_cachedData))
return -1;
MLItemId mlid = newItem->getId();
//this may be inneficient to look at every items, maybe we can have a hashmap to access the items by id
auto it = std::find_if(m_cachedData->list.begin(), m_cachedData->list.end(), [mlid](const ItemType& item) {
......@@ -165,6 +169,10 @@ int MLListCache::deleteItem(const MLItemId& mlid)
if (m_oldData)
return -1;
//we can't remove an item before we have any cache
if (unlikely(!m_cachedData))
return -1;
auto it = std::find_if(m_cachedData->list.begin(), m_cachedData->list.end(), [mlid](const ItemType& item) {
return (item->getId() == mlid);
});
......@@ -192,6 +200,9 @@ void MLListCache::moveRange(int first, int last, int to)
if (first <= to && to <= last)
return;
if (unlikely(!m_cachedData))
return;
emit beginMoveRows(first, last, to);
auto it = m_cachedData->list.begin();
//build a temporary list with the items in order
......@@ -217,6 +228,9 @@ void MLListCache::moveRange(int first, int last, int to)
void MLListCache::deleteRange(int first, int last)
{
if (unlikely(!m_cachedData))
return;
assert(first <= last);
emit beginRemoveRows(first, last);
auto it = m_cachedData->list.begin();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment