[plasmalnf] Improve lnf model
- remove useless widget pointer from themeinfo - notify when data changes in the model
This commit is contained in:
parent
1f57a0ddda
commit
f9e99da468
@ -59,7 +59,7 @@ ThemesModel::data( const QModelIndex& index, int role ) const
|
|||||||
QHash< int, QByteArray >
|
QHash< int, QByteArray >
|
||||||
ThemesModel::roleNames() const
|
ThemesModel::roleNames() const
|
||||||
{
|
{
|
||||||
return { { LabelRole, "label" }, { KeyRole, "key" } };
|
return { { LabelRole, "label" }, { KeyRole, "key" }, { ShownRole, "show" }, { ImageRole, "image" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -75,10 +75,16 @@ ThemesModel::setThemeImage( const QString& id, const QString& imagePath )
|
|||||||
void
|
void
|
||||||
ThemesModel::setThemeImage( const QMap< QString, QString >& images )
|
ThemesModel::setThemeImage( const QMap< QString, QString >& images )
|
||||||
{
|
{
|
||||||
|
if ( m_themes.isEmpty() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for ( const auto& k : images )
|
for ( const auto& k : images )
|
||||||
{
|
{
|
||||||
setThemeImage( k, images[ k ] );
|
setThemeImage( k, images[ k ] );
|
||||||
}
|
}
|
||||||
|
emit dataChanged( index( 0, 0 ), index( m_themes.count() - 1 ), { ImageRole } );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -94,10 +100,16 @@ ThemesModel::showTheme( const QString& id, bool show )
|
|||||||
void
|
void
|
||||||
ThemesModel::showOnlyThemes( const QMap< QString, QString >& onlyThese )
|
ThemesModel::showOnlyThemes( const QMap< QString, QString >& onlyThese )
|
||||||
{
|
{
|
||||||
|
if ( m_themes.isEmpty() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for ( auto& t : m_themes )
|
for ( auto& t : m_themes )
|
||||||
{
|
{
|
||||||
t.show = onlyThese.contains( t.id );
|
t.show = onlyThese.contains( t.id );
|
||||||
}
|
}
|
||||||
|
emit dataChanged( index( 0, 0 ), index( m_themes.count() - 1 ), { ShownRole } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -105,6 +117,5 @@ ThemeInfo::ThemeInfo( const KPluginMetaData& data )
|
|||||||
: id( data.pluginId() )
|
: id( data.pluginId() )
|
||||||
, name( data.name() )
|
, name( data.name() )
|
||||||
, description( data.description() )
|
, description( data.description() )
|
||||||
, widget( nullptr )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class KPluginMetaData;
|
class KPluginMetaData;
|
||||||
class ThemeWidget;
|
|
||||||
|
|
||||||
/** @brief describes a single plasma LnF theme.
|
/** @brief describes a single plasma LnF theme.
|
||||||
*
|
*
|
||||||
@ -30,24 +29,18 @@ struct ThemeInfo
|
|||||||
QString name;
|
QString name;
|
||||||
QString description;
|
QString description;
|
||||||
QString imagePath;
|
QString imagePath;
|
||||||
ThemeWidget* widget;
|
|
||||||
bool show = true;
|
bool show = true;
|
||||||
|
|
||||||
ThemeInfo()
|
ThemeInfo() {}
|
||||||
: widget( nullptr )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit ThemeInfo( const QString& _id )
|
explicit ThemeInfo( const QString& _id )
|
||||||
: id( _id )
|
: id( _id )
|
||||||
, widget( nullptr )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit ThemeInfo( const QString& _id, const QString& image )
|
explicit ThemeInfo( const QString& _id, const QString& image )
|
||||||
: id( _id )
|
: id( _id )
|
||||||
, imagePath( image )
|
, imagePath( image )
|
||||||
, widget( nullptr )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +91,8 @@ public:
|
|||||||
{
|
{
|
||||||
LabelRole = Qt::DisplayRole,
|
LabelRole = Qt::DisplayRole,
|
||||||
KeyRole = Qt::UserRole,
|
KeyRole = Qt::UserRole,
|
||||||
ShownRole
|
ShownRole,
|
||||||
|
ImageRole
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ThemesModel( QObject* parent );
|
explicit ThemesModel( QObject* parent );
|
||||||
|
Loading…
Reference in New Issue
Block a user