Skip to content
Permalink
Browse files

[ui] properly size symbols for the layout legend item widget's list

  • Loading branch information
nirvn committed Jun 15, 2018
1 parent 66ad9d9 commit e6bd0bc4ef905ec5df94983d02f6178e15eec823
Showing with 24 additions and 1 deletion.
  1. +22 −1 src/app/layout/qgslayoutlegendwidget.cpp
  2. +2 −0 src/app/layout/qgslayoutlegendwidget.h
@@ -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 )
{
@@ -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
@@ -627,6 +631,8 @@ void QgsLayoutLegendWidget::composerMapChanged( QgsLayoutItem *item )
mLegend->setLinkedMap( map );
mLegend->updateFilterByMap();
mLegend->endCommand();

setLegendMapViewData();
}
}

@@ -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() )
@@ -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();

0 comments on commit e6bd0bc

Please sign in to comment.
You can’t perform that action at this time.