From f16660ba5209938427cf097e5a8af2d693591a32 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Mon, 11 Mar 2019 21:42:19 -0400 Subject: [PATCH] Add ability to clone DBC signals. F2 will also do this from the keyboard (very handy!) --- connections/canconmanager.cpp | 1 + dbc/dbcsignaleditor.cpp | 45 ++++++++++++++++++++++++++++++++++- dbc/dbcsignaleditor.h | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/connections/canconmanager.cpp b/connections/canconmanager.cpp index 20e0b3f..014248f 100644 --- a/connections/canconmanager.cpp +++ b/connections/canconmanager.cpp @@ -94,6 +94,7 @@ void CANConManager::refreshCanList() if (mConns.count() == 0) { + //TODO: Seems to crash under heavy load. Find out why. if(buslessFrames.size()) { tempFrames.clear(); tempFrames.append(buslessFrames); //make a copy and pass that copy diff --git a/dbc/dbcsignaleditor.cpp b/dbc/dbcsignaleditor.cpp index 5e47d0a..d86353d 100644 --- a/dbc/dbcsignaleditor.cpp +++ b/dbc/dbcsignaleditor.cpp @@ -232,6 +232,9 @@ bool DBCSignalEditor::eventFilter(QObject *obj, QEvent *event) case Qt::Key_F1: HelpWindow::getRef()->showHelp("signaleditor.html"); break; + case Qt::Key_F2: + cloneSignal(); + break; } return true; } else { @@ -324,7 +327,11 @@ void DBCSignalEditor::onCustomMenuSignals(QPoint point) menu->setAttribute(Qt::WA_DeleteOnClose); menu->addAction(tr("Add a new signal"), this, SLOT(addNewSignal())); - menu->addAction(tr("Delete currently selected signal"), this, SLOT(deleteCurrentSignal())); + if (ui->signalsList->currentRow() != -1) + { + menu->addAction(tr("Clone currently selected signal"), this, SLOT(cloneSignal())); + menu->addAction(tr("Delete currently selected signal"), this, SLOT(deleteCurrentSignal())); + } menu->popup(ui->signalsList->mapToGlobal(point)); } @@ -365,7 +372,43 @@ void DBCSignalEditor::addNewSignal() /* this will call clickSignalList */ ui->signalsList->addItem(newName); ui->signalsList->setCurrentRow(ui->signalsList->count()-1); +} +void DBCSignalEditor::cloneSignal() +{ + int num = qrand() % 100; + + int idx = ui->signalsList->currentRow(); + if (idx < 0) return; + + DBC_SIGNAL *oldSig = dbcMessage->sigHandler->findSignalByIdx(idx); + if (!oldSig) return; + + QString newName = oldSig->name + QString::number(num); + DBC_SIGNAL newSig; + newSig.name = newName; + newSig.bias = oldSig->bias; + newSig.factor = oldSig->factor; + newSig.intelByteOrder = oldSig->intelByteOrder; + newSig.max = oldSig->max; + newSig.min = oldSig->min; + newSig.receiver = oldSig->receiver; + newSig.signalSize = oldSig->signalSize; + newSig.startBit = oldSig->startBit; + newSig.valType = oldSig->valType; + newSig.valList.append(oldSig->valList); + newSig.isMultiplexed = oldSig->isMultiplexed; + newSig.isMultiplexor = oldSig->isMultiplexor; //maybe should force this false since you can't have two or more! + newSig.multiplexValue = oldSig->multiplexValue; + newSig.parentMessage = dbcMessage; + + dbcMessage->sigHandler->addSignal(newSig); + + /* add item at the end of the list */ + ui->signalsList->addItem(newName); + + //unlike adding a signal we don't want to select the new signal here. + //ui->signalsList->setCurrentRow(ui->signalsList->count()-1); } void DBCSignalEditor::deleteCurrentSignal() diff --git a/dbc/dbcsignaleditor.h b/dbc/dbcsignaleditor.h index 97b883f..e807f58 100644 --- a/dbc/dbcsignaleditor.h +++ b/dbc/dbcsignaleditor.h @@ -27,6 +27,7 @@ private slots: void onCustomMenuSignals(QPoint); void onCustomMenuValues(QPoint); void addNewSignal(); + void cloneSignal(); void deleteCurrentSignal(); void deleteCurrentValue();