From e1a5fd4e2df606b71ff24b56a11d5a609e7644a8 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Mon, 24 Mar 2025 14:28:33 +0100 Subject: [PATCH] refactor: Simplify upper case validator --- src/gui/components/flightplancomponent.cpp | 6 ------ src/gui/eventfilter.cpp | 10 +++------- src/gui/eventfilter.h | 12 +----------- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/gui/components/flightplancomponent.cpp b/src/gui/components/flightplancomponent.cpp index 5da34b79d..670929d55 100644 --- a/src/gui/components/flightplancomponent.cpp +++ b/src/gui/components/flightplancomponent.cpp @@ -108,17 +108,11 @@ namespace swift::gui::components ui->le_SsrEquipment->setReadOnly(true); CUpperCaseEventFilter *ef = new CUpperCaseEventFilter(ui->pte_Route); - ef->setOnlyAscii(); ui->pte_Route->installEventFilter(ef); ef = new CUpperCaseEventFilter(ui->pte_Remarks); - ef->setOnlyAscii(); ui->pte_Remarks->installEventFilter(ef); ef = new CUpperCaseEventFilter(ui->pte_AdditionalRemarks); - ef->setOnlyAscii(); ui->pte_AdditionalRemarks->installEventFilter(ef); - // readonly - // ef = new CUpperCaseEventFilter(ui->pte_RemarksGenerated); - // ui->pte_RemarksGenerated->installEventFilter(ef); // connect connect(ui->pb_Send, &QPushButton::pressed, this, &CFlightPlanComponent::sendFlightPlan, Qt::QueuedConnection); diff --git a/src/gui/eventfilter.cpp b/src/gui/eventfilter.cpp index 2ca08cd12..a0858ac2f 100644 --- a/src/gui/eventfilter.cpp +++ b/src/gui/eventfilter.cpp @@ -27,21 +27,17 @@ namespace swift::gui if (e->text().length() == 1) { const QChar c = e->text().front(); - if (m_illegalChars.contains(c)) { return true; } if (c.isLetter()) { const ushort unicode = c.unicode(); - if (m_onlyAscii && unicode > 127) { return true; } + if (unicode > 127) { return true; } pte->insertPlainText(e->text().toUpper()); // return true to prevent further processing return true; } - else - { - // all codes like backspace etc. - return false; - } + // all codes like backspace etc. + return false; } // length } // key event } diff --git a/src/gui/eventfilter.h b/src/gui/eventfilter.h index d33b4dc57..5afea6d20 100644 --- a/src/gui/eventfilter.h +++ b/src/gui/eventfilter.h @@ -19,19 +19,9 @@ namespace swift::gui //! \copydoc QObject::QObject using QObject::QObject; - //! Not allowed characters - void setIllegalCharacters(const QString &illegal) { m_illegalChars = illegal; } - - //! Allow only ASCII - void setOnlyAscii() { m_onlyAscii = true; } - protected: //! Filter - virtual bool eventFilter(QObject *object, QEvent *event) override; - - private: - QString m_illegalChars; - bool m_onlyAscii = false; + bool eventFilter(QObject *object, QEvent *event) override; }; } // namespace swift::gui