added freq/time annotations to the image
This commit is contained in:
parent
3962bdc9fe
commit
9668f8e683
@ -2,6 +2,7 @@
|
||||
#include <qpainter.h>
|
||||
#include <QPaintEvent>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
|
||||
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;i<nbOfDiv;i++){
|
||||
unsigned long freq=(binSteps*i*freqStep)+minFreq;
|
||||
unsigned long x=binSteps*i;
|
||||
painter->drawLine(x,0,x,10);
|
||||
painter->drawText(QPoint(x+3,10),QString("%1 Hz").arg(freq));
|
||||
}
|
||||
for(int i=100;i<image.height();i+=100){
|
||||
unsigned long time=(endDate->toMSecsSinceEpoch()-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;
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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__;
|
||||
|
Loading…
x
Reference in New Issue
Block a user