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