! * \brief Sets the live data source of this dock widget * \param source */
| 249 | * \param source |
| 250 | */ |
| 251 | void LiveDataDock::setLiveDataSource(LiveDataSource* const source) { |
| 252 | #ifdef HAVE_MQTT |
| 253 | m_mqttClient = nullptr; |
| 254 | #endif |
| 255 | m_liveDataSource = nullptr; // prevent updates due to changes to input widgets |
| 256 | |
| 257 | ui.leName->setText(source->name()); |
| 258 | ui.leName->setStyleSheet(QString()); |
| 259 | ui.leName->setToolTip(QString()); |
| 260 | const LiveDataSource::SourceType sourceType = source->sourceType(); |
| 261 | const LiveDataSource::ReadingType readingType = source->readingType(); |
| 262 | const LiveDataSource::UpdateType updateType = source->updateType(); |
| 263 | const AbstractFileFilter::FileType fileType = source->fileType(); |
| 264 | ui.sbUpdateInterval->setValue(source->updateInterval()); |
| 265 | ui.cbUpdateType->setCurrentIndex(static_cast<int>(updateType)); |
| 266 | ui.cbReadingType->setCurrentIndex(static_cast<int>(readingType)); |
| 267 | |
| 268 | switch (sourceType) { |
| 269 | case LiveDataSource::SourceType::FileOrPipe: { |
| 270 | ui.leSourceInfo->setText(source->fileName()); |
| 271 | bool invalid = !QFile::exists(source->fileName()); |
| 272 | GuiTools::highlight(ui.leSourceInfo, invalid); |
| 273 | break; |
| 274 | } |
| 275 | case LiveDataSource::SourceType::NetworkTCPSocket: |
| 276 | case LiveDataSource::SourceType::NetworkUDPSocket: |
| 277 | ui.leSourceInfo->setText(QStringLiteral("%1:%2").arg(source->host()).arg(source->port())); |
| 278 | break; |
| 279 | case LiveDataSource::SourceType::LocalSocket: |
| 280 | ui.leSourceInfo->setText(source->localSocketName()); |
| 281 | break; |
| 282 | case LiveDataSource::SourceType::SerialPort: |
| 283 | ui.leSourceInfo->setText(source->serialPortName()); |
| 284 | break; |
| 285 | case LiveDataSource::SourceType::MQTT: |
| 286 | break; |
| 287 | } |
| 288 | |
| 289 | if (updateType == LiveDataSource::UpdateType::NewData) { |
| 290 | ui.lUpdateInterval->hide(); |
| 291 | ui.sbUpdateInterval->hide(); |
| 292 | } |
| 293 | |
| 294 | m_paused = source->isPaused(); |
| 295 | updatePlayPauseButtonText(m_paused); |
| 296 | |
| 297 | ui.sbKeepNValues->setValue(source->keepNValues()); |
| 298 | |
| 299 | // disable "whole file" when having no file (i.e. socket or port) |
| 300 | auto* model = qobject_cast<const QStandardItemModel*>(ui.cbReadingType->model()); |
| 301 | auto* item = model->item(static_cast<int>(LiveDataSource::ReadingType::WholeFile)); |
| 302 | if (sourceType == LiveDataSource::SourceType::FileOrPipe) { |
| 303 | item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
| 304 | // for file types other than ASCII and binary we support re-reading the whole file only |
| 305 | // select "read whole file" and deactivate the combobox |
| 306 | if (fileType != AbstractFileFilter::FileType::Ascii && fileType != AbstractFileFilter::FileType::Binary) { |
| 307 | ui.cbReadingType->setCurrentIndex(static_cast<int>(LiveDataSource::ReadingType::WholeFile)); |
| 308 | ui.cbReadingType->setEnabled(false); |
no test coverage detected