Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
qt
qvalidatedlineedit.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-present 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
5
#include <
qt/qvalidatedlineedit.h
>
6
7
#include <
qt/bitcoinaddressvalidator.h
>
8
#include <
qt/guiconstants.h
>
9
10
QValidatedLineEdit::QValidatedLineEdit
(QWidget* parent)
11
: QLineEdit(parent)
12
{
13
connect(
this
, &QValidatedLineEdit::textChanged,
this
, &
QValidatedLineEdit::markValid
);
14
}
15
16
void
QValidatedLineEdit::setText
(
const
QString& text)
17
{
18
QLineEdit::setText(text);
19
checkValidity
();
20
}
21
22
void
QValidatedLineEdit::setValid
(
bool
_valid)
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
40
void
QValidatedLineEdit::focusInEvent
(QFocusEvent *evt)
41
{
42
// Clear invalid flag on focus
43
setValid
(
true
);
44
45
QLineEdit::focusInEvent(evt);
46
}
47
48
void
QValidatedLineEdit::focusOutEvent
(QFocusEvent *evt)
49
{
50
checkValidity
();
51
52
QLineEdit::focusOutEvent(evt);
53
}
54
55
void
QValidatedLineEdit::markValid
()
56
{
57
// As long as a user is typing ensure we display state as valid
58
setValid
(
true
);
59
}
60
61
void
QValidatedLineEdit::clear
()
62
{
63
setValid
(
true
);
64
QLineEdit::clear();
65
}
66
67
void
QValidatedLineEdit::setEnabled
(
bool
enabled)
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
77
checkValidity
();
78
}
79
80
QLineEdit::setEnabled(enabled);
81
}
82
83
void
QValidatedLineEdit::checkValidity
()
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
94
if
(
checkValidator
)
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
110
void
QValidatedLineEdit::setCheckValidator
(
const
QValidator *v)
111
{
112
checkValidator
= v;
113
checkValidity
();
114
}
115
116
bool
QValidatedLineEdit::isValid
()
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
}
bitcoinaddressvalidator.h
QValidatedLineEdit::setText
void setText(const QString &)
Definition
qvalidatedlineedit.cpp:16
QValidatedLineEdit::markValid
void markValid()
Definition
qvalidatedlineedit.cpp:55
QValidatedLineEdit::QValidatedLineEdit
QValidatedLineEdit(QWidget *parent)
Definition
qvalidatedlineedit.cpp:10
QValidatedLineEdit::valid
bool valid
Definition
qvalidatedlineedit.h:28
QValidatedLineEdit::isValid
bool isValid()
Definition
qvalidatedlineedit.cpp:116
QValidatedLineEdit::validationDidChange
void validationDidChange(QValidatedLineEdit *validatedLineEdit)
QValidatedLineEdit::checkValidity
void checkValidity()
Definition
qvalidatedlineedit.cpp:83
QValidatedLineEdit::focusOutEvent
void focusOutEvent(QFocusEvent *evt) override
Definition
qvalidatedlineedit.cpp:48
QValidatedLineEdit::setValid
void setValid(bool valid)
Definition
qvalidatedlineedit.cpp:22
QValidatedLineEdit::focusInEvent
void focusInEvent(QFocusEvent *evt) override
Definition
qvalidatedlineedit.cpp:40
QValidatedLineEdit::clear
void clear()
Definition
qvalidatedlineedit.cpp:61
QValidatedLineEdit::setEnabled
void setEnabled(bool enabled)
Definition
qvalidatedlineedit.cpp:67
QValidatedLineEdit::setCheckValidator
void setCheckValidator(const QValidator *v)
Definition
qvalidatedlineedit.cpp:110
QValidatedLineEdit::checkValidator
const QValidator * checkValidator
Definition
qvalidatedlineedit.h:29
guiconstants.h
STYLE_INVALID
#define STYLE_INVALID
Definition
guiconstants.h:28
qvalidatedlineedit.h
Generated on
for Bitcoin Core by
1.17.0