source: ntrip/trunk/BNC/bncfigure.cpp@ 1935

Last change on this file since 1935 was 1935, checked in by mervart, 14 years ago

* empty log message *

File size: 4.4 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: bncFigure
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 "bncfigure.h"
44#include "bncsettings.h"
45
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50bncFigure::bncFigure(QWidget *parent) : QWidget(parent) {
51 updateMountPoints();
52 slotNextAnimationFrame();
53}
54
55// Destructor
56////////////////////////////////////////////////////////////////////////////
57bncFigure::~bncFigure() {
58}
59
60//
61////////////////////////////////////////////////////////////////////////////
62void bncFigure::updateMountPoints() {
63 QMutexLocker locker(&_mutex);
64
65 _counter = 0;
66
67 QMapIterator<QByteArray, sumAndMean*> it1(_bytes);
68 while (it1.hasNext()) {
69 it1.next();
70 delete it1.value();
71 }
72 _bytes.clear();
73
74 bncSettings settings;
75 QListIterator<QString> it(settings.value("mountPoints").toStringList());
76 while (it.hasNext()) {
77 QStringList hlp = it.next().split(" ");
78 QUrl url(hlp[0]);
79 QByteArray staID = url.path().mid(1).toAscii();
80 _bytes[staID] = new sumAndMean();
81 }
82}
83
84//
85////////////////////////////////////////////////////////////////////////////
86void bncFigure::slotNewData(const QByteArray staID, double nbyte) {
87 QMutexLocker locker(&_mutex);
88 QMap<QByteArray, sumAndMean*>::const_iterator it = _bytes.find(staID);
89 if (it != _bytes.end()) {
90 it.value()->_sum += nbyte;
91 }
92}
93
94//
95////////////////////////////////////////////////////////////////////////////
96void bncFigure::slotNextAnimationFrame() {
97 QMutexLocker locker(&_mutex);
98
99 const static int MAXCOUNTER = 10;
100
101 ++_counter;
102
103 // If counter reaches its maximal value, compute the mean rate
104 // -----------------------------------------------------------
105 if (_counter == MAXCOUNTER) {
106 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
107 while (it.hasNext()) {
108 it.next();
109 it.value()->_mean = it.value()->_sum / _counter;
110 it.value()->_sum = 0.0;
111 }
112 _counter = 0;
113 }
114
115 update();
116
117 QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
118}
119
120//
121////////////////////////////////////////////////////////////////////////////
122void bncFigure::paintEvent(QPaintEvent *) {
123 QRectF rectangle(0, 0, 640, 180);
124 QBrush rBrush(Qt::white,Qt::SolidPattern);
125 QPainter painter(this);
126 painter.fillRect(rectangle,rBrush);
127 painter.drawRect(rectangle);
128 QLine line(50, 140, 630, 140);
129 painter.drawLine(line);
130 line.setLine(50, 140, 50, 10);
131 painter.drawLine(line);
132 QPoint textP(40, 140);
133 painter.drawText(textP, tr("0"));
134 textP.setX(20);
135 textP.setY(25);
136 painter.drawText(textP, tr("3000"));
137 int anker=0;
138 textP.setY(160);
139 painter.drawText(textP, tr(QTime::currentTime().toString().toAscii()));
140 textP.setX(300);
141
142 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
143 while (it.hasNext()) {
144 it.next();
145 QByteArray staID = it.key();
146 double vv = it.value()->_mean;
147 QRectF vrect((100+anker*40), (140-vv), (30), (vv));
148 QBrush xBrush(Qt::green,Qt::SolidPattern);
149 textP.setX(100+anker*40);
150 painter.fillRect(vrect,xBrush);
151 painter.drawRect(vrect);
152 painter.drawText(textP, staID);
153 anker++;
154 }
155}
156
Note: See TracBrowser for help on using the repository browser.