24 #include "KDChartBarDiagram_p.h"
27 #include "KDChartPainterSaver_p.h"
29 using namespace KDChart;
31 BarDiagram::Private::Private(
const Private& rhs )
36 void BarDiagram::BarDiagramType::paintBars(
PaintContext* ctx,
const QModelIndex& index,
const QRectF& bar, qreal& maxDepth )
39 QPolygonF topPoints, sidePoints;
44 QBrush indexBrush( diagram()->brush( index ) );
45 QPen indexPen( diagram()->pen( index ) );
46 PainterSaver painterSaver( ctx->
painter() );
48 ctx->
painter()->setRenderHint( QPainter::Antialiasing, diagram()->antiAliasing() );
50 indexBrush = threeDAttrs.
threeDBrush( indexBrush, bar );
51 ctx->
painter()->setBrush( indexBrush );
55 bool stackedMode =
false;
56 bool percentMode =
false;
64 usedDepth = threeDAttrs.
depth()/4;
69 usedDepth = threeDAttrs.
depth();
74 usedDepth = threeDAttrs.
depth();
79 Q_ASSERT_X (
false,
"dataBoundaries()",
80 "Type item does not match a defined bar chart Type." );
82 isoRect = bar.translated( usedDepth, -usedDepth );
86 if ( isoRect.height() < 0 ) {
87 topPoints << isoRect.bottomLeft() << isoRect.bottomRight()
88 << bar.bottomRight() << bar.bottomLeft();
91 if ( index.column() == 0 ) {
99 reverseMapper().addRect( index.row(), index.column(), isoRect );
100 ctx->
painter()->drawRect( isoRect );
101 topPoints << bar.topLeft() << bar.topRight() << isoRect.topRight() << isoRect.topLeft();
104 if ( percentMode && isoRect.height() == 0 )
107 bool needToSetClippingOffForTop =
false;
112 bool hasPointOutside =
false;
113 const QRectF r( ctx->
rectangle().adjusted(0,-1,1,0) );
114 KDAB_FOREACH( QPointF pt, topPoints ) {
115 if ( r.contains( pt ) )
118 hasPointOutside =
true;
121 const PainterSaver p( ctx->
painter() );
122 needToSetClippingOffForTop = hasPointOutside && ctx->
painter()->hasClipping();
123 if ( needToSetClippingOffForTop )
124 ctx->
painter()->setClipping(
false );
125 reverseMapper().addPolygon( index.row(), index.column(), topPoints );
126 ctx->
painter()->drawPolygon( topPoints );
132 sidePoints << bar.topRight() << isoRect.topRight() << isoRect.bottomRight() << bar.bottomRight();
133 if ( bar.height() != 0 ) {
134 const PainterSaver p( ctx->
painter() );
135 if ( needToSetClippingOffForTop )
136 ctx->
painter()->setClipping(
false );
137 reverseMapper().addPolygon( index.row(), index.column(), sidePoints );
138 ctx->
painter()->drawPolygon( sidePoints );
142 if ( bar.height() != 0 )
144 reverseMapper().addRect( index.row(), index.column(), bar );
145 ctx->
painter()->drawRect( bar );
153 return m_private->attributesModel;
156 QModelIndex BarDiagram::BarDiagramType::attributesModelRootIndex()
const
158 return diagram()->attributesModelRootIndex();
161 BarDiagram* BarDiagram::BarDiagramType::diagram()
const
163 return static_cast< BarDiagram*
>( m_private->diagram );
166 void BarDiagram::BarDiagramType::calculateValueAndGapWidths(
int rowCount,
int colCount,
169 qreal& outSpaceBetweenBars,
170 qreal& outSpaceBetweenGroups )
173 Q_UNUSED( rowCount );
185 if ( type() == Normal )
192 qreal unitWidth = groupWidth / units;
193 outBarWidth = unitWidth;
209 return m_private->reverseMapper;
212 CartesianDiagramDataCompressor& BarDiagram::BarDiagramType::compressor()
const
214 return m_private->compressor;