Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cache pixmaps in feature list view
  • Loading branch information
nyalldawson committed Mar 8, 2016
1 parent ea10c5d commit 47d97b2
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/gui/attributetable/qgsfeaturelistviewdelegate.cpp
Expand Up @@ -58,6 +58,13 @@ QSize QgsFeatureListViewDelegate::sizeHint( const QStyleOptionViewItem& option,

void QgsFeatureListViewDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
static QPixmap selectedIcon;
if ( selectedIcon.isNull() )
selectedIcon = QgsApplication::getThemePixmap( "/mIconSelected.svg" );
static QPixmap deselectedIcon;
if ( deselectedIcon.isNull() )
deselectedIcon = QgsApplication::getThemePixmap( "/mIconDeselected.svg" );

QString text = index.model()->data( index, Qt::EditRole ).toString();
QgsFeatureListModel::FeatureInfo featInfo = index.model()->data( index, Qt::UserRole ).value<QgsFeatureListModel::FeatureInfo>();

Expand All @@ -68,25 +75,14 @@ void QgsFeatureListViewDelegate::paint( QPainter *painter, const QStyleOptionVie

QRect iconLayoutBounds( option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height() );

QPixmap icon;

if ( mFeatureSelectionModel->isSelected( index ) )
{
// Item is selected
icon = QgsApplication::getThemePixmap( "/mIconSelected.svg" );
}
else
{
icon = QgsApplication::getThemePixmap( "/mIconDeselected.svg" );
}
QPixmap icon = mFeatureSelectionModel->isSelected( index ) ? selectedIcon : deselectedIcon;

// Scale up the icon if needed
if ( option.rect.height() > sIconSize )
{
icon = icon.scaledToHeight( option.rect.height(), Qt::SmoothTransformation );
}


// Text layout options
QRect textLayoutBounds( iconLayoutBounds.x() + iconLayoutBounds.width(), option.rect.y(), option.rect.width() - ( iconLayoutBounds.x() + iconLayoutBounds.width() ), option.rect.height() );

Expand Down

0 comments on commit 47d97b2

Please sign in to comment.