Beispiel #1
0
//---------------------------------------------------------------------------
void Plots::Plots_Create(PlotType Type)
{
    // Paddings
    if (paddings[Type]==NULL)
    {
        paddings[Type]=new QWidget(this);
        paddings[Type]->setVisible(false);
    }

    // General design of plot
    QwtPlot* plot = new QwtPlot(this);
    plot->setVisible(false);
    plot->setMinimumHeight(1);
    plot->enableAxis(QwtPlot::xBottom, Type==PlotType_Axis);
    plot->setAxisMaxMajor(QwtPlot::yLeft, 0);
    plot->setAxisMaxMinor(QwtPlot::yLeft, 0);
    plot->setAxisScale(QwtPlot::xBottom, 0, FileInfoData->Videos[0]->x_Max[XAxis_Kind_index]);
    if (PerPlotGroup[Type].Count>3)
        plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    // Plot grid
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->enableXMin(true);
    grid->enableYMin(true);
    grid->setMajorPen(Qt::darkGray, 0, Qt::DotLine );
    grid->setMinorPen(Qt::gray, 0 , Qt::DotLine );
    grid->attach(plot);

    // Plot curves
    for(unsigned j=0; j<PerPlotGroup[Type].Count; ++j)
    {
        plotsCurves[Type][j] = new QwtPlotCurve(PerPlotName[PerPlotGroup[Type].Start+j].Name);
        QColor c;

        switch (PerPlotGroup[Type].Count)
        {
             case 1 :
                        switch (Type)
                        {
                            case PlotType_YDiff: c=Qt::darkGreen; break;
                            case PlotType_UDiff: c=Qt::darkBlue; break;
                            case PlotType_VDiff: c=Qt::darkRed; break;
                            default: c=Qt::black;
                        }
                        break;
             case 2 :
                        switch (j)
                        {
                            case 0: c=Qt::darkGreen; break;
                            case 1: c=Qt::darkRed; break;
                            default: c=Qt::black;
                        }
                        break;
             case 3 :
                        switch (j)
                        {
                            case 0: c=Qt::darkRed; break;
                            case 1: c=Qt::darkBlue; break;
                            case 2: c=Qt::darkGreen; break;
                            default: c=Qt::black;
                        }
                        break;
             case 5 :
                        switch (j)
                        {
                            case 0: c=Qt::red; break;
                            case 1: c=QColor::fromRgb(0x00, 0x66, 0x00); break; //Qt::green
                            case 2: c=Qt::black; break;
                            case 3: c=Qt::green; break;
                            case 4: c=Qt::red; break;
                            default: c=Qt::black;
                        }
                        break;
            default:    c=Qt::black;
        }

        plotsCurves[Type][j]->setPen(c);
        plotsCurves[Type][j]->setRenderHint(QwtPlotItem::RenderAntialiased);
        plotsCurves[Type][j]->setZ(plotsCurves[Type][j]->z()-j); //Invert data order (e.g. MAX before MIN)
        plotsCurves[Type][j]->attach(plot);
     }

    // Legends
    QwtLegend *legend = new QwtLegend(this);
    legend->setVisible(false);
    legend->setMinimumHeight(1);
    legend->setMaxColumns(1);
    QFont Font=legend->font();
    #ifdef _WIN32
        Font.setPointSize(6);
    #else // _WIN32
        Font.setPointSize(8);
    #endif //_WIN32
    legend->setFont(Font);
    connect(plot, SIGNAL(legendDataChanged(const QVariant &, const QList<QwtLegendData> &)), legend, SLOT(updateLegend(const QVariant &, const QList<QwtLegendData> &)));
    plot->updateLegend();

    // Assignment
    plots[Type]=plot;
    legends[Type]=legend;

    // Pickers
    plotsPickers[Type] = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, plots[Type]->canvas() );
    plotsPickers[Type]->setStateMachine( new QwtPickerDragPointMachine () );
    plotsPickers[Type]->setRubberBandPen( QColor( Qt::green ) );
    plotsPickers[Type]->setTrackerPen( QColor( Qt::white ) );
    connect(plotsPickers[Type], SIGNAL(moved(const QPointF&)), SLOT(plot_moved(const QPointF&)));
    connect(plotsPickers[Type], SIGNAL(selected(const QPointF&)), SLOT(plot_moved(const QPointF&)));

    // Marker
    QwtPlotMarker* plotMarker=new QwtPlotMarker;
    plotMarker->setLineStyle(QwtPlotMarker::VLine);
    plotMarker->setLinePen(QPen(Qt::magenta, 1));
    plotMarker->setXValue(0);
    plotMarker->attach(plot);
    plotsMarkers[Type]=plotMarker;
}
/*!
  \brief Insert a legend

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

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

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

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

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

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

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

        d_data->legend = legend;

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

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

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

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

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

            if ( previousInChain )
                qwtSetTabOrder( previousInChain, legend, true );
        }
    }