Skip to content
Permalink
Browse files

Add start angle offset for pie diagram

  • Loading branch information
m-kuhn committed Mar 27, 2013
1 parent 0005467 commit 429be1e9c56ba5f750a79d75e0e6fd462d34d618
@@ -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" ) );
@@ -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 )
@@ -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 );
@@ -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 )
{
@@ -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() );

@@ -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
@@ -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;
}
@@ -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
@@ -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 )
@@ -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;
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">

0 comments on commit 429be1e

Please sign in to comment.
You can’t perform that action at this time.