Beispiel #1
1
QTabWidget* ResultsPage::createDataTabWidget()
{
    QTabWidget *tabWidget = new QTabWidget;

    // Plot
    m_plot = new QwtPlot(tabWidget);
    m_plot->setCanvasBackground(Qt::white);
    m_plot->setContextMenuPolicy(Qt::CustomContextMenu);
    m_plot->setAutoReplot(false);

    connect(m_plot, SIGNAL(customContextMenuRequested(QPoint)),
            this, SLOT(showPlotContextMenu(QPoint)));
    
    // Picker to allow for selection of the closest curve and displays curve
    // coordinates with a cross rubber band.
    QwtPlotPicker *picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
                                              QwtPicker::CrossRubberBand, QwtPicker::ActiveOnly,
                                              m_plot->canvas());
    picker->setStateMachine(new QwtPickerDragPointMachine());

    connect(picker, SIGNAL(appended(QPoint)), this, SLOT(pointSelected(QPoint)));

    // Legend
    QwtLegend* legend = new QwtLegend;
    legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
    m_plot->insertLegend(legend, QwtPlot::BottomLegend);
#if QWT_VERSION >= 0x060100
    connect(m_plot,
            SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)),
            legend,
            SLOT(updateLegend(QVariant,QList<QwtLegendData>)));
#endif

    // Add the generic curves to the legend
    QList<QPair<QString, Qt::GlobalColor> > pairs;
    pairs << qMakePair(tr("Unselected Realization"), Qt::darkGray)
          << qMakePair(tr("Selected and Enabled Realization"), Qt::darkGreen)
          << qMakePair(tr("Selected and Disabled Realization"), Qt::darkRed);

    QPair<QString, Qt::GlobalColor> pair;
    foreach (pair, pairs) {
        QwtPlotCurve *curve = new QwtPlotCurve(pair.first);

        curve->setLegendIconSize(QSize(32, 8));
        curve->setPen(QPen(QBrush(pair.second), 2));
        curve->setLegendAttribute(QwtPlotCurve::LegendShowLine);
#if QWT_VERSION < 0x060100
        curve->updateLegend(legend);
#else
        m_plot->updateLegend(curve);
#endif
    }
void MainWindow::setupPlot()
{
    plotTimer.setInterval(1000/settingsDialog->rate);
    connect(&plotTimer, SIGNAL(timeout()), this, SLOT(plotUpdate()));
    plotTimer.start();

    if (!ui->plot->legend()) {
        QwtLegend* legend = new QwtLegend;
        legend->setItemMode(QwtLegend::CheckableItem);
        ui->plot->insertLegend(legend, QwtPlot::RightLegend);
    }

    ui->plot->setAxisTitle(QwtPlot::xBottom, "seconds");
    ui->plot->setCanvasBackground(Qt::white);

    QColor gridColor;
    gridColor.setNamedColor("grey");
    QPen gridPen(gridColor);
    gridPen.setStyle(Qt::DotLine);
    QwtPlotGrid* grid = new QwtPlotGrid;
    grid->setMajPen(gridPen);
    grid->attach(ui->plot);

    connect(ui->plot, SIGNAL(legendChecked(QwtPlotItem*,bool)), this, SLOT(showCurve(QwtPlotItem*,bool)));
}
void QwtPolarRenderer::renderLegend(
    QPainter *painter, const QRectF &rect ) const
{
    QwtLegend *legend = d_data->plot->legend();
    if ( legend == NULL || legend->isEmpty() )
        return;

    const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>(
        legend->contentsWidget()->layout() );
    if ( legendLayout == NULL )
        return;

    uint numCols = legendLayout->columnsForWidth( rect.width() );
    const QList<QRect> itemRects =
        legendLayout->layoutItems( rect.toRect(), numCols );

    int index = 0;

    for ( int i = 0; i < legendLayout->count(); i++ )
    {
        QLayoutItem *item = legendLayout->itemAt( i );
        QWidget *w = item->widget();
        if ( w )
        {
            painter->save();

            painter->setClipRect( itemRects[index] );
            renderLegendItem( painter, w, itemRects[index] );

            index++;
            painter->restore();
        }
    }

}
Beispiel #4
0
CopasiPlot::CopasiPlot(const CPlotSpecification* plotspec, QWidget* parent):
  QwtPlot(parent),
  mCurves(0),
  mCurveMap(),
  mDataBefore(0),
  mDataDuring(0),
  mDataAfter(0),
  mHaveBefore(false),
  mHaveDuring(false),
  mHaveAfter(false),
  mpPlotSpecification(NULL),
  mNextPlotTime(),
  mIgnoreUpdate(false),
  mpZoomer(NULL),
  mReplotFinished(false)
{
  QwtLegend *legend = new QwtLegend;
  legend->setItemMode(QwtLegend::CheckableItem);

  // whole legend can not be displayed at bottom on DARWIN
  // maybe a Qwt bug ?!?
#ifdef Darwin
  insertLegend(legend, QwtPlot::TopLegend);
#else
  insertLegend(legend, QwtPlot::BottomLegend);
#endif

  // Set up the zoom facility
  mpZoomer = new ScrollZoomer(canvas());
  mpZoomer->setRubberBandPen(QColor(Qt::black));
  mpZoomer->setTrackerPen(QColor(Qt::black));
  mpZoomer->setTrackerMode(QwtPicker::AlwaysOn);
  mpZoomer->setTrackerFont(this->font());

  // white background better for printing...
  setCanvasBackground(Qt::white);

  //  setTitle(FROM_UTF8(plotspec->getTitle()));
  setCanvasLineWidth(0);

  canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);

  connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
          SLOT(showCurve(QwtPlotItem *, bool)));

  // Size the vectors to be able to store information for all activities.
  mData.resize(ActivitySize);
  mObjectValues.resize(ActivitySize);
  mObjectInteger.resize(ActivitySize);
  mDataSize.resize(ActivitySize);
  mDataIndex.clear();

  // Initialize from the plot specification
  initFromSpec(plotspec);
  connect(this, SIGNAL(replotSignal()), this, SLOT(replot()));
}
void GenericHistogramView::init()
{
  this->setMouseTracking(true); //Switch on mouse tracking (no need to press button)

  _qwtPlot->setTitle("Histogram");
  
  _qwtPlot->setCanvasBackground(QColor(Qt::gray));
  _qwtPlot->plotLayout()->setAlignCanvasToScales(true);

  _qwtPlot->setAxisTitle(QwtPlot::yLeft, "Number of specimen");
  _qwtPlot->setAxisTitle(QwtPlot::xBottom, "Pixel value");

	QwtLegend* legend = new QwtLegend();
  legend->setItemMode(QwtLegend::CheckableItem);
  _qwtPlot->insertLegend(legend, QwtPlot::RightLegend);

  populate();
  
  _qwtPlot->canvas()->setMouseTracking(true);
  
  if(_horizontal)
  _principalPicker = new HistogramPicker(QwtPlotPicker::HLineRubberBand, QwtPicker::AlwaysOn, _qwtPlot->canvas());
  else
  _principalPicker = new HistogramPicker(QwtPlotPicker::VLineRubberBand, QwtPicker::AlwaysOn, _qwtPlot->canvas());
  _principalPicker->setStateMachine(new QwtPickerDragPointMachine());
  _principalPicker->setTrackerPen(QColor(Qt::white));
  _principalPicker->setRubberBandPen(QColor(Qt::yellow));
  
  _leftPicker = new HistogramPicker(_qwtPlot->canvas());
  _leftPicker->setStateMachine(new QwtPickerDragPointMachine());
  
  _rightPicker = new HistogramPicker(_qwtPlot->canvas());
  _rightPicker->setStateMachine(new QwtPickerDragPointMachine());
  _rightPicker->setRubberBand(QwtPlotPicker::VLineRubberBand);
  _rightPicker->setRubberBandPen(QColor(Qt::yellow));
	_rightPicker->setMousePattern(QwtPicker::MouseSelect1, Qt::RightButton);

  connect(_qwtPlot, SIGNAL(legendChecked(QwtPlotItem*, bool)), this, SLOT(showItem(QwtPlotItem*, bool)));
  connect(_rightPicker, SIGNAL(selected(const QPointF&)), this, SLOT(rightClick(const QPointF&)));
  connect(_leftPicker, SIGNAL(selected(const QPointF&)), this, SLOT(leftClick(const QPointF&)));
  connect(_principalPicker, SIGNAL(moved(const QPointF&)), this, SLOT(move(const QPointF&)));

  _qwtPlot->replot(); // creating the legend items

  QwtPlotItemList items = _qwtPlot->itemList(QwtPlotItem::Rtti_PlotHistogram);
  for(int i = 0; i < items.size(); i++)
  {
      QwtLegendItem* legendItem = qobject_cast<QwtLegendItem*>(legend->find(items[i]));
      if(legendItem)
    legendItem->setChecked(true);

  items[i]->setVisible(true);
  }

  _qwtPlot->setAutoReplot(true);
}
Beispiel #6
0
/*
void MyPlot2D::toggleCurve(long curveId) {
    QwtPlotCurve *c = curve(curveId);
    if ( c ) {
        c->setEnabled(!c->enabled());
        replot();
    }
}
*/
void MyPlot2D::enableLegend(bool value) {
    if (value) {
         // legend
         QwtLegend *legend = new QwtLegend;
         legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
         this->insertLegend(legend, QwtPlot::RightLegend);
    }
    else {
         this->insertLegend(NULL);
    }
    replot();
}
Beispiel #7
0
MavPlot::MavPlot(QWidget *parent) : QwtPlot(parent), _havePrintColors(false) {
    setAutoReplot(false);
    setTitle("MAV System Data Plot");
    setCanvasBackground(QColor(Qt::darkGray));

    // legend
    QwtLegend *legend = new QwtLegend;
    insertLegend(legend, QwtPlot::BottomLegend);
    #if (QWT_VERSION < QWT_VERSION_CHECK(6,1,0))
        legend->setItemMode(QwtLegend::ClickableItem);
        connect(this, SIGNAL(legendClicked(QwtPlotItem*)), SLOT(legendClicked(QwtPlotItem*)));
    #else
        legend->setDefaultItemMode(QwtLegendData::Clickable);        
        connect(legend, SIGNAL(clicked(const QVariant&, int)), SLOT(legendClickedNew(const QVariant&, int)));
    #endif    

    // grid
    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->enableXMin(true);
    #if (QWT_VERSION < QWT_VERSION_CHECK(6,1,0))
        grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
        grid->setMinPen(QPen(QColor(0x8, 0x8, 0x8), 0 , Qt::DotLine));
    #else
        grid->setMajorPen(QPen(Qt::gray, 0, Qt::DotLine));
        grid->setMinorPen(QPen(QColor(0x8, 0x8, 0x8), 0 , Qt::DotLine));
    #endif
    grid->attach(this);

    // axes
    //enableAxis(QwtPlot::yRight);
    setAxisTitle(QwtPlot::xBottom, "time");
    setAxisScaleDraw(QwtPlot::xBottom, new HumanReadableTime()); // no need to de-alloc or store, plot does it

    // A-B markers
    for (int i=0; i<2; i++) {
        _user_markers[i].setLineStyle(QwtPlotMarker::VLine);
        _user_markers[i].setLabelAlignment(Qt::AlignRight | Qt::AlignBottom);
        _user_markers[i].setLinePen(QPen(QColor(255, 140, 0), 0, Qt::SolidLine));
        _user_markers_visible[i] = false;
    }
    _user_markers[0].setLabel(QwtText("A"));
    _user_markers[1].setLabel(QwtText("B"));

    // data marker
    _data_marker.setLineStyle(QwtPlotMarker::VLine);
    _data_marker.setLinePen(QPen(QColor(255, 160, 47), 2, Qt::SolidLine));
    _data_marker.setLabel(QwtText("data"));
    _data_marker.setLabelAlignment(Qt::AlignTop | Qt::AlignRight);
    _data_marker_visible = false;
    _data_marker.setZ(9999); // higher value -> paint on top of everything else

    setAutoReplot(true);
}
Beispiel #8
0
void LineChart::setTooltip(QString t)
{
  tooltip = t;
  QwtPlot *p = plot();
  if (p == NULL)
    return;
  QwtLegend *l = p->legend();
  if (l == NULL)
    return;

  QwtLegendItem *legendItem = (QwtLegendItem *)l->find(this);

  if (legendItem != NULL)
    legendItem->setToolTip(tooltip);
}
Beispiel #9
0
TVPlot::TVPlot( QWidget *parent ):
    QwtPlot( parent )
{
    setTitle( "Watching TV during a weekend" );

    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    canvas->setPalette( Qt::gray );
    canvas->setBorderRadius( 10 );
    setCanvas( canvas );

    plotLayout()->setAlignCanvasToScales( true );

    setAxisTitle( QwtPlot::yLeft, "Number of People" );
    setAxisTitle( QwtPlot::xBottom, "Number of Hours" );

    QwtLegend *legend = new QwtLegend;
    legend->setDefaultItemMode( QwtLegendData::Checkable );
    insertLegend( legend, QwtPlot::RightLegend );

    populate();

    connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ),
        SLOT( showItem( const QVariant &, bool ) ) );

    replot(); // creating the legend items

    QwtPlotItemList items = itemList( QwtPlotItem::Rtti_PlotHistogram );
    for ( int i = 0; i < items.size(); i++ )
    {
        if ( i == 0 )
        {
            const QVariant itemInfo = itemToInfo( items[i] );

            QwtLegendLabel *legendLabel =
                qobject_cast<QwtLegendLabel *>( legend->legendWidget( itemInfo ) );
            if ( legendLabel )
                legendLabel->setChecked( true );

            items[i]->setVisible( true );
        }
        else
        {
            items[i]->setVisible( false );
        }
    }

    setAutoReplot( true );
}
Beispiel #10
0
void CpuPlot::showCurve( QwtPlotItem *item, bool on ) {
    item->setVisible( on );

    QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() );

    QList<QWidget *> legendWidgets =
        lgd->legendWidgets( itemToInfo( item ) );

    if ( legendWidgets.size() == 1 ) {
        QwtLegendLabel *legendLabel =
            qobject_cast<QwtLegendLabel *>( legendWidgets[0] );

        if ( legendLabel )
            legendLabel->setChecked( on );
    }

    replot();
}
Beispiel #11
0
void Graph::initLegend()
{
    QwtLegend *legend = new QwtLegend;
    legend->setDefaultItemMode(QwtLegendData::Checkable);
    insertLegend(legend, QwtPlot::BottomLegend);

    connect(legend, SIGNAL(checked(QVariant,bool,int)), SLOT(showCurve(QVariant,bool,int)));

    QwtPlotItemList l = this->itemList(QwtPlotItem::Rtti_PlotCurve);
    for(int i = 0; i < l.size(); ++i)
    {
        QwtPlotItem *curve = l[i];
        QVariant info = itemToInfo(curve);
        QWidget *w = legend->legendWidget(info);
        if(w && w->inherits("QwtLegendLabel"))
            ((QwtLegendLabel*)w)->setChecked(curve->isVisible());
    }
}
Beispiel #12
0
PlotWidget::PlotWidget(QWidget *parent) :
    QwtPlot(parent),
    ui(new Ui::PlotWidget)
{
    ui->setupUi(this);

    // Setup plot stuff
    setAutoReplot(false);
    canvas()->setBorderRadius( 10 );

    plotLayout()->setAlignCanvasToScales(true);

    QwtLegend *legend = new QwtLegend;
    legend->setItemMode(QwtLegend::CheckableItem);
    insertLegend(legend, QwtPlot::RightLegend);

    setAxisTitle(QwtPlot::xBottom, " Time [s]");
    setAxisScaleDraw(QwtPlot::xBottom,
                     new QwtScaleDraw());
    setAxisAutoScale(QwtPlot::xBottom, false);
    setAxisScale(QwtPlot::xBottom, 0, Market::EXPERIMENT_RUNNING_TIME);
    setAxisLabelRotation(QwtPlot::xBottom, -50.0);
    setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);

    setAxisTitle(QwtPlot::yLeft, " Price [$]");
    setAxisScaleDraw(QwtPlot::yLeft,
                     new QwtScaleDraw());
    setAxisScale(QwtPlot::yLeft, 0, MAX_PRICE_PLOT);
    setAxisLabelRotation(QwtPlot::yLeft, -50.0);
    setAxisLabelAlignment(QwtPlot::yLeft, Qt::AlignLeft | Qt::AlignBottom);

    // Setup the data
    asset1Data = new CircularBuffer((Market::EXPERIMENT_RUNNING_TIME)/2 + 4); // Running time, /2 for data every 2 seconds, + a safety buffer
    asset2Data = new CircularBuffer((Market::EXPERIMENT_RUNNING_TIME)/2 + 4);
    timeData = new CircularBuffer((Market::EXPERIMENT_RUNNING_TIME)/2 + 4);

    asset1Curve = new QwtPlotCurve("Asset 1");
    asset1Curve->setPen(QPen(Qt::red));
    asset1Curve->attach(this);

    asset2Curve = new QwtPlotCurve("Asset 2");
    asset2Curve->setPen(QPen(Qt::blue));
    asset2Curve->attach(this);
}
Beispiel #13
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    setTitle( "Trading Chart" );

    QwtDateScaleDraw *scaleDraw = new DateScaleDraw( Qt::UTC );
    QwtDateScaleEngine *scaleEngine = new QwtDateScaleEngine( Qt::UTC );

    setAxisTitle( QwtPlot::xBottom, QString( "2010" ) );
    setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
    setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );
    setAxisLabelRotation( QwtPlot::xBottom, -50.0 );
    setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );

    setAxisTitle( QwtPlot::yLeft, QString( "Price [EUR]" ) );

#if 0
    QwtLegend *legend = new QwtLegend;
    legend->setDefaultItemMode( QwtLegendData::Checkable );
    insertLegend( legend, QwtPlot::RightLegend );
#else
    Legend *legend = new Legend;
    insertLegend( legend, QwtPlot::RightLegend );
#endif

    populate();

    // LeftButton for the zooming
    // MidButton for the panning
    // RightButton: zoom out by 1
    // Ctrl+RighButton: zoom out to full size

    Zoomer* zoomer = new Zoomer( canvas() );
    zoomer->setMousePattern( QwtEventPattern::MouseSelect2,
        Qt::RightButton, Qt::ControlModifier );
    zoomer->setMousePattern( QwtEventPattern::MouseSelect3,
        Qt::RightButton );

    QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
    panner->setMouseButton( Qt::MidButton );

    connect( legend, SIGNAL( checked( QwtPlotItem *, bool, int ) ),
        SLOT( showItem( QwtPlotItem *, bool ) ) );
}
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);
}
	BatteryHistoryDialog::BatteryHistoryDialog (int histSize, QWidget *parent)
	: QDialog (parent)
	, Percent_ (new QwtPlotCurve (tr ("Percentage")))
	, Energy_ (new QwtPlotCurve (tr ("Energy rate")))
	{
		Ui_.setupUi (this);

		Ui_.PercentPlot_->setAxisAutoScale (QwtPlot::xBottom, false);
		Ui_.PercentPlot_->setAxisAutoScale (QwtPlot::yLeft, false);
		Ui_.PercentPlot_->setAxisScale (QwtPlot::xBottom, 0, histSize);
		Ui_.PercentPlot_->setAxisScale (QwtPlot::yLeft, 0, 100);
		Ui_.PercentPlot_->enableAxis (QwtPlot::yRight);
		Ui_.PercentPlot_->setAxisTitle (QwtPlot::yLeft, tr ("Percent"));
		Ui_.PercentPlot_->setAxisTitle (QwtPlot::yRight, tr ("Energy rate, W"));

		QColor percentColor (Qt::blue);
		Percent_->setPen (QPen (percentColor));
		percentColor.setAlpha (20);
		Percent_->setBrush (percentColor);

		Percent_->setRenderHint (QwtPlotItem::RenderAntialiased);
		Percent_->attach (Ui_.PercentPlot_);

		QColor energyColor (Qt::red);
		Energy_->setPen (QPen (energyColor));
		energyColor.setAlpha (20);
		Energy_->setBrush (energyColor);

		Energy_->setRenderHint (QwtPlotItem::RenderAntialiased);
		Energy_->setYAxis (QwtPlot::yRight);
		Energy_->attach (Ui_.PercentPlot_);

		QwtLegend *legend = new QwtLegend;
		legend->setItemMode (QwtLegend::ClickableItem);
		Ui_.PercentPlot_->insertLegend (legend, QwtPlot::BottomLegend);
	}
//---------------------------------------------------------------------------
JrkPlotDialog::JrkPlotDialog(jrk_variables *indata, jrk_pid_variables *pid_indata, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::JrkPlotDialog)
{
    int i;

    ui->setupUi(this);
    setLayout(ui->mainLayout);

    interval(200);
    history(10);
    setSamples();

    data_ptr = indata;
    pid_data_ptr = pid_indata;

    timeData = (double *) malloc(SAMPLES * sizeof(double));
    reset();

    ui->jrkPlot->setAutoReplot(false);
    ui->jrkPlot->canvas()->setBorderRadius(0);
    ui->jrkPlot->plotLayout()->setAlignCanvasToScales(true);
    ui->jrkPlot->setCanvasBackground(Qt::white);

    QwtLegend *legend = new QwtLegend;
    legend->setItemMode(QwtLegend::CheckableItem);
    ui->jrkPlot->insertLegend(legend, QwtPlot::RightLegend);

    ui->jrkPlot->setAxisTitle(QwtPlot::xBottom, "Seconds");
    ui->jrkPlot->setAxisScale(QwtPlot::xBottom, timeData[0], timeData[SAMPLES - 1]);

//    ui->jrkPlot->setAxisLabelRotation( QwtPlot::xBottom, -50.0 );
    ui->jrkPlot->setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );
    QwtScaleWidget *scaleWidget = ui->jrkPlot->axisWidget(QwtPlot::xBottom);
    i = QFontMetrics(scaleWidget->font()).height();
    scaleWidget->setMinBorderDist(0, i / 2);

    ui->jrkPlot->setAxisTitle(QwtPlot::yLeft, "%");
    ui->jrkPlot->setAxisScale(QwtPlot::yLeft, -100, 100);

    // picker, panner, zoomer
    plot_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
                                    QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
                                    ui->jrkPlot->canvas());
#if 0
    plot_picker->setStateMachine(new QwtPickerDragPointMachine());
    plot_picker->setRubberBandPen(QColor(Qt::black));
    plot_picker->setRubberBand(QwtPicker::CrossRubberBand );
#endif
    plot_picker->setTrackerPen(QColor(Qt::black));

    // panning with the left mouse button
    plot_panner = new QwtPlotPanner(ui->jrkPlot->canvas());
    plot_panner->setUpdatesEnabled(true);

    // zoom in/out with the wheel
    plot_zoomer = new QwtPlotMagnifier(ui->jrkPlot->canvas());

    // grid
    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->enableXMin( true );
    grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
    grid->setMinPen(QPen(Qt::black, 0, Qt::DotLine));
    grid->attach(ui->jrkPlot);

    // curves, scale is in %
    createCurve("Input",                Qt::gray,           false,  4095);
    createCurve("Target",               Qt::blue,           false,  4095);
    createCurve("Feedback",             Qt::darkBlue,       false,  4095);
    createCurve("Scaled feedback",      Qt::magenta,        false,  4095);
    createCurve("Error",                Qt::red,            true,   4095);
    createCurve("Integral",             Qt::darkGreen,      false,  1000);
    createCurve("Derivative",           Qt::yellow,         false,  1000);
    createCurve("Duty cycle target",    Qt::darkCyan,       false,  0600);
    createCurve("Duty cycle",           Qt::darkRed,        false,  0600);
    createCurve("Current",              Qt::black,          true,   0050);

    plot_timer = new QTimer(this);
    plot_timer->setInterval(INTERVAL);

    connect(plot_timer, SIGNAL(timeout()), this, SLOT(onUpdateGraph()));
    connect(ui->jrkPlot, SIGNAL(legendChecked(QwtPlotItem *, bool)),
            SLOT(showCurve(QwtPlotItem *, bool)));

#if 0
    connect(plot_picker, SIGNAL(moved(const QPoint &)),
            SLOT(picker_moved(const QPoint &)));
    connect(plot_picker, SIGNAL(selected(const QPolygon &)),
            SLOT(picker_selected(const QPolygon &)));
#endif

    connect(this, SIGNAL(finished(int)), this, SLOT(onFinished(int)));

//    plot_timer->start();
}
Beispiel #17
0
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();
}
Beispiel #18
0
//---------------------------------------------------------------------------
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;
}
Beispiel #19
0
void caStripPlot::setLegendAttribute(QColor c, QFont f, LegendAtttribute SW)
{
    int i;

#if QWT_VERSION < 0x060100
    for(i=0; i < NumberOfCurves; i++) {

        switch (SW) {
        case TEXT:
            if(thisLegendshow) {
                QwtText text;
                text.setText(legendText(i));
                qobject_cast<QwtLegendItem*>(this->legend()->find(curve[i]))->setText(text);
            }
            break;

        case FONT:

            if(getLegendEnabled()) {
                if(legend() != (QwtLegend*) 0) {
                    QList<QWidget *> list =  legend()->legendItems();
                    for (QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) {
                        QWidget *w = *it;
                        w->setFont(f);
                    }
                }
            }
            break;

        case COLOR:
            if(legend() != (QwtLegend*) 0) {
                QList<QWidget *> list =  legend()->legendItems();
                for (QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) {
                    QWidget *w = *it;
                    QPalette palette = w->palette();
                    palette.setColor( QPalette::WindowText, c); // for ticks
                    palette.setColor( QPalette::Text, c);       // for ticks' labels
                    w->setPalette (palette);
                    w->setFont(f);
                }
            }

            break;
        }

    }
#else
    i=0;
    foreach (QwtPlotItem *plt_item, itemList()) {
        if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
            QwtLegend *lgd = qobject_cast<QwtLegend *>(legend());
            QList<QWidget *> legendWidgets = lgd->legendWidgets(itemToInfo(plt_item));
            if ( legendWidgets.size() == 1 ) {
                QwtLegendLabel *b = qobject_cast<QwtLegendLabel *>(legendWidgets[0]);
                switch (SW) {

                case TEXT:

                    if(thisLegendshow) {

                        QwtText text;
                        text.setText(legendText(i++));
                        //printf("%s %s\n", b->plainText().toAscii().constData(), legendText(i-1).toAscii().constData());
                        b->setText(text);
                        b->update();


                    }
                    break;

                case FONT:
                    //printf("%s %s\n", b->plainText().toAscii().constData(), legendText(i-1).toAscii().constData());

                    b->setFont(f);
                    b->update();

                    break;

                case COLOR:

                    //printf("%s %s\n", b->plainText().toAscii().constData(), legendText(i-1).toAscii().constData());
                    QPalette palette = b->palette();
                    palette.setColor( QPalette::WindowText, c); // for ticks
                    palette.setColor( QPalette::Text, c);       // for ticks' labels
                    b->setPalette(palette);
                    b->update();

                    break;

                }


            }
        }
    }
#endif

}
Beispiel #20
0
int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    QwtPlot plot;
    plot.setTitle( "Plot Demo" );
    plot.setCanvasBackground( Qt::white );

    plot.setAxisScale( QwtPlot::xBottom, -1.0, 6.0 );

    QwtLegend *legend = new QwtLegend();
    legend->setDefaultItemMode( QwtLegendData::Checkable );
    plot.insertLegend( legend );

    for ( int i = 0; i < 4; i++ )
    {
        QwtPlotCurve *curve = new QwtPlotCurve();
        curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
        curve->setPen( Qt::blue );

        QBrush brush;
        QwtSymbol::Style style = QwtSymbol::NoSymbol;
        QString title;
        if ( i == 0 )
        {
            brush = Qt::magenta;
            style = QwtSymbol::Path;
            title = "Path";
        }
        else if ( i == 2 )
        {
            brush = Qt::red;
            style = QwtSymbol::Graphic;
            title = "Graphic";
        }
        else if ( i == 1 )
        {
            brush = Qt::yellow;
            style = QwtSymbol::SvgDocument;
            title = "Svg";
        }
        else if ( i == 3 )
        {
            brush = Qt::cyan;
            style = QwtSymbol::Pixmap;
            title = "Pixmap";
        }

        MySymbol *symbol = new MySymbol( style, brush );

        curve->setSymbol( symbol );
        curve->setTitle( title );
        curve->setLegendAttribute( QwtPlotCurve::LegendShowSymbol, true );
        curve->setLegendIconSize( QSize( 15, 18 ) );

        QPolygonF points;
        points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
            << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
            << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );

        points.translate( 0.0, i * 2.0 );

        curve->setSamples( points );
        curve->attach( &plot );
    }

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

    return a.exec();
}
/*!
  \brief Insert a legend

  If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend
  the legend will be organized in one column from top to down.
  Otherwise the legend items will be placed in a table
  with a best fit number of columns from left to right.

  insertLegend() will set the plot widget as parent for the legend.
  The legend will be deleted in the destructor of the plot or when 
  another legend is inserted.

  Legends, that are not inserted into the layout of the plot widget
  need to connect to the legendDataChanged() signal. Calling updateLegend()
  initiates this signal for an initial update. When the application code
  wants to implement its own layout this also needs to be done for
  rendering plots to a document ( see QwtPlotRenderer ).

  \param legend Legend
  \param pos The legend's position. For top/left position the number
             of columns will be limited to 1, otherwise it will be set to
             unlimited.

  \param ratio Ratio between legend and the bounding rectangle
               of title, canvas and axes. The legend will be shrunk
               if it would need more space than the given ratio.
               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
               it will be reset to the default ratio.
               The default vertical/horizontal ratio is 0.33/0.5.

  \sa legend(), QwtPlotLayout::legendPosition(),
      QwtPlotLayout::setLegendPosition()
*/
void QwtPlot::insertLegend( QwtAbstractLegend *legend,
    QwtPlot::LegendPosition pos, double ratio )
{
    d_data->layout->setLegendPosition( pos, ratio );

    if ( legend != d_data->legend )
    {
        if ( d_data->legend && d_data->legend->parent() == this )
            delete d_data->legend;

        d_data->legend = legend;

        if ( d_data->legend )
        {
            connect( this, 
                SIGNAL( legendDataChanged( 
                    const QVariant &, const QList<QwtLegendData> & ) ),
                d_data->legend, 
                SLOT( updateLegend( 
                    const QVariant &, const QList<QwtLegendData> & ) ) 
            );

            if ( d_data->legend->parent() != this )
                d_data->legend->setParent( this );

            qwtEnableLegendItems( this, false );
            updateLegend();
            qwtEnableLegendItems( this, true );

            QwtLegend *lgd = qobject_cast<QwtLegend *>( legend );
            if ( lgd )
            {
                switch ( d_data->layout->legendPosition() )
                {
                    case LeftLegend:
                    case RightLegend:
                    {
                        if ( lgd->maxColumns() == 0     )
                            lgd->setMaxColumns( 1 ); // 1 column: align vertical
                        break;
                    }
                    case TopLegend:
                    case BottomLegend:
                    {
                        lgd->setMaxColumns( 0 ); // unlimited
                        break;
                    }
                    default:
                        break;
                }
            }

            QWidget *previousInChain = NULL;
            switch ( d_data->layout->legendPosition() )
            {
                case LeftLegend:
                {
                    previousInChain = axisWidget( QwtPlot::xTop );
                    break;
                }
                case TopLegend:
                {
                    previousInChain = this;
                    break;
                }
                case RightLegend:
                {
                    previousInChain = axisWidget( QwtPlot::yRight );
                    break;
                }
                case BottomLegend:
                {
                    previousInChain = footerLabel();
                    break;
                }
            }

            if ( previousInChain )
                qwtSetTabOrder( previousInChain, legend, true );
        }
    }
Beispiel #22
0
AmpPlot::AmpPlot(QwtPlot *plot)
{

//TODO
//    _picker = new QwtPicker(canvas());
//    _picker->setStateMachine(new QwtPickerDragRectMachine());
//    _picker->setTrackerMode(QwtPicker::ActiveOnly);
//    _picker->setRubberBand(QwtPicker::RectRubberBand);

    _plot = plot;

    _panner = new QwtPlotPanner(_plot->canvas()); //Panning with the mouse
    _panner->setOrientations(Qt::Horizontal);
    //connect(_panner, SIGNAL(moved(int,int)), this, SLOT(pannerMoved(int,int)));

    _magnifier = new QwtPlotMagnifier(_plot->canvas()); //Zooming with the wheel

    _plot->canvas()->setBorderRadius(5);
    _plot->setCanvasBackground(Qt::white);
    _plot->plotLayout()->setAlignCanvasToScales(true);

    QwtLegend *legend = new QwtLegend;
    _plot->insertLegend(legend,QwtPlot::RightLegend);
    legend->setItemMode(QwtLegend::CheckableItem);
    connect(_plot,SIGNAL(legendChecked(QwtPlotItem*,bool)),SLOT(showCurve(QwtPlotItem*,bool)));

    _xMax = DEFAULT_X_MAX;
    _yMax = DEFAULT_Y_MAX;

    _plot->setAxisTitle(QwtPlot::xBottom, "ms");
    _plot->setAxisScale(QwtPlot::xBottom,0,_xMax);

    QwtScaleWidget *scaleWidget = _plot->axisWidget(QwtPlot::xBottom);
    const int fmh = QFontMetrics(scaleWidget->font()).height();
    scaleWidget->setMinBorderDist(0, fmh*2);

    _plot->setAxisTitle(QwtPlot::yLeft,"mA");
    _plot->setAxisAutoScale(QwtPlot::yLeft, true);

    _dataCurve = new QwtPlotCurve("mA");
    _dataCurve->attach(_plot);
    _dataCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
    _dataCurve->setVisible(_plot);

    _meanCurve = new QwtPlotCurve("avg mean");
    _meanCurve->attach(_plot);
    _meanCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
    _meanCurve->setPen(QPen(Qt::red));

    _maxCurve = new QwtPlotCurve("max");
    _maxCurve->attach(_plot);
    _maxCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
    _maxCurve->setPen(QPen(Qt::darkMagenta));

    _currentMeanCurve = new QwtPlotCurve("mean");
    _currentMeanCurve->attach(_plot);
    _currentMeanCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
    _currentMeanCurve->setPen(QPen(Qt::blue));

    showCurve(_dataCurve, true);
    showCurve(_meanCurve, false);
    showCurve(_maxCurve, false);
    showCurve(_currentMeanCurve, true);

    _time = new QTime();
    _time->start();

    _meanData.append(0.0);
    _meanTime.append(0.0);
    _meanData.append(0.0);
    _meanTime.append(0.0);

    _maxData.append(0.0);
    _maxTime.append(0.0);
    _maxData.append(0.0);
    _maxTime.append(0.0);

    _pauseTime = 0;


    _dataSource = NULL;

    _loadedCurve = NULL;
}
Beispiel #23
0
CpuPlot::CpuPlot( QWidget *parent ):
    QwtPlot( parent ),
    dataCount( 0 ) {

        setAutoReplot( false );

        QwtPlotCanvas *canvas = new QwtPlotCanvas();
        canvas->setBorderRadius( 10 );

        setCanvas( canvas );

        plotLayout()->setAlignCanvasToScales( true );

        QwtLegend *legend = new QwtLegend;
        legend->setDefaultItemMode( QwtLegendData::Checkable );
        insertLegend( legend, QwtPlot::RightLegend );

        setAxisTitle( QwtPlot::xBottom, "System Uptime [h:m:s]" );
        setAxisScaleDraw( QwtPlot::xBottom,
                new TimeScaleDraw( cpuStat.upTime() ) );
        setAxisScale( QwtPlot::xBottom, 0, HISTORY );
        //setAxisLabelRotation( QwtPlot::xBottom, -50.0 );
        setAxisLabelRotation( QwtPlot::xBottom, 0.0 );
        setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );

        /*
           In situations, when there is a label at the most right position of the
           scale, additional space is needed to display the overlapping part
           of the label would be taken by reducing the width of scale and canvas.
           To avoid this "jumping canvas" effect, we add a permanent margin.
           We don't need to do the same for the left border, because there
           is enough space for the overlapping label below the left scale.
           */

        QwtScaleWidget *scaleWidget = axisWidget( QwtPlot::xBottom );
        const int fmh = QFontMetrics( scaleWidget->font() ).height();
        scaleWidget->setMinBorderDist( 0, fmh / 2 );

        setAxisTitle( QwtPlot::yLeft, "Cpu Usage [%]" );
        setAxisScale( QwtPlot::yLeft, 0, 100 );


        //attach方法将元素关联到qwtplot空间上
        Background *bg = new Background();
        bg->attach( this );

        CpuPieMarker *pie = new CpuPieMarker();
        pie->attach( this );

        CpuCurve *curve;


        curve = new CpuCurve( "System" );
        curve->setColor( Qt::red );
        curve->attach( this );

        data[System].curve = curve;

        curve = new CpuCurve( "User" );
        curve->setColor( Qt::blue );
        curve->setZ( curve->z() - 1 );
        curve->attach( this );
        data[User].curve = curve;

        curve = new CpuCurve( "Total" );
        curve->setColor( Qt::black );
        curve->setZ( curve->z() - 2 );
        curve->attach( this );
        data[Total].curve = curve;

        curve = new CpuCurve( "Idle" );
        curve->setColor( Qt::darkCyan );
        curve->setZ( curve->z() - 3 );
        curve->attach( this );
        data[Idle].curve = curve;

        showCurve( data[System].curve, true );
        showCurve( data[User].curve, true );
        showCurve( data[Total].curve, false );
        showCurve( data[Idle].curve, false );

        for ( int i = 0; i < HISTORY; i++ )
            timeData[HISTORY - 1 - i] = i;

        ( void )startTimer( 1000 ); // 1 second

        connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ),
                SLOT( legendChecked( const QVariant &, bool ) ) );
    }
Beispiel #24
0
QwtGrapher::QwtGrapher(QWidget* parent):
    QwtPlot(parent) {
    m_values = new TwoDArray<double>(3,100);
    plotLayout()->setAlignCanvasToScales(true);
    QwtLegend *legend = new QwtLegend;
    legend->setItemMode(QwtLegend::CheckableItem);
    insertLegend(legend, QwtPlot::RightLegend);

    setAxisTitle(QwtPlot::xBottom, " FitnessCases");
    /*setAxisScaleDraw(QwtPlot::xBottom,
     new TimeScaleDraw(cpuStat.upTime()));
     setAxisScale(QwtPlot::xBottom, 0, HISTORY);
     setAxisLabelRotation(QwtPlot::xBottom, -50.0);
     setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
     */
    /*
     In situations, when there is a label at the most right position of the
     scale, additional space is needed to display the overlapping part
     of the label would be taken by reducing the width of scale and canvas.
     To avoid this "jumping canvas" effect, we add a permanent margin.
     We don't need to do the same for the left border, because there
     is enough space for the overlapping label below the left scale.
     */

    QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
    const int fmh = QFontMetrics(scaleWidget->font()).height();
    scaleWidget->setMinBorderDist(0, fmh / 2);

    setAxisTitle(QwtPlot::yLeft, "Ouput") ;
    //setAxisScale(QwtPlot::yLeft, 0, 100);

    // Background *bg = new Background();
    //bg->attach(this);

    /*CpuPieMarker *pie = new CpuPieMarker();
     pie->attach(this);
     */
    QwtPlotCurve *curve;

    curve = new QwtPlotCurve("Best");
    curve->setPen(QColor(Qt::green));
    curve->attach(this);
    m_curves[0] = curve;

    curve = new QwtPlotCurve("Average");
    curve->setPen(QColor(Qt::blue));
    curve->setZ(curve->z() - 1);
    curve->attach(this);
    m_curves[1] = curve;

    curve = new QwtPlotCurve("Worst");
    curve->setPen(QColor(Qt::black));
    curve->setZ(curve->z() - 2);
    curve->attach(this);
    m_curves[2] = curve;

    showCurve(m_curves[0], true);
    showCurve(m_curves[1], true);
    showCurve(m_curves[2], true);

    connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
            SLOT(showCurve(QwtPlotItem *, bool)));
}