mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Partially fix sizes of layer tree icons on hidpi displays
This commit is contained in:
parent
b86bb1e2ef
commit
f0179e2f8a
@ -1522,6 +1522,12 @@ QgsRenderContext *QgsLayerTreeModel::createTemporaryRenderContext() const
|
|||||||
// setup temporary render context
|
// setup temporary render context
|
||||||
std::unique_ptr<QgsRenderContext> context( new QgsRenderContext );
|
std::unique_ptr<QgsRenderContext> context( new QgsRenderContext );
|
||||||
context->setScaleFactor( dpi / 25.4 );
|
context->setScaleFactor( dpi / 25.4 );
|
||||||
|
|
||||||
|
if ( !mTargetScreenProperties.isEmpty() )
|
||||||
|
{
|
||||||
|
mTargetScreenProperties.begin()->updateRenderContextForScreen( *context );
|
||||||
|
}
|
||||||
|
|
||||||
context->setRendererScale( scale );
|
context->setRendererScale( scale );
|
||||||
context->setMapToPixel( QgsMapToPixel( mupp ) );
|
context->setMapToPixel( QgsMapToPixel( mupp ) );
|
||||||
context->setFlag( Qgis::RenderContextFlag::RenderSymbolPreview );
|
context->setFlag( Qgis::RenderContextFlag::RenderSymbolPreview );
|
||||||
|
@ -390,11 +390,14 @@ QSize QgsSymbolLegendNode::minimumIconSize( QgsRenderContext *context ) const
|
|||||||
const QSize size( mItem.symbol()->type() == Qgis::SymbolType::Marker ? maxSize : minSz.width(),
|
const QSize size( mItem.symbol()->type() == Qgis::SymbolType::Marker ? maxSize : minSz.width(),
|
||||||
maxSize );
|
maxSize );
|
||||||
|
|
||||||
|
QgsScreenProperties targetScreen = model() && !model()->targetScreenProperties().isEmpty()
|
||||||
|
? *model()->targetScreenProperties().begin() : QgsScreenProperties();
|
||||||
|
|
||||||
minSz = QgsImageOperation::nonTransparentImageRect(
|
minSz = QgsImageOperation::nonTransparentImageRect(
|
||||||
QgsSymbolLayerUtils::symbolPreviewPixmap( symbol ? symbol.get() : mItem.symbol(), size, 0,
|
QgsSymbolLayerUtils::symbolPreviewPixmap( symbol ? symbol.get() : mItem.symbol(), size, 0,
|
||||||
context ).toImage(),
|
context, false, nullptr, nullptr, targetScreen ).toImage(),
|
||||||
minSz,
|
minSz,
|
||||||
true ).size();
|
true ).size() / targetScreen.devicePixelRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !mTextOnSymbolLabel.isEmpty() && context )
|
if ( !mTextOnSymbolLabel.isEmpty() && context )
|
||||||
@ -493,6 +496,11 @@ QgsRenderContext *QgsLayerTreeModelLegendNode::createTemporaryRenderContext() co
|
|||||||
context->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
|
context->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
|
||||||
context->setFlag( Qgis::RenderContextFlag::RenderSymbolPreview, true );
|
context->setFlag( Qgis::RenderContextFlag::RenderSymbolPreview, true );
|
||||||
|
|
||||||
|
if ( model() && !model()->targetScreenProperties().isEmpty() )
|
||||||
|
{
|
||||||
|
model()->targetScreenProperties().begin()->updateRenderContextForScreen( *context );
|
||||||
|
}
|
||||||
|
|
||||||
QgsExpressionContext expContext;
|
QgsExpressionContext expContext;
|
||||||
expContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayerNode ? mLayerNode->layer() : nullptr ) );
|
expContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayerNode ? mLayerNode->layer() : nullptr ) );
|
||||||
context->setExpressionContext( expContext );
|
context->setExpressionContext( expContext );
|
||||||
@ -548,6 +556,9 @@ QVariant QgsSymbolLegendNode::data( int role ) const
|
|||||||
{
|
{
|
||||||
if ( mPixmap.isNull() )
|
if ( mPixmap.isNull() )
|
||||||
{
|
{
|
||||||
|
QgsScreenProperties targetScreen = model() && !model()->targetScreenProperties().isEmpty()
|
||||||
|
? *model()->targetScreenProperties().begin() : QgsScreenProperties();
|
||||||
|
|
||||||
if ( mItem.symbol() )
|
if ( mItem.symbol() )
|
||||||
{
|
{
|
||||||
std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
|
std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
|
||||||
@ -556,7 +567,7 @@ QVariant QgsSymbolLegendNode::data( int role ) const
|
|||||||
double width = 0.0;
|
double width = 0.0;
|
||||||
double height = 0.0;
|
double height = 0.0;
|
||||||
const std::unique_ptr<QgsSymbol> symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), MINIMUM_SIZE, MAXIMUM_SIZE, context.get(), width, height ) );
|
const std::unique_ptr<QgsSymbol> symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), MINIMUM_SIZE, MAXIMUM_SIZE, context.get(), width, height ) );
|
||||||
mPixmap = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol ? symbol.get() : mItem.symbol(), mIconSize, 0, context.get() );
|
mPixmap = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol ? symbol.get() : mItem.symbol(), mIconSize, 0, context.get(), false, nullptr, nullptr, targetScreen );
|
||||||
|
|
||||||
if ( !mTextOnSymbolLabel.isEmpty() && context )
|
if ( !mTextOnSymbolLabel.isEmpty() && context )
|
||||||
{
|
{
|
||||||
@ -575,7 +586,7 @@ QVariant QgsSymbolLegendNode::data( int role ) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mPixmap = QPixmap( mIconSize );
|
mPixmap = QPixmap( mIconSize * targetScreen.devicePixelRatio() );
|
||||||
mPixmap.fill( Qt::transparent );
|
mPixmap.fill( Qt::transparent );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user