24 mPen.setWidthF( 2.0 );
25 mPen.setColor( QColor( 0, 0, 0 ) );
26 mPen.setCapStyle( Qt::FlatCap );
27 mBrush.setStyle( Qt::SolidPattern );
47 attrVal = expression->
evaluate( feature );
54 if ( !attrVal.isValid() )
59 double scaledValue = attrVal.toDouble();
62 double scaledLowerSizeWidth = is.
lowerSize.width();
63 double scaledLowerSizeHeight = is.
lowerSize.height();
64 double scaledUpperSizeWidth = is.
upperSize.width();
65 double scaledUpperSizeHeight = is.
upperSize.height();
70 scaledValue = sqrt( scaledValue );
71 scaledLowerValue = sqrt( scaledLowerValue );
72 scaledUpperValue = sqrt( scaledUpperValue );
73 scaledLowerSizeWidth = sqrt( scaledLowerSizeWidth );
74 scaledLowerSizeHeight = sqrt( scaledLowerSizeHeight );
75 scaledUpperSizeWidth = sqrt( scaledUpperSizeWidth );
76 scaledUpperSizeHeight = sqrt( scaledUpperSizeHeight );
80 double scaledRatio = ( scaledValue - scaledLowerValue ) / ( scaledUpperValue - scaledLowerValue );
97 Q_UNUSED( attributes );
114 double w = spu.width();
115 double h = spu.height();
117 double baseX = position.x();
118 double baseY = position.y() - h;
120 QList<QPointF> textPositions;
122 for (
int i = 0; i < nCategories; ++i )
126 textPositions.push_back( QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) );
130 textPositions.push_back( QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
138 p->setBrush( mBrush );
143 p->drawEllipse( baseX, baseY, w, h );
146 QList<QPointF> intersect;
147 QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
148 double r1 = w / 2.0;
double r2 = h / 2.0;
150 for (
int i = 1; i < nCategories; ++i )
154 lineEllipseIntersection( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
158 lineEllipseIntersection( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
160 if ( intersect.size() > 1 )
162 p->drawLine( intersect.at( 0 ), intersect.at( 1 ) );
168 p->drawRect( QRectF( baseX, baseY, w, h ) );
169 for (
int i = 1; i < nCategories; ++i )
173 p->drawLine( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ) );
177 p->drawLine( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ) );
184 triangle << QPointF( baseX, baseY + h ) << QPointF( baseX + w, baseY + h ) << QPointF( baseX + w / 2.0, baseY );
185 p->drawPolygon( triangle );
187 QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
188 QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
189 QPointF intersectionPoint1, intersectionPoint2;
191 for (
int i = 1; i < nCategories; ++i )
195 QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
196 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
198 verticalLine.intersect( triangleEdgeLeft, &intersectionPoint1 );
202 verticalLine.intersect( triangleEdgeRight, &intersectionPoint1 );
204 p->drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
208 QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
209 horizontalLine.intersect( triangleEdgeLeft, &intersectionPoint1 );
210 horizontalLine.intersect( triangleEdgeRight, &intersectionPoint2 );
211 p->drawLine( intersectionPoint1, intersectionPoint2 );
218 QFontMetricsF fontMetrics( sFont );
221 for (
int i = 0; i < textPositions.size(); ++i )
224 QString val = expression->
evaluate( feature ).toString();
227 double textWidth = fontMetrics.width( val );
228 double textHeight = fontMetrics.height();
232 QPointF position = textPositions.at( i );
240 xOffset = textHeight / 2.0;
244 xOffset = fontMetrics.xHeight();
247 p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val );
251 void QgsTextDiagram::lineEllipseIntersection(
const QPointF& lineStart,
const QPointF& lineEnd,
const QPointF& ellipseMid,
double r1,
double r2, QList<QPointF>& result )
const
255 double rrx = r1 * r1;
256 double rry = r2 * r2;
257 double x21 = lineEnd.x() - lineStart.x();
258 double y21 = lineEnd.y() - lineStart.y();
259 double x10 = lineStart.x() - ellipseMid.x();
260 double y10 = lineStart.y() - ellipseMid.y();
261 double a = x21 * x21 / rrx + y21 * y21 / rry;
262 double b = x21 * x10 / rrx + y21 * y10 / rry;
263 double c = x10 * x10 / rrx + y10 * y10 / rry;
264 double d = b * b - a * ( c - 1 );
267 double e = sqrt( d );
268 double u1 = ( -b - e ) / a;
269 double u2 = ( -b + e ) / a;
271 if ( -0.00001 <= u1 && u1 < 1.00001 )
273 result.push_back( QPointF( lineStart.x() + x21 * u1, lineStart.y() + y21 * u1 ) );
275 if ( -0.00001 <= u2 && u2 <= 1.00001 )
277 result.push_back( QPointF( lineStart.x() + x21 * u2, lineStart.y() + y21 * u2 ) );