mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:25:54 +08:00
Ref T265, Ref T430, Ref T473 improved validator for parts
This commit is contained in:
committed by
Mat Sutcliffe
parent
d89b217e9b
commit
6bd3a50ed8
@@ -7,11 +7,13 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "blackmisc/stringutils.h"
|
||||||
#include "blackgui/uppercasevalidator.h"
|
#include "blackgui/uppercasevalidator.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
CUpperCaseValidator::CUpperCaseValidator(QObject *parent) : QValidator(parent)
|
CUpperCaseValidator::CUpperCaseValidator(QObject *parent) : QValidator(parent)
|
||||||
@@ -19,11 +21,15 @@ namespace BlackGui
|
|||||||
|
|
||||||
CUpperCaseValidator::CUpperCaseValidator(int minLength, int maxLength, QObject *parent) : QValidator(parent),
|
CUpperCaseValidator::CUpperCaseValidator(int minLength, int maxLength, QObject *parent) : QValidator(parent),
|
||||||
m_minLength(minLength), m_maxLength(maxLength)
|
m_minLength(minLength), m_maxLength(maxLength)
|
||||||
{ }
|
{
|
||||||
|
if (minLength < 1) { m_optionalValue = true; };
|
||||||
|
}
|
||||||
|
|
||||||
CUpperCaseValidator::CUpperCaseValidator(bool optionalValue, int minLength, int maxLength, QObject *parent) : QValidator(parent),
|
CUpperCaseValidator::CUpperCaseValidator(bool optionalValue, int minLength, int maxLength, QObject *parent) : QValidator(parent),
|
||||||
m_optionalValue(optionalValue), m_minLength(minLength), m_maxLength(maxLength)
|
m_optionalValue(optionalValue), m_minLength(minLength), m_maxLength(maxLength)
|
||||||
{ }
|
{
|
||||||
|
if (minLength < 1) { m_optionalValue = true; };
|
||||||
|
}
|
||||||
|
|
||||||
QValidator::State CUpperCaseValidator::validate(QString &input, int &pos) const
|
QValidator::State CUpperCaseValidator::validate(QString &input, int &pos) const
|
||||||
{
|
{
|
||||||
@@ -54,6 +60,9 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (input.isEmpty()) { return; }
|
if (input.isEmpty()) { return; }
|
||||||
input = input.toUpper();
|
input = input.toUpper();
|
||||||
|
if (!m_allowedCharacters.isEmpty())
|
||||||
|
{
|
||||||
|
input = removeIfNotInString(input, m_allowedCharacters);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ namespace BlackGui
|
|||||||
//! Set restrictions
|
//! Set restrictions
|
||||||
void setRestrictions(const QStringList &restrictions) { m_restrictions = restrictions; }
|
void setRestrictions(const QStringList &restrictions) { m_restrictions = restrictions; }
|
||||||
|
|
||||||
|
//! Allowed characters
|
||||||
|
void setAllowedCharacters(const QString &chars) { m_allowedCharacters = chars.toUpper(); }
|
||||||
|
|
||||||
//! \copydoc QValidator::validate
|
//! \copydoc QValidator::validate
|
||||||
virtual State validate(QString &input, int &pos) const override;
|
virtual State validate(QString &input, int &pos) const override;
|
||||||
|
|
||||||
@@ -46,6 +49,7 @@ namespace BlackGui
|
|||||||
bool m_optionalValue = false; //!< allow empty
|
bool m_optionalValue = false; //!< allow empty
|
||||||
int m_minLength = 0;
|
int m_minLength = 0;
|
||||||
int m_maxLength = 32678; //!< standard length
|
int m_maxLength = 32678; //!< standard length
|
||||||
|
QString m_allowedCharacters; //!< allowedCharacters
|
||||||
QStringList m_restrictions; //!< list of allowed strings
|
QStringList m_restrictions; //!< list of allowed strings
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,18 @@ namespace BlackMisc
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Remove if in string
|
||||||
|
inline QString removeIfInString(const QString &string, const QString &inString)
|
||||||
|
{
|
||||||
|
return removeChars(string.simplified(), [&](QChar c) { return inString.contains(c); });
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Remove if NOT in string
|
||||||
|
inline QString removeIfNotInString(const QString &string, const QString &inString)
|
||||||
|
{
|
||||||
|
return removeChars(string.simplified(), [&](QChar c) { return !inString.contains(c); });
|
||||||
|
}
|
||||||
|
|
||||||
//! Remove line breaks and tabs
|
//! Remove line breaks and tabs
|
||||||
inline QString removeLineBreakAndTab(const QString &s)
|
inline QString removeLineBreakAndTab(const QString &s)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user