📄 plot.cpp
字号:
#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());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -