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

Method importTo

src/frontend/datasources/ImportFileDialog.cpp:168–343  ·  view source on GitHub ↗

! triggers data import to the currently selected data container */

Source from the content-addressed store, hash-verified

166 triggers data import to the currently selected data container
167*/
168bool ImportFileDialog::importTo(QStatusBar* statusBar) const {
169 QDEBUG(" cbAddTo->currentModelIndex() =" << cbAddTo->currentModelIndex());
170 AbstractAspect* aspect = static_cast<AbstractAspect*>(cbAddTo->currentModelIndex().internalPointer());
171 if (!aspect) {
172 DEBUG(Q_FUNC_INFO << ", ERROR: No aspect available");
173 DEBUG(" cbAddTo->currentModelIndex().isValid() = " << cbAddTo->currentModelIndex().isValid());
174 DEBUG(" cbAddTo->currentModelIndex() row/column = " << cbAddTo->currentModelIndex().row() << ' ' << cbAddTo->currentModelIndex().column());
175 const_cast<ImportFileDialog*>(this)->showErrorMessage(i18n("No target data container selected"));
176 return false;
177 }
178
179 QString fileName = m_importFileWidget->fileName();
180 DEBUG(Q_FUNC_INFO << ", file name: " << fileName.toStdString());
181 auto mode = AbstractFileFilter::ImportMode(cbPosition->currentIndex());
182
183 // show a progress bar in the status bar
184 auto* progressBar = new QProgressBar();
185 progressBar->setRange(0, 100);
186 auto* filter = m_importFileWidget->currentFileFilter();
187 filter->setLastError(QString()); // clear the previos error, if any available
188 filter->clearLastWarnings(); // clear the previos warnings, if any available
189 connect(filter, &AbstractFileFilter::completed, progressBar, &QProgressBar::setValue);
190
191 statusBar->clearMessage();
192 statusBar->addWidget(progressBar, 1);
193
194 WAIT_CURSOR;
195 QApplication::processEvents(QEventLoop::AllEvents, 100);
196
197 QElapsedTimer timer;
198 timer.start();
199
200 if (aspect->inherits(AspectType::Matrix)) {
201 DEBUG(Q_FUNC_INFO << ", to Matrix");
202 auto* matrix = qobject_cast<Matrix*>(aspect);
203 filter->readDataFromFile(fileName, matrix, mode);
204 } else if (aspect->inherits(AspectType::Spreadsheet)) {
205 DEBUG(Q_FUNC_INFO << ", to Spreadsheet");
206 auto* spreadsheet = qobject_cast<Spreadsheet*>(aspect);
207 DEBUG("CALLING filter->readDataFromFile()")
208 // TODO: which extension (table) is imported?
209 filter->readDataFromFile(fileName, spreadsheet, mode);
210 } else if (aspect->inherits(AspectType::Workbook)) {
211 DEBUG(Q_FUNC_INFO << ", to Workbook");
212 auto* workbook = static_cast<Workbook*>(aspect);
213 workbook->setUndoAware(false);
214 auto sheets = workbook->children<AbstractAspect>();
215
216 auto fileType = m_importFileWidget->currentFileType();
217 // types supporting multiple data sets/variables
218 if (fileType == AbstractFileFilter::FileType::HDF5 || fileType == AbstractFileFilter::FileType::NETCDF || fileType == AbstractFileFilter::FileType::ROOT
219 || fileType == AbstractFileFilter::FileType::MATIO || fileType == AbstractFileFilter::FileType::XLSX
220 || fileType == AbstractFileFilter::FileType::Ods || fileType == AbstractFileFilter::FileType::VECTOR_BLF) {
221 QStringList names;
222 if (fileType == AbstractFileFilter::FileType::HDF5)
223 names = m_importFileWidget->selectedHDF5Names();
224 else if (fileType == AbstractFileFilter::FileType::VECTOR_BLF)
225 names = QStringList({QStringLiteral("TODO")}); // m_importFileWidget->selectedVectorBLFNames();

Callers 15

ifFunction · 0.45
importProjectDialogMethod · 0.45
testOrigin01Method · 0.45
testOrigin02Method · 0.45
testOrigin03Method · 0.45
testOrigin04Method · 0.45
testOrigin_2graphsMethod · 0.45
testOriginHistogramMethod · 0.45
testOriginBarPlotMethod · 0.45

Calls 15

ImportModeEnum · 0.85
currentModelIndexMethod · 0.80
toStdStringMethod · 0.80
currentFileFilterMethod · 0.80
clearLastWarningsMethod · 0.80
inheritsMethod · 0.80
setUndoAwareMethod · 0.80
currentFileTypeMethod · 0.80
selectedHDF5NamesMethod · 0.80
selectedNetCDFNamesMethod · 0.80
selectedROOTNamesMethod · 0.80
selectedMatioNamesMethod · 0.80

Tested by 15

testOrigin01Method · 0.36
testOrigin02Method · 0.36
testOrigin03Method · 0.36
testOrigin04Method · 0.36
testOrigin_2graphsMethod · 0.36
testOriginHistogramMethod · 0.36
testOriginBarPlotMethod · 0.36