mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +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 (input.length() > m_maxLength) { return Invalid; }
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,9 @@
|
||||
#define BLACKGUI_UPPERCASEVALIDATOR_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QValidator>
|
||||
|
||||
class QObject;
|
||||
class QString;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
//! Forces uppercase
|
||||
@@ -35,6 +32,9 @@ namespace BlackGui
|
||||
//! Constructor
|
||||
CUpperCaseValidator(bool optionalValue, int minLength, int maxLength, QObject *parent = nullptr);
|
||||
|
||||
//! Set restrictions
|
||||
void setRestrictions(const QStringList &restrictions) { m_restrictions = restrictions; }
|
||||
|
||||
//! \copydoc QValidator::validate
|
||||
virtual State validate(QString &input, int &pos) const override;
|
||||
|
||||
@@ -42,10 +42,10 @@ namespace BlackGui
|
||||
virtual void fixup(QString &input) const override;
|
||||
|
||||
private:
|
||||
bool m_optionalValue = false;
|
||||
bool m_optionalValue = false; //!< allow empty
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user