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

Last change on this file since 4634 was 4634, checked in by mervart, 12 years ago
File size: 3.3 KB
Line 
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/////////////////////////////////////////////////////////////////////////////
19t_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/////////////////////////////////////////////////////////////////////////////
67t_bncMap::~t_bncMap() {
68 delete _mapPlot;
69}
70
71//
72/////////////////////////////////////////////////////////////////////////////
73void t_bncMap::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
74 QColor red(220,20,60);
75 QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
76 QPen(red), QSize(2,2));
77 QwtPlotMarker* marker = new QwtPlotMarker();
78 marker->setValue(lonDeg, latDeg);
79 marker->setLabelAlignment(Qt::AlignRight);
80 marker->setLabel(QwtText(name.left(4)));
81 marker->setSymbol(symbol);
82 marker->attach(_mapPlot);
83}
84
85// Close
86////////////////////////////////////////////////////////////////////////////
87void t_bncMap::slotClose() {
88 done(0);
89}
90
91// Close Dialog gracefully
92////////////////////////////////////////////////////////////////////////////
93void t_bncMap::closeEvent(QCloseEvent* event) {
94 QDialog::closeEvent(event);
95}
96
97// Print the widget
98////////////////////////////////////////////////////////////////////////////
99void t_bncMap::slotPrint() {
100
101 QPrinter printer;
102 QPrintDialog* dialog = new QPrintDialog(&printer, this);
103 dialog->setWindowTitle(tr("Print Map"));
104 if (dialog->exec() != QDialog::Accepted) {
105 return;
106 }
107 else {
108 QwtPlotRenderer renderer;
109 renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
110 renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
111 renderer.renderTo(_mapPlot, printer);
112 }
113}
Note: See TracBrowser for help on using the repository browser.