Skip to content

Commit 5edb326

Browse files
authored
Merge pull request #7906 from borysiasty/deprecated_plugins_grayed_out
[Plugin manager] Deprecated plugins grayed out and moved to the list bottom
2 parents e52dc86 + 840749c commit 5edb326

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

src/app/pluginmanager/qgspluginitemdelegate.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ void QgsPluginItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem
7777
{
7878
painter->setPen( option.palette.highlightedText().color() );
7979
}
80+
else if ( index.data( PLUGIN_ISDEPRECATED_ROLE ).toString() == QLatin1String( "true" ) )
81+
{
82+
painter->setPen( option.palette.color( QPalette::Disabled, QPalette::Text ) );
83+
}
8084
else
8185
{
8286
painter->setPen( option.palette.text().color() );

src/app/pluginmanager/qgspluginmanager.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ void QgsPluginManager::reloadModelData()
538538
mypDetailItem->setData( it->value( QStringLiteral( "tags" ) ), PLUGIN_TAGS_ROLE );
539539
mypDetailItem->setData( it->value( QStringLiteral( "downloads" ) ).rightJustified( 10, '0' ), PLUGIN_DOWNLOADS_ROLE );
540540
mypDetailItem->setData( it->value( QStringLiteral( "average_vote" ) ), PLUGIN_VOTE_ROLE );
541+
mypDetailItem->setData( it->value( QStringLiteral( "deprecated" ) ), PLUGIN_ISDEPRECATED_ROLE );
541542

542543
if ( QFileInfo( iconPath ).isFile() )
543544
{

src/app/pluginmanager/qgspluginsortfilterproxymodel.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,24 @@ void QgsPluginSortFilterProxyModel::sortPluginsByStatus()
151151
sort( 0, Qt::DescendingOrder );
152152
setSortRole( PLUGIN_STATUS_ROLE );
153153
}
154+
155+
156+
157+
bool QgsPluginSortFilterProxyModel::lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const
158+
{
159+
// Always move deprecated plugins to bottom, regardless of the sort order.
160+
const bool isLeftDepreciated = sourceModel()->data( source_left, PLUGIN_ISDEPRECATED_ROLE ).toString() == QStringLiteral( "true" );
161+
const bool isRightDepreciated = sourceModel()->data( source_right, PLUGIN_ISDEPRECATED_ROLE ).toString() == QStringLiteral( "true" );
162+
if ( isRightDepreciated && !isLeftDepreciated )
163+
{
164+
return sortOrder() == Qt::AscendingOrder ? true : false;
165+
}
166+
else if ( isLeftDepreciated && !isRightDepreciated )
167+
{
168+
return sortOrder() == Qt::AscendingOrder ? false : true;
169+
}
170+
else
171+
{
172+
return QSortFilterProxyModel::lessThan( source_left, source_right );
173+
}
174+
}

src/app/pluginmanager/qgspluginsortfilterproxymodel.h

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const int PLUGIN_ERROR_ROLE = Qt::UserRole + 5; // for filtering
2929
const int PLUGIN_STATUS_ROLE = Qt::UserRole + 6; // for filtering and sorting
3030
const int PLUGIN_DOWNLOADS_ROLE = Qt::UserRole + 7; // for sorting
3131
const int PLUGIN_VOTE_ROLE = Qt::UserRole + 8; // for sorting
32+
const int PLUGIN_ISDEPRECATED_ROLE = Qt::UserRole + 9; // for styling
3233
const int SPACER_ROLE = Qt::UserRole + 20; // for sorting
3334

3435

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

72+
//! The sort method overwritten in order to always display deprecated plugins last.
73+
bool lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const override;
74+
7175
private:
7276
QStringList mAcceptedStatuses;
7377
QString mAcceptedSpacers;

0 commit comments

Comments
 (0)