Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Classes | Public Slots | Signals | Public Member Functions | Protected Member Functions | List of all members
HexDataSourceView Class Reference

A fully custom-painted hex dump view for a single packet data source. More...

#include <hex_data_source_view.h>

Inheritance diagram for HexDataSourceView:
BaseDataSourceView IDataPrintable

Classes

struct  ByteViewAnnotation
 A user-defined color annotation over a byte range. More...
 

Public Slots

void setMonospaceFont (const QFont &mono_font)
 Update the monospace font and recalculate layout metrics.
 
void updateByteViewSettings ()
 Reload byte-view display preferences and repaint.
 
void markProtocol (int start, int length)
 Highlight the enclosing protocol layer byte range.
 
void markField (int start, int length, bool scroll_to=true, bool hover=false)
 Highlight a specific dissected field byte range.
 
void markAppendix (int start, int length)
 Highlight the appendix (trailing) bytes of the selected field.
 
void unmarkField ()
 Clear field, appendix, and hover highlights.
 
- Public Slots inherited from BaseDataSourceView
virtual void setMonospaceFont (const QFont &mono_font)=0
 Update the monospace font used to render byte values.
 
virtual void detachData ()
 Detach the internal QByteArray from any shared copy.
 
virtual void markProtocol (int start, int length)=0
 Highlight the byte range belonging to the enclosing protocol layer.
 
virtual void markField (int start, int length, bool scroll_to=true, bool hover=false)=0
 Highlight the byte range for a specific dissected field.
 
virtual void markAppendix (int start, int length)=0
 Highlight the appendix byte range for the selected field.
 
virtual void unmarkField ()=0
 Clear all field and appendix highlights.
 

Signals

void byteViewSettingsChanged ()
 Emitted when any byte-view display setting changes.
 
void addAnnotationRequested ()
 Emitted when the user triggers "Add annotation" from the context menu.
 
void editAnnotationRequested ()
 Emitted when the user triggers "Edit annotation" from the context menu.
 
void removeAnnotationRequested ()
 Emitted when the user triggers "Remove annotation" from the context menu.
 
void offsetStartRequested (int byte)
 Emitted when the user requests a new offset-start marker.
 
void offsetEndRequested (int byte)
 Emitted when the user requests a new offset-end marker.
 
void offsetMarkersCleared ()
 Emitted when the user requests that both offset markers be cleared.
 
- Signals inherited from BaseDataSourceView
void byteHovered (int pos)
 Emitted when the cursor moves over a byte in the view.
 
void byteSelected (int pos)
 Emitted when the user clicks a byte in the view.
 

Public Member Functions

 HexDataSourceView (const QByteArray &data, packet_char_enc encoding=PACKET_CHAR_ENC_CHAR_ASCII, QWidget *parent=nullptr)
 Construct a HexDataSourceView.
 
 ~HexDataSourceView ()
 Destroy the view and its QTextLayout.
 
void setFormat (bytes_view_type format)
 Set the numeric base used to render hex-panel byte values.
 
void setAnnotations (const QVector< ByteViewAnnotation > &annotations)
 Replace the current set of user annotations.
 
bool selectionRange (int *start, int *length) const
 Return the current byte selection range.
 
int selectionAnchor () const
 Return the selection anchor byte offset.
 
int selectionEnd () const
 Return the byte offset at the end of the current selection.
 
int contextByteOffset () const
 Return the byte offset at which the context menu was invoked.
 
int dataSize () const
 Return the number of bytes in the data buffer.
 
int offsetStart () const
 Return the current offset-start marker byte position.
 
int offsetEnd () const
 Return the current offset-end marker byte position.
 
void setOffsetStart (int byte)
 Set the offset-start marker to the given byte.
 
void setOffsetEnd (int byte)
 Set the offset-end marker to the given byte.
 
void clearOffsetMarkers ()
 Clear both offset markers and repaint.
 
int selectedFieldStart () const
 
int selectedFieldLength () const
 
int selectedProtocolStart () const
 
int selectedProtocolLength () const
 
bool selectedFieldIsProtocol () const
 Return whether the selected field is itself a protocol layer.
 
bool selectedFieldUsesOwnRange () const
 Return whether the selected field defines its own byte range.
 
void setSelectedFieldIsProtocol (bool is_protocol)
 Set whether the selected field is a protocol-level item.
 
void setSelectedFieldUsesOwnRange (bool use_own_range)
 Set whether the selected field uses its own independent range.
 
- Public Member Functions inherited from BaseDataSourceView
 BaseDataSourceView (const QByteArray &data, QWidget *parent=nullptr)
 Construct a BaseDataSourceView.
 
virtual QSize minimumSizeHint () const
 Return the minimum size hint for the view.
 
virtual bool isEmpty () const
 Return whether the view contains no displayable data.
 
struct tvbufftvb () const
 Return the tvbuff associated with this data source.
 
void setTvb (struct tvbuff *tvb)
 Associate a Wireshark tvbuff with this data source.
 
int tabIndex () const
 Return the tab index of this view within the byte-view panel.
 
void setTabIndex (int tab_index)
 Set the tab index for this view.
 
- Public Member Functions inherited from IDataPrintable
virtual ~IDataPrintable ()
 Destroys the IDataPrintable object.
 

Protected Member Functions

virtual void paintEvent (QPaintEvent *event)
 Paint all visible rows of the hex dump.
 
virtual void resizeEvent (QResizeEvent *event)
 Recalculate scrollbar ranges and repaint after a resize.
 
virtual void showEvent (QShowEvent *event)
 Ensure the layout is up to date when the widget first becomes visible.
 
virtual void mousePressEvent (QMouseEvent *event)
 Begin a byte selection or move the cursor on mouse press.
 
virtual void mouseMoveEvent (QMouseEvent *event)
 Extend the selection during a mouse drag.
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 Finalise a drag selection on mouse release.
 
virtual void leaveEvent (QEvent *event)
 Clear hover highlights when the pointer leaves the widget.
 
virtual void contextMenuEvent (QContextMenuEvent *event)
 Show the byte-view context menu.
 
virtual void keyPressEvent (QKeyEvent *event)
 Handle keyboard navigation and copy commands.
 

Additional Inherited Members

- Protected Attributes inherited from BaseDataSourceView
QByteArray data_
 The raw packet bytes displayed by this view.
 

Detailed Description

A fully custom-painted hex dump view for a single packet data source.

Constructor & Destructor Documentation

◆ HexDataSourceView()

HexDataSourceView::HexDataSourceView ( const QByteArray &  data,
packet_char_enc  encoding = PACKET_CHAR_ENC_CHAR_ASCII,
QWidget *  parent = nullptr 
)
explicit

Construct a HexDataSourceView.

Parameters
dataThe raw packet bytes to display.
encodingCharacter encoding used for the ASCII panel; PACKET_CHAR_ENC_CHAR_ASCII (default) or PACKET_CHAR_ENC_CHAR_EBCDIC.
parentThe parent widget; may be nullptr.

Member Function Documentation

◆ byteViewSettingsChanged

void HexDataSourceView::byteViewSettingsChanged ( )
signal

Emitted when any byte-view display setting changes.

Connected to sibling views so all tabs stay in sync when the user changes the format, encoding, or row-width preference.

◆ contextByteOffset()

int HexDataSourceView::contextByteOffset ( ) const

Return the byte offset at which the context menu was invoked.

Saved in contextMenuEvent() so that context-menu action slots know which byte the user right-clicked on, independent of the current keyboard selection.

Returns
The byte offset under the cursor at context-menu open time.

◆ contextMenuEvent()

void HexDataSourceView::contextMenuEvent ( QContextMenuEvent *  event)
protectedvirtual

Show the byte-view context menu.

Parameters
eventThe context menu event.

◆ dataSize()

int HexDataSourceView::dataSize ( ) const
inline

Return the number of bytes in the data buffer.

Returns
data_.size() cast to int. Asserts that the size fits.

◆ keyPressEvent()

void HexDataSourceView::keyPressEvent ( QKeyEvent *  event)
protectedvirtual

Handle keyboard navigation and copy commands.

Parameters
eventThe key press event.

◆ leaveEvent()

void HexDataSourceView::leaveEvent ( QEvent *  event)
protectedvirtual

Clear hover highlights when the pointer leaves the widget.

Parameters
eventThe leave event.

◆ markAppendix

void HexDataSourceView::markAppendix ( int  start,
int  length 
)
slot

Highlight the appendix (trailing) bytes of the selected field.

Parameters
startFirst byte offset of the appendix.
lengthNumber of bytes in the appendix.

◆ markField

void HexDataSourceView::markField ( int  start,
int  length,
bool  scroll_to = true,
bool  hover = false 
)
slot

Highlight a specific dissected field byte range.

Parameters
startFirst byte offset of the field.
lengthNumber of bytes in the field.
scroll_totrue (default) to scroll the range into view.
hovertrue to apply hover coloring rather than selection.

◆ markProtocol

void HexDataSourceView::markProtocol ( int  start,
int  length 
)
slot

Highlight the enclosing protocol layer byte range.

Parameters
startFirst byte offset of the protocol span.
lengthNumber of bytes in the protocol span.

◆ mouseMoveEvent()

void HexDataSourceView::mouseMoveEvent ( QMouseEvent *  event)
protectedvirtual

Extend the selection during a mouse drag.

Parameters
eventThe mouse move event.

◆ mousePressEvent()

void HexDataSourceView::mousePressEvent ( QMouseEvent *  event)
protectedvirtual

Begin a byte selection or move the cursor on mouse press.

Parameters
eventThe mouse press event.

◆ mouseReleaseEvent()

void HexDataSourceView::mouseReleaseEvent ( QMouseEvent *  event)
protectedvirtual

Finalise a drag selection on mouse release.

Parameters
eventThe mouse release event.

◆ offsetEnd()

int HexDataSourceView::offsetEnd ( ) const
inline

Return the current offset-end marker byte position.

Returns
The byte offset of the end marker, or -1 if not set.

◆ offsetEndRequested

void HexDataSourceView::offsetEndRequested ( int  byte)
signal

Emitted when the user requests a new offset-end marker.

Parameters
byteThe byte offset under the cursor at the time of the request.

◆ offsetStart()

int HexDataSourceView::offsetStart ( ) const
inline

Return the current offset-start marker byte position.

Returns
The byte offset of the start marker, or -1 if not set.

◆ offsetStartRequested

void HexDataSourceView::offsetStartRequested ( int  byte)
signal

Emitted when the user requests a new offset-start marker.

Parameters
byteThe byte offset under the cursor at the time of the request.

◆ paintEvent()

void HexDataSourceView::paintEvent ( QPaintEvent *  event)
protectedvirtual

Paint all visible rows of the hex dump.

Parameters
eventProvides the dirty rect used to limit painting.

◆ resizeEvent()

void HexDataSourceView::resizeEvent ( QResizeEvent *  event)
protectedvirtual

Recalculate scrollbar ranges and repaint after a resize.

Parameters
eventThe resize event (unused beyond triggering the update).

◆ selectedFieldIsProtocol()

bool HexDataSourceView::selectedFieldIsProtocol ( ) const
inline

Return whether the selected field is itself a protocol layer.

Returns
true if the selected item in the packet tree is a protocol node.

◆ selectedFieldLength()

int HexDataSourceView::selectedFieldLength ( ) const
inline
Returns
Byte length of the currently highlighted field.

◆ selectedFieldStart()

int HexDataSourceView::selectedFieldStart ( ) const
inline
Returns
Start byte offset of the currently highlighted field.

◆ selectedFieldUsesOwnRange()

bool HexDataSourceView::selectedFieldUsesOwnRange ( ) const
inline

Return whether the selected field defines its own byte range.

Returns
true if the field uses its own independent range.

◆ selectedProtocolLength()

int HexDataSourceView::selectedProtocolLength ( ) const
inline
Returns
Byte length of the enclosing protocol span.

◆ selectedProtocolStart()

int HexDataSourceView::selectedProtocolStart ( ) const
inline
Returns
Start byte offset of the enclosing protocol span.

◆ selectionAnchor()

int HexDataSourceView::selectionAnchor ( ) const

Return the selection anchor byte offset.

The anchor is the byte where a drag or keyboard selection began. It may be greater than selectionEnd() for backward selections.

Returns
The anchor byte offset, or -1 if there is no selection.

◆ selectionEnd()

int HexDataSourceView::selectionEnd ( ) const

Return the byte offset at the end of the current selection.

Returns
The inclusive last selected byte offset, or -1 if none.

◆ selectionRange()

bool HexDataSourceView::selectionRange ( int *  start,
int *  length 
) const

Return the current byte selection range.

Parameters
[out]startSet to the first selected byte offset, or -1 if there is no selection.
[out]lengthSet to the number of selected bytes, or 0.
Returns
true if at least one byte is selected; false otherwise.

◆ setAnnotations()

void HexDataSourceView::setAnnotations ( const QVector< ByteViewAnnotation > &  annotations)

Replace the current set of user annotations.

Parameters
annotationsThe new annotation list.

◆ setFormat()

void HexDataSourceView::setFormat ( bytes_view_type  format)

Set the numeric base used to render hex-panel byte values.

Parameters
formatOne of the bytes_view_type values: hexadecimal, decimal, octal, or binary.

◆ setMonospaceFont

void HexDataSourceView::setMonospaceFont ( const QFont &  mono_font)
slot

Update the monospace font and recalculate layout metrics.

Parameters
mono_fontThe new monospace font.

◆ setOffsetEnd()

void HexDataSourceView::setOffsetEnd ( int  byte)

Set the offset-end marker to the given byte.

Parameters
byteZero-based byte offset at which the end marker is placed.

◆ setOffsetStart()

void HexDataSourceView::setOffsetStart ( int  byte)

Set the offset-start marker to the given byte.

Parameters
byteZero-based byte offset at which the start marker is placed.

◆ setSelectedFieldIsProtocol()

void HexDataSourceView::setSelectedFieldIsProtocol ( bool  is_protocol)
inline

Set whether the selected field is a protocol-level item.

Parameters
is_protocoltrue if the item is a protocol node.

◆ setSelectedFieldUsesOwnRange()

void HexDataSourceView::setSelectedFieldUsesOwnRange ( bool  use_own_range)
inline

Set whether the selected field uses its own independent range.

Parameters
use_own_rangetrue to use the field's own range.

◆ showEvent()

void HexDataSourceView::showEvent ( QShowEvent *  event)
protectedvirtual

Ensure the layout is up to date when the widget first becomes visible.

Parameters
eventThe show event.

The documentation for this class was generated from the following files: