FIX: 'data plot window' - keypress G in an empty plot crashed the client. Missing parenthis.

This commit is contained in:
iceman1001 2018-02-28 21:53:42 +01:00
parent 802994d30a
commit 5de4d9d3a6

View file

@ -240,8 +240,8 @@ int Plot::xCoordOf(int i, QRect r ) {
} }
int Plot::yCoordOf(int v, QRect r, int maxVal) { int Plot::yCoordOf(int v, QRect r, int maxVal) {
int z = (r.bottom() - r.top())/2; int z = (r.bottom() - r.top())/2;
return -(z * v) / maxVal + z; return -(z * v) / (maxVal + z);
} }
int Plot::valueOf_yCoord(int y, QRect r, int maxVal) { int Plot::valueOf_yCoord(int y, QRect r, int maxVal) {
@ -268,26 +268,26 @@ void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect)
{ {
if (len == 0) return; if (len == 0) return;
startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint)); startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
if(startMax < 0) { if (startMax < 0) {
startMax = 0; startMax = 0;
} }
if(GraphStart > startMax) { if (GraphStart > startMax) {
GraphStart = startMax; GraphStart = startMax;
} }
if (GraphStart > len) return; if (GraphStart > len) return;
int vMin = INT_MAX, vMax = INT_MIN, v = 0; int vMin = INT_MAX, vMax = INT_MIN, v = 0;
int sample_index = GraphStart ; int sample_index = GraphStart ;
for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) { for ( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
v = buffer[sample_index]; v = buffer[sample_index];
if(v < vMin) vMin = v; if (v < vMin) vMin = v;
if(v > vMax) vMax = v; if (v > vMax) vMax = v;
} }
g_absVMax = 0; g_absVMax = 0;
if(fabs( (double) vMin) > g_absVMax) g_absVMax = (int)fabs( (double) vMin); if (fabs( (double) vMin) > g_absVMax) g_absVMax = (int)fabs( (double) vMin);
if(fabs( (double) vMax) > g_absVMax) g_absVMax = (int)fabs( (double) vMax); if (fabs( (double) vMax) > g_absVMax) g_absVMax = (int)fabs( (double) vMax);
g_absVMax = (int)(g_absVMax*1.25 + 1); g_absVMax = (int)(g_absVMax * 1.25 + 1);
} }
void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset) void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset)
@ -418,9 +418,11 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
//printf("Plot time %f\n", elapsed_secs); //printf("Plot time %f\n", elapsed_secs);
} }
void Plot::plotGridLines(QPainter* painter,QRect r) { void Plot::plotGridLines(QPainter* painter, QRect r) {
// set GridOffset // set GridOffset
if (PlotGridX <= 0) return; if (PlotGridX <= 0) return;
int offset = GridOffset; int offset = GridOffset;
if (GridLocked && PlotGridX) { if (GridLocked && PlotGridX) {
offset = GridOffset + PlotGridX - (GraphStart % PlotGridX); offset = GridOffset + PlotGridX - (GraphStart % PlotGridX);
@ -433,15 +435,19 @@ void Plot::plotGridLines(QPainter* painter,QRect r) {
int i; int i;
int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint); int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
int grid_delta_y = PlotGridY; int grid_delta_y = PlotGridY;
if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) { if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
for(i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) { for (i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom()); painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
} }
} }
if (PlotGridY > 0) { if (PlotGridY > 0) {
for(i = 0; yCoordOf(i,r,g_absVMax) > r.top(); i += grid_delta_y) { for (i = 0; yCoordOf(i, r, g_absVMax) > r.top(); i += grid_delta_y) {
painter->drawLine( r.left(), yCoordOf(i,r,g_absVMax), r.right(), yCoordOf(i,r,g_absVMax) ); // line above mid
painter->drawLine( r.left(), yCoordOf(i*-1,r,g_absVMax), r.right(), yCoordOf(i*-1,r,g_absVMax) ); painter->drawLine( r.left(), yCoordOf(i, r, g_absVMax), r.right(), yCoordOf(i, r, g_absVMax) );
// line below mid
painter->drawLine( r.left(), yCoordOf(-i, r, g_absVMax), r.right(), yCoordOf(-i, r, g_absVMax) );
} }
} }
} }
@ -566,7 +572,7 @@ void Plot::mouseMoveEvent(QMouseEvent *event)
x -= WIDTH_AXES; x -= WIDTH_AXES;
x = (int)(x / GraphPixelsPerPoint); x = (int)(x / GraphPixelsPerPoint);
x += GraphStart; x += GraphStart;
if((event->buttons() & Qt::LeftButton)) { if ((event->buttons() & Qt::LeftButton)) {
CursorAPos = x; CursorAPos = x;
} else if (event->buttons() & Qt::RightButton) { } else if (event->buttons() & Qt::RightButton) {
CursorBPos = x; CursorBPos = x;
@ -578,32 +584,33 @@ void Plot::keyPressEvent(QKeyEvent *event)
{ {
int offset; int offset;
if(event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
if (PlotGridX) if (PlotGridX)
offset= PageWidth - (PageWidth % PlotGridX); offset = PageWidth - (PageWidth % PlotGridX);
else else
offset= PageWidth; offset = PageWidth;
} else } else {
if(event->modifiers() & Qt::ControlModifier) if (event->modifiers() & Qt::ControlModifier)
offset= 1; offset = 1;
else else
offset= (int)(20 / GraphPixelsPerPoint); offset = (int)(20 / GraphPixelsPerPoint);
}
switch(event->key()) { switch(event->key()) {
case Qt::Key_Down: case Qt::Key_Down:
if(GraphPixelsPerPoint <= 50) { if (GraphPixelsPerPoint <= 50) {
GraphPixelsPerPoint *= 2; GraphPixelsPerPoint *= 2;
} }
break; break;
case Qt::Key_Up: case Qt::Key_Up:
if(GraphPixelsPerPoint >= 0.02) { if (GraphPixelsPerPoint >= 0.02) {
GraphPixelsPerPoint /= 2; GraphPixelsPerPoint /= 2;
} }
break; break;
case Qt::Key_Right: case Qt::Key_Right:
if(GraphPixelsPerPoint < 20) { if (GraphPixelsPerPoint < 20) {
GraphStart += offset; GraphStart += offset;
} else { } else {
GraphStart++; GraphStart++;
@ -611,42 +618,49 @@ void Plot::keyPressEvent(QKeyEvent *event)
break; break;
case Qt::Key_Left: case Qt::Key_Left:
if(GraphPixelsPerPoint < 20) { if (GraphPixelsPerPoint < 20) {
GraphStart -= offset; GraphStart -= offset;
} else { } else {
GraphStart--; GraphStart--;
} }
break; break;
case Qt::Key_G: case Qt::Key_G:
if(PlotGridX || PlotGridY) { if (PlotGridX || PlotGridY) {
PlotGridX= 0; PlotGridX = 0;
PlotGridY= 0; PlotGridY = 0;
} else { } else {
PlotGridX= PlotGridXdefault; if ( PlotGridXdefault < 0 )
PlotGridY= PlotGridYdefault; PlotGridXdefault = 64;
if ( PlotGridYdefault < 0 )
PlotGridYdefault = 0;
PlotGridX = PlotGridXdefault;
PlotGridY = PlotGridYdefault;
} }
break; break;
case Qt::Key_H: case Qt::Key_H:
puts("Plot Window Keystrokes:\n");
puts(" Key Action\n"); puts("\n-----------------------------------------------------------------------");
puts(" DOWN Zoom in"); puts("PLOT window keystrokes");
puts(" G Toggle grid display"); puts("\tKey Action");
puts(" H Show help"); puts("-----------------------------------------------------------------------");
puts(" L Toggle lock grid relative to samples"); puts("\tUP Zoom out");
puts(" LEFT Move left"); puts("\tDOWN Zoom in");
puts(" <CTL>LEFT Move left 1 sample"); puts("\tG Toggle grid display");
puts(" <SHIFT>LEFT Page left"); puts("\tH Show help");
puts(" LEFT-MOUSE-CLICK Set yellow cursor"); puts("\tL Toggle lock grid relative to samples");
puts(" Q Hide window"); puts("\tQ Hide window");
puts(" RIGHT Move right"); puts("\tLEFT Move left");
puts(" <CTL>RIGHT Move right 1 sample"); puts("\t<CTLR> LEFT Move left 1 sample");
puts(" <SHIFT>RIGHT Page right"); puts("\t<SHIFT> LEFT Page left");
puts(" RIGHT-MOUSE-CLICK Set purple cursor"); puts("\tLEFT MOUSE CLICK Set yellow cursor");
puts(" UP Zoom out"); puts("\tRIGHT Move right");
puts(""); puts("\t<CTLR> RIGHT Move right 1 sample");
puts("Use client window 'data help' for more plot commands\n"); puts("\t<SHIFT> RIGHT Page right");
puts("\tRIGHT MOUSE CLICK Set purple cursor");
puts("-----------------------------------------------------------------------");
break; break;
case Qt::Key_L: case Qt::Key_L: