Skip to content

Commit 636da8b

Browse files
committed
Use QValidator
Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 334beaa commit 636da8b

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
container: ubuntu:${{ matrix.container }}
7171
strategy:
7272
matrix:
73-
container: ['22.04', '24.04', '25.04', '25.10']
73+
container: ['22.04', '24.04', '25.10', '26.04']
7474
arch: ['amd64', 'arm64']
7575
env:
7676
DEBIAN_FRONTEND: noninteractive
@@ -116,7 +116,7 @@ jobs:
116116
container: fedora:${{ matrix.container }}
117117
strategy:
118118
matrix:
119-
container: [42, 43]
119+
container: [42, 43, 44]
120120
steps:
121121
- name: Download artifact
122122
uses: dawidd6/action-download-artifact@v11

client/dialogs/RoleAddressDialog.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@
2828

2929
class 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-
4431
RoleAddressDialog::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

Comments
 (0)