diff --git a/python/core/auto_generated/layertree/qgslayertreemodellegendnode.sip.in b/python/core/auto_generated/layertree/qgslayertreemodellegendnode.sip.in index 416ca3b0fbd9..65278d362437 100644 --- a/python/core/auto_generated/layertree/qgslayertreemodellegendnode.sip.in +++ b/python/core/auto_generated/layertree/qgslayertreemodellegendnode.sip.in @@ -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. diff --git a/src/app/options/qgsoptions.cpp b/src/app/options/qgsoptions.cpp index bacdc2977fc8..b48fb7e61d48 100644 --- a/src/app/options/qgsoptions.cpp +++ b/src/app/options/qgsoptions.cpp @@ -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() ); diff --git a/src/core/layertree/qgslayertreemodellegendnode.cpp b/src/core/layertree/qgslayertreemodellegendnode.cpp index 0f4cdb8ca4f6..7cff8eb1eb2a 100644 --- a/src/core/layertree/qgslayertreemodellegendnode.cpp +++ b/src/core/layertree/qgslayertreemodellegendnode.cpp @@ -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( 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 symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), mSymbolMinimumSize, mSymbolMaximumSize, context, width, height ) ); + std::unique_ptr 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 symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), mSymbolMinimumSize, mSymbolMaximumSize, context, width, height ) ); + std::unique_ptr 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 symbol( QgsSymbolLayerUtils::restrictedSizeSymbol( mItem.symbol(), mSymbolMinimumSize, mSymbolMaximumSize, context.get(), width, height ) ); + std::unique_ptr 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 ); } } + diff --git a/src/core/layertree/qgslayertreemodellegendnode.h b/src/core/layertree/qgslayertreemodellegendnode.h index 0639430f6730..4dd01088435b 100644 --- a/src/core/layertree/qgslayertreemodellegendnode.h +++ b/src/core/layertree/qgslayertreemodellegendnode.h @@ -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;