Skip to content

Commit d7eec44

Browse files
committed
[FEATURE] Add checkbox to always show diagrams for a layer
Unlike the global labeling setting this applies only to diagrams, and only for a single layer. Defaults to on. (fix #8706)
1 parent 60526f4 commit d7eec44

6 files changed

+33
-14
lines changed

python/core/qgsdiagramrendererv2.sip

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct QgsDiagramLayerSettings
3636
QgsDiagramRendererV2* renderer; // if any renderer is assigned, it is owned by this class
3737
int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined)
3838
int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined)
39+
bool showAll;
3940

4041
void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
4142
void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;

src/app/qgsdiagramproperties.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
160160
mDiagramSizeSpinBox->setValue( 30 );
161161
mBarWidthSpinBox->setValue( 5 );
162162
mVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
163+
mShowAllCheckBox->setChecked( true );
163164
mMaximumDiagramScaleLineEdit->setText( QString::number( layer->maximumScale() ) );
164165
mMinimumDiagramScaleLineEdit->setText( QString::number( layer->minimumScale() ) );
165166

@@ -308,6 +309,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
308309
}
309310
mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( dls->placement ) );
310311
mLineOptionsComboBox->setCurrentIndex( mLineOptionsComboBox->findData( dls->placementFlags ) );
312+
mShowAllCheckBox->setChecked( dls->showAll );
311313
}
312314

313315
if ( dr->diagram() )
@@ -675,6 +677,7 @@ void QgsDiagramProperties::apply()
675677
QgsDiagramLayerSettings dls;
676678
dls.dist = mDiagramDistanceSpinBox->value();
677679
dls.priority = mPrioritySlider->value();
680+
dls.showAll = mShowAllCheckBox->isChecked();
678681
if ( mDataDefinedPositionGroupBox->isChecked() )
679682
{
680683
dls.xPosColumn = mDataDefinedXComboBox->itemData( mDataDefinedXComboBox->currentIndex() ).toInt();

src/core/qgsdiagramrendererv2.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ QgsDiagramLayerSettings::QgsDiagramLayerSettings()
3434
, xform( 0 )
3535
, xPosColumn( -1 )
3636
, yPosColumn( -1 )
37+
, showAll( true )
3738
{
3839
}
3940

@@ -53,6 +54,7 @@ void QgsDiagramLayerSettings::readXML( const QDomElement& elem, const QgsVectorL
5354
dist = elem.attribute( "dist" ).toDouble();
5455
xPosColumn = elem.attribute( "xPosColumn" ).toInt();
5556
yPosColumn = elem.attribute( "yPosColumn" ).toInt();
57+
showAll = ( elem.attribute( "showAll", "0" ) != "0" );
5658
}
5759

5860
void QgsDiagramLayerSettings::writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const
@@ -67,6 +69,7 @@ void QgsDiagramLayerSettings::writeXML( QDomElement& layerElem, QDomDocument& do
6769
diagramLayerElem.setAttribute( "dist", QString::number( dist ) );
6870
diagramLayerElem.setAttribute( "xPosColumn", xPosColumn );
6971
diagramLayerElem.setAttribute( "yPosColumn", yPosColumn );
72+
diagramLayerElem.setAttribute( "showAll", showAll );
7073
layerElem.appendChild( diagramLayerElem );
7174
}
7275

src/core/qgsdiagramrendererv2.h

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class CORE_EXPORT QgsDiagramLayerSettings
7979

8080
int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined)
8181
int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined)
82+
bool showAll;
8283

8384
void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
8485
void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;

src/core/qgspallabeling.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3476,6 +3476,7 @@ void QgsPalLabeling::registerDiagramFeature( const QString& layerID, QgsFeature&
34763476
}
34773477

34783478
// feature to the layer
3479+
bool alwaysShow = layerIt.value().showAll;
34793480
int ddColX = layerIt.value().xPosColumn;
34803481
int ddColY = layerIt.value().yPosColumn;
34813482
double ddPosX = 0.0;
@@ -3506,7 +3507,7 @@ void QgsPalLabeling::registerDiagramFeature( const QString& layerID, QgsFeature&
35063507

35073508
try
35083509
{
3509-
if ( !layerIt.value().palLayer->registerFeature( lbl->strId(), lbl, diagramWidth, diagramHeight, "", ddPosX, ddPosY, ddPos ) )
3510+
if ( !layerIt.value().palLayer->registerFeature( lbl->strId(), lbl, diagramWidth, diagramHeight, "", ddPosX, ddPosY, ddPos, 0.0, false, 0, 0, 0, 0, alwaysShow ) )
35103511
{
35113512
return;
35123513
}

src/ui/qgsdiagrampropertiesbase.ui

+23-13
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<rect>
4040
<x>0</x>
4141
<y>0</y>
42-
<width>756</width>
43-
<height>627</height>
42+
<width>740</width>
43+
<height>640</height>
4444
</rect>
4545
</property>
4646
<layout class="QVBoxLayout" name="scrollAreaLayout">
@@ -127,6 +127,19 @@
127127
<string>Appearance</string>
128128
</attribute>
129129
<layout class="QGridLayout" name="gridLayout_8">
130+
<item row="0" column="1">
131+
<spacer name="horizontalSpacer_6">
132+
<property name="orientation">
133+
<enum>Qt::Horizontal</enum>
134+
</property>
135+
<property name="sizeHint" stdset="0">
136+
<size>
137+
<width>0</width>
138+
<height>20</height>
139+
</size>
140+
</property>
141+
</spacer>
142+
</item>
130143
<item row="0" column="0" rowspan="2">
131144
<layout class="QGridLayout" name="gridLayout">
132145
<item row="4" column="2">
@@ -269,7 +282,7 @@
269282
</item>
270283
</layout>
271284
</item>
272-
<item row="2" column="0">
285+
<item row="3" column="0">
273286
<widget class="QGroupBox" name="mVisibilityGroupBox">
274287
<property name="toolTip">
275288
<string>Only show diagrams with a size inside the specified range.</string>
@@ -319,18 +332,15 @@
319332
</layout>
320333
</widget>
321334
</item>
322-
<item row="0" column="1">
323-
<spacer name="horizontalSpacer_6">
324-
<property name="orientation">
325-
<enum>Qt::Horizontal</enum>
335+
<item row="2" column="0">
336+
<widget class="QCheckBox" name="mShowAllCheckBox">
337+
<property name="text">
338+
<string>Show all diagrams</string>
326339
</property>
327-
<property name="sizeHint" stdset="0">
328-
<size>
329-
<width>0</width>
330-
<height>20</height>
331-
</size>
340+
<property name="checked">
341+
<bool>true</bool>
332342
</property>
333-
</spacer>
343+
</widget>
334344
</item>
335345
</layout>
336346
</widget>

0 commit comments

Comments
 (0)