1 |
|
---|
2 | #include <QtSvg>
|
---|
3 |
|
---|
4 | #include <qwt_symbol.h>
|
---|
5 | #include <qwt_plot.h>
|
---|
6 | #include <qwt_plot_svgitem.h>
|
---|
7 | #include <qwt_plot_curve.h>
|
---|
8 | #include <qwt_plot_marker.h>
|
---|
9 | #include <qwt_plot_canvas.h>
|
---|
10 | #include <qwt_plot_panner.h>
|
---|
11 | #include <qwt_plot_zoomer.h>
|
---|
12 | #include <qwt_plot_magnifier.h>
|
---|
13 | #include <qwt_plot_renderer.h>
|
---|
14 |
|
---|
15 | #include "bncmap.h"
|
---|
16 |
|
---|
17 | // Constructor
|
---|
18 | /////////////////////////////////////////////////////////////////////////////
|
---|
19 | t_bncMap::t_bncMap(QWidget* parent) : QDialog(parent) {
|
---|
20 |
|
---|
21 | // Map in Scalable Vector Graphics (svg) Format
|
---|
22 | // --------------------------------------------
|
---|
23 | _mapPlot = new QwtPlot();
|
---|
24 |
|
---|
25 | _mapPlot->setAxisScale(QwtPlot::xBottom, -180.0, 180.0);
|
---|
26 | _mapPlot->setAxisScale(QwtPlot::yLeft, -90.0, 90.0);
|
---|
27 |
|
---|
28 | // (void)new QwtPlotPanner(_mapPlot->canvas());
|
---|
29 | // (void)new QwtPlotMagnifier(_mapPlot->canvas());
|
---|
30 | (void)new QwtPlotZoomer(_mapPlot->canvas());
|
---|
31 |
|
---|
32 | _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus);
|
---|
33 |
|
---|
34 | QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
|
---|
35 | mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
|
---|
36 | mapItem->attach(_mapPlot);
|
---|
37 |
|
---|
38 | // Buttons
|
---|
39 | // -------
|
---|
40 | int ww = QFontMetrics(font()).width('w');
|
---|
41 |
|
---|
42 | _buttonClose = new QPushButton(tr("Close"), this);
|
---|
43 | _buttonClose->setMaximumWidth(10*ww);
|
---|
44 | connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
|
---|
45 |
|
---|
46 | _buttonPrint = new QPushButton(tr("Print"), this);
|
---|
47 | _buttonPrint->setMaximumWidth(10*ww);
|
---|
48 | connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
|
---|
49 |
|
---|
50 | // Layout
|
---|
51 | // ------
|
---|
52 | QHBoxLayout* buttonLayout = new QHBoxLayout;
|
---|
53 | buttonLayout->addWidget(_buttonClose);
|
---|
54 | buttonLayout->addWidget(_buttonPrint);
|
---|
55 |
|
---|
56 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
57 | mainLayout->addWidget(_mapPlot);
|
---|
58 | mainLayout->addLayout(buttonLayout);
|
---|
59 |
|
---|
60 | // Important
|
---|
61 | // ---------
|
---|
62 | _mapPlot->replot();
|
---|
63 | }
|
---|
64 |
|
---|
65 | // Destructor
|
---|
66 | /////////////////////////////////////////////////////////////////////////////
|
---|
67 | t_bncMap::~t_bncMap() {
|
---|
68 | delete _mapPlot;
|
---|
69 | }
|
---|
70 |
|
---|
71 | //
|
---|
72 | /////////////////////////////////////////////////////////////////////////////
|
---|
73 | void t_bncMap::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
|
---|
74 |
|
---|
75 | if (lonDeg > 180.0) lonDeg -= 360.0;
|
---|
76 |
|
---|
77 | QColor red(220,20,60);
|
---|
78 | QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
|
---|
79 | QPen(red), QSize(2,2));
|
---|
80 | QwtPlotMarker* marker = new QwtPlotMarker();
|
---|
81 | marker->setValue(lonDeg, latDeg);
|
---|
82 | marker->setLabelAlignment(Qt::AlignRight);
|
---|
83 | marker->setLabel(QwtText(name.left(4)));
|
---|
84 | marker->setSymbol(symbol);
|
---|
85 | marker->attach(_mapPlot);
|
---|
86 | }
|
---|
87 |
|
---|
88 | // Close
|
---|
89 | ////////////////////////////////////////////////////////////////////////////
|
---|
90 | void t_bncMap::slotClose() {
|
---|
91 | done(0);
|
---|
92 | }
|
---|
93 |
|
---|
94 | // Close Dialog gracefully
|
---|
95 | ////////////////////////////////////////////////////////////////////////////
|
---|
96 | void t_bncMap::closeEvent(QCloseEvent* event) {
|
---|
97 | QDialog::closeEvent(event);
|
---|
98 | }
|
---|
99 |
|
---|
100 | // Print the widget
|
---|
101 | ////////////////////////////////////////////////////////////////////////////
|
---|
102 | void t_bncMap::slotPrint() {
|
---|
103 |
|
---|
104 | QPrinter printer;
|
---|
105 | QPrintDialog* dialog = new QPrintDialog(&printer, this);
|
---|
106 | dialog->setWindowTitle(tr("Print Map"));
|
---|
107 | if (dialog->exec() != QDialog::Accepted) {
|
---|
108 | return;
|
---|
109 | }
|
---|
110 | else {
|
---|
111 | QwtPlotRenderer renderer;
|
---|
112 | renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
|
---|
113 | renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
|
---|
114 | renderer.renderTo(_mapPlot, printer);
|
---|
115 | }
|
---|
116 | }
|
---|