Model items can be imported from CSV file.
This commit is contained in:
@ -2,7 +2,9 @@
|
|||||||
#include "./ui_mainwindow.h"
|
#include "./ui_mainwindow.h"
|
||||||
|
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
#include <QUndoView>
|
#include <QUndoView>
|
||||||
|
|
||||||
@ -13,6 +15,7 @@
|
|||||||
#include "genericcore.h"
|
#include "genericcore.h"
|
||||||
#include "model/tablemodel.h"
|
#include "model/tablemodel.h"
|
||||||
|
|
||||||
|
static QStandardPaths::StandardLocation standardLocation = QStandardPaths::HomeLocation;
|
||||||
static QString updateTextClean = "Do you want to update the application now?";
|
static QString updateTextClean = "Do you want to update the application now?";
|
||||||
static QString updateTextDirty = "Do you want to save the tasks & update the application now?";
|
static QString updateTextDirty = "Do you want to save the tasks & update the application now?";
|
||||||
|
|
||||||
@ -238,6 +241,18 @@ void MainWindow::saveItems() {
|
|||||||
m_core->saveItems();
|
m_core->saveItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::importCSV() {
|
||||||
|
showStatusMessage(tr("Invoked 'File|Import CSV'"));
|
||||||
|
const QString csvFilePath = QFileDialog::getOpenFileName(
|
||||||
|
this, tr("Import CSV"), QStandardPaths::standardLocations(standardLocation).first(),
|
||||||
|
tr("CSV Files (*.csv)"));
|
||||||
|
if (QFileInfo::exists(csvFilePath)) {
|
||||||
|
m_core->importCSVFile(csvFilePath);
|
||||||
|
} else {
|
||||||
|
qWarning() << "Selected CSV file path doesn't exist. Doing nothing...";
|
||||||
|
showStatusMessage(tr("Could't find CSV file!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
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();
|
||||||
@ -270,8 +285,7 @@ void MainWindow::createFileActions() {
|
|||||||
|
|
||||||
m_importAct = make_unique<QAction>(tr("&Import CSV..."), this);
|
m_importAct = make_unique<QAction>(tr("&Import CSV..."), this);
|
||||||
m_importAct->setStatusTip(tr("Import an existing CSV file"));
|
m_importAct->setStatusTip(tr("Import an existing CSV file"));
|
||||||
// connect(m_importAct, &QAction::triggered, this, &MainWindow::importCSV);
|
connect(m_importAct.get(), &QAction::triggered, this, &MainWindow::importCSV);
|
||||||
m_importAct->setEnabled(false);
|
|
||||||
ui->menu_File->addAction(m_importAct.get());
|
ui->menu_File->addAction(m_importAct.get());
|
||||||
|
|
||||||
m_exportAct = make_unique<QAction>(tr("&Export CSV..."), this);
|
m_exportAct = make_unique<QAction>(tr("&Export CSV..."), this);
|
||||||
|
|||||||
@ -56,6 +56,7 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
/// 'File' slots
|
/// 'File' slots
|
||||||
void saveItems();
|
void saveItems();
|
||||||
|
void importCSV();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
|
|||||||
Reference in New Issue
Block a user