-
Notifications
You must be signed in to change notification settings - Fork 84
Fixes for the layer legend #4484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uclaros
wants to merge
7
commits into
master
Choose a base branch
from
fix-legend-size
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+219
−204
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
55b5330
Change static mmstyle members actually static
uclaros 0dfc36a
Properly scale legend, adjust margins and fix color
uclaros c5c97a3
Merge branch 'master' into fix-legend-size
uclaros 366dc6c
Fix legend scaling logic to work on both X11 and Android
uclaros d84ee2d
Merge branch 'master' into fix-legend-size
uclaros 306177c
Merge branch 'master' into fix-legend-size
uclaros 44186d8
properly resolve conflict
uclaros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,31 +47,36 @@ QImage LayerDetailLegendImageProvider::requestImage( const QString &, QSize *siz | |
| // it by dpr. | ||
|
|
||
| QScreen *screen = QGuiApplication::screens().at( 0 ); | ||
| qreal pdpi = screen->physicalDotsPerInch() * screen->devicePixelRatio(); | ||
| qreal dpm = pdpi / 25.4; | ||
| const qreal ldpi = screen->logicalDotsPerInch(); | ||
| const qreal dpr = screen->devicePixelRatio(); | ||
|
|
||
| QSize desiredSize( requestedSize ); | ||
| if ( desiredSize.isEmpty() ) | ||
| { | ||
| // fallback size | ||
| desiredSize = QSize( 60, 60 ); | ||
| } | ||
| const qreal dpmm = ldpi * dpr / 25.4; | ||
|
|
||
| // 60 is fallback size, not sure how it came to be | ||
| const int width = requestedSize.isEmpty() ? static_cast<int>( 60 * dpr ) : static_cast<int>( requestedSize.width() * dpr ); | ||
| const int height = static_cast<int>( minimumSize.height() * dpmm ); | ||
|
|
||
| QImage legend = QImage( desiredSize.width(), minimumSize.height() * dpm, QImage::Format_ARGB32_Premultiplied ); | ||
| QImage legend = QImage( width, height, QImage::Format_ARGB32_Premultiplied ); | ||
|
|
||
| QPainter painter( &legend ); | ||
| painter.setRenderHint( QPainter::Antialiasing ); | ||
| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of curiosity what's the reason for having this part of the code wrapped in extra curly braces? |
||
| QPainter painter( &legend ); | ||
| painter.setRenderHint( QPainter::Antialiasing ); | ||
|
|
||
| QgsRenderContext context = QgsRenderContext::fromQPainter( &painter ); | ||
|
|
||
| QgsRenderContext context = QgsRenderContext::fromQPainter( &painter ); | ||
| painter.scale( dpmm, dpmm ); | ||
|
|
||
| painter.scale( dpm, dpm ); | ||
| legend.fill( Qt::transparent ); | ||
|
|
||
| legend.fill( Qt::transparent ); | ||
| renderer->drawLegend( context ); | ||
| } | ||
|
|
||
| renderer->drawLegend( context ); | ||
| // Tag with DPR only after painting so QPainter does not auto-scale the | ||
| // coordinate system by dpr (which would otherwise double-apply the factor). | ||
| legend.setDevicePixelRatio( dpr ); | ||
|
|
||
| size->setHeight( desiredSize.height() ); | ||
| size->setWidth( desiredSize.width() ); | ||
| size->setWidth( static_cast<int>( width / dpr ) ); | ||
| size->setHeight( static_cast<int>( height / dpr ) ); | ||
|
|
||
| return legend; | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
QgsLegendStyle::Styleenum doesn't exist anymore in QGIS 3.44 -> QGIS PR