@@ -119,7 +119,19 @@ DataLoadCSV::DataLoadCSV()
119119 [this ]() { emit _ui->buttonBox ->accepted (); });
120120
121121 connect (_ui->checkBoxDateFormat , &QCheckBox::toggled, this ,
122- [this ](bool checked) { _ui->lineEditDateFormat ->setEnabled (checked); });
122+ [this ](bool checked) {
123+ _ui->radioCustomDate ->setEnabled (checked);
124+ _ui->radioIso8601Date ->setEnabled (checked);
125+ _ui->lineEditDateFormat ->setEnabled (_ui->radioCustomDate ->isChecked ());
126+ });
127+
128+ connect (_ui->radioCustomDate , &QRadioButton::clicked, this , [this ](bool checked){
129+ _ui->lineEditDateFormat ->setEnabled (checked);
130+ });
131+
132+ connect (_ui->radioIso8601Date , &QRadioButton::clicked, this , [this ](bool checked){
133+ _ui->lineEditDateFormat ->setEnabled (!checked);
134+ });
123135
124136 connect (_ui->dateTimeHelpButton , &QPushButton::clicked, this ,
125137 [this ]() { _dateTime_dialog->show (); });
@@ -490,6 +502,7 @@ bool DataLoadCSV::readDataFromFile(FileLoadInfo* info, PlotDataMapRef& plot_data
490502 double prev_time = std::numeric_limits<double >::lowest ();
491503 bool parse_date_format = _ui->checkBoxDateFormat ->isChecked ();
492504 QString format_string = _ui->lineEditDateFormat ->text ();
505+ bool parse_iso_8601 = _ui->radioIso8601Date ->isChecked ();
493506
494507 auto ParseTimestamp = [&](QString str, bool & is_number) {
495508 QString str_trimmed = str.trimmed ();
@@ -530,9 +543,9 @@ bool DataLoadCSV::readDataFromFile(FileLoadInfo* info, PlotDataMapRef& plot_data
530543 static QLocale locale_with_comma (QLocale::German);
531544 val = locale_with_comma.toDouble (str_trimmed, &is_number);
532545 }
533- if (!is_number && parse_date_format)
546+ if (!is_number && parse_date_format && (!format_string. isEmpty () || parse_iso_8601) )
534547 {
535- QDateTime ts = !format_string. isEmpty () ? QDateTime::fromString (str_trimmed, format_string ) : QDateTime::fromString (str_trimmed, Qt::ISODateWithMs );
548+ QDateTime ts = parse_iso_8601 ? QDateTime::fromString (str_trimmed, Qt::ISODateWithMs ) : QDateTime::fromString (str_trimmed, format_string );
536549 is_number = ts.isValid ();
537550 if (is_number)
538551 {
@@ -551,9 +564,9 @@ bool DataLoadCSV::readDataFromFile(FileLoadInfo* info, PlotDataMapRef& plot_data
551564 static QLocale locale_with_comma (QLocale::German);
552565 val = locale_with_comma.toDouble (str_trimmed, &is_number);
553566 }
554- if (!is_number && parse_date_format && !format_string.isEmpty ())
567+ if (!is_number && parse_date_format && ( !format_string.isEmpty () || parse_iso_8601 ))
555568 {
556- QDateTime ts = QDateTime::fromString (str_trimmed, format_string);
569+ QDateTime ts = parse_iso_8601 ? QDateTime::fromString (str_trimmed, Qt::ISODateWithMs) : QDateTime::fromString (str_trimmed, format_string);
557570 is_number = ts.isValid ();
558571 if (is_number)
559572 {
@@ -779,12 +792,16 @@ bool DataLoadCSV::xmlSaveState(QDomDocument& doc, QDomElement& parent_element) c
779792 elem.setAttribute (" time_axis" , _default_time_axis.c_str ());
780793 elem.setAttribute (" delimiter" , _ui->comboBox ->currentIndex ());
781794
782- QString date_format;
783795 if (_ui->checkBoxDateFormat ->isChecked ())
784796 {
785797 elem.setAttribute (" date_format" , _ui->lineEditDateFormat ->text ());
786798 }
787799
800+ if (_ui->radioIso8601Date ->isChecked ())
801+ {
802+ elem.setAttribute (" date_format_iso" , " ISO8601" );
803+ }
804+
788805 parent_element.appendChild (elem);
789806 return true ;
790807}
@@ -822,5 +839,11 @@ bool DataLoadCSV::xmlLoadState(const QDomElement& parent_element)
822839 _ui->checkBoxDateFormat ->setChecked (true );
823840 _ui->lineEditDateFormat ->setText (elem.attribute (" date_format" ));
824841 }
842+ if (elem.hasAttribute (" date_format_iso" ))
843+ {
844+ _ui->radioIso8601Date ->setChecked (true );
845+ } else {
846+ _ui->radioCustomDate ->setChecked (true );
847+ }
825848 return true ;
826849}
0 commit comments