Validate MP callsign with a reg-exp
This commit is contained in:
parent
42508619ee
commit
18b8b59af6
4 changed files with 52 additions and 2 deletions
|
@ -81,6 +81,15 @@ if (HAVE_QT)
|
|||
)
|
||||
qt5_add_resources(qrc_sources resources.qrc)
|
||||
|
||||
set(qml_sources
|
||||
DownloadSettings.qml
|
||||
GeneralSettings.qml
|
||||
MPSettings.qml
|
||||
RenderSettings.qml
|
||||
TimeSettings.qml
|
||||
ViewSettings.qml
|
||||
Weather.qml
|
||||
)
|
||||
|
||||
add_library(fglauncher QtLauncher.cxx
|
||||
QtLauncher.hxx
|
||||
|
@ -141,7 +150,8 @@ if (HAVE_QT)
|
|||
MPServersModel.cpp
|
||||
MPServersModel.h
|
||||
${uic_sources}
|
||||
${qrc_sources})
|
||||
${qrc_sources}
|
||||
${qml_sources})
|
||||
|
||||
set_property(TARGET fglauncher PROPERTY AUTOMOC ON)
|
||||
target_link_libraries(fglauncher Qt5::Core Qt5::Widgets Qt5::Network Qt5::Qml SimGearCore)
|
||||
|
|
|
@ -21,9 +21,13 @@ Section {
|
|||
label: "Callsign"
|
||||
description: "Enter a callsign you will use online. This is visible to all users and is " +
|
||||
"how ATC services and other pilots will refer to you. " +
|
||||
"(Maximum of ten characters permitted)"
|
||||
"(Maximum of seven characters permitted)"
|
||||
placeholder: "D-FGFS"
|
||||
keywords: ["callsign", "handle", "name"]
|
||||
|
||||
// between one and seven alphanumerics, underscores and or hypens
|
||||
// spaces not permitted
|
||||
validation: "[\\w-]{1,7}"
|
||||
}
|
||||
|
||||
Combo {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <QQmlContext>
|
||||
#include <QDateTimeEdit>
|
||||
#include <QPainter>
|
||||
#include <QRegularExpressionValidator>
|
||||
|
||||
#include "LaunchConfig.hxx"
|
||||
#include "SettingsSection.hxx"
|
||||
|
@ -504,6 +505,11 @@ QString SettingsText::placeholder() const
|
|||
#endif
|
||||
}
|
||||
|
||||
QString SettingsText::validation() const
|
||||
{
|
||||
return m_validation;
|
||||
}
|
||||
|
||||
void SettingsText::setPlaceholder(QString hold)
|
||||
{
|
||||
if (placeholder() == hold)
|
||||
|
@ -516,6 +522,26 @@ void SettingsText::setPlaceholder(QString hold)
|
|||
emit placeholderChanged(hold);
|
||||
}
|
||||
|
||||
void SettingsText::setValidation(QString validation)
|
||||
{
|
||||
if (m_validation == validation)
|
||||
return;
|
||||
|
||||
m_validation = validation;
|
||||
|
||||
QRegularExpression re(m_validation);
|
||||
if (!re.isValid()) {
|
||||
qWarning() << "invalid validation expression:" << re.errorString();
|
||||
m_validation.clear();
|
||||
validation.clear();
|
||||
m_edit->setValidator(nullptr);
|
||||
} else {
|
||||
m_edit->setValidator(new QRegularExpressionValidator(re, this));
|
||||
}
|
||||
|
||||
emit validationChanged(validation);
|
||||
}
|
||||
|
||||
SettingsPath::SettingsPath(QWidget *pr) :
|
||||
SettingsControl(pr)
|
||||
{
|
||||
|
|
|
@ -228,6 +228,9 @@ class SettingsText : public SettingsControl
|
|||
|
||||
Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)
|
||||
Q_PROPERTY(QString placeholder READ placeholder WRITE setPlaceholder NOTIFY placeholderChanged)
|
||||
|
||||
Q_PROPERTY(QString validation READ validation WRITE setValidation NOTIFY validationChanged)
|
||||
|
||||
public:
|
||||
SettingsText(QWidget *pr = nullptr);
|
||||
|
||||
|
@ -243,19 +246,26 @@ public:
|
|||
|
||||
QString placeholder() const;
|
||||
|
||||
QString validation() const;
|
||||
|
||||
public slots:
|
||||
void setValue(QString value);
|
||||
|
||||
void setPlaceholder(QString placeholder);
|
||||
|
||||
void setValidation(QString validation);
|
||||
|
||||
signals:
|
||||
void valueChanged(QString value);
|
||||
|
||||
void placeholderChanged(QString placeholder);
|
||||
|
||||
void validationChanged(QString validation);
|
||||
|
||||
private:
|
||||
QLineEdit* m_edit;
|
||||
QLabel* m_label;
|
||||
QString m_validation;
|
||||
};
|
||||
|
||||
class SettingsPath : public SettingsControl
|
||||
|
|
Loading…
Reference in a new issue