Limo
A simple mod manager
Loading...
Searching...
No Matches
ValidatingLineEdit Class Reference

A line edit which automatically validates its input and shows a visual indicator for invalid inputs. More...

#include <validatinglineedit.h>

Inheritance diagram for ValidatingLineEdit:
Collaboration diagram for ValidatingLineEdit:

Public Types

enum  ValidationMode {
  VALID_NONE = 0 , VALID_NOT_EMPTY = 1 , VALID_PATH_EXISTS = 2 , VALID_CUSTOM = 3 ,
  VALID_IS_EXISTING_FILE = 4 , VALID_IS_EXISTING_DIRECTORY = 5
}
 Type of validation to be applied. More...
 

Public Member Functions

 ValidatingLineEdit (QWidget *parent=nullptr, ValidationMode mode=VALID_NOT_EMPTY)
 Calls QLineEdit constructor and sets the validation mode.
 
 ValidatingLineEdit (const QString &contents, QWidget *parent=nullptr, ValidationMode mode=VALID_NOT_EMPTY)
 Calls QLineEdit constructor and sets the validation mode.
 
bool hasValidText ()
 Checks if the current text is valid.
 
void setValidationMode (ValidationMode mode)
 Changes the validation mode to the new mode.
 
void setCustomValidator (std::function< bool(QString)> validator)
 Sets a new custom validator function. Does not affect validation mode.
 
void updateValidation ()
 Updates the visual indicator using the current text.
 
bool acceptsEmptyPaths () const
 Returns whether or not an empty path will be accepted.
 
void setAcceptsEmptyPaths (bool accept)
 Sets whether or not an empty path will be accepted.
 
bool showsStatusTooltip () const
 Returns whether or not the tooltip is used to show a reason for input rejection.
 
void setShowStatusTooltip (bool show)
 Sets whether or not the tooltip is used to show a reason for input rejection.
 

Private Slots

void onTextChanged (const QString &new_text)
 Connected to this line edits textChanged signal. Updates the visual indicator.
 

Private Attributes

ValidationMode validation_mode_
 Determines how the input text is validated, see ValidationMode modes.
 
std::function< bool(QString)> validator_ = [](QString s) { return true; }
 If the validation mode is set to VALID_CUSTOM, this function will be called and be passed the current input text as argument, whenever the text is changed. The new text is valid, if the function returns true.
 
bool accept_empty_paths_ = false
 If true: Empty paths will be accepted in VALID_PATH_EXISTS.
 
bool show_status_tooltip_ = true
 If true: Use the tooltip to display a reason for input rejection.
 

Detailed Description

A line edit which automatically validates its input and shows a visual indicator for invalid inputs.

Member Enumeration Documentation

◆ ValidationMode

Type of validation to be applied.

Enumerator
VALID_NONE 

All text is valid.

VALID_NOT_EMPTY 

Requires text to not be an empty string.

VALID_PATH_EXISTS 

Requires text to be a path to an existing file or directory.

VALID_CUSTOM 

Uses a custom validation function.

VALID_IS_EXISTING_FILE 

Requires text to be a path to an existing file.

VALID_IS_EXISTING_DIRECTORY 

Requires text to be a path to an existing directory.

Constructor & Destructor Documentation

◆ ValidatingLineEdit() [1/2]

ValidatingLineEdit::ValidatingLineEdit ( QWidget * parent = nullptr,
ValidationMode mode = VALID_NOT_EMPTY )

Calls QLineEdit constructor and sets the validation mode.

Parameters
parentParent widget.
modeValidation mode to use.

◆ ValidatingLineEdit() [2/2]

ValidatingLineEdit::ValidatingLineEdit ( const QString & contents,
QWidget * parent = nullptr,
ValidationMode mode = VALID_NOT_EMPTY )

Calls QLineEdit constructor and sets the validation mode.

Parameters
contentsInitial text for this line edit.
parentParent widget.
modeValidation mode to use.

Member Function Documentation

◆ acceptsEmptyPaths()

bool ValidatingLineEdit::acceptsEmptyPaths ( ) const

Returns whether or not an empty path will be accepted.

Returns
The state.

◆ hasValidText()

bool ValidatingLineEdit::hasValidText ( )

Checks if the current text is valid.

Returns
True if the text is valid.

◆ onTextChanged

void ValidatingLineEdit::onTextChanged ( const QString & new_text)
privateslot

Connected to this line edits textChanged signal. Updates the visual indicator.

Parameters
new_textThe new display text

◆ setAcceptsEmptyPaths()

void ValidatingLineEdit::setAcceptsEmptyPaths ( bool accept)

Sets whether or not an empty path will be accepted.

Parameters
Thenew state.

◆ setCustomValidator()

void ValidatingLineEdit::setCustomValidator ( std::function< bool(QString)> validator)

Sets a new custom validator function. Does not affect validation mode.

Parameters
validatorIf the validation mode is set to VALID_CUSTOM, this function will be called and be passed the current input text as argument, whenever the text is changed. The new text is valid, if the function returns true.

◆ setShowStatusTooltip()

void ValidatingLineEdit::setShowStatusTooltip ( bool show)

Sets whether or not the tooltip is used to show a reason for input rejection.

Parameters
showThe new status.

◆ setValidationMode()

void ValidatingLineEdit::setValidationMode ( ValidationMode mode)

Changes the validation mode to the new mode.

Parameters
modeNew validation mode.

◆ showsStatusTooltip()

bool ValidatingLineEdit::showsStatusTooltip ( ) const

Returns whether or not the tooltip is used to show a reason for input rejection.

Returns
The status.

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