48 mPen.setWidthF( 2.0 );
49 mPen.setColor( QColor( 0, 0, 0 ) );
50 mPen.setCapStyle( Qt::FlatCap );
51 mBrush.setStyle( Qt::SolidPattern );
75 double w = spu.width();
76 double h = spu.height();
78 double baseX = position.x();
79 double baseY = position.y() - h;
81 QList<QPointF> textPositions;
83 for (
int i = 0; i < nCategories; ++i )
87 textPositions.push_back( QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0 , baseY + h / 2.0 ) );
91 textPositions.push_back( QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
104 p->drawEllipse( baseX, baseY, w, h );
107 QList<QPointF> intersect;
108 QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
109 double r1 = w / 2.0;
double r2 = h / 2.0;
111 for (
int i = 1; i < nCategories; ++i )
115 lineEllipseIntersection( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
119 lineEllipseIntersection( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
121 if ( intersect.size() > 1 )
123 p->drawLine( intersect.at( 0 ), intersect.at( 1 ) );
129 p->drawRect( QRectF( baseX, baseY, w, h ) );
130 for (
int i = 1; i < nCategories; ++i )
134 p->drawLine( QPointF( baseX + w / nCategories * i , baseY ), QPointF( baseX + w / nCategories * i, baseY + h ) );
138 p->drawLine( QPointF( baseX, baseY + h / nCategories * i ) , QPointF( baseX + w, baseY + h / nCategories * i ) );
145 triangle << QPointF( baseX, baseY + h ) << QPointF( baseX + w, baseY + h ) << QPointF( baseX + w / 2.0, baseY );
146 p->drawPolygon( triangle );
148 QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
149 QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
150 QPointF intersectionPoint1, intersectionPoint2;
152 for (
int i = 1; i < nCategories; ++i )
156 QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
157 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
159 verticalLine.intersect( triangleEdgeLeft, &intersectionPoint1 );
163 verticalLine.intersect( triangleEdgeRight, &intersectionPoint1 );
165 p->drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
169 QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
170 horizontalLine.intersect( triangleEdgeLeft, &intersectionPoint1 );
171 horizontalLine.intersect( triangleEdgeRight, &intersectionPoint2 );
172 p->drawLine( intersectionPoint1, intersectionPoint2 );
179 QFontMetricsF fontMetrics( sFont );
182 for (
int i = 0; i < textPositions.size(); ++i )
186 double textHeight = fontMetrics.height();
187 double textWidth = fontMetrics.width( val );
190 QPointF position = textPositions.at( i );
191 p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + textHeight / 2.0 ), val );
199 double rrx = r1 * r1;
200 double rry = r2 * r2;
201 double x21 = lineEnd.x() - lineStart.x();
202 double y21 = lineEnd.y() - lineStart.y();
203 double x10 = lineStart.x() - ellipseMid.x();
204 double y10 = lineStart.y() - ellipseMid.y();
205 double a = x21 * x21 / rrx + y21 * y21 / rry;
206 double b = x21 * x10 / rrx + y21 * y10 / rry;
207 double c = x10 * x10 / rrx + y10 * y10 / rry;
208 double d = b * b - a * ( c - 1 );
211 double e = sqrt( d );
212 double u1 = ( -b - e ) / a;
213 double u2 = ( -b + e ) / a;
215 if ( -0.00001 <= u1 && u1 < 1.00001 )
217 result.push_back( QPointF( lineStart.x() + x21 * u1, lineStart.y() + y21 * u1 ) );
219 if ( -0.00001 <= u2 && u2 <= 1.00001 )
221 result.push_back( QPointF( lineStart.x() + x21 * u2, lineStart.y() + y21 * u2 ) );
229 mPen.setStyle( Qt::SolidLine );
245 QList<double> values;
246 double currentVal = 0;
252 currentVal = att[*catIt].toDouble();
253 values.push_back( currentVal );
254 valSum += currentVal;
258 double totalAngle = 0;
263 double w = spu.width();
264 double h = spu.height();
266 double baseX = position.x();
267 double baseY = position.y() - h;
273 QList<double>::const_iterator valIt = values.constBegin();
274 QList< QColor >::const_iterator colIt = s.
categoryColors.constBegin();
275 for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
277 currentAngle = *valIt / valSum * 360 * 16;
280 p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
281 totalAngle += currentAngle;