LCOV - code coverage report
Current view: top level - src/qt - qvalidatedlineedit.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 65 0.0 %
Date: 2020-09-26 01:30:44 Functions: 0 11 0.0 %

          Line data    Source code
       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             : 
       5             : #include <qt/qvalidatedlineedit.h>
       6             : 
       7             : #include <qt/bitcoinaddressvalidator.h>
       8             : #include <qt/guiconstants.h>
       9             : 
      10           0 : QValidatedLineEdit::QValidatedLineEdit(QWidget *parent) :
      11           0 :     QLineEdit(parent),
      12           0 :     valid(true),
      13           0 :     checkValidator(nullptr)
      14           0 : {
      15           0 :     connect(this, &QValidatedLineEdit::textChanged, this, &QValidatedLineEdit::markValid);
      16           0 : }
      17             : 
      18           0 : void QValidatedLineEdit::setValid(bool _valid)
      19             : {
      20           0 :     if(_valid == this->valid)
      21             :     {
      22             :         return;
      23             :     }
      24             : 
      25           0 :     if(_valid)
      26             :     {
      27           0 :         setStyleSheet("");
      28           0 :     }
      29             :     else
      30             :     {
      31           0 :         setStyleSheet(STYLE_INVALID);
      32             :     }
      33           0 :     this->valid = _valid;
      34           0 : }
      35             : 
      36           0 : void QValidatedLineEdit::focusInEvent(QFocusEvent *evt)
      37             : {
      38             :     // Clear invalid flag on focus
      39           0 :     setValid(true);
      40             : 
      41           0 :     QLineEdit::focusInEvent(evt);
      42           0 : }
      43             : 
      44           0 : void QValidatedLineEdit::focusOutEvent(QFocusEvent *evt)
      45             : {
      46           0 :     checkValidity();
      47             : 
      48           0 :     QLineEdit::focusOutEvent(evt);
      49           0 : }
      50             : 
      51           0 : void QValidatedLineEdit::markValid()
      52             : {
      53             :     // As long as a user is typing ensure we display state as valid
      54           0 :     setValid(true);
      55           0 : }
      56             : 
      57           0 : void QValidatedLineEdit::clear()
      58             : {
      59           0 :     setValid(true);
      60           0 :     QLineEdit::clear();
      61           0 : }
      62             : 
      63           0 : void QValidatedLineEdit::setEnabled(bool enabled)
      64             : {
      65           0 :     if (!enabled)
      66             :     {
      67             :         // A disabled QValidatedLineEdit should be marked valid
      68           0 :         setValid(true);
      69           0 :     }
      70             :     else
      71             :     {
      72             :         // Recheck validity when QValidatedLineEdit gets enabled
      73           0 :         checkValidity();
      74             :     }
      75             : 
      76           0 :     QLineEdit::setEnabled(enabled);
      77           0 : }
      78             : 
      79           0 : void QValidatedLineEdit::checkValidity()
      80             : {
      81           0 :     if (text().isEmpty())
      82             :     {
      83           0 :         setValid(true);
      84           0 :     }
      85           0 :     else if (hasAcceptableInput())
      86             :     {
      87           0 :         setValid(true);
      88             : 
      89             :         // Check contents on focus out
      90           0 :         if (checkValidator)
      91             :         {
      92           0 :             QString address = text();
      93           0 :             int pos = 0;
      94           0 :             if (checkValidator->validate(address, pos) == QValidator::Acceptable)
      95           0 :                 setValid(true);
      96             :             else
      97           0 :                 setValid(false);
      98           0 :         }
      99             :     }
     100             :     else
     101           0 :         setValid(false);
     102             : 
     103           0 :     Q_EMIT validationDidChange(this);
     104           0 : }
     105             : 
     106           0 : void QValidatedLineEdit::setCheckValidator(const QValidator *v)
     107             : {
     108           0 :     checkValidator = v;
     109           0 : }
     110             : 
     111           0 : bool QValidatedLineEdit::isValid()
     112             : {
     113             :     // use checkValidator in case the QValidatedLineEdit is disabled
     114           0 :     if (checkValidator)
     115             :     {
     116           0 :         QString address = text();
     117           0 :         int pos = 0;
     118           0 :         if (checkValidator->validate(address, pos) == QValidator::Acceptable)
     119           0 :             return true;
     120           0 :     }
     121             : 
     122           0 :     return valid;
     123           0 : }

Generated by: LCOV version 1.15