Пример #1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuPvtPlotWidget::setPlotDefaults(QwtPlot* plot)
{
    // Plot background and frame look
    QPalette newPalette(plot->palette());
    newPalette.setColor(QPalette::Background, Qt::white);
    plot->setPalette(newPalette);

    plot->setAutoFillBackground(true);
    plot->setCanvasBackground(Qt::white);

    QFrame* canvasFrame = dynamic_cast<QFrame*>(plot->canvas());
    if (canvasFrame)
    {
        canvasFrame->setFrameShape(QFrame::NoFrame);
    }

    // Grid
    {
        QwtPlotGrid* grid = new QwtPlotGrid;
        grid->attach(plot);
        QPen gridPen(Qt::SolidLine);
        gridPen.setColor(Qt::lightGray);
        grid->setPen(gridPen);
    }

    // Axis number font
    {
        QFont axisFont = plot->axisFont(QwtPlot::xBottom);
        axisFont.setPointSize(8);
        plot->setAxisFont(QwtPlot::xBottom, axisFont);
        plot->setAxisFont(QwtPlot::yLeft, axisFont);
    }

    // Axis title font
    {
        QwtText axisTitle = plot->axisTitle(QwtPlot::xBottom);
        QFont axisTitleFont = axisTitle.font();
        axisTitleFont.setPointSize(8);
        axisTitleFont.setBold(false);
        axisTitle.setFont(axisTitleFont);
        axisTitle.setRenderFlags(Qt::AlignRight);
        plot->setAxisTitle(QwtPlot::xBottom, axisTitle);
        plot->setAxisTitle(QwtPlot::yLeft, axisTitle);
    }

    // Title font
    {
        QwtText plotTitle = plot->title();
        QFont titleFont = plotTitle.font();
        titleFont.setPointSize(12);
        plotTitle.setFont(titleFont);
        plot->setTitle(plotTitle);
    }


    plot->setAxisMaxMinor(QwtPlot::xBottom, 2);
    plot->setAxisMaxMinor(QwtPlot::yLeft, 3);

    plot->plotLayout()->setAlignCanvasToScales(true);
}
Пример #2
0
void Plot::open(QString filename)
{

    this->detachItems();

    // Insert new curves
    curve = new QwtPlotCurve( "y = sin(x)" );
    curve->setRenderHint( QwtPlotItem::RenderAntialiased );
    curve->setLegendAttribute( QwtPlotCurve::LegendShowLine, true );
    curve->setPen( Qt::red );
    curve->attach( this );

    Data* data = new Data(filename);

    curve->setData(data);

    setAxisScale( yLeft, data->yMin, data->yMax);
    setAxisScale( xBottom, data->xMin, data->xMax);


    QwtPlotGrid* grid = new QwtPlotGrid();
    grid->setPen(Qt::black, 0.1, Qt::DashLine);
    grid->attach(this);

}
Пример #3
0
void Plot::paste()
{
    QLocale l;
    QClipboard *clipboard = QApplication::clipboard();
    QString text = clipboard->text();

    if(!text.isEmpty()) {
        QList<QString> items = text.split('\n');
        QList<float> values;
        for(int i = 0; i < items.count(); i++) {
            values.append(l.toFloat(items[i]));
        }


        this->detachItems();

        // Insert new curves
        curve = new QwtPlotCurve( "y = sin(x)" );
        curve->setRenderHint( QwtPlotItem::RenderAntialiased );
        curve->setLegendAttribute( QwtPlotCurve::LegendShowLine, true );
        curve->setPen( Qt::red );
        curve->attach( this );

        Data* data = new Data(&values);
        curve->setData(data);

        setAxisScale( yLeft, data->yMin, data->yMax);
        setAxisScale( xBottom, data->xMin, data->xMax);


        QwtPlotGrid* grid = new QwtPlotGrid();
        grid->setPen(Qt::black, 0.1, Qt::DashLine);
        grid->attach(this);
    }
}
Пример #4
0
//#include "freeems/fetable2ddata.h"
TableView2D::TableView2D(QWidget *parent)
{
	Q_UNUSED(parent)
	//m_isSignedData = isSigned;
	m_isFlashOnly = false;
	ui.setupUi(this);
	metaDataValid = false;
	tableData=0;
	//ui.tableWidget->setColumnCount(1);
	ui.tableWidget->setRowCount(2);
	ui.tableWidget->horizontalHeader()->hide();
	ui.tableWidget->verticalHeader()->hide();
	//ui.tableWidget->setColumnWidth(0,100);
	connect(ui.savePushButton,SIGNAL(clicked()),this,SLOT(saveClicked()));
	connect(ui.loadFlashPushButton,SIGNAL(clicked()),this,SLOT(loadFlashClicked()));
	connect(ui.loadRamPushButton,SIGNAL(clicked()),this,SLOT(loadRamClicked()));
	connect(ui.tableWidget,SIGNAL(cellChanged(int,int)),this,SLOT(tableCellChanged(int,int)));
	connect(ui.tableWidget,SIGNAL(currentCellChanged(int,int,int,int)),this,SLOT(tableCurrentCellChanged(int,int,int,int)));
	connect(ui.exportPushButton,SIGNAL(clicked()),this,SLOT(exportClicked()));
	connect(ui.importPushButton,SIGNAL(clicked()),this,SLOT(importClicked()));
	connect(ui.tableWidget,SIGNAL(hotKeyPressed(int,Qt::KeyboardModifiers)),this,SLOT(hotKeyPressed(int,Qt::KeyboardModifiers)));
	ui.tableWidget->addHotkey(Qt::Key_Plus,Qt::ShiftModifier);
	ui.tableWidget->addHotkey(Qt::Key_Minus,Qt::NoModifier);
	ui.tableWidget->addHotkey(Qt::Key_Underscore,Qt::ShiftModifier);
	ui.tableWidget->addHotkey(Qt::Key_Equal,Qt::NoModifier);
	ui.tableWidget->setItemDelegate(new TableWidgetDelegate());

	QPalette pal = ui.plot->palette();
	pal.setColor(QPalette::Background,QColor::fromRgb(0,0,0));
	ui.plot->setPalette(pal);
	curve = new QwtPlotCurve("Test");
	curve->attach(ui.plot);
	curve->setPen(QPen(QColor::fromRgb(255,0,0),3));
	QwtPlotGrid *grid = new QwtPlotGrid();
	grid->setPen(QPen(QColor::fromRgb(100,100,100)));
	grid->attach(ui.plot);


	//curve->setData()
	//QwtSeriesData<QwtIntervalSample> series;
	/*if (!isram)
	{
		//Is only flash
		ui.loadRamPushButton->setVisible(false);
	}
	else if (!isflash)
	{
		//Is only ram
		ui.loadFlashPushButton->setVisible(false);
		ui.savePushButton->setVisible(false);
	}
	else
	{
		//Is both ram and flash
	}*/
	connect(ui.tracingCheckBox,SIGNAL(stateChanged(int)),this,SLOT(tracingCheckBoxStateChanged(int)));
}
Пример #5
0
Plot::Plot(QWidget *parent):
    QwtPlot(parent),
    d_paintedPoints(0),
    d_interval(0.0, 10.0),
    d_timerId(-1)
{
    d_directPainter = new QwtPlotDirectPainter();

    setAutoReplot(false);

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


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

    plotLayout()->setAlignCanvasToScales(true);

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

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

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

    d_curve = new QwtPlotCurve();
    d_curve->setStyle(QwtPlotCurve::Lines);
    d_curve->setPen(QPen(Qt::green));
#if 1
    d_curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
#endif
#if 1
    d_curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
#endif
    d_curve->setData(new CurveData());
    d_curve->attach(this);
}
Пример #6
0
Osc::Osc( QWidget * parent )
: QwtPlot( parent )
{
    COscScaler * scaler = new COscScaler( this );
    scaler->setWheelZoomX( true );
    scaler->setWheelZoomY( true );
    scaler->setEqualScales( false );
    scaler->setSaveScales( false );

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

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

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

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

    m_timer = new QTimer( this );
    connect( m_timer, SIGNAL(timeout()), this, SIGNAL(timeout()) );
}
Пример #7
0
QgsCurveEditorWidget::QgsCurveEditorWidget( QWidget *parent, const QgsCurveTransform &transform )
  : QWidget( parent )
  , mCurve( transform )
  , mCurrentPlotMarkerIndex( -1 )
{
  mPlot = new QwtPlot();
  mPlot->setMinimumSize( QSize( 0, 100 ) );
  mPlot->setAxisScale( QwtPlot::yLeft, 0, 1 );
  mPlot->setAxisScale( QwtPlot::yRight, 0, 1 );
  mPlot->setAxisScale( QwtPlot::xBottom, 0, 1 );
  mPlot->setAxisScale( QwtPlot::xTop, 0, 1 );

  QVBoxLayout *vlayout = new QVBoxLayout();
  vlayout->addWidget( mPlot );
  setLayout( vlayout );

  // hide the ugly canvas frame
  mPlot->setFrameStyle( QFrame::NoFrame );
  QFrame *plotCanvasFrame = dynamic_cast<QFrame *>( mPlot->canvas() );
  if ( plotCanvasFrame )
    plotCanvasFrame->setFrameStyle( QFrame::NoFrame );

  mPlot->enableAxis( QwtPlot::yLeft, false );
  mPlot->enableAxis( QwtPlot::xBottom, false );

  // add a grid
  QwtPlotGrid *grid = new QwtPlotGrid();
  QwtScaleDiv gridDiv( 0.0, 1.0, QList<double>(), QList<double>(), QList<double>() << 0.2 << 0.4 << 0.6 << 0.8 );
  grid->setXDiv( gridDiv );
  grid->setYDiv( gridDiv );
  grid->setPen( QPen( QColor( 0, 0, 0, 50 ) ) );
  grid->attach( mPlot );

  mPlotCurve = new QwtPlotCurve();
  mPlotCurve->setTitle( QStringLiteral( "Curve" ) );
  mPlotCurve->setPen( QPen( QColor( 30, 30, 30 ), 0.0 ) ),
             mPlotCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mPlotCurve->attach( mPlot );

  mPlotFilter = new QgsCurveEditorPlotEventFilter( mPlot );
  connect( mPlotFilter, &QgsCurveEditorPlotEventFilter::mousePress, this, &QgsCurveEditorWidget::plotMousePress );
  connect( mPlotFilter, &QgsCurveEditorPlotEventFilter::mouseRelease, this, &QgsCurveEditorWidget::plotMouseRelease );
  connect( mPlotFilter, &QgsCurveEditorPlotEventFilter::mouseMove, this, &QgsCurveEditorWidget::plotMouseMove );

  mPlotCurve->setVisible( true );
  updatePlot();
}
Пример #8
0
TempCompCurve::TempCompCurve(QWidget *parent) :
    QwtPlot(parent), dataCurve(NULL), fitCurve(NULL)
{
    setMouseTracking(true);

    setMinimumSize(64, 64);
    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

    setCanvasBackground(QColor(64, 64, 64));

    //Add grid lines
    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->setMajPen(QPen(Qt::gray, 0, Qt::DashLine));
    grid->setMinPen(QPen(Qt::lightGray, 0, Qt::DotLine));
    grid->setPen(QPen(Qt::darkGray, 1, Qt::DotLine));
    grid->attach(this);
}
Пример #9
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    canvas->setBorderRadius( 10 );
    setCanvas( canvas );

#if 0
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen( Qt::DotLine );
    grid->attach( this );
#endif

    d_spectrogram = new QwtPlotSpectrogram();
    d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count

    d_spectrogram->setColorMap( new ColorMap() );

    d_spectrogram->setData( new RasterData() );
    d_spectrogram->attach( this );

    const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
    // A color bar on the right axis
    QwtScaleWidget *rightAxis = axisWidget( QwtPlot::yRight );
    rightAxis->setColorBarEnabled( true );
    rightAxis->setColorBarWidth( 40 );
    rightAxis->setColorMap( zInterval, new ColorMap() );

    setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
    enableAxis( QwtPlot::yRight );

    plotLayout()->setAlignCanvasToScales( true );

    setAxisScale( QwtPlot::xBottom, 0.0, 3.0 );
    setAxisMaxMinor( QwtPlot::xBottom, 0 );
    setAxisScale( QwtPlot::yLeft, 0.0, 3.0 );
    setAxisMaxMinor( QwtPlot::yLeft, 0 );

    QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas );
    magnifier->setAxisEnabled( QwtPlot::yRight, false );

    QwtPlotPanner *panner = new QwtPlotPanner( canvas );
    panner->setAxisEnabled( QwtPlot::yRight, false );
}
Пример #10
0
Spectrograph::Spectrograph(QWidget *parent):
    QwtPlot(parent)
{
    //real-time plotting
    d_directPainter = new QwtPlotDirectPainter();

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

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

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

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

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

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

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

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

    plotLayout()->setAlignCanvasToScales( true );

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

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

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

    d_curve = new QwtPlotCurve();
    d_curve->setStyle( QwtPlotCurve::Lines );
    d_curve->setPen( canvas()->palette().color( QPalette::WindowText ) );
    d_curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    d_curve->setPaintAttribute( QwtPlotCurve::ClipPolygons, false );
    d_curve->setData( new CurveData() );
    d_curve->attach( this );
}
Пример #12
0
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{
    // create menu bar and actions
    createActions();
    createMenus();

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

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

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

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

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

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

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

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

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

    // finally, refresh the plot
    m_main_plot->replot();
}
Пример #13
0
void QgsHistogramWidget::drawHistogram()
{
  // clear plot
  mpPlot->detachItems();

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

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

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

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

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

  int rangeIndex = 0;
  int lastValue = 0;

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

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

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

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

    lastValue = binValue;
  }

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

  mRangeMarkers.clear();
  Q_FOREACH ( const QgsRendererRange &range, mRanges )
  {
    QwtPlotMarker *rangeMarker = new QwtPlotMarker();
    rangeMarker->attach( mpPlot );
    rangeMarker->setLineStyle( QwtPlotMarker::VLine );
    rangeMarker->setXValue( range.upperValue() );
    rangeMarker->setLabel( QString::number( range.upperValue() ) );
    rangeMarker->setLabelOrientation( Qt::Vertical );
    rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
    rangeMarker->show();
    mRangeMarkers << rangeMarker;
  }
Пример #14
0
void CurveWidget::initialize(bool zoom)
{
    setContentsMargins(2, 2, 2, 2);
    setMinimumHeight(338);

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

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

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

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

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

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

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

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

    //! curve

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

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

    // Legend
    QwtPlotLegendItem* legendItem = new JLegendItem;
    legendItem->setMaxColumns(q_curves.count());
    legendItem->attach(this);
}
Пример #15
0
QgsGradientColorRampDialog::QgsGradientColorRampDialog( const QgsGradientColorRamp &ramp, QWidget *parent )
  : QDialog( parent )
  , mRamp( ramp )
  , mCurrentPlotColorComponent( -1 )
  , mCurrentPlotMarkerIndex( 0 )
{
  setupUi( this );
#ifdef Q_OS_MAC
  setWindowModality( Qt::WindowModal );
#endif

  mPositionSpinBox->setShowClearButton( false );
  btnColor1->setAllowOpacity( true );
  btnColor1->setColorDialogTitle( tr( "Select Ramp Color" ) );
  btnColor1->setContext( QStringLiteral( "symbology" ) );
  btnColor1->setShowNoColor( true );
  btnColor1->setNoColorString( tr( "Transparent" ) );
  btnColor2->setAllowOpacity( true );
  btnColor2->setColorDialogTitle( tr( "Select Ramp Color" ) );
  btnColor2->setContext( QStringLiteral( "symbology" ) );
  btnColor2->setShowNoColor( true );
  btnColor2->setNoColorString( tr( "Transparent" ) );
  updateColorButtons();
  connect( btnColor1, &QgsColorButton::colorChanged, this, &QgsGradientColorRampDialog::setColor1 );
  connect( btnColor2, &QgsColorButton::colorChanged, this, &QgsGradientColorRampDialog::setColor2 );

  // fill type combobox
  cboType->blockSignals( true );
  cboType->addItem( tr( "Discrete" ) );
  cboType->addItem( tr( "Continuous" ) );
  if ( mRamp.isDiscrete() )
    cboType->setCurrentIndex( 0 );
  else
    cboType->setCurrentIndex( 1 );
  cboType->blockSignals( false );

  if ( mRamp.info().isEmpty() )
    btnInformation->setEnabled( false );

  mStopEditor->setGradientRamp( mRamp );
  connect( mStopEditor, &QgsGradientStopEditor::changed, this, &QgsGradientColorRampDialog::updateRampFromStopEditor );

  connect( mColorWidget, &QgsCompoundColorWidget::currentColorChanged, this, &QgsGradientColorRampDialog::colorWidgetChanged );
  connect( mDeleteStopButton, &QAbstractButton::clicked, mStopEditor, &QgsGradientStopEditor::deleteSelectedStop );

  QgsSettings settings;
  restoreGeometry( settings.value( QStringLiteral( "Windows/GradientEditor/geometry" ) ).toByteArray() );

  // hide the ugly canvas frame
  mPlot->setFrameStyle( QFrame::NoFrame );
  QFrame *plotCanvasFrame = dynamic_cast<QFrame *>( mPlot->canvas() );
  if ( plotCanvasFrame )
    plotCanvasFrame->setFrameStyle( QFrame::NoFrame );

  mPlot->setAxisScale( QwtPlot::yLeft, 0.0, 1.0 );
  mPlot->enableAxis( QwtPlot::yLeft, false );

  // add a grid
  QwtPlotGrid *grid = new QwtPlotGrid();
  QwtScaleDiv gridDiv( 0.0, 1.0, QList<double>(), QList<double>(), QList<double>() << 0.2 << 0.4 << 0.6 << 0.8 );
  grid->setXDiv( gridDiv );
  grid->setYDiv( gridDiv );
  grid->setPen( QPen( QColor( 0, 0, 0, 50 ) ) );
  grid->attach( mPlot );

  mLightnessCurve = new QwtPlotCurve();
  mLightnessCurve->setTitle( QStringLiteral( "Lightness" ) );
  mLightnessCurve->setPen( QPen( QColor( 70, 150, 255 ), 0.0 ) ),
                  mLightnessCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mLightnessCurve->attach( mPlot );

  mHueCurve = new QwtPlotCurve();
  mHueCurve->setTitle( QStringLiteral( "Hue" ) );
  mHueCurve->setPen( QPen( QColor( 255, 215, 70 ), 0.0 ) ),
            mHueCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mHueCurve->attach( mPlot );

  mSaturationCurve = new QwtPlotCurve();
  mSaturationCurve->setTitle( QStringLiteral( "Saturation" ) );
  mSaturationCurve->setPen( QPen( QColor( 255, 70, 150 ), 0.0 ) ),
                   mSaturationCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mSaturationCurve->attach( mPlot );

  mAlphaCurve = new QwtPlotCurve();
  mAlphaCurve->setTitle( QStringLiteral( "Opacity" ) );
  mAlphaCurve->setPen( QPen( QColor( 50, 50, 50 ), 0.0 ) ),
              mAlphaCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mAlphaCurve->attach( mPlot );

  mPlotFilter = new QgsGradientPlotEventFilter( mPlot );
  connect( mPlotFilter, &QgsGradientPlotEventFilter::mousePress, this, &QgsGradientColorRampDialog::plotMousePress );
  connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseRelease, this, &QgsGradientColorRampDialog::plotMouseRelease );
  connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseMove, this, &QgsGradientColorRampDialog::plotMouseMove );

  mPlotHueCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotHue" ), false ).toBool() );
  mPlotLightnessCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotLightness" ), true ).toBool() );
  mPlotSaturationCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotSaturation" ), false ).toBool() );
  mPlotAlphaCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotAlpha" ), false ).toBool() );

  mHueCurve->setVisible( mPlotHueCheckbox->isChecked() );
  mLightnessCurve->setVisible( mPlotLightnessCheckbox->isChecked() );
  mSaturationCurve->setVisible( mPlotSaturationCheckbox->isChecked() );
  mAlphaCurve->setVisible( mPlotAlphaCheckbox->isChecked() );

  connect( mStopEditor, &QgsGradientStopEditor::selectedStopChanged, this, &QgsGradientColorRampDialog::selectedStopChanged );
  mStopEditor->selectStop( 0 );

  connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsGradientColorRampDialog::showHelp );
}
Пример #16
0
ChartView::ChartView( QWidget * parent ) : QwtPlot( parent )
{
    // void setupPalette()
    {
        QPalette pal = palette();
        QLinearGradient gradient;
        gradient.setCoordinateMode( QGradient::StretchToDeviceMode );
        // gradient.setColorAt( 0.0, QColor( 0xcf, 0xcf, 0xc4 ) ); // pastel gray
        // gradient.setColorAt( 1.0, QColor( 0xae, 0xc6, 0xcf ) ); // pastel blue
        gradient.setColorAt( 0.0, QColor( 0xc1, 0xff, 0xc1 ) ); // darkseagreen
        gradient.setColorAt( 1.0, QColor( 0xb4, 0xee, 0xb4 ) ); // darkseagreen 2
         
        pal.setBrush( QPalette::Window, QBrush( gradient ) );
         
        // QPalette::WindowText is used for the curve color
        // pal.setColor( QPalette::WindowText, Qt::green );

        setPalette( pal );
    }

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

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

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

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

    if ( auto panner = new QwtPlotPanner( canvas() ) ) {
        panner->setAxisEnabled( QwtPlot::yRight, false );
        panner->setMouseButton( Qt::MidButton );
    }
    
    if ( auto picker = new QwtPlotPicker( canvas() ) ) {
        picker->setMousePattern( QwtEventPattern::MouseSelect1,  Qt::RightButton );
        picker->setStateMachine( new QwtPickerDragRectMachine() );
        picker->setRubberBand( QwtPicker::RectRubberBand );
        picker->setRubberBandPen( QColor(Qt::red) );
        picker->setTrackerPen( QColor( Qt::blue ) );
        connect( picker, static_cast< void(QwtPlotPicker::*)(const QRectF&) >(&QwtPlotPicker::selected), this, &ChartView::selected );
        picker->setEnabled( true );
    }
}
Пример #17
0
EigenPlotDlg::EigenPlotDlg(QWidget* parent) :
   QDialog(parent),
   mpPlot(NULL),
   mpCurve(NULL),
   mpComponentsSpin(NULL)
{
   // Eigen plot
   mpPlot = new QwtPlot(this);
   mpPlot->installEventFilter(this);
   mpPlot->setAutoFillBackground(true);

   QFont ftAxis = QApplication::font();
   ftAxis.setBold(true);
   ftAxis.setPointSize(10);

   QwtText bottomText("Number of Components");
   bottomText.setFont(ftAxis);
   mpPlot->setAxisTitle(QwtPlot::xBottom, bottomText);

   QwtText leftText("Eigen Values");
   leftText.setFont(ftAxis);
   mpPlot->setAxisTitle(QwtPlot::yLeft, leftText);

   QwtScaleEngine* pLinearScale = mpPlot->axisScaleEngine(QwtPlot::xBottom);
   pLinearScale->setAttribute(QwtScaleEngine::Floating);

   QwtLog10ScaleEngine* pLogScale = new QwtLog10ScaleEngine();
   pLogScale->setAttribute(QwtScaleEngine::Floating);
   mpPlot->setAxisScaleEngine(QwtPlot::yLeft, pLogScale);

   QPalette plotPalette = mpPlot->palette();
   plotPalette.setColor(QPalette::Window, Qt::white);
   mpPlot->setPalette(plotPalette);

   QwtPlotCanvas* pPlotCanvas = mpPlot->canvas();
   pPlotCanvas->setFrameStyle(QFrame::NoFrame);

   QwtPlotLayout* pPlotLayout = mpPlot->plotLayout();
   pPlotLayout->setMargin(5);

   QwtPlotGrid* pPlotGrid = new QwtPlotGrid();
   pPlotGrid->setPen(QPen(Qt::DotLine));
   pPlotGrid->attach(mpPlot);
   mpPlot->replot();

   // Number of components
   QLabel* pComponentsLabel = new QLabel("Number of Components:", this);
   mpComponentsSpin = new QSpinBox(this);
   mpComponentsSpin->setFixedWidth(50);
   mpComponentsSpin->setMinimum(1);

   QLabel* pDescriptionLabel = new QLabel("To set, left click in the plot or enter a value.", this);
   pDescriptionLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
   pDescriptionLabel->setWordWrap(true);

   QFont descriptionFont(pDescriptionLabel->font());
   descriptionFont.setItalic(true);
   pDescriptionLabel->setFont(descriptionFont);

   QHBoxLayout* pComponentsLayout = new QHBoxLayout();
   pComponentsLayout->setMargin(0);
   pComponentsLayout->setSpacing(5);
   pComponentsLayout->addWidget(pComponentsLabel);
   pComponentsLayout->addWidget(mpComponentsSpin);
   pComponentsLayout->addWidget(pDescriptionLabel, 10);

   // Horizontal line
   QFrame* pLine = new QFrame(this);
   pLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);

   // Buttons
   QPushButton* pOk = new QPushButton("&OK", this);
   QPushButton* pCancel = new QPushButton("&Cancel", this);
   connect(pOk, SIGNAL(clicked()), this, SLOT(accept()));
   connect(pCancel, SIGNAL(clicked()), this, SLOT(reject()));

   QHBoxLayout* pButtonLayout = new QHBoxLayout();
   pButtonLayout->setMargin(0);
   pButtonLayout->setSpacing(5);
   pButtonLayout->addStretch(10);
   pButtonLayout->addWidget(pOk);
   pButtonLayout->addWidget(pCancel);

   // Layout
   QGridLayout* pGrid = new QGridLayout(this);
   pGrid->setMargin(10);
   pGrid->setSpacing(10);
   pGrid->addWidget(mpPlot, 0, 0);
   pGrid->addLayout(pComponentsLayout, 1, 0);
   pGrid->addWidget(pLine, 2, 0);
   pGrid->addLayout(pButtonLayout, 3, 0);
   pGrid->setRowStretch(0, 10);

   // Initialization
   setWindowTitle("PCA Components");
   setModal(true);
   resize(440, 300);
}
Пример #18
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    //setAutoFillBackground( true );
    //setPalette( QPalette( QColor( 165, 193, 228 ) ) );
    //updateGradient();

    //setTitle( "A Simple QwtPlot Demonstration" );
    //insertLegend( new QwtLegend(), QwtPlot::BottomLegend );

    // axes
    setAxisTitle( xBottom, "x -->" );
    setAxisScale( xBottom, 0.0, 360.0 );

    setAxisTitle( yLeft, "y -->" );
    setAxisScale( yLeft, -10.0, 10.0 );


    // canvas
    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    //canvas->setLineWidth( 1 );
    canvas->setFrameStyle( QFrame::StyledPanel  );
    //canvas->setBorderRadius( 15 );

    QwtPlotGrid* grid = new QwtPlotGrid();
    grid->setPen(Qt::black, 0.1, Qt::DashLine);
    grid->attach(this);

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

    setCanvas( canvas );

    // panning with the left mouse button
    QwtPlotPanner* panner = new QwtPlotPanner( canvas );
    panner->setMouseButton(Qt::LeftButton, Qt::ControlModifier);

    // zoom in/out with the wheel
    QwtPlotMagnifier* magnifier = new QwtPlotMagnifier( canvas );
    magnifier->setAxisEnabled(xBottom, false);


    QwtPlotZoomer* zoomer = new QwtPlotZoomer(canvas);
    zoomer->setKeyPattern( QwtEventPattern::KeyRedo, Qt::Key_I, Qt::ShiftModifier );
    zoomer->setKeyPattern( QwtEventPattern::KeyUndo, Qt::Key_O, Qt::ShiftModifier );
    zoomer->setKeyPattern( QwtEventPattern::KeyHome, Qt::Key_Home );

    zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton, Qt::ShiftModifier);
    zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ShiftModifier);




    canvas->setFocusPolicy(Qt::StrongFocus);
    canvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator);
    canvas->setFocus();
    //canvas->setFrameShadow(QwtPlot::Plain);
    //canvas->setCursor(Qt::arrowCursor);
    canvas->setLineWidth(0);
    //canvas->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    //canvas->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);

    //populate();    
}
Пример #19
0
Plot::Plot(QWidget *parent):
    QwtPlot(parent),
    d_paintedPoints0(0),
    d_paintedPoints1(0),
    d_interval(0.0, 25.0),
    d_timerId(-1)
{
    d_directPainter0 = new QwtPlotDirectPainter();

    setAutoReplot(false);

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


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

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

#endif

    initGradient();

    plotLayout()->setAlignCanvasToScales(true);

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

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

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

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

    d_curve1 = new QwtPlotCurve();
    d_curve1->setStyle(QwtPlotCurve::Lines);
    d_curve1->setPen(QPen(Qt::red,3));
#if 1
    d_curve1->setRenderHint(QwtPlotItem::RenderAntialiased, true);
#endif
#if 1
    d_curve1->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
#endif
    d_curve1->setData(new CurveData());
    d_curve1->attach(this);
}
Пример #20
0
Plot::Plot(QWidget *parent):
    QwtPlot(parent),
    d_paintedPoints(0),
    d_interval(0.0, 10.0),
    d_timerId(-1)
{
    d_directPainter = new QwtPlotDirectPainter();

    setAutoReplot(false);

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

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


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

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

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

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

#endif

    initGradient();

    plotLayout()->setAlignCanvasToScales(true);

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

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

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

    d_curve = new QwtPlotCurve();
    d_curve->setStyle(QwtPlotCurve::Lines);
    d_curve->setPen(QPen(Qt::green));
#if 1
    d_curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
#endif
#if 1
    d_curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
#endif
    d_curve->setData(new CurveData());
    d_curve->attach(this);
}
Variog_multiplot::
Variog_multiplot( const std::vector<Discrete_function>& df_vec,
                  const QStringList& titles,
                  QWidget *parent, const char *name )
       : QwtPlot(parent)
{
  if (name)
    setObjectName(name);
  
  //this->setWindowFlags( Qt::SubWindow|Qt::MSWindowsFixedSizeDialogHint);

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

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


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

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


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

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

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

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

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

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

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

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

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

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

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

    delete [] x;
    delete [] y;
  }

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

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

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

}
Пример #22
0
void QgsHistogramWidget::drawHistogram()
{
  if ( !mVectorLayer || mSourceFieldExp.isEmpty() )
    return;

  QApplication::setOverrideCursor( Qt::WaitCursor );

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

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

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

  // clear plot
  mpPlot->detachItems();

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

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

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

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

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

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

#endif

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

  int rangeIndex = 0;
  int lastValue = 0;

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

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

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

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

    lastValue = binValue;
  }

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

  mRangeMarkers.clear();
  foreach ( QgsRendererRangeV2 range, mRanges )
  {
    QwtPlotMarker* rangeMarker = new QwtPlotMarker();
    rangeMarker->attach( mpPlot );
    rangeMarker->setLineStyle( QwtPlotMarker::VLine );
    rangeMarker->setXValue( range.upperValue() );
    rangeMarker->setLabel( QString::number( range.upperValue() ) );
    rangeMarker->setLabelOrientation( Qt::Vertical );
    rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
    rangeMarker->show();
    mRangeMarkers << rangeMarker;
  }
Пример #23
0
COscMain::COscMain()
: QMainWindow()
{
    m_dev = new CUsbIo();
    m_running = false;

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

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

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


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

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

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

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

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

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

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

    ui.sb->adjustSize();

    open();
    curvesCntChanged();
    settingsChanged();
    /*if ( m_dev->isOpen() )
    {
        
        m_dev->setTimer( 12000, CUsbIo::T1024 );
        m_dev->setTimer( 6000,  CUsbIo::T1024 );
        m_dev->setTimer( 255,   CUsbIo::T1024 );
    }*/
}
Пример #24
0
Variog_plot::
Variog_plot( const Discrete_function& df,
			       const Variogram_function_adaptor<Covariance<GsTLPoint> > *model,
			       GsTLVector<double> angle,
             const std::vector<int>& pairs,
             const QString& title, bool y_starts_at_zero,
			       QWidget *parent, const char *name)
  : QwtPlot(parent), pairs_shown_(false), model1_(0), model2_(0)
{

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

  this->replot();

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


  /*
  QObject::connect( this, SIGNAL(plotMouseReleased(const QMouseEvent& )), 
                    this, SLOT(show_pairs_count(const QMouseEvent&)) );
  */
  delete [] x;
  delete [] y;
}