Changeset View
Changeset View
Standalone View
Standalone View
src/widget/utils/kexidatetimeformatter.cpp
Context not available. | |||||
23 | 23 | | |||
---|---|---|---|---|---|
24 | #include <QLineEdit> | 24 | #include <QLineEdit> | ||
25 | #include <QLocale> | 25 | #include <QLocale> | ||
26 | #include <QRegularExpression> | ||||
26 | 27 | | |||
27 | class KexiDateFormatter::Private | 28 | class KexiDateFormatter::Private | ||
28 | { | 29 | { | ||
Context not available. | |||||
53 | { | 54 | { | ||
54 | public: | 55 | public: | ||
55 | Private() | 56 | Private() | ||
56 | : hmsRegExp(new QRegExp( | 57 | : hmsRegExp(new QRegularExpression( | ||
57 | QLatin1String("(\\d*):(\\d*):(\\d*).*( am| pm){,1}"), Qt::CaseInsensitive)) | 58 | QLatin1String("(\\d*):(\\d*):(\\d*).*( am| pm){,1}"), QRegularExpression::CaseInsensitiveOption)) | ||
58 | , hmRegExp(new QRegExp( | 59 | , hmRegExp(new QRegularExpression( | ||
59 | QLatin1String("(\\d*):(\\d*).*( am| pm){,1}"), Qt::CaseInsensitive)) | 60 | QLatin1String("(\\d*):(\\d*).*( am| pm){,1}"), QRegularExpression::CaseInsensitiveOption)) | ||
60 | { | 61 | { | ||
61 | } | 62 | } | ||
62 | 63 | | |||
Context not available. | |||||
82 | //! Used in fromString(const QString&) to convert string back to QTime | 83 | //! Used in fromString(const QString&) to convert string back to QTime | ||
83 | int hourpos, minpos, secpos, ampmpos; | 84 | int hourpos, minpos, secpos, ampmpos; | ||
84 | 85 | | |||
85 | QRegExp *hmsRegExp, *hmRegExp; | 86 | QRegularExpression *hmsRegExp, *hmRegExp; | ||
86 | }; | 87 | }; | ||
87 | 88 | | |||
88 | KexiDateFormatter::KexiDateFormatter() | 89 | KexiDateFormatter::KexiDateFormatter() | ||
Context not available. | |||||
318 | QTime time; | 319 | QTime time; | ||
319 | int hour, min, sec; | 320 | int hour, min, sec; | ||
320 | bool pm = false; | 321 | bool pm = false; | ||
321 | 322 | QRegularExpressionMatch matchHms = d->hmsRegExp->match(str); | |||
323 | QRegularExpressionMatch matchHm = d->hmRegExp->match(str); | ||||
322 | bool tryWithoutSeconds = true; | 324 | bool tryWithoutSeconds = true; | ||
325 | | ||||
323 | if (d->secpos >= 0) { | 326 | if (d->secpos >= 0) { | ||
324 | if (-1 != d->hmsRegExp->indexIn(str)) { | 327 | if (-1 != matchHms.capturedStart()) { | ||
325 | hour = d->hmsRegExp->cap(1).toInt(); | 328 | hour = matchHms.captured(1).toInt(); | ||
326 | min = d->hmsRegExp->cap(2).toInt(); | 329 | min = matchHms.captured(2).toInt(); | ||
327 | sec = d->hmsRegExp->cap(3).toInt(); | 330 | sec = matchHms.captured(3).toInt(); | ||
328 | if (d->ampmpos >= 0 && d->hmsRegExp->captureCount() > 3) | 331 | if (d->ampmpos >= 0 && d->hmsRegExp->captureCount() > 3) | ||
329 | pm = d->hmsRegExp->cap(4).trimmed().toLower() == "pm"; | 332 | pm = matchHms.captured(4).trimmed().toLower() == "pm"; | ||
330 | tryWithoutSeconds = false; | 333 | tryWithoutSeconds = false; | ||
331 | } | 334 | } | ||
332 | } | 335 | } | ||
333 | if (tryWithoutSeconds) { | 336 | if (tryWithoutSeconds) { | ||
334 | if (-1 == d->hmRegExp->indexIn(str)) | 337 | if (-1 == matchHm.capturedStart()) | ||
335 | return QTime(99, 0, 0); | 338 | return QTime(99, 0, 0); | ||
336 | hour = d->hmRegExp->cap(1).toInt(); | 339 | hour = matchHm.captured(1).toInt(); | ||
337 | min = d->hmRegExp->cap(2).toInt(); | 340 | min = matchHm.captured(2).toInt(); | ||
338 | sec = 0; | 341 | sec = 0; | ||
339 | if (d->ampmpos >= 0 && d->hmRegExp->captureCount() > 2) | 342 | if (d->ampmpos >= 0 && d->hmRegExp->captureCount() > 2) | ||
340 | pm = d->hmsRegExp->cap(4).toLower() == "pm"; | 343 | pm = matchHm.captured(4).toLower() == "pm"; | ||
341 | } | 344 | } | ||
342 | 345 | | |||
343 | if (pm && hour < 12) | 346 | if (pm && hour < 12) | ||
Context not available. |