Limo
A simple mod manager
Loading...
Searching...
No Matches
validatinglineedit.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <QLineEdit>
9
14class ValidatingLineEdit : public QLineEdit
15{
16 Q_OBJECT
17public:
34
40 ValidatingLineEdit(QWidget* parent = nullptr, ValidationMode mode = VALID_NOT_EMPTY);
47 ValidatingLineEdit(const QString& contents,
48 QWidget* parent = nullptr,
50
55 bool hasValidText();
67 void setCustomValidator(std::function<bool(QString)> validator);
69 void updateValidation();
74 bool acceptsEmptyPaths() const;
79 void setAcceptsEmptyPaths(bool accept);
84 bool showsStatusTooltip() const;
89 void setShowStatusTooltip(bool show);
90
91private:
97 std::function<bool(QString)> validator_ = [](QString s) { return true; };
99 bool accept_empty_paths_ = false;
102
103private slots:
108 void onTextChanged(const QString& new_text);
109};
bool showsStatusTooltip() const
Returns whether or not the tooltip is used to show a reason for input rejection.
Definition validatinglineedit.cpp:71
ValidationMode validation_mode_
Determines how the input text is validated, see ValidationMode modes.
Definition validatinglineedit.h:93
void updateValidation()
Updates the visual indicator using the current text.
Definition validatinglineedit.cpp:55
void setValidationMode(ValidationMode mode)
Changes the validation mode to the new mode.
Definition validatinglineedit.cpp:44
bool acceptsEmptyPaths() const
Returns whether or not an empty path will be accepted.
Definition validatinglineedit.cpp:60
bool hasValidText()
Checks if the current text is valid.
Definition validatinglineedit.cpp:23
void setCustomValidator(std::function< bool(QString)> validator)
Sets a new custom validator function. Does not affect validation mode.
Definition validatinglineedit.cpp:50
ValidationMode
Type of validation to be applied.
Definition validatinglineedit.h:20
@ VALID_PATH_EXISTS
Requires text to be a path to an existing file or directory.
Definition validatinglineedit.h:26
@ VALID_NOT_EMPTY
Requires text to not be an empty string.
Definition validatinglineedit.h:24
@ VALID_IS_EXISTING_DIRECTORY
Requires text to be a path to an existing directory.
Definition validatinglineedit.h:32
@ VALID_IS_EXISTING_FILE
Requires text to be a path to an existing file.
Definition validatinglineedit.h:30
@ VALID_NONE
All text is valid.
Definition validatinglineedit.h:22
@ VALID_CUSTOM
Uses a custom validation function.
Definition validatinglineedit.h:28
void onTextChanged(const QString &new_text)
Connected to this line edits textChanged signal. Updates the visual indicator.
Definition validatinglineedit.cpp:81
void setAcceptsEmptyPaths(bool accept)
Sets whether or not an empty path will be accepted.
Definition validatinglineedit.cpp:65
bool show_status_tooltip_
If true: Use the tooltip to display a reason for input rejection.
Definition validatinglineedit.h:101
std::function< bool(QString)> validator_
If the validation mode is set to VALID_CUSTOM, this function will be called and be passed the current...
Definition validatinglineedit.h:97
ValidatingLineEdit(QWidget *parent=nullptr, ValidationMode mode=VALID_NOT_EMPTY)
Calls QLineEdit constructor and sets the validation mode.
Definition validatinglineedit.cpp:7
void setShowStatusTooltip(bool show)
Sets whether or not the tooltip is used to show a reason for input rejection.
Definition validatinglineedit.cpp:76
bool accept_empty_paths_
If true: Empty paths will be accepted in VALID_PATH_EXISTS.
Definition validatinglineedit.h:99