Exemplo n.º 1
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    setAutoReplot( false );

    setTitle( "Frequency Response of a Second-Order System" );

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

    setCanvas( canvas );
    setCanvasBackground( QColor( "MidnightBlue" ) );

    // legend
    QwtLegend *legend = new QwtLegend;
    insertLegend( legend, QwtPlot::BottomLegend );

    // grid
    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->enableXMin( true );
    grid->setMajorPen( Qt::white, 0, Qt::DotLine );
    grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
    grid->attach( this );

    // axes
    enableAxis( QwtPlot::yRight );
    setAxisTitle( QwtPlot::xBottom, "Normalized Frequency" );
    setAxisTitle( QwtPlot::yLeft, "Amplitude [dB]" );
    setAxisTitle( QwtPlot::yRight, "Phase [deg]" );

    setAxisMaxMajor( QwtPlot::xBottom, 6 );
    setAxisMaxMinor( QwtPlot::xBottom, 9 );
    setAxisScaleEngine( QwtPlot::xBottom, new QwtLogScaleEngine );

    // curves
    d_curve1 = new QwtPlotCurve( "Amplitude" );
    d_curve1->setRenderHint( QwtPlotItem::RenderAntialiased );
    d_curve1->setPen( Qt::yellow );
    d_curve1->setLegendAttribute( QwtPlotCurve::LegendShowLine );
    d_curve1->setYAxis( QwtPlot::yLeft );
    d_curve1->attach( this );

    d_curve2 = new QwtPlotCurve( "Phase" );
    d_curve2->setRenderHint( QwtPlotItem::RenderAntialiased );
    d_curve2->setPen( Qt::cyan );
    d_curve2->setLegendAttribute( QwtPlotCurve::LegendShowLine );
    d_curve2->setYAxis( QwtPlot::yRight );
    d_curve2->attach( this );

    // marker
    d_marker1 = new QwtPlotMarker();
    d_marker1->setValue( 0.0, 0.0 );
    d_marker1->setLineStyle( QwtPlotMarker::VLine );
    d_marker1->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom );
    d_marker1->setLinePen( Qt::green, 0, Qt::DashDotLine );
    d_marker1->attach( this );

    d_marker2 = new QwtPlotMarker();
    d_marker2->setLineStyle( QwtPlotMarker::HLine );
    d_marker2->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom );
    d_marker2->setLinePen( QColor( 200, 150, 0 ), 0, Qt::DashDotLine );
    d_marker2->setSymbol( new QwtSymbol( QwtSymbol::Diamond,
        QColor( Qt::yellow ), QColor( Qt::green ), QSize( 8, 8 ) ) );
    d_marker2->attach( this );

    setDamp( 0.0 );

    setAutoReplot( true );
}
Exemplo n.º 2
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( QwtAxis::xBottom, " System Uptime [h:m:s]" );
    setAxisScaleDraw( QwtAxis::xBottom,
        new TimeScaleDraw( cpuStat.upTime() ) );
    setAxisScale( QwtAxis::xBottom, 0, HISTORY );
    setAxisLabelRotation( QwtAxis::xBottom, -50.0 );
    setAxisLabelAlignment( QwtAxis::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( QwtAxis::xBottom );
    const int fmh = QFontMetrics( scaleWidget->font() ).height();
    scaleWidget->setMinBorderDist( 0, fmh / 2 );

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

    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 ) ) );
}
Exemplo n.º 3
0
int QwtPlotWidget::interpret(const char *command, double *x, double *y)
{
  if(command == NULL) return -1;
  line = command;

  if     (isCommand("setCurveData("))
  {
    if(x == NULL) return -1;
    if(y == NULL) return -1;
    int c,count;
    sscanf(command,"setCurveData(%d,%d",&c,&count);
    if(c<0 || c>=nCurves) return -1;
    if(curves[c] != NULL) curves[c]->setData(x,y,count);
  }
  else if(isCommand("replot("))
  {
    replot();
  }
  else if(isCommand("setTitle("))
  {
    QString text;
    if(getText(command,text) != 0) return -1;
    setTitle(text);
  }
  else if(isCommand("setCanvasBackground("))
  {
    int r,g,b;
    sscanf(command,"setCanvasBackground(%d,%d,%d",&r,&g,&b);
    setCanvasBackground(QColor(r,g,b));
  }
  else if(isCommand("enableOutline("))
  {
    int val;
    sscanf(command,"enableOutline(%d",&val);
    if( val == 0 || val == 1 )
    {
      //xx enableOutline(val);
      //xx setOutlineStyle(Qwt::Rect );
    }
    else
    {
      //xx enableOutline( 1 );
      //xx setOutlineStyle(Qwt::Cross );
    }
  }
  else if(isCommand("setOutlinePen("))
  {
    int r,g,b;
    sscanf(command,"setOutlinePen(%d,%d,%d",&r,&g,&b);
    //xx setOutlinePen(QColor(r,g,b));
  }
  else if(isCommand("setAutoLegend("))
  {
    int val;
    sscanf(command,"setAutoLegend(%d",&val);
    //xx setAutoLegend(val);
    autolegend = val;
  }
  else if(isCommand("enableLegend("))
  {
    int val;
    sscanf(command,"enableLegend(%d",&val);
    enablelegend = val;
  }
  else if(isCommand("setLegendPos("))
  {
    int val;
    sscanf(command,"setLegendPos(%d",&val);
    if(opt.arg_debug) printf("SetLegendPos begin\n");;
    if(legend == NULL) legend = new QwtLegend();
    if(opt.arg_debug) printf("SetLegendPos 1\n");;
    legend->setItemMode(QwtLegend::ClickableItem);
    if(opt.arg_debug) printf("SetLegendPos 2\n");;
    switch(val)
    {
      case PV::LeftLegend:
        insertLegend(legend, QwtPlot::LeftLegend);
        break;
      case PV::RightLegend:
        insertLegend(legend, QwtPlot::RightLegend);
        break;
      case PV::TopLegend:
        insertLegend(legend, QwtPlot::TopLegend);
        break;
      default:
        insertLegend(legend, QwtPlot::BottomLegend);
        break;
    }
    if(opt.arg_debug) printf("SetLegendPos end\n");;
  }
  else if(isCommand("setLegendFrameStyle("))
  {
    int val;
    sscanf(command,"setLegendFrameStyle(%d",&val);
    legendframestyle = val;
    if(legend != NULL) legend->setFrameStyle(legendframestyle);
  }
  else if(isCommand("enableGridXMin("))
  {
    grid.enableXMin(true);
  }
  else if(isCommand("setGridMajPen("))
  {
    int r,g,b,style;
    sscanf(command,"setGridMajPen(%d,%d,%d,%d",&r,&g,&b,&style);
    grid.setMajPen(QPen(QColor(r,g,b),0,(Qt::PenStyle) style));
  }
  else if(isCommand("setGridMinPen("))
  {
    int r,g,b,style;
    sscanf(command,"setGridMinPen(%d,%d,%d,%d",&r,&g,&b,&style);
    grid.setMinPen(QPen(QColor(r,g,b),0,(Qt::PenStyle) style));
  }
  else if(isCommand("enableAxis("))
  {
    int pos;
    sscanf(command,"enableAxis(%d",&pos);
    enableAxis(pos);
  }
  else if(isCommand("setAxisTitle("))
  {
    int pos;
    QString text;
    sscanf(command,"setAxisTitle(%d",&pos);
    if(getText(command,text) != 0) return -1;
    setAxisTitle(pos,text);
  }
  else if(isCommand("setAxisOptions("))
  {
    int pos,val;
    sscanf(command,"setAxisOptions(%d,%d",&pos,&val);
    //xx setAxisOptions(pos,val);
  }
  else if(isCommand("setAxisMaxMajor("))
  {
    int pos,val;
    sscanf(command,"setAxisMaxMajor(%d,%d",&pos,&val);
    setAxisMaxMajor(pos,val);
  }
  else if(isCommand("setAxisMaxMinor("))
  {
    int pos,val;
    sscanf(command,"setAxisMaxMinor(%d,%d",&pos,&val);
    setAxisMaxMinor(pos,val);
  }
  else if(isCommand("insertCurve("))
  {
    int pos;
    QString text;
    sscanf(command,"insertCurve(%d",&pos);
    if(getText(command,text) != 0) return -1;
    if(pos<0 || pos>=nCurves) return -1;
    //xx removeCurve( curves[pos] );
    //xx curves[pos] = insertCurve(text);
    if(curves[pos] != NULL) delete curves[pos];
    if(opt.arg_debug) printf("new QwtPlotCurve(%s)\n",(const char *) text.toUtf8());
    curves[pos] = new QwtPlotCurve(text);
    curves[pos]->attach(this);
    if(legend != NULL)
    {
      QWidget *w = legend->find(curves[pos]);
      if(w != NULL) 
      {
        if(opt.arg_debug) printf("setChecked(%d)\n",autolegend);
        ((QwtLegendItem *)w)->setChecked(autolegend);
      }
    }
    replot();

    //if(autolegend && legend != NULL) curves[pos]->updateLegend(legend);
  }
  else if(isCommand("removeCurve("))
  {
    int pos;
    sscanf(command,"removeCurve(%d",&pos);
    if(pos<0 || pos>=nCurves) return -1;
    //xx removeCurve( curves[pos] );
    if(curves[pos] != NULL) curves[pos]->detach();
    if(curves[pos] != NULL) delete curves[pos];
    curves[pos] = NULL;
  }
  else if(isCommand("setCurvePen("))
  {
    int pos,r,g,b,width,style;
    sscanf(command,"setCurvePen(%d,%d,%d,%d,%d,%d",&pos,&r,&g,&b,&width,&style);
    if(pos<0 || pos>=nCurves) return -1;
    //xx setCurvePen(curves[pos],QPen(QColor(r,g,b),width,(Qt::PenStyle) style));
    QPen pen(QColor(r,g,b));
    pen.setWidth(width);
    pen.setStyle((Qt::PenStyle) style);
    if(curves[pos] != NULL) curves[pos]->setPen(pen);
  }
  else if(isCommand("setCurveSymbol("))
  {
    int pos,symbol,r1,g1,b1,r2,g2,b2,w,h;
    sscanf(command,"setCurveSymbol(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&pos,&symbol,
                    &r1,&g1,&b1,&r2,&g2,&b2,&w,&h);
    if(pos<0 || pos>=nCurves) return -1;
    //xx setCurveSymbol(curves[pos], QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h)));
    if(curves[pos] != NULL) curves[pos]->setSymbol(QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h)));
  }
  else if(isCommand("setCurveYAxis("))
  {
    int pos,pos2;
    sscanf(command,"setCurveYAxis(%d,%d",&pos,&pos2);
    if(pos<0 || pos>=nCurves) return -1;
    //xx setCurveYAxis(curves[pos],pos2); rl2013
    if(curves[pos] != NULL) curves[pos]->setYAxis(pos2);
  }
  else if(isCommand("insertMarker("))
  {
    int pos;
    sscanf(command,"insertMarker(%d",&pos);
    if(pos<0 || pos>=nMarker) return -1;
    //xx marker[pos] = insertMarker();
    if(marker[pos] != NULL) delete marker[pos];
    marker[pos] = new QwtPlotMarker();
    marker[pos]->attach(this);
  }
  else if(isCommand("setMarkerLineStyle("))
  {
    int pos,style;
    sscanf(command,"setMarkerLineStyle(%d,%d",&pos,&style);
    if(pos<0 || pos>=nMarker) return -1;
    //xx setMarkerLineStyle(marker[pos],(QwtMarker::LineStyle) style);
    if(marker[pos] != NULL) marker[pos]->setLineStyle((QwtPlotMarker::LineStyle) style);
  }
  else if(isCommand("setMarkerPos("))
  {
    int pos;
    float x,y;
    sscanf(command,"setMarkerPos(%d,%f,%f",&pos,&x,&y);
    if(pos<0 || pos>=nMarker) return -1;
    //xx setMarkerPos(marker[pos],x,y);
    if(marker[pos] != NULL) marker[pos]->setValue(x,y);
  }
  else if(isCommand("setMarkerLabelAlign("))
  {
    int pos,align;
    sscanf(command,"setMarkerLabelAlign(%d,%d",&pos,&align);
    if(pos<0 || pos>=nMarker) return -1;
    //xx setMarkerLabelAlign(marker[pos],align);
    if(marker[pos] != NULL) marker[pos]->setLabelAlignment((Qt::Alignment) align);
  }
  else if(isCommand("setMarkerLabel("))
  {
    int pos;
    QString text;
    sscanf( command, "setMarkerLabel(%d",&pos );
    if(getText(command, text) != 0 ) return -1;
    //xx setMarkerLabel(marker[pos], text );
    if(marker[pos] != NULL) marker[pos]->setLabel(text);
  }
  else if(isCommand("setMarkerPen("))
  {
    int pos,r,g,b,style;
    sscanf(command,"setMarkerPen(%d,%d,%d,%d,%d",&pos,&r,&g,&b,&style);
    if(pos<0 || pos>=nMarker) return -1;
    //xx setMarkerPen(marker[pos],QPen(QColor(r,g,b),0,(Qt::PenStyle) style));
    if(marker[pos] != NULL) marker[pos]->setLinePen(QPen(QColor(r,g,b)));
  }
  else if(isCommand("setMarkerFont("))
  {
    int pos,size,style;
    QString family;
    sscanf(command,"setMarkerFont(%d,%d,%d",&pos,&size,&style);
    if(pos<0 || pos>=nMarker) return -1;
    if(getText(command,family) != 0) return -1;
    //xx setMarkerFont(marker[pos],QFont(family,size,style));
  }
  else if(isCommand("setMarkerSymbol("))
  {
    int pos,symbol,r1,g1,b1,r2,g2,b2,w,h;
    sscanf(command,"setMarkerSymbol(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
                  &pos,&symbol,&r1,&g1,&b1,&r2,&g2,&b2,&w,&h);
    if(pos<0 || pos>=nMarker) return -1;
    //xx setMarkerSymbol(marker[pos], QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h)));
    if(marker[pos] != NULL) marker[pos]->setSymbol(QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h)));
  }
  else if(isCommand("insertLineMarker("))
  {
    int pos,pos2;
    QString text;
    sscanf(command,"insertLineMarker(%d,%d",&pos,&pos2);
    if(getText(command,text) != 0) return -1;
    if(pos<0 || pos>=nMarker) return -1;
    //xx marker[pos] = insertLineMarker(text, pos2);
    if(marker[pos] != NULL) delete marker[pos];
    marker[pos] = new QwtPlotMarker();
    marker[pos]->attach(this);
    if(marker[pos] != NULL) marker[pos]->setLabel(text);
  }
  else if( isCommand("setAxisScaleDraw("))
  {
    int pos;
    QString qtext;
    char text[1024];
    sscanf( command, "setAxisScaleDraw(%d",&pos );
    if( getText(command, qtext) != 0 ) return -1;
    if(qtext.length() < ((int) sizeof(text) -1))
    {
      strcpy(text,qtext.toUtf8());
    }
    else
    {
      strcpy(text,"text too long");
    }
    if(opt.arg_debug) printf("setAxisScaleDraw(%s)\n",text);
    setAxisScaleDraw( pos, new UserScaleDraw( text ));
  }
  else if( isCommand("setAxisScale("))
  {
    int pos;
    float min,max,step;
    sscanf( command, "setAxisScale(%d,%f,%f,%f",&pos ,&min, &max, &step);
    if(opt.arg_debug) printf("setAxisScale(%d,%f,%f,%f)\n",pos,min,max,step);
    setAxisScale(pos,min,max,step);
  }
  else
  {
    return -1;
  }

  return 0;
}
Exemplo n.º 4
0
AllPlot::AllPlot(AllPlotWindow *parent, MainWindow *mainWindow):
    QwtPlot(parent),
    rideItem(NULL),
    unit(0),
    shade_zones(true),
    showPowerState(3),
    showHrState(Qt::Checked),
    showSpeedState(Qt::Checked),
    showCadState(Qt::Checked),
    showAltState(Qt::Checked),
    bydist(false),
    parent(parent)
{
    boost::shared_ptr<QSettings> settings = GetApplicationSettings();
    unit = settings->value(GC_UNIT);

    referencePlot = NULL;

    useMetricUnits = (unit.toString() == "Metric");

    // options for turning off/on shading on all plot
    // will come in with a future patch, for now we
    // enable zone shading by default, since this is
    // the current default behaviour
    if (false) shade_zones = false;
    else shade_zones = true;

    smooth = settings->value(GC_RIDE_PLOT_SMOOTHING).toInt();
    if (smooth < 1) smooth = 1;

    // create a background object for shading
    bg = new AllPlotBackground(this);
    bg->attach(this);

    insertLegend(new QwtLegend(), QwtPlot::BottomLegend);
    setCanvasBackground(GColor(CPLOTBACKGROUND));

    setXTitle();

    wattsCurve = new QwtPlotCurve(tr("Power"));

    hrCurve = new QwtPlotCurve(tr("Heart Rate"));
    hrCurve->setYAxis(yLeft2);

    speedCurve = new QwtPlotCurve(tr("Speed"));
    speedCurve->setYAxis(yRight);

    cadCurve = new QwtPlotCurve(tr("Cadence"));
    cadCurve->setYAxis(yLeft2);

    altCurve = new QwtPlotCurve(tr("Altitude"));
    // altCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
    altCurve->setYAxis(yRight2);

    intervalHighlighterCurve = new QwtPlotCurve();
    intervalHighlighterCurve->setYAxis(yLeft);
    intervalHighlighterCurve->setData(IntervalPlotData(this, mainWindow));
    intervalHighlighterCurve->attach(this);
    this->legend()->remove(intervalHighlighterCurve); // don't show in legend

    grid = new QwtPlotGrid();
    grid->enableX(false);
    grid->attach(this);

    // get rid of nasty blank space on right of the plot
    plotLayout()->setAlignCanvasToScales(true);

    configChanged(); // set colors
}
ribi::QtToolTestApproximatorXyzMainDialog::QtToolTestApproximatorXyzMainDialog(QWidget *parent) noexcept :
  QtHideAndShowDialog(parent),
  ui(new Ui::QtToolTestApproximatorXyzMainDialog),
  m_approximator(),
  m_data(CreateData())
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);

  //Set up the plots and curves
  GetPlot(0)->setTitle("Approximator, for z = 0.0");
  GetPlot(1)->setTitle("Approximator, for z = 0.5");
  GetPlot(2)->setTitle("Approximator, for z = 1.0");
  for (auto i=0; i!=m_n_curves; ++i)
  {
    const auto plot = GetPlot(i);
    plot->setAxisTitle(QwtPlot::xBottom,"X");
    plot->setAxisTitle(QwtPlot::yLeft,"Y");
    #ifdef _WIN32
    plot->setCanvasBackground(QBrush(QColor(255,255,255)));
    #else
    plot->setCanvasBackground(QColor(255,255,255));
    #endif

    const auto curve_values = GetCurveValues(i);
    assert(curve_values);
    curve_values->setTitle("Points");
    curve_values->attach(plot.get());
    curve_values->setStyle(QwtPlotCurve::Dots);
    curve_values->setPen(QPen(QColor(255,0,0),5));

    const auto curve_approximation = GetCurveApproximation(i);
    assert(curve_approximation);
    curve_approximation->setTitle("Approximation");
    curve_approximation->attach(plot.get());
    curve_approximation->setStyle(QwtPlotCurve::Dots);
    curve_approximation->setPen(QPen(QColor(0,0,255),3));

    //Add grid
    {
      QwtPlotGrid * const grid = new QwtPlotGrid;
      grid->setPen(QPen(QColor(128,128,128)));
      grid->attach(plot.get());
    }
    //Add zoomer
    {
      new QwtPlotZoomer(plot->canvas());
    }
    //Add legend
    {
      QwtLegend * const legend = new QwtLegend;
      legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
      plot->insertLegend(legend, QwtPlot::RightLegend);
    }

    plot->setAxisScale(
      QwtPlot::xBottom,
      static_cast<double>(ui->box_int_x->minimum()),
      static_cast<double>(ui->box_int_x->maximum())
    );
    plot->setAxisScale(
      QwtPlot::yLeft,
      static_cast<double>(ui->box_double_y->minimum()),
      static_cast<double>(ui->box_double_y->maximum())
    );

    //Add to dialog
    assert(ui->verticalLayout->layout());
    ui->verticalLayout->layout()->addWidget(plot.get());
  }




  //Add some nice testing values
  ui->box_int_x->setValue(ui->box_int_x->minimum() / 2);
  ui->box_double_y->setValue(ui->box_double_y->maximum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->minimum() / 4);
  ui->box_double_y->setValue(ui->box_double_y->minimum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->maximum() / 4);
  ui->box_double_y->setValue(ui->box_double_y->maximum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->maximum() / 2);
  ui->box_double_y->setValue(ui->box_double_y->minimum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(0);
  ui->box_double_y->setValue(0.0);
}
void QxrdSynchronizedAcquisitionPlot::init(QxrdSynchronizedAcquisitionPlotSettingsWPtr settings)
{
  QcepPlot::init(settings);

  insertLegend(m_Legend, QwtPlot::BottomLegend);
}
Exemplo n.º 7
0
//
//  Initialize main window
//
DataPlot::DataPlot(QWidget *parent):
    QwtPlot(parent),
    d_interval(0),
    d_timerId(-1)
{
    // Disable polygon clipping
    QwtPainter::setDeviceClipping(false);

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

#if QT_VERSION >= 0x040000
#ifdef Q_WS_X11
    /*
       Qt::WA_PaintOnScreen is only supported for X11, but leads
       to substantial bugs with Qt 4.2.x/Windows
     */
    canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
#endif
#endif

    alignScales();
    
    //  Initialize data
    for (int i = 0; i< PLOT_SIZE; i++)
    {
        d_x[i] = 0.5 * i;     // time axis
        d_y[i] = 0;
        d_z[i] = 0;
    }

    // Assign a title
    setTitle("A Test for High Refresh Rates");
    insertLegend(new QwtLegend(), QwtPlot::BottomLegend);

    // Insert new curves
    QwtPlotCurve *cRight = new QwtPlotCurve("Data Moving Right");
    cRight->attach(this);

    QwtPlotCurve *cLeft = new QwtPlotCurve("Data Moving Left");
    cLeft->attach(this);

    // Set curve styles
    cRight->setPen(QPen(Qt::red));
    cLeft->setPen(QPen(Qt::blue));

    // Attach (don't copy) data. Both curves use the same x array.
    cRight->setRawData(d_x, d_y, PLOT_SIZE);
    cLeft->setRawData(d_x, d_z, PLOT_SIZE);

#if 0
    //  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(this);
#endif

    // Axis 
    setAxisTitle(QwtPlot::xBottom, "Time/seconds");
    setAxisScale(QwtPlot::xBottom, 0, 100);

    setAxisTitle(QwtPlot::yLeft, "Values");
    setAxisScale(QwtPlot::yLeft, -1.5, 1.5);
    
    setTimerInterval(0.0); 
}
Exemplo n.º 8
0
void caStripPlot::defineCurves(QStringList titres, units unit, double period, int width, int nbCurves)
{
    int min, max;
    NumberOfCurves = nbCurves;
    Unit = unit;
    Period = period;
    scaleWidget->getBorderDistHint(min, max);
    savedTitres = titres;

    defineAxis(unit, period);

    // define curves
    for(int i=0; i < MAXCURVES; i++) {
        curvStyle s = Lines;
        QColor c;

        if(curve[i] != (QwtPlotCurve*) 0) {
            s = getStyle(i);
            c = getColor(i);
            delete curve[i];
        }

        if(errorcurve[i] != (QwtPlotIntervalCurve*) 0) {
            delete errorcurve[i];
        }
        if(fillcurve[i] != (QwtPlotIntervalCurve*) 0) {
            delete fillcurve[i];
        }

        if(i < NumberOfCurves) {
            // set title and limits to legend
            QString titre = legendText(i);

            curve[i] = new QwtPlotCurve(titre);
            errorcurve[i] = new QwtPlotIntervalCurve(titre);
            fillcurve[i] = new QwtPlotIntervalCurve(titre);
            setStyle(s, i);

            curve[i]->setZ(i);
            curve[i]->attach(this);
            fillcurve[i]->setZ(i);
            fillcurve[i]->attach(this);
            fillcurve[i]->setItemAttribute(QwtPlotItem::Legend, false);
            errorcurve[i]->setZ(i);
            errorcurve[i]->attach(this);
            errorcurve[i]->setItemAttribute(QwtPlotItem::Legend, false);

            showCurve(i, false);

            realMax[i] = maxVal[i] = -1000000;
            realMin[i] = minVal[i] =  1000000;
            actVal[i] = realVal[i] = 0;
        }
    }

    showCurve(0, true);

    // draw legend
    if(thisLegendshow) {
        QwtLegend *lgd = new QwtLegend;
        insertLegend(lgd, QwtPlot::BottomLegend);

        // set color on legend texts
        setLegendAttribute(thisScaleColor, QFont("arial",9), COLOR);
    }
    RescaleCurves(width, unit, period);
}
Exemplo n.º 9
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();
}
Exemplo n.º 10
0
LevelOneMuChart::LevelOneMuChart(QWidget *parent)
    : QwtPlot(parent)
{
    setAutoReplot(false);

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

    /* Zoom in/out with the wheel */
    (void)new QwtPlotMagnifier(canvas());

    /* Picker  */
    plotPicker = new QwtPlotPicker(QwtPlot::xBottom,
                                   QwtPlot::yLeft,
                                   QwtPlotPicker::CrossRubberBand,
                                   QwtPicker::AlwaysOn,
                                   canvas());
    plotPicker->setStateMachine(new QwtPickerDragPointMachine());
    plotPicker->setRubberBandPen(QColor(Qt::blue));
    plotPicker->setRubberBand(QwtPicker::CrossRubberBand);
    plotPicker->setTrackerPen(QColor(Qt::black));

    setAutoFillBackground(true);
    setPalette(QPalette(QColor(199, 237, 255))); // Light Blue

    updateWidgetGradient();

    setTitle(tr("Chart of available deviations"));

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

    /* Canvas Settings */
    canvas()->setLineWidth(1);
    canvas()->setFrameStyle(QFrame::Box | QFrame::Plain);

    QPalette canvasPalette(Qt::white);
    canvasPalette.setColor(QPalette::Foreground, QColor(133, 190, 232));
    canvas()->setPalette(canvasPalette);

    plotAssay();

    /* Legend */
    connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
            SLOT(showItem(QwtPlotItem *, bool)));

    QwtPlotItemList items = itemList(QwtPlotItem::Rtti_PlotCurve);
    for (int i = 0; i < items.size(); i++)
    {
        if (i < 3)
        {
            QwtLegendItem *legendItem =
                    qobject_cast<QwtLegendItem *>(legend->find(items[i]));
            if (legendItem)
            {
                legendItem->setChecked(true);
            }
            items[i]->setVisible(true);
        }
        else
        {
            items[i]->setVisible(false);
        }
    }
    setAutoReplot(true);
}
Exemplo n.º 11
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)));
}
Exemplo n.º 12
0
bool TeSQLite::insertTheme(TeAbstractTheme *theme)
{
	errorMessage_ = "";

	string sql  = "INSERT INTO te_theme (layer_id, view_id, name, parent_id, priority, node_type, ";
	       sql += "min_scale, max_scale, generate_attribute_where, generate_spatial_where, ";
		   sql += "generate_temporal_where, collection_table, visible_rep, enable_visibility, ";
		   sql += "lower_x, lower_y, upper_x, upper_y, creation_time) VALUES(";
		   
		   if(theme->type()==TeTHEME)
			   sql += Te2String(static_cast<TeTheme*>(theme)->layerId());
		   else
			   sql += " NULL ";
		   sql += ", ";
		   sql += Te2String(theme->view());
		   sql += ", '";
		   sql += theme->name();
		   sql += "', ";
		   sql += Te2String(theme->parentId());
		   sql += ", ";
		   sql += Te2String(theme->priority());
		   sql += ", ";
		   sql += Te2String(theme->type());
		   sql += ", ";
		   sql += Te2String(theme->minScale(), 15);
		   sql += ", ";
		   sql += Te2String(theme->maxScale(), 15);
		   sql += ", '";
		   sql += escapeSequence(theme->attributeRest());
		   sql += "', '";
		   sql += escapeSequence(theme->spatialRest());
		   sql += "', '";
		   sql += escapeSequence(theme->temporalRest());
		   sql += "', '";
		   if(theme->type()==TeTHEME)
				sql += static_cast<TeTheme*>(theme)->collectionTable();
		   sql += "', ";
		   sql += Te2String(theme->visibleRep());
		   sql += ", ";
		   sql += Te2String(theme->visibility());
		   sql += ", ";
		   sql += Te2String(theme->box().x1(), 15);
		   sql += ", ";
		   sql += Te2String(theme->box().y1(), 15);
		   sql += ", ";
		   sql += Te2String(theme->box().x2(), 15);
		   sql += ", ";
		   sql += Te2String(theme->box().y2(), 15);
		   sql += ", ";
		   TeTime creationTime = theme->getCreationTime();
		   sql += getSQLTime(creationTime);
		   sql += " )";

	if(this->execute(sql))
	{
		//int newId = getMaxValue(this, "te_theme", "theme_id");
		int newId = getLastInsertedSerial();
		if(newId >= 0)
		{
			theme->id(newId);
		}
	}
	else
		return false;


	if((theme->type()==TeTHEME || theme->type()==TeEXTERNALTHEME) && static_cast<TeTheme*>(theme)->collectionTable().empty())
	{
		sql  = "UPDATE te_theme SET";
		sql += " collection_table = 'te_collection_" + Te2String(theme->id()) + "'";
		sql += " WHERE theme_id = ";
		sql += Te2String(theme->id());

		static_cast<TeTheme*>(theme)->collectionTable(string("te_collection_") + Te2String(theme->id()));

		if(!this->execute(sql))
			return false;
	}
	if(theme->parentId() == 0)
	{
		std::string sql = "UPDATE te_theme SET";
		sql += "  parent_id = " + Te2String(theme->id());
		sql += " WHERE theme_id = ";
		sql += Te2String(theme->id());

		theme->parentId(theme->id());

		if(!this->execute(sql))
			return false;
	}

	bool status;

	// insert grouping
	int numSlices = 0;
	if(theme->grouping().groupMode_ != TeNoGrouping)
	{
		if(!insertGrouping (theme->id(), theme->grouping()))
			return false;
		numSlices = theme->grouping().groupNumSlices_;
	}
		
	// insert legend
	theme->outOfCollectionLegend().group(-1); 
	theme->outOfCollectionLegend().theme(theme->id()); 
	status = insertLegend (&(theme->outOfCollectionLegend())); 
	if (!status)
		return status;

	theme->withoutDataConnectionLegend().group(-2); 
	theme->withoutDataConnectionLegend().theme(theme->id()); 
	status = insertLegend (&(theme->withoutDataConnectionLegend())); 
	if (!status)
		return status;

	theme->defaultLegend().group(-3); 
	theme->defaultLegend().theme(theme->id()); 
	status = insertLegend (&(theme->defaultLegend())); 
	if (!status)
		return status;

	theme->pointingLegend().group(-4); 
	theme->pointingLegend().theme(theme->id()); 
	status = insertLegend (&(theme->pointingLegend())); 
	if (!status)
		return status;

	theme->queryLegend().group(-5); 
	theme->queryLegend().theme(theme->id()); 
	status = insertLegend (&(theme->queryLegend())); 
	if (!status)
		return status;

	theme->queryAndPointingLegend().group(-6); 
	theme->queryAndPointingLegend().theme(theme->id()); 
	status = insertLegend (&(theme->queryAndPointingLegend())); 
	if (!status)
		return status;

	for (int i = 0; i < numSlices; i++)
	{
		theme->legend()[i].group(i);
		theme->legend()[i].theme(theme->id());
		status = insertLegend (&(theme->legend()[i]));
		if (!status)
			return status;
	}
	if (!status)
		return status;

	//insert metadata theme
	if(!theme->saveMetadata(this))
		return false;

	themeMap()[theme->id()] = theme;

	if(theme->type()==TeTHEME && !updateThemeTable(static_cast<TeTheme*>(theme)))
		return false;

	return true;
}