Esempio n. 1
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QwtPlot plot;
    plot.setCanvasBackground(QColor(Qt::white));
    plot.setTitle("Bar Chart");

	QwtPlotGrid *grid = new QwtPlotGrid;
	grid->enableX(false);
	grid->enableYMin(true);
	grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
	grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
	grid->attach(&plot);

	BarChartItem *item = new BarChartItem();
	item->attach(&plot);
	QList< QPair<int, QString> > barHeights;
	barHeights.append(QPair<int, QString>(10, ""));
	barHeights.append(QPair<int, QString>(100, ""));
	barHeights.append(QPair<int, QString>(20, ""));
	item->setData(barHeights);

	plot.enableAxis(QwtPlot::xBottom, false);

	plot.resize(600, 400);
	plot.show();

	return app.exec();
}
Esempio n. 2
0
void HistPlot::populate()
{
	setTitle("Watching TV during a weekend");
	setAxisTitle(QwtPlot::yLeft, "Number of People");
	setAxisTitle(QwtPlot::xBottom, "Number of Hours");

	QwtPlotGrid *grid = new QwtPlotGrid;
	grid->enableX(false);
	grid->enableY(true);
	grid->enableXMin(false);
	grid->enableYMin(false);
	grid->setMajPen(QPen(Qt::black, 0, Qt::SolidLine));
	grid->attach(this);

	const double juneValues[] = { 7, 19, 24, 32, 10, 5, 3 };
	const double novemberValues[] = { 4, 15, 22, 34, 13, 8, 4 };

	Histogram *histogramJune = new Histogram("Summer", Qt::red);
	histogramJune->setValues(
		sizeof(juneValues) / sizeof(double), juneValues);
	histogramJune->attach(this);

	Histogram *histogramNovember = new Histogram("Winter", Qt::blue);
	histogramNovember->setValues(
		sizeof(novemberValues) / sizeof(double), novemberValues);
	histogramNovember->attach(this);
}
Esempio n. 3
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    setAutoFillBackground( true );
    setPalette( Qt::darkGray );
    setCanvasBackground( Qt::white );

    plotLayout()->setAlignCanvasToScales( true );

    initAxis( QwtAxis::yLeft, "Local Time", Qt::LocalTime );
    initAxis( QwtAxis::yRight, 
        "Coordinated Universal Time ( UTC )", Qt::UTC );

    QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
    QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas() );

    for ( int axis = 0; axis < QwtAxis::PosCount; axis++ )
    {
        const bool on = QwtAxis::isYAxis( axis );

        setAxisVisible( axis, on );
        panner->setAxisEnabled( axis, on );
        magnifier->setAxisEnabled( axis, on );
    }

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setMajorPen( Qt::black, 0, Qt::SolidLine );
    grid->setMinorPen( Qt::gray, 0 , Qt::SolidLine );
    grid->enableX( false );
    grid->enableXMin( false );
    grid->enableY( true );
    grid->enableYMin( true );

    grid->attach( this );
}
Esempio n. 4
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent ),
    d_curve( NULL )
{
    /*canvas()->setStyleSheet(
        "border: 2px solid Black;"
        "border-radius: 15px;"
        "background-color: qlineargradient( x1: 0, y1: 0, x2: 0, y2: 1,"
            "stop: 0 LemonChiffon, stop: 1 PaleGoldenrod );"
    );*/
    //QwtPlotCanvas *newcanvas=new QwtPlotCanvas();
    //newcanvas->setPalette(Qt::white);
    //newcanvas->setBorderRadius(10);
    //setCanvas( newcanvas );
    //plotLayout()->setAlignCanvasToScales( true );
    setAxisTitle( QwtPlot::yLeft, "ylabel" );
    setAxisTitle( QwtPlot::xBottom, "xlabel" );
    //setAxisScale(QwtPlot::yLeft,0.0,25.0);
    //setAxisScale(QwtPlot::xBottom,0.0,25.0);
    //canvas()->resize(800, 600);
    //plotLayout(AlignScales);
    // attach curve
    d_curve = new QwtPlotCurve( "Scattered Points" );
    d_curve->setPen( QColor( "Black" ) );
//    d_curve->setCurveAttribute(fitten);
    // when using QwtPlotCurve::ImageBuffer simple dots can be
    // rendered in parallel on multicore systems.
    d_curve->setRenderThreadCount( 0 ); // 0: use QThread::idealThreadCount()

    //d_curve->setCurveAttribute(QwtPlotCurve::Fitted, true);

    d_curve->attach( this );

    QwtSymbol * symbol2 = new QwtSymbol( QwtSymbol::XCross, QBrush(Qt::white), QPen(Qt::red, 1), QSize(6,6));
    //QwtSymbol::Style  style = Cross;
    setSymbol( symbol2 );
    //setSymbol(NULL);

    // panning with the left mouse button
    (void )new QwtPlotPanner( canvas() );

    // zoom in/out with the wheel
    QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas() );
    magnifier->setMouseButton( Qt::NoButton );

    // distanve measurement with the right mouse button
    DistancePicker *picker = new DistancePicker( canvas() );
    picker->setMousePattern( QwtPlotPicker::MouseSelect1, Qt::RightButton );
    picker->setRubberBandPen( QPen( Qt::blue ) );

    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->enableX( true );//设置网格线
    grid->enableY( true );
    grid->setMajorPen( Qt::black, 0, Qt::DotLine );
    grid->attach( this );

    //QSize sizeH = sizeHint();

}
Esempio n. 5
0
Plot::Plot(QWidget *parent):
    QwtPlot(parent),
    d_paintedPoints(0),
    d_interval(0.0, 10.0),
    d_timerId(-1)
{
    d_directPainter = new QwtPlotDirectPainter();

    setAutoReplot(false);

    // We don't need the cache here
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    //canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);


#if defined(Q_WS_X11)
    // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
    // works on X11. This has a nice effect on the performance.
    
    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
#endif

    plotLayout()->setAlignCanvasToScales(true);

    setAxisTitle(QwtPlot::xBottom, "Time [s]");
    setAxisScale(QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue()); 
    setAxisScale(QwtPlot::yLeft, -200.0, 200.0);

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine));
    grid->enableX(true);
    grid->enableXMin(true);
    grid->enableY(true);
    grid->enableYMin(false);
    grid->attach(this);

    d_origin = new QwtPlotMarker();
    d_origin->setLineStyle(QwtPlotMarker::Cross);
    d_origin->setValue(d_interval.minValue() + d_interval.width() / 2.0, 0.0);
    d_origin->setLinePen(QPen(Qt::gray, 0.0, Qt::DashLine));
    d_origin->attach(this);

    d_curve = new QwtPlotCurve();
    d_curve->setStyle(QwtPlotCurve::Lines);
    d_curve->setPen(QPen(Qt::green));
#if 1
    d_curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
#endif
#if 1
    d_curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
#endif
    d_curve->setData(new CurveData());
    d_curve->attach(this);
}
void GenericHistogramView::populate()
{
  QwtPlotGrid* grid = new QwtPlotGrid();
  grid->enableX(false);
  grid->enableY(true);
  grid->enableXMin(false);
  grid->enableYMin(false);
  grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
  grid->attach(_qwtPlot);

	for(unsigned int i = 0; i < _image->getNbChannels(); ++i)
	{
		imagein::Array<unsigned int>* histogram;
		if(_projection)
			histogram = new imagein::ProjectionHistogram(*_image, _value, _horizontal, *_rectangle, i);
		else
			histogram = new imagein::Histogram(*_image, i, *_rectangle);
		
		int values[histogram->getWidth()];

		for(unsigned int j = 0; j < histogram->getWidth(); ++j)
			values[j] = (*histogram)[j];
		
		GraphicalHistogram* graphicalHisto;
		switch(i)
		{
			case 0:
				if(_image->getNbChannels() == 1 || _image->getNbChannels() == 2)
					graphicalHisto = new GraphicalHistogram("Black", Qt::black);
				else
					graphicalHisto = new GraphicalHistogram("Red", Qt::red);
			break;
			case 1:
				if(_image->getNbChannels() == 1 || _image->getNbChannels() == 2)
					graphicalHisto = new GraphicalHistogram("Alpha", Qt::white);
				else
					graphicalHisto = new GraphicalHistogram("Green", Qt::green);
			break;
			case 2:
				graphicalHisto = new GraphicalHistogram("Blue", Qt::blue);
			break;
			case 3:
				graphicalHisto = new GraphicalHistogram("Alpha", Qt::black);
			break;
			default:
				graphicalHisto = new GraphicalHistogram("Default", Qt::black);
		}
		graphicalHisto->setValues(sizeof(values) / sizeof(int), values);
		if(_horizontal)
			graphicalHisto->setOrientation(Qt::Horizontal);
		graphicalHisto->attach(_qwtPlot);
    _graphicalHistos.push_back(graphicalHisto);
	}
}
Esempio n. 7
0
void AnalogGraph::populate()
{
    QwtPlotGrid *grid = new QwtPlotGrid;

    grid->enableX(false);
    grid->enableY(false);
    grid->enableXMin(false);
    grid->enableYMin(false);
    grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));

    grid->attach(this);

    analogHistogram_ = new Histogram("", QColor(80, 180, 220, 150));
    //analogHistogram_->setValues(analogChannels_);
    analogHistogram_->attach(this);
}
void panelControlMotor::chartSetting()
{
    QwtPlotGrid *grid = new QwtPlotGrid();
    ui->chartTemp->setAutoReplot(true);

    grid->setMinorPen(QPen(Qt::gray, 0, Qt::DotLine));
    grid->setMajorPen(QPen(Qt::gray, 0, Qt::DotLine));
    grid->enableX(true);
    grid->enableY(true);
    grid->attach(ui->chartTemp);

    temperature = new QwtPlotCurve();
    temperature->setTitle("temperature");
    temperature->setPen(Qt::black, 2, Qt::SolidLine);
    temperature->setRenderHint(QwtPlotItem::RenderAntialiased, true);
    temperature->attach(ui->chartTemp);
}
Esempio n. 9
0
void ICResultChart::populate()
{
    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->enableX( false );
    grid->enableY( true );
    grid->enableXMin( false );
    grid->enableYMin( false );
    grid->setMajorPen( Qt::black, 0, Qt::DotLine );
    grid->attach( this );

    QColor color = Qt::blue;
    color.setAlpha(180);

    QwtColumnSymbol *symbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
    symbol->setLineWidth(2);
    symbol->setFrameStyle(QwtColumnSymbol::Raised);
    symbol->setPalette(QPalette(color));

    d_barChartItem->setSymbol(symbol);

    QVector<double> samples;

    QMap<QString, int>::const_iterator i = result.constBegin();
    while (i != result.constEnd()) {
        samples.append(i.value());
        ++i;
    }

    d_barChartItem->setSamples(samples);

    double k = (0.0 + SPACING_RATIO) / MARGIN_RATIO;

    double m = (0.0 + WINDOW_WIDTH - BAR_WIDTH) / (2 + k * (result.size() - 1));
    int margin = static_cast<int>(m);
    int spacing = static_cast<int>(m * k);

    if (spacing < MIN_SPACING) spacing = MIN_SPACING;
    if (margin < MIN_MARGIN) margin = MIN_MARGIN;

    d_barChartItem->setSpacing(spacing);
    d_barChartItem->setMargin(100);
    //d_barChartItem->setLayoutPolicy(QwtPlotAbstractBarChart::FixedSampleSize);
    //d_barChartItem->setLayoutHint(BAR_WIDTH);

}
Esempio n. 10
0
void HistPlot::setValueHist(const vector<double>& histogram, int origin)
{
	setTitle("Histogram");
	setAxisTitle(QwtPlot::yLeft, "Count");
	setAxisTitle(QwtPlot::xBottom, "Value");

	QwtPlotGrid *grid = new QwtPlotGrid;
	grid->enableX(false);
	grid->enableY(true);
	grid->enableXMin(false);
	grid->enableYMin(false);
	grid->setMajPen(QPen(Qt::darkGreen, 0, Qt::SolidLine));
	grid->attach(this);

	Histogram *histogramJune = new Histogram("Summer", Qt::red);
	histogramJune->setValues(
		histogram.size(), &histogram[0], origin);
	histogramJune->attach(this);
}
PowerBarHistoryPlot::PowerBarHistoryPlot(double defaultTime, double defaultPowerLevel, QWidget* parent)
	: QWidget(parent)
	, m_overalTime(0.0)
	, m_lastSampleTime(0.0)
	, m_firstTime(true)
	, m_defaultTime(defaultTime)
	, m_defaultPowerLevel(defaultPowerLevel)
	, m_powerAxisMax(defaultPowerLevel)
	, m_powerAxisMin(-1*defaultPowerLevel)
	, m_timeAxisMax(defaultTime)
{
	m_plot = new QwtPlot();
	m_plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
	m_plot->setAxisScale(QwtPlot::xBottom, 0, defaultTime, defaultTime/20.0);
	m_plot->setAxisScale(QwtPlot::yLeft, -1 * defaultPowerLevel, defaultPowerLevel, defaultPowerLevel/2.0);
	m_plot->setAxisAutoScale(QwtPlot::xBottom, false);
	m_plot->setCanvasBackground(QBrush(Qt::white));
	m_plot->setAxisTitle(QwtPlot::xBottom, tr(TIME_AXIS_NAME));
	m_plot->setAxisTitle(QwtPlot::yLeft, tr(POWER_AXIS_NAME));
	
	// legend
	QwtLegend *legend = new QwtLegend;
	legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
	m_plot->insertLegend(legend, QwtPlot::BottomLegend);

	QwtPlotGrid *grid = new QwtPlotGrid;
	grid->enableX(false);
	grid->enableYMin(true);
	grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
	grid->setMinPen(QPen(Qt::transparent, 0 , Qt::NoPen));
	grid->attach(m_plot);

	setupCurves();

	QHBoxLayout* historyPlotlayout = new QHBoxLayout;
	historyPlotlayout->addWidget(m_plot);
	historyPlotlayout->setSpacing(0);

	setColors(Qt::blue, Qt::red);

	setLayout(historyPlotlayout);
}
Esempio n. 12
0
Spectrograph::Spectrograph(QWidget *parent):
    QwtPlot(parent)
{
    //real-time plotting
    d_directPainter = new QwtPlotDirectPainter();

    setAutoReplot( false );
    //all plot widgets will be displayed on the canvas
    setCanvas( new QwtPlotCanvas() );

    plotLayout()->setAlignCanvasToScales( true );
    //set plot title and range
    setAxisTitle( QwtPlot::xBottom, "Frequency (MHz)" );
    setAxisTitle( QwtPlot::yLeft, "Amplitude (dB)" );
    setAxisScale( QwtPlot::xBottom, 0, RESULT_LENGTH );
    setAxisScale( QwtPlot::yLeft, -90, -10);

    //black background
    setCanvasBackground(QColor(0,0,0));

    //add grid
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen( Qt::white, 0.0, Qt::DotLine );
    grid->enableX( true );
    grid->enableXMin( true );
    grid->enableY( true );
    grid->enableYMin( false );
    grid->attach( this );//attach grid to plot

    //add curve
    d_curve = new QwtPlotCurve();
    d_curve->setStyle( QwtPlotCurve::Lines );
    d_curve->setPen(Qt::yellow);
    d_curve->setPaintAttribute( QwtPlotCurve::ClipPolygons, false );
    d_curve->attach( this );//attach curve to plot

    for(int i=0; i<RESULT_LENGTH; ++i) {
        d_x[i] = i;
    }

}
OscilloscopePlot::OscilloscopePlot( QWidget *parent ):
    QwtPlot( parent ),
    d_paintedPoints( 0 ),
    d_interval( 0.0, 10.0 ),
    d_timerId( -1 )
{
    d_directPainter = new QwtPlotDirectPainter();

    setAutoReplot( false );
    setCanvas( new Canvas() );

    plotLayout()->setAlignCanvasToScales( true );

    setAxisTitle( QwtPlot::xBottom, "Time [s]" );
    setAxisScale( QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue() );
    setAxisScale( QwtPlot::yLeft, -200.0, 200.0 );

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen( Qt::gray, 0.0, Qt::DotLine );
    grid->enableX( true );
    grid->enableXMin( true );
    grid->enableY( true );
    grid->enableYMin( false );
    grid->attach( this );

    d_origin = new QwtPlotMarker();
    d_origin->setLineStyle( QwtPlotMarker::Cross );
    d_origin->setValue( d_interval.minValue() + d_interval.width() / 2.0, 0.0 );
    d_origin->setLinePen( Qt::gray, 0.0, Qt::DashLine );
    d_origin->attach( this );

    d_curve = new QwtPlotCurve();
    d_curve->setStyle( QwtPlotCurve::Lines );
    d_curve->setPen( canvas()->palette().color( QPalette::WindowText ) );
    d_curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    d_curve->setPaintAttribute( QwtPlotCurve::ClipPolygons, false );
    d_curve->setData( new CurveData() );
    d_curve->attach( this );
}
Esempio n. 14
0
Osc::Osc( QWidget * parent )
: QwtPlot( parent )
{
    COscScaler * scaler = new COscScaler( this );
    scaler->setWheelZoomX( true );
    scaler->setWheelZoomY( true );
    scaler->setEqualScales( false );
    scaler->setSaveScales( false );

    QwtPlotGrid * g = new QwtPlotGrid();
    g->enableXMin( true );
    g->enableYMin( true );
    g->setPen( QPen( Qt::gray, 0.0, Qt::DotLine ) );
    g->attach( this );

    g = new QwtPlotGrid();
    g->enableX( true );
    g->enableY( true );
    g->setPen( QPen( Qt::gray, 0.0, Qt::SolidLine ) );
    g->attach( this );

    canvas()->setBorderRadius( 10 );
    plotLayout()->setAlignCanvasToScales( true );

    // Nice background coloration.
    QPalette pal = canvas()->palette();
    QLinearGradient gr( 0.0, 0.0, 1.0, 1.0 );
    gr.setCoordinateMode( QGradient::StretchToDeviceMode );
    gr.setColorAt( 0.0, QColor( 200, 200, 230 ) );
    gr.setColorAt( 1.0, QColor( 230, 230, 250 ) );
    pal.setBrush( QPalette::Window, QBrush( gr ) );
    canvas()->setPalette( pal );
    canvas()->setBorderRadius( 10 );
    plotLayout()->setAlignCanvasToScales( true );

    m_timer = new QTimer( this );
    connect( m_timer, SIGNAL(timeout()), this, SIGNAL(timeout()) );
}
Esempio n. 15
0
void Histograma::populate(QImage *img)
{
    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->enableX(false);
    grid->enableY(true);
    grid->enableXMin(true);
    grid->enableYMin(true);
    grid->setMajorPen(QPen(Qt::black, 0, Qt::DotLine));
    grid->setMinorPen(QPen(Qt::gray, 0, Qt::DotLine));
    grid->attach(this);

    int cinza, mQtd = 0;
    int x, y;
    // Quantidade de pontos de 0 a 255
    const int pts = 256;

    QVector<float> valores(pts);

    // inicializa os valores com 0
    for (int i = 0; i < pts; i++)
            valores[i] = 0.0;

    for (x = 0; x < img->width(); x++) {
        for (y = 0; y < img->height(); y++) {
            cinza = qGray(img->pixel(QPoint(x,y)));
            valores[cinza]++;

            if (valores[cinza] > mQtd)
                mQtd = valores[cinza];
        }
    }

    Histogram *hist = new Histogram("", Qt::black);
    hist->setValues(pts, &valores);

    hist->attach(this);
    this->replot();
}
Esempio n. 16
0
void TVPlot::populate()
{
    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->enableX( false );
    grid->enableY( true );
    grid->enableXMin( false );
    grid->enableYMin( false );
    grid->setMajorPen( Qt::black, 0, Qt::DotLine );
    grid->attach( this );

    const double juneValues[] = { 7, 19, 24, 32, 10, 5, 3 };
    const double novemberValues[] = { 4, 15, 22, 34, 13, 8, 4 };

    Histogram *histogramJune = new Histogram( "Summer", Qt::red );
    histogramJune->setValues(
        sizeof( juneValues ) / sizeof( double ), juneValues );
    histogramJune->attach( this );

    Histogram *histogramNovember = new Histogram( "Winter", Qt::blue );
    histogramNovember->setValues(
        sizeof( novemberValues ) / sizeof( double ), novemberValues );
    histogramNovember->attach( this );
}
Esempio n. 17
0
Plot::Plot(QWidget *parent):
    QwtPlot(parent),
    d_paintedPoints0(0),
    d_paintedPoints1(0),
    d_interval(0.0, 25.0),
    d_timerId(-1)
{
    d_directPainter0 = new QwtPlotDirectPainter();

    setAutoReplot(false);

    canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false);


#if defined(Q_WS_X11)
    
    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);

    if ( canvas()->testPaintAttribute( QwtPlotCanvas::BackingStore ) )
    {
        canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
        canvas()->setAttribute(Qt::WA_NoSystemBackground, true);
    }

#endif

    initGradient();

    plotLayout()->setAlignCanvasToScales(true);

    setAxisTitle(QwtPlot::xBottom, "Time [s]");
    setAxisScale(QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue()); 
    setAxisScale(QwtPlot::yLeft, 0, 10.0);

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen(QPen(Qt::green, 0.0, Qt::DotLine));
    grid->enableX(true);
    grid->enableXMin(true);
    grid->enableY(true);
    grid->enableYMin(false);
    grid->attach(this);

    d_origin = new QwtPlotMarker();
    d_origin->setLineStyle(QwtPlotMarker::Cross);
    d_origin->setValue(d_interval.minValue() + d_interval.width() / 2.0, 0.0);
    d_origin->setLinePen(QPen(Qt::red, 0.0, Qt::DashLine));
    d_origin->attach(this);

    d_curve0 = new QwtPlotCurve();
    d_curve0->setStyle(QwtPlotCurve::Lines);
    d_curve0->setPen(QPen(Qt::green,3));
#if 1
    d_curve0->setRenderHint(QwtPlotItem::RenderAntialiased, true);
#endif
#if 1
    d_curve0->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
#endif
    d_curve0->setData(new CurveData());
    d_curve0->attach(this);

    d_curve1 = new QwtPlotCurve();
    d_curve1->setStyle(QwtPlotCurve::Lines);
    d_curve1->setPen(QPen(Qt::red,3));
#if 1
    d_curve1->setRenderHint(QwtPlotItem::RenderAntialiased, true);
#endif
#if 1
    d_curve1->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
#endif
    d_curve1->setData(new CurveData());
    d_curve1->attach(this);
}
Esempio n. 18
0
void QgsHistogramWidget::drawHistogram()
{
  // clear plot
  mpPlot->detachItems();

  //ensure all children get removed
  mpPlot->setAutoDelete( true );
  // Set axis titles
  if ( !mXAxisTitle.isEmpty() )
    mpPlot->setAxisTitle( QwtPlot::xBottom, mXAxisTitle );
  if ( !mYAxisTitle.isEmpty() )
    mpPlot->setAxisTitle( QwtPlot::yLeft, mYAxisTitle );
  mpPlot->setAxisFont( QwtPlot::xBottom, this->font() );
  mpPlot->setAxisFont( QwtPlot::yLeft, this->font() );
  QFont titleFont = this->font();
  titleFont.setBold( true );
  QwtText xAxisText = mpPlot->axisTitle( QwtPlot::xBottom );
  xAxisText.setFont( titleFont );
  mpPlot->setAxisTitle( QwtPlot::xBottom, xAxisText );
  QwtText yAxisText = mpPlot->axisTitle( QwtPlot::yLeft );
  yAxisText.setFont( titleFont );
  mpPlot->setAxisTitle( QwtPlot::yLeft, yAxisText );
  mpPlot->setAxisAutoScale( QwtPlot::yLeft );
  mpPlot->setAxisAutoScale( QwtPlot::xBottom );

  // add a grid
  QwtPlotGrid *grid = new QwtPlotGrid();
  grid->enableX( false );
  grid->setPen( mGridPen );
  grid->attach( mpPlot );

  // make colors list
  mHistoColors.clear();
  Q_FOREACH ( const QgsRendererRange &range, mRanges )
  {
    mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black );
  }

  //draw histogram
  QwtPlotHistogram *plotHistogram = nullptr;
  plotHistogram = createPlotHistogram( !mRanges.isEmpty() ? mRanges.at( 0 ).label() : QString(),
                                       !mRanges.isEmpty() ? QBrush( mHistoColors.at( 0 ) ) : mBrush,
                                       !mRanges.isEmpty() ? Qt::NoPen : mPen );
  QVector<QwtIntervalSample> dataHisto;

  int bins = mBinsSpinBox->value();
  QList<double> edges = mHistogram.binEdges( bins );
  QList<int> counts = mHistogram.counts( bins );

  int rangeIndex = 0;
  int lastValue = 0;

  for ( int bin = 0; bin < bins; ++bin )
  {
    int binValue = counts.at( bin );

    //current bin crosses two graduated ranges, so we split between
    //two histogram items
    if ( rangeIndex < mRanges.count() - 1 && edges.at( bin ) > mRanges.at( rangeIndex ).upperValue() )
    {
      rangeIndex++;
      plotHistogram->setSamples( dataHisto );
      plotHistogram->attach( mpPlot );
      plotHistogram = createPlotHistogram( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) );
      dataHisto.clear();
      dataHisto << QwtIntervalSample( lastValue, mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) );
    }

    double upperEdge = !mRanges.isEmpty() ? qMin( edges.at( bin + 1 ), mRanges.at( rangeIndex ).upperValue() )
                       : edges.at( bin + 1 );

    dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge );

    lastValue = binValue;
  }

  plotHistogram->setSamples( dataHisto );
  plotHistogram->attach( mpPlot );

  mRangeMarkers.clear();
  Q_FOREACH ( const QgsRendererRange &range, mRanges )
  {
    QwtPlotMarker *rangeMarker = new QwtPlotMarker();
    rangeMarker->attach( mpPlot );
    rangeMarker->setLineStyle( QwtPlotMarker::VLine );
    rangeMarker->setXValue( range.upperValue() );
    rangeMarker->setLabel( QString::number( range.upperValue() ) );
    rangeMarker->setLabelOrientation( Qt::Vertical );
    rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
    rangeMarker->show();
    mRangeMarkers << rangeMarker;
  }
Esempio n. 19
0
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{
    // create menu bar and actions
    createActions();
    createMenus();

    // initialize FFTW
    m_main_signal = new DataFft();
    m_qpoint_magnitude.resize(m_main_signal->get_fft_size());
    setCentralWidget(new QWidget(this));
    QVBoxLayout *layout = new QVBoxLayout;
    layout->setSpacing(5);
    layout->setMargin(15);

    //------------qwt plot start---------------------
    QString label;
    label.sprintf( "FFT plot" );
    QwtText text(label);
    m_main_plot = new QwtPlot(text, parent);
    m_main_plot->setCanvasBackground(QColor( Qt::darkBlue ));
    m_main_plot->setAxisScale( QwtPlot::xBottom, 0, m_main_signal->get_fft_size() / 2 );
    m_main_plot->setAxisTitle( QwtPlot::xBottom, "FFT points [-]" );
    m_main_plot->setAxisScale( QwtPlot::yLeft, -250, 2 );
    m_main_plot->setAxisTitle( QwtPlot::yLeft, "Sine magnitude [dB]" );
    m_main_plot->enableAxis(QwtPlot::yRight,true);
    m_main_plot->setAxisScale( QwtPlot::yRight, -250, 2 );
    m_main_plot->enableAxis(QwtPlot::xTop,true);
    m_main_plot->setAxisScale( QwtPlot::xTop, 0, m_main_signal->get_fft_size() / 2 );

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen( QPen( Qt::green, 0.0, Qt::DotLine ) );
    grid->enableX( true );
    grid->enableXMin( true );
    grid->enableY( true );
    grid->enableYMin( false );
    grid->attach( m_main_plot );

    m_slider_freq = new Slider(this, 2, sineStartValue);
    m_main_plot->setCanvasBackground( QColor( Qt::white ) );

    m_slider_scroll = new Slider(this, 2, 2500);

    // add curve
    m_main_curve = new QwtPlotCurve("Main curve");

    // connect or copy the data to the curves
    int iter = 0;
    for(auto it = m_qpoint_magnitude.begin(); it != m_qpoint_magnitude.end(); it++ , iter++)
    {
        *it = QPointF(iter,iter);   // initialize 'x' axis
    }

    layout->addWidget(m_slider_freq);
    layout->addWidget(m_slider_scroll);
    layout->addWidget(m_main_plot);
    centralWidget()->setLayout(layout);

    m_main_curve->setSamples(m_qpoint_magnitude);
    m_main_curve->setPen(QPen(Qt::green));
    m_main_curve->attach(m_main_plot);

    // finally, refresh the plot
    m_main_plot->replot();
}
Esempio n. 20
0
void CurveWidget::initialize(bool zoom)
{
    setContentsMargins(2, 2, 2, 2);
    setMinimumHeight(338);

    int _width = QApplication::desktop()->availableGeometry().width();
    switch (_width) {
    case 1280: q_width = 493; break;
    case 1366: q_width = 532; break;
    default: q_width = 493; break;
    }

    setFixedWidth(q_width);
    plotLayout()->setAlignCanvasToScales( true);
    setAutoReplot();
    //setAxisAutoScale(QwtPlot::yLeft, false);

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen(QColor(80, 80, 80, 100), 0.5, Qt::SolidLine);
    grid->enableX(true);
    grid->enableY(true);
    grid->attach(this);

    q_origin = new QwtPlotMarker();
    q_origin->setLineStyle( QwtPlotMarker::Cross);
    q_origin->setLinePen(QColor(100, 100, 100, 100), 1.0, Qt::DashLine );
    q_origin->attach(this);

    setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());

    TimePlotPicker* picker = new TimePlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
        QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, canvas());
    picker->setStateMachine(new QwtPickerDragPointMachine());
    picker->setRubberBandPen(QColor(100, 100, 100, 200));
    picker->setTrackerPen(QColor(128, 128, 200, 200));

    // zoomer
    if (zoom) {
        q_zoomer = new Zoomer(QwtPlot::xBottom, QwtPlot::yLeft, canvas());
        q_zoomer->setRubberBand(QwtPicker::RectRubberBand);
        q_zoomer->setRubberBandPen(QColor(Qt::green));
        q_zoomer->setTrackerMode(QwtPicker::ActiveOnly);
        q_zoomer->setTrackerPen(QColor(Qt::white));
    }

    // scale
    //setAxisScale( QwtPlot::xBottom, 0, 200 );
    //setAxisScale( QwtPlot::yLeft, 400, 800 );

    //! curve

    //srand(QDateTime::currentDateTime().fromMSecsSinceEpoch());

    //
    QVector<QPointF> samples(0);
    addCurve("Curve 1", QPen(QColor("#0c78a6"), 1), samples);
    addCurve("Curve 2", QPen(QColor("#5fd43b"), 1), samples);

    // Legend
    QwtPlotLegendItem* legendItem = new JLegendItem;
    legendItem->setMaxColumns(q_curves.count());
    legendItem->attach(this);
}
Esempio n. 21
0
Plot::Plot(QWidget *parent):
    QwtPlot(parent),
    d_paintedPoints(0),
    d_interval(0.0, 10.0),
    d_timerId(-1)
{
    d_directPainter = new QwtPlotDirectPainter();

    setAutoReplot(false);

    // The backing store is important, when working with widget
    // overlays ( f.e rubberbands for zooming ).
    // Here we don't have them and the internal
    // backing store of QWidget is good enough.

    canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false);


#if defined(Q_WS_X11)
    // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
    // works on X11. This has a nice effect on the performance.

    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);

    // Disabling the backing store of Qt improves the performance
    // for the direct painter even more, but the canvas becomes
    // a native window of the window system, receiving paint events
    // for resize and expose operations. Those might be expensive
    // when there are many points and the backing store of
    // the canvas is disabled. So in this application
    // we better don't both backing stores.

    if ( canvas()->testPaintAttribute( QwtPlotCanvas::BackingStore ) )
    {
        canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
        canvas()->setAttribute(Qt::WA_NoSystemBackground, true);
    }

#endif

    initGradient();

    plotLayout()->setAlignCanvasToScales(true);

    setAxisTitle(QwtPlot::xBottom, "Time [s]");
    setAxisScale(QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue());
    setAxisScale(QwtPlot::yLeft, -200.0, 200.0);

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine));
    grid->enableX(true);
    grid->enableXMin(true);
    grid->enableY(true);
    grid->enableYMin(false);
    grid->attach(this);

    d_origin = new QwtPlotMarker();
    d_origin->setLineStyle(QwtPlotMarker::Cross);
    d_origin->setValue(d_interval.minValue() + d_interval.width() / 2.0, 0.0);
    d_origin->setLinePen(QPen(Qt::gray, 0.0, Qt::DashLine));
    d_origin->attach(this);

    d_curve = new QwtPlotCurve();
    d_curve->setStyle(QwtPlotCurve::Lines);
    d_curve->setPen(QPen(Qt::green));
#if 1
    d_curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
#endif
#if 1
    d_curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
#endif
    d_curve->setData(new CurveData());
    d_curve->attach(this);
}
Variog_plot::
Variog_plot( const Discrete_function& df,
			       const Variogram_function_adaptor<Covariance<GsTLPoint> > *model,
			       GsTLVector<double> angle,
             const std::vector<int>& pairs,
             const QString& title, bool y_starts_at_zero,
			       QWidget *parent, const char *name)
  : QwtPlot(parent), pairs_shown_(false), model1_(0), model2_(0)
{

  //this->setWindowFlags( );
  setWindowFlags(Qt::SubWindow | Qt::MSWindowsFixedSizeDialogHint);
  
  if (name)
    setObjectName(name);

  setWindowIcon(QIcon());
  
  //------------
  // configure the plotting area

  //use a light gray for the grid
  QwtPlotGrid * grid = new QwtPlotGrid();
  grid->enableX(true);
  grid->setPen( QPen( QColor(150,150,150), 0, Qt::DotLine ) );
  grid->attach(this);

  this->axisScaleEngine(QwtPlot::xBottom)->setReference(0);
  this->axisScaleEngine(QwtPlot::yLeft)->setReference(0);
  this->axisScaleEngine(QwtPlot::xBottom)->setMargins(0,0.5);
  this->axisScaleEngine(QwtPlot::yLeft)->setMargins(0,0.5);
  this->axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating |
							QwtScaleEngine::IncludeReference);
  this->axisScaleEngine(QwtPlot::yLeft)->setAttributes(QwtScaleEngine::Floating |
							QwtScaleEngine::IncludeReference);


  QFont axis_font =  this->axisFont( QwtPlot::xBottom );
  axis_font.setPointSize( 7 );

  QwtText t("distance");
  t.setFont(axis_font);
  this->setAxisTitle( QwtPlot::xBottom,t);

  //-------------

  if( !title.isEmpty() ) {
    QFont title_font;
    QwtText T(title);
    
    title_font.setPointSize( 8 );
    T.setFont(title_font);
    this->setTitle( T );
    this->setWindowTitle( title );
  }
  
  std::vector<double> x_vals = df.x_values();
  std::vector<double> y_vals = df.y_values();
  angle_ = angle;

  double* x = new double[x_vals.size()];
  double* y = new double[x_vals.size()];

  int actual_size = 0;
  for( int i=0 ; i < x_vals.size() ; i++ ) {
    if( GsTL::equals( x_vals[i], df.no_data_value(), 0.001 ) ||
        GsTL::equals( y_vals[i], df.no_data_value(), 0.001 ) ) continue;

    x[actual_size] = x_vals[i];
    y[actual_size] = y_vals[i];
    pairs_.push_back( pairs[i] );
    pairs_coord_x_.push_back( x_vals[i] );
    pairs_coord_y_.push_back( y_vals[i] );

    actual_size++;
  }
      
  model1_=model;
    
  const float ymargin = 1.05;
  const float xmargin = 1.06;
  if( actual_size > 0 ) {
    float ymax = *(std::max_element( y, y+actual_size ));
    float ymin = *(std::min_element( y, y+actual_size ));
    if( ymax == 0 && ymin == 0 ) 
      this->setAxisAutoScale( QwtPlot::yLeft );
    else if(ymax>0)
      this->setAxisScale( QwtPlot::yLeft, 0.0, ymax*ymargin );
    else
      this->setAxisScale( QwtPlot::yLeft, ymin*(2-ymargin), ymax*ymargin );
  
    if( y_starts_at_zero )
      this->setAxisScale( QwtPlot::yLeft, 0.0, ymax*ymargin );

    float xmax = *(std::max_element( x, x+actual_size ));
    this->setAxisScale( QwtPlot::xBottom, 0, xmax*xmargin );  
  }

  curve1_= new QwtPlotCurve("Discrete Function");
  curve1_->setData( x, y, actual_size );

  curve2_=new QwtPlotCurve("Model");
  curve1_->attach(this);      
  curve2_->attach(this);
  
  QwtSymbol symbol;
  symbol.setStyle(QwtSymbol::XCross);
  symbol.setPen( QPen(Qt::red, 3 ) );
  symbol.setSize(7);
      
  curve1_->setSymbol(symbol);
  curve1_->setStyle(QwtPlotCurve::NoCurve);
   
  symbol.setStyle( QwtSymbol::NoSymbol );
  symbol.setPen( QPen( Qt::blue, 1 ) );
  curve2_->setSymbol(symbol);
  curve2_->setStyle(QwtPlotCurve::Lines);

  this->replot();

  max_x_ = this->axisScaleDiv( QwtPlot::xBottom )->hBound();


  /*
  QObject::connect( this, SIGNAL(plotMouseReleased(const QMouseEvent& )), 
                    this, SLOT(show_pairs_count(const QMouseEvent&)) );
  */
  delete [] x;
  delete [] y;
}
Esempio n. 23
0
ChartView::ChartView( QWidget * parent ) : QwtPlot( parent )
{
    // void setupPalette()
    {
        QPalette pal = palette();
        QLinearGradient gradient;
        gradient.setCoordinateMode( QGradient::StretchToDeviceMode );
        // gradient.setColorAt( 0.0, QColor( 0xcf, 0xcf, 0xc4 ) ); // pastel gray
        // gradient.setColorAt( 1.0, QColor( 0xae, 0xc6, 0xcf ) ); // pastel blue
        gradient.setColorAt( 0.0, QColor( 0xc1, 0xff, 0xc1 ) ); // darkseagreen
        gradient.setColorAt( 1.0, QColor( 0xb4, 0xee, 0xb4 ) ); // darkseagreen 2
         
        pal.setBrush( QPalette::Window, QBrush( gradient ) );
         
        // QPalette::WindowText is used for the curve color
        // pal.setColor( QPalette::WindowText, Qt::green );

        setPalette( pal );
    }

    this->enableAxis( QwtPlot::yLeft, true );
    this->enableAxis( QwtPlot::xBottom, true );
    
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen( Qt::gray, 0.0, Qt::DotLine );
    grid->enableX( true );
    grid->enableXMin( true );
    grid->enableY( true );
    grid->enableYMin( false );
    grid->attach( this );

    this->axisScaleEngine( QwtPlot::yLeft )->setAttribute( QwtScaleEngine::Floating, true );
    this->axisScaleEngine( QwtPlot::xBottom )->setAttribute( QwtScaleEngine::Floating, true );
    
    auto zoomer = new adplot::Zoomer( QwtPlot::xBottom, QwtPlot::yLeft, this->canvas() );

    // Shift+LeftButton: zoom out to full size
    // Double click: zoom out by 1
    zoomer->setMousePattern( QwtEventPattern::MouseSelect2, Qt::LeftButton, Qt::ShiftModifier );

    const QColor c( Qt::darkBlue );
    zoomer->setRubberBandPen( c );
    zoomer->setTrackerPen( c );
    zoomer->autoYScaleHock( [&]( QRectF& rc ){ yScaleHock( rc ); } ); 
    zoomer->autoYScale( true );

    if ( auto panner = new QwtPlotPanner( canvas() ) ) {
        panner->setAxisEnabled( QwtPlot::yRight, false );
        panner->setMouseButton( Qt::MidButton );
    }
    
    if ( auto picker = new QwtPlotPicker( canvas() ) ) {
        picker->setMousePattern( QwtEventPattern::MouseSelect1,  Qt::RightButton );
        picker->setStateMachine( new QwtPickerDragRectMachine() );
        picker->setRubberBand( QwtPicker::RectRubberBand );
        picker->setRubberBandPen( QColor(Qt::red) );
        picker->setTrackerPen( QColor( Qt::blue ) );
        connect( picker, static_cast< void(QwtPlotPicker::*)(const QRectF&) >(&QwtPlotPicker::selected), this, &ChartView::selected );
        picker->setEnabled( true );
    }
}
Variog_multiplot::
Variog_multiplot( const std::vector<Discrete_function>& df_vec,
                  const QStringList& titles,
                  QWidget *parent, const char *name )
       : QwtPlot(parent)
{
  if (name)
    setObjectName(name);
  
  //this->setWindowFlags( Qt::SubWindow|Qt::MSWindowsFixedSizeDialogHint);

  //------------
  // configure the plotting area

  //use a light gray for the grid
  QwtPlotGrid * grid = new QwtPlotGrid();
  grid->enableX(true);
  grid->setPen( QPen( QColor(150,150,150), 0, Qt::DotLine ) );
  grid->attach(this);
    
  // configure the plot axis
  this->axisScaleEngine(QwtPlot::xBottom)->setReference(0);
  this->axisScaleEngine(QwtPlot::yLeft)->setReference(0);
  this->axisScaleEngine(QwtPlot::xBottom)->setMargins(0,0.5);
  this->axisScaleEngine(QwtPlot::yLeft)->setMargins(0,0.5);
  this->axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating |
							QwtScaleEngine::IncludeReference);
  this->axisScaleEngine(QwtPlot::yLeft)->setAttributes(QwtScaleEngine::Floating |
							QwtScaleEngine::IncludeReference);


  QFont axis_font =  this->axisFont( QwtPlot::xBottom );
  axis_font.setPointSize( 7 );

  QwtText title("distance");
  title.setFont(axis_font);
  this->setAxisTitle( QwtPlot::xBottom,title);


  //-------------
  this->setWindowTitle( "All Plots" );

  typedef enum QwtSymbol::Style QwtStyleEnum;
  typedef enum Qt::PenStyle QtPenStyleEnum;

  unsigned int dot_styles[8] = { QwtSymbol::Ellipse,
                                  QwtSymbol::Rect,
                                  QwtSymbol::Diamond,
                                  QwtSymbol::DTriangle,
                                  QwtSymbol::UTriangle,
                                  QwtSymbol::RTriangle,
                                  QwtSymbol::Cross,
                                  QwtSymbol::XCross };
  unsigned int line_styles[5] = {Qt::SolidLine, 
                                 Qt::DashLine, 
                                 Qt::DotLine,
                                 Qt::DashDotLine, 
                                 Qt::DashDotDotLine };
  /*
  if( !title.isEmpty() ) {
    QFont title_font;
    title_font.setPointSize( 8 );
    this->setTitle( title );
    this->setTitleFont( title_font );
    this->setCaption( title );
  }
  */
  const float ymargin = 1.05;
  const float xmargin = 1.06;

  float ymax = -9e99;
  float ymin = 9e99;
  float xmax = -9e99;
  for( unsigned int plot_id = 0; plot_id < df_vec.size() ; plot_id++ ) {
    std::vector<double> x_vals = df_vec[plot_id].x_values();
    std::vector<double> y_vals = df_vec[plot_id].y_values();

    double* x = new double[x_vals.size()];
    double* y = new double[x_vals.size()];

    int actual_size = 0;
    for( int i=0 ; i < x_vals.size() ; i++ ) {
      if( GsTL::equals( x_vals[i], df_vec[plot_id].no_data_value(), 0.001 ) ||
          GsTL::equals( y_vals[i], df_vec[plot_id].no_data_value(), 0.001 ) ) continue;

      x[actual_size] = x_vals[i];
      y[actual_size] = y_vals[i];

      actual_size++;
    }
    if( actual_size > 0 ) {
      float current_ymax = *(std::max_element( y, y+actual_size ));
      float current_ymin = *(std::min_element( y, y+actual_size ));
      float current_xmax = *(std::max_element( x, x+actual_size ));

      ymax = std::max(ymax, current_ymax );
      ymin = std::min(ymin, current_ymin );

      xmax = std::max(xmax, current_xmax );
    }

    QwtPlotCurve * curve_id = new QwtPlotCurve(titles[plot_id]);
    curve_id->attach(this);
    curve_id->setData( x, y, actual_size );
  
    QwtSymbol symbol;
    // The following line uses an awful cast from int to enum !!
    // Awful, but it will stay until I find a more elegant way of looping
    // through all the qwt styles.
    symbol.setStyle( static_cast<QwtStyleEnum>(dot_styles[plot_id%8]) ); 
    symbol.setPen( QPen(Qt::black, 1 ) );
    symbol.setSize(6);
      
    curve_id->setSymbol(symbol);
    curve_id->setStyle(QwtPlotCurve::Lines);
    curve_id->setPen( QPen(Qt::darkGray, 0, 
			   static_cast<QtPenStyleEnum>(line_styles[plot_id%5]) ) );

    delete [] x;
    delete [] y;
  }

  if( ymax == 0 && ymin == 0 ) 
    this->setAxisAutoScale( QwtPlot::yLeft );
  else
    this->setAxisScale( QwtPlot::yLeft, ymin*(2-ymargin), ymax*ymargin );

  if( xmax > 0 ) {
    this->setAxisScale( QwtPlot::xBottom, 0, xmax*xmargin );  
  }

  QwtLegend * legend = new QwtLegend();
  this->insertLegend(legend);
  this->replot();

}
Esempio n. 25
0
COscMain::COscMain()
: QMainWindow()
{
    m_dev = new CUsbIo();
    m_running = false;

    ui.setupUi( this );
    connect( ui.actionQuit, SIGNAL(triggered()), this, SLOT(close()) );
    connect( ui.actionRun, SIGNAL(triggered()), this, SLOT(start()) );
    connect( ui.actionConnect, SIGNAL(triggered()), this, SLOT(open()) );
    COscScaler * scaler = new COscScaler( ui.plot );
    scaler->setWheelZoomX( true );
    scaler->setWheelZoomY( true );
    scaler->setEqualScales( false );
    scaler->setSaveScales( false );

    QwtPlotGrid * g = new QwtPlotGrid();
    g->enableXMin( true );
    g->enableYMin( true );
    g->setPen( QPen( Qt::gray, 0.0, Qt::DotLine ) );
    g->attach( ui.plot );

    g = new QwtPlotGrid();
    g->enableX( true );
    g->enableY( true );
    g->setPen( QPen( Qt::gray, 0.0, Qt::SolidLine ) );
    g->attach( ui.plot );


    connect( this, SIGNAL(sigReplot()), this, SLOT(replot()), Qt::QueuedConnection );

    ui.plot->canvas()->setBorderRadius( 10 );
    ui.plot->plotLayout()->setAlignCanvasToScales( true );

    // Nice background coloration.
    QPalette pal = ui.plot->canvas()->palette();
    QLinearGradient gr( 0.0, 0.0, 1.0, 1.0 );
    gr.setCoordinateMode( QGradient::StretchToDeviceMode );
    gr.setColorAt( 0.0, QColor( 200, 200, 230 ) );
    gr.setColorAt( 1.0, QColor( 230, 230, 250 ) );
    pal.setBrush( QPalette::Window, QBrush( gr ) );
    ui.plot->canvas()->setPalette( pal );

    m_ptsPerSecond = new QSpinBox();
    m_ptsPerSecond->setRange( 1, 128 );
    m_ptsPerSecond->setPrefix( tr( "Pts/sec" ) );
    m_ptsPerSecond->setValue( 50 );
    connect( m_ptsPerSecond, SIGNAL(editingFinished()), this, SLOT(settingsChanged()) );

    m_seconds = new QSpinBox();
    m_seconds->setRange( 1, 600 );
    m_seconds->setPrefix( tr( "Seconds" ) );
    m_seconds->setValue( 3 );
    connect( m_seconds, SIGNAL(editingFinished()), this, SLOT(settingsChanged()) );

    m_curvesCnt = new QSpinBox();
    m_curvesCnt->setRange( 1, 10 );
    m_curvesCnt->setValue( 3 );
    m_curvesCnt->setPrefix( tr( "Curves" ) );
    connect( m_curvesCnt, SIGNAL(editingFinished()), this, SLOT(curvesCntChanged()) );

    ui.sb->addWidget( m_ptsPerSecond );
    ui.sb->addWidget( m_seconds );
    ui.sb->addWidget( m_curvesCnt );

    ui.sb->adjustSize();

    open();
    curvesCntChanged();
    settingsChanged();
    /*if ( m_dev->isOpen() )
    {
        
        m_dev->setTimer( 12000, CUsbIo::T1024 );
        m_dev->setTimer( 6000,  CUsbIo::T1024 );
        m_dev->setTimer( 255,   CUsbIo::T1024 );
    }*/
}
Esempio n. 26
0
void QgsHistogramWidget::drawHistogram()
{
  if ( !mVectorLayer || mSourceFieldExp.isEmpty() )
    return;

  QApplication::setOverrideCursor( Qt::WaitCursor );

  if ( mValues.empty() )
  {
    bool ok;
    mValues = mVectorLayer->getDoubleValues( mSourceFieldExp, ok );

    if ( ! ok )
    {
      QApplication::restoreOverrideCursor();
      return;
    }
    qSort( mValues.begin(), mValues.end() );
    mHistogram.setValues( mValues );
    mBinsSpinBox->blockSignals( true );
    mBinsSpinBox->setValue( qMax( mHistogram.optimalNumberBins(), 30 ) );
    mBinsSpinBox->blockSignals( false );

    mStats.setStatistics( QgsStatisticalSummary::StDev );
    mStats.calculate( mValues );
  }

  // clear plot
  mpPlot->detachItems();

  //ensure all children get removed
  mpPlot->setAutoDelete( true );
  // Set axis titles
  mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr( "Value" ) );
  mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr( "Count" ) );
  mpPlot->setAxisAutoScale( QwtPlot::yLeft );
  mpPlot->setAxisAutoScale( QwtPlot::xBottom );

  // add a grid
  QwtPlotGrid * grid = new QwtPlotGrid();
  grid->enableX( false );
  grid->setPen( mGridPen );
  grid->attach( mpPlot );

  // make colors list
  mHistoColors.clear();
  foreach ( QgsRendererRangeV2 range, mRanges )
  {
    mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black );
  }

  //draw histogram
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
  QwtPlotHistogram * plotHistogram = 0;
  plotHistogram = createPlotHistogram( mRanges.count() > 0 ? mRanges.at( 0 ).label() : QString(),
                                       mRanges.count() > 0 ? QBrush( mHistoColors.at( 0 ) ) : mBrush,
                                       mRanges.count() > 0 ? Qt::NoPen : mPen );
#else
  HistogramItem *plotHistogramItem = 0;
  plotHistogramItem = createHistoItem( mRanges.count() > 0 ? mRanges.at( 0 ).label() : QString(),
                                       mRanges.count() > 0 ? QBrush( mHistoColors.at( 0 ) ) : mBrush,
                                       mRanges.count() > 0 ? Qt::NoPen : mPen );
#endif

#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
  QVector<QwtIntervalSample> dataHisto;
#else

  // we safely assume that QT>=4.0 (min version is 4.7), therefore QwtArray is a QVector, so don't set size here
  QwtArray<QwtDoubleInterval> intervalsHisto;
  QwtArray<double> valuesHisto;

#endif

  int bins = mBinsSpinBox->value();
  QList<double> edges = mHistogram.binEdges( bins );
  QList<int> counts = mHistogram.counts( bins );

  int rangeIndex = 0;
  int lastValue = 0;

  for ( int bin = 0; bin < bins; ++bin )
  {
    int binValue = counts.at( bin );

    //current bin crosses two graduated ranges, so we split between
    //two histogram items
    if ( rangeIndex < mRanges.count() - 1 && edges.at( bin ) > mRanges.at( rangeIndex ).upperValue() )
    {
      rangeIndex++;
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
      plotHistogram->setSamples( dataHisto );
      plotHistogram->attach( mpPlot );
      plotHistogram = createPlotHistogram( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) );
      dataHisto.clear();
      dataHisto << QwtIntervalSample( lastValue, mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) );
#else
      plotHistogramItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) );
      plotHistogramItem->attach( mpPlot );
      plotHistogramItem = createHistoItem( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) );
      intervalsHisto.clear();
      valuesHisto.clear();
      intervalsHisto.append( QwtDoubleInterval( mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) ) );
      valuesHisto.append( lastValue );
#endif
    }

    double upperEdge = mRanges.count() > 0 ? qMin( edges.at( bin + 1 ), mRanges.at( rangeIndex ).upperValue() )
                       : edges.at( bin + 1 );

#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
    dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge );
#else
    intervalsHisto.append( QwtDoubleInterval( edges.at( bin ), upperEdge ) );
    valuesHisto.append( double( binValue ) );
#endif

    lastValue = binValue;
  }

#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
  plotHistogram->setSamples( dataHisto );
  plotHistogram->attach( mpPlot );
#else
  plotHistogramItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) );
  plotHistogramItem->attach( mpPlot );
#endif

  mRangeMarkers.clear();
  foreach ( QgsRendererRangeV2 range, mRanges )
  {
    QwtPlotMarker* rangeMarker = new QwtPlotMarker();
    rangeMarker->attach( mpPlot );
    rangeMarker->setLineStyle( QwtPlotMarker::VLine );
    rangeMarker->setXValue( range.upperValue() );
    rangeMarker->setLabel( QString::number( range.upperValue() ) );
    rangeMarker->setLabelOrientation( Qt::Vertical );
    rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
    rangeMarker->show();
    mRangeMarkers << rangeMarker;
  }