Skip to content

Commit

Permalink
Merge pull request #7906 from borysiasty/deprecated_plugins_grayed_out
Browse files Browse the repository at this point in the history
[Plugin manager] Deprecated plugins grayed out and moved to the list bottom
  • Loading branch information
borysiasty committed Sep 18, 2018
2 parents e52dc86 + 840749c commit 5edb326
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/pluginmanager/qgspluginitemdelegate.cpp
Expand Up @@ -77,6 +77,10 @@ void QgsPluginItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem
{
painter->setPen( option.palette.highlightedText().color() );
}
else if ( index.data( PLUGIN_ISDEPRECATED_ROLE ).toString() == QLatin1String( "true" ) )
{
painter->setPen( option.palette.color( QPalette::Disabled, QPalette::Text ) );
}
else
{
painter->setPen( option.palette.text().color() );
Expand Down
1 change: 1 addition & 0 deletions src/app/pluginmanager/qgspluginmanager.cpp
Expand Up @@ -538,6 +538,7 @@ void QgsPluginManager::reloadModelData()
mypDetailItem->setData( it->value( QStringLiteral( "tags" ) ), PLUGIN_TAGS_ROLE );
mypDetailItem->setData( it->value( QStringLiteral( "downloads" ) ).rightJustified( 10, '0' ), PLUGIN_DOWNLOADS_ROLE );
mypDetailItem->setData( it->value( QStringLiteral( "average_vote" ) ), PLUGIN_VOTE_ROLE );
mypDetailItem->setData( it->value( QStringLiteral( "deprecated" ) ), PLUGIN_ISDEPRECATED_ROLE );

if ( QFileInfo( iconPath ).isFile() )
{
Expand Down
21 changes: 21 additions & 0 deletions src/app/pluginmanager/qgspluginsortfilterproxymodel.cpp
Expand Up @@ -151,3 +151,24 @@ void QgsPluginSortFilterProxyModel::sortPluginsByStatus()
sort( 0, Qt::DescendingOrder );
setSortRole( PLUGIN_STATUS_ROLE );
}



bool QgsPluginSortFilterProxyModel::lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const
{
// Always move deprecated plugins to bottom, regardless of the sort order.
const bool isLeftDepreciated = sourceModel()->data( source_left, PLUGIN_ISDEPRECATED_ROLE ).toString() == QStringLiteral( "true" );
const bool isRightDepreciated = sourceModel()->data( source_right, PLUGIN_ISDEPRECATED_ROLE ).toString() == QStringLiteral( "true" );
if ( isRightDepreciated && !isLeftDepreciated )
{
return sortOrder() == Qt::AscendingOrder ? true : false;
}
else if ( isLeftDepreciated && !isRightDepreciated )
{
return sortOrder() == Qt::AscendingOrder ? false : true;
}
else
{
return QSortFilterProxyModel::lessThan( source_left, source_right );
}
}
4 changes: 4 additions & 0 deletions src/app/pluginmanager/qgspluginsortfilterproxymodel.h
Expand Up @@ -29,6 +29,7 @@ const int PLUGIN_ERROR_ROLE = Qt::UserRole + 5; // for filtering
const int PLUGIN_STATUS_ROLE = Qt::UserRole + 6; // for filtering and sorting
const int PLUGIN_DOWNLOADS_ROLE = Qt::UserRole + 7; // for sorting
const int PLUGIN_VOTE_ROLE = Qt::UserRole + 8; // for sorting
const int PLUGIN_ISDEPRECATED_ROLE = Qt::UserRole + 9; // for styling
const int SPACER_ROLE = Qt::UserRole + 20; // for sorting


Expand Down Expand Up @@ -68,6 +69,9 @@ class QgsPluginSortFilterProxyModel : public QSortFilterProxyModel
//! The main filter method
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;

//! The sort method overwritten in order to always display deprecated plugins last.
bool lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const override;

private:
QStringList mAcceptedStatuses;
QString mAcceptedSpacers;
Expand Down

0 comments on commit 5edb326

Please sign in to comment.