QGraphicsItem* CGraphicsPolylineItem::createItem() { QGraphicsPathItem* pItem = new QGraphicsPathItem(m_Parent); drawPen(pItem); QPainterPath path; QPolygonF d; QStringList lstPath = GET_VALUE(d).split(' '); int iCount = lstPath.size(); for (int j = 0; j < iCount; j++) { QStringList lstPoint = lstPath[j].split(','); d.append(QPointF(lstPoint[0].toDouble(), lstPoint[1].toDouble())); lstPoint.clear(); } if (d.count() > 0) { path.moveTo(d[0]); } for (int i = 1; i < d.count() ; i++) { path.lineTo(d[i]); } pItem->setPath(path); return pItem; }
void VLCStatsView::addValue( float value ) { value /= 1000; QPolygonF shape = totalbitrateShape->polygon(); if ( shape.count() > ( STATS_LENGTH + 2 ) ) /* keep only STATS_LENGTH samples */ { shape.remove( 1 ); for(int i=1; i<( STATS_LENGTH + 2 ); i++) ( (QPointF &) shape.at(i) ).setX( i - 1 ); /*move back values*/ } int count = shape.count(); if ( count == 0 ) { shape << QPointF( 0, 0 ); /* begin and close shape */ shape << QPointF( count, 0 ); } shape.insert( shape.end() - 1, QPointF( count, value ) ); ( (QPointF &) shape.last() ).setX( count ); totalbitrateShape->setPolygon( shape ); addHistoryValue( value ); QRectF maxsizes = scene()->itemsBoundingRect(); maxsizes.setRight( STATS_LENGTH ); fitInView( maxsizes ); /* fix viewport */ drawRulers( maxsizes ); }
void QgsMarkerLineSymbolLayerV2::renderOffsetVertexAlongLine( const QPolygonF &points, int vertex, double distance, QgsSymbolV2RenderContext& context ) { if ( points.isEmpty() ) return; QgsRenderContext& rc = context.renderContext(); double origAngle = mMarker->angle(); if ( distance == 0 ) { // rotate marker (if desired) if ( mRotateMarker ) { bool isRing = false; if ( points.first() == points.last() ) isRing = true; double angle = markerAngle( points, isRing, vertex ); mMarker->setAngle( origAngle + angle * 180 / M_PI ); } mMarker->renderPoint( points[vertex], context.feature(), rc, -1, context.selected() ); return; } int pointIncrement = distance > 0 ? 1 : -1; QPointF previousPoint = points[vertex]; int startPoint = distance > 0 ? qMin( vertex + 1, points.count() - 1 ) : qMax( vertex - 1, 0 ); int endPoint = distance > 0 ? points.count() - 1 : 0; double distanceLeft = qAbs( distance ); for ( int i = startPoint; pointIncrement > 0 ? i <= endPoint : i >= endPoint; i += pointIncrement ) { const QPointF& pt = points[i]; if ( previousPoint == pt ) // must not be equal! continue; // create line segment MyLine l( previousPoint, pt ); if ( distanceLeft < l.length() ) { //destination point is in current segment QPointF markerPoint = previousPoint + l.diffForInterval( distanceLeft ); // rotate marker (if desired) if ( mRotateMarker ) { mMarker->setAngle( origAngle + ( l.angle() * 180 / M_PI ) ); } mMarker->renderPoint( markerPoint, context.feature(), rc, -1, context.selected() ); return; } distanceLeft -= l.length(); previousPoint = pt; } //didn't find point return; }
void paintElements( AbstractDiagram::Private *diagramPrivate, PaintContext* ctx, const LabelPaintCache& lpc, const LineAttributesInfoList& lineList ) { AbstractDiagram* diagram = diagramPrivate->diagram; // paint all lines and their attributes const PainterSaver painterSaver( ctx->painter() ); ctx->painter()->setRenderHint( QPainter::Antialiasing, diagram->antiAliasing() ); QBrush curBrush; QPen curPen; QPolygonF points; KDAB_FOREACH ( const LineAttributesInfo& lineInfo, lineList ) { const QModelIndex& index = lineInfo.index; const ThreeDLineAttributes td = threeDLineAttributes( diagram, index ); if ( td.isEnabled() ) { PaintingHelpers::paintThreeDLines( ctx, diagram, index, lineInfo.value, lineInfo.nextValue, td, &diagramPrivate->reverseMapper ); } else { const QBrush brush( diagram->brush( index ) ); const QPen pen( diagram->pen( index ) ); // line goes from lineInfo.value to lineInfo.nextValue diagramPrivate->reverseMapper.addLine( lineInfo.index.row(), lineInfo.index.column(), lineInfo.value, lineInfo.nextValue ); if ( points.count() && points.last() == lineInfo.value && curBrush == brush && curPen == pen ) { // continue the current run of lines } else { // different painter settings or discontinuous line: start a new run of lines if ( points.count() ) { PaintingHelpers::paintPolyline( ctx, curBrush, curPen, points ); } curBrush = brush; curPen = pen; points.clear(); points << lineInfo.value; } points << lineInfo.nextValue; } } if ( points.count() ) { // the last run of lines is yet to be painted - do it now PaintingHelpers::paintPolyline( ctx, curBrush, curPen, points ); } KDAB_FOREACH ( const LineAttributesInfo& lineInfo, lineList ) { const ValueTrackerAttributes vt = valueTrackerAttributes( diagram, lineInfo.index ); if ( vt.isEnabled() ) { PaintingHelpers::paintValueTracker( ctx, vt, lineInfo.nextValue ); } } // paint all data value texts and the point markers diagramPrivate->paintDataValueTextsAndMarkers( ctx, lpc, true ); }
// this method is factored out from LineDiagram::paint, and contains // the common parts of the method that previously implemented all // chart types in one void LineDiagram::LineDiagramType::paintElements( PaintContext* ctx, DataValueTextInfoList& list, LineAttributesInfoList& lineList, LineAttributes::MissingValuesPolicy policy ) { Q_UNUSED( policy ); // paint all lines and their attributes const PainterSaver painterSaver( ctx->painter() ); if ( diagram()->antiAliasing() ) ctx->painter()->setRenderHint ( QPainter::Antialiasing ); LineAttributesInfoListIterator itline ( lineList ); QBrush curBrush; QPen curPen; QPolygonF points; while ( itline.hasNext() ) { const LineAttributesInfo& lineInfo = itline.next(); const QModelIndex& index = lineInfo.index; const ThreeDLineAttributes td = diagram()->threeDLineAttributes( index ); const ValueTrackerAttributes vt = diagram()->valueTrackerAttributes( index ); if( td.isEnabled() ){ paintThreeDLines( ctx, index, lineInfo.value, lineInfo.nextValue, td.depth() ); } else { const QBrush br( diagram()->brush( index ) ); const QPen pn( diagram()->pen( index ) ); if( points.count() && points.last() == lineInfo.value && curBrush == br && curPen == pn ) { // line goes from last value in points to lineInfo.nextValue reverseMapper().addLine( lineInfo.index.row(), lineInfo.index.column(), points.last(), lineInfo.nextValue ); points << lineInfo.nextValue; } else { if( points.count() ) paintPolyline( ctx, curBrush, curPen, points ); curBrush = br; curPen = pn; points.clear(); // line goes from lineInfo.value to lineInfo,nextValue reverseMapper().addLine( lineInfo.index.row(), lineInfo.index.column(), lineInfo.value, lineInfo.nextValue ); points << lineInfo.value << lineInfo.nextValue; } } if( vt.isEnabled() ) paintValueTracker( ctx, vt, lineInfo.value ); } if( points.count() ) paintPolyline( ctx, curBrush, curPen, points ); // paint all data value texts and the point markers paintDataValueTextsAndMarkers( diagram(), ctx, list, true ); }
void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement ) { if ( points.isEmpty() ) return; QgsRenderContext& rc = context.renderContext(); double origAngle = mMarker->angle(); int i, maxCount; bool isRing = false; if ( placement == FirstVertex ) { i = 0; maxCount = 1; } else if ( placement == LastVertex ) { i = points.count() - 1; maxCount = points.count(); } else { i = 0; maxCount = points.count(); if ( points.first() == points.last() ) isRing = true; } for ( ; i < maxCount; ++i ) { if ( isRing && placement == Vertex && i == points.count() - 1 ) { continue; // don't draw the last marker - it has been drawn already } // rotate marker (if desired) if ( mRotateMarker ) { double angle = markerAngle( points, isRing, i ); mMarker->setAngle( origAngle + angle * 180 / M_PI ); } mMarker->renderPoint( points.at( i ), context.feature(), rc, -1, context.selected() ); } // restore original rotation mMarker->setAngle( origAngle ); }
/*! Fill the area between the curve and the baseline with the curve brush \param painter Painter \param xMap x map \param yMap y map \param canvasRect Contents rectangle of the canvas \param polygon Polygon - will be modified ! \sa setBrush(), setBaseline(), setStyle() */ void QwtPlotCurve::fillCurve( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, QPolygonF &polygon ) const { if ( d_data->brush.style() == Qt::NoBrush ) return; closePolyline( painter, xMap, yMap, polygon ); if ( polygon.count() <= 2 ) // a line can't be filled return; QBrush brush = d_data->brush; if ( !brush.color().isValid() ) brush.setColor( d_data->pen.color() ); if ( d_data->paintAttributes & ClipPolygons ) polygon = QwtClipper::clipPolygonF( canvasRect, polygon, true ); painter->save(); painter->setPen( Qt::NoPen ); painter->setBrush( brush ); QwtPainter::drawPolygon( painter, polygon ); painter->restore(); }
void Checker::prepareForDisplay (const QPolygonF &polygon, int pointRadius, const DocumentModelAxesChecker &modelAxesChecker, const DocumentModelCoords &modelCoords) { LOG4CPP_INFO_S ((*mainCat)) << "Checker::prepareForDisplay"; ENGAUGE_ASSERT (polygon.count () == NUM_AXES_POINTS); // Convert pixel coordinates in QPointF to screen and graph coordinates in Point using // identity transformation, so this routine can reuse computations provided by Transformation QList<Point> points; QPolygonF::const_iterator itr; for (itr = polygon.begin (); itr != polygon.end (); itr++) { const QPointF &pF = *itr; Point p (DUMMY_CURVENAME, pF, pF); points.push_back (p); } // Screen and graph coordinates are treated as the same, so identity transform is used Transformation transformIdentity; transformIdentity.identity(); prepareForDisplay (points, pointRadius, modelAxesChecker, modelCoords, transformIdentity); }
void DiveProfileItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); if (polygon().isEmpty()) return; painter->save(); // This paints the Polygon + Background. I'm setting the pen to QPen() so we don't get a black line here, // after all we need to plot the correct velocities colors later. setPen(Qt::NoPen); QGraphicsPolygonItem::paint(painter, option, widget); // Here we actually paint the boundaries of the Polygon using the colors that the model provides. // Those are the speed colors of the dives. QPen pen; pen.setCosmetic(true); pen.setWidth(2); QPolygonF poly = polygon(); // This paints the colors of the velocities. for (int i = 1, count = dataModel->rowCount(); i < count; i++) { QModelIndex colorIndex = dataModel->index(i, DivePlotDataModel::COLOR); pen.setBrush(QBrush(colorIndex.data(Qt::BackgroundRole).value<QColor>())); painter->setPen(pen); if (i < poly.count()) painter->drawLine(poly[i - 1], poly[i]); } painter->restore(); }
void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) { // draw arrow at the end of line QPainter* p = context.renderContext().painter(); if ( !p ) { return; } int cnt = points.count(); QPointF p2 = points.at( --cnt ); QPointF p1 = points.at( --cnt ); while ( p2 == p1 && cnt ) p1 = points.at( --cnt ); if ( p1 == p2 ) { // this is a collapsed line... don't bother drawing an arrow // with arbitrary orientation return; } double angle = atan2( p2.y() - p1.y(), p2.x() - p1.x() ); double size = context.outputLineWidth( mWidth * 8 ); double angle1 = angle + M_PI / 6; double angle2 = angle - M_PI / 6; QPointF p2_1 = p2 - QPointF( size * cos( angle1 ), size * sin( angle1 ) ); QPointF p2_2 = p2 - QPointF( size * cos( angle2 ), size * sin( angle2 ) ); p->setPen( context.selected() ? mSelPen : mPen ); p->drawLine( p2, p2_1 ); p->drawLine( p2, p2_2 ); }
void QgsAnnotation::drawFrame( QgsRenderContext &context ) const { if ( !mFillSymbol ) return; context.painter()->setRenderHint( QPainter::Antialiasing, context.flags() & QgsRenderContext::Antialiasing ); QPolygonF poly; QList<QPolygonF> rings; //empty list for ( int i = 0; i < 4; ++i ) { QLineF currentSegment = segment( i ); poly << currentSegment.p1(); if ( i == mBalloonSegment && mHasFixedMapPosition ) { poly << mBalloonSegmentPoint1; poly << QPointF( 0, 0 ); poly << mBalloonSegmentPoint2; } poly << currentSegment.p2(); } if ( poly.at( 0 ) != poly.at( poly.count() - 1 ) ) poly << poly.at( 0 ); mFillSymbol->startRender( context ); mFillSymbol->renderPolygon( poly, &rings, nullptr, context ); mFillSymbol->stopRender( context ); }
void VLCStatsView::addHistoryValue( float value ) { /* We keep a full history by creating virtual blocks for inserts, growing by power of 2 when no more space is available. At this time, we also free space by agregating the oldest values 2 by 2. Each shown value finally being a mean of blocksize samples. */ bool doinsert = false; int next_blocksize = blocksize; QPolygonF shape = historyShape->polygon(); int count = shape.count(); if ( count == 0 ) { shape << QPointF( 0, 0 ); /* begin and close shape */ shape << QPointF( count, 0 ); } valuesaccumulator += ( value / blocksize ); valuesaccumulatorcount++; if ( valuesaccumulatorcount == blocksize ) { valuesaccumulator = 0; valuesaccumulatorcount = 0; doinsert = true; } if ( doinsert ) { if ( count > ( STATS_LENGTH + 2 ) ) { float y = 0; y += ((QPointF &) shape.at( historymergepointer + 1 )).y(); y += ((QPointF &) shape.at( historymergepointer + 2 )).y(); y /= 2; /* merge */ shape.remove( historymergepointer + 2 ); ( (QPointF &) shape.at( historymergepointer + 1 ) ).setY( y ); for(int i=historymergepointer +1; i<( STATS_LENGTH + 2 ); i++) ( (QPointF &) shape.at(i) ).setX( i - 1 ); /*move back values*/ historymergepointer++; if ( historymergepointer > ( STATS_LENGTH - 1 ) ) { historymergepointer = 0; next_blocksize = ( blocksize << 1 ); } } shape.insert( shape.end() - 1, QPointF( count, value ) ); ( (QPointF &) shape.last() ).setX( count ); } else ( (QPointF &) shape.last() ).setX( count - 1 ); historyShape->setPolygon( shape ); blocksize = next_blocksize; }
QPolygonF TupGraphicalAlgorithm::polygonFit(const QPolygonF &points) { QPolygonF lines; for (int i = 0; i < points.count(); i+=2) { if (i+1 >= points.count()) { lines << points[i]; break; } QPointF first = points[i]; QPointF second = points[i+1]; lines << fillLine(first, second); } return lines; }
QPolygonF bezier_fit_cubic_single( const QPolygonF& data, double error ) { QPolygonF out(4); const int retn = sp_bezier_fit_cubic(out.data(), data.data(), data.count(), error); if( retn >= 0 ) return out; else return QPolygonF(); }
void LineHandler::highlightPorts(bool isStart) { dehighlightPorts(); const QPolygonF line = mEdge->line(); mNodeWithHighlightedPorts = mEdge->getNodeAt(isStart ? line[0] : line[line.count() - 1], isStart); if (mNodeWithHighlightedPorts) { mNodeWithHighlightedPorts->setPortsVisible(isStart ? mEdge->fromPortTypes() : mEdge->toPortTypes()); } }
EaglePolygon::EaglePolygon(QPolygonF _vertices, qreal _width, int _layer, qreal _spacing) { width = _width; layer = _layer; spacing = _spacing; sourcePoly.resize(_vertices.count()); for (int i = 0; i < _vertices.count(); i++) { ClipperLib::long64 x = (ClipperLib::long64)(_vertices.at(i).x()*RES); ClipperLib::long64 y = (ClipperLib::long64)(_vertices.at(i).y()*RES); sourcePoly[0].push_back(ClipperLib::IntPoint(x,y)); } ClipperLib::Clipper c; c.AddPolygons(sourcePoly, ClipperLib::ptSubject); c.Execute(ClipperLib::ctUnion,sourcePoly); // only makes sure polys orientation is correct ClipperLib::OffsetPolygons(sourcePoly,buffedPoly, width*RES/2, ClipperLib::jtRound); // offset for (unsigned int i = 0; i < buffedPoly[0].size(); i++) { vertices.append(QPointF(buffedPoly[0].at(i).X/RES, buffedPoly[0].at(i).Y/RES)); } }
//! [4] void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (myStartItem->collidesWithItem(myEndItem)) return; QPen myPen = pen(); myPen.setColor(myColor); qreal arrowSize = 20; painter->setPen(myPen); painter->setBrush(myColor); //! [4] //! [5] QLineF centerLine(myStartItem->pos(), myEndItem->pos()); QPolygonF endPolygon = myEndItem->polygon(); QPointF p1 = endPolygon.first() + myEndItem->pos(); QPointF p2; QPointF intersectPoint; QLineF polyLine; for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i) + myEndItem->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } setLine(QLineF(intersectPoint, myStartItem->pos())); //! [5] //! [6] double angle = ::acos(line().dx() / line().length()); if (line().dy() >= 0) angle = (Pi * 2) - angle; QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, cos(angle + Pi / 3) * arrowSize); QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, cos(angle + Pi - Pi / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; //! [6] //! [7] painter->drawLine(line()); painter->drawPolygon(arrowHead); if (isSelected()) { painter->setPen(QPen(myColor, 1, Qt::DashLine)); QLineF myLine = line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); } }
void QgsCentroidFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) { Q_UNUSED( rings ); // calculate centroid double cx = 0, cy = 0; double area, sum = 0; for ( int i = points.count() - 1, j = 0; j < points.count(); i = j++ ) { const QPointF& p1 = points[i]; const QPointF& p2 = points[j]; area = p1.x() * p2.y() - p1.y() * p2.x(); sum += area; cx += ( p1.x() + p2.x() ) * area; cy += ( p1.y() + p2.y() ) * area; } sum *= 3.0; cx /= sum; cy /= sum; mMarker->renderPoint( QPointF( cx, cy ), context.feature(), context.renderContext(), -1, context.selected() ); }
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if(!myStartItem || !myEndItem) { return; } if(myEndItem->sceneBoundingRect().contains(p1())) { return; } QPen myPen = pen(); myPen.setColor(myColor); qreal arrowSize = 5; painter->setPen(myPen); painter->setBrush(myColor); QLineF centerLine(p1(), p2()); QPolygonF endPolygon = myEndItem->mapToScene(myEndItem->shape()).toFillPolygon(); QPointF p1 = endPolygon.first(); QPointF p2; QPointF intersectPoint; QLineF polyLine; for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } setLine(QLineF(intersectPoint, this->p1())); double angle = ::acos(line().dx() / line().length()); if (line().dy() >= 0) angle = (Pi * 2) - angle; QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, cos(angle + Pi / 3) * arrowSize); QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, cos(angle + Pi - Pi / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; painter->drawLine(line()); painter->drawPolygon(arrowHead); }
casa::ImageRegion* ImageRegionGenerator::_makeRegionPolygon( casa::ImageInterface<casa::Float> * image, Carta::Lib::Regions::Polygon* polygon ){ casa::ImageRegion* imageRegion = nullptr; if ( image && polygon ){ QPolygonF poly = polygon->qpolyf(); int cornerPointCount = poly.count(); casa::Vector<casa::Double> x( cornerPointCount ); casa::Vector<casa::Double> y( cornerPointCount ); const casa::CoordinateSystem &cs = image->coordinates( ); bool successful = true; for ( int i = 0; i < cornerPointCount; ++i ) { QPointF polyPt = poly.value( i ); casa::Vector<casa::Double> worldPt = _toWorld( cs, polyPt.x(), polyPt.y(), &successful ); if ( successful ){ x[i] = worldPt[0]; y[i] = worldPt[1]; } else { qDebug() << "i="<<i<<" could not convert x="<<polyPt.x()<<" y="<<polyPt.y()<<" to world."; break; } } if ( successful ){ casa::Vector<casa::Int> dispAxes(2); const casa::CoordinateSystem &cs = image->coordinates( ); int directionIndex = cs.findCoordinate( casa::Coordinate::DIRECTION ); if ( directionIndex >= 0 ){ casa::Vector<casa::Int> dirPixelAxis = cs.pixelAxes(directionIndex); dispAxes(0) = dirPixelAxis[0]; dispAxes(1) = dirPixelAxis[1]; const casa::String units( RAD_UNITS.toStdString().c_str() ); try { casa::Quantum<casa::Vector<casa::Double> > qx( x, units ); casa::Quantum<casa::Vector<casa::Double> > qy( y, units ); casa::WCPolygon poly(qx, qy, casa::IPosition(dispAxes), cs); imageRegion = new casa::ImageRegion(poly); } catch( casa::AipsError& error ) { qDebug() << "Error making image region: "<<error.getMesg().c_str(); } } } } return imageRegion; }
QLineF::IntersectType getIntersection (const QLineF& l, const QPolygonF& p, QPointF* intersectPoint) { QPointF p1 = p.first(); QPointF p2; QLineF polyLine; for ( int i = 1; i < p.count(); ++i) { p2 = p.at(i); polyLine = QLineF( p1, p2); QLineF::IntersectType intersectType = polyLine.intersect( l, intersectPoint); if ( intersectType == QLineF::BoundedIntersection) { return QLineF::BoundedIntersection; } p1 = p2; } return QLineF::NoIntersection; }
QPolygonF bezier_fit_cubic_multi( const QPolygonF& data, double error, unsigned max_beziers ) { QPolygonF out(4*max_beziers); const int retn = sp_bezier_fit_cubic_r(out.data(), data.data(), data.count(), error, max_beziers); if( retn >= 0 ) { // get rid of unused points if( retn*4 < out.count() ) out.remove( retn*4, out.count()-retn*4 ); return out; } else return QPolygonF(); }
bool GraphicsUtils::isRect(const QPolygonF & poly) { if (poly.count() != 5) return false; if (poly.at(0) != poly.at(4)) return false; // either we start running across top or running along side if (poly.at(0).x() == poly.at(1).x() && poly.at(1).y() == poly.at(2).y() && poly.at(2).x() == poly.at(3).x() && poly.at(3).y() == poly.at(4).y()) return true; if (poly.at(0).y() == poly.at(1).y() && poly.at(1).x() == poly.at(2).x() && poly.at(2).y() == poly.at(3).y() && poly.at(3).x() == poly.at(4).x()) return true; return false; }
void ChartsView::refreshCharts() { if(!prepareCharts()){ sceneCharts->clear(); drawText(julyTr("CHARTS_WAITING_FOR_DATA","Waiting for data..."),0,0,"font-size:28px;color:"+baseValues.appTheme.gray.name()); return; } for(qint32 i=0;i<chartsModel->graphAmountY.count();i++){ drawRect(chartsModel->graphAmountX.at(i),chartsModel->graphAmountY.at(i)); } /*for(qint32 i=1;i<chartsModel->graphBoundsSellX.count();i++){ sceneCharts->addLine(chartsModel->graphBoundsSellX.at(i-1),chartsModel->graphBoundsSellY.at(i-1),chartsModel->graphBoundsSellX.at(i),chartsModel->graphBoundsSellY.at(i),QPen("#000000")); } for(qint32 i=1;i<chartsModel->graphBoundsBuyX.count();i++){ sceneCharts->addLine(chartsModel->graphBoundsBuyX.at(i-1),chartsModel->graphBoundsBuyY.at(i-1),chartsModel->graphBoundsBuyX.at(i),chartsModel->graphBoundsBuyY.at(i),QPen("#000000")); }*/ QPolygonF boundsPolygon; for(qint32 i=0;i<chartsModel->graphBoundsSellX.count();i++){ boundsPolygon << QPointF(chartsModel->graphBoundsSellX.at(i), chartsModel->graphBoundsSellY.at(i)); } for(qint32 i=chartsModel->graphBoundsBuyX.count()-1;i>=0;i--){ boundsPolygon << QPointF(chartsModel->graphBoundsBuyX.at(i), chartsModel->graphBoundsBuyY.at(i)); } if(boundsPolygon.count())sceneCharts->addPolygon(boundsPolygon,QPen("#4000FF00"),QBrush("#4000FF00")); if(chartsModel->graphTradesX.count()){ QPen pen; if(chartsModel->graphTradesType[0]==1)pen=QPen("#FF0000");else pen=QPen("#0000FF"); sceneCharts->addEllipse(chartsModel->graphTradesX.at(0)-2,chartsModel->graphTradesY.at(0)-2,4,4,pen); for(qint32 i=1;i<chartsModel->graphTradesX.count();i++){ if(chartsModel->graphTradesType[i]==1)pen=QPen("#FF0000");else pen=QPen("#0000FF"); sceneCharts->addLine(chartsModel->graphTradesX.at(i-1),chartsModel->graphTradesY.at(i-1),chartsModel->graphTradesX.at(i),chartsModel->graphTradesY.at(i),pen); sceneCharts->addEllipse(chartsModel->graphTradesX.at(i)-2,chartsModel->graphTradesY.at(i)-2,4,4,pen); } } }
static SIP_SSIZE_T slot_QPolygonF___len__(PyObject *sipSelf) { QPolygonF *sipCpp = reinterpret_cast<QPolygonF *>(sipGetCppPtr((sipSimpleWrapper *)sipSelf,sipType_QPolygonF)); if (!sipCpp) return 0; { { SIP_SSIZE_T sipRes = 0; #line 1 "Auto-generated" sipRes = (SIP_SSIZE_T)sipCpp->count(); #line 1472 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\QtGui/sipQtGuiQPolygonF.cpp" return sipRes; } } return 0; }
void GraphPolygonClipperF::clipEdge(Edge edge, const QPolygonF &pa, QPolygonF &cpa) const { if ( pa.count() == 0 ) { cpa.resize(0); return; } unsigned int count = 0; GraphDoublePoint p1 = pa[0]; if ( insideEdge(p1, edge) ) addPoint(cpa, count++, p1); const uint nPoints = pa.size(); for ( uint i = 1; i < nPoints; i++ ) { const GraphDoublePoint p2 = pa[(int)i]; if ( insideEdge(p2, edge) ) { if ( insideEdge(p1, edge) ) addPoint(cpa, count++, p2); else { addPoint(cpa, count++, intersectEdge(p1, p2, edge)); addPoint(cpa, count++, p2); } } else { if ( insideEdge(p1, edge) ) addPoint(cpa, count++, intersectEdge(p1, p2, edge)); } p1 = p2; } cpa.resize(count); }
/*! Fill the area between the curve and the baseline with the curve brush \param painter Painter \param xMap x map \param yMap y map \param polygon Polygon \sa setBrush(), setBaseline(), setCurveType() */ void QwtPlotCurve::fillCurve( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, QPolygonF &polygon ) const { if ( d_data->brush.style() == Qt::NoBrush ) return; closePolyline( painter, xMap, yMap, polygon ); if ( polygon.count() <= 2 ) // a line can't be filled return; QBrush b = d_data->brush; if ( !b.color().isValid() ) b.setColor( d_data->pen.color() ); painter->save(); painter->setPen( QPen( Qt::NoPen ) ); painter->setBrush( b ); QwtPainter::drawPolygon( painter, polygon ); painter->restore(); }
void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); if (polygon().isEmpty()) return; painter->save(); QPen mypen; mypen.setWidthF(vAxis->posAtValue(0) - vAxis->posAtValue(4)); mypen.setCosmetic(false); QPolygonF poly = polygon(); for (int i = 1, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) { if (i < poly.count()) { double value = dataModel->index(i, vDataColumn).data().toDouble(); int cyl = dataModel->index(i, DivePlotDataModel::CYLINDERINDEX).data().toInt(); int inert = 1000 - get_o2(&displayed_dive.cylinder[cyl].gasmix); mypen.setBrush(QBrush(ColorScale(value, inert))); painter->setPen(mypen); painter->drawLine(poly[i - 1], poly[i]); } } painter->restore(); }
void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*) { if (polygon().isEmpty()) return; painter->save(); QPen mypen; mypen.setCapStyle(Qt::FlatCap); mypen.setCosmetic(false); QPolygonF poly = polygon(); for (int i = 1, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) { if (i < poly.count()) { double value = dataModel->index(i, vDataColumn).data().toDouble(); struct gasmix gasmix = gasmix_air; const struct event *ev = NULL; int sec = dataModel->index(i, DivePlotDataModel::TIME).data().toInt(); gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix); int inert = 1000 - get_o2(gasmix); mypen.setBrush(QBrush(ColorScale(value, inert))); painter->setPen(mypen); painter->drawLine(poly[i - 1], poly[i]); } } painter->restore(); }
void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement ) { if ( points.isEmpty() ) return; QgsRenderContext& rc = context.renderContext(); double origAngle = mMarker->angle(); int i, maxCount; bool isRing = false; double offsetAlongLine = mOffsetAlongLine; QgsExpression* offsetAlongLineExpression = expression( "offset_along_line" ); if ( offsetAlongLineExpression ) { offsetAlongLine = offsetAlongLineExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } if ( offsetAlongLine != 0 ) { //scale offset along line offsetAlongLine *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( rc, mOffsetAlongLineUnit, mOffsetAlongLineMapUnitScale ); } if ( placement == FirstVertex ) { i = 0; maxCount = 1; } else if ( placement == LastVertex ) { i = points.count() - 1; maxCount = points.count(); } else { i = 0; maxCount = points.count(); if ( points.first() == points.last() ) isRing = true; } if ( offsetAlongLine > 0 && ( placement == FirstVertex || placement == LastVertex ) ) { double distance; distance = placement == FirstVertex ? offsetAlongLine : -offsetAlongLine; renderOffsetVertexAlongLine( points, i, distance, context ); // restore original rotation mMarker->setAngle( origAngle ); return; } for ( ; i < maxCount; ++i ) { if ( isRing && placement == Vertex && i == points.count() - 1 ) { continue; // don't draw the last marker - it has been drawn already } // rotate marker (if desired) if ( mRotateMarker ) { double angle = markerAngle( points, isRing, i ); mMarker->setAngle( origAngle + angle * 180 / M_PI ); } mMarker->renderPoint( points.at( i ), context.feature(), rc, -1, context.selected() ); } // restore original rotation mMarker->setAngle( origAngle ); }