Skip to content

Commit 429be1e

Browse files
committedMar 27, 2013
Add start angle offset for pie diagram
1 parent 0005467 commit 429be1e

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed
 

‎src/app/qgsdiagramproperties.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
4444

4545
setupUi( this );
4646

47-
4847
mBackgroundColorButton->setColorDialogTitle( tr( "Background color" ) );
4948
mBackgroundColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
5049
mDiagramPenColorButton->setColorDialogTitle( tr( "Pen color" ) );
@@ -112,6 +111,11 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
112111
mDataDefinedXComboBox->addItem( tr( "None" ), -1 );
113112
mDataDefinedYComboBox->addItem( tr( "None" ), -1 );
114113

114+
mAngleOffsetComboBox->addItem( tr( "Top" ), 90 * 16 );
115+
mAngleOffsetComboBox->addItem( tr( "Right" ), 0 );
116+
mAngleOffsetComboBox->addItem( tr( "Bottom" ), 270 * 16 );
117+
mAngleOffsetComboBox->addItem( tr( "Left" ), 180 * 16 );
118+
115119
//insert all attributes into the combo boxes
116120
const QgsFields& layerFields = layer->pendingFields();
117121
for ( int idx = 0; idx < layerFields.count(); ++idx )
@@ -198,6 +202,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
198202
mLabelPlacementComboBox->setCurrentIndex( 1 );
199203
}
200204

205+
mAngleOffsetComboBox->setCurrentIndex( mAngleOffsetComboBox->findData( settingList.at( 0 ).angleOffset ) );
206+
201207
mOrientationLeftButton->setProperty( "direction", QgsDiagramSettings::Left );
202208
mOrientationRightButton->setProperty( "direction", QgsDiagramSettings::Right );
203209
mOrientationUpButton->setProperty( "direction", QgsDiagramSettings::Up );
@@ -346,6 +352,17 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int inde
346352
mScaleDependencyComboBox->hide();
347353
mScaleDependencyLabel->hide();
348354
}
355+
356+
if ( DIAGRAM_NAME_PIE == diagramType )
357+
{
358+
mAngleOffsetComboBox->show();
359+
mAngleOffsetLabel->show();
360+
}
361+
else
362+
{
363+
mAngleOffsetComboBox->hide();
364+
mAngleOffsetLabel->hide();
365+
}
349366
}
350367
void QgsDiagramProperties::addAttribute( QTreeWidgetItem * item )
351368
{
@@ -521,6 +538,9 @@ void QgsDiagramProperties::apply()
521538
ds.maxScaleDenominator = -1;
522539
}
523540

541+
// Diagram angle offset (pie)
542+
ds.angleOffset = mAngleOffsetComboBox->itemData( mAngleOffsetComboBox->currentIndex() ).toInt();
543+
524544
// Diagram orientation (histogram)
525545
ds.diagramOrientation = static_cast<QgsDiagramSettings::DiagramOrientation>( mOrientationButtonGroup->checkedButton()->property( "direction" ).toInt() );
526546

‎src/core/diagram/qgspiediagram.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void QgsPieDiagram::renderDiagram( const QgsAttributes& att, QgsRenderContext& c
128128
QList< QColor >::const_iterator colIt = s.categoryColors.constBegin();
129129
for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
130130
{
131-
currentAngle = *valIt / valSum * 360 * 16;
131+
currentAngle = *valIt / valSum * 360 * 16;
132132
mCategoryBrush.setColor( *colIt );
133133
p->setBrush( mCategoryBrush );
134134
// if only 1 value is > 0, draw a circle
@@ -138,7 +138,7 @@ void QgsPieDiagram::renderDiagram( const QgsAttributes& att, QgsRenderContext& c
138138
}
139139
else
140140
{
141-
p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
141+
p->drawPie( baseX, baseY, w, h, totalAngle + s.angleOffset, currentAngle );
142142
}
143143
totalAngle += currentAngle;
144144
}

‎src/core/qgsdiagramrendererv2.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ void QgsDiagramSettings::readXML( const QDomElement& elem )
111111

112112
barWidth = elem.attribute( "barWidth" ).toDouble();
113113

114+
angleOffset = elem.attribute( "angleOffset" ).toInt();
115+
114116
minimumSize = elem.attribute( "minimumSize" ).toDouble();
115117

116118
//colors
@@ -204,6 +206,7 @@ void QgsDiagramSettings::writeXML( QDomElement& rendererElem, QDomDocument& doc
204206

205207
categoryElem.setAttribute( "barWidth", QString::number( barWidth ) );
206208
categoryElem.setAttribute( "minimumSize", QString::number( minimumSize ) );
209+
categoryElem.setAttribute( "angleOffset", QString::number( angleOffset ) );
207210

208211
QString colors;
209212
for ( int i = 0; i < categoryColors.size(); ++i )

‎src/core/qgsdiagramrendererv2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class CORE_EXPORT QgsDiagramSettings
128128
double barWidth;
129129
int transparency; // 0 - 100
130130
bool scaleByArea;
131+
int angleOffset;
131132

132133
//scale range (-1 if no lower / upper bound )
133134
double minScaleDenominator;

‎src/ui/qgsdiagrampropertiesbase.ui

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<rect>
4040
<x>0</x>
4141
<y>0</y>
42-
<width>752</width>
43-
<height>613</height>
42+
<width>756</width>
43+
<height>627</height>
4444
</rect>
4545
</property>
4646
<layout class="QVBoxLayout" name="scrollAreaLayout">
@@ -124,8 +124,8 @@
124124
<rect>
125125
<x>0</x>
126126
<y>0</y>
127-
<width>713</width>
128-
<height>364</height>
127+
<width>725</width>
128+
<height>397</height>
129129
</rect>
130130
</property>
131131
<attribute name="label">
@@ -134,6 +134,13 @@
134134
<layout class="QGridLayout" name="gridLayout_8">
135135
<item row="0" column="0" rowspan="2">
136136
<layout class="QGridLayout" name="gridLayout">
137+
<item row="4" column="2">
138+
<widget class="QgsColorButton" name="mDiagramPenColorButton">
139+
<property name="text">
140+
<string/>
141+
</property>
142+
</widget>
143+
</item>
137144
<item row="3" column="1">
138145
<widget class="QLabel" name="mBackgroundColorLabel">
139146
<property name="text">
@@ -155,7 +162,7 @@
155162
</property>
156163
</widget>
157164
</item>
158-
<item row="6" column="1">
165+
<item row="7" column="1">
159166
<widget class="QPushButton" name="mDiagramFontButton">
160167
<property name="sizePolicy">
161168
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -231,13 +238,16 @@
231238
</property>
232239
</widget>
233240
</item>
234-
<item row="4" column="2">
235-
<widget class="QgsColorButton" name="mDiagramPenColorButton">
241+
<item row="6" column="1">
242+
<widget class="QLabel" name="mAngleOffsetLabel">
236243
<property name="text">
237-
<string/>
244+
<string>Start Angle</string>
238245
</property>
239246
</widget>
240247
</item>
248+
<item row="6" column="2">
249+
<widget class="QComboBox" name="mAngleOffsetComboBox"/>
250+
</item>
241251
</layout>
242252
</item>
243253
<item row="2" column="0">
@@ -310,8 +320,8 @@
310320
<rect>
311321
<x>0</x>
312322
<y>0</y>
313-
<width>715</width>
314-
<height>318</height>
323+
<width>725</width>
324+
<height>293</height>
315325
</rect>
316326
</property>
317327
<attribute name="label">
@@ -499,8 +509,8 @@
499509
<rect>
500510
<x>0</x>
501511
<y>0</y>
502-
<width>713</width>
503-
<height>271</height>
512+
<width>725</width>
513+
<height>278</height>
504514
</rect>
505515
</property>
506516
<attribute name="label">
@@ -661,8 +671,8 @@
661671
<rect>
662672
<x>0</x>
663673
<y>0</y>
664-
<width>728</width>
665-
<height>166</height>
674+
<width>738</width>
675+
<height>196</height>
666676
</rect>
667677
</property>
668678
<attribute name="label">

0 commit comments

Comments
 (0)
Please sign in to comment.