From c6a43dbffa5dfcc7d06fbe2af16e7055a8743cdc Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 26 May 2019 18:42:46 +0100 Subject: [PATCH 1/5] Fix unsigned usage in signed contexts --- src/historygraph.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/historygraph.cpp b/src/historygraph.cpp index ae4c7031..c64131aa 100644 --- a/src/historygraph.cpp +++ b/src/historygraph.cpp @@ -168,7 +168,7 @@ void AHistoryGraph::DrawFrame ( const int iNewNumTicksX ) { int iBottomExtraTickLen = 0; const int iCurX = gridFrameX + static_cast ( dayXSpace * ( i + 1 ) ); - const QDate curXAxisDate = curDate.addDays ( i - iNumTicksX + 1 ); + const QDate curXAxisDate = curDate.addDays ( 0 - static_cast( iNumTicksX ) + i + 1 ); // text (print only every "iXAxisTickStep" tick) if ( !( i % iXAxisTickStep ) ) @@ -219,7 +219,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(iNumTicksX) - 1 ) ) + if ( -iXAxisOffs > ( static_cast( iNumTicksX ) - 1 ) ) { return; } @@ -229,7 +229,7 @@ void AHistoryGraph::AddMarker ( const SHistoryData& curHistoryData ) static_cast ( curHistoryData.DateTime.time().minute() ) / 60; // calculate the actual point in the graph (in pixels) - int curPointX = gridFrameX + static_cast ( dayXSpace * ( iNumTicksX + iXAxisOffs ) ); + int curPointX = gridFrameX + static_cast ( dayXSpace * ( static_cast( iNumTicksX ) + iXAxisOffs ) ); int curPointY = gridFrameY + static_cast ( static_cast ( gridFrameHeight ) / ( iYAxisEnd - iYAxisStart ) * dYAxisOffs ); QString curPointColour = MarkerNewColor; From 450fe4b530f6f3c9493e186c5abee924046d989d Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 26 May 2019 18:43:11 +0100 Subject: [PATCH 2/5] Fix alignment of markers to axes --- src/historygraph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/historygraph.cpp b/src/historygraph.cpp index c64131aa..557b25fc 100644 --- a/src/historygraph.cpp +++ b/src/historygraph.cpp @@ -252,5 +252,5 @@ void AHistoryGraph::AddMarker ( const SHistoryData& curHistoryData ) break; } - point( curPointX, curPointY, curPointSize, curPointColour ); + point( curPointX - curPointSize / 2, curPointY - curPointSize / 2, curPointSize, curPointColour ); } From ea022759b27e4adee81dfb65993631a3dfcd4084 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 26 May 2019 19:00:09 +0100 Subject: [PATCH 3/5] Reduce to single history graph header --- Jamulus.pro | 4 +-- src/historygraph.h | 60 +++++++++++++++++++++++++++++++++++++++- src/jpeghistorygraph.cpp | 2 +- src/jpeghistorygraph.h | 34 ----------------------- src/serverlogging.h | 3 +- src/svghistorygraph.cpp | 2 +- src/svghistorygraph.h | 41 --------------------------- 7 files changed, 63 insertions(+), 83 deletions(-) delete mode 100755 src/jpeghistorygraph.h delete mode 100755 src/svghistorygraph.h diff --git a/Jamulus.pro b/Jamulus.pro index 2165d5f5..5fa7de19 100755 --- a/Jamulus.pro +++ b/Jamulus.pro @@ -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 \ diff --git a/src/historygraph.h b/src/historygraph.h index 49f45568..198bcd4b 100644 --- a/src/historygraph.h +++ b/src/historygraph.h @@ -9,11 +9,19 @@ #include "global.h" #include "util.h" +// for CJpegHistoryGraph +#include +#include + +// for CSvgHistoryGraph +#include +#include + /* Definitions ****************************************************************/ // number of history items to store #define NUM_ITEMS_HISTORY 600 -/* Interface ********************************************************************/ +/* Interface ******************************************************************/ class AHistoryGraph { public: @@ -97,4 +105,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 diff --git a/src/jpeghistorygraph.cpp b/src/jpeghistorygraph.cpp index 41b1391f..14dc0d6f 100644 --- a/src/jpeghistorygraph.cpp +++ b/src/jpeghistorygraph.cpp @@ -1,4 +1,4 @@ -#include "jpeghistorygraph.h" +#include "historygraph.h" CJpegHistoryGraph::CJpegHistoryGraph() : AHistoryGraph(), diff --git a/src/jpeghistorygraph.h b/src/jpeghistorygraph.h deleted file mode 100755 index f4dd3c88..00000000 --- a/src/jpeghistorygraph.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef JPEGHISTORYGRAPH_H -#define JPEGHISTORYGRAPH_H - -#include "historygraph.h" - -#include -#include - -/* 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 diff --git a/src/serverlogging.h b/src/serverlogging.h index 649bbdd5..a8fb8386 100755 --- a/src/serverlogging.h +++ b/src/serverlogging.h @@ -33,8 +33,7 @@ #include "global.h" #include "util.h" -#include "jpeghistorygraph.h" -#include "svghistorygraph.h" +#include "historygraph.h" /* Classes ********************************************************************/ class CServerLogging diff --git a/src/svghistorygraph.cpp b/src/svghistorygraph.cpp index d5287320..fa364d2a 100755 --- a/src/svghistorygraph.cpp +++ b/src/svghistorygraph.cpp @@ -1,4 +1,4 @@ -#include "svghistorygraph.h" +#include "historygraph.h" CSvgHistoryGraph::CSvgHistoryGraph() : AHistoryGraph(), diff --git a/src/svghistorygraph.h b/src/svghistorygraph.h deleted file mode 100755 index 86ce4f83..00000000 --- a/src/svghistorygraph.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef SVGHISTORYGRAPH_H -#define SVGHISTORYGRAPH_H - -#include "historygraph.h" - -#include -#include - -/* 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 From 78897e09950839d519bdffefa678e5ba4e9b89e3 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 26 May 2019 19:16:45 +0100 Subject: [PATCH 4/5] Reduce to single history graph source --- Jamulus.pro | 4 +- src/historygraph.cpp | 201 +++++++++++++++++++++++++++++++++++++++ src/jpeghistorygraph.cpp | 96 ------------------- src/svghistorygraph.cpp | 104 -------------------- 4 files changed, 202 insertions(+), 203 deletions(-) delete mode 100644 src/jpeghistorygraph.cpp delete mode 100755 src/svghistorygraph.cpp diff --git a/Jamulus.pro b/Jamulus.pro index 5fa7de19..c082665f 100755 --- a/Jamulus.pro +++ b/Jamulus.pro @@ -272,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 \ diff --git a/src/historygraph.cpp b/src/historygraph.cpp index 557b25fc..4407c896 100644 --- a/src/historygraph.cpp +++ b/src/historygraph.cpp @@ -1,5 +1,6 @@ #include "historygraph.h" +/* Abstract class *************************************************************/ AHistoryGraph::AHistoryGraph() : sFileName ( "" ), bDoHistory ( false ), @@ -254,3 +255,203 @@ void AHistoryGraph::AddMarker ( const SHistoryData& curHistoryData ) 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(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); +} diff --git a/src/jpeghistorygraph.cpp b/src/jpeghistorygraph.cpp deleted file mode 100644 index 14dc0d6f..00000000 --- a/src/jpeghistorygraph.cpp +++ /dev/null @@ -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(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 ); -} diff --git a/src/svghistorygraph.cpp b/src/svghistorygraph.cpp deleted file mode 100755 index fa364d2a..00000000 --- a/src/svghistorygraph.cpp +++ /dev/null @@ -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); -} From 4dffa9615abb27ee510ea22e6590a7437f09d719 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 26 May 2019 19:23:13 +0100 Subject: [PATCH 5/5] Add (C) and GPL2 banners --- src/historygraph.cpp | 25 +++++++++++++++++++++++++ src/historygraph.h | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/historygraph.cpp b/src/historygraph.cpp index 4407c896..6bcf0a96 100644 --- a/src/historygraph.cpp +++ b/src/historygraph.cpp @@ -1,3 +1,28 @@ +/******************************************************************************\ + * Copyright (c) 2004-2019 + * + * Author(s): + * Volker Fischer + * Peter L Jones + * + ****************************************************************************** + * + * 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 *************************************************************/ diff --git a/src/historygraph.h b/src/historygraph.h index 198bcd4b..ccd43c9d 100644 --- a/src/historygraph.h +++ b/src/historygraph.h @@ -1,3 +1,28 @@ +/******************************************************************************\ + * Copyright (c) 2004-2019 + * + * Author(s): + * Volker Fischer + * Peter L Jones + * + ****************************************************************************** + * + * 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