Qwt User's Guide: qwt_plot_panner.cpp Source File

- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# qwt_plot_panner.cpp

    00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
    00002  * Qwt Widget Library
    00003  * Copyright (C) 1997   Josef Wilgen
    00004  * Copyright (C) 2002   Uwe Rathmann
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the Qwt License, Version 1.0
    00008  *****************************************************************************/
    00009
    00010 // vim: expandtab
    00011
    00012 #include "qwt_scale_div.h"
    00013 #include "qwt_plot.h"
    00014 #include "qwt_plot_canvas.h"
    00015 #include "qwt_plot_panner.h"
    00016
    00017 class QwtPlotPanner::PrivateData
    00018 {
    00019 public:
    00020     PrivateData()
    00021     {
    00022         for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    00023             isAxisEnabled[axis] = true;
    00024     }
    00025
    00026     bool isAxisEnabled[QwtPlot::axisCnt];
    00027 };
    00028
    00038 QwtPlotPanner::QwtPlotPanner(QwtPlotCanvas *canvas):
    00039     QwtPanner(canvas)
    00040 {
    00041     d_data = new PrivateData();
    00042
    00043     connect(this, SIGNAL(panned(int, int)),
    00044         SLOT(moveCanvas(int, int)));
    00045 }
    00046
    00048 QwtPlotPanner::~QwtPlotPanner()
    00049 {
    00050     delete d_data;
    00051 }
    00052
    00064 void QwtPlotPanner::setAxisEnabled(int axis, bool on)
    00065 {
    00066     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    00067         d_data->isAxisEnabled[axis] = on;
    00068 }
    00069
    00078 bool QwtPlotPanner::isAxisEnabled(int axis) const
    00079 {
    00080     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    00081         return d_data->isAxisEnabled[axis];
    00082
    00083     return true;
    00084 }
    00085
    00087 QwtPlotCanvas *QwtPlotPanner::canvas()
    00088 {
    00089     QWidget *w = parentWidget();
    00090     if ( w && w->inherits("QwtPlotCanvas") )
    00091         return (QwtPlotCanvas *)w;
    00092
    00093     return NULL;
    00094 }
    00095
    00097 const QwtPlotCanvas *QwtPlotPanner::canvas() const
    00098 {
    00099     return ((QwtPlotPanner *)this)->canvas();
    00100 }
    00101
    00103 QwtPlot *QwtPlotPanner::plot()
    00104 {
    00105     QObject *w = canvas();
    00106     if ( w )
    00107     {
    00108         w = w->parent();
    00109         if ( w && w->inherits("QwtPlot") )
    00110             return (QwtPlot *)w;
    00111     }
    00112
    00113     return NULL;
    00114 }
    00115
    00117 const QwtPlot *QwtPlotPanner::plot() const
    00118 {
    00119     return ((QwtPlotPanner *)this)->plot();
    00120 }
    00121
    00130 void QwtPlotPanner::moveCanvas(int dx, int dy)
    00131 {
    00132     if ( dx == 0 && dy == 0 )
    00133         return;
    00134
    00135     QwtPlot *plot = QwtPlotPanner::plot();
    00136     if ( plot == NULL )
    00137         return;
    00138
    00139     const bool doAutoReplot = plot->autoReplot();
    00140     plot->setAutoReplot(false);
    00141
    00142     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    00143     {
    00144         if ( !d_data->isAxisEnabled[axis] )
    00145             continue;
    00146
    00147         const QwtScaleMap map = plot->canvasMap(axis);
    00148
    00149         const int i1 = map.transform(plot->axisScaleDiv(axis)->lBound());
    00150         const int i2 = map.transform(plot->axisScaleDiv(axis)->hBound());
    00151
    00152         double d1, d2;
    00153         if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
    00154         {
    00155             d1 = map.invTransform(i1 - dx);
    00156             d2 = map.invTransform(i2 - dx);
    00157         }
    00158         else
    00159         {
    00160             d1 = map.invTransform(i1 - dy);
    00161             d2 = map.invTransform(i2 - dy);
    00162         }
    00163
    00164         plot->setAxisScale(axis, d1, d2);
    00165     }
    00166
    00167     plot->setAutoReplot(doAutoReplot);
    00168     plot->replot();
    00169 }