[vlc-devel] [PATCH 03/13] qt: medialib: do not count on item()

Steve Lhomme robux4 at ycbcr.xyz
Mon Nov 23 17:52:05 CET 2020


It would be simpler to use rowCount() instead of the m_total_count 
value. This way you don't require to call rowCount() before.

On 2020-11-23 17:30, Romain Vimont wrote:
> The count is initialized by a call to rowCount(), which must be called
> before calling item().
> ---
>   modules/gui/qt/medialibrary/mlbasemodel.hpp | 13 ++-----------
>   1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp
> index 10ce9b71ec..1d2cb2233a 100644
> --- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
> @@ -219,20 +219,11 @@ public:
>   protected:
>       T* item(int signedidx) const
>       {
> -        if (signedidx < 0)
> +        if (!m_initialized || signedidx < 0)
>               return nullptr;
>   
>           unsigned int idx = static_cast<unsigned int>(signedidx);
> -        if ( m_initialized == false )
> -        {
> -            m_total_count = countTotalElements();
> -            if ( m_total_count > 0 )
> -                m_item_list = fetch();
> -            m_initialized = true;
> -            emit countChanged( static_cast<unsigned int>(m_total_count) );
> -        }
> -
> -        if ( idx >= m_total_count  )
> +        if ( idx >= m_total_count )
>               return nullptr;
>   
>           if ( idx < m_query_param.i_offset ||  idx >= m_query_param.i_offset + m_item_list.size() )
> -- 
> 2.29.2
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list