Merge pull request #8 from pljones/feature/pljones-svg-history
Feature/pljones svg history
This commit is contained in:
commit
4deae974c3
8 changed files with 317 additions and 288 deletions
|
@ -174,9 +174,7 @@ HEADERS += src/audiomixerboard.h \
|
|||
src/recorder/jamrecorder.h \
|
||||
src/recorder/creaperproject.h \
|
||||
src/recorder/cwavestream.h \
|
||||
src/historygraph.h \
|
||||
src/jpeghistorygraph.h \
|
||||
src/svghistorygraph.h
|
||||
src/historygraph.h
|
||||
|
||||
HEADERS_OPUS = libs/opus/include/opus.h \
|
||||
libs/opus/include/opus_multistream.h \
|
||||
|
@ -274,9 +272,7 @@ SOURCES += src/audiomixerboard.cpp \
|
|||
src/recorder/jamrecorder.cpp \
|
||||
src/recorder/creaperproject.cpp \
|
||||
src/recorder/cwavestream.cpp \
|
||||
src/historygraph.cpp \
|
||||
src/jpeghistorygraph.cpp \
|
||||
src/svghistorygraph.cpp
|
||||
src/historygraph.cpp
|
||||
|
||||
SOURCES_OPUS = libs/opus/src/opus.c \
|
||||
libs/opus/src/opus_decoder.c \
|
||||
|
|
|
@ -1,5 +1,31 @@
|
|||
/******************************************************************************\
|
||||
* Copyright (c) 2004-2019
|
||||
*
|
||||
* 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.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
\******************************************************************************/
|
||||
|
||||
#include "historygraph.h"
|
||||
|
||||
/* Abstract class *************************************************************/
|
||||
AHistoryGraph::AHistoryGraph() :
|
||||
sFileName ( "" ),
|
||||
bDoHistory ( false ),
|
||||
|
@ -168,7 +194,7 @@ void AHistoryGraph::DrawFrame ( const int iNewNumTicksX )
|
|||
{
|
||||
int iBottomExtraTickLen = 0;
|
||||
const int iCurX = gridFrameX + static_cast<int> ( dayXSpace * ( i + 1 ) );
|
||||
const QDate curXAxisDate = curDate.addDays ( i - iNumTicksX + 1 );
|
||||
const QDate curXAxisDate = curDate.addDays ( 0 - static_cast<signed>( iNumTicksX ) + i + 1 );
|
||||
|
||||
// text (print only every "iXAxisTickStep" tick)
|
||||
if ( !( i % iXAxisTickStep ) )
|
||||
|
@ -219,7 +245,7 @@ void AHistoryGraph::AddMarker ( const SHistoryData& curHistoryData )
|
|||
curDate.daysTo ( curHistoryData.DateTime.date() );
|
||||
|
||||
// check range, if out of range, do not plot anything
|
||||
if ( -iXAxisOffs > ( static_cast<int>(iNumTicksX) - 1 ) )
|
||||
if ( -iXAxisOffs > ( static_cast<signed>( iNumTicksX ) - 1 ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -229,7 +255,7 @@ void AHistoryGraph::AddMarker ( const SHistoryData& curHistoryData )
|
|||
static_cast<double> ( curHistoryData.DateTime.time().minute() ) / 60;
|
||||
|
||||
// calculate the actual point in the graph (in pixels)
|
||||
int curPointX = gridFrameX + static_cast<int> ( dayXSpace * ( iNumTicksX + iXAxisOffs ) );
|
||||
int curPointX = gridFrameX + static_cast<int> ( dayXSpace * ( static_cast<signed>( iNumTicksX ) + iXAxisOffs ) );
|
||||
int curPointY = gridFrameY + static_cast<int> ( static_cast<double> (
|
||||
gridFrameHeight ) / ( iYAxisEnd - iYAxisStart ) * dYAxisOffs );
|
||||
QString curPointColour = MarkerNewColor;
|
||||
|
@ -252,5 +278,205 @@ void AHistoryGraph::AddMarker ( const SHistoryData& curHistoryData )
|
|||
break;
|
||||
}
|
||||
|
||||
point( curPointX, curPointY, curPointSize, curPointColour );
|
||||
point( curPointX - curPointSize / 2, curPointY - curPointSize / 2, curPointSize, curPointColour );
|
||||
}
|
||||
|
||||
/* JPEG History Graph implementation ******************************************/
|
||||
CJpegHistoryGraph::CJpegHistoryGraph() :
|
||||
AHistoryGraph(),
|
||||
PlotPixmap ( 1, 1, QImage::Format_RGB32 ),
|
||||
iAxisFontWeight ( -1 )
|
||||
{
|
||||
// scale pixmap to correct size
|
||||
PlotPixmap = PlotPixmap.scaled ( canvasRectWidth, canvasRectHeight );
|
||||
|
||||
// axisFontWeight is a string matching the CSS2 font-weight definition
|
||||
// Thin = 0, // 100
|
||||
// ExtraLight = 12, // 200
|
||||
// Light = 25, // 300
|
||||
// Normal = 50, // 400
|
||||
// Medium = 57, // 500
|
||||
// DemiBold = 63, // 600
|
||||
// Bold = 75, // 700
|
||||
// ExtraBold = 81, // 800
|
||||
// Black = 87 // 900
|
||||
bool ok;
|
||||
int weight = axisFontWeight.toInt( &ok );
|
||||
if (!ok)
|
||||
{
|
||||
if (!QString("normal").compare(axisFontWeight, Qt::CaseSensitivity::CaseInsensitive)) { iAxisFontWeight = 50; }
|
||||
else if (!QString("bold").compare(axisFontWeight, Qt::CaseSensitivity::CaseInsensitive)) { weight = 75; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weight <= 100) { iAxisFontWeight = 0; }
|
||||
else if (weight <= 200) { iAxisFontWeight = 12; }
|
||||
else if (weight <= 300) { iAxisFontWeight = 25; }
|
||||
else if (weight <= 400) { iAxisFontWeight = 50; }
|
||||
else if (weight <= 500) { iAxisFontWeight = 57; }
|
||||
else if (weight <= 600) { iAxisFontWeight = 63; }
|
||||
else if (weight <= 700) { iAxisFontWeight = 75; }
|
||||
else if (weight <= 800) { iAxisFontWeight = 81; }
|
||||
else if (weight <= 900) { iAxisFontWeight = 87; }
|
||||
}
|
||||
// if all else fails, it's left at -1
|
||||
|
||||
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
||||
tsConsoleStream << "CJpegHistoryGraph" << endl; // on console
|
||||
|
||||
// Connections -------------------------------------------------------------
|
||||
QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ),
|
||||
this, SLOT ( OnTimerDailyUpdate() ) );
|
||||
}
|
||||
|
||||
// Override Update to blank out the plot area each time
|
||||
void CJpegHistoryGraph::Update()
|
||||
{
|
||||
if ( bDoHistory )
|
||||
{
|
||||
// create JPEG image
|
||||
PlotPixmap.fill ( BackgroundColor ); // fill background
|
||||
|
||||
AHistoryGraph::Update();
|
||||
}
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::Save ( const QString sFileName )
|
||||
{
|
||||
// save plot as a file
|
||||
PlotPixmap.save ( sFileName, "JPG", 90 );
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height )
|
||||
{
|
||||
QPainter PlotPainter ( &PlotPixmap );
|
||||
PlotPainter.setPen ( FrameColor );
|
||||
PlotPainter.drawRect ( x, y, width, height );
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::text ( const unsigned int x, const unsigned int y, const QString& value )
|
||||
{
|
||||
QPainter PlotPainter ( &PlotPixmap );
|
||||
PlotPainter.setPen ( TextColor );
|
||||
// QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
|
||||
PlotPainter.setFont ( QFont( axisFontFamily, static_cast<int>(axisFontSize), iAxisFontWeight ) );
|
||||
PlotPainter.drawText ( QPoint ( x, y ), value );
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth )
|
||||
{
|
||||
QPainter PlotPainter ( &PlotPixmap );
|
||||
PlotPainter.setPen ( QPen ( QBrush ( QColor ( GridColor ) ), strokeWidth ) );
|
||||
PlotPainter.drawLine ( x1, y1, x2, y2 );
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour )
|
||||
{
|
||||
QPainter PlotPainter ( &PlotPixmap );
|
||||
PlotPainter.setPen ( QPen ( QBrush( QColor ( colour ) ), size ) );
|
||||
PlotPainter.drawPoint ( x, y );
|
||||
}
|
||||
|
||||
/* SVG History Graph implementation *******************************************/
|
||||
CSvgHistoryGraph::CSvgHistoryGraph() :
|
||||
AHistoryGraph(),
|
||||
svgImage( "" ),
|
||||
svgStreamWriter( &svgImage )
|
||||
{
|
||||
// set SVG veiwBox to correct size to ensure correct scaling
|
||||
svgRootAttributes.append("viewBox",
|
||||
QString("%1, %2, %3, %4")
|
||||
.arg(canvasRectX)
|
||||
.arg(canvasRectY)
|
||||
.arg(canvasRectWidth)
|
||||
.arg(canvasRectHeight)
|
||||
);
|
||||
|
||||
svgRootAttributes.append("xmlns", "http://www.w3.org/2000/svg");
|
||||
svgRootAttributes.append("xmlns:xlink", "http://www.w3.org/1999/xlink");
|
||||
|
||||
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
||||
tsConsoleStream << "CSvgHistoryGraph" << endl; // on console
|
||||
|
||||
// Connections -------------------------------------------------------------
|
||||
QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ),
|
||||
this, SLOT ( OnTimerDailyUpdate() ) );
|
||||
}
|
||||
|
||||
// Override Update to create the fresh SVG stream each time
|
||||
void CSvgHistoryGraph::Update()
|
||||
{
|
||||
if ( bDoHistory )
|
||||
{
|
||||
// create SVG document
|
||||
svgImage = "";
|
||||
|
||||
svgStreamWriter.setAutoFormatting(true);
|
||||
svgStreamWriter.writeStartDocument();
|
||||
svgStreamWriter.writeStartElement("svg");
|
||||
svgStreamWriter.writeAttributes(svgRootAttributes);
|
||||
|
||||
AHistoryGraph::Update();
|
||||
}
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::Save ( const QString sFileName )
|
||||
{
|
||||
svgStreamWriter.writeEndDocument();
|
||||
|
||||
QFile outf (sFileName);
|
||||
if (!outf.open(QFile::WriteOnly)) {
|
||||
throw std::runtime_error( (sFileName + " could not be written. Aborting.").toStdString() );
|
||||
}
|
||||
QTextStream out(&outf);
|
||||
|
||||
out << svgImage << endl;
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height )
|
||||
{
|
||||
svgStreamWriter.writeEmptyElement("rect");
|
||||
svgStreamWriter.writeAttribute("x", QString("%1").arg(x));
|
||||
svgStreamWriter.writeAttribute("y", QString("%1").arg(y));
|
||||
svgStreamWriter.writeAttribute("width", QString("%1").arg(width));
|
||||
svgStreamWriter.writeAttribute("height", QString("%1").arg(height));
|
||||
svgStreamWriter.writeAttribute("stroke", FrameColor);
|
||||
svgStreamWriter.writeAttribute("stroke-width", QString("1"));
|
||||
svgStreamWriter.writeAttribute("style", QString("fill: none;"));
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::text ( const unsigned int x, const unsigned int y, const QString& value )
|
||||
{
|
||||
svgStreamWriter.writeStartElement("text");
|
||||
svgStreamWriter.writeAttribute("x", QString("%1").arg(x));
|
||||
svgStreamWriter.writeAttribute("y", QString("%1").arg(y));
|
||||
svgStreamWriter.writeAttribute("stroke", TextColor);
|
||||
svgStreamWriter.writeAttribute("font-family", axisFontFamily);
|
||||
svgStreamWriter.writeAttribute("font-weight", axisFontWeight);
|
||||
svgStreamWriter.writeAttribute("font-size", QString("%1").arg(axisFontSize));
|
||||
|
||||
svgStreamWriter.writeCharacters( value );
|
||||
svgStreamWriter.writeEndElement();
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth )
|
||||
{
|
||||
svgStreamWriter.writeEmptyElement("line");
|
||||
svgStreamWriter.writeAttribute("x1", QString("%1").arg(x1));
|
||||
svgStreamWriter.writeAttribute("y1", QString("%1").arg(y1));
|
||||
svgStreamWriter.writeAttribute("x2", QString("%1").arg(x2));
|
||||
svgStreamWriter.writeAttribute("y2", QString("%1").arg(y2));
|
||||
svgStreamWriter.writeAttribute("stroke", GridColor);
|
||||
svgStreamWriter.writeAttribute("stroke-width", QString("%1").arg(strokeWidth));
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour )
|
||||
{
|
||||
svgStreamWriter.writeEmptyElement("rect");
|
||||
svgStreamWriter.writeAttribute("x", QString("%1").arg(x));
|
||||
svgStreamWriter.writeAttribute("y", QString("%1").arg(y));
|
||||
svgStreamWriter.writeAttribute("width", QString("%1").arg(size));
|
||||
svgStreamWriter.writeAttribute("height", QString("%1").arg(size));
|
||||
svgStreamWriter.writeAttribute("stroke-opacity", "0");
|
||||
svgStreamWriter.writeAttribute("fill", colour);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,28 @@
|
|||
/******************************************************************************\
|
||||
* Copyright (c) 2004-2019
|
||||
*
|
||||
* 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.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
\******************************************************************************/
|
||||
|
||||
#ifndef HISTORYGRAPH_H
|
||||
#define HISTORYGRAPH_H
|
||||
|
||||
|
@ -9,11 +34,19 @@
|
|||
#include "global.h"
|
||||
#include "util.h"
|
||||
|
||||
// for CJpegHistoryGraph
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
|
||||
// for CSvgHistoryGraph
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QXmlStreamAttributes>
|
||||
|
||||
/* Definitions ****************************************************************/
|
||||
// number of history items to store
|
||||
#define NUM_ITEMS_HISTORY 600
|
||||
|
||||
/* Interface ********************************************************************/
|
||||
/* Interface ******************************************************************/
|
||||
class AHistoryGraph
|
||||
{
|
||||
public:
|
||||
|
@ -97,4 +130,54 @@ protected:
|
|||
QTimer TimerDailyUpdate;
|
||||
};
|
||||
|
||||
/* Implementations ************************************************************/
|
||||
class CJpegHistoryGraph : public QObject, virtual public AHistoryGraph
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CJpegHistoryGraph();
|
||||
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(); }
|
||||
};
|
||||
|
||||
class CSvgHistoryGraph : public QObject, virtual public AHistoryGraph
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CSvgHistoryGraph();
|
||||
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(); }
|
||||
};
|
||||
|
||||
#endif // HISTORYGRAPH_H
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
#include "jpeghistorygraph.h"
|
||||
|
||||
CJpegHistoryGraph::CJpegHistoryGraph() :
|
||||
AHistoryGraph(),
|
||||
PlotPixmap ( 1, 1, QImage::Format_RGB32 ),
|
||||
iAxisFontWeight ( -1 )
|
||||
{
|
||||
// scale pixmap to correct size
|
||||
PlotPixmap = PlotPixmap.scaled ( canvasRectWidth, canvasRectHeight );
|
||||
|
||||
// axisFontWeight is a string matching the CSS2 font-weight definition
|
||||
// Thin = 0, // 100
|
||||
// ExtraLight = 12, // 200
|
||||
// Light = 25, // 300
|
||||
// Normal = 50, // 400
|
||||
// Medium = 57, // 500
|
||||
// DemiBold = 63, // 600
|
||||
// Bold = 75, // 700
|
||||
// ExtraBold = 81, // 800
|
||||
// Black = 87 // 900
|
||||
bool ok;
|
||||
int weight = axisFontWeight.toInt( &ok );
|
||||
if (!ok)
|
||||
{
|
||||
if (!QString("normal").compare(axisFontWeight, Qt::CaseSensitivity::CaseInsensitive)) { iAxisFontWeight = 50; }
|
||||
else if (!QString("bold").compare(axisFontWeight, Qt::CaseSensitivity::CaseInsensitive)) { weight = 75; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weight <= 100) { iAxisFontWeight = 0; }
|
||||
else if (weight <= 200) { iAxisFontWeight = 12; }
|
||||
else if (weight <= 300) { iAxisFontWeight = 25; }
|
||||
else if (weight <= 400) { iAxisFontWeight = 50; }
|
||||
else if (weight <= 500) { iAxisFontWeight = 57; }
|
||||
else if (weight <= 600) { iAxisFontWeight = 63; }
|
||||
else if (weight <= 700) { iAxisFontWeight = 75; }
|
||||
else if (weight <= 800) { iAxisFontWeight = 81; }
|
||||
else if (weight <= 900) { iAxisFontWeight = 87; }
|
||||
}
|
||||
// if all else fails, it's left at -1
|
||||
|
||||
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
||||
tsConsoleStream << "CJpegHistoryGraph" << endl; // on console
|
||||
|
||||
// Connections -------------------------------------------------------------
|
||||
QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ),
|
||||
this, SLOT ( OnTimerDailyUpdate() ) );
|
||||
}
|
||||
|
||||
// Override Update to create the fresh SVG stream each time
|
||||
void CJpegHistoryGraph::Update()
|
||||
{
|
||||
if ( bDoHistory )
|
||||
{
|
||||
// create JPEG image
|
||||
PlotPixmap.fill ( BackgroundColor ); // fill background
|
||||
|
||||
AHistoryGraph::Update();
|
||||
}
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::Save ( const QString sFileName )
|
||||
{
|
||||
// save plot as a file
|
||||
PlotPixmap.save ( sFileName, "JPG", 90 );
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height )
|
||||
{
|
||||
QPainter PlotPainter ( &PlotPixmap );
|
||||
PlotPainter.setPen ( FrameColor );
|
||||
PlotPainter.drawRect ( x, y, width, height );
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::text ( const unsigned int x, const unsigned int y, const QString& value )
|
||||
{
|
||||
QPainter PlotPainter ( &PlotPixmap );
|
||||
PlotPainter.setPen ( TextColor );
|
||||
// QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
|
||||
PlotPainter.setFont ( QFont( axisFontFamily, static_cast<int>(axisFontSize), iAxisFontWeight ) );
|
||||
PlotPainter.drawText ( QPoint ( x, y ), value );
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth )
|
||||
{
|
||||
QPainter PlotPainter ( &PlotPixmap );
|
||||
PlotPainter.setPen ( QPen ( QBrush ( QColor ( GridColor ) ), strokeWidth ) );
|
||||
PlotPainter.drawLine ( x1, y1, x2, y2 );
|
||||
}
|
||||
|
||||
void CJpegHistoryGraph::point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour )
|
||||
{
|
||||
QPainter PlotPainter ( &PlotPixmap );
|
||||
PlotPainter.setPen ( QPen ( QBrush( QColor ( colour ) ), size ) );
|
||||
PlotPainter.drawPoint ( x, y );
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef JPEGHISTORYGRAPH_H
|
||||
#define JPEGHISTORYGRAPH_H
|
||||
|
||||
#include "historygraph.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
|
||||
/* Classes ********************************************************************/
|
||||
class CJpegHistoryGraph : public QObject, virtual public AHistoryGraph
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CJpegHistoryGraph();
|
||||
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 // JPEGHISTORYGRAPH_H
|
|
@ -33,8 +33,7 @@
|
|||
#include "global.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "jpeghistorygraph.h"
|
||||
#include "svghistorygraph.h"
|
||||
#include "historygraph.h"
|
||||
|
||||
/* Classes ********************************************************************/
|
||||
class CServerLogging
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
#include "svghistorygraph.h"
|
||||
|
||||
CSvgHistoryGraph::CSvgHistoryGraph() :
|
||||
AHistoryGraph(),
|
||||
svgImage( "" ),
|
||||
svgStreamWriter( &svgImage )
|
||||
{
|
||||
// set SVG veiwBox to correct size to ensure correct scaling
|
||||
svgRootAttributes.append("viewBox",
|
||||
QString("%1, %2, %3, %4")
|
||||
.arg(canvasRectX)
|
||||
.arg(canvasRectY)
|
||||
.arg(canvasRectWidth)
|
||||
.arg(canvasRectHeight)
|
||||
);
|
||||
|
||||
svgRootAttributes.append("xmlns", "http://www.w3.org/2000/svg");
|
||||
svgRootAttributes.append("xmlns:xlink", "http://www.w3.org/1999/xlink");
|
||||
|
||||
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
||||
tsConsoleStream << "CSvgHistoryGraph" << endl; // on console
|
||||
|
||||
// Connections -------------------------------------------------------------
|
||||
QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ),
|
||||
this, SLOT ( OnTimerDailyUpdate() ) );
|
||||
}
|
||||
|
||||
// Override Update to create the fresh SVG stream each time
|
||||
void CSvgHistoryGraph::Update()
|
||||
{
|
||||
if ( bDoHistory )
|
||||
{
|
||||
// create SVG document
|
||||
svgImage = "";
|
||||
|
||||
svgStreamWriter.setAutoFormatting(true);
|
||||
svgStreamWriter.writeStartDocument();
|
||||
svgStreamWriter.writeStartElement("svg");
|
||||
svgStreamWriter.writeAttributes(svgRootAttributes);
|
||||
|
||||
AHistoryGraph::Update();
|
||||
}
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::Save ( const QString sFileName )
|
||||
{
|
||||
svgStreamWriter.writeEndDocument();
|
||||
|
||||
QFile outf (sFileName);
|
||||
if (!outf.open(QFile::WriteOnly)) {
|
||||
throw std::runtime_error( (sFileName + " could not be written. Aborting.").toStdString() );
|
||||
}
|
||||
QTextStream out(&outf);
|
||||
|
||||
out << svgImage << endl;
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height )
|
||||
{
|
||||
svgStreamWriter.writeEmptyElement("rect");
|
||||
svgStreamWriter.writeAttribute("x", QString("%1").arg(x));
|
||||
svgStreamWriter.writeAttribute("y", QString("%1").arg(y));
|
||||
svgStreamWriter.writeAttribute("width", QString("%1").arg(width));
|
||||
svgStreamWriter.writeAttribute("height", QString("%1").arg(height));
|
||||
svgStreamWriter.writeAttribute("stroke", FrameColor);
|
||||
svgStreamWriter.writeAttribute("stroke-width", QString("1"));
|
||||
svgStreamWriter.writeAttribute("style", QString("fill: none;"));
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::text ( const unsigned int x, const unsigned int y, const QString& value )
|
||||
{
|
||||
svgStreamWriter.writeStartElement("text");
|
||||
svgStreamWriter.writeAttribute("x", QString("%1").arg(x));
|
||||
svgStreamWriter.writeAttribute("y", QString("%1").arg(y));
|
||||
svgStreamWriter.writeAttribute("stroke", TextColor);
|
||||
svgStreamWriter.writeAttribute("font-family", axisFontFamily);
|
||||
svgStreamWriter.writeAttribute("font-weight", axisFontWeight);
|
||||
svgStreamWriter.writeAttribute("font-size", QString("%1").arg(axisFontSize));
|
||||
|
||||
svgStreamWriter.writeCharacters( value );
|
||||
svgStreamWriter.writeEndElement();
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth )
|
||||
{
|
||||
svgStreamWriter.writeEmptyElement("line");
|
||||
svgStreamWriter.writeAttribute("x1", QString("%1").arg(x1));
|
||||
svgStreamWriter.writeAttribute("y1", QString("%1").arg(y1));
|
||||
svgStreamWriter.writeAttribute("x2", QString("%1").arg(x2));
|
||||
svgStreamWriter.writeAttribute("y2", QString("%1").arg(y2));
|
||||
svgStreamWriter.writeAttribute("stroke", GridColor);
|
||||
svgStreamWriter.writeAttribute("stroke-width", QString("%1").arg(strokeWidth));
|
||||
}
|
||||
|
||||
void CSvgHistoryGraph::point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour )
|
||||
{
|
||||
svgStreamWriter.writeEmptyElement("rect");
|
||||
svgStreamWriter.writeAttribute("x", QString("%1").arg(x));
|
||||
svgStreamWriter.writeAttribute("y", QString("%1").arg(y));
|
||||
svgStreamWriter.writeAttribute("width", QString("%1").arg(size));
|
||||
svgStreamWriter.writeAttribute("height", QString("%1").arg(size));
|
||||
svgStreamWriter.writeAttribute("stroke-opacity", "0");
|
||||
svgStreamWriter.writeAttribute("fill", colour);
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
#ifndef SVGHISTORYGRAPH_H
|
||||
#define SVGHISTORYGRAPH_H
|
||||
|
||||
#include "historygraph.h"
|
||||
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QXmlStreamAttributes>
|
||||
|
||||
/* Definitions ****************************************************************/
|
||||
// number of history items to store
|
||||
#ifndef NUM_ITEMS_HISTORY
|
||||
#define NUM_ITEMS_HISTORY 600
|
||||
#endif
|
||||
|
||||
/* Classes ********************************************************************/
|
||||
class CSvgHistoryGraph : public QObject, virtual public AHistoryGraph
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CSvgHistoryGraph();
|
||||
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(); }
|
||||
};
|
||||
|
||||
#endif // SVGHISTORYGRAPH_H
|
Loading…
Reference in a new issue