! * \brief Sets the source's update type to updatetype and handles this change * \param updatetype */
| 324 | * \param updatetype |
| 325 | */ |
| 326 | void LiveDataSource::setUpdateType(UpdateType updatetype) { |
| 327 | switch (updatetype) { |
| 328 | case UpdateType::NewData: { |
| 329 | m_updateTimer->stop(); |
| 330 | if (!m_fileSystemWatcher) |
| 331 | m_fileSystemWatcher = new QFileSystemWatcher(this); |
| 332 | |
| 333 | m_fileSystemWatcher->addPath(m_fileName); |
| 334 | |
| 335 | QFileInfo file(m_fileName); |
| 336 | // If the watched file currently does not exist (because it is recreated for instance), watch its containing |
| 337 | // directory instead. Once the file exists again, switch to watching the file in readOnUpdate(). |
| 338 | // Reading will only start 100ms after the last update, to prevent continuous re-reading while the file is updated. |
| 339 | // If the watched file intentionally is updated more often than that, the user should switch to periodic reading. |
| 340 | if (m_fileSystemWatcher->files().contains(m_fileName)) |
| 341 | m_fileSystemWatcher->removePath(file.absolutePath()); |
| 342 | else |
| 343 | m_fileSystemWatcher->addPath(file.absolutePath()); |
| 344 | |
| 345 | connect(m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, [&]() { |
| 346 | m_watchTimer->start(); |
| 347 | }); |
| 348 | connect(m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, [&]() { |
| 349 | m_watchTimer->start(); |
| 350 | }); |
| 351 | break; |
| 352 | } |
| 353 | case UpdateType::TimeInterval: |
| 354 | delete m_fileSystemWatcher; |
| 355 | m_fileSystemWatcher = nullptr; |
| 356 | break; |
| 357 | } |
| 358 | m_updateType = updatetype; |
| 359 | } |
| 360 | |
| 361 | LiveDataSource::UpdateType LiveDataSource::updateType() const { |
| 362 | return m_updateType; |
nothing calls this directly
no test coverage detected