Skip to content

Commit a487149

Browse files
committedFeb 15, 2021
Add symbol button to allow users to customise the line symbol used
in collapsed data defined size legends While it was possible to set the symbol style via api, there was no UI to allow users to set this themselves, which meant that you were stuck with the default black solid line symbol (which could be totally unreadable on dark backgrounds...)
1 parent 7de6dd1 commit a487149

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed
 

‎src/core/qgsdatadefinedsizelegend.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
300300

301301
if ( mLineSymbol )
302302
{
303-
mLineSymbol->setColor( mTextColor );
304303
mLineSymbol->startRender( context );
305304
}
306305

@@ -375,10 +374,10 @@ QgsDataDefinedSizeLegend *QgsDataDefinedSizeLegend::readXml( const QDomElement &
375374
ddsLegend->setSymbol( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( elemSymbol, context ) );
376375
}
377376

378-
QDomElement lineSymbol = elem.firstChildElement( QStringLiteral( "lineSymbol" ) );
379-
if ( !lineSymbol.isNull() )
377+
const QDomElement lineSymbolElem = elem.firstChildElement( QStringLiteral( "lineSymbol" ) );
378+
if ( !lineSymbolElem.isNull() )
380379
{
381-
ddsLegend->setLineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( lineSymbol, context ) );
380+
ddsLegend->setLineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( lineSymbolElem.firstChildElement(), context ) );
382381
}
383382

384383
QgsSizeScaleTransformer *transformer = nullptr;
@@ -435,8 +434,9 @@ void QgsDataDefinedSizeLegend::writeXml( QDomElement &elem, const QgsReadWriteCo
435434

436435
if ( mLineSymbol )
437436
{
438-
QDomElement elemSymbol = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "lineSymbol" ), mLineSymbol.get(), doc, context );
439-
elem.appendChild( elemSymbol );
437+
QDomElement lineSymbolElem = doc.createElement( QStringLiteral( "lineSymbol" ) );
438+
lineSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "lineSymbol" ), mLineSymbol.get(), doc, context ) );
439+
elem.appendChild( lineSymbolElem );
440440
}
441441

442442
if ( mSizeScaleTransformer )

‎src/gui/symbology/qgsdatadefinedsizelegendwidget.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ QgsDataDefinedSizeLegendWidget::QgsDataDefinedSizeLegendWidget( const QgsDataDef
3939
setupUi( this );
4040
setPanelTitle( tr( "Data-defined Size Legend" ) );
4141

42+
mLineSymbolButton->setSymbolType( QgsSymbol::Line );
43+
4244
QgsMarkerSymbol *symbol = nullptr;
4345

4446
if ( !ddsLegend )
@@ -57,6 +59,9 @@ QgsDataDefinedSizeLegendWidget::QgsDataDefinedSizeLegendWidget( const QgsDataDef
5759
else
5860
cboAlignSymbols->setCurrentIndex( 1 );
5961

62+
if ( ddsLegend->lineSymbol() )
63+
mLineSymbolButton->setSymbol( ddsLegend->lineSymbol()->clone() );
64+
6065
symbol = ddsLegend->symbol() ? ddsLegend->symbol()->clone() : nullptr; // may be null (undefined)
6166
}
6267

@@ -120,6 +125,7 @@ QgsDataDefinedSizeLegendWidget::QgsDataDefinedSizeLegendWidget( const QgsDataDef
120125
connect( groupManualSizeClasses, &QGroupBox::clicked, this, &QgsPanelWidget::widgetChanged );
121126
connect( btnChangeSymbol, &QPushButton::clicked, this, &QgsDataDefinedSizeLegendWidget::changeSymbol );
122127
connect( editTitle, &QLineEdit::textChanged, this, &QgsPanelWidget::widgetChanged );
128+
connect( mLineSymbolButton, &QgsSymbolButton::changed, this, &QgsPanelWidget::widgetChanged );
123129
connect( this, &QgsPanelWidget::widgetChanged, this, &QgsDataDefinedSizeLegendWidget::updatePreview );
124130
updatePreview();
125131
}
@@ -157,6 +163,8 @@ QgsDataDefinedSizeLegend *QgsDataDefinedSizeLegendWidget::dataDefinedSizeLegend(
157163
}
158164
ddsLegend->setClasses( classes );
159165
}
166+
167+
ddsLegend->setLineSymbol( mLineSymbolButton->clonedSymbol< QgsLineSymbol >() );
160168
return ddsLegend;
161169
}
162170

‎src/ui/qgsdatadefinedsizelegendwidget.ui

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,8 @@
133133
<property name="title">
134134
<string>Options (collapsed only)</string>
135135
</property>
136-
<layout class="QHBoxLayout" name="horizontalLayout">
137-
<item>
138-
<widget class="QLabel" name="label">
139-
<property name="text">
140-
<string>Align symbols</string>
141-
</property>
142-
</widget>
143-
</item>
144-
<item>
136+
<layout class="QGridLayout" name="gridLayout">
137+
<item row="0" column="1">
145138
<widget class="QComboBox" name="cboAlignSymbols">
146139
<item>
147140
<property name="text">
@@ -155,6 +148,33 @@
155148
</item>
156149
</widget>
157150
</item>
151+
<item row="0" column="0">
152+
<widget class="QLabel" name="label">
153+
<property name="text">
154+
<string>Align symbols</string>
155+
</property>
156+
</widget>
157+
</item>
158+
<item row="1" column="1">
159+
<widget class="QgsSymbolButton" name="mLineSymbolButton">
160+
<property name="sizePolicy">
161+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
162+
<horstretch>0</horstretch>
163+
<verstretch>0</verstretch>
164+
</sizepolicy>
165+
</property>
166+
<property name="text">
167+
<string>Change…</string>
168+
</property>
169+
</widget>
170+
</item>
171+
<item row="1" column="0">
172+
<widget class="QLabel" name="label_3">
173+
<property name="text">
174+
<string>Line symbol</string>
175+
</property>
176+
</widget>
177+
</item>
158178
</layout>
159179
</widget>
160180
</item>
@@ -175,6 +195,13 @@
175195
</item>
176196
</layout>
177197
</widget>
198+
<customwidgets>
199+
<customwidget>
200+
<class>QgsSymbolButton</class>
201+
<extends>QToolButton</extends>
202+
<header>qgssymbolbutton.h</header>
203+
</customwidget>
204+
</customwidgets>
178205
<tabstops>
179206
<tabstop>radDisabled</tabstop>
180207
<tabstop>radSeparated</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.