示例#1
0
MSPeaksWnd::MSPeaksWnd(QWidget *parent) : QWidget(parent)
{
    plots_.push_back( std::make_shared< adwplot::Dataplot >() );
    plots_.push_back( std::make_shared< adwplot::Dataplot >() );
    
    plotMarkers_.resize( plots_.size() );
    plotCurves_.resize( plots_.size() );

    static struct {
        const char * xBottom;
        const char * yLeft;
    } axis_titles [] = {
        { "&radic;<span style=\"text-decoration: overline\">&nbsp;<i>m/z</i></span>"
          , "time (&mu;s)"
        }
        , { "flight length (m)"
          , "time (&mu;s)"
        }
    };
    assert( sizeof( axis_titles ) / sizeof( axis_titles[0] ) == plots_.size() );

    QFont font;
	qtwrapper::font::setFont( font, qtwrapper::fontSizeSmall, qtwrapper::fontAxisLabel );
    font.setFamily( "Consolas" );
    font.setBold( false );
	font.setPointSize( 8 );

    int n = 0;
    for ( auto& plot: plots_ ) {

        plot->setMinimumHeight( 40 );
        plot->setMinimumWidth( 40 );
        plot->enableAxis( QwtPlot::yRight );

        plot->setAxisFont( QwtPlot::xBottom, font );
        plot->setAxisFont( QwtPlot::yLeft, font );
        plot->setAxisFont( QwtPlot::yRight, font );

        plot->setAxisTitle( QwtPlot::yLeft, QwtText( axis_titles[ n ].yLeft, QwtText::RichText ) );
        plot->setAxisTitle( QwtPlot::xBottom, QwtText( axis_titles[ n ].xBottom, QwtText::RichText ) );
        plot->setAxisTitle( QwtPlot::yRight, QwtText( "&delta;(ns)", QwtText::RichText ) );

        plot->axisAutoScale( QwtPlot::xBottom );
        plot->axisAutoScale( QwtPlot::yLeft );
        ++n;

        QwtPlotGrid * grid = new QwtPlotGrid;
        grid->setMajorPen( Qt::gray, 0, Qt::DotLine );
        grid->attach( plot.get() );

        QwtPlotLegendItem * legendItem = new QwtPlotLegendItem;
        legendItem->attach( plot.get() );
    };

    init();
}
示例#2
0
QWidget * createLinePlot(vector<double> & x, vector<double> & y1)
{
    /// first plot (single line)
    QLinePlot * plot1 = new QLinePlot();
    plot1->setTitle( "Plot Demo - single Y axis" );

    // legend item
    QwtPlotLegendItem * legendItem = new QwtPlotLegendItem();
    legendItem->attach( plot1 );

    legendItem->setRenderHint( QwtPlotItem::RenderAntialiased );
    legendItem->setMaxColumns( 1 );
    legendItem->setAlignment( Qt::AlignRight );

    QColor color( Qt::white );
    legendItem->setTextPen( color );
    legendItem->setBorderPen( color );

    QColor c( Qt::gray );
    c.setAlpha( 200 );
    legendItem->setBackgroundBrush( c );


    plot1->setAxisTitle (QwtPlot::xBottom, "x-axis");
    plot1->setAxisTitle (QwtPlot::yLeft, "y-axis 1");

    // Grid
    plot1->grid()->enableX(true);
    plot1->grid()->enableY(true);

    // first curve
    QPlotCurve *curve = new QPlotCurve();
    curve->setTitle( "sin(x)" );
    curve->setPen( QColorPalette::color(1), 4 ),
          curve->setYAxis(QwtPlot::yLeft);
    curve->setRawSamples(&x[0], &y1[0], x.size());

    // attach Curve to qwtPlot
    curve->attach( plot1 );
    plot1->replot();

    // curves must be attached to plot, otherwise
    // nothing is applied.
    plot1->setColorPalette(QColorPalette::MSOffice2007);

    return plot1;
}
int QwtLegendLayoutItem::heightForWidth( int w ) const
{
    return d_legendItem->heightForWidth( d_data, w );
}
QSize QwtLegendLayoutItem::minimumSize() const
{
    return d_legendItem->minimumSize( d_data );
}
示例#5
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);
}