Model data can be exported to CSV file.
This commit is contained in:
@ -248,11 +248,32 @@ void MainWindow::importCSV() {
|
|||||||
tr("CSV Files (*.csv)"));
|
tr("CSV Files (*.csv)"));
|
||||||
if (QFileInfo::exists(csvFilePath)) {
|
if (QFileInfo::exists(csvFilePath)) {
|
||||||
m_core->importCSVFile(csvFilePath);
|
m_core->importCSVFile(csvFilePath);
|
||||||
|
showStatusMessage(tr("Imported CSV file."));
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Selected CSV file path doesn't exist. Doing nothing...";
|
qWarning() << "Selected CSV file path doesn't exist. Doing nothing...";
|
||||||
showStatusMessage(tr("Could't find CSV file!"));
|
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() {
|
void MainWindow::createActions() {
|
||||||
// TODO add generic menu actions (file/new, edit/cut, ...)
|
// TODO add generic menu actions (file/new, edit/cut, ...)
|
||||||
createFileActions();
|
createFileActions();
|
||||||
@ -290,8 +311,7 @@ void MainWindow::createFileActions() {
|
|||||||
|
|
||||||
m_exportAct = make_unique<QAction>(tr("&Export CSV..."), this);
|
m_exportAct = make_unique<QAction>(tr("&Export CSV..."), this);
|
||||||
m_exportAct->setStatusTip(tr("Export content to a CSV document to disk"));
|
m_exportAct->setStatusTip(tr("Export content to a CSV document to disk"));
|
||||||
// connect(m_exportAct, &QAction::triggered, this, &MainWindow::exportCSV);
|
connect(m_exportAct.get(), &QAction::triggered, this, &MainWindow::exportCSV);
|
||||||
m_exportAct->setEnabled(false);
|
|
||||||
ui->menu_File->addAction(m_exportAct.get());
|
ui->menu_File->addAction(m_exportAct.get());
|
||||||
|
|
||||||
ui->menu_File->addSeparator();
|
ui->menu_File->addSeparator();
|
||||||
|
|||||||
@ -57,6 +57,7 @@ class MainWindow : public QMainWindow {
|
|||||||
/// 'File' slots
|
/// 'File' slots
|
||||||
void saveItems();
|
void saveItems();
|
||||||
void importCSV();
|
void importCSV();
|
||||||
|
void exportCSV();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
|
|||||||
Reference in New Issue
Block a user