source: ntrip/trunk/BNC/src/bncfigure.cpp@ 10554

Last change on this file since 10554 was 10524, checked in by stuerze, 3 months ago

replacement of obsolete qt-class members

File size: 6.1 KB
RevLine 
[1932]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: bncFigure
30 *
[7640]31 * Purpose:
[1932]32 *
33 * Author: Perlt, Mervart
34 *
35 * Created: 11-Nov-2009
36 *
[7640]37 * Changes:
[1932]38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
[8252]43#include <QMapIterator>
44#include <QPainter>
45#include <QTimer>
46#include <QUrl>
47#include <QVariant>
48
[7640]49#include "bncfigure.h"
[1932]50#include "bncsettings.h"
51
52using namespace std;
53
54// Constructor
55////////////////////////////////////////////////////////////////////////////
56bncFigure::bncFigure(QWidget *parent) : QWidget(parent) {
[1933]57 updateMountPoints();
58 slotNextAnimationFrame();
[1956]59 for (int ii = 0; ii <= 1000; ii++) {
[10524]60 _ran[0][ii] = rand() % 255;
61 _ran[1][ii] = rand() % 255;
62 _ran[2][ii] = rand() % 255;
[1956]63 }
[1933]64}
65
66// Destructor
67////////////////////////////////////////////////////////////////////////////
[7640]68bncFigure::~bncFigure() {
69 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
70 while (it.hasNext()) {
71 it.next();
72 delete it.value();
73 }
[10234]74 _bytes.clear();
[1933]75}
76
[7640]77//
[1933]78////////////////////////////////////////////////////////////////////////////
79void bncFigure::updateMountPoints() {
80 QMutexLocker locker(&_mutex);
81
82 _counter = 0;
[1936]83 _maxRate = 0;
[1933]84
85 QMapIterator<QByteArray, sumAndMean*> it1(_bytes);
86 while (it1.hasNext()) {
87 it1.next();
88 delete it1.value();
89 }
90 _bytes.clear();
91
[1932]92 bncSettings settings;
93 QListIterator<QString> it(settings.value("mountPoints").toStringList());
94 while (it.hasNext()) {
95 QStringList hlp = it.next().split(" ");
[7182]96 if (hlp.size() <= 1) continue;
[1932]97 QUrl url(hlp[0]);
[8204]98 QByteArray staID = url.path().mid(1).toLatin1();
[1932]99 _bytes[staID] = new sumAndMean();
100 }
101}
102
[7640]103//
[1932]104////////////////////////////////////////////////////////////////////////////
105void bncFigure::slotNewData(const QByteArray staID, double nbyte) {
106 QMutexLocker locker(&_mutex);
107 QMap<QByteArray, sumAndMean*>::const_iterator it = _bytes.find(staID);
108 if (it != _bytes.end()) {
[2007]109 it.value()->_sum += nbyte*8.;
[1932]110 }
111}
112
[7640]113//
[1932]114////////////////////////////////////////////////////////////////////////////
115void bncFigure::slotNextAnimationFrame() {
116 QMutexLocker locker(&_mutex);
[1934]117
118 const static int MAXCOUNTER = 10;
119
120 ++_counter;
121
[1935]122 // If counter reaches its maximal value, compute the mean rate
123 // -----------------------------------------------------------
[1934]124 if (_counter == MAXCOUNTER) {
[1936]125 _maxRate = 0.0;
[1935]126 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
127 while (it.hasNext()) {
128 it.next();
129 it.value()->_mean = it.value()->_sum / _counter;
[1936]130 it.value()->_sum = 0.0;
131 if (it.value()->_mean > _maxRate) {
132 _maxRate = it.value()->_mean;
133 }
134 }
[1932]135 _counter = 0;
136 }
[1934]137
[1932]138 update();
[1935]139
[1932]140 QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
141}
142
[7640]143//
[1932]144////////////////////////////////////////////////////////////////////////////
145void bncFigure::paintEvent(QPaintEvent *) {
[1936]146
147 int xMin = 0;
148 int xMax = 640;
149 int yMin = 0;
[9124]150 int yMax = 90;
[1951]151 float xLine = .60;
[1936]152
[1932]153 QPainter painter(this);
154
[1960]155 QFont font;
[1963]156 font.setPointSize(int(font.QFont::pointSize()*0.8));
[1960]157 painter.setFont(font);
158
[1936]159 // y-axis
160 // ------
[1951]161 int yLength = int((yMax-yMin)*xLine) - (yMin+10);
[1989]162 painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMin+60, yMin+10);
[1936]163
[2007]164 double maxRateRounded;
[1938]165 QString maxRateStr;
[2007]166 if (_maxRate < 1e3) {
167 maxRateRounded = int(_maxRate/200)*200 + 300;
168 maxRateStr = QString("%1 bps ").arg(int(maxRateRounded/200)*200);
[1989]169 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 bps "));
[1938]170 }
[2007]171 else if (_maxRate < 1e6) {
172 maxRateRounded = int(_maxRate/1.e3)*1.e3 + 1500;
173 maxRateStr = QString("%1 kbps ").arg(int(maxRateRounded/1.e3));
[1989]174 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 kbps "));
[1938]175 }
176 else {
[2007]177 maxRateRounded = int(_maxRate/1.e6)*1.e6 + 1500000;
178 maxRateStr = QString("%1 Mbps ").arg(int(maxRateRounded/1.e6));
[1989]179 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 Mbps "));
[1938]180 }
181
[1951]182 if(_maxRate > 0.0) {
[2007]183 painter.drawText(0, yMin+20-5, xMin+60,15,Qt::AlignRight,maxRateStr);
[1951]184 }
[1938]185
[1936]186 // x-axis
187 // ------
[1989]188 painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMax*3, int((yMax-yMin)*xLine));
[1936]189
190 int anchor = 0;
[1932]191 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
192 while (it.hasNext()) {
193 it.next();
194 QByteArray staID = it.key();
[1936]195
[1989]196 int xx = xMin+80+anchor*12;
[1936]197
[1948]198 if(_maxRate > 0.0) {
[2007]199 int yy = int(yLength * (it.value()->_mean / maxRateRounded));
[1994]200 QColor color = QColor::fromRgb(_ran[0][anchor],_ran[1][anchor],_ran[2][anchor],150);
[7640]201 painter.fillRect(xx-13, int((yMax-yMin)*xLine)-yy, 9, yy,
[1956]202 QBrush(color,Qt::SolidPattern));
[1990]203 painter.setPen(Qt::black);
204 if(it.value()->_mean<=0) {
205 painter.setPen(Qt::red);
206 }
[1948]207 }
[1937]208
[1990]209 painter.save();
210 painter.translate(xx-13, int(yMax-yMin)*xLine+65);
211 painter.rotate(-90);
[9124]212 painter.drawText(-30,0,95,50,Qt::AlignRight,staID.left(10) + " ");
[1990]213 painter.restore();
214
[1936]215 anchor++;
[1932]216 }
217}
218
Note: See TracBrowser for help on using the repository browser.