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

Method importTo

src/frontend/datasources/ImportSQLDatabaseDialog.cpp:72–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72bool ImportSQLDatabaseDialog::importTo(QStatusBar* statusBar) const {
73 DEBUG("ImportSQLDatabaseDialog::import()");
74 AbstractAspect* aspect = static_cast<AbstractAspect*>(cbAddTo->currentModelIndex().internalPointer());
75 if (!aspect) {
76 DEBUG("ERROR: No aspect available!");
77 return false;
78 }
79
80 const auto mode = AbstractFileFilter::ImportMode(cbPosition->currentIndex());
81
82 // show a progress bar in the status bar
83 auto* progressBar = new QProgressBar();
84 progressBar->setMinimum(0);
85 progressBar->setMaximum(100);
86 connect(importSQLDatabaseWidget, &ImportSQLDatabaseWidget::completed, progressBar, &QProgressBar::setValue);
87
88 statusBar->clearMessage();
89 statusBar->addWidget(progressBar, 1);
90
91 WAIT_CURSOR;
92 QApplication::processEvents(QEventLoop::AllEvents, 100);
93
94 // TODO: error handling
95 QElapsedTimer timer;
96 timer.start();
97 if (aspect->inherits(AspectType::Matrix)) {
98 auto* matrix = qobject_cast<Matrix*>(aspect);
99 importSQLDatabaseWidget->read(matrix, mode);
100 } else if (aspect->inherits(AspectType::Spreadsheet)) {
101 auto* spreadsheet = qobject_cast<Spreadsheet*>(aspect);
102 importSQLDatabaseWidget->read(spreadsheet, mode);
103 } else if (aspect->inherits(AspectType::Workbook)) {
104 // use active spreadsheet or matrix (only if numeric data is going to be imported) if present,
105 // create a new spreadsheet in the selected workbook otherwise
106 auto* workbook = qobject_cast<Workbook*>(aspect);
107 Spreadsheet* spreadsheet = workbook->currentSpreadsheet();
108 Matrix* matrix = workbook->currentMatrix();
109 if (spreadsheet)
110 importSQLDatabaseWidget->read(spreadsheet, mode);
111 else if (matrix && importSQLDatabaseWidget->isNumericData())
112 importSQLDatabaseWidget->read(matrix, mode);
113 else {
114 spreadsheet = new Spreadsheet(i18n("Spreadsheet"));
115 workbook->addChild(spreadsheet);
116 importSQLDatabaseWidget->read(spreadsheet, mode);
117 }
118 }
119 statusBar->showMessage(i18n("Data imported in %1 seconds.", (float)timer.elapsed() / 1000));
120
121 RESET_CURSOR;
122 statusBar->removeWidget(progressBar);
123 return true;
124}
125
126QString ImportSQLDatabaseDialog::selectedObject() const {
127 return importSQLDatabaseWidget->selectedTable();

Callers

nothing calls this directly

Calls 14

ImportModeEnum · 0.85
currentModelIndexMethod · 0.80
setMinimumMethod · 0.80
setMaximumMethod · 0.80
inheritsMethod · 0.80
currentMatrixMethod · 0.80
isNumericDataMethod · 0.80
showMessageMethod · 0.80
removeWidgetMethod · 0.80
currentIndexMethod · 0.45
startMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected