some more optimizations, added local/remote feature for graph markers

This commit is contained in:
Volker Fischer 2009-06-07 10:00:05 +00:00
parent 742201760b
commit 81c4f1f4d6
2 changed files with 71 additions and 34 deletions

View file

@ -29,8 +29,7 @@
CHistoryGraph::CHistoryGraph() : CHistoryGraph::CHistoryGraph() :
sFileName ( "" ), sFileName ( "" ),
bDoHistory ( false ), bDoHistory ( false ),
vDateTimeFifo ( NUM_ITEMS_HISTORY ), vHistoryDataFifo ( NUM_ITEMS_HISTORY ),
vItemTypeFifo ( NUM_ITEMS_HISTORY ),
PlotCanvasRect ( 0, 0, 600, 450 ), // defines total size of graph PlotCanvasRect ( 0, 0, 600, 450 ), // defines total size of graph
iNumTicksX ( 0 ), // just an initialization value, will be overwritten iNumTicksX ( 0 ), // just an initialization value, will be overwritten
iYAxisStart ( 0 ), iYAxisStart ( 0 ),
@ -42,12 +41,13 @@ CHistoryGraph::CHistoryGraph() :
iMarkerSize ( 9 ), iMarkerSize ( 9 ),
AxisFont ( "Arial", 12 ), AxisFont ( "Arial", 12 ),
iTextOffsetX ( 18 ), iTextOffsetX ( 18 ),
PlotBackgroundColor ( Qt::white ), // white background PlotBackgroundColor ( Qt::white ), // background
PlotFrameColor ( Qt::black ), // black frame PlotFrameColor ( Qt::black ), // frame
PlotGridColor ( Qt::gray ), // gray grid PlotGridColor ( Qt::gray ), // grid
PlotTextColor ( Qt::black ), // black text PlotTextColor ( Qt::black ), // text
PlotMarkerNewColor ( Qt::blue ), // blue marker for new connection PlotMarkerNewColor ( Qt::darkCyan ), // marker for new connection
PlotMarkerStopColor ( Qt::red ), // red marker server stop PlotMarkerNewLocalColor ( Qt::blue ), // marker for new local connection
PlotMarkerStopColor ( Qt::red ), // marker for server stop
PlotPixmap ( 1, 1, QImage::Format_RGB32 ) PlotPixmap ( 1, 1, QImage::Format_RGB32 )
{ {
// generate plot grid frame rectangle // generate plot grid frame rectangle
@ -164,12 +164,12 @@ void CHistoryGraph::DrawFrame ( const int iNewNumTicksX )
} }
} }
void CHistoryGraph::AddMarker ( const QDateTime& curDateTime, void CHistoryGraph::AddMarker ( const SHistoryData& curHistoryData )
const bool bIsServerStop )
{ {
// calculate x-axis offset (difference of days compared to // calculate x-axis offset (difference of days compared to
// current date) // current date)
const int iXAxisOffs = curDate.daysTo ( curDateTime.date() ); const int iXAxisOffs =
curDate.daysTo ( curHistoryData.DateTime.date() );
// check range, if out of range, do not plot anything // check range, if out of range, do not plot anything
if ( -iXAxisOffs > ( iNumTicksX - 1 ) ) if ( -iXAxisOffs > ( iNumTicksX - 1 ) )
@ -178,8 +178,8 @@ void CHistoryGraph::AddMarker ( const QDateTime& curDateTime,
} }
// calculate y-axis offset (consider hours and minutes) // calculate y-axis offset (consider hours and minutes)
const double dYAxisOffs = 24 - curDateTime.time().hour() - const double dYAxisOffs = 24 - curHistoryData.DateTime.time().hour() -
static_cast<double> ( curDateTime.time().minute() ) / 60; static_cast<double> ( curHistoryData.DateTime.time().minute() ) / 60;
// calculate the actual point in the graph (in pixels) // calculate the actual point in the graph (in pixels)
const QPoint curPoint ( const QPoint curPoint (
@ -191,17 +191,25 @@ void CHistoryGraph::AddMarker ( const QDateTime& curDateTime,
QPainter PlotPainter ( &PlotPixmap ); QPainter PlotPainter ( &PlotPixmap );
// we use different markers for new connection and server stop items // we use different markers for new connection and server stop items
if ( bIsServerStop ) switch ( curHistoryData.Type )
{ {
case HIT_SERVER_STOP:
// filled circle marker // filled circle marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerStopColor ), PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerStopColor ),
iMarkerSize, Qt::SolidLine, Qt::RoundCap ) ); iMarkerSize, Qt::SolidLine, Qt::RoundCap ) );
} break;
else
{ case HIT_LOCAL_CONNECTION:
// filled square marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerNewLocalColor ),
iMarkerSize ) );
break;
case HIT_REMOTE_CONNECTION:
// filled square marker // filled square marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerNewColor ), PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerNewColor ),
iMarkerSize ) ); iMarkerSize ) );
break;
} }
PlotPainter.drawPoint ( curPoint ); PlotPainter.drawPoint ( curPoint );
} }
@ -213,13 +221,16 @@ void CHistoryGraph::Save ( const QString sFileName )
} }
void CHistoryGraph::Add ( const QDateTime& newDateTime, void CHistoryGraph::Add ( const QDateTime& newDateTime,
const bool newIsServerStop ) const EHistoryItemType curType )
{ {
if ( bDoHistory ) if ( bDoHistory )
{ {
// add new element in FIFOs // create and add new element in FIFO
vDateTimeFifo.Add ( newDateTime ); SHistoryData curHistoryData;
vItemTypeFifo.Add ( static_cast<int> ( newIsServerStop ) ); curHistoryData.DateTime = newDateTime;
curHistoryData.Type = curType;
vHistoryDataFifo.Add ( curHistoryData );
} }
} }
@ -234,15 +245,15 @@ void CHistoryGraph::Update()
// get oldest date in history // get oldest date in history
QDate oldestDate = curDate.addDays ( 1 ); // one day in the future QDate oldestDate = curDate.addDays ( 1 ); // one day in the future
const int iNumItemsForHistory = vDateTimeFifo.Size(); const int iNumItemsForHistory = vHistoryDataFifo.Size();
for ( i = 0; i < iNumItemsForHistory; i++ ) for ( i = 0; i < iNumItemsForHistory; i++ )
{ {
// only use valid dates // only use valid dates
if ( vDateTimeFifo[i].date().isValid() ) if ( vHistoryDataFifo[i].DateTime.date().isValid() )
{ {
if ( vDateTimeFifo[i].date() < oldestDate ) if ( vHistoryDataFifo[i].DateTime.date() < oldestDate )
{ {
oldestDate = vDateTimeFifo[i].date(); oldestDate = vHistoryDataFifo[i].DateTime.date();
} }
} }
} }
@ -254,7 +265,7 @@ void CHistoryGraph::Update()
// add markers // add markers
for ( i = 0; i < iNumItemsForHistory; i++ ) for ( i = 0; i < iNumItemsForHistory; i++ )
{ {
AddMarker ( vDateTimeFifo[i], static_cast<bool> ( vItemTypeFifo[i] ) ); AddMarker ( vHistoryDataFifo[i] );
} }
// save graph as picture in file // save graph as picture in file
@ -299,8 +310,21 @@ void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr )
#endif #endif
*this << strLogStr; // in log file *this << strLogStr; // in log file
// add element to history // add element to history, distinguish between a local connection
HistoryGraph.Add ( QDateTime::currentDateTime(), false ); // and a remote connection
if ( ( ClientInetAddr == QHostAddress ( "127.0.0.1" ) ) ||
( ClientInetAddr.toString().left ( 7 ).compare ( "192.168" ) == 0 ) )
{
// local connection
HistoryGraph.Add ( QDateTime::currentDateTime(),
CHistoryGraph::HIT_LOCAL_CONNECTION );
}
else
{
// remote connection
HistoryGraph.Add ( QDateTime::currentDateTime(),
CHistoryGraph::HIT_REMOTE_CONNECTION );
}
} }
void CServerLogging::AddServerStopped() void CServerLogging::AddServerStopped()
@ -315,7 +339,9 @@ void CServerLogging::AddServerStopped()
*this << strLogStr; // in log file *this << strLogStr; // in log file
// add element to history and update on server stop // add element to history and update on server stop
HistoryGraph.Add ( QDateTime::currentDateTime(), true ); HistoryGraph.Add ( QDateTime::currentDateTime(),
CHistoryGraph::HIT_SERVER_STOP );
HistoryGraph.Update(); HistoryGraph.Update();
} }

View file

@ -47,15 +47,26 @@ class CHistoryGraph : public QObject
Q_OBJECT Q_OBJECT
public: public:
enum EHistoryItemType
{
HIT_LOCAL_CONNECTION,
HIT_REMOTE_CONNECTION,
HIT_SERVER_STOP
};
CHistoryGraph(); CHistoryGraph();
void Start ( const QString& sNewFileName ); void Start ( const QString& sNewFileName );
void Add ( const QDateTime& newDateTime, const bool newIsServerStop ); void Add ( const QDateTime& newDateTime, const EHistoryItemType curType );
void Update(); void Update();
protected: protected:
struct SHistoryData
{
QDateTime DateTime;
EHistoryItemType Type;
};
void DrawFrame ( const int iNewNumTicksX ); void DrawFrame ( const int iNewNumTicksX );
void AddMarker ( const QDateTime& curDateTime, void AddMarker ( const SHistoryData& curHistoryData );
const bool bIsServerStop );
void Save ( const QString sFileName ); void Save ( const QString sFileName );
bool bDoHistory; bool bDoHistory;
@ -76,6 +87,7 @@ protected:
QColor PlotGridColor; QColor PlotGridColor;
QColor PlotTextColor; QColor PlotTextColor;
QColor PlotMarkerNewColor; QColor PlotMarkerNewColor;
QColor PlotMarkerNewLocalColor;
QColor PlotMarkerStopColor; QColor PlotMarkerStopColor;
QDate curDate; QDate curDate;
QImage PlotPixmap; QImage PlotPixmap;
@ -84,8 +96,7 @@ protected:
QString sFileName; QString sFileName;
QTimer TimerDailyUpdate; QTimer TimerDailyUpdate;
CFIFO<QDateTime> vDateTimeFifo; CFIFO<SHistoryData> vHistoryDataFifo;
CFIFO<int> vItemTypeFifo;
public slots: public slots:
void OnTimerDailyUpdate() { Update(); } void OnTimerDailyUpdate() { Update(); }