mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-24 09:54:16 +08:00
Ref T215, validator can be restricted to a string list
This commit is contained in:
@@ -34,6 +34,19 @@ namespace BlackGui
|
|||||||
if (m_optionalValue && input.isEmpty()) { return Acceptable; }
|
if (m_optionalValue && input.isEmpty()) { return Acceptable; }
|
||||||
if (input.length() > m_maxLength) { return Invalid; }
|
if (input.length() > m_maxLength) { return Invalid; }
|
||||||
if (input.length() < m_minLength) { return Intermediate; }
|
if (input.length() < m_minLength) { return Intermediate; }
|
||||||
|
if (!m_restrictions.isEmpty())
|
||||||
|
{
|
||||||
|
bool valid = false;
|
||||||
|
for (const QString &r : m_restrictions)
|
||||||
|
{
|
||||||
|
if (r.startsWith(input))
|
||||||
|
{
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!valid) { return Invalid; }
|
||||||
|
}
|
||||||
return Acceptable;
|
return Acceptable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,9 @@
|
|||||||
#define BLACKGUI_UPPERCASEVALIDATOR_H
|
#define BLACKGUI_UPPERCASEVALIDATOR_H
|
||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
|
#include <QStringList>
|
||||||
#include <QValidator>
|
#include <QValidator>
|
||||||
|
|
||||||
class QObject;
|
|
||||||
class QString;
|
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
//! Forces uppercase
|
//! Forces uppercase
|
||||||
@@ -35,6 +32,9 @@ namespace BlackGui
|
|||||||
//! Constructor
|
//! Constructor
|
||||||
CUpperCaseValidator(bool optionalValue, int minLength, int maxLength, QObject *parent = nullptr);
|
CUpperCaseValidator(bool optionalValue, int minLength, int maxLength, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
//! Set restrictions
|
||||||
|
void setRestrictions(const QStringList &restrictions) { m_restrictions = restrictions; }
|
||||||
|
|
||||||
//! \copydoc QValidator::validate
|
//! \copydoc QValidator::validate
|
||||||
virtual State validate(QString &input, int &pos) const override;
|
virtual State validate(QString &input, int &pos) const override;
|
||||||
|
|
||||||
@@ -42,10 +42,10 @@ namespace BlackGui
|
|||||||
virtual void fixup(QString &input) const override;
|
virtual void fixup(QString &input) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_optionalValue = false;
|
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
|
||||||
|
QStringList m_restrictions; //!< list of allowed strings
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user