diff --git a/Configuration.cpp b/Configuration.cpp index bb7efdf12..79ee5c353 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -60,6 +60,8 @@ namespace // disabled int const combo_box_item_enabled (32 | 1); int const combo_box_item_disabled (0); + + QRegExp message_alphabet {"[- A-Za-z0-9+./?]*"}; } @@ -165,6 +167,32 @@ public: }; +// Class MessageItemDelegate +// +// Item delegate for message entry such as free text message macros. +// +class MessageItemDelegate final + : public QStyledItemDelegate +{ +public: + explicit MessageItemDelegate (QObject * parent = nullptr) + : QStyledItemDelegate {parent} + { + } + + QWidget * createEditor (QWidget * parent + , QStyleOptionViewItem const& /* option*/ + , QModelIndex const& /* index */ + ) const override + { + auto editor = new QLineEdit {parent}; + editor->setFrame (false); + editor->setValidator (new QRegExpValidator {message_alphabet, editor}); + return editor; + } +}; + + // Fields that are transceiver related. // // These are aggregated in a structure to enable a non-equivalence to @@ -682,7 +710,7 @@ Configuration::impl::impl (Configuration * self, QString const& instance_key, QS // ui_->callsign_line_edit->setValidator (new QRegExpValidator {QRegExp {"[A-Za-z0-9/]+"}, this}); ui_->grid_line_edit->setValidator (new QRegExpValidator {QRegExp {"[A-Ra-r]{2,2}[0-9]{2,2}[A-Xa-x]{0,2}"}, this}); - ui_->add_macro_line_edit->setValidator (new QRegExpValidator {QRegExp {"[ A-Za-z0-9/?]+"}, this}); + ui_->add_macro_line_edit->setValidator (new QRegExpValidator {message_alphabet, this}); // // assign ids to radio buttons @@ -736,6 +764,7 @@ Configuration::impl::impl (Configuration * self, QString const& instance_key, QS // setup macros list view // ui_->macros_list_view->setModel (&next_macros_); + ui_->macros_list_view->setItemDelegate (new MessageItemDelegate {this}); macro_delete_action_ = new QAction {tr ("&Delete"), ui_->macros_list_view}; ui_->macros_list_view->insertAction (nullptr, macro_delete_action_); diff --git a/FrequencyItemDelegate.hpp b/FrequencyItemDelegate.hpp index 5d35a9a0a..55ec3b099 100644 --- a/FrequencyItemDelegate.hpp +++ b/FrequencyItemDelegate.hpp @@ -3,9 +3,6 @@ #include -class QStyleOptionItemView; -class QWidget; -class QModelIndex; class Bands; // diff --git a/mainwindow.cpp b/mainwindow.cpp index 9b035bdad..69e217c4d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,7 +7,8 @@ #include #include -#include +#include +#include #include #include @@ -42,6 +43,7 @@ wchar_t buffer[256]; namespace { Radio::Frequency constexpr default_frequency {14076000}; + QRegExp message_alphabet {"[- A-Za-z0-9+./?]*"}; } class BandAndFrequencyItemDelegate final @@ -239,6 +241,15 @@ MainWindow::MainWindow(bool multiple, QSettings * settings, QSharedMemory *shdme connect (&m_config, &Configuration::transceiver_update, this, &MainWindow::handle_transceiver_update); connect (&m_config, &Configuration::transceiver_failure, this, &MainWindow::handle_transceiver_failure); + // set up message text validators + ui->tx1->setValidator (new QRegExpValidator {message_alphabet, this}); + ui->tx2->setValidator (new QRegExpValidator {message_alphabet, this}); + ui->tx3->setValidator (new QRegExpValidator {message_alphabet, this}); + ui->tx4->setValidator (new QRegExpValidator {message_alphabet, this}); + ui->tx5->setValidator (new QRegExpValidator {message_alphabet, this}); + ui->tx6->setValidator (new QRegExpValidator {message_alphabet, this}); + ui->freeTextMsg->setValidator (new QRegExpValidator {message_alphabet, this}); + // Free text macros model to widget hook up. ui->tx5->setModel (m_config.macros ()); connect (ui->tx5->lineEdit ()