Simple implementation of CSV file import. Successfully imported items are appended to the model.
This commit is contained in:
@ -101,8 +101,6 @@ void GenericCore::saveItems() {
|
||||
const QJsonDocument doc = m_mainModel->getAllItemsAsJsonDoc();
|
||||
const bool successfulSave = FileHandler::saveToFile(doc, ITEM_FILE_NAME);
|
||||
if (successfulSave) {
|
||||
// QStringList completedTaskStrings = m_model->completedTasks();
|
||||
// appendCompletedTasksToFile(completedTaskStrings, "completed.txt");
|
||||
m_modelUndoStack->setClean();
|
||||
emit displayStatusMessage(QString("Items saved."));
|
||||
} else {
|
||||
@ -110,6 +108,20 @@ void GenericCore::saveItems() {
|
||||
}
|
||||
}
|
||||
|
||||
void GenericCore::importCSVFile(const QString& filePath) {
|
||||
qInfo() << "importing items from CSV...";
|
||||
qDebug() << "filePath:" << filePath;
|
||||
const QList<QHash<int, QVariant>> itemValuesList =
|
||||
FileHandler::getItemValuesFromCSVFile(filePath);
|
||||
// NEXT inform UI on errors
|
||||
if (itemValuesList.isEmpty()) {
|
||||
qDebug() << "No items found. Doing nothing...";
|
||||
return;
|
||||
}
|
||||
// qDebug() << "CSV file content:" << itemValuesList;
|
||||
m_mainModel->insertItems(m_mainModel->rowCount(), itemValuesList);
|
||||
}
|
||||
|
||||
void GenericCore::setupModels() {
|
||||
m_mainModel = make_shared<TableModel>(m_modelUndoStack, this);
|
||||
// TODO add QAbstractItemModelTester
|
||||
|
||||
Reference in New Issue
Block a user