diff --git a/src/notesapi.cpp b/src/notesapi.cpp index a3f5add..de2b0b1 100644 --- a/src/notesapi.cpp +++ b/src/notesapi.cpp @@ -136,10 +136,8 @@ void NotesApi::setPath(QString path) { void NotesApi::setDataFile(QString dataFile) { if (dataFile != m_jsonFile.fileName()) { m_jsonFile.close(); - if (!dataFile.isEmpty()) { + if (!dataFile.isEmpty()) m_jsonFile.setFileName(dataFile); - m_jsonFile.open(QIODevice::ReadWrite | QIODevice::Text); // | QIODevice::Unbuffered - } emit dataFileChanged(m_jsonFile.fileName()); //qDebug() << m_jsonFile.fileName(); } @@ -259,5 +257,9 @@ void NotesApi::sslError(QNetworkReply *reply, const QList &errors) { } void NotesApi::saveToFile(QModelIndex, QModelIndex, QVector) { - qDebug() << "Should write the data now to a file" << m_jsonFile.fileName(); + if (m_jsonFile.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) { + qDebug() << "Writing data to file" << m_jsonFile.fileName(); + m_jsonFile.write(mp_model->toJsonDocument().toJson()); + m_jsonFile.close(); + } } diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index 7816f2a..609aaf2 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -141,6 +141,7 @@ bool NotesModel::removeNote(const Note ¬e) { beginRemoveRows(QModelIndex(), position, position); m_notes.removeAt(position); endRemoveRows(); + emit dataChanged(index(position), index(position)); return true; } return false;