source: ntrip/trunk/BNC/src/bncmap_svg.cpp@ 4636

Last change on this file since 4636 was 4636, checked in by mervart, 12 years ago
File size: 4.7 KB
Line 
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_panner.h>
50#include <qwt_plot_zoomer.h>
51#include <qwt_plot_magnifier.h>
52#include <qwt_plot_renderer.h>
53
54#include "bncmap.h"
55
56// Constructor
57/////////////////////////////////////////////////////////////////////////////
58t_bncMap::t_bncMap(QWidget* parent) : QDialog(parent) {
59
60 // Map in Scalable Vector Graphics (svg) Format
61 // --------------------------------------------
62 _mapPlot = new QwtPlot();
63
64 _mapPlot->setAxisScale(QwtPlot::xBottom, -180.0, 180.0);
65 _mapPlot->setAxisScale(QwtPlot::yLeft, -90.0, 90.0);
66
67 // (void)new QwtPlotPanner(_mapPlot->canvas());
68 // (void)new QwtPlotMagnifier(_mapPlot->canvas());
69 (void)new QwtPlotZoomer(_mapPlot->canvas());
70
71 _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus);
72
73 QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
74 mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
75 mapItem->attach(_mapPlot);
76
77 // Buttons
78 // -------
79 int ww = QFontMetrics(font()).width('w');
80
81 _buttonClose = new QPushButton(tr("Close"), this);
82 _buttonClose->setMaximumWidth(10*ww);
83 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
84
85 _buttonPrint = new QPushButton(tr("Print"), this);
86 _buttonPrint->setMaximumWidth(10*ww);
87 connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
88
89 // Layout
90 // ------
91 QHBoxLayout* buttonLayout = new QHBoxLayout;
92 buttonLayout->addWidget(_buttonClose);
93 buttonLayout->addWidget(_buttonPrint);
94
95 QVBoxLayout* mainLayout = new QVBoxLayout(this);
96 mainLayout->addWidget(_mapPlot);
97 mainLayout->addLayout(buttonLayout);
98
99 // Important
100 // ---------
101 _mapPlot->replot();
102}
103
104// Destructor
105/////////////////////////////////////////////////////////////////////////////
106t_bncMap::~t_bncMap() {
107 delete _mapPlot;
108}
109
110//
111/////////////////////////////////////////////////////////////////////////////
112void t_bncMap::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
113
114 if (lonDeg > 180.0) lonDeg -= 360.0;
115
116 QColor red(220,20,60);
117 QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
118 QPen(red), QSize(2,2));
119 QwtPlotMarker* marker = new QwtPlotMarker();
120 marker->setValue(lonDeg, latDeg);
121 marker->setLabelAlignment(Qt::AlignRight);
122 marker->setLabel(QwtText(name.left(4)));
123 marker->setSymbol(symbol);
124 marker->attach(_mapPlot);
125}
126
127// Close
128////////////////////////////////////////////////////////////////////////////
129void t_bncMap::slotClose() {
130 done(0);
131}
132
133// Close Dialog gracefully
134////////////////////////////////////////////////////////////////////////////
135void t_bncMap::closeEvent(QCloseEvent* event) {
136 QDialog::closeEvent(event);
137}
138
139// Print the widget
140////////////////////////////////////////////////////////////////////////////
141void t_bncMap::slotPrint() {
142
143 QPrinter printer;
144 QPrintDialog* dialog = new QPrintDialog(&printer, this);
145 dialog->setWindowTitle(tr("Print Map"));
146 if (dialog->exec() != QDialog::Accepted) {
147 return;
148 }
149 else {
150 QwtPlotRenderer renderer;
151 renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
152 renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
153 renderer.renderTo(_mapPlot, printer);
154 }
155}
Note: See TracBrowser for help on using the repository browser.