Skip to content
Permalink
Browse files

It's FAR too expensive to construct a QgsSettings object for every sy…

…mbol node, especially for complex

projects. So only read the valid size ranges once, and store them for subsequent use

(cherry picked from commit da51a5a)
  • Loading branch information
nyalldawson committed Dec 21, 2020
1 parent 622ca71 commit c40c55cde26d2712fb37e90c0c7cb45a5f9eb5ec
@@ -257,6 +257,9 @@ and allowing interaction with the symbol / renderer.
%End
public:

static double MINIMUM_SIZE;
static double MAXIMUM_SIZE;

QgsSymbolLegendNode( QgsLayerTreeLayer *nodeLayer, const QgsLegendSymbolItem &item, QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsSymbolLegendNode.
@@ -38,6 +38,7 @@
#include "qgsexpressioncontextutils.h"
#include "qgslocaldefaultsettings.h"
#include "qgsnumericformatwidget.h"
#include "qgslayertreemodellegendnode.h"

#include "qgsattributetablefiltermodel.h"
#include "qgslocalizeddatapathregistry.h"
@@ -1570,6 +1571,8 @@ void QgsOptions::saveOptions()

mSettings->setValue( QStringLiteral( "/qgis/legendsymbolMinimumSize" ), mLegendSymbolMinimumSizeSpinBox->value() );
mSettings->setValue( QStringLiteral( "/qgis/legendsymbolMaximumSize" ), mLegendSymbolMaximumSizeSpinBox->value() );
QgsSymbolLegendNode::MINIMUM_SIZE = mLegendSymbolMinimumSizeSpinBox->value();
QgsSymbolLegendNode::MAXIMUM_SIZE = mLegendSymbolMaximumSizeSpinBox->value();

mSettings->setValue( QStringLiteral( "/qgis/defaultLegendGraphicResolution" ), mLegendGraphicResolutionSpinBox->value() );
mSettings->setValue( QStringLiteral( "/qgis/mapTipsDelay" ), mMapTipsDelaySpinBox->value() );
@@ -242,6 +242,9 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &set

// -------------------------------------------------------------------------

double QgsSymbolLegendNode::MINIMUM_SIZE = -1.0;
double QgsSymbolLegendNode::MAXIMUM_SIZE = -1.0;

QgsSymbolLegendNode::QgsSymbolLegendNode( QgsLayerTreeLayer *nodeLayer, const QgsLegendSymbolItem &item, QObject *parent )
: QgsLayerTreeModelLegendNode( nodeLayer, parent )
, mItem( item )
@@ -250,9 +253,14 @@ QgsSymbolLegendNode::QgsSymbolLegendNode( QgsLayerTreeLayer *nodeLayer, const Qg
const int iconSize = QgsLayerTreeModel::scaleIconSize( 16 );
mIconSize = QSize( iconSize, iconSize );

QgsSettings settings;
mSymbolMinimumSize = settings.value( "/qgis/legendsymbolMinimumSize", 0.5 ).toDouble();
mSymbolMaximumSize = settings.value( "/qgis/legendsymbolMaximumSize", 20.0 ).toDouble();
if ( MINIMUM_SIZE < 0 )
{
// it's FAR too expensive to construct a QgsSettings object for every symbol node, especially for complex
// projects. So only read the valid size ranges once, and store them for subsequent use
QgsSettings settings;
MINIMUM_SIZE = settings.value( "/qgis/legendsymbolMinimumSize", 0.5 ).toDouble();
MAXIMUM_SIZE = settings.value( "/qgis/legendsymbolMaximumSize", 20.0 ).toDouble();
}

updateLabel();
connect( qobject_cast<QgsVectorLayer *>( nodeLayer->layer() ), &QgsVectorLayer::symbolFeatureCountMapChanged, this, &QgsSymbolLegendNode::updateLabel );
@@ -287,7 +295,7 @@ QSize QgsSymbolLegendNode::minimumIconSize( QgsRenderContext *context ) const
// unusued width, height variables
double width = 0.0;
double height = 0.0;
std::unique_ptr<QgsSymbol> symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), mSymbolMinimumSize, mSymbolMaximumSize, context, width, height ) );
std::unique_ptr<QgsSymbol> symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), MINIMUM_SIZE, MAXIMUM_SIZE, context, width, height ) );
minSz = QgsImageOperation::nonTransparentImageRect(
QgsSymbolLayerUtils::symbolPreviewPixmap( symbol ? symbol.get() : mItem.symbol(), QSize( largeIconSize, largeIconSize ), 0,
context ).toImage(),
@@ -298,7 +306,7 @@ QSize QgsSymbolLegendNode::minimumIconSize( QgsRenderContext *context ) const
{
double width = 0.0;
double height = 0.0;
std::unique_ptr<QgsSymbol> symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), mSymbolMinimumSize, mSymbolMaximumSize, context, width, height ) );
std::unique_ptr<QgsSymbol> symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), MINIMUM_SIZE, MAXIMUM_SIZE, context, width, height ) );
minSz = QgsImageOperation::nonTransparentImageRect(
QgsSymbolLayerUtils::symbolPreviewPixmap( symbol ? symbol.get() : mItem.symbol(), QSize( minSz.width(), largeIconSize ), 0,
context ).toImage(),
@@ -468,7 +476,7 @@ QVariant QgsSymbolLegendNode::data( int role ) const
// unusued width, height variables
double width = 0.0;
double height = 0.0;
std::unique_ptr<QgsSymbol> symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), mSymbolMinimumSize, mSymbolMaximumSize, context.get(), width, height ) );
std::unique_ptr<QgsSymbol> symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), MINIMUM_SIZE, MAXIMUM_SIZE, context.get(), width, height ) );
pix = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol ? symbol.get() : mItem.symbol(), mIconSize, 0, context.get() );

if ( !mTextOnSymbolLabel.isEmpty() && context )
@@ -1307,3 +1315,4 @@ void QgsDataDefinedSizeLegendNode::cacheImage() const
mImage = mSettings->collapsedLegendImage( *context );
}
}

@@ -307,9 +307,11 @@ class CORE_EXPORT QgsSymbolLegendNode : public QgsLayerTreeModelLegendNode
{
Q_OBJECT


public:

static double MINIMUM_SIZE;
static double MAXIMUM_SIZE;

/**
* Constructor for QgsSymbolLegendNode.
* \param nodeLayer layer node
@@ -489,8 +491,6 @@ class CORE_EXPORT QgsSymbolLegendNode : public QgsLayerTreeModelLegendNode
bool mSymbolUsesMapUnits;

QSize mIconSize;
double mSymbolMinimumSize = 0.5;
double mSymbolMaximumSize = 20.0;

QString mTextOnSymbolLabel;
QgsTextFormat mTextOnSymbolTextFormat;

0 comments on commit c40c55c

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