1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <qfiledialog.h>
#include <qwt_plot_svgitem.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_layout.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include "plot.h"
Plot::Plot(QWidget *parent):
QwtPlot(parent),
d_mapItem(NULL),
d_mapRect(0.0, 0.0, 100.0, 100.0) // something
{
#if 1
/*
d_mapRect is only a reference for zooming, but
the ranges are nothing useful for the user. So we
hide the axes.
*/
plotLayout()->setCanvasMargin(0);
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
enableAxis(axis, false);
#else
QwtPlotGrid *grid = new QwtPlotGrid();
grid->attach(this);
#endif
/*
Navigation:
Left Mouse Button: Panning
Mouse Wheel: Zooming In/Out
Right Mouse Button: Reset to initial
*/
(void)new QwtPlotPanner(canvas());
(void)new QwtPlotMagnifier(canvas());
#if QT_VERSION >= 0x040000
using namespace Qt;
#endif
canvas()->setFocusPolicy(WheelFocus);
rescale();
}
void Plot::loadSVG()
{
QString dir;
#if 0
dir = "/dw/svg";
#endif
#if QT_VERSION >= 0x040000
const QString fileName = QFileDialog::getOpenFileName( NULL,
"Load a Scaleable Vector Graphic (SVG) Map",
dir, "SVG Files (*.svg)");
#else
const QString fileName = QFileDialog::getOpenFileName(
dir, "SVG Files (*.svg)", NULL, NULL,
"Load a Scaleable Vector Graphic (SVG) Map" );
#endif
if ( !fileName.isEmpty() )
{
if ( d_mapItem == NULL )
{
d_mapItem = new QwtPlotSvgItem();
d_mapItem->attach(this);
}
d_mapItem->loadFile(d_mapRect, fileName);
rescale();
replot();
}
}
void Plot::rescale()
{
setAxisScale(QwtPlot::xBottom,
d_mapRect.left(), d_mapRect.right());
setAxisScale(QwtPlot::yLeft,
d_mapRect.top(), d_mapRect.bottom());
}
|