void
ThemesModel::setThemeImage( const QString& id, const QString& imagePath )
{
- auto* theme = m_themes.findById( id );
+ auto [ i, theme ] = m_themes.indexById( id );
if ( theme )
{
theme->imagePath = imagePath;
+ emit dataChanged( index( i, 0 ), index( i, 0 ), { ImageRole } );
}
}
return;
}
- for ( const auto& k : images )
+ // Don't emit signals from each call, aggregate to one call (below this block)
{
- setThemeImage( k, images[ k ] );
+ QSignalBlocker b( this );
+ for ( const auto& k : images )
+ {
+ setThemeImage( k, images[ k ] );
+ }
}
emit dataChanged( index( 0, 0 ), index( m_themes.count() - 1 ), { ImageRole } );
}
void
ThemesModel::showTheme( const QString& id, bool show )
{
- auto* theme = m_themes.findById( id );
+ auto [ i, theme ] = m_themes.indexById( id );
if ( theme )
{
theme->show = show;
+ emit dataChanged( index( i, 0 ), index( i, 0 ), { ShownRole } );
}
}
return;
}
+ // No signal blocker block needed here because we're not calling showTheme()
+ // QSignalBlocker b( this );
for ( auto& t : m_themes )
{
t.show = onlyThese.contains( t.id );
class ThemeInfoList : public QList< ThemeInfo >
{
public:
- std::pair< int, ThemeInfo* > indexById( const QString& id )
+ std::pair< int, const ThemeInfo* > indexById( const QString& id ) const
{
int index = 0;
- for ( ThemeInfo& i : *this )
+ for ( const ThemeInfo& i : *this )
{
if ( i.id == id )
{
return { -1, nullptr };
}
+ std::pair< int, ThemeInfo* > indexById( const QString& id )
+ {
+ // Call the const version and then munge the types
+ auto [ i, p ] = const_cast< const ThemeInfoList* >( this )->indexById( id );
+ return { i, const_cast< ThemeInfo* >( p ) };
+ }
+
/** @brief Looks for a given @p id in the list of themes, returns nullptr if not found. */
ThemeInfo* findById( const QString& id )
{
- for ( ThemeInfo& i : *this )
- {
- if ( i.id == id )
- {
- return &i;
- }
- }
- return nullptr;
+ auto [ i, p ] = indexById( id );
+ return p;
}
/** @brief Looks for a given @p id in the list of themes, returns nullptr if not found. */
const ThemeInfo* findById( const QString& id ) const
{
- for ( const ThemeInfo& i : *this )
- {
- if ( i.id == id )
- {
- return &i;
- }
- }
- return nullptr;
+ auto [ i, p ] = indexById( id );
+ return p;
}
/** @brief Checks if a given @p id is in the list of themes. */