24 mPen.setWidthF( 2.0 );
25 mPen.setColor( QColor( 0, 0, 0 ) );
26 mPen.setCapStyle( Qt::FlatCap );
27 mBrush.setStyle( Qt::SolidPattern );
46 attrVal = expression->
evaluate( &expressionContext );
54 double val = attrVal.toDouble( &ok );
66 return std::max( size.width(), size.height() );
77 Q_UNUSED( attributes )
84 QPainter *p =
c.painter();
92 double w = spu.width();
93 double h = spu.height();
95 double baseX = position.x();
96 double baseY = position.y() - h;
98 QVector<QPointF> textPositions;
100 for (
int i = 0; i < nCategories; ++i )
104 textPositions.push_back( QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) );
108 textPositions.push_back( QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
116 p->setBrush( mBrush );
121 p->drawEllipse( baseX, baseY, w, h );
124 QList<QPointF> intersect;
125 QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
129 for (
int i = 1; i < nCategories; ++i )
133 lineEllipseIntersection( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
137 lineEllipseIntersection( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
139 if ( intersect.size() > 1 )
141 p->drawLine( intersect.at( 0 ), intersect.at( 1 ) );
147 p->drawRect( QRectF( baseX, baseY, w, h ) );
148 for (
int i = 1; i < nCategories; ++i )
152 p->drawLine( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ) );
156 p->drawLine( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ) );
163 triangle << QPointF( baseX, baseY + h ) << QPointF( baseX + w, baseY + h ) << QPointF( baseX + w / 2.0, baseY );
164 p->drawPolygon( triangle );
166 QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
167 QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
168 QPointF intersectionPoint1, intersectionPoint2;
170 for (
int i = 1; i < nCategories; ++i )
174 QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
175 if ( baseX + w / nCategories * i < baseX + w / 2.0 )
177 verticalLine.intersect( triangleEdgeLeft, &intersectionPoint1 );
181 verticalLine.intersect( triangleEdgeRight, &intersectionPoint1 );
183 p->drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
187 QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
188 horizontalLine.intersect( triangleEdgeLeft, &intersectionPoint1 );
189 horizontalLine.intersect( triangleEdgeRight, &intersectionPoint2 );
190 p->drawLine( intersectionPoint1, intersectionPoint2 );
197 QFontMetricsF fontMetrics( sFont );
205 for (
int i = 0; i < textPositions.size(); ++i )
208 QString val = expression->
evaluate( &expressionContext ).toString();
211 double textWidth = fontMetrics.width( val );
212 double textHeight = fontMetrics.height();
216 QPointF position = textPositions.at( i );
224 xOffset = textHeight / 2.0;
228 xOffset = fontMetrics.xHeight();
231 p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val );
235 void QgsTextDiagram::lineEllipseIntersection( QPointF lineStart, QPointF lineEnd, QPointF ellipseMid,
double r1,
double r2, QList<QPointF> &result )
const
239 double rrx = r1 * r1;
240 double rry = r2 * r2;
241 double x21 = lineEnd.x() - lineStart.x();
242 double y21 = lineEnd.y() - lineStart.y();
243 double x10 = lineStart.x() - ellipseMid.x();
244 double y10 = lineStart.y() - ellipseMid.y();
245 double a = x21 * x21 / rrx + y21 * y21 / rry;
246 double b = x21 * x10 / rrx + y21 * y10 / rry;
247 double c = x10 * x10 / rrx + y10 * y10 / rry;
248 double d = b * b - a * (
c - 1 );
251 double e = std::sqrt( d );
252 double u1 = ( -b - e ) / a;
253 double u2 = ( -b + e ) / a;
255 if ( -0.00001 <= u1 && u1 < 1.00001 )
257 result.push_back( QPointF( lineStart.x() + x21 * u1, lineStart.y() + y21 * u1 ) );
259 if ( -0.00001 <= u2 && u2 <= 1.00001 )
261 result.push_back( QPointF( lineStart.x() + x21 * u2, lineStart.y() + y21 * u2 ) );