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

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