From 936bb3199753bfe694f68067722ad75bf82b1fe2 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Sun, 26 Apr 2020 16:09:14 +0200 Subject: [PATCH 1/3] onModelChange save note I like the way onModelChange is done. Except that you forget to use the note you computed. --- qt/aqt/addcards.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 8b4da53a2..ed725c50a 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -114,6 +114,9 @@ class AddCards(QDialog): except IndexError: pass self.removeTempNote(oldNote) + self.editor.note = note + # When on model change is called, reset is necessarily called. + # Reset load note, so it is not required to load it here. def onReset(self, model: None = None, keep: bool = False) -> None: oldNote = self.editor.note From d427e1028b87c34b51f31220385abd018676b068 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Sun, 26 Apr 2020 16:52:35 +0200 Subject: [PATCH 2/3] single try in onModelChange --- qt/aqt/addcards.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index ed725c50a..513f4b199 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -100,17 +100,15 @@ class AddCards(QDialog): newFields = list(note.keys()) for n, f in enumerate(note.model()["flds"]): fieldName = f["name"] - try: - oldFieldName = oldNote.model()["flds"][n]["name"] - except IndexError: - oldFieldName = None # copy identical fields if fieldName in oldFields: note[fieldName] = oldNote[fieldName] - # set non-identical fields by field index - elif oldFieldName and oldFieldName not in newFields: + else: + # set non-identical fields by field index try: - note.fields[n] = oldNote.fields[n] + oldFieldName = oldNote.model()["flds"][n]["name"] + if oldFieldName not in newFields: + note.fields[n] = oldNote.fields[n] except IndexError: pass self.removeTempNote(oldNote) From f2fbf667cd2eb7c9b3c00c68ba86610bdccdceb3 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Sun, 26 Apr 2020 16:53:23 +0200 Subject: [PATCH 3/3] onModelChange: replacing try by if --- qt/aqt/addcards.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 513f4b199..4928beb18 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -103,14 +103,11 @@ class AddCards(QDialog): # copy identical fields if fieldName in oldFields: note[fieldName] = oldNote[fieldName] - else: + elif n < len(oldNote.model()["flds"]): # set non-identical fields by field index - try: - oldFieldName = oldNote.model()["flds"][n]["name"] - if oldFieldName not in newFields: - note.fields[n] = oldNote.fields[n] - except IndexError: - pass + oldFieldName = oldNote.model()["flds"][n]["name"] + if oldFieldName not in newFields: + note.fields[n] = oldNote.fields[n] self.removeTempNote(oldNote) self.editor.note = note # When on model change is called, reset is necessarily called.