From f9e99da4686829ec28822f75ed112c4aaaaa259f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 17 Nov 2020 00:12:47 +0100 Subject: [PATCH] [plasmalnf] Improve lnf model - remove useless widget pointer from themeinfo - notify when data changes in the model --- src/modules/plasmalnf/ThemeInfo.cpp | 15 +++++++++++++-- src/modules/plasmalnf/ThemeInfo.h | 12 +++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/modules/plasmalnf/ThemeInfo.cpp b/src/modules/plasmalnf/ThemeInfo.cpp index c9ab3e36a..f3f2a192a 100644 --- a/src/modules/plasmalnf/ThemeInfo.cpp +++ b/src/modules/plasmalnf/ThemeInfo.cpp @@ -59,7 +59,7 @@ ThemesModel::data( const QModelIndex& index, int role ) const QHash< int, QByteArray > ThemesModel::roleNames() const { - return { { LabelRole, "label" }, { KeyRole, "key" } }; + return { { LabelRole, "label" }, { KeyRole, "key" }, { ShownRole, "show" }, { ImageRole, "image" } }; } void @@ -75,10 +75,16 @@ ThemesModel::setThemeImage( const QString& id, const QString& imagePath ) void ThemesModel::setThemeImage( const QMap< QString, QString >& images ) { + if ( m_themes.isEmpty() ) + { + return; + } + for ( const auto& k : images ) { setThemeImage( k, images[ k ] ); } + emit dataChanged( index( 0, 0 ), index( m_themes.count() - 1 ), { ImageRole } ); } void @@ -94,10 +100,16 @@ ThemesModel::showTheme( const QString& id, bool show ) void ThemesModel::showOnlyThemes( const QMap< QString, QString >& onlyThese ) { + if ( m_themes.isEmpty() ) + { + return; + } + for ( auto& t : m_themes ) { 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() ) , name( data.name() ) , description( data.description() ) - , widget( nullptr ) { } diff --git a/src/modules/plasmalnf/ThemeInfo.h b/src/modules/plasmalnf/ThemeInfo.h index cba9b87d6..a75c3c2bc 100644 --- a/src/modules/plasmalnf/ThemeInfo.h +++ b/src/modules/plasmalnf/ThemeInfo.h @@ -15,7 +15,6 @@ #include class KPluginMetaData; -class ThemeWidget; /** @brief describes a single plasma LnF theme. * @@ -30,24 +29,18 @@ struct ThemeInfo QString name; QString description; QString imagePath; - ThemeWidget* widget; bool show = true; - ThemeInfo() - : widget( nullptr ) - { - } + ThemeInfo() {} explicit ThemeInfo( const QString& _id ) : id( _id ) - , widget( nullptr ) { } explicit ThemeInfo( const QString& _id, const QString& image ) : id( _id ) , imagePath( image ) - , widget( nullptr ) { } @@ -98,7 +91,8 @@ public: { LabelRole = Qt::DisplayRole, KeyRole = Qt::UserRole, - ShownRole + ShownRole, + ImageRole }; explicit ThemesModel( QObject* parent );