Model data can be exported to CSV file.
This commit is contained in:
@ -248,11 +248,32 @@ void MainWindow::importCSV() {
|
||||
tr("CSV Files (*.csv)"));
|
||||
if (QFileInfo::exists(csvFilePath)) {
|
||||
m_core->importCSVFile(csvFilePath);
|
||||
showStatusMessage(tr("Imported CSV file."));
|
||||
} else {
|
||||
qWarning() << "Selected CSV file path doesn't exist. Doing nothing...";
|
||||
showStatusMessage(tr("Could't find CSV file!"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::exportCSV() {
|
||||
showStatusMessage(tr("Invoked 'File|Export'"));
|
||||
const QString filter = tr("CSV Files (*.csv)");
|
||||
const QString location = QStandardPaths::standardLocations(standardLocation).first();
|
||||
QFileDialog dialog(this, "Export CSV File", location, "Comma-separated file (*.csv)");
|
||||
dialog.setDefaultSuffix(".csv");
|
||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
if (dialog.exec()) {
|
||||
const QString csvFilePath = dialog.selectedFiles().first();
|
||||
const bool successful = m_core->exportCSVFile(csvFilePath);
|
||||
if (successful) {
|
||||
const QString message = QString(tr("CSV exported to: %1")).arg(csvFilePath);
|
||||
showStatusMessage(message);
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Selected CSV file path doesn't exist. Doing nothing...";
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::createActions() {
|
||||
// TODO add generic menu actions (file/new, edit/cut, ...)
|
||||
createFileActions();
|
||||
@ -290,8 +311,7 @@ void MainWindow::createFileActions() {
|
||||
|
||||
m_exportAct = make_unique<QAction>(tr("&Export CSV..."), this);
|
||||
m_exportAct->setStatusTip(tr("Export content to a CSV document to disk"));
|
||||
// connect(m_exportAct, &QAction::triggered, this, &MainWindow::exportCSV);
|
||||
m_exportAct->setEnabled(false);
|
||||
connect(m_exportAct.get(), &QAction::triggered, this, &MainWindow::exportCSV);
|
||||
ui->menu_File->addAction(m_exportAct.get());
|
||||
|
||||
ui->menu_File->addSeparator();
|
||||
|
||||
Reference in New Issue
Block a user