source: ntrip/trunk/BNC/bncfigurelate.cpp@ 1990

Last change on this file since 1990 was 1990, checked in by weber, 14 years ago

* empty log message *

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: bncFigureLate
30 *
31 * Purpose:
32 *
33 * Author: Perlt, Mervart
34 *
35 * Created: 11-Nov-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
43#include "bncfigurelate.h"
44#include "bncsettings.h"
45
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50bncFigureLate::bncFigureLate(QWidget *parent) : QWidget(parent) {
51 updateMountPoints();
52 slotNextAnimationFrame();
53 for (int ii = 0; ii <= 1000; ii++) {
54 _rgb[0][ii] = qrand() % 255;
55 _rgb[2][ii] = qrand() % 255;
56 _rgb[1][ii] = qrand() % 255;
57 }
58}
59
60// Destructor
61////////////////////////////////////////////////////////////////////////////
62bncFigureLate::~bncFigureLate() {
63}
64
65//
66////////////////////////////////////////////////////////////////////////////
67void bncFigureLate::updateMountPoints() {
68 QMutexLocker locker(&_mutex);
69
70 _latency.clear();
71
72 bncSettings settings;
73 QListIterator<QString> it(settings.value("mountPoints").toStringList());
74 while (it.hasNext()) {
75 QStringList hlp = it.next().split(" ");
76 QUrl url(hlp[0]);
77 QByteArray staID = url.path().mid(1).toAscii();
78 _latency[staID] = 0.0;
79 }
80}
81
82//
83////////////////////////////////////////////////////////////////////////////
84void bncFigureLate::slotNewLatency(const QByteArray staID, double clate) {
85 QMutexLocker locker(&_mutex);
86 if (_latency.find(staID) != _latency.end()) {
87 _latency[staID] = fabs(clate)*1000.0;
88 }
89}
90
91//
92////////////////////////////////////////////////////////////////////////////
93void bncFigureLate::slotNextAnimationFrame() {
94 QMutexLocker locker(&_mutex);
95 update();
96 QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
97}
98
99//
100////////////////////////////////////////////////////////////////////////////
101void bncFigureLate::paintEvent(QPaintEvent *) {
102
103 int xMin = 0;
104 int xMax = 640;
105 int yMin = 0;
106 int yMax = 140;
107 float xLine = .60;
108
109 QPainter painter(this);
110
111 QFont font;
112 font.setPointSize(int(font.QFont::pointSize()*0.8));
113 painter.setFont(font);
114
115 // y-axis
116 // ------
117 int yLength = int((yMax-yMin)*xLine) - (yMin+10);
118 painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMin+60, yMin+10);
119 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 ms "));
120
121 double maxLate = 0.0;
122 QMapIterator<QByteArray, double> it1(_latency);
123 while (it1.hasNext()) {
124 it1.next();
125 if (it1.value() > maxLate) {
126 maxLate = it1.value();
127 }
128 }
129
130 if(maxLate > 0.0) {
131 QString maxLateStr;
132 maxLateStr = QString("%1 ms ").arg(int(maxLate));
133 painter.drawText(0, yMin+25-5, xMin+60,15,Qt::AlignRight,maxLateStr);
134 }
135
136 // x-axis
137 // ------
138 painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMax*3, int((yMax-yMin)*xLine));
139
140 int anchor = 0;
141 QMapIterator<QByteArray, double> it(_latency);
142 while (it.hasNext()) {
143 it.next();
144 QByteArray staID = it.key();
145
146 int xx = xMin+80+anchor*12;
147
148 if(maxLate > 0.0) {
149 int yy = int(yLength * (it.value() / maxLate));
150 QColor color = QColor::fromRgb(_rgb[0][anchor],_rgb[1][anchor],_rgb[2][anchor]);
151 painter.fillRect(xx-13, int((yMax-yMin)*xLine)-yy, 9, yy,
152 QBrush(color,Qt::SolidPattern));
153 painter.setPen(Qt::black);
154 if(it.value()<=0) {
155 painter.setPen(Qt::red);
156 }
157 }
158
159 painter.save();
160 painter.translate(xx-13, int(yMax-yMin)*xLine+65);
161 painter.rotate(-90);
162 painter.drawText(0,0,65,50,Qt::AlignRight,staID.left(5) + " ");
163 painter.restore();
164
165 anchor++;
166 }
167}
168
Note: See TracBrowser for help on using the repository browser.