Skip to content

Commit e6bd0bc

Browse files
committedJun 16, 2018
[ui] properly size symbols for the layout legend item widget's list
1 parent 66ad9d9 commit e6bd0bc

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎src/app/layout/qgslayoutlegendwidget.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@
3434
#include "qgsmaplayerlegend.h"
3535
#include "qgsproject.h"
3636
#include "qgsvectorlayer.h"
37-
#include "qgslayoutitemlegend.h"
3837
#include "qgslayoutatlas.h"
38+
#include "qgslayoutitemlegend.h"
39+
#include "qgslayoutmeasurementconverter.h"
40+
#include "qgsunittypes.h"
3941

4042
#include <QMessageBox>
4143
#include <QInputDialog>
4244

45+
Q_GUI_EXPORT extern int qt_defaultDpiX();
4346

4447
static int _unfilteredLegendNodeIndex( QgsLayerTreeModelLegendNode *legendNode )
4548
{
@@ -135,6 +138,7 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend )
135138

136139
mItemTreeView->setModel( legend->model() );
137140
mItemTreeView->setMenuProvider( new QgsLayoutLegendMenuProvider( mItemTreeView, this ) );
141+
setLegendMapViewData();
138142
connect( legend, &QgsLayoutObject::changed, this, &QgsLayoutLegendWidget::setGuiElements );
139143

140144
// connect atlas state to the filter legend by atlas checkbox
@@ -627,6 +631,8 @@ void QgsLayoutLegendWidget::composerMapChanged( QgsLayoutItem *item )
627631
mLegend->setLinkedMap( map );
628632
mLegend->updateFilterByMap();
629633
mLegend->endCommand();
634+
635+
setLegendMapViewData();
630636
}
631637
}
632638

@@ -1035,6 +1041,21 @@ void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()
10351041
mLegend->updateFilterByMap();
10361042
}
10371043

1044+
void QgsLayoutLegendWidget::setLegendMapViewData()
1045+
{
1046+
if ( mLegend->linkedMap() )
1047+
{
1048+
int dpi = qt_defaultDpiX();
1049+
QgsLayoutMeasurementConverter measurementConverter = QgsLayoutMeasurementConverter();
1050+
measurementConverter.setDpi( dpi );
1051+
double mapWidth = measurementConverter.convert( mLegend->linkedMap()->sizeWithUnits(), QgsUnitTypes::LayoutPixels ).width();
1052+
double mapHeight = measurementConverter.convert( mLegend->linkedMap()->sizeWithUnits(), QgsUnitTypes::LayoutPixels ).height();
1053+
double mapUnitsPerPixelX = mLegend->linkedMap()->extent().width() / mapWidth;
1054+
double mapUnitsPerPixelY = mLegend->linkedMap()->extent().height() / mapHeight;
1055+
mLegend->model()->setLegendMapViewData( ( mapUnitsPerPixelX > mapUnitsPerPixelY ? mapUnitsPerPixelX : mapUnitsPerPixelY ), dpi, mLegend->linkedMap()->scale() );
1056+
}
1057+
}
1058+
10381059
void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton()
10391060
{
10401061
if ( QgsLayoutAtlas *atlas = layoutAtlas() )

‎src/app/layout/qgslayoutlegendwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class QgsLayoutLegendWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayo
9393

9494
void setCurrentNodeStyleFromAction();
9595

96+
void setLegendMapViewData();
97+
9698
private slots:
9799
//! Sets GUI according to state of mLegend
98100
void setGuiElements();

0 commit comments

Comments
 (0)
Please sign in to comment.