1 /***************************************************************************
2 statistics.cpp - description
4 begin : Mon Aug 19 2002
5 copyright : (C) 2002 by Stefan Winter
6 email : mail@stefan-winter.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
21 #include <QPaintEvent>
23 #include "statistics.h"
24 #include "interface_wireless.h"
25 #include "kwifi_settings.h"
27 Statistics::Statistics ( Interface_wireless
* device
, QWidget
* parent
):QWidget ( parent
)
29 this->device
= device
;
33 Statistics::determineTop ( )
35 return ( device
->sigLevelMax
> device
->noiseLevelMax
) ? device
->sigLevelMax
: device
->noiseLevelMax
;
39 Statistics::determineBottom ( )
41 return ( device
->sigLevelMin
> device
->noiseLevelMin
) ? device
->noiseLevelMin
: device
->sigLevelMin
;
45 Statistics::paintEvent ( QPaintEvent
* )
47 statpainter
= new QPainter ( this );
48 QColor
farbe ( 255, 255, 255 );
49 statpainter
->fillRect ( 0, 0, 480, 201, farbe
);
50 QPolygon
signal ( 240 );
51 QPolygon
noise ( 240 );
53 int datarange
= determineTop ( ) - determineBottom ( );
55 // if values are all below 0, this indicates proper dBm values
59 scaleRatio
= 200. / datarange
;
64 bool atLeastOneValid
= false;
65 for ( int j
= device
->current
; j
< device
->current
+ MAX_HISTORY
; j
++ )
67 if ( device
->valid
[j
% MAX_HISTORY
] )
69 atLeastOneValid
= true;
70 signal
.setPoint ( i
, ( i
* 2 ),
72 ( int ) ( ( ( device
->sigLevel
[j
% MAX_HISTORY
] +
73 device
->sigLevel
[( j
- 1 ) % MAX_HISTORY
] ) / 2 -
74 determineBottom ( ) ) * scaleRatio
) );
75 noise
.setPoint ( i
, ( i
* 2 ),
77 ( int ) ( ( ( device
->noiseLevel
[j
% MAX_HISTORY
] +
78 device
->noiseLevel
[( j
- 1 ) % MAX_HISTORY
] ) / 2 -
79 determineBottom ( ) ) * scaleRatio
) );
83 signal
.setPoint ( i
, ( i
* 2 ), 200 );
84 noise
.setPoint ( i
, ( i
* 2 ), 200 );
88 // the above point array is only useful if at least one entry has its
89 // valid flag set. This fact is determined in the iteration before.
90 // Only paint the point array if there is one valid entry
91 if ( atLeastOneValid
)
93 if ( KWiFiSettings::self()->showNoiseInStats() )
95 statpainter
->setPen ( Qt::red
);
96 statpainter
->drawPolyline ( noise
);
98 statpainter
->setPen ( Qt::blue
);
99 statpainter
->drawPolyline ( signal
);