Bitcoin Core 28.99.0
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages Concepts
qvalidatedlineedit.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
8#include <qt/guiconstants.h>
9
11 : QLineEdit(parent)
12{
13 connect(this, &QValidatedLineEdit::textChanged, this, &QValidatedLineEdit::markValid);
14}
15
16void QValidatedLineEdit::setText(const QString& text)
17{
18 QLineEdit::setText(text);
20}
21
23{
24 if(_valid == this->valid)
25 {
26 return;
27 }
28
29 if(_valid)
30 {
31 setStyleSheet("");
32 }
33 else
34 {
35 setStyleSheet("QValidatedLineEdit { " STYLE_INVALID "}");
36 }
37 this->valid = _valid;
38}
39
41{
42 // Clear invalid flag on focus
43 setValid(true);
44
45 QLineEdit::focusInEvent(evt);
46}
47
49{
51
52 QLineEdit::focusOutEvent(evt);
53}
54
56{
57 // As long as a user is typing ensure we display state as valid
58 setValid(true);
59}
60
62{
63 setValid(true);
64 QLineEdit::clear();
65}
66
68{
69 if (!enabled)
70 {
71 // A disabled QValidatedLineEdit should be marked valid
72 setValid(true);
73 }
74 else
75 {
76 // Recheck validity when QValidatedLineEdit gets enabled
78 }
79
80 QLineEdit::setEnabled(enabled);
81}
82
84{
85 if (text().isEmpty())
86 {
87 setValid(true);
88 }
89 else if (hasAcceptableInput())
90 {
91 setValid(true);
92
93 // Check contents on focus out
95 {
96 QString address = text();
97 int pos = 0;
98 if (checkValidator->validate(address, pos) == QValidator::Acceptable)
99 setValid(true);
100 else
101 setValid(false);
102 }
103 }
104 else
105 setValid(false);
106
107 Q_EMIT validationDidChange(this);
108}
109
111{
112 checkValidator = v;
114}
115
117{
118 // use checkValidator in case the QValidatedLineEdit is disabled
119 if (checkValidator)
120 {
121 QString address = text();
122 int pos = 0;
123 if (checkValidator->validate(address, pos) == QValidator::Acceptable)
124 return true;
125 }
126
127 return valid;
128}
void setText(const QString &)
QValidatedLineEdit(QWidget *parent)
void validationDidChange(QValidatedLineEdit *validatedLineEdit)
void focusOutEvent(QFocusEvent *evt) override
void setValid(bool valid)
void focusInEvent(QFocusEvent *evt) override
void setEnabled(bool enabled)
void setCheckValidator(const QValidator *v)
const QValidator * checkValidator
#define STYLE_INVALID
Definition: guiconstants.h:28