diff --git a/vendor/DOtherSide/lib/CMakeLists.txt b/vendor/DOtherSide/lib/CMakeLists.txt index db2205b5d1..1a81f6b1ac 100644 --- a/vendor/DOtherSide/lib/CMakeLists.txt +++ b/vendor/DOtherSide/lib/CMakeLists.txt @@ -35,7 +35,7 @@ macro(add_target name type) endif() # for DOtherSide.pc - set(PC_REQUIRES "Qt5Core, Qt5Gui, Qt5Widgets, Qt5Qml, Qt5Quick, Qt5Network, Qt5DBus, Qt5Multimedia SortFilterProxyModel") + set(PC_REQUIRES "Qt5Core, Qt5Gui, Qt5Widgets, Qt5Qml, Qt5Quick, Qt5Network, Qt5DBus, Qt5Multimedia, SortFilterProxyModel") if (${Qt5QuickControls2_FOUND}) target_link_libraries(${name} PRIVATE Qt5::QuickControls2) set(PC_REQUIRES "${PC_REQUIRES}, Qt5QuickControls2") diff --git a/vendor/DOtherSide/lib/include/DOtherSide/Status/RXValidator.h b/vendor/DOtherSide/lib/include/DOtherSide/Status/RXValidator.h new file mode 100644 index 0000000000..2cabed2e6a --- /dev/null +++ b/vendor/DOtherSide/lib/include/DOtherSide/Status/RXValidator.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +// A QValidator built around QRegularExpression, but with Unicode support +// (RegularExpressionValidator doesn't expose this to QML) + +class RXValidator : public QValidator +{ + Q_OBJECT + Q_PROPERTY(QRegularExpression regularExpression READ regularExpression WRITE setRegularExpression NOTIFY regularExpressionChanged) + +public: + RXValidator(QObject* parent = nullptr); + + // helper QML function + Q_INVOKABLE bool test(QString input) const; + +protected: + QValidator::State validate(QString &input, int &pos) const override; + +signals: + void regularExpressionChanged(const QRegularExpression &re); + +private: + QRegularExpression regularExpression() const; + void setRegularExpression(const QRegularExpression &re); + + QRegularExpression m_rx; +}; diff --git a/vendor/DOtherSide/lib/src/DOtherSide.cpp b/vendor/DOtherSide/lib/src/DOtherSide.cpp index 3f936d74ab..18d06faf2d 100644 --- a/vendor/DOtherSide/lib/src/DOtherSide.cpp +++ b/vendor/DOtherSide/lib/src/DOtherSide.cpp @@ -72,6 +72,7 @@ #include "DOtherSide/Status/KeychainManager.h" #include "DOtherSide/Status/SoundManager.h" #include "DOtherSide/Status/QClipboardProxy.h" +#include "DOtherSide/Status/RXValidator.h" #include "DOtherSide/DosSpellchecker.h" #include @@ -85,6 +86,7 @@ void register_meta_types() qmlRegisterType("DotherSide", 0 , 1, "StatusSyntaxHighlighter"); qmlRegisterType("DotherSide", 0, 1, "SpellChecker"); qmlRegisterSingletonType("DotherSide", 0 , 1, "QClipboardProxy", &QClipboardProxy::qmlInstance); + qmlRegisterType("DotherSide", 0, 1, "RXValidator"); qqsfpm::registerTypes(); } diff --git a/vendor/DOtherSide/lib/src/Status/RXValidator.cpp b/vendor/DOtherSide/lib/src/Status/RXValidator.cpp new file mode 100644 index 0000000000..b4ce87c777 --- /dev/null +++ b/vendor/DOtherSide/lib/src/Status/RXValidator.cpp @@ -0,0 +1,44 @@ +#include "DOtherSide/Status/RXValidator.h" + +RXValidator::RXValidator(QObject* parent) + : QValidator(parent) +{ +} + +bool RXValidator::test(QString input) const +{ + int dummy_pos = 0; + return validate(input, dummy_pos) == QValidator::Acceptable; +} + +QRegularExpression RXValidator::regularExpression() const +{ + return m_rx; +} + +void RXValidator::setRegularExpression(const QRegularExpression& re) +{ + if (m_rx != re) { + m_rx = re; + m_rx.setPatternOptions(re.patternOptions() | QRegularExpression::UseUnicodePropertiesOption); + m_rx.setPattern(QRegularExpression::anchoredPattern(re.pattern())); + emit regularExpressionChanged(m_rx); + emit changed(); + } +} + +QValidator::State RXValidator::validate(QString& input, int& pos) const +{ + if (m_rx.pattern().isEmpty()) + return Acceptable; + + const QRegularExpressionMatch m = m_rx.match(input, 0, QRegularExpression::PartialPreferCompleteMatch); + if (m.hasMatch()) + return Acceptable; + + if (input.isEmpty() || m.hasPartialMatch()) + return Intermediate; + + pos = input.size(); + return Invalid; +}