Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions plotjuggler_plugins/DataLoadCSV/dataload_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,64 @@ bool DataLoadCSV::readDataFromFile(FileLoadInfo* info, PlotDataMapRef& plot_data
const QString format_string = _ui->lineEditDateFormat->text();
const bool parse_date_format = _ui->radioCustomTime->isChecked();

auto ParseNumber = [&](QString str, bool& is_number) {
QString str_trimmed = str.trimmed();
double val = val = str_trimmed.toDouble(&is_number);
// handle numbers with comma instead of point as decimal separator
if (!is_number)
{
static QLocale locale_with_comma(QLocale::German);
val = locale_with_comma.toDouble(str_trimmed, &is_number);
}
// handle hexadecimal values (with or without 0x prefix)
if (!is_number)
{
bool ok = false;
// Try parsing as hex with 0x prefix
if (str_trimmed.startsWith("0x", Qt::CaseInsensitive))
{
val = str_trimmed.toLongLong(&ok, 16);
is_number = ok;
}
// Try parsing as plain hex (e.g., "A", "FF", "1A")
else if (str_trimmed.length() > 0)
{
bool all_hex = true;
for (int i = 0; i < str_trimmed.length(); ++i)
{
QChar c = str_trimmed[i];
if (!c.isDigit() && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
{
all_hex = false;
break;
}
}
if (all_hex)
{
val = str_trimmed.toLongLong(&ok, 16);
is_number = ok;
}
}
}
if (!is_number)
{
QDateTime ts;
if (parse_date_format)
{
ts = QDateTime::fromString(str_trimmed, format_string);
}
else
{
ts = QDateTime::fromString(str_trimmed, Qt::ISODateWithMs);
}
is_number = ts.isValid();
if (is_number)
{
val = ts.toMSecsSinceEpoch() / 1000.0;
}
}
return val;
};
// Vector to store detected column types (detected from first data row)
std::vector<PJ::CSV::ColumnTypeInfo> column_types(column_names.size());
bool column_types_detected = false;
Expand Down