[plasmalnf] Prep-work for loading the themes into the model

This commit is contained in:
Adriaan de Groot 2020-11-16 21:28:37 +01:00
parent 57907ca992
commit 254933a488
2 changed files with 52 additions and 0 deletions

View file

@ -60,6 +60,45 @@ ThemesModel::roleNames() const
return { { LabelRole, "label" }, { KeyRole, "key" } };
}
void
ThemesModel::setThemeImage( const QString& id, const QString& imagePath )
{
auto* theme = m_themes.findById( id );
if ( theme )
{
theme->imagePath = imagePath;
}
}
void
ThemesModel::setThemeImage( const QMap< QString, QString >& images )
{
for ( const auto& k : images )
{
setThemeImage( k, images[ k ] );
}
}
void
ThemesModel::showTheme( const QString& id, bool show )
{
auto* theme = m_themes.findById( id );
if ( theme )
{
theme->show = show;
}
}
void
ThemesModel::showTheme( const QMap< QString, QString >& onlyThese )
{
for ( auto& t : m_themes )
{
t.show = onlyThese.contains( t.id );
}
}
ThemeInfo::ThemeInfo( const KPluginMetaData& data )
: id( data.pluginId() )
, name( data.name() )

View file

@ -31,6 +31,7 @@ struct ThemeInfo
QString description;
QString imagePath;
ThemeWidget* widget;
bool show = true;
ThemeInfo()
: widget( nullptr )
@ -108,6 +109,18 @@ public:
const ThemeInfo* findById( const QString& id ) const { return m_themes.findById( id ); }
/// @brief Set the screenshot to go with the given @p id
void setThemeImage( const QString& id, const QString& imagePath );
/// @brief Call setThemeImage( key, value ) for all keys in @p images
void setThemeImage( const QMap< QString, QString >& images );
/// @brief Set whether to show the given theme @p id (or not)
void showTheme( const QString& id, bool show = true );
/// @brief Shows the keys in the @p onlyThese map, and hides the rest
void showTheme( const QMap< QString, QString >& onlyThese );
private:
ThemeInfoList m_themes;
};