Bitcoin ABC
0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
src
qt
qvalidatedlineedit.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-2016 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), valid(
true
), checkValidator(
nullptr
) {
12
connect
(
this
, &QValidatedLineEdit::textChanged,
this
,
13
&
QValidatedLineEdit::markValid
);
14
}
15
16
void
QValidatedLineEdit::setValid
(
bool
_valid
) {
17
if
(
_valid
== this->
valid
) {
18
return
;
19
}
20
21
if
(_valid) {
22
setStyleSheet
(
""
);
23
}
else
{
24
setStyleSheet
(
STYLE_INVALID
);
25
}
26
this->
valid
=
_valid
;
27
28
Q_EMIT
validationDidChange
(
this
);
29
}
30
31
void
QValidatedLineEdit::focusInEvent
(
QFocusEvent
*
evt
) {
32
// Clear invalid flag on focus
33
setValid
(
true
);
34
35
QLineEdit::focusInEvent(
evt
);
36
}
37
38
void
QValidatedLineEdit::focusOutEvent
(
QFocusEvent
*
evt
) {
39
checkValidity
();
40
41
QLineEdit::focusOutEvent(
evt
);
42
}
43
44
void
QValidatedLineEdit::markValid
() {
45
// As long as a user is typing ensure we display state as valid
46
setValid
(
true
);
47
}
48
49
void
QValidatedLineEdit::clear
() {
50
setValid
(
true
);
51
QLineEdit::clear();
52
}
53
54
void
QValidatedLineEdit::setEnabled
(
bool
enabled) {
55
if
(!enabled) {
56
// A disabled QValidatedLineEdit should be marked valid
57
setValid
(
true
);
58
}
else
{
59
// Recheck validity when QValidatedLineEdit gets enabled
60
checkValidity
();
61
}
62
63
QLineEdit::setEnabled(enabled);
64
}
65
66
void
QValidatedLineEdit::checkValidity
() {
67
if
(text().isEmpty()) {
68
setValid
(
true
);
69
}
else
if
(
hasAcceptableInput
()) {
70
setValid
(
true
);
71
72
// Check contents on focus out
73
if
(
checkValidator
) {
74
QString
address = text();
75
int
pos = 0;
76
if
(
checkValidator
->validate(address, pos) ==
77
QValidator::Acceptable) {
78
setValid
(
true
);
79
}
else
{
80
setValid
(
false
);
81
}
82
}
83
}
else
{
84
setValid
(
false
);
85
}
86
}
87
88
void
QValidatedLineEdit::setCheckValidator
(
const
QValidator *v) {
89
checkValidator
= v;
90
}
91
92
bool
QValidatedLineEdit::isValid
() {
93
// use checkValidator in case the QValidatedLineEdit is disabled
94
if
(
checkValidator
) {
95
QString
address = text();
96
int
pos = 0;
97
if
(
checkValidator
->validate(address, pos) == QValidator::Acceptable) {
98
return
true
;
99
}
100
}
101
102
return
valid
;
103
}
bitcoinaddressvalidator.h
QValidatedLineEdit::markValid
void markValid()
Definition
qvalidatedlineedit.cpp:44
QValidatedLineEdit::QValidatedLineEdit
QValidatedLineEdit(QWidget *parent)
Definition
qvalidatedlineedit.cpp:10
QValidatedLineEdit::valid
bool valid
Definition
qvalidatedlineedit.h:28
QValidatedLineEdit::isValid
bool isValid()
Definition
qvalidatedlineedit.cpp:92
QValidatedLineEdit::validationDidChange
void validationDidChange(QValidatedLineEdit *validatedLineEdit)
QValidatedLineEdit::checkValidity
void checkValidity()
Definition
qvalidatedlineedit.cpp:66
QValidatedLineEdit::focusOutEvent
void focusOutEvent(QFocusEvent *evt) override
Definition
qvalidatedlineedit.cpp:38
QValidatedLineEdit::setValid
void setValid(bool valid)
Definition
qvalidatedlineedit.cpp:16
QValidatedLineEdit::focusInEvent
void focusInEvent(QFocusEvent *evt) override
Definition
qvalidatedlineedit.cpp:31
QValidatedLineEdit::clear
void clear()
Definition
qvalidatedlineedit.cpp:49
QValidatedLineEdit::setEnabled
void setEnabled(bool enabled)
Definition
qvalidatedlineedit.cpp:54
QValidatedLineEdit::setCheckValidator
void setCheckValidator(const QValidator *v)
Definition
qvalidatedlineedit.cpp:88
QValidatedLineEdit::checkValidator
const QValidator * checkValidator
Definition
qvalidatedlineedit.h:29
guiconstants.h
STYLE_INVALID
#define STYLE_INVALID
Definition
guiconstants.h:22
qvalidatedlineedit.h
GetRand
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition
random.h:85
Generated on Thu Dec 26 2024 02:38:04 for Bitcoin ABC by
1.9.8