Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
6
8#include <qt/guiconstants.h>
9
11 : QLineEdit(parent), valid(true), checkValidator(nullptr) {
12 connect(this, &QValidatedLineEdit::textChanged, this,
14}
15
17 if (_valid == this->valid) {
18 return;
19 }
20
21 if (_valid) {
22 setStyleSheet("");
23 } else {
25 }
26 this->valid = _valid;
27
29}
30
32 // Clear invalid flag on focus
33 setValid(true);
34
35 QLineEdit::focusInEvent(evt);
36}
37
40
41 QLineEdit::focusOutEvent(evt);
42}
43
45 // As long as a user is typing ensure we display state as valid
46 setValid(true);
47}
48
50 setValid(true);
51 QLineEdit::clear();
52}
53
55 if (!enabled) {
56 // A disabled QValidatedLineEdit should be marked valid
57 setValid(true);
58 } else {
59 // Recheck validity when QValidatedLineEdit gets enabled
61 }
62
63 QLineEdit::setEnabled(enabled);
64}
65
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
88void QValidatedLineEdit::setCheckValidator(const QValidator *v) {
90}
91
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}
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
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