Bugfix when deleting a note
This commit is contained in:
parent
426f7ea509
commit
4341b2bd01
4 changed files with 19 additions and 14 deletions
|
@ -173,7 +173,7 @@ void NotesApi::getAllNotes(QStringList excludeFields) {
|
|||
}
|
||||
}
|
||||
|
||||
void NotesApi::getNote(int noteId, QStringList excludeFields) {
|
||||
void NotesApi::getNote(double noteId, QStringList excludeFields) {
|
||||
QUrl url = m_url;
|
||||
url.setPath(url.path() + QString("/notes/%1").arg(noteId));
|
||||
if (!excludeFields.isEmpty())
|
||||
|
@ -197,7 +197,7 @@ void NotesApi::createNote(QVariantMap fields) {
|
|||
}
|
||||
}
|
||||
|
||||
void NotesApi::updateNote(int noteId, QVariantMap fields) {
|
||||
void NotesApi::updateNote(double noteId, QVariantMap fields) {
|
||||
QUrl url = m_url;
|
||||
url.setPath(url.path() + QString("/notes/%1").arg(noteId));
|
||||
if (url.isValid()) {
|
||||
|
@ -208,7 +208,7 @@ void NotesApi::updateNote(int noteId, QVariantMap fields) {
|
|||
}
|
||||
}
|
||||
|
||||
void NotesApi::deleteNote(int noteId) {
|
||||
void NotesApi::deleteNote(double noteId) {
|
||||
QUrl url = m_url;
|
||||
url.setPath(url.path() + QString("/notes/%1").arg(noteId));
|
||||
if (url.isValid()) {
|
||||
|
@ -217,6 +217,7 @@ void NotesApi::deleteNote(int noteId) {
|
|||
m_replies << m_manager.deleteResource(m_request);
|
||||
emit busyChanged(busy());
|
||||
}
|
||||
mp_model->removeNote(noteId);
|
||||
}
|
||||
|
||||
void NotesApi::verifyUrl(QUrl url) {
|
||||
|
@ -234,7 +235,7 @@ void NotesApi::replyFinished(QNetworkReply *reply) {
|
|||
QJsonDocument json = QJsonDocument::fromJson(data);
|
||||
if (mp_model)
|
||||
mp_model->fromJsonDocument(json);
|
||||
//qDebug() << json;
|
||||
//qDebug() << data;
|
||||
}
|
||||
else {
|
||||
qDebug() << reply->error() << reply->errorString();
|
||||
|
@ -252,5 +253,5 @@ void NotesApi::sslError(QNetworkReply *reply, const QList<QSslError> &errors) {
|
|||
}
|
||||
|
||||
void NotesApi::saveToFile(QModelIndex, QModelIndex, QVector<int>) {
|
||||
|
||||
qDebug() << "Should write the data now to a file" << m_jsonFile.fileName();
|
||||
}
|
||||
|
|
|
@ -65,10 +65,10 @@ public:
|
|||
bool busy() const;
|
||||
|
||||
Q_INVOKABLE void getAllNotes(QStringList excludeFields = QStringList());
|
||||
Q_INVOKABLE void getNote(int noteId, QStringList excludeFields = QStringList());
|
||||
Q_INVOKABLE void getNote(double noteId, QStringList excludeFields = QStringList());
|
||||
Q_INVOKABLE void createNote(QVariantMap fields = QVariantMap());
|
||||
Q_INVOKABLE void updateNote(int noteId, QVariantMap fields = QVariantMap());
|
||||
Q_INVOKABLE void deleteNote(int noteId);
|
||||
Q_INVOKABLE void updateNote(double noteId, QVariantMap fields = QVariantMap());
|
||||
Q_INVOKABLE void deleteNote(double noteId);
|
||||
Q_INVOKABLE NotesProxyModel* model() const { return mp_modelProxy; }
|
||||
|
||||
signals:
|
||||
|
|
|
@ -52,11 +52,13 @@ NotesModel::~NotesModel() {
|
|||
|
||||
bool NotesModel::fromJsonDocument(const QJsonDocument &jdoc) {
|
||||
qDebug() << "Applying new JSON input"; // << json;
|
||||
if (!jdoc.isNull()) {
|
||||
if (!jdoc.isNull() && !jdoc.isEmpty()) {
|
||||
if (jdoc.isArray()) {
|
||||
qDebug() << "- It's an array...";
|
||||
QVector<double> notesIdsToRemove = ids();
|
||||
QVector<double> notesIdsToRemove;
|
||||
QJsonArray jarr = jdoc.array();
|
||||
if (!jarr.empty())
|
||||
notesIdsToRemove = ids();
|
||||
while (!jarr.empty()) {
|
||||
QJsonValue jval = jarr.first();
|
||||
if (jval.isObject()) {
|
||||
|
@ -128,6 +130,7 @@ int NotesModel::insertNote(const Note ¬e) {
|
|||
beginInsertRows(QModelIndex(), position, position);
|
||||
m_notes.append(note);
|
||||
endInsertRows();
|
||||
emit dataChanged(index(position), index(position));
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@ public:
|
|||
bool fromJsonDocument(const QJsonDocument &jdoc);
|
||||
QJsonDocument toJsonDocument() const;
|
||||
|
||||
int insertNote(const Note ¬e);
|
||||
bool removeNote(const Note ¬e);
|
||||
bool removeNote(double id);
|
||||
|
||||
enum NoteRoles {
|
||||
IdRole = Qt::UserRole,
|
||||
ModifiedRole = Qt::UserRole + 1,
|
||||
|
@ -62,14 +66,11 @@ public:
|
|||
QMap<int, QVariant> itemData(const QModelIndex &index) const;
|
||||
|
||||
protected:
|
||||
void addNote(const QJsonValue ¬e);
|
||||
//void addNote(const QJsonValue ¬e);
|
||||
QVector<double> ids() const;
|
||||
//int indexOf(const Note ¬e) const;
|
||||
//int indexOf(int id) const;
|
||||
int insertNote(const Note ¬e);
|
||||
//bool replaceNote(const Note ¬e);
|
||||
bool removeNote(const Note ¬e);
|
||||
bool removeNote(double id);
|
||||
|
||||
signals:
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ());
|
||||
|
|
Loading…
Reference in a new issue