1 | // Part of BNC, a utility for retrieving decoding and
|
---|
2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2007
|
---|
5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
6 | // http://www.bkg.bund.de
|
---|
7 | // Czech Technical University Prague, Department of Geodesy
|
---|
8 | // http://www.fsv.cvut.cz
|
---|
9 | //
|
---|
10 | // Email: euref-ip@bkg.bund.de
|
---|
11 | //
|
---|
12 | // This program is free software; you can redistribute it and/or
|
---|
13 | // modify it under the terms of the GNU General Public License
|
---|
14 | // as published by the Free Software Foundation, version 2.
|
---|
15 | //
|
---|
16 | // This program is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU General Public License
|
---|
22 | // along with this program; if not, write to the Free Software
|
---|
23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
24 |
|
---|
25 | /* -------------------------------------------------------------------------
|
---|
26 | * BKG NTRIP Client
|
---|
27 | * -------------------------------------------------------------------------
|
---|
28 | *
|
---|
29 | * Class: t_bncMap
|
---|
30 | *
|
---|
31 | * Purpose: Plot map of stations from NTRIP source table
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 02-Sep-2012
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <QtSvg>
|
---|
42 |
|
---|
43 | #include <qwt_symbol.h>
|
---|
44 | #include <qwt_plot.h>
|
---|
45 | #include <qwt_plot_svgitem.h>
|
---|
46 | #include <qwt_plot_curve.h>
|
---|
47 | #include <qwt_plot_marker.h>
|
---|
48 | #include <qwt_plot_canvas.h>
|
---|
49 | #include <qwt_plot_zoomer.h>
|
---|
50 | #include <qwt_plot_renderer.h>
|
---|
51 |
|
---|
52 | #include "bncmap.h"
|
---|
53 |
|
---|
54 | // Constructor
|
---|
55 | /////////////////////////////////////////////////////////////////////////////
|
---|
56 | t_bncMap::t_bncMap(QWidget* parent) : QDialog(parent) {
|
---|
57 |
|
---|
58 | // Map in Scalable Vector Graphics (svg) Format
|
---|
59 | // --------------------------------------------
|
---|
60 | _mapPlot = new QwtPlot();
|
---|
61 |
|
---|
62 | _mapPlot->setAxisScale(QwtPlot::xBottom, -180.0, 180.0);
|
---|
63 | _mapPlot->setAxisScale(QwtPlot::yLeft, -90.0, 90.0);
|
---|
64 |
|
---|
65 | _mapPlotZoomer = new QwtPlotZoomer(_mapPlot->canvas());
|
---|
66 |
|
---|
67 | _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus);
|
---|
68 |
|
---|
69 | QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
|
---|
70 | mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
|
---|
71 | mapItem->attach(_mapPlot);
|
---|
72 |
|
---|
73 | // Buttons
|
---|
74 | // -------
|
---|
75 | int ww = QFontMetrics(font()).width('w');
|
---|
76 |
|
---|
77 | _buttonClose = new QPushButton(tr("Close"), this);
|
---|
78 | _buttonClose->setMaximumWidth(10*ww);
|
---|
79 | connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
|
---|
80 |
|
---|
81 | _buttonPrint = new QPushButton(tr("Print"), this);
|
---|
82 | _buttonPrint->setMaximumWidth(10*ww);
|
---|
83 | connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
|
---|
84 |
|
---|
85 | // Layout
|
---|
86 | // ------
|
---|
87 | QHBoxLayout* buttonLayout = new QHBoxLayout;
|
---|
88 | buttonLayout->addWidget(_buttonClose);
|
---|
89 | buttonLayout->addWidget(_buttonPrint);
|
---|
90 |
|
---|
91 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
92 | mainLayout->addWidget(_mapPlot);
|
---|
93 | mainLayout->addLayout(buttonLayout);
|
---|
94 |
|
---|
95 | // Minimal and Maximal Coordinates
|
---|
96 | // -------------------------------
|
---|
97 | _minPointLat = 0.0;
|
---|
98 | _maxPointLat = 0.0;
|
---|
99 | _minPointLon = 0.0;
|
---|
100 | _maxPointLon = 0.0;
|
---|
101 |
|
---|
102 | // Important
|
---|
103 | // ---------
|
---|
104 | _mapPlot->replot();
|
---|
105 | }
|
---|
106 |
|
---|
107 | // Destructor
|
---|
108 | /////////////////////////////////////////////////////////////////////////////
|
---|
109 | t_bncMap::~t_bncMap() {
|
---|
110 | delete _mapPlot;
|
---|
111 | }
|
---|
112 |
|
---|
113 | //
|
---|
114 | /////////////////////////////////////////////////////////////////////////////
|
---|
115 | void t_bncMap::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
|
---|
116 |
|
---|
117 | if (lonDeg > 180.0) lonDeg -= 360.0;
|
---|
118 |
|
---|
119 | QColor red(220,20,60);
|
---|
120 | QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
|
---|
121 | QPen(red), QSize(2,2));
|
---|
122 | QwtPlotMarker* marker = new QwtPlotMarker();
|
---|
123 | marker->setValue(lonDeg, latDeg);
|
---|
124 | marker->setLabelAlignment(Qt::AlignRight);
|
---|
125 | marker->setLabel(QwtText(name.left(4)));
|
---|
126 | marker->setSymbol(symbol);
|
---|
127 | marker->attach(_mapPlot);
|
---|
128 |
|
---|
129 | // Remeber minimal and maximal coordinates
|
---|
130 | // ---------------------------------------
|
---|
131 | if (_minPointLat == 0.0 && _maxPointLat == 0.0 &&
|
---|
132 | _minPointLon == 0.0 && _maxPointLon == 0.0) {
|
---|
133 | _minPointLat = latDeg;
|
---|
134 | _maxPointLat = latDeg;
|
---|
135 | _minPointLon = lonDeg;
|
---|
136 | _maxPointLon = lonDeg;
|
---|
137 | }
|
---|
138 | else {
|
---|
139 | if (_maxPointLat < latDeg) {
|
---|
140 | _maxPointLat = latDeg;
|
---|
141 | }
|
---|
142 | else if (_minPointLat > latDeg) {
|
---|
143 | _minPointLat = latDeg;
|
---|
144 | }
|
---|
145 | if (_maxPointLon < lonDeg) {
|
---|
146 | _maxPointLon = lonDeg;
|
---|
147 | }
|
---|
148 | else if (_minPointLon > lonDeg) {
|
---|
149 | _minPointLon = lonDeg;
|
---|
150 | }
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | // Close
|
---|
155 | ////////////////////////////////////////////////////////////////////////////
|
---|
156 | void t_bncMap::slotClose() {
|
---|
157 | done(0);
|
---|
158 | }
|
---|
159 |
|
---|
160 | // Close Dialog gracefully
|
---|
161 | ////////////////////////////////////////////////////////////////////////////
|
---|
162 | void t_bncMap::closeEvent(QCloseEvent* event) {
|
---|
163 | QDialog::closeEvent(event);
|
---|
164 | }
|
---|
165 |
|
---|
166 | //
|
---|
167 | ////////////////////////////////////////////////////////////////////////////
|
---|
168 | void t_bncMap::showEvent(QShowEvent* event) {
|
---|
169 | double width = _maxPointLon - _minPointLon;
|
---|
170 | double height = _maxPointLat - _minPointLat;
|
---|
171 | if (width > 0 && height > 0) {
|
---|
172 | double eps = 2.0;
|
---|
173 | QRectF rect(_minPointLon-eps, _minPointLat-eps, width+2*eps, height+2*eps);
|
---|
174 | _mapPlotZoomer->zoom(rect);
|
---|
175 | }
|
---|
176 | QDialog::showEvent(event);
|
---|
177 | }
|
---|
178 |
|
---|
179 | // Print the widget
|
---|
180 | ////////////////////////////////////////////////////////////////////////////
|
---|
181 | void t_bncMap::slotPrint() {
|
---|
182 |
|
---|
183 | QPrinter printer;
|
---|
184 | QPrintDialog* dialog = new QPrintDialog(&printer, this);
|
---|
185 | dialog->setWindowTitle(tr("Print Map"));
|
---|
186 | if (dialog->exec() != QDialog::Accepted) {
|
---|
187 | return;
|
---|
188 | }
|
---|
189 | else {
|
---|
190 | QwtPlotRenderer renderer;
|
---|
191 | renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
|
---|
192 | renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
|
---|
193 | renderer.renderTo(_mapPlot, printer);
|
---|
194 | }
|
---|
195 | }
|
---|