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)
|
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
|
add_library(fglauncher QtLauncher.cxx
|
||||||
QtLauncher.hxx
|
QtLauncher.hxx
|
||||||
|
@ -141,7 +150,8 @@ if (HAVE_QT)
|
||||||
MPServersModel.cpp
|
MPServersModel.cpp
|
||||||
MPServersModel.h
|
MPServersModel.h
|
||||||
${uic_sources}
|
${uic_sources}
|
||||||
${qrc_sources})
|
${qrc_sources}
|
||||||
|
${qml_sources})
|
||||||
|
|
||||||
set_property(TARGET fglauncher PROPERTY AUTOMOC ON)
|
set_property(TARGET fglauncher PROPERTY AUTOMOC ON)
|
||||||
target_link_libraries(fglauncher Qt5::Core Qt5::Widgets Qt5::Network Qt5::Qml SimGearCore)
|
target_link_libraries(fglauncher Qt5::Core Qt5::Widgets Qt5::Network Qt5::Qml SimGearCore)
|
||||||
|
|
|
@ -21,9 +21,13 @@ Section {
|
||||||
label: "Callsign"
|
label: "Callsign"
|
||||||
description: "Enter a callsign you will use online. This is visible to all users and is " +
|
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. " +
|
"how ATC services and other pilots will refer to you. " +
|
||||||
"(Maximum of ten characters permitted)"
|
"(Maximum of seven characters permitted)"
|
||||||
placeholder: "D-FGFS"
|
placeholder: "D-FGFS"
|
||||||
keywords: ["callsign", "handle", "name"]
|
keywords: ["callsign", "handle", "name"]
|
||||||
|
|
||||||
|
// between one and seven alphanumerics, underscores and or hypens
|
||||||
|
// spaces not permitted
|
||||||
|
validation: "[\\w-]{1,7}"
|
||||||
}
|
}
|
||||||
|
|
||||||
Combo {
|
Combo {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QDateTimeEdit>
|
#include <QDateTimeEdit>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QRegularExpressionValidator>
|
||||||
|
|
||||||
#include "LaunchConfig.hxx"
|
#include "LaunchConfig.hxx"
|
||||||
#include "SettingsSection.hxx"
|
#include "SettingsSection.hxx"
|
||||||
|
@ -504,6 +505,11 @@ QString SettingsText::placeholder() const
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SettingsText::validation() const
|
||||||
|
{
|
||||||
|
return m_validation;
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsText::setPlaceholder(QString hold)
|
void SettingsText::setPlaceholder(QString hold)
|
||||||
{
|
{
|
||||||
if (placeholder() == hold)
|
if (placeholder() == hold)
|
||||||
|
@ -516,6 +522,26 @@ void SettingsText::setPlaceholder(QString hold)
|
||||||
emit placeholderChanged(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) :
|
SettingsPath::SettingsPath(QWidget *pr) :
|
||||||
SettingsControl(pr)
|
SettingsControl(pr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -228,6 +228,9 @@ class SettingsText : public SettingsControl
|
||||||
|
|
||||||
Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)
|
Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)
|
||||||
Q_PROPERTY(QString placeholder READ placeholder WRITE setPlaceholder NOTIFY placeholderChanged)
|
Q_PROPERTY(QString placeholder READ placeholder WRITE setPlaceholder NOTIFY placeholderChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(QString validation READ validation WRITE setValidation NOTIFY validationChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SettingsText(QWidget *pr = nullptr);
|
SettingsText(QWidget *pr = nullptr);
|
||||||
|
|
||||||
|
@ -243,19 +246,26 @@ public:
|
||||||
|
|
||||||
QString placeholder() const;
|
QString placeholder() const;
|
||||||
|
|
||||||
|
QString validation() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setValue(QString value);
|
void setValue(QString value);
|
||||||
|
|
||||||
void setPlaceholder(QString placeholder);
|
void setPlaceholder(QString placeholder);
|
||||||
|
|
||||||
|
void setValidation(QString validation);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void valueChanged(QString value);
|
void valueChanged(QString value);
|
||||||
|
|
||||||
void placeholderChanged(QString placeholder);
|
void placeholderChanged(QString placeholder);
|
||||||
|
|
||||||
|
void validationChanged(QString validation);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLineEdit* m_edit;
|
QLineEdit* m_edit;
|
||||||
QLabel* m_label;
|
QLabel* m_label;
|
||||||
|
QString m_validation;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SettingsPath : public SettingsControl
|
class SettingsPath : public SettingsControl
|
||||||
|
|
Loading…
Reference in a new issue