diff --git a/SavvyCAN.pro.user b/SavvyCAN.pro.user index b97025f..b32a501 100644 --- a/SavvyCAN.pro.user +++ b/SavvyCAN.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/graphingwindow.cpp b/graphingwindow.cpp index aada43d..3d7fdd1 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -26,8 +26,11 @@ GraphingWindow::GraphingWindow(QList *frames, QWidget *parent) : ui->graphingView->legend->setVisible(true); QFont legendFont = font(); legendFont.setPointSize(10); + QFont legendSelectedFont = font(); + legendSelectedFont.setPointSize(12); + legendSelectedFont.setBold(true); ui->graphingView->legend->setFont(legendFont); - ui->graphingView->legend->setSelectedFont(legendFont); + ui->graphingView->legend->setSelectedFont(legendSelectedFont); ui->graphingView->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items // connect slot that ties some axis selections together (especially opposite axes): @@ -48,8 +51,8 @@ GraphingWindow::GraphingWindow(QList *frames, QWidget *parent) : ui->graphingView->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->graphingView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint))); - - + selectedPen.setWidth(1); + selectedPen.setColor(Qt::blue); } GraphingWindow::~GraphingWindow() @@ -176,14 +179,48 @@ void GraphingWindow::removeSelectedGraph() { 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()) + { + idx = i; + break; + } + } + graphParams.removeAt(idx); + ui->graphingView->removeGraph(ui->graphingView->selectedGraphs().first()); ui->graphingView->replot(); } } +void GraphingWindow::editSelectedGraph() +{ + 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()) + { + idx = i; + break; + } + } + + qDebug() << "Selected index for editing: " << idx; + + showParamsDialog(idx); + + //ui->graphingView->replot(); + } +} + void GraphingWindow::removeAllGraphs() { ui->graphingView->clearGraphs(); + graphParams.clear(); ui->graphingView->replot(); } @@ -194,139 +231,163 @@ void GraphingWindow::contextMenuRequest(QPoint pos) if (ui->graphingView->legend->selectTest(pos, false) >= 0) // context menu on legend requested { - menu->addAction("Move to top left", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignLeft)); - menu->addAction("Move to top center", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignHCenter)); - menu->addAction("Move to top right", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignRight)); - menu->addAction("Move to bottom right", this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignRight)); - menu->addAction("Move to bottom left", this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignLeft)); + menu->addAction(tr("Move to top left"), this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignLeft)); + menu->addAction(tr("Move to top center"), this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignHCenter)); + menu->addAction(tr("Move to top right"), this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignRight)); + menu->addAction(tr("Move to bottom right"), this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignRight)); + menu->addAction(tr("Move to bottom left"), this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignLeft)); } else // general context menu on graphs requested { - menu->addAction("Add new graph", this, SLOT(addNewGraph())); + menu->addAction(tr("Add new graph"), this, SLOT(addNewGraph())); if (ui->graphingView->selectedGraphs().size() > 0) - menu->addAction("Remove selected graph", this, SLOT(removeSelectedGraph())); + { + menu->addAction(tr("Edit selected graph"), this, SLOT(editSelectedGraph())); + menu->addAction(tr("Remove selected graph"), this, SLOT(removeSelectedGraph())); + } if (ui->graphingView->graphCount() > 0) - menu->addAction("Remove all graphs", this, SLOT(removeAllGraphs())); + menu->addAction(tr("Remove all graphs"), this, SLOT(removeAllGraphs())); } menu->popup(ui->graphingView->mapToGlobal(pos)); } +void GraphingWindow::showParamsDialog(int idx = -1) +{ + NewGraphDialog *thisDialog = new NewGraphDialog(); + if (idx > -1) thisDialog->setParams(graphParams[idx]); + if (thisDialog->exec() == QDialog::Accepted) + { + if (idx > -1) //if there was an existing graph then delete it + { + graphParams.removeAt(idx); + ui->graphingView->removeGraph(idx); + } + //create a new graph with the returned parameters. + GraphParams params; + thisDialog->getParams(params); + createGraph(params); + } + delete thisDialog; +} + void GraphingWindow::addNewGraph() +{ + showParamsDialog(-1); +} + +void GraphingWindow::createGraph(GraphParams ¶ms) { int tempVal; float minval=1000000, maxval = -100000; - NewGraphDialog *thisDialog = new NewGraphDialog(); - if (thisDialog->exec() == QDialog::Accepted) + + qDebug() << "New Graph ID: " << params.ID; + qDebug() << "Start byte: " << params.startByte; + qDebug() << "End Byte: " << params.endByte; + qDebug() << "Mask: " << params.mask; + + frameCache.clear(); + for (int i = 0; i < modelFrames->count(); i++) { - GraphParams params; - thisDialog->getParams(params); - qDebug() << "Returned ID: " << params.ID; - qDebug() << "Start byte: " << params.startByte; - qDebug() << "End Byte: " << params.endByte; - qDebug() << "Mask: " << params.mask; - - frameCache.clear(); - for (int i = 0; i < modelFrames->count(); i++) - { - CANFrame thisFrame = modelFrames->at(i); - if (thisFrame.ID == params.ID) frameCache.append(thisFrame); - } - - int numEntries = frameCache.count() / params.stride; - - QVector x(numEntries), y(numEntries); - - if (params.endByte == -1 || params.startByte == params.endByte) - { - for (int j = 0; j < numEntries; j++) - { - tempVal = (frameCache[j * params.stride].data[params.startByte] & params.mask); - if (params.isSigned && tempVal > 127) - { - tempVal = tempVal - 256; - } - x[j] = j; - y[j] = (tempVal + params.bias) * params.scale; - if (y[j] < minval) minval = y[j]; - if (y[j] > maxval) maxval = y[j]; - } - } - else if (params.endByte > params.startByte) //big endian - { - float tempValue; - int tempValInt; - int numBytes = (params.endByte - params.startByte) + 1; - int shiftRef = 1 << (numBytes * 8); - for (int j = 0; j < numEntries; j++) - { - tempValInt = 0; - int expon = 1; - for (int c = 0; c < numBytes; c++) - { - tempValInt += (frameCache[j * params.stride].data[params.endByte - c] * expon); - expon *= 256; - } - - tempValInt &= params.mask; - - if (params.isSigned && tempValInt > ((shiftRef / 2) - 1)) - { - tempValInt = tempValInt - shiftRef; - } - - tempValue = (float)tempValInt; - x[j] = j; - y[j] = (tempValue + params.bias) * params.scale; - if (y[j] < minval) minval = y[j]; - if (y[j] > maxval) maxval = y[j]; - } - } - else //little endian - { - float tempValue; - int tempValInt; - int numBytes = (params.startByte - params.endByte) + 1; - int shiftRef = 1 << (numBytes * 8); - for (int j = 0; j < numEntries; j++) - { - tempValInt = 0; - int expon = 1; - for (int c = 0; c < numBytes; c++) - { - tempValInt += frameCache[j * params.stride].data[params.endByte + c] * expon; - expon *= 256; - } - tempValInt &= params.mask; - - if (params.isSigned && tempValInt > ((shiftRef / 2) - 1)) - { - tempValInt = tempValInt - shiftRef; - } - - tempValue = (float)tempValInt; - x[j] = j; - y[j] = (tempValue + params.bias) * params.scale; - if (y[j] < minval) minval = y[j]; - if (y[j] > maxval) maxval = y[j]; - } - } - ui->graphingView->addGraph(); - ui->graphingView->graph()->setName(QString("Graph %1").arg(ui->graphingView->graphCount()-1)); - ui->graphingView->graph()->setData(x,y); - ui->graphingView->graph()->setLineStyle(QCPGraph::lsLine); //connect points with lines - QPen graphPen; - graphPen.setColor(params.color); - graphPen.setWidth(1); - ui->graphingView->graph()->setPen(graphPen); - - ui->graphingView->xAxis->setRange(0, numEntries); - ui->graphingView->yAxis->setRange(minval, maxval); - ui->graphingView->axisRect()->setupFullAxesBox(); - - - ui->graphingView->replot(); + CANFrame thisFrame = modelFrames->at(i); + if (thisFrame.ID == params.ID) frameCache.append(thisFrame); } - delete thisDialog; + + int numEntries = frameCache.count() / params.stride; + + QVector x(numEntries), y(numEntries); + + if (params.endByte == -1 || params.startByte == params.endByte) + { + for (int j = 0; j < numEntries; j++) + { + tempVal = (frameCache[j * params.stride].data[params.startByte] & params.mask); + if (params.isSigned && tempVal > 127) + { + tempVal = tempVal - 256; + } + x[j] = j; + y[j] = (tempVal + params.bias) * params.scale; + if (y[j] < minval) minval = y[j]; + if (y[j] > maxval) maxval = y[j]; + } + } + else if (params.endByte > params.startByte) //big endian + { + float tempValue; + int tempValInt; + int numBytes = (params.endByte - params.startByte) + 1; + int shiftRef = 1 << (numBytes * 8); + for (int j = 0; j < numEntries; j++) + { + tempValInt = 0; + int expon = 1; + for (int c = 0; c < numBytes; c++) + { + tempValInt += (frameCache[j * params.stride].data[params.endByte - c] * expon); + expon *= 256; + } + + tempValInt &= params.mask; + + if (params.isSigned && tempValInt > ((shiftRef / 2) - 1)) + { + tempValInt = tempValInt - shiftRef; + } + + tempValue = (float)tempValInt; + x[j] = j; + y[j] = (tempValue + params.bias) * params.scale; + if (y[j] < minval) minval = y[j]; + if (y[j] > maxval) maxval = y[j]; + } + } + else //little endian + { + float tempValue; + int tempValInt; + int numBytes = (params.startByte - params.endByte) + 1; + int shiftRef = 1 << (numBytes * 8); + for (int j = 0; j < numEntries; j++) + { + tempValInt = 0; + int expon = 1; + for (int c = 0; c < numBytes; c++) + { + tempValInt += frameCache[j * params.stride].data[params.endByte + c] * expon; + expon *= 256; + } + tempValInt &= params.mask; + + if (params.isSigned && tempValInt > ((shiftRef / 2) - 1)) + { + tempValInt = tempValInt - shiftRef; + } + + tempValue = (float)tempValInt; + x[j] = j; + y[j] = (tempValue + params.bias) * params.scale; + if (y[j] < minval) minval = y[j]; + if (y[j] > maxval) maxval = y[j]; + } + } + ui->graphingView->addGraph(); + params.ref = ui->graphingView->graph(); + graphParams.append(params); + ui->graphingView->graph()->setSelectedBrush(Qt::NoBrush); + ui->graphingView->graph()->setSelectedPen(selectedPen); + ui->graphingView->graph()->setName(QString("Graph %1").arg(ui->graphingView->graphCount()-1)); + ui->graphingView->graph()->setData(x,y); + ui->graphingView->graph()->setLineStyle(QCPGraph::lsLine); //connect points with lines + QPen graphPen; + graphPen.setColor(params.color); + graphPen.setWidth(1); + ui->graphingView->graph()->setPen(graphPen); + + ui->graphingView->xAxis->setRange(0, numEntries); + ui->graphingView->yAxis->setRange(minval, maxval); + ui->graphingView->axisRect()->setupFullAxesBox(); + + ui->graphingView->replot(); } void GraphingWindow::moveLegend() diff --git a/graphingwindow.h b/graphingwindow.h index a158167..afe8e65 100644 --- a/graphingwindow.h +++ b/graphingwindow.h @@ -10,6 +10,20 @@ namespace Ui { class GraphingWindow; } +class GraphParams +{ +public: + int32_t ID; + int startByte, endByte; + bool isSigned; + int32_t mask; + float bias; + float scale; + int stride; + QColor color; + QCPGraph *ref; +}; + class GraphingWindow : public QDialog { Q_OBJECT @@ -30,24 +44,17 @@ private slots: void contextMenuRequest(QPoint pos); void moveLegend(); void addNewGraph(); + void createGraph(GraphParams ¶ms); + void editSelectedGraph(); private: Ui::GraphingWindow *ui; QList frameCache; QList *modelFrames; -}; + QList graphParams; + QPen selectedPen; -class GraphParams -{ -public: - int32_t ID; - int startByte, endByte; - bool isSigned; - int32_t mask; - float bias; - float scale; - int stride; - QColor color; + void showParamsDialog(int idx); }; #endif // GRAPHINGWINDOW_H diff --git a/newgraphdialog.cpp b/newgraphdialog.cpp index 1e4d689..82f1ad8 100644 --- a/newgraphdialog.cpp +++ b/newgraphdialog.cpp @@ -42,6 +42,29 @@ void NewGraphDialog::colorSwatchClick() } +void NewGraphDialog::setParams(GraphParams ¶ms) +{ + ui->txtID->setText("0x" + QString::number(params.ID, 16).toUpper()); + ui->txtBias->setText(QString::number(params.bias)); + ui->txtMask->setText("0x" + QString::number(params.mask, 16).toUpper()); + ui->txtScale->setText(QString::number(params.scale)); + ui->txtStride->setText(QString::number(params.stride)); + ui->cbSigned->setChecked(params.isSigned); + + if (params.endByte > -1) + { + ui->txtData->setText(QString::number(params.startByte) + "-" + QString::number(params.endByte)); + } + else + { + ui->txtData->setText(QString::number(params.startByte)); + } + + QPalette p = ui->colorSwatch->palette(); + p.setColor(QPalette::Button, params.color); + ui->colorSwatch->setPalette(p); +} + void NewGraphDialog::getParams(GraphParams ¶ms) { params.ID = Utility::ParseStringToNum(ui->txtID->text()); diff --git a/newgraphdialog.h b/newgraphdialog.h index 6559d01..54c88a2 100644 --- a/newgraphdialog.h +++ b/newgraphdialog.h @@ -16,6 +16,7 @@ public: explicit NewGraphDialog(QWidget *parent = 0); ~NewGraphDialog(); void getParams(GraphParams &); + void setParams(GraphParams &); private slots: void addButtonClicked(); diff --git a/newgraphdialog.ui b/newgraphdialog.ui index 1eec111..0fb3e37 100644 --- a/newgraphdialog.ui +++ b/newgraphdialog.ui @@ -11,7 +11,7 @@ - Dialog + Graph Settings