MCPcopy Create free account
hub / github.com/KDE/labplot / checkOkButton

Method checkOkButton

src/frontend/datasources/ImportFileDialog.cpp:374–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372}
373
374void ImportFileDialog::checkOkButton() {
375 DEBUG(Q_FUNC_INFO);
376 if (cbAddTo) { // only check for the target container when no file data source is being added
377 QDEBUG(" cbAddTo->currentModelIndex() = " << cbAddTo->currentModelIndex());
378 AbstractAspect* aspect = static_cast<AbstractAspect*>(cbAddTo->currentModelIndex().internalPointer());
379 if (!aspect) {
380 okButton->setEnabled(false);
381 okButton->setToolTip(i18n("Select a data container where the data has to be imported into."));
382 lPosition->setEnabled(false);
383 cbPosition->setEnabled(false);
384 cbAddTo->setFocus(); // set the focus to make the user aware about the fact that a data container needs to be provided
385 return;
386 } else {
387 lPosition->setEnabled(true);
388 cbPosition->setEnabled(true);
389 }
390 }
391
392 QString fileName = ImportFileWidget::absolutePath(m_importFileWidget->fileName());
393 const auto sourceType = m_importFileWidget->currentSourceType();
394 switch (sourceType) {
395 case LiveDataSource::SourceType::FileOrPipe: // fall through
396 case LiveDataSource::SourceType::LocalSocket: {
397 if (fileName.isEmpty()) {
398 okButton->setEnabled(false);
399 okButton->setToolTip(i18n("No file provided for import."));
400 return;
401 }
402 break;
403 }
404 case LiveDataSource::SourceType::NetworkTCPSocket: // fall through
405 case LiveDataSource::SourceType::NetworkUDPSocket: // fall through
406 case LiveDataSource::SourceType::SerialPort: // fall through
407 case LiveDataSource::SourceType::MQTT: // fall through
408 break;
409 }
410
411 // process all events first so the dialog is completely drawn before we wait for the socket connect below
412 QApplication::processEvents(QEventLoop::AllEvents, 100);
413
414 DEBUG(Q_FUNC_INFO << ", Data Source Type: " << ENUM_TO_STRING(LiveDataSource, SourceType, sourceType));
415 switch (sourceType) {
416 case LiveDataSource::SourceType::FileOrPipe: {
417 DEBUG(Q_FUNC_INFO << ", fileName = " << qPrintable(fileName));
418 const bool enable = QFile::exists(fileName);
419 if (enable)
420 showErrorMessage(QString());
421 else {
422 // suppress the error widget when the dialog is opened the first time.
423 // show only the error widget if the file was really a non-existing file.
424 showErrorMessage(i18n("The provided file doesn't exist."));
425 }
426
427 break;
428 }
429 case LiveDataSource::SourceType::LocalSocket: {
430 const bool enable = QFile::exists(fileName);
431 if (enable) {

Callers

nothing calls this directly

Calls 15

currentModelIndexMethod · 0.80
setToolTipMethod · 0.80
currentSourceTypeMethod · 0.80
serialPortMethod · 0.80
setBaudRateMethod · 0.80
errorMethod · 0.80
isMqttValidMethod · 0.80
QStringClass · 0.50
setEnabledMethod · 0.45
setFocusMethod · 0.45
fileNameMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected