2828
2929class RoleAddressDialog ::Private: public Ui::RoleAddressDialog {};
3030
31- static QString cleanUp (const QString& src) {
32- QString dst;
33- dst.reserve (src.size ());
34- size_t dlen = 0 ;
35- for (auto s = src.cbegin (); s != src.cend (); s++) {
36- if ((*s <= ' ' ) && (*s != QChar (0x9 )) && (*s != QChar (0xa )) && (*s != QChar (0xd ))) continue ;
37- if ((*s == QChar (0xfffe )) || (*s == QChar (0xffff ))) continue ;
38- dst.append (*s);
39- }
40- dst.resize (dlen);
41- return dst;
42- }
43-
4431RoleAddressDialog::RoleAddressDialog (QWidget *parent)
4532 : QDialog(parent)
4633 , d(new Private)
@@ -50,17 +37,20 @@ RoleAddressDialog::RoleAddressDialog(QWidget *parent)
5037 d->buttonLayout ->setDirection (QBoxLayout::RightToLeft);
5138#endif
5239 setWindowFlags (Qt::Dialog | Qt::CustomizeWindowHint);
53- for (QLineEdit *w: findChildren<QLineEdit*>())
54- w->setAttribute (Qt::WA_MacShowFocusRect, false );
5540
5641 connect ( d->cancel , &QPushButton::clicked, this , &RoleAddressDialog::reject );
5742 connect ( d->sign , &QPushButton::clicked, this , &RoleAddressDialog::accept );
5843
44+ auto *validator = new QRegularExpressionValidator (
45+ QRegularExpression (QStringLiteral (" [^\\ x00-\\ x08\\ x0B\\ x0C\\ x0E-\\ x1F\\ x{FFFE}\\ x{FFFF}]*" )),
46+ this );
5947 auto list = findChildren<QLineEdit*>();
6048 if (!list.isEmpty ())
6149 list.first ()->setFocus ();
6250 for (QLineEdit *line: list)
6351 {
52+ line->setAttribute (Qt::WA_MacShowFocusRect, false );
53+ line->setValidator (validator);
6454 Settings::Option<QStringList> s{line->objectName (), {}};
6555 auto *completer = new QCompleter (s, line);
6656 completer->setMaxVisibleItems (10 );
@@ -70,9 +60,8 @@ RoleAddressDialog::RoleAddressDialog(QWidget *parent)
7060 line->setCompleter (completer);
7161 connect (line, &QLineEdit::editingFinished, this , [line, s = std::move (s)] {
7262 QStringList list = s;
73- QString text = cleanUp (line->text ());
74- list.removeAll (text);
75- list.insert (0 , text);
63+ list.removeAll (line->text ());
64+ list.insert (0 , line->text ());
7665 if (list.size () > 10 )
7766 list.removeLast ();
7867 s.clear (); // Uses on Windows MULTI_STRING registry
@@ -95,10 +84,10 @@ int RoleAddressDialog::get(QString &city, QString &country, QString &state, QStr
9584 int result = QDialog::exec ();
9685 if (result == QDialog::Rejected)
9786 return result;
98- role = cleanUp ( d->Role ->text () );
99- city = cleanUp ( d->City ->text () );
100- state = cleanUp ( d->State ->text () );
101- country = cleanUp ( d->Country ->text () );
102- zip = cleanUp ( d->Zip ->text () );
87+ role = d->Role ->text ();
88+ city = d->City ->text ();
89+ state = d->State ->text ();
90+ country = d->Country ->text ();
91+ zip = d->Zip ->text ();
10392 return result;
10493}
0 commit comments