refs #288, validator for upper case inputs such as callsign, ICAO data

This commit is contained in:
Klaus Basan
2014-11-15 01:32:01 +01:00
committed by Roland Winklmeier
parent 44d0cd002b
commit dae22f5a3f
2 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "uppercasevalidator.h"
namespace BlackGui
{
CUpperCaseValidator::CUpperCaseValidator(QObject *parent) : QValidator(parent)
{ }
CUpperCaseValidator::CUpperCaseValidator(int minLength, int maxLength, QObject *parent) : QValidator(parent),
m_minLength(minLength), m_maxLength(maxLength)
{ }
CUpperCaseValidator::CUpperCaseValidator(bool optionalValue, int minLength, int maxLength, QObject *parent) : QValidator(parent),
m_minLength(minLength), m_maxLength(maxLength), m_optionalValue(optionalValue)
{ }
QValidator::State CUpperCaseValidator::validate(QString &input, int &pos) const
{
Q_UNUSED(input);
Q_UNUSED(pos);
fixup(input);
if (m_optionalValue && input.isEmpty()) { return Acceptable; }
if (input.length() > m_maxLength) { return Invalid; }
if (input.length() < m_minLength) { return Intermediate; }
return Acceptable;
}
void CUpperCaseValidator::fixup(QString &input) const
{
if (input.isEmpty()) { return; }
input = input.toUpper();
}
} // namespace

View File

@@ -0,0 +1,46 @@
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_UPPERCASEVALIDATOR_H
#define BLACKGUI_UPPERCASEVALIDATOR_H
#include <QValidator>
namespace BlackGui
{
//! Forces uppercase
class CUpperCaseValidator : public QValidator
{
public:
//! Constructor
explicit CUpperCaseValidator(QObject *parent = nullptr);
//! Constructor
CUpperCaseValidator(int minLength, int maxLength, QObject *parent = nullptr);
//! Constructor
CUpperCaseValidator(bool optionalValue, int minLength, int maxLength, QObject *parent = nullptr);
//! \copydoc QValidator::validate
virtual State validate(QString &input, int &pos) const override;
//! \copydoc QValidator::fixup
virtual void fixup(QString &input) const override;
private:
bool m_optionalValue = false;
int m_minLength = 0;
int m_maxLength = 32678; // standard length
};
}
#endif // guard