Example #1
0
void PlotZoomer::zoom(int up)
{
  // FIXME: Save the current zoom window in case it's been panned.
  int zoomIndex = zoomRectIndex();
  if (zoomIndex > 0)
  {
    QStack<QRectF> stack = zoomStack();
    if (zoomIndex < stack.size())
    {
      QRectF r = scaleRect();
      stack[zoomIndex] = r;
      setZoomStack(stack, zoomIndex);
    }
  }

  Super::zoom(up);
  if (zoomRectIndex() == 0)
  {
    if (QwtPlot *plotter = plot())
    {
      plotter->setAxisAutoScale(AxisX);
      plotter->setAxisAutoScale(AxisY);
      plotter->updateAxes();
    }
  }
}
Example #2
0
void ScrollZoomer::rescale()
{
    QwtScaleWidget *xScale = plot()->axisWidget( xAxis() );
    QwtScaleWidget *yScale = plot()->axisWidget( yAxis() );

    if ( zoomRectIndex() <= 0 )
    {
        if ( d_inZoom )
        {
            xScale->setMinBorderDist( 0, 0 );
            yScale->setMinBorderDist( 0, 0 );

            QwtPlotLayout *layout = plot()->plotLayout();

            for ( int axis = 0; axis < QwtAxis::PosCount; axis++ )
                layout->setAlignCanvasToScale( axis, d_alignCanvasToScales );

            d_inZoom = false;
        }
    }
    else
    {
        if ( !d_inZoom )
        {
            /*
             We set a minimum border distance.
             Otherwise the canvas size changes when scrolling,
             between situations where the major ticks are at
             the canvas borders (requiring extra space for the label)
             and situations where all labels can be painted below/top
             or left/right of the canvas.
             */
            int start, end;

            xScale->getBorderDistHint( start, end );
            xScale->setMinBorderDist( start, end );

            yScale->getBorderDistHint( start, end );
            yScale->setMinBorderDist( start, end );

            QwtPlotLayout *layout = plot()->plotLayout();
            for ( int axis = 0; axis < QwtAxis::PosCount; axis++ )
            {
                d_alignCanvasToScales[axis] = 
                    layout->alignCanvasToScale( axis );
            }

            layout->setAlignCanvasToScales( false );

            d_inZoom = true;
        }
    }

    QwtPlotZoomer::rescale();
    updateScrollBars();
}
Example #3
0
void PlotZoomer::saveSettings(QSettings &settings)
{
  settings.beginGroup("zoom");
  settings.setValue("mode", int(_zoomMode));

  settings.setValue("index", zoomRectIndex());
  settings.beginWriteArray("stack", zoomStack().size());
  int i = 0;
  for (const QRectF &zoom : zoomStack())
  {
    settings.setArrayIndex(i++);
    write(settings, zoom);
  }
  settings.endArray();

  settings.endGroup();
}
Example #4
0
void PlotZoomer::zoomToFit(bool replot)
{
  if (zoomRectIndex() <= 0)
  {
    // Force zoom signal for synchronisation.
    zoom(0);
    emit zoomed(zoomRect());
  }
  else
  {
    zoom(0);
  }
  if (QwtPlot *plotter = plot())
  {
    plotter->setAxisAutoScale(AxisX);
    plotter->setAxisAutoScale(AxisY);
    plotter->updateAxes();
  }
  setZoomBase(replot);
}
Example #5
0
void ScrollZoomer::rescale()
{
    QwtScaleWidget *xScale = plot()->axisWidget(xAxis());
    QwtScaleWidget *yScale = plot()->axisWidget(yAxis());

    if ( zoomRectIndex() <= 0 )
    {
        if ( d_inZoom )
        {
            xScale->setMinBorderDist(0, 0);
            yScale->setMinBorderDist(0, 0);
            d_inZoom = false;
        }
    }
    else
    {
        if ( !d_inZoom )
        {
            /*
             We set a minimum border distance. 
             Otherwise the canvas size changes when scrolling, 
             between situations where the major ticks are at
             the canvas borders (requiring extra space for the label)
             and situations where all labels can be painted below/top
             or left/right of the canvas.
             */
            int start, end;

            xScale->getBorderDistHint(start, end);
            xScale->setMinBorderDist(start, end);

            yScale->getBorderDistHint(start, end);
            yScale->setMinBorderDist(start, end);

            d_inZoom = false;
        }
    }

    QwtPlotZoomer::rescale();
    updateScrollBars();
}
Example #6
0
    virtual void rescale()
    {
        QwtScaleWidget *scaleWidget = plot()->axisWidget(yAxis());
        QwtScaleDraw *sd = scaleWidget->scaleDraw();

        int minExtent = 0;
        if ( zoomRectIndex() > 0 )
        {
            // When scrolling in vertical direction
            // the plot is jumping in horizontal direction
            // because of the different widths of the labels
            // So we better use a fixed extent.

            minExtent = sd->spacing() + sd->maxTickLength() + 1;
            minExtent += sd->labelSize(
                scaleWidget->font(), c_rangeMax).width();
        }

        sd->setMinimumExtent(minExtent);

        ScrollZoomer::rescale();
    }
Example #7
0
LogPlotZoomer::LogPlotZoomer(QWidget *canvas) :
  QwtPlotZoomer(canvas)
#else
LogPlotZoomer::LogPlotZoomer(QwtPlotCanvas *canvas):
  QwtPlotZoomer(canvas)
#endif
{}

#if QWT_VERSION > 0x060000
QwtText LogPlotZoomer::trackerTextF(const QwtDoublePoint &pos) const
#else
QwtText LogPlotZoomer::trackerText(const QwtDoublePoint &pos) const
#endif
{
  switch (rubberBand())
    {
      case HLineRubberBand:
        return QString().sprintf("%.4g", pos.y());

      case VLineRubberBand:
        return QString().sprintf("%.4g", pos.x());

      default:
        return QString().sprintf("%.4g, %.4g", pos.x(), pos.y());
    }

  return QwtText(); // make some dumb compilers happy
}

/*void QwtPlotZoomer::move(double x, double y)
{
    x = qwtMax(x, zoomBase().left());
    x = qwtMin(x, zoomBase().right() - zoomRect().width());

    y = qwtMax(y, zoomBase().top());
    y = qwtMin(y, zoomBase().bottom() - zoomRect().height());

    if (x != zoomRect().left() || y != zoomRect().top())
    {
        d_data->zoomStack[d_data->zoomRectIndex].moveTo(x, y);
        rescale();
    }
}*/

#if QWT_VERSION > 0x060000
void LogPlotZoomer::moveTo(const QPointF &  pos)
{
  double x = pos.x();
  double y = pos.y();
#else
void LogPlotZoomer::move(double x, double y)
{
#endif
  //QwtPlotZoomer::move(x,y);

  x = qwtMax(x, (double)zoomBase().left());
  x = qwtMin(x, (double)(zoomBase().right() - zoomRect().width()));

  y = qwtMax(y, (double)zoomBase().top());
  y = qwtMin(y, (double)(zoomBase().bottom() - zoomRect().height()));

  if (x != zoomRect().left() || y != zoomRect().top())
    {
      //zoomStack()[zoomRectIndex()].moveTo(x, y);
      QwtDoubleRect & rect = const_cast<QwtDoubleRect &>(zoomStack()[zoomRectIndex()]);

      //handle x axis
      const int xAxis = QwtPlotZoomer::xAxis();
      const QwtScaleEngine *sex = plot()->axisScaleEngine(xAxis);

#if QWT_VERSION > 0x060000

      if (dynamic_cast<const QwtLogScaleEngine*>(sex))
#else
      if (dynamic_cast<const QwtLog10ScaleEngine*>(sex))
#endif
        {
          //logarithmic
          double factor = rect.right() / rect.left();
          rect.setRight(x * factor);
          rect.setLeft(x);
        }
      else
        {
          rect.moveLeft(x);
        }

      const int yAxis = QwtPlotZoomer::yAxis();

      const QwtScaleEngine *sey = plot()->axisScaleEngine(yAxis);

#if QWT_VERSION > 0x060000

      if (dynamic_cast<const QwtLogScaleEngine*>(sey))
#else
      if (dynamic_cast<const QwtLog10ScaleEngine*>(sey))
#endif
        {
          //logarithmic
          double factor = rect.bottom() / rect.top();
          rect.setBottom(y * factor);
          rect.setTop(y);
        }
      else
        {
          rect.moveTop(y);
        }

      //zoomStack()[zoomRectIndex()].moveTo(x, y);
      rescale();
    }
}