Write notes to local files for upcoming offline mode

This commit is contained in:
Scharel Clemens 2020-01-04 16:08:40 +01:00
parent f7bc0ed9b8
commit 385cdc4cca
2 changed files with 7 additions and 4 deletions

View file

@ -136,10 +136,8 @@ void NotesApi::setPath(QString path) {
void NotesApi::setDataFile(QString dataFile) { void NotesApi::setDataFile(QString dataFile) {
if (dataFile != m_jsonFile.fileName()) { if (dataFile != m_jsonFile.fileName()) {
m_jsonFile.close(); m_jsonFile.close();
if (!dataFile.isEmpty()) { if (!dataFile.isEmpty())
m_jsonFile.setFileName(dataFile); m_jsonFile.setFileName(dataFile);
m_jsonFile.open(QIODevice::ReadWrite | QIODevice::Text); // | QIODevice::Unbuffered
}
emit dataFileChanged(m_jsonFile.fileName()); emit dataFileChanged(m_jsonFile.fileName());
//qDebug() << m_jsonFile.fileName(); //qDebug() << m_jsonFile.fileName();
} }
@ -259,5 +257,9 @@ void NotesApi::sslError(QNetworkReply *reply, const QList<QSslError> &errors) {
} }
void NotesApi::saveToFile(QModelIndex, QModelIndex, QVector<int>) { void NotesApi::saveToFile(QModelIndex, QModelIndex, QVector<int>) {
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();
}
} }

View file

@ -141,6 +141,7 @@ bool NotesModel::removeNote(const Note &note) {
beginRemoveRows(QModelIndex(), position, position); beginRemoveRows(QModelIndex(), position, position);
m_notes.removeAt(position); m_notes.removeAt(position);
endRemoveRows(); endRemoveRows();
emit dataChanged(index(position), index(position));
return true; return true;
} }
return false; return false;