Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Public Types | Public Slots | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
SyntaxLineEdit Class Reference

QLineEdit subclass that adds syntax-state colouring, error messaging, and partial token-based autocompletion for display filters, field names, custom columns, and integer inputs. More...

#include <syntax_line_edit.h>

Inheritance diagram for SyntaxLineEdit:
CaptureFilterEdit DisplayFilterEdit DissectorSyntaxLineEdit FieldFilterEdit RangeSyntaxLineEdit

Public Types

enum  SyntaxState {
  Empty , Busy , Invalid , Deprecated ,
  Valid
}
 Visual and semantic state of the text currently in the editor. More...
 

Public Slots

void setStyleSheet (const QString &style_sheet)
 Sets the base style sheet; the state-driven style is composited on top.
 
void insertFilter (const QString &filter)
 Inserts filter text at the cursor position, adding surrounding spaces where necessary to keep the expression well-formed.
 
bool checkDisplayFilter (QString filter)
 Validates filter as a Wireshark display filter and updates the syntax state and error message accordingly.
 
void checkFieldName (QString field)
 Validates field as a protocol field name and updates the syntax state.
 
void checkCustomColumn (QString fields)
 Validates fields as a custom-column field expression and updates the syntax state.
 
void checkInteger (QString number)
 Validates number as a well-formed integer and updates the syntax state.
 

Public Member Functions

 SyntaxLineEdit (QWidget *parent=0)
 Constructs the SyntaxLineEdit in the Empty state with no completer.
 
SyntaxState syntaxState () const
 Returns the current syntax validation state.
 
void setSyntaxState (SyntaxState state=Empty)
 Sets the syntax state and updates the widget's style sheet to reflect it.
 
QString syntaxErrorMessage ()
 Returns a short, human-readable description of the current syntax error.
 
QString syntaxErrorMessageFull ()
 Returns a full error message that includes the filter expression and the location of the error within it.
 
QString styleSheet () const
 Returns the base style sheet, excluding any state-driven overrides.
 
QString deprecatedToken ()
 Returns the deprecated token string when the state is Deprecated.
 
void setCompleter (QCompleter *c)
 Installs a QCompleter for token-based autocompletion.
 
QCompleter * completer () const
 Returns the currently installed completer.
 
void allowCompletion (bool enabled)
 Enables or disables autocompletion without removing the completer.
 

Static Public Member Functions

static QString createSyntaxErrorMessageFull (const QString &filter, const QString &err_msg, qsizetype loc_start, size_t loc_length)
 Builds a full syntax error message string combining the filter expression with a location-annotated error description.
 

Protected Member Functions

void setCompletionTokenChars (const QString &token_chars)
 Sets the characters that may appear in a completion token (e.g. letters, digits, underscores, dots). Must be called by subclasses before completion is used.
 
bool isComplexFilter (const QString &filter)
 Returns true if filter contains operators or structure that make it too complex for token-level autocompletion.
 
virtual void buildCompletionList (const QString &field_word, const QString &preamble)
 Builds the list of completion candidates based on the current token and filter context. Subclasses must override this to provide context-appropriate completions.
 
QPoint getTokenUnderCursor ()
 Returns the start position and length of the token under the cursor.
 
QStringList splitLineUnderCursor ()
 Splits the line at the cursor into the preamble and the current token.
 
virtual bool event (QEvent *event)
 Intercepts Tab and other keys to trigger or dismiss the completer.
 
void completionKeyPressEvent (QKeyEvent *event)
 Handles key press events while the completer popup is visible, forwarding navigation keys to the popup and committing on Enter/Tab.
 
void completionFocusInEvent (QFocusEvent *event)
 Triggers a completion refresh when the widget gains focus.
 
virtual void focusOutEvent (QFocusEvent *event)
 Hides the completer popup when the widget loses focus.
 
virtual void paintEvent (QPaintEvent *event)
 Paints the widget, overlaying a state-appropriate background colour.
 

Protected Attributes

QCompleter * completer_
 
QStringListModel * completion_model_
 

Properties

SyntaxState syntaxState
 

Detailed Description

QLineEdit subclass that adds syntax-state colouring, error messaging, and partial token-based autocompletion for display filters, field names, custom columns, and integer inputs.

Autocompletion is partially implemented. Subclasses must:

Member Enumeration Documentation

◆ SyntaxState

Visual and semantic state of the text currently in the editor.

Enumerator
Empty 

The field is empty; no validation has been performed.

Busy 

Validation is in progress (e.g. asynchronous lookup).

Invalid 

The current text fails validation.

Deprecated 

The current text is valid but uses a deprecated construct.

Valid 

The current text passes validation.

Constructor & Destructor Documentation

◆ SyntaxLineEdit()

SyntaxLineEdit::SyntaxLineEdit ( QWidget *  parent = 0)
explicit

Constructs the SyntaxLineEdit in the Empty state with no completer.

Parameters
parentOptional parent widget.

Member Function Documentation

◆ allowCompletion()

void SyntaxLineEdit::allowCompletion ( bool  enabled)

Enables or disables autocompletion without removing the completer.

Parameters
enabledtrue to allow completion popups; false to suppress them.

◆ buildCompletionList()

virtual void SyntaxLineEdit::buildCompletionList ( const QString &  field_word,
const QString &  preamble 
)
inlineprotectedvirtual

Builds the list of completion candidates based on the current token and filter context. Subclasses must override this to provide context-appropriate completions.

Parameters
field_wordThe current token under the cursor that is being completed.
preambleThe portion of the filter before the current token, which may provide context for filtering the completion list.

◆ checkCustomColumn

void SyntaxLineEdit::checkCustomColumn ( QString  fields)
slot

Validates fields as a custom-column field expression and updates the syntax state.

Parameters
fieldsCustom column field expression to check.

◆ checkDisplayFilter

bool SyntaxLineEdit::checkDisplayFilter ( QString  filter)
slot

Validates filter as a Wireshark display filter and updates the syntax state and error message accordingly.

Parameters
filterDisplay filter expression to check.
Returns
true if the filter is valid or empty; false if invalid.

◆ checkFieldName

void SyntaxLineEdit::checkFieldName ( QString  field)
slot

Validates field as a protocol field name and updates the syntax state.

Parameters
fieldField name string to check (e.g. "tcp.port").

◆ checkInteger

void SyntaxLineEdit::checkInteger ( QString  number)
slot

Validates number as a well-formed integer and updates the syntax state.

Parameters
numberString to validate as an integer.

◆ completer()

QCompleter * SyntaxLineEdit::completer ( ) const
inline

Returns the currently installed completer.

Returns
Pointer to the QCompleter, or nullptr if none is installed.

◆ completionFocusInEvent()

void SyntaxLineEdit::completionFocusInEvent ( QFocusEvent *  event)
protected

Triggers a completion refresh when the widget gains focus.

Parameters
eventThe focus-in event.

◆ completionKeyPressEvent()

void SyntaxLineEdit::completionKeyPressEvent ( QKeyEvent *  event)
protected

Handles key press events while the completer popup is visible, forwarding navigation keys to the popup and committing on Enter/Tab.

Parameters
eventThe key press event.

◆ createSyntaxErrorMessageFull()

QString SyntaxLineEdit::createSyntaxErrorMessageFull ( const QString &  filter,
const QString &  err_msg,
qsizetype  loc_start,
size_t  loc_length 
)
static

Builds a full syntax error message string combining the filter expression with a location-annotated error description.

Parameters
filterThe filter expression that failed validation.
err_msgShort error message returned by the validator.
loc_startZero-based character offset where the error begins.
loc_lengthNumber of characters the error spans.
Returns
Formatted full error message string.

◆ deprecatedToken()

QString SyntaxLineEdit::deprecatedToken ( )

Returns the deprecated token string when the state is Deprecated.

Returns
The deprecated token, or an empty string if the state is not Deprecated.

◆ event()

bool SyntaxLineEdit::event ( QEvent *  event)
protectedvirtual

Intercepts Tab and other keys to trigger or dismiss the completer.

Parameters
eventThe event to inspect.
Returns
true if the event was consumed; false to pass it on.

◆ focusOutEvent()

void SyntaxLineEdit::focusOutEvent ( QFocusEvent *  event)
protectedvirtual

Hides the completer popup when the widget loses focus.

Parameters
eventThe focus-out event.

Reimplemented in DisplayFilterEdit, and FieldFilterEdit.

◆ getTokenUnderCursor()

QPoint SyntaxLineEdit::getTokenUnderCursor ( )
protected

Returns the start position and length of the token under the cursor.

Returns
QPoint where x is the start character offset and y is the token length.

◆ insertFilter

void SyntaxLineEdit::insertFilter ( const QString &  filter)
slot

Inserts filter text at the cursor position, adding surrounding spaces where necessary to keep the expression well-formed.

Parameters
filterFilter text to insert.

◆ isComplexFilter()

bool SyntaxLineEdit::isComplexFilter ( const QString &  filter)
protected

Returns true if filter contains operators or structure that make it too complex for token-level autocompletion.

Parameters
filterFilter expression to inspect.
Returns
true if the filter is considered complex.

◆ paintEvent()

void SyntaxLineEdit::paintEvent ( QPaintEvent *  event)
protectedvirtual

Paints the widget, overlaying a state-appropriate background colour.

Parameters
eventThe paint event.

Reimplemented in CaptureFilterEdit, and DisplayFilterEdit.

◆ setCompleter()

void SyntaxLineEdit::setCompleter ( QCompleter *  c)

Installs a QCompleter for token-based autocompletion.

Parameters
cCompleter to install; pass nullptr to remove the current completer.

◆ setCompletionTokenChars()

void SyntaxLineEdit::setCompletionTokenChars ( const QString &  token_chars)
inlineprotected

Sets the characters that may appear in a completion token (e.g. letters, digits, underscores, dots). Must be called by subclasses before completion is used.

Parameters
token_charsString of characters valid within a single completion token.

◆ setStyleSheet

void SyntaxLineEdit::setStyleSheet ( const QString &  style_sheet)
slot

Sets the base style sheet; the state-driven style is composited on top.

Parameters
style_sheetNew base style sheet string.

◆ setSyntaxState()

void SyntaxLineEdit::setSyntaxState ( SyntaxState  state = Empty)

Sets the syntax state and updates the widget's style sheet to reflect it.

Parameters
stateNew syntax state; defaults to Empty.

◆ splitLineUnderCursor()

QStringList SyntaxLineEdit::splitLineUnderCursor ( )
protected

Splits the line at the cursor into the preamble and the current token.

Returns
QStringList of exactly two elements: { preamble, token }.

◆ styleSheet()

QString SyntaxLineEdit::styleSheet ( ) const

Returns the base style sheet, excluding any state-driven overrides.

Returns
Base style sheet string.

◆ syntaxErrorMessage()

QString SyntaxLineEdit::syntaxErrorMessage ( )

Returns a short, human-readable description of the current syntax error.

Returns
Error message string, or an empty string if the state is not Invalid.

◆ syntaxErrorMessageFull()

QString SyntaxLineEdit::syntaxErrorMessageFull ( )

Returns a full error message that includes the filter expression and the location of the error within it.

Returns
Full error message string, or an empty string if there is no error.

◆ syntaxState()

SyntaxState SyntaxLineEdit::syntaxState ( ) const
inline

Returns the current syntax validation state.

Returns
Current SyntaxState value.

Member Data Documentation

◆ completer_

QCompleter* SyntaxLineEdit::completer_
protected

Installed autocompletion provider; may be nullptr.

◆ completion_model_

QStringListModel* SyntaxLineEdit::completion_model_
protected

String list model backing the completer.


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