From 9668f8e6836cb4ac68c6b44687c748ec9807e3a0 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 15 Jun 2021 21:09:35 +0200 Subject: [PATCH] added freq/time annotations to the image --- displayarea.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- displayarea.h | 10 ++++++++++ inputparser.cpp | 18 +++++++++++++++++- inputparser.h | 3 +++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/displayarea.cpp b/displayarea.cpp index de30208..69b68ba 100644 --- a/displayarea.cpp +++ b/displayarea.cpp @@ -2,6 +2,7 @@ #include #include #include +#include DisplayArea::DisplayArea(QWidget *parent) : QWidget(parent) { @@ -17,6 +18,7 @@ void DisplayArea::paintEvent(QPaintEvent *event) QPainter painter(this); QRect rect=event->rect(); painter.drawImage(rect,image,rect); + displayScale(&painter); } bool DisplayArea::pixelSet(int x, int y) @@ -49,7 +51,10 @@ void DisplayArea::updateDisp() bool DisplayArea::saveImage(const QString &fileName, const char *fileFormat) { - return image.save(fileName, fileFormat); + QImage output=QImage(image); + QPainter painter(&output); + displayScale(&painter); + return output.save(fileName, fileFormat); } void DisplayArea::updateColorMap(float oldMin, float oldMax, float newMin, float newMax,QImage palette) @@ -78,3 +83,37 @@ unsigned long DisplayArea::remap(unsigned long c, float omin, float omax, float float nVal=(255*(omin-nmin)+c*(omax-omin))/(nmax-nmin); return qRound(nVal); } + +void DisplayArea::displayScale(QPainter* painter) +{ + if(!freqStep) return; + + painter->setPen(qRgb(0,0,0)); + + int nbOfDiv=5; + unsigned long freqDiff=maxFreq-minFreq; + unsigned long binNb=freqDiff/freqStep; + unsigned long binSteps=binNb/nbOfDiv; + for(int i=0;idrawLine(x,0,x,10); + painter->drawText(QPoint(x+3,10),QString("%1 Hz").arg(freq)); + } + for(int i=100;itoMSecsSinceEpoch()-startDate->toMSecsSinceEpoch())*i/image.height()+startDate->toMSecsSinceEpoch(); + QDateTime date=QDateTime::fromMSecsSinceEpoch(time); + painter->drawLine(0,i,50,i); + painter->drawText(QPoint(3,i+15),QString(date.toString())); + } +} + +void DisplayArea::updateScale(unsigned long minFreq, unsigned long maxFreq, unsigned long freqStep, unsigned long timeStep,QDateTime* startDate,QDateTime* endDate) +{ + this->minFreq=minFreq; + this->maxFreq=maxFreq; + this->freqStep=freqStep; + this->timeStep=timeStep; + this->startDate=startDate; + this->endDate=endDate; +} diff --git a/displayarea.h b/displayarea.h index 3d51db9..ff9e640 100644 --- a/displayarea.h +++ b/displayarea.h @@ -12,6 +12,7 @@ public: bool saveImage(const QString &fileName, const char *fileFormat); void updateColorMap(float oldMin,float oldMax,float newMin,float newMax,QImage palette); bool pixelSet(int x,int y); + void updateScale(unsigned long minFreq, unsigned long maxFreq, unsigned long freqStep, unsigned long timeStep,QDateTime* startDate,QDateTime* endDate); protected: void paintEvent(QPaintEvent *event) override; @@ -22,6 +23,15 @@ private: unsigned long remap(unsigned long val,float omin,float omax,float nmin,float nmax); unsigned long findPaletteIndex(QRgb col,QRgb* palette,unsigned long size); + void displayScale(QPainter* painter); + + unsigned long minFreq=0; + unsigned long maxFreq=0; + unsigned long freqStep=0; + unsigned long timeStep=0; + QDateTime* startDate; + QDateTime* endDate; + QImage image; public slots: diff --git a/inputparser.cpp b/inputparser.cpp index c0fc0ce..9290810 100644 --- a/inputparser.cpp +++ b/inputparser.cpp @@ -47,6 +47,12 @@ void InputParser::process() switch(index){ case 1: computeEpochDate(); + if(nbOfLinesParsed==ignoreFirstNLines){ + startDate=currentLine.parsedDate; + endDate=currentLine.parsedDate; + } + startDate=qMin(currentLine.parsedDate,startDate); + endDate=qMax(currentLine.parsedDate,endDate); break; case 3: if(currentLine.maxFreq==maxFreq) currentY++; @@ -56,6 +62,7 @@ void InputParser::process() break; case 4: if(decimal) currentLine.freqStep++; + freqStep=currentLine.freqStep; break; default: if(index>5){ @@ -69,6 +76,8 @@ void InputParser::process() case '\n': sendPixel(); + display->updateScale(minFreq,maxFreq,freqStep,10,&startDate,&endDate); + lastMaxFreq=currentLine.maxFreq; index=0; @@ -81,6 +90,14 @@ void InputParser::process() break; case '-': sign=-1; + switch(index){ + case 0: + addToString(c,¤tLine.firstDate); + break; + case 1: + addToString(c,¤tLine.secondDate); + break; + } break; default: switch(index){ @@ -106,7 +123,6 @@ void InputParser::process() break; } } - //printf("%c aaa"); } void InputParser::addToString(char c, QString* str) diff --git a/inputparser.h b/inputparser.h index cf42b1d..845fa53 100644 --- a/inputparser.h +++ b/inputparser.h @@ -30,6 +30,9 @@ public: private: unsigned long minFreq=-1; unsigned long maxFreq=0; + unsigned long freqStep=0; + QDateTime startDate; + QDateTime endDate; float minPow=__FLT_MAX__; float maxPow=-__FLT_MAX__;