source: ntrip/trunk/BNC/bncmap.cpp@ 2754

Last change on this file since 2754 was 2754, checked in by mervart, 13 years ago
File size: 3.3 KB
Line 
1// ------------
2// author: jan dousa (jan.dousa@pecny.cz)
3// ------------
4
5#include <iostream>
6#include "bncmap.h"
7
8
9// ------------
10bncMap::bncMap(QWidget* parent) : QDialog(parent)
11{
12 _scale = 2.8; // scale the map
13 _LaOff = 20; // shift longitude
14 _mapView = new QGraphicsView();
15 _mapScen = new QGraphicsScene();
16 _mapView->setScene(_mapScen);
17 slotReadMap();
18 slotCreateMap();
19
20 setWindowTitle(tr("World Map [*]"));
21
22 /* close button */
23 QPushButton* buttClose = new QPushButton("Close");
24 connect(buttClose, SIGNAL(clicked()), this, SLOT(close()));
25
26 /* reset button */
27 QPushButton* buttReset = new QPushButton("Reset");
28 connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
29
30 /* layout */
31 QGridLayout *layout = new QGridLayout;
32 layout->setRowMinimumHeight( 0, 250);
33 layout->addWidget(_mapView, 0, 0, 3, 1, Qt::AlignLeft);
34 layout->addWidget(buttReset, 1, 1, 1, 1, Qt::AlignBottom);
35 layout->addWidget(buttClose, 2, 1, 1, 1, Qt::AlignBottom);
36 setLayout(layout);
37
38// this->resize(860,400);
39 this->show();
40}
41
42
43// ------------
44bncMap::~bncMap(){
45 delete _mapView;
46}
47
48
49// ------------
50void bncMap::slotReadMap()
51{
52 QFile world(":worldmap.dat");
53 float fi, la;
54
55 world.open(QIODevice::ReadOnly | QIODevice::Text);
56
57 QTextStream in(&world);
58 in.setRealNumberNotation(QTextStream::FixedNotation);
59
60 while( ! in.atEnd() ){
61
62 in >> la >> fi;
63 _worldMap << QPointF( la, -fi );
64
65 }
66
67 world.close();
68}
69
70
71// ------------
72void bncMap::slotCreateMap()
73{
74// mapScen->setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern)); // grid
75
76 int begIdx = 0;
77 int endIdx = 0;
78 for( int i=0; i < _worldMap.size(); i++ ){
79 if( _worldMap.at(i).x() == 0.0 and _worldMap.at(i).y() == 0.0 ){
80 if( i > 0 ){
81 endIdx = i-1;
82 while( begIdx < endIdx ){
83
84 int l1 = 0;
85 int l2 = 0;
86
87 float la1 = _worldMap.at(begIdx+0).x() + _LaOff;
88 float fi1 = _worldMap.at(begIdx+0).y();
89 float la2 = _worldMap.at(begIdx+1).x() + _LaOff;
90 float fi2 = _worldMap.at(begIdx+1).y();
91 begIdx++;
92
93 while( la1 < 0 ){ la1 += 360; l1++; }
94 while( la1 >= 360 ){ la1 -= 360; l1--; }
95 while( la2 < 0 ){ la2 += 360; l2++; }
96 while( la2 >= 360 ){ la2 -= 360; l2--; }
97
98 if( l1 != 0 and l2 == 0 ){ continue; } // break this line
99 if( l2 != 0 and l1 == 0 ){ continue; } // break this line
100
101 _mapScen->addLine(la1*_scale, fi1*_scale, la2*_scale, fi2*_scale, QPen(QBrush(Qt::black),1));
102 }
103 }
104 if( i+1 < _worldMap.size() ) begIdx = i+1;
105 }
106 }
107 _mapScen->setSceneRect(0*_scale,-90*_scale,360*_scale,180*_scale);
108}
109
110
111// ------------
112void bncMap::slotResetMap()
113{
114 QMutexLocker locker(&_mutexMap);
115 _mapScen->clear();
116 slotCreateMap();
117}
118
119
120// ------------
121void bncMap::slotNewPoint(QPointF point, QString name, QPen pen)
122{
123 float la = point.x() + _LaOff;
124 float fi = point.y();
125
126 while( la < 0 ){ la += 360; }
127 while( la >= 360 ){ la -= 360; }
128
129 _mapScen->addEllipse( la*_scale, -fi*_scale, 5, 5, pen );
130
131 if( ! name.isEmpty() ){
132 QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
133 nameItem->setPos( QPointF(la*_scale, -fi*_scale));
134 nameItem->setFont( QFont("Helvetica", 8) );
135
136 _mapScen->addItem( nameItem );
137 }
138}
Note: See TracBrowser for help on using the repository browser.