Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/importexport/csv/kexicsvimportdialog.cpp
Context not available. | |||||
337 | } | 337 | } | ||
---|---|---|---|---|---|
338 | else if ( mode == File ) | 338 | else if ( mode == File ) | ||
339 | {*/ | 339 | {*/ | ||
340 | m_dateRegExp = QRegExp("(\\d{1,4})([/\\-\\.])(\\d{1,2})([/\\-\\.])(\\d{1,4})"); | 340 | m_dateRegExp = QRegularExpression("^(\\d{1,4})([/\\-\\.])(\\d{1,2})([/\\-\\.])(\\d{1,4})$"); | ||
341 | m_timeRegExp1 = QRegExp("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})"); | 341 | m_timeRegExp1 = QRegularExpression("^(\\d{1,2}):(\\d{1,2}):(\\d{1,2})$"); | ||
342 | m_timeRegExp2 = QRegExp("(\\d{1,2}):(\\d{1,2})"); | 342 | m_timeRegExp2 = QRegularExpression("^(\\d{1,2}):(\\d{1,2})$"); | ||
343 | m_fpNumberRegExp1 = QRegExp("[\\-]{0,1}\\d*[,\\.]\\d+"); | 343 | m_fpNumberRegExp1 = QRegularExpression("^[\\-]{0,1}\\d*[,\\.]\\d+$"); | ||
344 | // E notation, e.g. 0.1e2, 0.1e+2, 0.1e-2, 0.1E2, 0.1E+2, 0.1E-2 | 344 | // E notation, e.g. 0.1e2, 0.1e+2, 0.1e-2, 0.1E2, 0.1E+2, 0.1E-2 | ||
345 | m_fpNumberRegExp2 = QRegExp("[\\-]{0,1}\\d*[,\\.]\\d+[Ee][+-]{0,1}\\d+"); | 345 | m_fpNumberRegExp2 = QRegularExpression("^[\\-]{0,1}\\d*[,\\.]\\d+[Ee][+-]{0,1}\\d+$"); | ||
346 | m_loadingProgressDlg = 0; | 346 | m_loadingProgressDlg = 0; | ||
347 | if (m_mode == Clipboard) { | 347 | if (m_mode == Clipboard) { | ||
348 | m_infoLbl->setIcon(koIconName("edit-paste")); | 348 | m_infoLbl->setIcon(koIconName("edit-paste")); | ||
Context not available. | |||||
1400 | if (!found && (row == 1 || type == KDbField::Integer || type == KDbField::Double | 1400 | if (!found && (row == 1 || type == KDbField::Integer || type == KDbField::Double | ||
1401 | || type == KDbField::InvalidType)) | 1401 | || type == KDbField::InvalidType)) | ||
1402 | { | 1402 | { | ||
1403 | bool ok = text.isEmpty() || m_fpNumberRegExp1.exactMatch(text) || m_fpNumberRegExp2.exactMatch(text); | 1403 | bool ok = text.isEmpty() || m_fpNumberRegExp1.match(text).hasMatch() || m_fpNumberRegExp2.match(text).hasMatch(); | ||
1404 | if (ok && (row == 1 || type == KDbField::InvalidType)) | 1404 | if (ok && (row == 1 || type == KDbField::InvalidType)) | ||
1405 | { | 1405 | { | ||
1406 | d->setDetectedType(col, KDbField::Double); | 1406 | d->setDetectedType(col, KDbField::Double); | ||
Context not available. | |||||
1420 | //-date? | 1420 | //-date? | ||
1421 | if (!found && (row == 1 || type == KDbField::Date || type == KDbField::InvalidType)) { | 1421 | if (!found && (row == 1 || type == KDbField::Date || type == KDbField::InvalidType)) { | ||
1422 | if ((row == 1 || type == KDbField::InvalidType) | 1422 | if ((row == 1 || type == KDbField::InvalidType) | ||
1423 | && (text.isEmpty() || m_dateRegExp.exactMatch(text))) { | 1423 | && (text.isEmpty() || m_dateRegExp.match(text).hasMatch())) { | ||
1424 | d->setDetectedType(col, KDbField::Date); | 1424 | d->setDetectedType(col, KDbField::Date); | ||
1425 | found = true; //yes | 1425 | found = true; //yes | ||
1426 | } | 1426 | } | ||
Context not available. | |||||
1428 | //-time? | 1428 | //-time? | ||
1429 | if (!found && (row == 1 || type == KDbField::Time || type == KDbField::InvalidType)) { | 1429 | if (!found && (row == 1 || type == KDbField::Time || type == KDbField::InvalidType)) { | ||
1430 | if ((row == 1 || type == KDbField::InvalidType) | 1430 | if ((row == 1 || type == KDbField::InvalidType) | ||
1431 | && (text.isEmpty() || m_timeRegExp1.exactMatch(text) || m_timeRegExp2.exactMatch(text))) | 1431 | && (text.isEmpty() || m_timeRegExp1.match(text).hasMatch() || m_timeRegExp2.match(text).hasMatch())) | ||
1432 | { | 1432 | { | ||
1433 | d->setDetectedType(col, KDbField::Time); | 1433 | d->setDetectedType(col, KDbField::Time); | ||
1434 | found = true; //yes | 1434 | found = true; //yes | ||
Context not available. | |||||
1447 | //try all combinations | 1447 | //try all combinations | ||
1448 | QString datePart(dateTimeList[0].trimmed()); | 1448 | QString datePart(dateTimeList[0].trimmed()); | ||
1449 | QString timePart(dateTimeList[1].trimmed()); | 1449 | QString timePart(dateTimeList[1].trimmed()); | ||
1450 | ok = m_dateRegExp.exactMatch(datePart) | 1450 | ok = m_dateRegExp.match(datePart).hasMatch() | ||
1451 | && (m_timeRegExp1.exactMatch(timePart) || m_timeRegExp2.exactMatch(timePart)); | 1451 | && (m_timeRegExp1.match(timePart).hasMatch() || m_timeRegExp2.match(timePart).hasMatch()); | ||
1452 | } | 1452 | } | ||
1453 | detected = ok; | 1453 | detected = ok; | ||
1454 | } | 1454 | } | ||
Context not available. | |||||
1500 | 1500 | | |||
1501 | bool KexiCSVImportDialog::parseDate(const QString& text, QDate& date) | 1501 | bool KexiCSVImportDialog::parseDate(const QString& text, QDate& date) | ||
1502 | { | 1502 | { | ||
1503 | if (!m_dateRegExp.exactMatch(text)) | 1503 | QRegularExpressionMatch match = m_dateRegExp.match(text); | ||
1504 | if (!match.hasMatch()) | ||||
1504 | return false; | 1505 | return false; | ||
1505 | //dddd - dd - dddd | 1506 | //dddd - dd - dddd | ||
1506 | //1 2 3 4 5 <- pos | 1507 | //1 2 3 4 5 <- pos | ||
1507 | const int d1 = m_dateRegExp.cap(1).toInt(), d3 = m_dateRegExp.cap(3).toInt(), d5 = m_dateRegExp.cap(5).toInt(); | 1508 | const int d1 = match.captured(1).toInt(), d3 = match.captured(3).toInt(), d5 = match.captured(5).toInt(); | ||
1508 | switch (m_options.dateFormat) { | 1509 | switch (m_options.dateFormat) { | ||
1509 | case KexiCSVImportOptions::DMY: date = buildDate(d5, d3, d1); break; | 1510 | case KexiCSVImportOptions::DMY: date = buildDate(d5, d3, d1); break; | ||
1510 | case KexiCSVImportOptions::YMD: date = buildDate(d1, d3, d5); break; | 1511 | case KexiCSVImportOptions::YMD: date = buildDate(d1, d3, d5); break; | ||
1511 | case KexiCSVImportOptions::MDY: date = buildDate(d5, d1, d3); break; | 1512 | case KexiCSVImportOptions::MDY: date = buildDate(d5, d1, d3); break; | ||
1512 | case KexiCSVImportOptions::AutoDateFormat: | 1513 | case KexiCSVImportOptions::AutoDateFormat: | ||
1513 | if (m_dateRegExp.cap(2) == "/") { //probably separator for american format mm/dd/yyyy | 1514 | if (match.captured(2) == "/") { //probably separator for american format mm/dd/yyyy | ||
1514 | date = buildDate(d5, d1, d3); | 1515 | date = buildDate(d5, d1, d3); | ||
1515 | } else { | 1516 | } else { | ||
1516 | if (d5 > 31) //d5 == year | 1517 | if (d5 > 31) //d5 == year | ||
Context not available. | |||||
1529 | time = QTime::fromString(text, Qt::ISODate); //same as m_timeRegExp1 | 1530 | time = QTime::fromString(text, Qt::ISODate); //same as m_timeRegExp1 | ||
1530 | if (time.isValid()) | 1531 | if (time.isValid()) | ||
1531 | return true; | 1532 | return true; | ||
1532 | if (m_timeRegExp2.exactMatch(text)) { //hh:mm:ss | 1533 | | ||
1533 | time = QTime(m_timeRegExp2.cap(1).toInt(), | 1534 | QRegularExpressionMatch match = m_timeRegExp2.match(text); | ||
1534 | m_timeRegExp2.cap(3).toInt(), m_timeRegExp2.cap(5).toInt()); | 1535 | if (match.hasMatch()) { //hh:mm:ss | ||
1536 | time = QTime(match.captured(1).toInt(), | ||||
1537 | match.captured(3).toInt(), match.captured(5).toInt()); | ||||
1535 | return true; | 1538 | return true; | ||
1536 | } | 1539 | } | ||
1537 | return false; | 1540 | return false; | ||
Context not available. |