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

Method ImportFileDialog

src/frontend/datasources/ImportFileDialog.cpp:50–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48 */
49
50ImportFileDialog::ImportFileDialog(MainWin* parent, bool liveDataSource, const QString& fileName)
51 : ImportDialog(parent)
52 , m_importFileWidget(new ImportFileWidget(this, liveDataSource, fileName)) {
53 vLayout->addWidget(m_importFileWidget);
54 m_liveDataSource = liveDataSource;
55
56 // dialog buttons
57 auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Reset | QDialogButtonBox::Cancel);
58 okButton = buttonBox->button(QDialogButtonBox::Ok);
59 m_optionsButton = buttonBox->button(QDialogButtonBox::Reset); // we highjack the default "Reset" button and use if for showing/hiding the options
60 okButton->setEnabled(false); // ok is only available if a valid container was selected
61 vLayout->addWidget(buttonBox);
62
63 if (!liveDataSource)
64 setModel(); // set the model and hide the data-source related widgets
65 else
66 setAttribute(Qt::WA_DeleteOnClose, false); // don't delete on close for live data sources, it's done in MainWin::newLiveDataSource()
67
68 // Signals/Slots
69 connect(buttonBox, &QDialogButtonBox::accepted, this, &ImportDialog::accept);
70 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
71
72 if (!liveDataSource)
73 setWindowTitle(i18nc("@title:window", "Import Data to Spreadsheet or Matrix"));
74 else
75 setWindowTitle(i18nc("@title:window", "Add New Live Data Source"));
76
77 setWindowIcon(QIcon::fromTheme(QStringLiteral("document-import-database")));
78
79 // restore saved settings if available
80 create(); // ensure there's a window created
81
82 KConfigGroup conf = Settings::group(QStringLiteral("ImportFileDialog"));
83 if (conf.exists()) {
84 m_showOptions = conf.readEntry("ShowOptions", false);
85
86 KWindowConfig::restoreWindowSize(windowHandle(), conf);
87 resize(windowHandle()->size()); // workaround for QTBUG-40584
88 } else
89 resize(QSize(0, 0).expandedTo(minimumSize()));
90
91 m_importFileWidget->showOptions(m_showOptions);
92 // do the signal-slot connections after all settings were loaded in import file widget and check the OK button after this
93 connect(m_importFileWidget, &ImportFileWidget::enableImportToMatrix, this, &ImportFileDialog::enableImportToMatrix);
94 connect(m_importFileWidget, QOverload<>::of(&ImportFileWidget::fileNameChanged), this, &ImportFileDialog::checkOkButton);
95 connect(m_importFileWidget, QOverload<>::of(&ImportFileWidget::sourceTypeChanged), this, &ImportFileDialog::checkOkButton);
96 connect(m_importFileWidget, &ImportFileWidget::hostChanged, this, &ImportFileDialog::checkOkButton);
97 connect(m_importFileWidget, &ImportFileWidget::portChanged, this, &ImportFileDialog::checkOkButton);
98 connect(m_importFileWidget, &ImportFileWidget::error, this, &ImportFileDialog::showErrorMessage);
99 connect(m_importFileWidget, &ImportFileWidget::previewReady, this, &ImportFileDialog::checkOkButton);
100 connect(this, &ImportDialog::dataContainerChanged, m_importFileWidget, &ImportFileWidget::dataContainerChanged);
101#ifdef HAVE_MQTT
102 connect(m_importFileWidget, &ImportFileWidget::subscriptionsChanged, this, &ImportFileDialog::checkOkButton);
103 connect(m_importFileWidget, &ImportFileWidget::checkFileType, this, &ImportFileDialog::checkOkButton);
104#endif
105
106 m_showOptions ? m_optionsButton->setText(i18n("Hide Options")) : m_optionsButton->setText(i18n("Show Options"));
107 connect(m_optionsButton, &QPushButton::clicked, this, &ImportFileDialog::toggleOptions);

Callers

nothing calls this directly

Calls 8

groupFunction · 0.85
buttonMethod · 0.80
existsMethod · 0.80
setEnabledMethod · 0.45
sizeMethod · 0.45
showOptionsMethod · 0.45
setTextMethod · 0.45
loadSettingsMethod · 0.45

Tested by

no test coverage detected