Browse Source

qt: allow to move or remove range of items from the cache

this would allow to move or update elements in "a priori" before getting the
notification from the database
pull/134/head
Pierre Lamot 4 years ago
committed by Jean-Baptiste Kempf
parent
commit
5e7e9cac35
  1. 21
      modules/gui/qt/medialibrary/mlbasemodel.cpp
  2. 3
      modules/gui/qt/medialibrary/mlbasemodel.hpp
  3. 42
      modules/gui/qt/medialibrary/mllistcache.cpp
  4. 13
      modules/gui/qt/medialibrary/mllistcache.hpp

21
modules/gui/qt/medialibrary/mlbasemodel.cpp

@ -574,6 +574,27 @@ void MLBaseModel::deleteItemInCache(const MLItemId& mlid)
m_cache->deleteItem(mlid);
}
void MLBaseModel::moveRangeInCache(int first, int last, int to)
{
if (!m_cache)
{
emit resetRequested();
return;
}
m_cache->moveRange(first, last, to);
}
void MLBaseModel::deleteRangeInCache(int first, int last)
{
if (!m_cache)
{
emit resetRequested();
return;
}
m_cache->deleteRange(first, last);
}
//-------------------------------------------------------------------------------------------------
MLBaseModel::BaseLoader::BaseLoader(MLItemId parent, QString searchPattern,

3
modules/gui/qt/medialibrary/mlbasemodel.hpp

@ -123,6 +123,9 @@ protected:
//this is only to reflect changes from the ML, it won't alter the database
void deleteItemInCache(const MLItemId& mlid);
void moveRangeInCache(int first, int last, int to);
void deleteRangeInCache(int first, int last);
virtual void onVlcMlEvent( const MLEvent &event );

42
modules/gui/qt/medialibrary/mllistcache.cpp

@ -151,6 +151,48 @@ int MLListCache::deleteItem(const MLItemId& mlid)
return pos;
}
void MLListCache::moveRange(int first, int last, int to)
{
assert(first <= last);
if (first <= to && to <= last)
return;
emit beginMoveRows(first, last, to);
auto it = m_cachedData->list.begin();
//build a temporary list with the items in order
std::vector<ItemType> tmpList;
if (to < first)
{
std::move(it, it+to, std::back_inserter(tmpList));
std::move(it+first, it+(last+1), std::back_inserter(tmpList));
std::move(it+to, it+first, std::back_inserter(tmpList));
std::move(it+(last+1), m_cachedData->list.end(), std::back_inserter(tmpList));
}
else //last < to
{
std::move(it, it+first, std::back_inserter(tmpList));
std::move(it+last+1, it+to, std::back_inserter(tmpList));
std::move(it+first, it+(last+1), std::back_inserter(tmpList));
std::move(it+to, m_cachedData->list.end(), std::back_inserter(tmpList));
}
m_cachedData->list = std::move(tmpList);
emit endMoveRows();
}
void MLListCache::deleteRange(int first, int last)
{
assert(first <= last);
emit beginRemoveRows(first, last);
auto it = m_cachedData->list.begin();
m_cachedData->list.erase(it+first, it+(last+1));
size_t delta = m_cachedData->loadedCount - m_cachedData->list.size();
m_cachedData->loadedCount -= delta;
m_cachedData->totalCount -= delta;
emit endRemoveRows();
emit localSizeChanged(m_cachedData->totalCount);
}
ssize_t MLListCache::count() const
{
if (!m_cachedData)

13
modules/gui/qt/medialibrary/mllistcache.hpp

@ -155,6 +155,19 @@ public:
*/
int deleteItem(const MLItemId& mlid);
/**
* move items in the cache contained between @a first
* and @a last to the index @a to
*/
void moveRange(int first, int last, int to);
/**
* remove items in the cache from the index @a first up to the
* index @a last
*/
void deleteRange(int first, int last);
/**
* Return the number of items or `COUNT_UNINITIALIZED`
*

Loading…
Cancel
Save