Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(uiform): Added format constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Diadlo committed Oct 7, 2016
1 parent d909d99 commit 13baf93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/widget/form/settings/userinterfaceform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QFileDialog>
#include <QFont>
#include <QMessageBox>
#include <QRegularExpressionValidator>
#include <QStandardPaths>
#include <QStyleFactory>
#include <QTime>
Expand Down Expand Up @@ -124,8 +125,15 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent) :
timeFormats.removeDuplicates();
bodyUI->timestamp->addItems(timeFormats);

QRegularExpression re(QString("^[^\\n]{0,%0}$").arg(MAX_FORMAT_LENGTH));
QRegularExpressionValidator* validator = new QRegularExpressionValidator(re, this);
QString timeFormat = s.getTimestampFormat();

if (!re.match(timeFormat).hasMatch())
timeFormat = timeFormats[0];

bodyUI->timestamp->setCurrentText(timeFormat);
bodyUI->timestamp->setValidator(validator);
on_timestamp_editTextChanged(timeFormat);

QStringList dateFormats;
Expand All @@ -140,7 +148,11 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent) :
bodyUI->dateFormats->addItems(dateFormats);

QString dateFormat = s.getDateFormat();
if (!re.match(dateFormat).hasMatch())
dateFormat = dateFormats[0];

bodyUI->dateFormats->setCurrentText(dateFormat);
bodyUI->dateFormats->setValidator(validator);
on_dateFormats_editTextChanged(dateFormat);

eventsInit();
Expand Down
3 changes: 2 additions & 1 deletion src/widget/form/settings/userinterfaceform.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ private slots:
private:
QList<QLabel*> smileLabels;
SettingsWidget* parent;
Ui::UserInterfaceSettings *bodyUI;
Ui::UserInterfaceSettings* bodyUI;
const int MAX_FORMAT_LENGTH = 128;
};

#endif

0 comments on commit 13baf93

Please sign in to comment.