Model slots

This commit is contained in:
Scharel Clemens 2020-04-19 19:01:03 +02:00
parent 433a049a14
commit cd55e83ae9
5 changed files with 45 additions and 10 deletions

View file

@ -181,7 +181,13 @@ ApplicationWindow
onNetworkAccessibleChanged: { onNetworkAccessibleChanged: {
console.log("Device is " + (accessible ? "online" : "offline")) console.log("Device is " + (accessible ? "online" : "offline"))
accessible ? offlineNotification.close(Notification.Closed) : offlineNotification.publish() if (accessible) {
offlineNotification.close(Notification.Closed)
getAllNotes()
}
else {
offlineNotification.publish()
}
} }
onNoteError: { onNoteError: {
apiErrorNotification.close() apiErrorNotification.close()

View file

@ -155,7 +155,7 @@ Page {
Label { Label {
id: categoryLabel id: categoryLabel
anchors.centerIn: parent anchors.centerIn: parent
text: category text: categoryLabel.text.length > 0 ? category : ""
color: note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor color: note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall font.pixelSize: Theme.fontSizeExtraSmall
} }

View file

@ -31,16 +31,15 @@ int main(int argc, char *argv[])
NotesApi* notesApi = new NotesApi; NotesApi* notesApi = new NotesApi;
//QObject::connect(notesApi, SIGNAL(allNotesReceived(QList<int>)), notesModel, SLOT()); //QObject::connect(notesApi, SIGNAL(allNotesReceived(QList<int>)), notesModel, SLOT());
QObject::connect(notesApi, SIGNAL(noteCreated(int,QJsonObject)), notesModel, SLOT(insertNote(int,QJsonObject))); QObject::connect(notesApi, SIGNAL(noteCreated(int,QJsonObject)), notesModel, SLOT(insertNoteFromApi(int,QJsonObject)));
QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNote(int,QJsonObject))); QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNoteFromApi(int,QJsonObject)));
QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNote(int))); QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNoteFromApi(int)));
QObject::connect(notesApi, SIGNAL(noteCreated(int,QJsonObject)), notesStore, SLOT(insertNote(int,QJsonObject))); //QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesStore, SLOT(updateNote(int,QJsonObject)));
QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesStore, SLOT(updateNote(int,QJsonObject))); //QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(deleteNote(int)));
QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(removeNote(int)));
QObject::connect(notesStore, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNote(int,QJsonObject))); //QObject::connect(notesStore, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNoteFromStore(int,QJsonObject)));
QObject::connect(notesStore, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNote(int))); //QObject::connect(notesStore, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNoteFromStore(int)));
QQuickView* view = SailfishApp::createView(); QQuickView* view = SailfishApp::createView();
#ifdef QT_DEBUG #ifdef QT_DEBUG

View file

@ -139,6 +139,30 @@ void NotesModel::removeNote(const int id) {
} }
} }
void NotesModel::insertNoteFromApi(const int id, const QJsonObject &note) {
insertNote(id, note);
}
void NotesModel::updateNoteFromApi(const int id, const QJsonObject &note) {
updateNote(id, note);
}
void NotesModel::removeNoteFromApi(const int id) {
removeNote(id);
}
void NotesModel::insertNoteFromStore(const int id, const QJsonObject &note) {
insertNote(id, note);
}
void NotesModel::updateNoteFromStore(const int id, const QJsonObject &note) {
updateNote(id, note);
}
void NotesModel::removeNoteFromStore(const int id) {
removeNote(id);
}
void NotesModel::clear() { void NotesModel::clear() {
qDebug() << "Clearing model"; qDebug() << "Clearing model";
beginResetModel(); beginResetModel();

View file

@ -69,6 +69,12 @@ public slots:
Q_INVOKABLE void insertNote(const int id, const QJsonObject& note); Q_INVOKABLE void insertNote(const int id, const QJsonObject& note);
Q_INVOKABLE void updateNote(const int id, const QJsonObject& note); Q_INVOKABLE void updateNote(const int id, const QJsonObject& note);
Q_INVOKABLE void removeNote(const int id); Q_INVOKABLE void removeNote(const int id);
Q_INVOKABLE void insertNoteFromApi(const int id, const QJsonObject& note);
Q_INVOKABLE void updateNoteFromApi(const int id, const QJsonObject& note);
Q_INVOKABLE void removeNoteFromApi(const int id);
Q_INVOKABLE void insertNoteFromStore(const int id, const QJsonObject& note);
Q_INVOKABLE void updateNoteFromStore(const int id, const QJsonObject& note);
Q_INVOKABLE void removeNoteFromStore(const int id);
Q_INVOKABLE void clear(); Q_INVOKABLE void clear();
Q_INVOKABLE int indexOfNoteById(int id) const; Q_INVOKABLE int indexOfNoteById(int id) const;