@@ -283,6 +283,7 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index)
283
283
idString = firstCol->text (0 ).split (" " )[0 ];
284
284
msgID = static_cast <uint32_t >(Utility::ParseStringToNum (idString));
285
285
msg = dbcFile->messageHandler ->findMsgByID (msgID);
286
+ // msg = itemToMessage[firstCol];
286
287
msgEditor->setMessageRef (msg);
287
288
msgEditor->setFileIdx (fileIdx);
288
289
// msgEditor->setWindowModality(Qt::WindowModal);
@@ -296,6 +297,7 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index)
296
297
if (nameString.contains (" (" )) nameString = nameString.split (" " )[1 ];
297
298
else nameString = nameString.split (" " )[0 ];
298
299
sig = msg->sigHandler ->findSignalByName (nameString);
300
+ // sig = itemToSignal[firstCol];
299
301
if (sig)
300
302
{
301
303
sigEditor->setSignalRef (sig);
@@ -494,8 +496,14 @@ void DBCMainEditor::updatedNode(DBC_NODE *node)
494
496
else qDebug () << " That node doesn't exist. That's a bug dude." ;
495
497
}
496
498
497
- void DBCMainEditor::updatedMessage (DBC_MESSAGE *msg)
499
+ void DBCMainEditor::updatedMessage (DBC_MESSAGE *msg, quint32 orig_ID )
498
500
{
501
+ // if ID was changed then the messagehandler must be told to update its QMap as well.
502
+ if (msg->ID != orig_ID)
503
+ {
504
+ dbcFile->messageHandler ->changeMessageID (msg, orig_ID);
505
+ }
506
+
499
507
if (messageToItem.contains (msg))
500
508
{
501
509
QTreeWidgetItem *item = messageToItem.value (msg);
@@ -675,7 +683,7 @@ void DBCMainEditor::newMessage()
675
683
nodeItem = msgItem->parent ();
676
684
}
677
685
if (typ == DBCItemTypes::NODE){
678
- msgItem = nodeItem;
686
+ msgItem = nullptr ; // we have no message, just a node selected
679
687
}
680
688
681
689
// if there was a comment this will find the location of the comment and snip it out.
@@ -709,15 +717,15 @@ void DBCMainEditor::newMessage()
709
717
else
710
718
{
711
719
msgPtr->name = nodeName + " Msg" + QString::number (randGen.bounded (500 ));
712
- msgPtr->ID = 0 ;
720
+ msgPtr->ID = 0x003 ;
713
721
msgPtr->len = 8 ;
714
722
msgPtr->bgColor = QApplication::palette ().color (QPalette::Base);
715
723
}
716
724
}
717
725
else
718
726
{
719
727
msgPtr->name = nodeName + " Msg" + QString::number (randGen.bounded (500 ));
720
- msgPtr->ID = 0 ;
728
+ msgPtr->ID = 0x004 ;
721
729
msgPtr->len = 8 ;
722
730
}
723
731
msgPtr->sender = node;
@@ -743,23 +751,41 @@ void DBCMainEditor::newSignal()
743
751
QTreeWidgetItem *parentItem = nullptr ;
744
752
msgItem = ui->treeDBC ->currentItem ();
745
753
parentItem = msgItem;
746
- if (!msgItem) return ; // nothing selected!
754
+ if (!msgItem)
755
+ {
756
+ qDebug () << " Nothing selected!" ;
757
+ return ; // nothing selected!
758
+ }
747
759
int typ = msgItem->data (0 , Qt::UserRole).toInt ();
748
- if (typ == DBCItemTypes::NODE) return ; // can't add signals to a node!
760
+ if (typ == DBCItemTypes::NODE)
761
+ {
762
+ qDebug () << " Can't add signals to a node!" ;
763
+ return ; // can't add signals to a node!
764
+ }
749
765
if (typ == DBCItemTypes::SIG)
750
766
{
751
767
sigItem = msgItem;
752
768
msgItem = msgItem->parent ();
753
769
parentItem = msgItem;
754
770
// walk up the tree to find the parent msg
755
771
while (msgItem && msgItem->data (0 , Qt::UserRole).toInt () != DBCItemTypes::MESG) msgItem = msgItem->parent ();
756
- if (!msgItem) return ; // something bad happened. abort.
772
+ if (!msgItem)
773
+ {
774
+ qDebug () << " Could not find parent message to attach signal to!" ;
775
+ return ; // something bad happened. abort.
776
+ }
757
777
}
758
778
759
779
QString idString = msgItem->text (0 ).split (" " )[0 ];
760
780
int msgID = static_cast <uint32_t >(Utility::ParseStringToNum (idString));
761
- DBC_MESSAGE *msg = dbcFile->messageHandler ->findMsgByID (msgID);
762
- if (!msg) return ; // null pointers are a bummer. Do not follow them.
781
+ DBCMessageHandler *msgHandler = dbcFile->messageHandler ;
782
+
783
+ DBC_MESSAGE *msg = msgHandler->findMsgByID (msgID);
784
+ if (!msg)
785
+ {
786
+ qDebug () << " Could not find data structure for message 0x" << QString::number (msgID, 16 ) << " . Aborting!" ;
787
+ return ; // null pointers are a bummer. Do not follow them.
788
+ }
763
789
DBC_SIGNAL *sigPtr = new DBC_SIGNAL;
764
790
if (sigItem)
765
791
{
@@ -841,8 +867,8 @@ void DBCMainEditor::deleteCurrentTreeItem()
841
867
qDebug () << " Could not find the node in the map. That should not happen." ;
842
868
}
843
869
}
844
-
845
870
break ;
871
+
846
872
case DBCItemTypes::MESG: // cascades to removing all signals too.
847
873
idString = currItem->text (0 ).split (" " )[0 ];
848
874
msgID = static_cast <uint32_t >(Utility::ParseStringToNum (idString));
@@ -864,6 +890,7 @@ void DBCMainEditor::deleteCurrentTreeItem()
864
890
}
865
891
}
866
892
break ;
893
+
867
894
case DBCItemTypes::SIG: // no cascade, just this one signal.
868
895
confirmDialog = QMessageBox::question (this , " Really?" , " Are you sure you want to delete this signal?" ,
869
896
QMessageBox::Yes|QMessageBox::No);
@@ -957,13 +984,22 @@ void DBCMainEditor::deleteMessage(DBC_MESSAGE *msg)
957
984
void DBCMainEditor::deleteSignal (DBC_SIGNAL *sig)
958
985
{
959
986
qDebug () << " Signal about to vanish." ;
960
- if (!signalToItem.contains (sig)) return ;
987
+ if (!signalToItem.contains (sig))
988
+ {
989
+ qDebug () << " Could not find signal in signalToItem collection! Aborting!" ;
990
+ return ;
991
+ }
961
992
QTreeWidgetItem *currItem = signalToItem[sig];
993
+ if (!currItem)
994
+ {
995
+ qDebug () << " currItem was null in deleteSignal. Aborting!" ;
996
+ return ;
997
+ }
962
998
sig->parentMessage ->sigHandler ->removeSignal (sig->name );
963
999
964
1000
itemToSignal.remove (currItem);
965
1001
signalToItem.remove (sig);
966
1002
ui->treeDBC ->removeItemWidget (currItem, 0 );
967
- // delete currItem; //already removed by above remove call
1003
+ delete currItem; // should have been removed above but do we need to call this anyway?!
968
1004
dbcFile->setDirtyFlag ();
969
1005
}
0 commit comments