* @brief Detects the CSV timestamp format and initializes the cache. */
| 314 | * @brief Detects the CSV timestamp format and initializes the cache. |
| 315 | */ |
| 316 | void CSV::Player::initializeTimestamps() |
| 317 | { |
| 318 | Q_ASSERT(!m_csvData.isEmpty()); |
| 319 | Q_ASSERT(m_csvFile.isOpen()); |
| 320 | |
| 321 | bool error = false; |
| 322 | QString firstCell = getCellValue(1, 0, error); |
| 323 | double firstTimestamp = error ? -1.0 : getTimestampSeconds(firstCell); |
| 324 | |
| 325 | if (firstTimestamp >= 0.0) { |
| 326 | m_timestampCache.clear(); |
| 327 | m_timestampCache.reserve(m_csvData.count()); |
| 328 | |
| 329 | for (int i = 0; i < m_csvData.count(); ++i) { |
| 330 | bool err = false; |
| 331 | QString cell = getCellValue(i, 0, err); |
| 332 | double ts = err ? 0.0 : getTimestampSeconds(cell); |
| 333 | m_timestampCache.append(ts); |
| 334 | } |
| 335 | |
| 336 | m_useHighPrecisionTimestamps = true; |
| 337 | m_startTimestampSeconds = (m_timestampCache.size() > 1) ? m_timestampCache[1] : 0.0; |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | if (getDateTime(1).isValid()) { |
| 342 | m_useHighPrecisionTimestamps = false; |
| 343 | m_timestampCache.clear(); |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | m_useHighPrecisionTimestamps = false; |
| 348 | m_timestampCache.clear(); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * @brief Opens the CSV at filePath and prepares it for playback. |