Skip to content

Commit

Permalink
Make bar width configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 9, 2012
1 parent 04fd6b6 commit 55ff09e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -900,6 +900,8 @@ void QgsVectorLayerProperties::apply()
ds.diagramOrientation = QgsDiagramSettings::Left;
}

ds.barWidth = mBarWidthSpinBox->value();

if ( mFixedSizeCheckBox->isChecked() )
{
QgsSingleCategoryDiagramRenderer* dr = new QgsSingleCategoryDiagramRenderer();
Expand Down Expand Up @@ -1748,9 +1750,10 @@ void QgsVectorLayerProperties::initDiagramTab()
case QgsDiagramSettings::Down:
mOrientationDownButton->setChecked( true );
break;

}

mBarWidthSpinBox->setValue( settingList.at( 0 ).barWidth );

mIncreaseSmallDiagramsCheckBox->setChecked( settingList.at( 0 ).minimumSize != 0 );
mIncreaseMinimumSizeSpinBox->setValue( settingList.at( 0 ).minimumSize );

Expand Down
15 changes: 7 additions & 8 deletions src/core/qgsdiagram.cpp
Expand Up @@ -351,7 +351,8 @@ void QgsHistogramDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderCo
values.push_back( currentVal );
}

double currentOffset = 0;
double currentOffset = 0 - ( values.size() * s.barWidth ) / 2;
double scaledWidth = sizePainterUnits( s.barWidth, s, c );

double baseX = position.x();
double baseY = position.y();
Expand All @@ -360,8 +361,6 @@ void QgsHistogramDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderCo
setPenWidth( mPen, s, c );
p->setPen( mPen );

p->drawPoint( baseX, baseY );

QList<double>::const_iterator valIt = values.constBegin();
QList< QColor >::const_iterator colIt = s.categoryColors.constBegin();
for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
Expand All @@ -374,22 +373,22 @@ void QgsHistogramDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderCo
switch ( s.diagramOrientation )
{
case QgsDiagramSettings::Up:
p->drawRect( baseX + currentOffset, baseY, 10, 0 - length );
p->drawRect( baseX + currentOffset, baseY, scaledWidth, 0 - length );
break;

case QgsDiagramSettings::Down:
p->drawRect( baseX + currentOffset, baseY, 10, length );
p->drawRect( baseX + currentOffset, baseY, scaledWidth, length );
break;

case QgsDiagramSettings::Right:
p->drawRect( baseX, baseY + currentOffset, 0 - length, 10 );
p->drawRect( baseX, baseY + currentOffset, 0 - length, scaledWidth );
break;

case QgsDiagramSettings::Left:
p->drawRect( baseX, baseY + currentOffset, length, 10 );
p->drawRect( baseX, baseY + currentOffset, length, scaledWidth );
break;
}

currentOffset += 10;
currentOffset += scaledWidth;
}
}
3 changes: 3 additions & 0 deletions src/core/qgsdiagramrendererv2.cpp
Expand Up @@ -93,6 +93,8 @@ void QgsDiagramSettings::readXML( const QDomElement& elem )
diagramOrientation = Up;
}

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

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

//colors
Expand Down Expand Up @@ -170,6 +172,7 @@ void QgsDiagramSettings::writeXML( QDomElement& rendererElem, QDomDocument& doc
break;
}

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

QString colors;
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsdiagramrendererv2.h
Expand Up @@ -123,6 +123,7 @@ struct CORE_EXPORT QgsDiagramSettings
double penWidth;
LabelPlacementMethod labelPlacementMethod;
DiagramOrientation diagramOrientation;
double barWidth;

//scale range (-1 if no lower / upper bound )
double minScaleDenominator;
Expand Down
14 changes: 14 additions & 0 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -1353,6 +1353,20 @@
</property>
</spacer>
</item>
<item row="6" column="0" colspan="3">
<layout class="QHBoxLayout" name="mBarWidthLayout">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Bar width</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="mBarWidthSpinBox"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 55ff09e

Please sign in to comment.