Skip to content

Commit

Permalink
Use lossless format to get sharper project preview images
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 authored and nirvn committed Jan 13, 2024
1 parent b2d24bc commit 0147c41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/core/projectsimageprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ QImage ProjectsImageProvider::requestImage( const QString &id, QSize *size, cons
{
// the id is passed on as an encoded URL string which needs decoding
const QString path = QUrl::fromPercentEncoding( id.toUtf8() );
const QString previewPath = QStringLiteral( "%1.jpg" ).arg( path );
return QFileInfo::exists( previewPath ) ? QImage( previewPath ) : QImage();
const QString previewPath = QStringLiteral( "%1.png" ).arg( path );

if ( QFileInfo::exists( previewPath ) )
return QImage( previewPath );

// Fallback to jpg generated by older QField versions
const QString previewPathJpg = QStringLiteral( "%1.jpg" ).arg( path );
if ( QFileInfo::exists( previewPathJpg ) )
return QImage( previewPathJpg );

return QImage();
}
4 changes: 2 additions & 2 deletions src/core/qgismobileapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ void QgisMobileapp::onMapCanvasRefreshed()
disconnect( mMapCanvas, &QgsQuickMapCanvasMap::mapCanvasRefreshed, this, &QgisMobileapp::onMapCanvasRefreshed );
if ( !mProjectFilePath.isEmpty() )
{
if ( !QFileInfo::exists( QStringLiteral( "%1.jpg" ).arg( mProjectFilePath ) ) )
if ( !QFileInfo::exists( QStringLiteral( "%1.png" ).arg( mProjectFilePath ) ) )
{
saveProjectPreviewImage();
}
Expand Down Expand Up @@ -1371,7 +1371,7 @@ void QgisMobileapp::saveProjectPreviewImage()
const int pixels = std::min( grab.width(), grab.height() );
const QRect rect( ( grab.width() - pixels ) / 2, ( grab.height() - pixels ) / 2, pixels, pixels );
const QImage img = grab.copy( rect );
img.save( QStringLiteral( "%1.jpg" ).arg( mProjectFilePath ) );
img.save( QStringLiteral( "%1.png" ).arg( mProjectFilePath ) );
}
}
}
Expand Down

0 comments on commit 0147c41

Please sign in to comment.