Reduce to single history graph source

This commit is contained in:
Peter L Jones 2019-05-26 19:16:45 +01:00
parent ea022759b2
commit 78897e0995
4 changed files with 202 additions and 203 deletions

View file

@ -272,9 +272,7 @@ SOURCES += src/audiomixerboard.cpp \
src/recorder/jamrecorder.cpp \ src/recorder/jamrecorder.cpp \
src/recorder/creaperproject.cpp \ src/recorder/creaperproject.cpp \
src/recorder/cwavestream.cpp \ src/recorder/cwavestream.cpp \
src/historygraph.cpp \ src/historygraph.cpp
src/jpeghistorygraph.cpp \
src/svghistorygraph.cpp
SOURCES_OPUS = libs/opus/src/opus.c \ SOURCES_OPUS = libs/opus/src/opus.c \
libs/opus/src/opus_decoder.c \ libs/opus/src/opus_decoder.c \

View file

@ -1,5 +1,6 @@
#include "historygraph.h" #include "historygraph.h"
/* Abstract class *************************************************************/
AHistoryGraph::AHistoryGraph() : AHistoryGraph::AHistoryGraph() :
sFileName ( "" ), sFileName ( "" ),
bDoHistory ( false ), bDoHistory ( false ),
@ -254,3 +255,203 @@ void AHistoryGraph::AddMarker ( const SHistoryData& curHistoryData )
point( curPointX - curPointSize / 2, curPointY - curPointSize / 2, 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);
}

View file

@ -1,96 +0,0 @@
#include "historygraph.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 );
}

View file

@ -1,104 +0,0 @@
#include "historygraph.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);
}