Skip to content

Commit

Permalink
[ui] properly size symbols for the layout legend item widget's list
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jun 16, 2018
1 parent 66ad9d9 commit e6bd0bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/app/layout/qgslayoutlegendwidget.cpp
Expand Up @@ -34,12 +34,15 @@
#include "qgsmaplayerlegend.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgslayoutitemlegend.h"
#include "qgslayoutatlas.h"
#include "qgslayoutitemlegend.h"
#include "qgslayoutmeasurementconverter.h"
#include "qgsunittypes.h"

#include <QMessageBox>
#include <QInputDialog>

Q_GUI_EXPORT extern int qt_defaultDpiX();

static int _unfilteredLegendNodeIndex( QgsLayerTreeModelLegendNode *legendNode )
{
Expand Down Expand Up @@ -135,6 +138,7 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend )

mItemTreeView->setModel( legend->model() );
mItemTreeView->setMenuProvider( new QgsLayoutLegendMenuProvider( mItemTreeView, this ) );
setLegendMapViewData();
connect( legend, &QgsLayoutObject::changed, this, &QgsLayoutLegendWidget::setGuiElements );

// connect atlas state to the filter legend by atlas checkbox
Expand Down Expand Up @@ -627,6 +631,8 @@ void QgsLayoutLegendWidget::composerMapChanged( QgsLayoutItem *item )
mLegend->setLinkedMap( map );
mLegend->updateFilterByMap();
mLegend->endCommand();

setLegendMapViewData();
}
}

Expand Down Expand Up @@ -1035,6 +1041,21 @@ void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()
mLegend->updateFilterByMap();
}

void QgsLayoutLegendWidget::setLegendMapViewData()
{
if ( mLegend->linkedMap() )
{
int dpi = qt_defaultDpiX();
QgsLayoutMeasurementConverter measurementConverter = QgsLayoutMeasurementConverter();
measurementConverter.setDpi( dpi );
double mapWidth = measurementConverter.convert( mLegend->linkedMap()->sizeWithUnits(), QgsUnitTypes::LayoutPixels ).width();
double mapHeight = measurementConverter.convert( mLegend->linkedMap()->sizeWithUnits(), QgsUnitTypes::LayoutPixels ).height();
double mapUnitsPerPixelX = mLegend->linkedMap()->extent().width() / mapWidth;
double mapUnitsPerPixelY = mLegend->linkedMap()->extent().height() / mapHeight;
mLegend->model()->setLegendMapViewData( ( mapUnitsPerPixelX > mapUnitsPerPixelY ? mapUnitsPerPixelX : mapUnitsPerPixelY ), dpi, mLegend->linkedMap()->scale() );
}
}

void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton()
{
if ( QgsLayoutAtlas *atlas = layoutAtlas() )
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout/qgslayoutlegendwidget.h
Expand Up @@ -93,6 +93,8 @@ class QgsLayoutLegendWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayo

void setCurrentNodeStyleFromAction();

void setLegendMapViewData();

private slots:
//! Sets GUI according to state of mLegend
void setGuiElements();
Expand Down

0 comments on commit e6bd0bc

Please sign in to comment.