[4622] | 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>
|
---|
[4629] | 11 | #include <qwt_symbol.h>
|
---|
[4622] | 12 |
|
---|
| 13 | #include "bncmap.h"
|
---|
| 14 |
|
---|
| 15 | // Constructor
|
---|
| 16 | /////////////////////////////////////////////////////////////////////////////
|
---|
[4626] | 17 | t_bncMap::t_bncMap(QWidget* parent) : QDialog(parent) {
|
---|
[4622] | 18 |
|
---|
[4630] | 19 | // Map in Scalable Vector Graphics (svg) Format
|
---|
| 20 | // --------------------------------------------
|
---|
[4626] | 21 | _mapPlot = new QwtPlot();
|
---|
[4622] | 22 |
|
---|
[4626] | 23 | (void)new QwtPlotPanner(_mapPlot->canvas());
|
---|
| 24 | (void)new QwtPlotMagnifier(_mapPlot->canvas());
|
---|
[4622] | 25 |
|
---|
[4626] | 26 | _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus);
|
---|
[4622] | 27 |
|
---|
[4626] | 28 | QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
|
---|
| 29 | mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
|
---|
| 30 | mapItem->attach(_mapPlot);
|
---|
[4622] | 31 |
|
---|
[4630] | 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 |
|
---|
[4622] | 50 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
[4626] | 51 | mainLayout->addWidget(_mapPlot);
|
---|
[4630] | 52 | mainLayout->addLayout(buttonLayout);
|
---|
[4622] | 53 |
|
---|
[4630] | 54 | // Important
|
---|
| 55 | // ---------
|
---|
[4626] | 56 | _mapPlot->replot();
|
---|
[4622] | 57 | }
|
---|
| 58 |
|
---|
| 59 | // Destructor
|
---|
| 60 | /////////////////////////////////////////////////////////////////////////////
|
---|
[4626] | 61 | t_bncMap::~t_bncMap() {
|
---|
| 62 | delete _mapPlot;
|
---|
[4622] | 63 | }
|
---|
[4626] | 64 |
|
---|
| 65 | //
|
---|
| 66 | /////////////////////////////////////////////////////////////////////////////
|
---|
[4627] | 67 | void t_bncMap::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
|
---|
[4629] | 68 | QColor red(220,20,60);
|
---|
| 69 | QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
|
---|
| 70 | QPen(red), QSize(2,2));
|
---|
[4626] | 71 | QwtPlotMarker* marker = new QwtPlotMarker();
|
---|
[4627] | 72 | marker->setValue(lonDeg, latDeg);
|
---|
[4629] | 73 | marker->setLabelAlignment(Qt::AlignRight);
|
---|
[4628] | 74 | marker->setLabel(QwtText(name.left(4)));
|
---|
[4629] | 75 | marker->setSymbol(symbol);
|
---|
[4626] | 76 | marker->attach(_mapPlot);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[4630] | 79 | // Close
|
---|
| 80 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 81 | void t_bncMap::slotClose() {
|
---|
| 82 | done(0);
|
---|
| 83 | }
|
---|
[4626] | 84 |
|
---|
[4630] | 85 | // Close Dialog gracefully
|
---|
| 86 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 87 | void t_bncMap::closeEvent(QCloseEvent* event) {
|
---|
| 88 | QDialog::closeEvent(event);
|
---|
| 89 | }
|
---|
[4626] | 90 |
|
---|
[4630] | 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 | }
|
---|