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); }
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 ); }
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(); }
SimDialog::SimDialog( QWidget * parent, Qt::WFlags f) : QDialog(parent, f) { setupUi(this); // setup the plot ... m_plot->setTitle("Comparing Similarity Measures"); m_plot->insertLegend(new QwtLegend(), QwtPlot::BottomLegend); // set up the axes ... m_plot->setAxisTitle(QwtPlot::xBottom, "Variations"); m_plot->setAxisScale(QwtPlot::xBottom, -10, 10); m_plot->setAxisTitle(QwtPlot::yLeft, "Similarity"); m_plot->setAxisScale(QwtPlot::yLeft, -1.5, 1.5); // enable grid ... QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(m_plot); // Insert zero line at y = 0 QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop); mY->setLineStyle(QwtPlotMarker::HLine); mY->setYValue(0.0); mY->attach(m_plot); // Insert zero line at x = 0 QwtPlotMarker *mX = new QwtPlotMarker(); mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop); mX->setLineStyle(QwtPlotMarker::VLine); mX->setXValue(0.0); mX->attach(m_plot); // Insert new curves cReg = new QwtPlotCurve("Regular Similarity Measure"); cReg->attach(m_plot); cOct = new QwtPlotCurve("Octree based Similarity Measure"); cOct->attach(m_plot); // Set curve styles cReg->setPen(QPen(Qt::red, 2)); cOct->setPen(QPen(Qt::blue, 2)); // Populate the volume combos ... MainWindow* _win = (MainWindow *)this->parent(); viewer3d * _view = (viewer3d *) _win->getViewer(); QList<Volume*> _vols = _view->getVolumes(); // append Volume names to combo boxes ... // Need to modify Volume class so that it stored patient name ... // More importantly modify PatientBrowser so that the data can be directly // loaded. }
// Init X axis. void DataPlot::setGridPlot() { QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(this); }
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); } }
QmitkHistogramWidget::QmitkHistogramWidget(QWidget * parent, bool showreport) : QDialog(parent) { QBoxLayout *layout = new QVBoxLayout(this); //***histogram*** QGroupBox *hgroupbox = new QGroupBox("", this); hgroupbox->setMinimumSize(900, 400); m_Plot = new QwtPlot(hgroupbox); m_Plot->setCanvasBackground(QColor(Qt::white)); m_Plot->setTitle("Histogram"); QwtText text = m_Plot->titleLabel()->text(); text.setFont(QFont("Helvetica", 12, QFont::Normal)); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(m_Plot); layout->addWidget(hgroupbox); layout->setSpacing(20); if (showreport == true) { //***report*** QGroupBox *rgroupbox = new QGroupBox("", this); rgroupbox->setMinimumSize(900, 400); QLabel *label = new QLabel("Gray Value Analysis", rgroupbox); label->setAlignment(Qt::AlignHCenter); label->setFont(QFont("Helvetica", 14, QFont::Bold)); m_Textedit = new QTextEdit(rgroupbox); m_Textedit->setFont(QFont("Helvetica", 12, QFont::Normal)); m_Textedit->setReadOnly(true); layout->addWidget(rgroupbox); } m_Picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPicker::PointSelection, QwtPlotPicker::NoRubberBand, QwtPicker::AlwaysOn, m_Plot->canvas()); connect(m_Picker, SIGNAL(selected(const QwtDoublePoint &)), SLOT(OnSelect(const QwtDoublePoint &))); }
int main(int argc, char **argv) { QApplication a(argc, argv); QwtPlot plot; plot.setCanvasBackground(QColor(Qt::white)); plot.setTitle("Histogram"); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(&plot); HistogramItem *histogram = new HistogramItem(); histogram->setColor(Qt::darkCyan); const int numValues = 20; QwtArray<QwtDoubleInterval> intervals(numValues); QwtArray<double> values(numValues); double pos = 0.0; for ( int i = 0; i < (int)intervals.size(); i++ ) { const int width = 5 + rand() % 15; const int value = rand() % 100; intervals[i] = QwtDoubleInterval(pos, pos + double(width)); values[i] = value; pos += width; } histogram->setData(QwtIntervalData(intervals, values)); histogram->attach(&plot); plot.setAxisScale(QwtPlot::yLeft, 0.0, 100.0); plot.setAxisScale(QwtPlot::xBottom, 0.0, pos); plot.replot(); #if QT_VERSION < 0x040000 a.setMainWidget(&plot); #endif plot.resize(600,400); plot.show(); return a.exec(); }
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); }
int main( int argc, char **argv ) { //using HistogramItem = QwtPlotItem; using HistogramItem = QwtPlotHistogram; //using QwtIntervalData = QwtSeriesData<QwtIntervalSample>; QApplication a(argc, argv); QwtPlot plot; plot.setCanvasBackground(QColor(Qt::white)); plot.setTitle("Histogram"); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajorPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinorPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(&plot); HistogramItem *histogram = new HistogramItem; //histogram->setColor(Qt::darkCyan); const int numValues = 20; //QwtArray<QwtDoubleInterval> intervals(numValues); QwtArray<QwtIntervalSample> intervals(numValues); QwtArray<double> values(numValues); double pos = 0.0; for ( int i = 0; i < (int)intervals.size(); i++ ) { //const int width = 5 + rand() % 15; const int value = rand() % 100; //intervals[i] = QwtDoubleInterval(pos, pos + double(width)); intervals[i] = QwtIntervalSample(value, pos, pos + double(width)); //values[i] = value; pos += width; } //histogram->setData(QwtIntervalData(intervals, values)); histogram->setSamples(intervals); //histogram->setSamples(QwtIntervalData(intervals, values)); //QwtIntervalData d; //histogram->setData(d); histogram->attach(&plot); plot.setAxisScale(QwtPlot::yLeft, 0.0, 100.0); plot.setAxisScale(QwtPlot::xBottom, 0.0, pos); plot.replot(); plot.resize(600,400); plot.show(); return a.exec(); }
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); }
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); }
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 ); }
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(); }
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()) ); }
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 ); }
BrainPlot::BrainPlot(QWidget *parent, int nChannels, int Length, int Amplitude): QwtPlot( parent ), d_curves( nChannels ), d_zeros( nChannels ) { /*Set some attributes*/ minusExpectedAmplitude = -Amplitude; plotLength = Length; this->nChannels = nChannels; /*Start sample counter*/ sample = 0; /*Painter*/ d_directPainter = new QwtPlotDirectPainter( this ); if ( QwtPainter::isX11GraphicsSystem() ) { #if QT_VERSION < 0x050000 canvas()->setAttribute( Qt::WA_PaintOutsidePaintEvent, true ); #endif canvas()->setAttribute( Qt::WA_PaintOnScreen, true ); } /*Activates the legend for channel tracking*/ QwtLegend *legend = new QwtLegend; legend->setDefaultItemMode( QwtLegendData::ReadOnly); insertLegend( legend, QwtPlot::LeftLegend ); /*Instantiate the reference lines and the data curves for each channel*/ int Hfactor = 360/(nChannels+1);//different colors for each curve char name[15]; for(int c = 0; c < nChannels; c++) { /*Curve*/ sprintf(name, "Channel %d", c+1); d_curves[c] = new QwtPlotCurve( name); d_curves[c]->setData( new CurveData(plotLength, minusExpectedAmplitude*(2*c+1)) ); d_curves[c]->setPen( QColor::fromHsv ( Hfactor*c, 255, 255)); d_curves[c]->setStyle( QwtPlotCurve::Lines ); d_curves[c]->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol)); d_curves[c]->attach( this ); /*Reference line*/ d_zeros[c] = new QwtPlotCurve; d_zeros[c]->setData( new CurveData() ); d_zeros[c]->setPen( QColor::fromHsv ( Hfactor*c, 255, 140)); d_zeros[c]->setStyle( QwtPlotCurve::Lines ); d_zeros[c]->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol)); d_zeros[c]->setItemAttribute(QwtPlotItem::Legend, false); d_zeros[c]->attach( this ); /*Draw reference lines*/ CurveData *data = static_cast<CurveData *>( d_zeros[c]->data() ); data->append(QPointF(0, minusExpectedAmplitude*(2*c+1))); data->append(QPointF(plotLength, minusExpectedAmplitude*(2*c+1))); d_directPainter->drawSeries( d_zeros[c], 0, 1); } /*Sweeping line*/ d_sweep = new QwtPlotCurve; d_sweep->setData( new CurveData() ); d_sweep->setPen( Qt::black, plotLength/100, Qt::SolidLine); d_sweep->setStyle( QwtPlotCurve::Lines ); d_sweep->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol)); d_sweep->setItemAttribute(QwtPlotItem::Legend, false); d_sweep->attach( this ); CurveData *data = static_cast<CurveData *>( d_sweep->data() ); data->append(QPointF(0, plotLength)); data->append(QPointF(0, 2*nChannels*minusExpectedAmplitude)); /*Axis*/ setAxisScale( xBottom, 0, plotLength ); setAxisScale( yLeft, 2*nChannels*minusExpectedAmplitude, 0 ); enableAxis(xBottom, false); enableAxis(yLeft, false); /*Frame*/ setFrameStyle( QFrame::NoFrame ); setLineWidth( 0 ); /*Canvas*/ plotLayout()->setAlignCanvasToScales( true ); plotLayout()->setCanvasMargin(100, QwtPlot::xBottom); plotLayout()->setCanvasMargin(100, QwtPlot::xTop); setCanvasBackground( Qt::black ); /*Grid*/ QwtPlotGrid *grid = new QwtPlotGrid; grid->setMajorPen( Qt::gray, 0, Qt::DotLine ); grid->setMinorPen( Qt::gray, 0, Qt::DotLine ); grid->enableYMin(true); grid->attach( this ); /*Optimizaion for real-time data collecting*/ setAutoReplot( false ); /*Show*/ replot(); }
//--------------------------------------------------------------------------- void Plots::Plots_Create(PlotType Type) { // Paddings if (paddings[Type]==NULL) { paddings[Type]=new QWidget(this); paddings[Type]->setVisible(false); } // General design of plot QwtPlot* plot = new QwtPlot(this); plot->setVisible(false); plot->setMinimumHeight(1); plot->enableAxis(QwtPlot::xBottom, Type==PlotType_Axis); plot->setAxisMaxMajor(QwtPlot::yLeft, 0); plot->setAxisMaxMinor(QwtPlot::yLeft, 0); plot->setAxisScale(QwtPlot::xBottom, 0, FileInfoData->Videos[0]->x_Max[XAxis_Kind_index]); if (PerPlotGroup[Type].Count>3) plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // Plot grid QwtPlotGrid *grid = new QwtPlotGrid(); grid->enableXMin(true); grid->enableYMin(true); grid->setMajorPen(Qt::darkGray, 0, Qt::DotLine ); grid->setMinorPen(Qt::gray, 0 , Qt::DotLine ); grid->attach(plot); // Plot curves for(unsigned j=0; j<PerPlotGroup[Type].Count; ++j) { plotsCurves[Type][j] = new QwtPlotCurve(PerPlotName[PerPlotGroup[Type].Start+j].Name); QColor c; switch (PerPlotGroup[Type].Count) { case 1 : switch (Type) { case PlotType_YDiff: c=Qt::darkGreen; break; case PlotType_UDiff: c=Qt::darkBlue; break; case PlotType_VDiff: c=Qt::darkRed; break; default: c=Qt::black; } break; case 2 : switch (j) { case 0: c=Qt::darkGreen; break; case 1: c=Qt::darkRed; break; default: c=Qt::black; } break; case 3 : switch (j) { case 0: c=Qt::darkRed; break; case 1: c=Qt::darkBlue; break; case 2: c=Qt::darkGreen; break; default: c=Qt::black; } break; case 5 : switch (j) { case 0: c=Qt::red; break; case 1: c=QColor::fromRgb(0x00, 0x66, 0x00); break; //Qt::green case 2: c=Qt::black; break; case 3: c=Qt::green; break; case 4: c=Qt::red; break; default: c=Qt::black; } break; default: c=Qt::black; } plotsCurves[Type][j]->setPen(c); plotsCurves[Type][j]->setRenderHint(QwtPlotItem::RenderAntialiased); plotsCurves[Type][j]->setZ(plotsCurves[Type][j]->z()-j); //Invert data order (e.g. MAX before MIN) plotsCurves[Type][j]->attach(plot); } // Legends QwtLegend *legend = new QwtLegend(this); legend->setVisible(false); legend->setMinimumHeight(1); legend->setMaxColumns(1); QFont Font=legend->font(); #ifdef _WIN32 Font.setPointSize(6); #else // _WIN32 Font.setPointSize(8); #endif //_WIN32 legend->setFont(Font); connect(plot, SIGNAL(legendDataChanged(const QVariant &, const QList<QwtLegendData> &)), legend, SLOT(updateLegend(const QVariant &, const QList<QwtLegendData> &))); plot->updateLegend(); // Assignment plots[Type]=plot; legends[Type]=legend; // Pickers plotsPickers[Type] = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, plots[Type]->canvas() ); plotsPickers[Type]->setStateMachine( new QwtPickerDragPointMachine () ); plotsPickers[Type]->setRubberBandPen( QColor( Qt::green ) ); plotsPickers[Type]->setTrackerPen( QColor( Qt::white ) ); connect(plotsPickers[Type], SIGNAL(moved(const QPointF&)), SLOT(plot_moved(const QPointF&))); connect(plotsPickers[Type], SIGNAL(selected(const QPointF&)), SLOT(plot_moved(const QPointF&))); // Marker QwtPlotMarker* plotMarker=new QwtPlotMarker; plotMarker->setLineStyle(QwtPlotMarker::VLine); plotMarker->setLinePen(QPen(Qt::magenta, 1)); plotMarker->setXValue(0); plotMarker->attach(plot); plotsMarkers[Type]=plotMarker; }
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(); }
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 ); } }
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); }
//--------------------------------------------------------------------------- Plot::Plot( size_t streamPos, size_t Type, size_t Group, QWidget *parent ) : QwtPlot( parent ), m_streamPos( streamPos ), m_type( Type ), m_group( Group ) { setAutoReplot( false ); QwtPlotCanvas* canvas = dynamic_cast<QwtPlotCanvas*>( this->canvas() ); if ( canvas ) { canvas->setFrameStyle( QFrame::Plain | QFrame::Panel ); canvas->setLineWidth( 1 ); #if 1 canvas->setPalette( QColor("Cornsilk") ); #endif } setAxisMaxMajor( QwtPlot::yLeft, 0 ); setAxisMaxMinor( QwtPlot::yLeft, 0 ); setAxisScaleDraw( QwtPlot::yLeft, new PlotScaleDrawY() ); enableAxis( QwtPlot::xBottom, false ); // something invalid setAxisScale( QwtPlot::xBottom, -1, 0 ); setAxisScale( QwtPlot::yLeft, -1, 0 ); // Plot grid QwtPlotGrid *grid = new QwtPlotGrid(); grid->enableXMin( true ); grid->enableYMin( true ); grid->setMajorPen( Qt::darkGray, 0, Qt::DotLine ); grid->setMinorPen( Qt::gray, 0 , Qt::DotLine ); grid->attach( this ); m_cursor = new PlotCursor( canvas ); m_cursor->setPosition( 0 ); // curves for( unsigned j = 0; j < PerStreamType[m_type].PerGroup[m_group].Count; ++j ) { QwtPlotCurve* curve = new QwtPlotCurve( PerStreamType[m_type].PerItem[PerStreamType[m_type].PerGroup[m_group].Start + j].Name ); curve->setPen( curveColor( j ) ); curve->setRenderHint( QwtPlotItem::RenderAntialiased ); curve->setZ( curve->z() - j ); //Invert data order (e.g. MAX before MIN) curve->attach( this ); m_curves += curve; } // visual helpers if ( m_type == Type_Video ) switch (m_group) { case Group_Y : Plot_AddHLine( this, 16, 61, 89, 171); Plot_AddHLine( this, 235, 220, 20, 60); break; case Group_U : case Group_V : Plot_AddHLine( this, 16, 61, 89, 171); Plot_AddHLine( this, 240, 220, 20, 60); break; case Group_Sat : Plot_AddHLine( this, 88, 255, 0, 255); Plot_AddHLine( this, 118, 220, 20, 60); break; default : ; } PlotPicker* picker = new PlotPicker( canvas, &PerStreamType[m_type], m_group, &m_curves ); connect( picker, SIGNAL( moved( const QPointF& ) ), SLOT( onPickerMoved( const QPointF& ) ) ); connect( picker, SIGNAL( selected( const QPointF& ) ), SLOT( onPickerMoved( const QPointF& ) ) ); connect( axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ), SLOT( onXScaleChanged() ) ); // legend m_legend = new PlotLegend(); connect( this, SIGNAL( legendDataChanged( const QVariant &, const QList<QwtLegendData> & ) ), m_legend, SLOT( updateLegend( const QVariant &, const QList<QwtLegendData> & ) ) ); updateLegend(); }
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 ); }*/ }
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); }