/** * This is a helper method to create new band markers with the same line * style and a custom color. * * @param color The color of the band marker * @return The requested plot marker; ownership is passed to the caller */ QwtPlotMarker *SpectralPlotWindow::createMarker(QColor color) { QPen markerPen(color); markerPen.setWidth(1); QwtPlotMarker *newMarker = new QwtPlotMarker; newMarker->setLineStyle(QwtPlotMarker::LineStyle(2)); newMarker->setLinePen(markerPen); newMarker->attach(plot()); newMarker->setVisible(false); return newMarker; }
void Plot::populate() { GridItem *gridItem = new GridItem(); #if 0 gridItem->setOrientations( Qt::Horizontal ); #endif gridItem->attach( this ); const Qt::GlobalColor colors[] = { Qt::red, Qt::blue, Qt::darkCyan, Qt::darkMagenta, Qt::darkYellow }; const int numColors = sizeof( colors ) / sizeof( colors[0] ); for ( int i = 0; i < QuoteFactory::NumStocks; i++ ) { QuoteFactory::Stock stock = static_cast<QuoteFactory::Stock>( i ); QwtPlotTradingCurve *curve = new QwtPlotTradingCurve(); curve->setTitle( QuoteFactory::title( stock ) ); curve->setOrientation( Qt::Vertical ); curve->setSamples( QuoteFactory::samples2010( stock ) ); // as we have one sample per day a symbol width of // 12h avoids overlapping symbols. We also bound // the width, so that is is not scaled below 3 and // above 15 pixels. curve->setSymbolExtent( 12 * 3600 * 1000.0 ); curve->setMinSymbolWidth( 3 ); curve->setMaxSymbolWidth( 15 ); const Qt::GlobalColor color = colors[ i % numColors ]; curve->setSymbolPen( color ); curve->setSymbolBrush( QwtPlotTradingCurve::Decreasing, color ); curve->setSymbolBrush( QwtPlotTradingCurve::Increasing, Qt::white ); curve->attach( this ); showItem( curve, true ); } for ( int i = 0; i < 2; i++ ) { QwtPlotMarker *marker = new QwtPlotMarker(); marker->setTitle( QString( "Event %1" ).arg( i + 1 ) ); marker->setLineStyle( QwtPlotMarker::VLine ); marker->setLinePen( colors[ i % numColors ], 0, Qt::DashLine ); marker->setVisible( false ); QDateTime dt( QDate( 2010, 1, 1 ) ); dt = dt.addDays( 77 * ( i + 1 ) ); marker->setValue( QwtDate::toDouble( dt ), 0.0 ); marker->setItemAttribute( QwtPlotItem::Legend, true ); marker->attach( this ); } // to show how QwtPlotZoneItem works ZoneItem *zone1 = new ZoneItem( "Zone 1"); zone1->setColor( Qt::darkBlue ); zone1->setInterval( QDate( 2010, 3, 10 ), QDate( 2010, 3, 27 ) ); zone1->setVisible( false ); zone1->attach( this ); ZoneItem *zone2 = new ZoneItem( "Zone 2"); zone2->setColor( Qt::darkMagenta ); zone2->setInterval( QDate( 2010, 8, 1 ), QDate( 2010, 8, 24 ) ); zone2->setVisible( false ); zone2->attach( this ); }