Add const to methods that do not modify the object for which it is called
[bitcoinplatinum.git] / src / qt / qvalidatedlineedit.cpp
blob179ecdc8b3835371a91ceaf645dc3c0fb388c914
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.
5 #include "qvalidatedlineedit.h"
7 #include "bitcoinaddressvalidator.h"
8 #include "guiconstants.h"
10 QValidatedLineEdit::QValidatedLineEdit(QWidget *parent) :
11 QLineEdit(parent),
12 valid(true),
13 checkValidator(0)
15 connect(this, SIGNAL(textChanged(QString)), this, SLOT(markValid()));
18 void QValidatedLineEdit::setValid(bool _valid)
20 if(_valid == this->valid)
22 return;
25 if(_valid)
27 setStyleSheet("");
29 else
31 setStyleSheet(STYLE_INVALID);
33 this->valid = _valid;
36 void QValidatedLineEdit::focusInEvent(QFocusEvent *evt)
38 // Clear invalid flag on focus
39 setValid(true);
41 QLineEdit::focusInEvent(evt);
44 void QValidatedLineEdit::focusOutEvent(QFocusEvent *evt)
46 checkValidity();
48 QLineEdit::focusOutEvent(evt);
51 void QValidatedLineEdit::markValid()
53 // As long as a user is typing ensure we display state as valid
54 setValid(true);
57 void QValidatedLineEdit::clear()
59 setValid(true);
60 QLineEdit::clear();
63 void QValidatedLineEdit::setEnabled(bool enabled)
65 if (!enabled)
67 // A disabled QValidatedLineEdit should be marked valid
68 setValid(true);
70 else
72 // Recheck validity when QValidatedLineEdit gets enabled
73 checkValidity();
76 QLineEdit::setEnabled(enabled);
79 void QValidatedLineEdit::checkValidity()
81 if (text().isEmpty())
83 setValid(true);
85 else if (hasAcceptableInput())
87 setValid(true);
89 // Check contents on focus out
90 if (checkValidator)
92 QString address = text();
93 int pos = 0;
94 if (checkValidator->validate(address, pos) == QValidator::Acceptable)
95 setValid(true);
96 else
97 setValid(false);
100 else
101 setValid(false);
103 Q_EMIT validationDidChange(this);
106 void QValidatedLineEdit::setCheckValidator(const QValidator *v)
108 checkValidator = v;
111 bool QValidatedLineEdit::isValid()
113 // use checkValidator in case the QValidatedLineEdit is disabled
114 if (checkValidator)
116 QString address = text();
117 int pos = 0;
118 if (checkValidator->validate(address, pos) == QValidator::Acceptable)
119 return true;
122 return valid;