Bitcoin Core 22.99.0
P2P Digital Currency
qvalidatedlineedit.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2018 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 valid(true),
13 checkValidator(nullptr)
14{
15 connect(this, &QValidatedLineEdit::textChanged, this, &QValidatedLineEdit::markValid);
16}
17
19{
20 if(_valid == this->valid)
21 {
22 return;
23 }
24
25 if(_valid)
26 {
27 setStyleSheet("");
28 }
29 else
30 {
31 setStyleSheet(STYLE_INVALID);
32 }
33 this->valid = _valid;
34}
35
37{
38 // Clear invalid flag on focus
39 setValid(true);
40
41 QLineEdit::focusInEvent(evt);
42}
43
45{
47
48 QLineEdit::focusOutEvent(evt);
49}
50
52{
53 // As long as a user is typing ensure we display state as valid
54 setValid(true);
55}
56
58{
59 setValid(true);
60 QLineEdit::clear();
61}
62
64{
65 if (!enabled)
66 {
67 // A disabled QValidatedLineEdit should be marked valid
68 setValid(true);
69 }
70 else
71 {
72 // Recheck validity when QValidatedLineEdit gets enabled
74 }
75
76 QLineEdit::setEnabled(enabled);
77}
78
80{
81 if (text().isEmpty())
82 {
83 setValid(true);
84 }
85 else if (hasAcceptableInput())
86 {
87 setValid(true);
88
89 // Check contents on focus out
91 {
92 QString address = text();
93 int pos = 0;
94 if (checkValidator->validate(address, pos) == QValidator::Acceptable)
95 setValid(true);
96 else
97 setValid(false);
98 }
99 }
100 else
101 setValid(false);
102
103 Q_EMIT validationDidChange(this);
104}
105
107{
108 checkValidator = v;
109}
110
112{
113 // use checkValidator in case the QValidatedLineEdit is disabled
114 if (checkValidator)
115 {
116 QString address = text();
117 int pos = 0;
118 if (checkValidator->validate(address, pos) == QValidator::Acceptable)
119 return true;
120 }
121
122 return valid;
123}
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:22