SavvyCAN icon indicating copy to clipboard operation
SavvyCAN copied to clipboard

Highlight changed bytes in Frames view when Overwrite mode is enabled

Open dontgetfoundout opened this issue 2 years ago • 1 comments

Description:

This change introduces a QItemDelegate that is used to paint the Data column of the main window's Frames view. Before the change, the value of the Data column was calculated as a string by CANFrameModel::data() and displayed using the default QStyledItemDelegate. In the current version of the changes, the CANFrame is returned as Data instead and the parsing and display logic has been moved to CanDataItemDelegate. Most of the structure of the code was maintained, but now it is orchestrating QPainter draw calls rather than building up the string representation of the bytes.

There are a lot of ways this solution could be tweaked (improved?). For example:

  • CANFrameModel::data() could parse the CANFrame into a streamlined data type with just the byte data, changed bytes, error message text, and some settings (like bits per line) and return that as a QVariant for the delegate to display rather than this design which returns QVariant::fromValue(CANFrame) and moves all of the parsing and display logic to the delegate
  • Some other data type for the changed bytes bit field
  • This implementation uses CANFrameModel to read settings in CanDataItemDelegate but this coupling could be reduced with another representation
  • etc.

Previously discussed as: #84 Color code changed bits in overwrite mode While working on this, I found this already closed suggestion for the feature. I agree the sniffer window can be used to show this data, but I've come to like the visual feedback of having byte diffs in overwrite mode. Feel free to close this PR if you don't want to add this extra complexity to the project.

Screenshot

SavvyCAN-OverwriteDiff Example of the UI receiving Fuzzed frames using "Sweep" Bit Scanning

Validated:

  • <=8 byte CAN frames generated from Fuzzing window display properly
    • Hex
    • Decimal
  • Bytes per line of 4 splits 8 bytes over 2 lines

Not tested:

  • Error frame messages
  • DBC mapping text
    • These should probably work, but I couldn't find good example data. Let me know if there is a good example set for validation.
  • Larger frames
    • ~Probably needs some updates~ maybe works after commit "Increase size of changed bytes bit field" still needs testing

Notes:

It's been a little while since I've messed around with someone else's C++ codebase and I don't use it professionally atm. Please let me know if you have feedback (even if trivial).

dontgetfoundout avatar Dec 07 '23 04:12 dontgetfoundout

Updated to add a setting to enable/disable this behavior: image

image

dontgetfoundout avatar Dec 07 '23 06:12 dontgetfoundout