00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <QAbstractItemModel>
00031
00032 #include "KDChartBarDiagram.h"
00033 #include "KDChartLineDiagram.h"
00034 #include "KDChartTextAttributes.h"
00035 #include "KDChartAttributesModel.h"
00036 #include "KDChartAbstractCartesianDiagram.h"
00037 #include "KDChartNormalLineDiagram_p.h"
00038
00039 using namespace KDChart;
00040
00041 NormalLineDiagram::NormalLineDiagram( LineDiagram* d )
00042 : LineDiagramType( d )
00043 {
00044 }
00045
00046 LineDiagram::LineType NormalLineDiagram::type() const
00047 {
00048 return LineDiagram::Normal;
00049 }
00050
00051 const QPair< QPointF, QPointF > NormalLineDiagram::calculateDataBoundaries() const
00052 {
00053 const int rowCount = compressor().modelDataRows();
00054 const int colCount = compressor().modelDataColumns();
00055 double xMin = 0;
00056 double xMax = diagram()->model() ? diagram()->model()->rowCount( diagram()->rootIndex() ) - 1 : 0;
00057 double yMin = 0;
00058 double yMax = 0;
00059
00060 bool first = true;
00061 for( int column = 0; column < colCount; ++column )
00062 {
00063 for ( int row = 0; row < rowCount; ++row )
00064 {
00065 const CartesianDiagramDataCompressor::CachePosition position( row, column );
00066 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
00067
00068 if ( first ) {
00069 yMin = point.value;
00070 yMax = point.value;
00071 } else {
00072 yMin = qMin( yMin, point.value );
00073 yMax = qMax( yMax, point.value );
00074 }
00075
00076 first = false;
00077 }
00078 }
00079
00080 const QPointF bottomLeft( QPointF( xMin, qMin( 0.0, yMin ) ) );
00081 const QPointF topRight( QPointF( xMax, yMax ) );
00082 return QPair< QPointF, QPointF >( bottomLeft, topRight );
00083 }
00084
00085 void NormalLineDiagram::paint( PaintContext* ctx )
00086 {
00087 reverseMapper().clear();
00088 Q_ASSERT( dynamic_cast<CartesianCoordinatePlane*>( ctx->coordinatePlane() ) );
00089 CartesianCoordinatePlane* plane = static_cast<CartesianCoordinatePlane*>( ctx->coordinatePlane() );
00090 const int columnCount = compressor().modelDataColumns();
00091 const int rowCount = compressor().modelDataRows();
00092 if ( columnCount == 0 || rowCount == 0 ) return;
00093
00094
00095
00096 int maxFound = 0;
00097
00098
00099
00100
00101
00102
00103
00104 maxFound = columnCount;
00105
00106
00107 DataValueTextInfoList textInfoList;
00108 LineAttributesInfoList lineList;
00109 LineAttributes::MissingValuesPolicy policy;
00110
00111 for( int column = 0; column < columnCount; ++column ) {
00112 LineAttributes laPreviousCell;
00113 CartesianDiagramDataCompressor::CachePosition previousCellPosition;
00114
00115 for ( int row = 0; row < rowCount; ++row ) {
00116 const CartesianDiagramDataCompressor::CachePosition position( row, column );
00117
00118 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
00119 LineAttributes laCell;
00120 if ( row > 0 ) {
00121 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
00122 const CartesianDiagramDataCompressor::DataPoint lastPoint = compressor().data( previousCellPosition );
00123
00124 const QPointF a( plane->translate( QPointF( lastPoint.key, lastPoint.value ) ) );
00125 const QPointF b( plane->translate( QPointF( point.key, point.value ) ) );
00126 const QPointF c( plane->translate( QPointF( lastPoint.key, 0.0 ) ) );
00127 const QPointF d( plane->translate( QPointF( point.key, 0.0 ) ) );
00128
00129 laCell = diagram()->lineAttributes( sourceIndex );
00130
00131 const PositionPoints pts = PositionPoints( b, a, d, c );
00132
00133 QList<QPolygonF> areas;
00134 if ( laCell.displayArea() ) {
00135 QPolygonF polygon;
00136 polygon << a << b << d << c;
00137 areas << polygon;
00138 }
00139
00140 if ( ! point.hidden ) {
00141 appendDataValueTextInfoToList( diagram(), textInfoList, sourceIndex, pts,
00142 Position::NorthWest, Position::SouthWest,
00143 point.value );
00144 paintAreas( ctx, attributesModel()->mapToSource( lastPoint.index ), areas, laCell.transparency() );
00145 lineList.append( LineAttributesInfo( sourceIndex, a, b ) );
00146 }
00147 }
00148
00149 previousCellPosition = position;
00150 laPreviousCell = laCell;
00151 }
00152 }
00153
00154 paintElements( ctx, textInfoList, lineList, policy );
00155 }