Changeset View
Changeset View
Standalone View
Standalone View
src/kdefrontend/datasources/ImportFileWidget.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
57 | #include <QUdpSocket> | 57 | #include <QUdpSocket> | ||
58 | #include <QCheckBox> | 58 | #include <QCheckBox> | ||
59 | #include <QTreeWidgetItem> | 59 | #include <QTreeWidgetItem> | ||
60 | #include <QStringList> | 60 | #include <QStringList> | ||
61 | 61 | | |||
62 | #include <KConfigGroup> | 62 | #include <KConfigGroup> | ||
63 | #include <KLocalizedString> | 63 | #include <KLocalizedString> | ||
64 | #include <KSharedConfig> | 64 | #include <KSharedConfig> | ||
65 | #include <KUrlComboBox> | ||||
65 | 66 | | |||
66 | #ifdef HAVE_MQTT | 67 | #ifdef HAVE_MQTT | ||
67 | #include "kdefrontend/widgets/MQTTWillSettingsWidget.h" | 68 | #include "kdefrontend/widgets/MQTTWillSettingsWidget.h" | ||
68 | #include "MQTTConnectionManagerDialog.h" | 69 | #include "MQTTConnectionManagerDialog.h" | ||
69 | #include "MQTTSubscriptionWidget.h" | 70 | #include "MQTTSubscriptionWidget.h" | ||
70 | #include <QMqttClient> | 71 | #include <QMqttClient> | ||
71 | #include <QMqttSubscription> | 72 | #include <QMqttSubscription> | ||
72 | #include <QMqttTopicFilter> | 73 | #include <QMqttTopicFilter> | ||
Show All 14 Lines | 86 | ImportFileWidget::ImportFileWidget(QWidget* parent, bool liveDataSource, const QString& fileName) : QWidget(parent), | |||
87 | m_liveDataSource(liveDataSource) | 88 | m_liveDataSource(liveDataSource) | ||
88 | #ifdef HAVE_MQTT | 89 | #ifdef HAVE_MQTT | ||
89 | , | 90 | , | ||
90 | m_connectTimeoutTimer(new QTimer(this)), | 91 | m_connectTimeoutTimer(new QTimer(this)), | ||
91 | m_subscriptionWidget(new MQTTSubscriptionWidget(this)) | 92 | m_subscriptionWidget(new MQTTSubscriptionWidget(this)) | ||
92 | #endif | 93 | #endif | ||
93 | { | 94 | { | ||
94 | ui.setupUi(this); | 95 | ui.setupUi(this); | ||
95 | ui.leFileName->setCompleter(new QCompleter(new QDirModel)); | | |||
96 | 96 | | |||
97 | //add supported file types | 97 | //add supported file types | ||
98 | if (!liveDataSource) { | 98 | if (!liveDataSource) { | ||
99 | ui.cbFileType->addItem(i18n("ASCII data"), AbstractFileFilter::Ascii); | 99 | ui.cbFileType->addItem(i18n("ASCII data"), AbstractFileFilter::Ascii); | ||
100 | ui.cbFileType->addItem(i18n("Binary data"), AbstractFileFilter::Binary); | 100 | ui.cbFileType->addItem(i18n("Binary data"), AbstractFileFilter::Binary); | ||
101 | ui.cbFileType->addItem(i18n("Image"), AbstractFileFilter::Image); | 101 | ui.cbFileType->addItem(i18n("Image"), AbstractFileFilter::Image); | ||
102 | #ifdef HAVE_HDF5 | 102 | #ifdef HAVE_HDF5 | ||
103 | ui.cbFileType->addItem(i18n("Hierarchical Data Format 5 (HDF5)"), AbstractFileFilter::HDF5); | 103 | ui.cbFileType->addItem(i18n("Hierarchical Data Format 5 (HDF5)"), AbstractFileFilter::HDF5); | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 139 | #endif | |||
163 | m_twPreview = new QTableWidget(ui.tePreview); | 163 | m_twPreview = new QTableWidget(ui.tePreview); | ||
164 | m_twPreview->verticalHeader()->hide(); | 164 | m_twPreview->verticalHeader()->hide(); | ||
165 | m_twPreview->setEditTriggers(QTableWidget::NoEditTriggers); | 165 | m_twPreview->setEditTriggers(QTableWidget::NoEditTriggers); | ||
166 | auto* layout = new QHBoxLayout; | 166 | auto* layout = new QHBoxLayout; | ||
167 | layout->addWidget(m_twPreview); | 167 | layout->addWidget(m_twPreview); | ||
168 | ui.tePreview->setLayout(layout); | 168 | ui.tePreview->setLayout(layout); | ||
169 | m_twPreview->hide(); | 169 | m_twPreview->hide(); | ||
170 | 170 | | |||
171 | // the combobox for the import path | ||||
172 | m_cbFileName = new KUrlComboBox(KUrlComboBox::Mode::Files, ui.tePreview); | ||||
173 | m_cbFileName->setMaxItems(7); | ||||
174 | auto* gridLayout = dynamic_cast<QGridLayout*>(ui.gbDataSource->layout()); | ||||
175 | if (gridLayout) | ||||
asemke: no brackets for one-liners | |||||
176 | gridLayout->addWidget(m_cbFileName, 1, 2, 1, 3); | ||||
177 | | ||||
171 | #ifdef HAVE_MQTT | 178 | #ifdef HAVE_MQTT | ||
172 | ui.cbSourceType->addItem(QLatin1String("MQTT")); | 179 | ui.cbSourceType->addItem(QLatin1String("MQTT")); | ||
173 | m_configPath = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).constFirst() + QLatin1String("MQTT_connections"); | 180 | m_configPath = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).constFirst() + QLatin1String("MQTT_connections"); | ||
174 | 181 | | |||
175 | //add subscriptions widget | 182 | //add subscriptions widget | ||
176 | layout = new QHBoxLayout; | 183 | layout = new QHBoxLayout; | ||
177 | layout->setContentsMargins(0, 0, 0, 0); | 184 | layout->setContentsMargins(0, 0, 0, 0); | ||
178 | layout->setSpacing(0); | 185 | layout->setSpacing(0); | ||
Show All 37 Lines | 222 | if (ui.cbFileType->currentIndex() == i) | |||
216 | initOptionsWidget(); | 223 | initOptionsWidget(); | ||
217 | else | 224 | else | ||
218 | ui.cbFileType->setCurrentIndex(i); | 225 | ui.cbFileType->setCurrentIndex(i); | ||
219 | 226 | | |||
220 | break; | 227 | break; | ||
221 | } | 228 | } | ||
222 | } | 229 | } | ||
223 | 230 | | |||
231 | if (m_fileName.isEmpty()) { | ||||
224 | ui.cbFilter->setCurrentIndex(conf.readEntry("Filter", 0)); | 232 | ui.cbFilter->setCurrentIndex(conf.readEntry("Filter", 0)); | ||
233 | m_cbFileName->setUrl(conf.readEntry("LastImportedFile", "")); | ||||
234 | QStringList urls = m_cbFileName->urls(); | ||||
235 | urls.append(conf.readXdgListEntry("LastImportedFiles")); | ||||
236 | m_cbFileName->setUrls(urls); | ||||
225 | filterChanged(ui.cbFilter->currentIndex()); // needed if filter is not changed | 237 | filterChanged(ui.cbFilter->currentIndex()); // needed if filter is not changed | ||
226 | if (m_fileName.isEmpty()) | 238 | } else | ||
227 | ui.leFileName->setText(conf.readEntry("LastImportedFile", "")); | 239 | m_cbFileName->setUrl(QUrl(m_fileName)); | ||
228 | else | 240 | | ||
229 | ui.leFileName->setText(m_fileName); | | |||
230 | 241 | | |||
231 | //live data related settings | 242 | //live data related settings | ||
232 | ui.cbBaudRate->setCurrentIndex(conf.readEntry("BaudRate").toInt()); | 243 | ui.cbBaudRate->setCurrentIndex(conf.readEntry("BaudRate").toInt()); | ||
233 | ui.cbReadingType->setCurrentIndex(conf.readEntry("ReadingType").toInt()); | 244 | ui.cbReadingType->setCurrentIndex(conf.readEntry("ReadingType").toInt()); | ||
234 | ui.cbSerialPort->setCurrentIndex(conf.readEntry("SerialPort").toInt()); | 245 | ui.cbSerialPort->setCurrentIndex(conf.readEntry("SerialPort").toInt()); | ||
235 | ui.cbUpdateType->setCurrentIndex(conf.readEntry("UpdateType").toInt()); | 246 | ui.cbUpdateType->setCurrentIndex(conf.readEntry("UpdateType").toInt()); | ||
236 | updateTypeChanged(ui.cbUpdateType->currentIndex()); | 247 | updateTypeChanged(ui.cbUpdateType->currentIndex()); | ||
237 | ui.leHost->setText(conf.readEntry("Host","")); | 248 | ui.leHost->setText(conf.readEntry("Host","")); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 291 | if (m_liveDataSource) | |||
281 | confName = QLatin1String("LiveDataImport"); | 292 | confName = QLatin1String("LiveDataImport"); | ||
282 | else | 293 | else | ||
283 | confName = QLatin1String("FileImport"); | 294 | confName = QLatin1String("FileImport"); | ||
284 | KConfigGroup conf(KSharedConfig::openConfig(), confName); | 295 | KConfigGroup conf(KSharedConfig::openConfig(), confName); | ||
285 | 296 | | |||
286 | // general settings | 297 | // general settings | ||
287 | conf.writeEntry("Type", (int)currentFileType()); | 298 | conf.writeEntry("Type", (int)currentFileType()); | ||
288 | conf.writeEntry("Filter", ui.cbFilter->currentIndex()); | 299 | conf.writeEntry("Filter", ui.cbFilter->currentIndex()); | ||
289 | conf.writeEntry("LastImportedFile", ui.leFileName->text()); | 300 | conf.writeEntry("LastImportedFile", m_cbFileName->currentText()); | ||
301 | conf.writeXdgListEntry("LastImportedFiles", m_cbFileName->urls()); | ||||
290 | 302 | | |||
291 | //live data related settings | 303 | //live data related settings | ||
292 | conf.writeEntry("SourceType", (int)currentSourceType()); | 304 | conf.writeEntry("SourceType", (int)currentSourceType()); | ||
293 | conf.writeEntry("UpdateType", ui.cbUpdateType->currentIndex()); | 305 | conf.writeEntry("UpdateType", ui.cbUpdateType->currentIndex()); | ||
294 | conf.writeEntry("ReadingType", ui.cbReadingType->currentIndex()); | 306 | conf.writeEntry("ReadingType", ui.cbReadingType->currentIndex()); | ||
295 | conf.writeEntry("SampleSize", ui.sbSampleSize->value()); | 307 | conf.writeEntry("SampleSize", ui.sbSampleSize->value()); | ||
296 | conf.writeEntry("KeepNValues", ui.sbKeepNValues->value()); | 308 | conf.writeEntry("KeepNValues", ui.sbKeepNValues->value()); | ||
297 | conf.writeEntry("BaudRate", ui.cbBaudRate->currentIndex()); | 309 | conf.writeEntry("BaudRate", ui.cbBaudRate->currentIndex()); | ||
Show All 34 Lines | 335 | #endif | |||
332 | if (m_jsonOptionsWidget) | 344 | if (m_jsonOptionsWidget) | ||
333 | m_jsonOptionsWidget->saveSettings(); | 345 | m_jsonOptionsWidget->saveSettings(); | ||
334 | } | 346 | } | ||
335 | 347 | | |||
336 | void ImportFileWidget::initSlots() { | 348 | void ImportFileWidget::initSlots() { | ||
337 | //SLOTs for the general part of the data source configuration | 349 | //SLOTs for the general part of the data source configuration | ||
338 | connect(ui.cbSourceType, static_cast<void (QComboBox::*) (int)>(&QComboBox::currentIndexChanged), | 350 | connect(ui.cbSourceType, static_cast<void (QComboBox::*) (int)>(&QComboBox::currentIndexChanged), | ||
339 | this, static_cast<void (ImportFileWidget::*) (int)>(&ImportFileWidget::sourceTypeChanged)); | 351 | this, static_cast<void (ImportFileWidget::*) (int)>(&ImportFileWidget::sourceTypeChanged)); | ||
340 | connect(ui.leFileName, &QLineEdit::textChanged, | 352 | connect(m_cbFileName, &KUrlComboBox::urlActivated, | ||
341 | this, static_cast<void (ImportFileWidget::*) (const QString&)>(&ImportFileWidget::fileNameChanged)); | 353 | this, [=](const QUrl &url){fileNameChanged(url.path());}); | ||
342 | connect(ui.leHost, &QLineEdit::textChanged, this, &ImportFileWidget::hostChanged); | 354 | connect(ui.leHost, &QLineEdit::textChanged, this, &ImportFileWidget::hostChanged); | ||
343 | connect(ui.lePort, &QLineEdit::textChanged, this, &ImportFileWidget::portChanged); | 355 | connect(ui.lePort, &QLineEdit::textChanged, this, &ImportFileWidget::portChanged); | ||
344 | connect(ui.tvJson, &QTreeView::clicked, this, &ImportFileWidget::refreshPreview); | 356 | connect(ui.tvJson, &QTreeView::clicked, this, &ImportFileWidget::refreshPreview); | ||
345 | connect(ui.bOpen, &QPushButton::clicked, this, &ImportFileWidget::selectFile); | 357 | connect(ui.bOpen, &QPushButton::clicked, this, &ImportFileWidget::selectFile); | ||
346 | connect(ui.bFileInfo, &QPushButton::clicked, this, &ImportFileWidget::fileInfoDialog); | 358 | connect(ui.bFileInfo, &QPushButton::clicked, this, &ImportFileWidget::fileInfoDialog); | ||
347 | connect(ui.bSaveFilter, &QPushButton::clicked, this, &ImportFileWidget::saveFilter); | 359 | connect(ui.bSaveFilter, &QPushButton::clicked, this, &ImportFileWidget::saveFilter); | ||
348 | connect(ui.bManageFilters, &QPushButton::clicked, this, &ImportFileWidget::manageFilters); | 360 | connect(ui.bManageFilters, &QPushButton::clicked, this, &ImportFileWidget::manageFilters); | ||
349 | connect(ui.cbFileType, static_cast<void (KComboBox::*) (int)>(&KComboBox::currentIndexChanged), | 361 | connect(ui.cbFileType, static_cast<void (KComboBox::*) (int)>(&KComboBox::currentIndexChanged), | ||
Show All 35 Lines | 395 | void ImportFileWidget::showOptions(bool b) { | |||
385 | 397 | | |||
386 | if (m_liveDataSource) | 398 | if (m_liveDataSource) | ||
387 | ui.gbUpdateOptions->setVisible(b); | 399 | ui.gbUpdateOptions->setVisible(b); | ||
388 | 400 | | |||
389 | resize(layout()->minimumSize()); | 401 | resize(layout()->minimumSize()); | ||
390 | } | 402 | } | ||
391 | 403 | | |||
392 | QString ImportFileWidget::fileName() const { | 404 | QString ImportFileWidget::fileName() const { | ||
393 | return ui.leFileName->text(); | 405 | return m_cbFileName->currentText(); | ||
394 | } | 406 | } | ||
395 | 407 | | |||
396 | QString ImportFileWidget::selectedObject() const { | 408 | QString ImportFileWidget::selectedObject() const { | ||
397 | const QString& path = ui.leFileName->text(); | 409 | const QString& path = fileName(); | ||
398 | 410 | | |||
399 | //determine the file name only | 411 | //determine the file name only | ||
400 | QString name = path.right(path.length() - path.lastIndexOf(QDir::separator()) - 1); | 412 | QString name = path.right(path.length() - path.lastIndexOf(QDir::separator()) - 1); | ||
401 | 413 | | |||
402 | //strip away the extension if available | 414 | //strip away the extension if available | ||
403 | if (name.indexOf('.') != -1) | 415 | if (name.indexOf('.') != -1) | ||
404 | name = name.left(name.lastIndexOf('.')); | 416 | name = name.left(name.lastIndexOf('.')); | ||
405 | 417 | | |||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 465 | /*! | |||
454 | saves the settings to the data source \c source. | 466 | saves the settings to the data source \c source. | ||
455 | */ | 467 | */ | ||
456 | void ImportFileWidget::saveSettings(LiveDataSource* source) const { | 468 | void ImportFileWidget::saveSettings(LiveDataSource* source) const { | ||
457 | AbstractFileFilter::FileType fileType = currentFileType(); | 469 | AbstractFileFilter::FileType fileType = currentFileType(); | ||
458 | auto updateType = static_cast<LiveDataSource::UpdateType>(ui.cbUpdateType->currentIndex()); | 470 | auto updateType = static_cast<LiveDataSource::UpdateType>(ui.cbUpdateType->currentIndex()); | ||
459 | LiveDataSource::SourceType sourceType = currentSourceType(); | 471 | LiveDataSource::SourceType sourceType = currentSourceType(); | ||
460 | auto readingType = static_cast<LiveDataSource::ReadingType>(ui.cbReadingType->currentIndex()); | 472 | auto readingType = static_cast<LiveDataSource::ReadingType>(ui.cbReadingType->currentIndex()); | ||
461 | 473 | | |||
462 | source->setComment( ui.leFileName->text() ); | 474 | source->setComment( fileName() ); | ||
463 | source->setFileType(fileType); | 475 | source->setFileType(fileType); | ||
464 | currentFileFilter(); | 476 | currentFileFilter(); | ||
465 | source->setFilter(m_currentFilter.release()); // pass ownership of the filter to the LiveDataSource | 477 | source->setFilter(m_currentFilter.release()); // pass ownership of the filter to the LiveDataSource | ||
466 | 478 | | |||
467 | source->setSourceType(sourceType); | 479 | source->setSourceType(sourceType); | ||
468 | source->setReadingType(readingType); | 480 | source->setReadingType(readingType); | ||
469 | 481 | | |||
470 | if (updateType == LiveDataSource::UpdateType::TimeInterval) | 482 | if (updateType == LiveDataSource::UpdateType::TimeInterval) | ||
471 | source->setUpdateInterval(ui.sbUpdateInterval->value()); | 483 | source->setUpdateInterval(ui.sbUpdateInterval->value()); | ||
472 | else | 484 | else | ||
473 | source->setFileWatched(true); | 485 | source->setFileWatched(true); | ||
474 | 486 | | |||
475 | source->setKeepNValues(ui.sbKeepNValues->value()); | 487 | source->setKeepNValues(ui.sbKeepNValues->value()); | ||
476 | source->setUpdateType(updateType); | 488 | source->setUpdateType(updateType); | ||
477 | 489 | | |||
478 | if (readingType != LiveDataSource::ReadingType::TillEnd) | 490 | if (readingType != LiveDataSource::ReadingType::TillEnd) | ||
479 | source->setSampleSize(ui.sbSampleSize->value()); | 491 | source->setSampleSize(ui.sbSampleSize->value()); | ||
480 | 492 | | |||
481 | switch (sourceType) { | 493 | switch (sourceType) { | ||
482 | case LiveDataSource::SourceType::FileOrPipe: | 494 | case LiveDataSource::SourceType::FileOrPipe: | ||
483 | source->setFileName(ui.leFileName->text()); | 495 | source->setFileName(fileName()); | ||
484 | source->setFileLinked(ui.chbLinkFile->isChecked()); | 496 | source->setFileLinked(ui.chbLinkFile->isChecked()); | ||
485 | break; | 497 | break; | ||
486 | case LiveDataSource::SourceType::LocalSocket: | 498 | case LiveDataSource::SourceType::LocalSocket: | ||
487 | source->setFileName(ui.leFileName->text()); | 499 | source->setFileName(fileName()); | ||
488 | source->setLocalSocketName(ui.leFileName->text()); | 500 | source->setLocalSocketName(fileName()); | ||
489 | break; | 501 | break; | ||
490 | case LiveDataSource::SourceType::NetworkTcpSocket: | 502 | case LiveDataSource::SourceType::NetworkTcpSocket: | ||
491 | case LiveDataSource::SourceType::NetworkUdpSocket: | 503 | case LiveDataSource::SourceType::NetworkUdpSocket: | ||
492 | source->setHost(ui.leHost->text()); | 504 | source->setHost(ui.leHost->text()); | ||
493 | source->setPort((quint16)ui.lePort->text().toInt()); | 505 | source->setPort((quint16)ui.lePort->text().toInt()); | ||
494 | break; | 506 | break; | ||
495 | case LiveDataSource::SourceType::SerialPort: | 507 | case LiveDataSource::SourceType::SerialPort: | ||
496 | source->setBaudRate(ui.cbBaudRate->currentText().toInt()); | 508 | source->setBaudRate(ui.cbBaudRate->currentText().toInt()); | ||
Show All 10 Lines | |||||
507 | /*! | 519 | /*! | ||
508 | saves the settings to the MQTTClient \c client. | 520 | saves the settings to the MQTTClient \c client. | ||
509 | */ | 521 | */ | ||
510 | void ImportFileWidget::saveMQTTSettings(MQTTClient* client) const { | 522 | void ImportFileWidget::saveMQTTSettings(MQTTClient* client) const { | ||
511 | DEBUG("ImportFileWidget::saveMQTTSettings"); | 523 | DEBUG("ImportFileWidget::saveMQTTSettings"); | ||
512 | MQTTClient::UpdateType updateType = static_cast<MQTTClient::UpdateType>(ui.cbUpdateType->currentIndex()); | 524 | MQTTClient::UpdateType updateType = static_cast<MQTTClient::UpdateType>(ui.cbUpdateType->currentIndex()); | ||
513 | MQTTClient::ReadingType readingType = static_cast<MQTTClient::ReadingType>(ui.cbReadingType->currentIndex()); | 525 | MQTTClient::ReadingType readingType = static_cast<MQTTClient::ReadingType>(ui.cbReadingType->currentIndex()); | ||
514 | 526 | | |||
515 | client->setComment(ui.leFileName->text()); | 527 | client->setComment(fileName()); | ||
516 | currentFileFilter(); | 528 | currentFileFilter(); | ||
517 | client->setFilter(static_cast<AsciiFilter*>(m_currentFilter.release())); // pass ownership of the filter to MQTTClient | 529 | client->setFilter(static_cast<AsciiFilter*>(m_currentFilter.release())); // pass ownership of the filter to MQTTClient | ||
518 | 530 | | |||
519 | client->setReadingType(readingType); | 531 | client->setReadingType(readingType); | ||
520 | 532 | | |||
521 | if (updateType == MQTTClient::UpdateType::TimeInterval) | 533 | if (updateType == MQTTClient::UpdateType::TimeInterval) | ||
522 | client->setUpdateInterval(ui.sbUpdateInterval->value()); | 534 | client->setUpdateInterval(ui.sbUpdateInterval->value()); | ||
523 | 535 | | |||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Line(s) | 757 | if (pos != -1) { | |||
747 | if (newDir != dir) | 759 | if (newDir != dir) | ||
748 | conf.writeEntry(QLatin1String("LastDir"), newDir); | 760 | conf.writeEntry(QLatin1String("LastDir"), newDir); | ||
749 | } | 761 | } | ||
750 | 762 | | |||
751 | //process all events after the FileDialog was closed to repaint the widget | 763 | //process all events after the FileDialog was closed to repaint the widget | ||
752 | //before we start calculating the preview | 764 | //before we start calculating the preview | ||
753 | QApplication::processEvents(QEventLoop::AllEvents, 0); | 765 | QApplication::processEvents(QEventLoop::AllEvents, 0); | ||
754 | 766 | | |||
755 | ui.leFileName->setText(path); | 767 | QStringList urls = m_cbFileName->urls(); | ||
768 | urls.append(path); | ||||
769 | m_cbFileName->setUrls(urls); | ||||
770 | fileNameChanged(urls.last()); // why do I have to call this function seperately | ||||
756 | } | 771 | } | ||
757 | 772 | | |||
758 | /*! | 773 | /*! | ||
759 | hides the MQTT related items of the widget | 774 | hides the MQTT related items of the widget | ||
760 | */ | 775 | */ | ||
761 | void ImportFileWidget::setMQTTVisible(bool visible) { | 776 | void ImportFileWidget::setMQTTVisible(bool visible) { | ||
762 | ui.lConnections->setVisible(visible); | 777 | ui.lConnections->setVisible(visible); | ||
763 | ui.cbConnection->setVisible(visible); | 778 | ui.cbConnection->setVisible(visible); | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 877 | /*! | |||
865 | and activates the corresponding options. | 880 | and activates the corresponding options. | ||
866 | */ | 881 | */ | ||
867 | void ImportFileWidget::fileNameChanged(const QString& name) { | 882 | void ImportFileWidget::fileNameChanged(const QString& name) { | ||
868 | DEBUG("ImportFileWidget::fileNameChanged()"); | 883 | DEBUG("ImportFileWidget::fileNameChanged()"); | ||
869 | const QString fileName = absolutePath(name); | 884 | const QString fileName = absolutePath(name); | ||
870 | 885 | | |||
871 | bool fileExists = QFile::exists(fileName); | 886 | bool fileExists = QFile::exists(fileName); | ||
872 | if (fileExists) | 887 | if (fileExists) | ||
873 | ui.leFileName->setStyleSheet(QString()); | 888 | m_cbFileName->setStyleSheet(QString()); | ||
874 | else | 889 | else | ||
875 | ui.leFileName->setStyleSheet("QLineEdit{background:red;}"); | 890 | m_cbFileName->setStyleSheet("QComboBox{background:red;}"); | ||
876 | 891 | | |||
877 | ui.gbOptions->setEnabled(fileExists); | 892 | ui.gbOptions->setEnabled(fileExists); | ||
878 | ui.bManageFilters->setEnabled(fileExists); | 893 | ui.bManageFilters->setEnabled(fileExists); | ||
879 | ui.cbFilter->setEnabled(fileExists); | 894 | ui.cbFilter->setEnabled(fileExists); | ||
880 | ui.cbFileType->setEnabled(fileExists); | 895 | ui.cbFileType->setEnabled(fileExists); | ||
881 | ui.bFileInfo->setEnabled(fileExists); | 896 | ui.bFileInfo->setEnabled(fileExists); | ||
882 | ui.gbUpdateOptions->setEnabled(fileExists); | 897 | ui.gbUpdateOptions->setEnabled(fileExists); | ||
883 | if (!fileExists) { | 898 | if (!fileExists) { | ||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | 956 | void ImportFileWidget::fileTypeChanged(int index) { | |||
1021 | ui.cbFilter->addItem( i18n("Automatic") ); | 1036 | ui.cbFilter->addItem( i18n("Automatic") ); | ||
1022 | ui.cbFilter->addItem( i18n("Custom") ); | 1037 | ui.cbFilter->addItem( i18n("Custom") ); | ||
1023 | 1038 | | |||
1024 | //TODO: populate the combobox with the available pre-defined filter settings for the selected type | 1039 | //TODO: populate the combobox with the available pre-defined filter settings for the selected type | ||
1025 | ui.cbFilter->setCurrentIndex(lastUsedFilterIndex); | 1040 | ui.cbFilter->setCurrentIndex(lastUsedFilterIndex); | ||
1026 | filterChanged(lastUsedFilterIndex); | 1041 | filterChanged(lastUsedFilterIndex); | ||
1027 | 1042 | | |||
1028 | if (currentSourceType() == LiveDataSource::FileOrPipe) { | 1043 | if (currentSourceType() == LiveDataSource::FileOrPipe) { | ||
1029 | const QString& fileName = absolutePath(ui.leFileName->text()); | 1044 | QString tempFileName = fileName(); | ||
1045 | const QString& fileName = absolutePath(tempFileName); | ||||
1030 | if (QFile::exists(fileName)) | 1046 | if (QFile::exists(fileName)) | ||
1031 | updateContent(fileName); | 1047 | updateContent(fileName); | ||
1032 | } | 1048 | } | ||
1033 | 1049 | | |||
1034 | //for file types other than ASCII and binary we support re-reading the whole file only | 1050 | //for file types other than ASCII and binary we support re-reading the whole file only | ||
1035 | //select "read whole file" and deactivate the combobox | 1051 | //select "read whole file" and deactivate the combobox | ||
1036 | if (m_liveDataSource && (fileType != AbstractFileFilter::Ascii && fileType != AbstractFileFilter::Binary)) { | 1052 | if (m_liveDataSource && (fileType != AbstractFileFilter::Ascii && fileType != AbstractFileFilter::Binary)) { | ||
1037 | ui.cbReadingType->setCurrentIndex(LiveDataSource::ReadingType::WholeFile); | 1053 | ui.cbReadingType->setCurrentIndex(LiveDataSource::ReadingType::WholeFile); | ||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | |||||
1150 | const QStringList ImportFileWidget::selectedROOTNames() const { | 1166 | const QStringList ImportFileWidget::selectedROOTNames() const { | ||
1151 | return m_rootOptionsWidget->selectedNames(); | 1167 | return m_rootOptionsWidget->selectedNames(); | ||
1152 | } | 1168 | } | ||
1153 | 1169 | | |||
1154 | /*! | 1170 | /*! | ||
1155 | shows the dialog with the information about the file(s) to be imported. | 1171 | shows the dialog with the information about the file(s) to be imported. | ||
1156 | */ | 1172 | */ | ||
1157 | void ImportFileWidget::fileInfoDialog() { | 1173 | void ImportFileWidget::fileInfoDialog() { | ||
1158 | QStringList files = ui.leFileName->text().split(';'); | 1174 | QStringList files = fileName().split(';'); | ||
1159 | auto* dlg = new FileInfoDialog(this); | 1175 | auto* dlg = new FileInfoDialog(this); | ||
1160 | dlg->setFiles(files); | 1176 | dlg->setFiles(files); | ||
1161 | dlg->exec(); | 1177 | dlg->exec(); | ||
1162 | } | 1178 | } | ||
1163 | 1179 | | |||
1164 | /*! | 1180 | /*! | ||
1165 | enables the options if the filter "custom" was chosen. Disables the options otherwise. | 1181 | enables the options if the filter "custom" was chosen. Disables the options otherwise. | ||
1166 | */ | 1182 | */ | ||
Show All 20 Lines | |||||
1187 | 1203 | | |||
1188 | void ImportFileWidget::refreshPreview() { | 1204 | void ImportFileWidget::refreshPreview() { | ||
1189 | if (m_suppressRefresh) | 1205 | if (m_suppressRefresh) | ||
1190 | return; | 1206 | return; | ||
1191 | 1207 | | |||
1192 | DEBUG("ImportFileWidget::refreshPreview()"); | 1208 | DEBUG("ImportFileWidget::refreshPreview()"); | ||
1193 | WAIT_CURSOR; | 1209 | WAIT_CURSOR; | ||
1194 | 1210 | | |||
1195 | QString fileName = absolutePath(ui.leFileName->text()); | 1211 | QString tempFileName = fileName(); | ||
1212 | QString fileName = absolutePath(tempFileName); | ||||
1196 | AbstractFileFilter::FileType fileType = currentFileType(); | 1213 | AbstractFileFilter::FileType fileType = currentFileType(); | ||
we don't really need this temp variable. Let's do it directly with QString fileName = absolutePath(fileName()); asemke: we don't really need this temp variable. Let's do it directly with QString fileName =… | |||||
1197 | LiveDataSource::SourceType sourceType = currentSourceType(); | 1214 | LiveDataSource::SourceType sourceType = currentSourceType(); | ||
1198 | int lines = ui.sbPreviewLines->value(); | 1215 | int lines = ui.sbPreviewLines->value(); | ||
1199 | 1216 | | |||
1200 | if (sourceType == LiveDataSource::SourceType::FileOrPipe) | 1217 | if (sourceType == LiveDataSource::SourceType::FileOrPipe) | ||
1201 | DEBUG("refreshPreview(): file name = " << fileName.toStdString()); | 1218 | DEBUG("refreshPreview(): file name = " << fileName.toStdString()); | ||
1202 | 1219 | | |||
1203 | // generic table widget | 1220 | // generic table widget | ||
1204 | if (fileType == AbstractFileFilter::Ascii || fileType == AbstractFileFilter::Binary | 1221 | if (fileType == AbstractFileFilter::Ascii || fileType == AbstractFileFilter::Binary | ||
▲ Show 20 Lines • Show All 335 Lines • ▼ Show 20 Line(s) | 1555 | void ImportFileWidget::sourceTypeChanged(int idx) { | |||
1540 | 1557 | | |||
1541 | // enable/disable "on new data"-option | 1558 | // enable/disable "on new data"-option | ||
1542 | const auto* model = qobject_cast<const QStandardItemModel*>(ui.cbUpdateType->model()); | 1559 | const auto* model = qobject_cast<const QStandardItemModel*>(ui.cbUpdateType->model()); | ||
1543 | QStandardItem* item = model->item(LiveDataSource::UpdateType::NewData); | 1560 | QStandardItem* item = model->item(LiveDataSource::UpdateType::NewData); | ||
1544 | 1561 | | |||
1545 | switch (sourceType) { | 1562 | switch (sourceType) { | ||
1546 | case LiveDataSource::SourceType::FileOrPipe: | 1563 | case LiveDataSource::SourceType::FileOrPipe: | ||
1547 | ui.lFileName->show(); | 1564 | ui.lFileName->show(); | ||
1548 | ui.leFileName->show(); | 1565 | m_cbFileName->show(); | ||
1549 | ui.bFileInfo->show(); | 1566 | ui.bFileInfo->show(); | ||
1550 | ui.bOpen->show(); | 1567 | ui.bOpen->show(); | ||
1551 | ui.chbLinkFile->show(); | 1568 | ui.chbLinkFile->show(); | ||
1552 | 1569 | | |||
1553 | //option for sample size are available for "continuously fixed" and "from end" reading options | 1570 | //option for sample size are available for "continuously fixed" and "from end" reading options | ||
1554 | if (ui.cbReadingType->currentIndex() < 2) { | 1571 | if (ui.cbReadingType->currentIndex() < 2) { | ||
1555 | ui.lSampleSize->show(); | 1572 | ui.lSampleSize->show(); | ||
1556 | ui.sbSampleSize->show(); | 1573 | ui.sbSampleSize->show(); | ||
1557 | } else { | 1574 | } else { | ||
1558 | ui.lSampleSize->hide(); | 1575 | ui.lSampleSize->hide(); | ||
1559 | ui.sbSampleSize->hide(); | 1576 | ui.sbSampleSize->hide(); | ||
1560 | } | 1577 | } | ||
1561 | 1578 | | |||
1562 | ui.cbBaudRate->hide(); | 1579 | ui.cbBaudRate->hide(); | ||
1563 | ui.lBaudRate->hide(); | 1580 | ui.lBaudRate->hide(); | ||
1564 | ui.lHost->hide(); | 1581 | ui.lHost->hide(); | ||
1565 | ui.leHost->hide(); | 1582 | ui.leHost->hide(); | ||
1566 | ui.lPort->hide(); | 1583 | ui.lPort->hide(); | ||
1567 | ui.lePort->hide(); | 1584 | ui.lePort->hide(); | ||
1568 | ui.cbSerialPort->hide(); | 1585 | ui.cbSerialPort->hide(); | ||
1569 | ui.lSerialPort->hide(); | 1586 | ui.lSerialPort->hide(); | ||
1570 | 1587 | | |||
1571 | item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | 1588 | item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | ||
1572 | 1589 | | |||
1573 | fileNameChanged(ui.leFileName->text()); | 1590 | fileNameChanged(fileName()); | ||
1574 | ui.cbFileType->show(); | 1591 | ui.cbFileType->show(); | ||
1575 | ui.lFileType->show(); | 1592 | ui.lFileType->show(); | ||
1576 | setMQTTVisible(false); | 1593 | setMQTTVisible(false); | ||
1577 | break; | 1594 | break; | ||
1578 | case LiveDataSource::SourceType::NetworkTcpSocket: | 1595 | case LiveDataSource::SourceType::NetworkTcpSocket: | ||
1579 | case LiveDataSource::SourceType::NetworkUdpSocket: | 1596 | case LiveDataSource::SourceType::NetworkUdpSocket: | ||
1580 | ui.lHost->show(); | 1597 | ui.lHost->show(); | ||
1581 | ui.leHost->show(); | 1598 | ui.leHost->show(); | ||
1582 | ui.lePort->show(); | 1599 | ui.lePort->show(); | ||
1583 | ui.lPort->show(); | 1600 | ui.lPort->show(); | ||
1584 | if (sourceType == LiveDataSource::SourceType::NetworkTcpSocket) { | 1601 | if (sourceType == LiveDataSource::SourceType::NetworkTcpSocket) { | ||
1585 | ui.lSampleSize->hide(); | 1602 | ui.lSampleSize->hide(); | ||
1586 | ui.sbSampleSize->hide(); | 1603 | ui.sbSampleSize->hide(); | ||
1587 | } else { | 1604 | } else { | ||
1588 | ui.lSampleSize->show(); | 1605 | ui.lSampleSize->show(); | ||
1589 | ui.sbSampleSize->show(); | 1606 | ui.sbSampleSize->show(); | ||
1590 | } | 1607 | } | ||
1591 | 1608 | | |||
1592 | ui.lBaudRate->hide(); | 1609 | ui.lBaudRate->hide(); | ||
1593 | ui.cbBaudRate->hide(); | 1610 | ui.cbBaudRate->hide(); | ||
1594 | ui.lSerialPort->hide(); | 1611 | ui.lSerialPort->hide(); | ||
1595 | ui.cbSerialPort->hide(); | 1612 | ui.cbSerialPort->hide(); | ||
1596 | 1613 | | |||
1597 | ui.lFileName->hide(); | 1614 | ui.lFileName->hide(); | ||
1598 | ui.leFileName->hide(); | 1615 | m_cbFileName->hide(); | ||
1599 | ui.bFileInfo->hide(); | 1616 | ui.bFileInfo->hide(); | ||
1600 | ui.bOpen->hide(); | 1617 | ui.bOpen->hide(); | ||
1601 | ui.chbLinkFile->hide(); | 1618 | ui.chbLinkFile->hide(); | ||
1602 | 1619 | | |||
1603 | item->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled)); | 1620 | item->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled)); | ||
1604 | 1621 | | |||
1605 | ui.gbOptions->setEnabled(true); | 1622 | ui.gbOptions->setEnabled(true); | ||
1606 | ui.bManageFilters->setEnabled(true); | 1623 | ui.bManageFilters->setEnabled(true); | ||
1607 | ui.cbFilter->setEnabled(true); | 1624 | ui.cbFilter->setEnabled(true); | ||
1608 | ui.cbFileType->setEnabled(true); | 1625 | ui.cbFileType->setEnabled(true); | ||
1609 | ui.cbFileType->show(); | 1626 | ui.cbFileType->show(); | ||
1610 | ui.lFileType->show(); | 1627 | ui.lFileType->show(); | ||
1611 | setMQTTVisible(false); | 1628 | setMQTTVisible(false); | ||
1612 | break; | 1629 | break; | ||
1613 | case LiveDataSource::SourceType::LocalSocket: | 1630 | case LiveDataSource::SourceType::LocalSocket: | ||
1614 | ui.lFileName->show(); | 1631 | ui.lFileName->show(); | ||
1615 | ui.leFileName->show(); | 1632 | m_cbFileName->show(); | ||
1616 | ui.bOpen->show(); | 1633 | ui.bOpen->show(); | ||
1617 | ui.lSampleSize->hide(); | 1634 | ui.lSampleSize->hide(); | ||
1618 | ui.sbSampleSize->hide(); | 1635 | ui.sbSampleSize->hide(); | ||
1619 | 1636 | | |||
1620 | ui.bFileInfo->hide(); | 1637 | ui.bFileInfo->hide(); | ||
1621 | ui.cbBaudRate->hide(); | 1638 | ui.cbBaudRate->hide(); | ||
1622 | ui.lBaudRate->hide(); | 1639 | ui.lBaudRate->hide(); | ||
1623 | ui.lHost->hide(); | 1640 | ui.lHost->hide(); | ||
Show All 22 Lines | 1658 | case LiveDataSource::SourceType::SerialPort: | |||
1646 | ui.lSampleSize->show(); | 1663 | ui.lSampleSize->show(); | ||
1647 | ui.sbSampleSize->show(); | 1664 | ui.sbSampleSize->show(); | ||
1648 | 1665 | | |||
1649 | ui.lHost->hide(); | 1666 | ui.lHost->hide(); | ||
1650 | ui.leHost->hide(); | 1667 | ui.leHost->hide(); | ||
1651 | ui.lePort->hide(); | 1668 | ui.lePort->hide(); | ||
1652 | ui.lPort->hide(); | 1669 | ui.lPort->hide(); | ||
1653 | ui.lFileName->hide(); | 1670 | ui.lFileName->hide(); | ||
1654 | ui.leFileName->hide(); | 1671 | m_cbFileName->hide(); | ||
1655 | ui.bFileInfo->hide(); | 1672 | ui.bFileInfo->hide(); | ||
1656 | ui.bOpen->hide(); | 1673 | ui.bOpen->hide(); | ||
1657 | ui.chbLinkFile->hide(); | 1674 | ui.chbLinkFile->hide(); | ||
1658 | 1675 | | |||
1659 | item->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled)); | 1676 | item->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled)); | ||
1660 | 1677 | | |||
1661 | ui.cbFileType->setEnabled(true); | 1678 | ui.cbFileType->setEnabled(true); | ||
1662 | ui.cbFileType->show(); | 1679 | ui.cbFileType->show(); | ||
Show All 25 Lines | 1687 | #ifdef HAVE_MQTT | |||
1688 | ui.cbBaudRate->hide(); | 1705 | ui.cbBaudRate->hide(); | ||
1689 | ui.lSerialPort->hide(); | 1706 | ui.lSerialPort->hide(); | ||
1690 | ui.cbSerialPort->hide(); | 1707 | ui.cbSerialPort->hide(); | ||
1691 | ui.lHost->hide(); | 1708 | ui.lHost->hide(); | ||
1692 | ui.leHost->hide(); | 1709 | ui.leHost->hide(); | ||
1693 | ui.lPort->hide(); | 1710 | ui.lPort->hide(); | ||
1694 | ui.lePort->hide(); | 1711 | ui.lePort->hide(); | ||
1695 | ui.lFileName->hide(); | 1712 | ui.lFileName->hide(); | ||
1696 | ui.leFileName->hide(); | 1713 | m_cbFileName->hide(); | ||
1697 | ui.bFileInfo->hide(); | 1714 | ui.bFileInfo->hide(); | ||
1698 | ui.bOpen->hide(); | 1715 | ui.bOpen->hide(); | ||
1699 | ui.chbLinkFile->hide(); | 1716 | ui.chbLinkFile->hide(); | ||
1700 | 1717 | | |||
1701 | setMQTTVisible(true); | 1718 | setMQTTVisible(true); | ||
1702 | 1719 | | |||
1703 | ui.cbFileType->setEnabled(true); | 1720 | ui.cbFileType->setEnabled(true); | ||
1704 | ui.gbOptions->setEnabled(true); | 1721 | ui.gbOptions->setEnabled(true); | ||
▲ Show 20 Lines • Show All 389 Lines • Show Last 20 Lines |
no brackets for one-liners