Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Feature: possibility to use placeholder icon in legend for raster layer
  • Loading branch information
mhugent committed Jul 2, 2021
1 parent c8156b0 commit 991f935
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 25 deletions.
12 changes: 12 additions & 0 deletions python/core/auto_generated/raster/qgsrasterlayer.sip.in
Expand Up @@ -420,6 +420,18 @@ to be drawn outside the data extent.
virtual QgsMapLayerTemporalProperties *temporalProperties();


bool usePlaceholderLegendIcon() const;
%Docstring
True if a placeholder legend is shown in the legend rather than all the color entries
%End

void setUsePlaceholderLegendIcon( bool usePlaceholderIcon );
%Docstring
Set if a placeholder legend is shown in the legend

:param usePlaceholderIcon: true if placeholder icon will be shown instead of symbology items
%End

public slots:
void showStatusMessage( const QString &message );

Expand Down
8 changes: 6 additions & 2 deletions src/core/qgsmaplayerlegend.cpp
Expand Up @@ -14,7 +14,7 @@
***************************************************************************/

#include "qgsmaplayerlegend.h"

#include "qgsiconutils.h"
#include "qgssettings.h"
#include "qgslayertree.h"
#include "qgslayertreemodellegendnode.h"
Expand Down Expand Up @@ -502,7 +502,11 @@ QList<QgsLayerTreeModelLegendNode *> QgsDefaultRasterLayerLegend::createLayerTre
nodes << new QgsWmsLegendNode( nodeLayer );
}

if ( mLayer->renderer() )
if ( mLayer->usePlaceholderLegendIcon() )
{
nodes << new QgsSimpleLegendNode( nodeLayer, QString(), QgsIconUtils::iconRaster() );
}
else if ( mLayer->renderer() )
nodes.append( mLayer->renderer()->createLegendNodes( nodeLayer ) );
return nodes;
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -2163,6 +2163,8 @@ bool QgsRasterLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &c

readStyleManager( layer_node );

mUsePlaceholderLegendIcon = layer_node.toElement().attribute( QStringLiteral( "usePlaceholderLegendIcon" ), QStringLiteral( "0" ) ).compare( QStringLiteral( "1" ) ) == 0;

return res;
}

Expand Down Expand Up @@ -2278,6 +2280,8 @@ bool QgsRasterLayer::writeXml( QDomNode &layer_node,

writeStyleManager( layer_node, document );

mapLayerNode.setAttribute( QStringLiteral( "usePlaceholderLegendIcon" ), mUsePlaceholderLegendIcon );

//write out the symbology
QString errorMsg;
return writeSymbology( layer_node, document, errorMsg, context );
Expand Down
11 changes: 11 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -467,6 +467,15 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

QgsMapLayerTemporalProperties *temporalProperties() override;

//! True if a placeholder legend is shown in the legend rather than all the color entries
bool usePlaceholderLegendIcon() const { return mUsePlaceholderLegendIcon; }

/**
* Set if a placeholder legend is shown in the legend
* \param usePlaceholderIcon true if placeholder icon will be shown instead of symbology items
*/
void setUsePlaceholderLegendIcon( bool usePlaceholderIcon ) { mUsePlaceholderLegendIcon = usePlaceholderIcon; }

public slots:
void showStatusMessage( const QString &message );

Expand Down Expand Up @@ -565,6 +574,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

QDomDocument mOriginalStyleDocument;
QDomElement mOriginalStyleElement;

bool mUsePlaceholderLegendIcon = false;
};

// clazy:excludeall=qstring-allocations
Expand Down
2 changes: 2 additions & 0 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -914,6 +914,7 @@ void QgsRasterLayerProperties::sync()
QVariant wmsBackgroundLayer = mRasterLayer->customProperty( QStringLiteral( "WMSBackgroundLayer" ), false );
mBackgroundLayerCheckBox->setChecked( wmsBackgroundLayer.toBool() );

mPlaceholderIconCheckBox->setCheckState( mRasterLayer->usePlaceholderLegendIcon() ? Qt::Checked : Qt::Unchecked );
mLegendConfigEmbeddedWidget->setLayer( mRasterLayer );

mTemporalWidget->syncToLayer();
Expand Down Expand Up @@ -946,6 +947,7 @@ void QgsRasterLayerProperties::apply()
/*
* Legend Tab
*/
mRasterLayer->setUsePlaceholderLegendIcon( mPlaceholderIconCheckBox->isChecked() );
mLegendConfigEmbeddedWidget->applyToLayer();

QgsDebugMsgLevel( QStringLiteral( "apply processing symbology tab" ), 3 );
Expand Down
41 changes: 18 additions & 23 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Expand Up @@ -254,7 +254,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="mOptsPage_Information">
<layout class="QVBoxLayout" name="verticalLayout_20">
Expand Down Expand Up @@ -299,8 +299,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>643</width>
<height>679</height>
<width>650</width>
<height>673</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -1563,8 +1563,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>577</width>
<height>190</height>
<width>650</width>
<height>673</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1633,8 +1633,8 @@ border-radius: 2px;</string>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Fira Sans'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell';&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:12pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1739,20 +1739,15 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
<widget class="QWidget" name="mOptsPage_Legend">
<layout class="QVBoxLayout" name="verticalLayout_18">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_15">
<item row="0" column="0">
<widget class="QCheckBox" name="mPlaceholderIconCheckBox">
<property name="text">
<string>Show placeholder icon in legend</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Embedded Widgets in Legend</string>
Expand Down Expand Up @@ -1793,8 +1788,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>343</width>
<height>684</height>
<width>394</width>
<height>793</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_12">
Expand Down

0 comments on commit 991f935

Please sign in to comment.