Skip to content

Commit

Permalink
Merge pull request #483 from matthias-kuhn/pie-angle
Browse files Browse the repository at this point in the history
Add start angle offset for pie diagram
  • Loading branch information
mhugent committed Mar 27, 2013
2 parents 0005467 + 429be1e commit c2dcc72
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
22 changes: 21 additions & 1 deletion src/app/qgsdiagramproperties.cpp
Expand Up @@ -44,7 +44,6 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare

setupUi( this );


mBackgroundColorButton->setColorDialogTitle( tr( "Background color" ) );
mBackgroundColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mDiagramPenColorButton->setColorDialogTitle( tr( "Pen color" ) );
Expand Down Expand Up @@ -112,6 +111,11 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mDataDefinedXComboBox->addItem( tr( "None" ), -1 );
mDataDefinedYComboBox->addItem( tr( "None" ), -1 );

mAngleOffsetComboBox->addItem( tr( "Top" ), 90 * 16 );
mAngleOffsetComboBox->addItem( tr( "Right" ), 0 );
mAngleOffsetComboBox->addItem( tr( "Bottom" ), 270 * 16 );
mAngleOffsetComboBox->addItem( tr( "Left" ), 180 * 16 );

//insert all attributes into the combo boxes
const QgsFields& layerFields = layer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
Expand Down Expand Up @@ -198,6 +202,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mLabelPlacementComboBox->setCurrentIndex( 1 );
}

mAngleOffsetComboBox->setCurrentIndex( mAngleOffsetComboBox->findData( settingList.at( 0 ).angleOffset ) );

mOrientationLeftButton->setProperty( "direction", QgsDiagramSettings::Left );
mOrientationRightButton->setProperty( "direction", QgsDiagramSettings::Right );
mOrientationUpButton->setProperty( "direction", QgsDiagramSettings::Up );
Expand Down Expand Up @@ -346,6 +352,17 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int inde
mScaleDependencyComboBox->hide();
mScaleDependencyLabel->hide();
}

if ( DIAGRAM_NAME_PIE == diagramType )
{
mAngleOffsetComboBox->show();
mAngleOffsetLabel->show();
}
else
{
mAngleOffsetComboBox->hide();
mAngleOffsetLabel->hide();
}
}
void QgsDiagramProperties::addAttribute( QTreeWidgetItem * item )
{
Expand Down Expand Up @@ -521,6 +538,9 @@ void QgsDiagramProperties::apply()
ds.maxScaleDenominator = -1;
}

// Diagram angle offset (pie)
ds.angleOffset = mAngleOffsetComboBox->itemData( mAngleOffsetComboBox->currentIndex() ).toInt();

// Diagram orientation (histogram)
ds.diagramOrientation = static_cast<QgsDiagramSettings::DiagramOrientation>( mOrientationButtonGroup->checkedButton()->property( "direction" ).toInt() );

Expand Down
4 changes: 2 additions & 2 deletions src/core/diagram/qgspiediagram.cpp
Expand Up @@ -128,7 +128,7 @@ void QgsPieDiagram::renderDiagram( const QgsAttributes& att, QgsRenderContext& c
QList< QColor >::const_iterator colIt = s.categoryColors.constBegin();
for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
{
currentAngle = *valIt / valSum * 360 * 16;
currentAngle = *valIt / valSum * 360 * 16;
mCategoryBrush.setColor( *colIt );
p->setBrush( mCategoryBrush );
// if only 1 value is > 0, draw a circle
Expand All @@ -138,7 +138,7 @@ void QgsPieDiagram::renderDiagram( const QgsAttributes& att, QgsRenderContext& c
}
else
{
p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
p->drawPie( baseX, baseY, w, h, totalAngle + s.angleOffset, currentAngle );
}
totalAngle += currentAngle;
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsdiagramrendererv2.cpp
Expand Up @@ -111,6 +111,8 @@ void QgsDiagramSettings::readXML( const QDomElement& elem )

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

angleOffset = elem.attribute( "angleOffset" ).toInt();

minimumSize = elem.attribute( "minimumSize" ).toDouble();

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

categoryElem.setAttribute( "barWidth", QString::number( barWidth ) );
categoryElem.setAttribute( "minimumSize", QString::number( minimumSize ) );
categoryElem.setAttribute( "angleOffset", QString::number( angleOffset ) );

QString colors;
for ( int i = 0; i < categoryColors.size(); ++i )
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsdiagramrendererv2.h
Expand Up @@ -128,6 +128,7 @@ class CORE_EXPORT QgsDiagramSettings
double barWidth;
int transparency; // 0 - 100
bool scaleByArea;
int angleOffset;

//scale range (-1 if no lower / upper bound )
double minScaleDenominator;
Expand Down
38 changes: 24 additions & 14 deletions src/ui/qgsdiagrampropertiesbase.ui
Expand Up @@ -39,8 +39,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>752</width>
<height>613</height>
<width>756</width>
<height>627</height>
</rect>
</property>
<layout class="QVBoxLayout" name="scrollAreaLayout">
Expand Down Expand Up @@ -124,8 +124,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>713</width>
<height>364</height>
<width>725</width>
<height>397</height>
</rect>
</property>
<attribute name="label">
Expand All @@ -134,6 +134,13 @@
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0" rowspan="2">
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="2">
<widget class="QgsColorButton" name="mDiagramPenColorButton">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="mBackgroundColorLabel">
<property name="text">
Expand All @@ -155,7 +162,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QPushButton" name="mDiagramFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
Expand Down Expand Up @@ -231,13 +238,16 @@
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QgsColorButton" name="mDiagramPenColorButton">
<item row="6" column="1">
<widget class="QLabel" name="mAngleOffsetLabel">
<property name="text">
<string/>
<string>Start Angle</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QComboBox" name="mAngleOffsetComboBox"/>
</item>
</layout>
</item>
<item row="2" column="0">
Expand Down Expand Up @@ -310,8 +320,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>715</width>
<height>318</height>
<width>725</width>
<height>293</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -499,8 +509,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>713</width>
<height>271</height>
<width>725</width>
<height>278</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -661,8 +671,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>728</width>
<height>166</height>
<width>738</width>
<height>196</height>
</rect>
</property>
<attribute name="label">
Expand Down

0 comments on commit c2dcc72

Please sign in to comment.