First approach to plot quality
This commit is contained in:
+61
-39
@@ -27,6 +27,15 @@
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
Void PlotSubWindow::definePlotColors()
|
||||
{
|
||||
m_arrayColorList.append( Qt::blue );
|
||||
m_arrayColorList.append( Qt::red );
|
||||
m_arrayColorList.append( Qt::green );
|
||||
m_arrayColorList.append( Qt::black );
|
||||
m_arrayColorList.append( Qt::cyan );
|
||||
}
|
||||
|
||||
PlotSubWindow::PlotSubWindow( QWidget * parent ) :
|
||||
SubWindowHandle( parent, SubWindowHandle::PLOT_SUBWINDOW )
|
||||
{
|
||||
@@ -39,26 +48,6 @@ PlotSubWindow::PlotSubWindow( QWidget * parent ) :
|
||||
m_cPlotArea = new QCustomPlot( this );
|
||||
setWidget( m_cPlotArea );
|
||||
|
||||
Example();
|
||||
|
||||
}
|
||||
|
||||
Void PlotSubWindow::Example()
|
||||
{
|
||||
// add two new graphs and set their look:
|
||||
m_cPlotArea->addGraph();
|
||||
m_cPlotArea->graph( 0 )->setPen( QPen( Qt::blue ) ); // line color blue for first graph
|
||||
m_cPlotArea->graph( 0 )->setBrush( QBrush( QColor( 0, 0, 255, 20 ) ) ); // first graph will be filled with translucent blue
|
||||
m_cPlotArea->addGraph();
|
||||
m_cPlotArea->graph( 1 )->setPen( QPen( Qt::red ) ); // line color red for second graph
|
||||
// generate some points of data (y0 for first, y1 for second graph):
|
||||
QVector<double> x( 250 ), y0( 250 ), y1( 250 );
|
||||
for( int i = 0; i < 250; ++i )
|
||||
{
|
||||
x[i] = i;
|
||||
y0[i] = exp( -i / 150.0 ) * cos( i / 10.0 ); // exponentially decaying cosine
|
||||
y1[i] = exp( -i / 150.0 ); // exponential envelope
|
||||
}
|
||||
// configure right and top axis to show ticks but no labels:
|
||||
// (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
|
||||
m_cPlotArea->xAxis2->setVisible( true );
|
||||
@@ -68,19 +57,30 @@ Void PlotSubWindow::Example()
|
||||
// make left and bottom axes always transfer their ranges to right and top axes:
|
||||
connect( m_cPlotArea->xAxis, SIGNAL( rangeChanged(QCPRange) ), m_cPlotArea->xAxis2, SLOT( setRange(QCPRange) ) );
|
||||
connect( m_cPlotArea->yAxis, SIGNAL( rangeChanged(QCPRange) ), m_cPlotArea->yAxis2, SLOT( setRange(QCPRange) ) );
|
||||
// pass data points to graphs:
|
||||
m_cPlotArea->graph( 0 )->setData( x, y0 );
|
||||
m_cPlotArea->graph( 1 )->setData( x, y1 );
|
||||
// let the ranges scale themselves so graph 0 fits perfectly in the visible area:
|
||||
m_cPlotArea->graph( 0 )->rescaleAxes();
|
||||
// same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
|
||||
m_cPlotArea->graph( 1 )->rescaleAxes( true );
|
||||
// Note: we could have also just called m_cPlotArea->rescaleAxes(); instead
|
||||
// Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
|
||||
|
||||
definePlotColors();
|
||||
m_uiNumberPlots = 0;
|
||||
|
||||
m_cPlotArea->setInteractions( QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables );
|
||||
|
||||
}
|
||||
|
||||
Void PlotSubWindow::Example()
|
||||
{
|
||||
// generate some points of data (y0 for first, y1 for second graph):
|
||||
QVector<double> x( 250 ), y0( 250 ), y1( 250 );
|
||||
for( int i = 0; i < 250; ++i )
|
||||
{
|
||||
x[i] = i;
|
||||
y0[i] = exp( -i / 150.0 ) * cos( i / 10.0 ); // exponentially decaying cosine
|
||||
y1[i] = exp( -i / 150.0 ); // exponential envelope
|
||||
}
|
||||
|
||||
addPlot( x, y0 );
|
||||
addPlot( x, y1 );
|
||||
|
||||
}
|
||||
|
||||
PlotSubWindow::~PlotSubWindow()
|
||||
{
|
||||
delete m_cPlotArea;
|
||||
@@ -106,15 +106,37 @@ Void PlotSubWindow::scaleView( Double scale, QPoint center )
|
||||
|
||||
}
|
||||
|
||||
//QSize PlotSubWindow::sizeHint() const
|
||||
//{
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
//QSize PlotSubWindow::sizeHint( const QSize & maxSize ) const
|
||||
//{
|
||||
//
|
||||
//}
|
||||
QSize PlotSubWindow::sizeHint() const
|
||||
{
|
||||
QSize maxSize;
|
||||
QWidget *p = parentWidget();
|
||||
if( p )
|
||||
{
|
||||
maxSize = p->size();
|
||||
}
|
||||
else
|
||||
{
|
||||
maxSize = QApplication::desktop()->availableGeometry().size();
|
||||
}
|
||||
return sizeHint( maxSize );
|
||||
}
|
||||
|
||||
QSize PlotSubWindow::sizeHint( const QSize & maxSize ) const
|
||||
{
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
Void PlotSubWindow::addPlot( const QVector<Double> &key, const QVector<Double> &value )
|
||||
{
|
||||
QCPGraph *newPlot = m_cPlotArea->addGraph();
|
||||
newPlot->setPen( QPen( m_arrayColorList.at( m_uiNumberPlots ) ) ); // line color blue for first graph
|
||||
newPlot->setBrush( QBrush( QColor( 0, 0, 255, 20 ) ) ); // first graph will be filled with translucent blue
|
||||
// pass data points to graphs:
|
||||
newPlot->setData( key, value );
|
||||
// let the ranges scale themselves so graph 0 fits perfectly in the visible area:
|
||||
newPlot->rescaleAxes( m_uiNumberPlots > 1 ? true : false );
|
||||
|
||||
m_uiNumberPlots++;
|
||||
}
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user