QwtPlotShapeItem* Editor::itemAt( const QPoint& pos ) const { const QwtPlot *plot = this->plot(); if ( plot == NULL ) return NULL; // translate pos into the plot coordinates double coords[ QwtPlot::axisCnt ]; coords[ QwtPlot::xBottom ] = plot->canvasMap( QwtPlot::xBottom ).invTransform( pos.x() ); coords[ QwtPlot::xTop ] = plot->canvasMap( QwtPlot::xTop ).invTransform( pos.x() ); coords[ QwtPlot::yLeft ] = plot->canvasMap( QwtPlot::yLeft ).invTransform( pos.y() ); coords[ QwtPlot::yRight ] = plot->canvasMap( QwtPlot::yRight ).invTransform( pos.y() ); QwtPlotItemList items = plot->itemList(); for ( int i = items.size() - 1; i >= 0; i-- ) { QwtPlotItem *item = items[ i ]; if ( item->isVisible() && item->rtti() == QwtPlotItem::Rtti_PlotShape ) { QwtPlotShapeItem *shapeItem = static_cast<QwtPlotShapeItem *>( item ); const QPointF p( coords[ item->xAxis() ], coords[ item->yAxis() ] ); if ( shapeItem->boundingRect().contains( p ) && shapeItem->shape().contains( p ) ) { return shapeItem; } } } return NULL; }
void Plot::addShape( const QString &title, ShapeFactory::Shape shape, const QColor &color, const QPointF &pos, const QSizeF &size ) { QwtPlotShapeItem *item = new QwtPlotShapeItem( title ); item->setItemAttribute( QwtPlotItem::Legend, true ); item->setLegendMode( QwtPlotShapeItem::LegendShape ); item->setLegendIconSize( QSize( 20, 20 ) ); item->setRenderHint( QwtPlotItem::RenderAntialiased, true ); item->setShape( ShapeFactory::path( shape, pos, size ) ); QColor fillColor = color; fillColor.setAlpha( 200 ); QPen pen( color, 3 ); pen.setJoinStyle( Qt::MiterJoin ); item->setPen( pen ); item->setBrush( fillColor ); item->attach( this ); }
void Plot::populate() { const double d = 900.0; const QRectF rect( 1.0, 1.0, d, d ); QPainterPath path; //path.setFillRule( Qt::WindingFill ); path.addEllipse( rect ); const QRectF rect2 = rect.adjusted( 0.2 * d, 0.3 * d, -0.22 * d, 1.5 * d ); path.addEllipse( rect2 ); #if 0 QFont font; font.setPointSizeF( 200 ); QPainterPath textPath; textPath.addText( rect.center(), font, "Seppi" ); QTransform transform; transform.translate( rect.center().x() - 600, rect.center().y() + 50 ); transform.rotate( 180.0, Qt::XAxis ); textPath = transform.map( textPath ); path.addPath( textPath ); #endif QwtPlotShapeItem *item = new QwtPlotShapeItem( "Shape" ); item->setItemAttribute( QwtPlotItem::Legend, true ); item->setRenderHint( QwtPlotItem::RenderAntialiased, true ); #if 1 item->setRenderTolerance( 1.0 ); #endif item->setShape( path ); item->setPen( Qt::yellow ); QColor c = Qt::darkRed; c.setAlpha( 100 ); item->setBrush( c ); item->attach( this ); }