jamulus/src/historygraph.h

189 lines
6.2 KiB
C
Raw Normal View History

2019-05-26 20:23:13 +02:00
/******************************************************************************\
2020-01-01 15:41:43 +01:00
* Copyright (c) 2004-2020
2019-05-26 20:23:13 +02:00
*
* Author(s):
* Volker Fischer
* Peter L Jones <pljones@users.sf.net>
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2019-05-26 20:23:13 +02:00
*
\******************************************************************************/
2019-07-09 08:52:38 +02:00
#pragma once
2019-05-19 09:30:49 +02:00
#include <QDateTime>
#include <QHostAddress>
#include <QFile>
#include <QString>
#include <QTimer>
#include "global.h"
#include "util.h"
2019-05-26 20:00:09 +02:00
// for CJpegHistoryGraph
#ifndef HEADLESS
# include <QImage>
# include <QPainter>
#endif
2019-05-26 20:00:09 +02:00
// for CSvgHistoryGraph
#include <QXmlStreamWriter>
#include <QXmlStreamAttributes>
2019-05-27 18:04:24 +02:00
2020-03-22 18:45:00 +01:00
/* Definitions ****************************************************************/
// number of history items to store
#define NUM_ITEMS_HISTORY 20000
2019-05-26 20:00:09 +02:00
/* Interface ******************************************************************/
2019-05-20 21:00:09 +02:00
class AHistoryGraph
2019-05-19 09:30:49 +02:00
{
public:
enum EHistoryItemType
{
HIT_LOCAL_CONNECTION,
HIT_REMOTE_CONNECTION,
HIT_SERVER_STOP
};
2020-03-22 20:24:30 +01:00
AHistoryGraph ( const int iMaxDaysHistory );
2020-06-24 17:26:36 +02:00
virtual ~AHistoryGraph() { }
2019-05-20 21:00:09 +02:00
2019-05-19 09:30:49 +02:00
void Start ( const QString& sNewFileName );
void Add ( const QDateTime& newDateTime, const EHistoryItemType curType );
void Add ( const QDateTime& newDateTime, const QHostAddress ClientInetAddr );
2019-05-20 21:00:09 +02:00
virtual void Update ( );
2019-05-19 09:30:49 +02:00
protected:
struct SHistoryData
{
QDateTime DateTime;
EHistoryItemType Type;
};
void DrawFrame ( const int iNewNumTicksX );
void AddMarker ( const SHistoryData& curHistoryData );
2019-05-20 21:00:09 +02:00
virtual void Save ( const QString sFileName ) = 0;
2019-05-19 09:30:49 +02:00
2019-05-20 21:00:09 +02:00
virtual void rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height ) = 0;
virtual void text ( const unsigned int x, const unsigned int y, const QString& value ) = 0;
virtual void line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth = 1 ) = 0;
virtual void point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour ) = 0;
2019-05-19 09:30:49 +02:00
2019-05-20 21:00:09 +02:00
// Constructor sets these
QString sFileName;
2019-05-19 09:30:49 +02:00
bool bDoHistory;
CFIFO<SHistoryData> vHistoryDataFifo;
2019-05-20 21:00:09 +02:00
unsigned int iNumTicksX; // Class global, not sure why
2020-03-21 19:57:18 +01:00
int iHistMaxDays;
2019-05-20 21:00:09 +02:00
QString BackgroundColor;
QString FrameColor;
QString GridColor;
QString TextColor;
QString MarkerNewColor;
QString MarkerNewLocalColor;
QString MarkerStopColor;
const unsigned int canvasRectX;
const unsigned int canvasRectY;
const unsigned int canvasRectWidth;
const unsigned int canvasRectHeight;
const unsigned int iGridFrameOffset;
const unsigned int iGridWidthWeekend;
const unsigned int iXAxisTextHeight;
const unsigned int gridFrameX;
const unsigned int gridFrameY;
const unsigned int gridFrameWidth;
const unsigned int gridFrameHeight;
const unsigned int gridFrameRight;
const unsigned int gridFrameBottom;
const QString axisFontFamily;
const QString axisFontWeight;
const unsigned int axisFontSize;
const unsigned int iYAxisStart;
const unsigned int iYAxisEnd;
const unsigned int iNumTicksY;
const unsigned int iTextOffsetToGrid;
const unsigned int iTextOffsetX;
const unsigned int iMarkerSizeNewCon;
const unsigned int iMarkerSizeServSt;
// others
2019-05-27 18:04:24 +02:00
double dayXSpace;
2019-05-20 21:00:09 +02:00
unsigned int iYSpace;
2019-05-27 18:04:24 +02:00
QDate curDate;
QTimer TimerDailyUpdate;
2019-05-19 09:30:49 +02:00
};
2019-05-27 18:04:24 +02:00
2019-05-26 20:00:09 +02:00
/* Implementations ************************************************************/
#ifndef HEADLESS
2019-05-26 20:00:09 +02:00
class CJpegHistoryGraph : public QObject, virtual public AHistoryGraph
{
Q_OBJECT
public:
2020-03-22 20:24:30 +01:00
CJpegHistoryGraph ( const int iMaxDaysHistory );
2019-05-26 20:00:09 +02:00
virtual void Update ( );
protected:
virtual void Save ( const QString sFileName );
virtual void rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height );
virtual void text ( const unsigned int x, const unsigned int y, const QString& value );
virtual void line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth = 1 );
virtual void point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour );
private:
QImage PlotPixmap;
int iAxisFontWeight;
public slots:
void OnTimerDailyUpdate() { Update(); }
};
#endif
2019-05-26 20:00:09 +02:00
class CSvgHistoryGraph : public QObject, virtual public AHistoryGraph
{
Q_OBJECT
public:
2020-03-22 20:24:30 +01:00
CSvgHistoryGraph ( const int iMaxDaysHistory );
2019-05-26 20:00:09 +02:00
virtual void Update();
protected:
virtual void Save ( const QString sFileName );
virtual void rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height );
virtual void text ( const unsigned int x, const unsigned int y, const QString& value );
virtual void line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth = 1 );
virtual void point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour );
private:
QXmlStreamAttributes svgRootAttributes;
QString svgImage;
QXmlStreamWriter svgStreamWriter;
public slots:
void OnTimerDailyUpdate() { Update(); }
};