diff --git a/src/tools/notes/notessaveload.cpp b/src/tools/notes/notessaveload.cpp index a38ce83a..189eddef 100644 --- a/src/tools/notes/notessaveload.cpp +++ b/src/tools/notes/notessaveload.cpp @@ -345,6 +345,8 @@ void NotesSaveLoad::buildChapters(const QStringList &folders, NoteBook &book) co { qCDebug(gmNotesSaveLoad()) << "Building chapters in book" << book.name() << folders; + bool createdNewChapters = false; + foreach (const auto &folder, folders) { bool exists = false; @@ -360,6 +362,7 @@ void NotesSaveLoad::buildChapters(const QStringList &folders, NoteBook &book) co if (!exists) { + createdNewChapters = true; const auto *chapter = new NoteBookChapter(folder, &book); connect(chapter, &NoteBookChapter::loadPages, this, &NotesSaveLoad::loadPages); connect(chapter, &NoteBookChapter::createPage, this, &NotesSaveLoad::createPage); @@ -368,7 +371,10 @@ void NotesSaveLoad::buildChapters(const QStringList &folders, NoteBook &book) co } } - book.onChaptersLoaded(); + if (createdNewChapters) + { + book.onChaptersLoaded(); + } } /** @@ -400,8 +406,11 @@ void NotesSaveLoad::buildPages(const QStringList &files, NoteBookChapter &chapte } } - chapter.onPagesLoaded(); - emit pagesLoaded(pages); + if (!pages.isEmpty()) + { + chapter.onPagesLoaded(); + emit pagesLoaded(pages); + } } /** diff --git a/tests/testhelper/staticabstracttest.cpp b/tests/testhelper/staticabstracttest.cpp index 1324f4b7..9262b091 100644 --- a/tests/testhelper/staticabstracttest.cpp +++ b/tests/testhelper/staticabstracttest.cpp @@ -40,7 +40,7 @@ void StaticAbstractTest::waitForSpy(QSignalSpy &spy, int count) while (spy.count() < count) { - ASSERT_TRUE(spy.wait()); + ASSERT_TRUE(spy.wait()) << "current count: " << spy.count() << ", expected count: " << count; } ASSERT_EQ(spy.count(), count); diff --git a/tests/tools/notes/testnotestool.cpp b/tests/tools/notes/testnotestool.cpp index 924518a0..0a39bbef 100644 --- a/tests/tools/notes/testnotestool.cpp +++ b/tests/tools/notes/testnotestool.cpp @@ -64,8 +64,10 @@ class NotesToolTest : public AbstractTest QSignalSpy spy(book, &TreeItem::childItemsChanged); book->create(book->creatables().at(0), u"chapter"_s); StaticAbstractTest::waitForSpy(spy, 1); + spy.clear(); + book->toggle(); - StaticAbstractTest::waitForSpy(spy, 2); + StaticAbstractTest::waitForSpy(spy, 1); chapter = qobject_cast(book->childItems().at(0)); ASSERT_TRUE(chapter);