From 793820d6f87d1fe44595ea91b16e4a811718798d Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 2 Aug 2015 20:22:38 -0400 Subject: [PATCH] Added ability to save the custom graph names you give to things. Also fixed up an issue with the signed value support in the graphs. Lastly, a small change to the random colors to ensure they ever get too bright. --- config.h | 2 +- graphingwindow.cpp | 39 ++++++++++++++++++++++++++++++++------- graphingwindow.h | 1 + newgraphdialog.cpp | 3 ++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/config.h b/config.h index b29837d..be09b01 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 127 +#define VERSION 128 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/graphingwindow.cpp b/graphingwindow.cpp index 479fff7..64dca96 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -168,6 +168,20 @@ void GraphingWindow::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem if (ok) { plItem->plottable()->setName(newName); + + if (ui->graphingView->selectedGraphs().size() > 0) + { + int idx = -1; + for (int i = 0; i < graphParams.count(); i++) + { + if (graphParams[i].ref == ui->graphingView->selectedGraphs().first()) + { + graphParams[i].graphName = newName; + break; + } + } + } + ui->graphingView->replot(); } } @@ -403,6 +417,8 @@ void GraphingWindow::saveDefinitions() outFile->write(QString::number(iter->color.green()).toUtf8()); outFile->putChar(','); outFile->write(QString::number(iter->color.blue()).toUtf8()); + outFile->putChar(','); + outFile->write(iter->graphName.toUtf8()); outFile->write("\n"); } outFile->close(); @@ -450,6 +466,10 @@ void GraphingWindow::loadDefinitions() gp.color.setRed(tokens[8].toInt()); gp.color.setGreen(tokens[9].toInt()); gp.color.setBlue(tokens[10].toInt()); + if (tokens.length() > 11) + gp.graphName = tokens[11]; + else + gp.graphName = QString(); createGraph(gp, true); } } @@ -553,8 +573,9 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) tempValInt &= params.mask; long long twocompPoint = params.mask; - if (shiftRef < twocompPoint) twocompPoint = shiftRef; - if (params.isSigned && tempValInt > ((twocompPoint / 2) - 1)) + if (shiftRef < twocompPoint || twocompPoint == -1) twocompPoint = shiftRef; + qDebug() << "two comp point: " << twocompPoint; + if (params.isSigned && tempValInt > ((twocompPoint / 2))) { tempValInt = tempValInt - twocompPoint; } @@ -601,8 +622,9 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) tempValInt &= params.mask; long long twocompPoint = params.mask; - if (shiftRef < twocompPoint) twocompPoint = shiftRef; - if (params.isSigned && tempValInt > ((twocompPoint / 2) - 1)) + if (shiftRef < twocompPoint || twocompPoint == -1) twocompPoint = shiftRef; + qDebug() << "two comp point: " << twocompPoint; + if (params.isSigned && tempValInt > ((twocompPoint / 2))) { tempValInt = tempValInt - twocompPoint; } @@ -639,9 +661,12 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) ui->graphingView->graph()->setSelectedBrush(Qt::NoBrush); ui->graphingView->graph()->setSelectedPen(selectedPen); - QString gName = "0x"+ QString::number(params.ID, 16) + ":" + QString::number(params.startByte); - if ((params.endByte != -1) && (params.endByte != params.startByte)) gName += "-" + QString::number(params.endByte); - ui->graphingView->graph()->setName(gName); + if (params.graphName == NULL || params.graphName.length() == 0) + { + params.graphName = QString("0x") + QString::number(params.ID, 16) + ":" + QString::number(params.startByte); + if ((params.endByte != -1) && (params.endByte != params.startByte)) params.graphName += "-" + QString::number(params.endByte); + } + ui->graphingView->graph()->setName(params.graphName); ui->graphingView->graph()->setData(x,y); ui->graphingView->graph()->setLineStyle(QCPGraph::lsLine); //connect points with lines diff --git a/graphingwindow.h b/graphingwindow.h index 888bba0..bb0ddfd 100644 --- a/graphingwindow.h +++ b/graphingwindow.h @@ -22,6 +22,7 @@ public: int stride; QColor color; QCPGraph *ref; + QString graphName; }; class GraphingWindow : public QDialog diff --git a/newgraphdialog.cpp b/newgraphdialog.cpp index b8c6c7c..f5c371d 100644 --- a/newgraphdialog.cpp +++ b/newgraphdialog.cpp @@ -17,7 +17,8 @@ NewGraphDialog::NewGraphDialog(QWidget *parent) : qsrand((uint)time.msec()); QPalette p = ui->colorSwatch->palette(); - p.setColor(QPalette::Button, QColor(qrand() % 255,qrand() % 255,qrand() % 255)); + //using 160 instead of 255 so that colors are always at least a little dark + p.setColor(QPalette::Button, QColor(qrand() % 160,qrand() % 160,qrand() % 160)); ui->colorSwatch->setPalette(p); }