Web Analytics Made Easy - Statcounter
Skip to content

Class SBGUITextEdit#

ClassList > SBGUITextEdit

The SBGUITextEdit class extends QFrame to include a QTextEdit with additional features.More...

  • #include <SBGUITextEdit.hpp>

Inherits the following classes: QFrame, Ui::SBGUITextEditGUI

Public Signals#

Type Name
signal void committed (const QString & text)
Emitted when the text is committed.
signal void discarded (const QString & text)
Emitted when changes to the text are discarded.
signal void limitExceeded (int value)
Emitted when the text exceeds the set character limit.
signal void originalValueChanged (const QString & text)
Emitted whenever the original value of the text changes.
signal void pendingValueChanged (const QString & text)
Emitted whenever the pending value of the text changes.

Public Functions#

Type Name
SBGUITextEdit (QWidget * parent=nullptr, int characterLimit=-1)
Constructs a new SBGUITextEdit widget.
bool charLimitValid () const
Checks whether the text changes are ok with the limit.
int getCharLimit () const
Retrieves the current character limit for the QPlainTextEdit.
QString getOriginalValue () const
Returns the original value of the text.
QString getPendingValue () const
Returns the pending value of the text.
QTextEdit * getTextEdit () const
Retrieves a pointer to the internal QPlainTextEdit.
bool isCommittable () const
Checks whether the text changes are committable.
void keyPressEvent (QKeyEvent * event)
Custom key event handler that manages key press events for commit and discard operations.
QSize minimumSizeHint () override const
void setCharLimit (int characterLimit=-1)
Sets the character limit for the QPlainTextEdit.
void setCommittable (bool committable=true)
Enables or disables the ability to commit changes.
void setOriginalValue (const QString & value)
Sets the original value of the text.
void setPendingValue (const QString & value)
Sets the pending value of the text, which is the value staged for commit.
void setPlainText (const QString & text)
Sets the text displayed in the QPlainTextEdit, respecting the character limit if set.
void setValues (const QString & originValue, const QString & pendingValue)
Sets both the original and pending values at once.
QSize sizeHint () override const
QString toLimitedPlainText () const
Returns the text trimmed to the current character limit.
QString toPlainText () const
Returns the text currently displayed in the QPlainTextEdit.

Protected Functions#

Type Name
void resizeEvent (QResizeEvent * event) override
Handles the resize event to update the layout and appearance of the widget.

Detailed Description#

This class supports character limits, commit/discard mechanisms, and the handling of "original" and "pending" text values. It is useful for input fields where changes can be staged and either committed or discarded.

Short name: SBTextEdit

Example:

SBGUITextEdit *textEdit = new SBGUITextEdit(0, 50); // 50 character limit
textEdit->setPlainText("Hello world");
lineEdit->setCommittable(true);

Note: This class also emits signals when text is committed or discarded, providing hooks for further action.

Public Signals Documentation#

signal committed#

Emitted when the text is committed.

void SBGUITextEdit::committed;

This signal is triggered when the user finalizes their input, which could be through an explicit commit action (e.g., pressing an Enter key or a dedicated button). It signifies that the pending changes have been accepted and the internal state of the text should be updated to reflect this.

Parameters:

  • text The text that was committed. This is typically the content that was pending and has now been confirmed.

signal discarded#

Emitted when changes to the text are discarded.

void SBGUITextEdit::discarded;

This signal is triggered when the user decides to revert their input back to the last committed state. This is useful in scenarios where temporary modifications to text are allowed but the user opts to cancel these changes.

Parameters:

  • text The text that was discarded. This could reflect the content that was pending before being reverted to the original.

signal limitExceeded#

Emitted when the text exceeds the set character limit.

void SBGUITextEdit::limitExceeded;

This signal is triggered when an attempt is made to input more characters than the current limit allows. It can be used to provide feedback to the user, such as displaying a warning message or altering the visual state of the input field to indicate an error.

Parameters:

  • value The character limit that has been exceeded. This is the maximum number of characters that were set as allowable.

signal originalValueChanged#

Emitted whenever the original value of the text changes.

void SBGUITextEdit::originalValueChanged;

This signal is useful for tracking changes to the baseline state of the text input. It can be used to monitor resets or updates to the original text from which changes are being made.

Parameters:

  • text The new original text. This reflects the baseline or committed state of the text to which any new changes will be compared.

signal pendingValueChanged#

Emitted whenever the pending value of the text changes.

void SBGUITextEdit::pendingValueChanged;

This signal provides a hook for external components to react to changes in the staged (pending) text. It is useful for enabling or disabling UI components based on whether there are uncommitted changes in the input field.

Parameters:

  • text The new pending text. This text is the current content of the QPlainTextEdit that has not yet been committed.

Public Functions Documentation#

function SBGUITextEdit#

Constructs a new SBGUITextEdit widget.

explicit SBGUITextEdit::SBGUITextEdit (
    QWidget * parent=nullptr,
    int characterLimit=-1
) 

Initializes the UI elements and sets up the character limit.

Parameters:

  • parent The parent widget of this text edit, typically a form or another container.
  • characterLimit The initial character limit; -1 indicates no limit.

function charLimitValid#

Checks whether the text changes are ok with the limit.

bool SBGUITextEdit::charLimitValid () const

Checks whether the current text length respects the character limit.

Returns:

true if the text length is within the limit or if no limit is set.


function getCharLimit#

Retrieves the current character limit for the QPlainTextEdit.

int SBGUITextEdit::getCharLimit () const

Retrieves the current character limit.

Returns:

The current character limit; -1 if no limit is set.


function getOriginalValue#

Returns the original value of the text.

QString SBGUITextEdit::getOriginalValue () const

Returns:

The original text before any edits were made.


function getPendingValue#

Returns the pending value of the text.

QString SBGUITextEdit::getPendingValue () const

Returns:

The pending text that is staged for commit.


function getTextEdit#

Retrieves a pointer to the internal QPlainTextEdit.

QTextEdit * SBGUITextEdit::getTextEdit () const

Retrieves a pointer to the internal QTextEdit.

Returns:

Pointer to the encapsulated QTextEdit object.


function isCommittable#

Checks whether the text changes are committable.

bool SBGUITextEdit::isCommittable () const

Checks whether the widget allows committing changes.

Returns:

true if the widget is committable; otherwise false.


function keyPressEvent#

Custom key event handler that manages key press events for commit and discard operations.

void SBGUITextEdit::keyPressEvent (
    QKeyEvent * event
) 

Handles key press events for commit and discard operations.

Interprets Escape to discard changes and Ctrl+Enter/Return to commit changes when applicable.

Parameters:

  • event The key event to process.

function minimumSizeHint#

QSize SBGUITextEdit::minimumSizeHint () override const

function setCharLimit#

Sets the character limit for the QPlainTextEdit.

void SBGUITextEdit::setCharLimit (
    int characterLimit=-1
) 

Sets the character limit for the text edit.

A limit of -1 disables the limit.

Parameters:

  • characterLimit The maximum number of characters allowed; -1 for no limit.

function setCommittable#

Enables or disables the ability to commit changes.

void SBGUITextEdit::setCommittable (
    bool committable=true
) 

Controls whether the widget allows committing or discarding edits.

Parameters:

  • committable Set to true to allow committing changes, false to disable.

function setOriginalValue#

Sets the original value of the text.

void SBGUITextEdit::setOriginalValue (
    const QString & value
) 

Emits a signal when the original value changes.

Parameters:

  • value The text to set as the original value.

function setPendingValue#

Sets the pending value of the text, which is the value staged for commit.

void SBGUITextEdit::setPendingValue (
    const QString & value
) 

Sets the pending value of the text.

Emits a signal when the pending value changes.

Parameters:

  • value The text to set as the pending value.

function setPlainText#

Sets the text displayed in the QPlainTextEdit, respecting the character limit if set.

void SBGUITextEdit::setPlainText (
    const QString & text
) 

Sets the text displayed in the QTextEdit, respecting the character limit if set.

Parameters:

  • text The text to display in the widget.

function setValues#

Sets both the original and pending values at once.

void SBGUITextEdit::setValues (
    const QString & originValue,
    const QString & pendingValue
) 

Parameters:

  • originValue The text for the original value.
  • pendingValue The text for the pending value.

function sizeHint#

QSize SBGUITextEdit::sizeHint () override const

function toLimitedPlainText#

Returns the text trimmed to the current character limit.

QString SBGUITextEdit::toLimitedPlainText () const

If a character limit is set, the returned text will be truncated accordingly.

Returns:

The plain text limited by the character limit.


function toPlainText#

Returns the text currently displayed in the QPlainTextEdit.

QString SBGUITextEdit::toPlainText () const

Returns the text currently displayed in the QTextEdit.

Returns:

The current plain text.


Protected Functions Documentation#

function resizeEvent#

Handles the resize event to update the layout and appearance of the widget.

void SBGUITextEdit::resizeEvent (
    QResizeEvent * event
) override

Handles resize events to update widget layout and visibility.

Parameters:

  • event The resize event information.