diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 0e652878c..4f8434bab 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -77,11 +77,11 @@ Group::~Group() cleanupParent(); } -template inline bool Group::set(P& property, const V& value) +template inline bool Group::set(P& property, const V& value, bool preserveTimeinfo) { if (property != value) { property = value; - emitModified(); + emitModifiedEx(preserveTimeinfo); return true; } else { return false; @@ -440,6 +440,15 @@ const Group* Group::parentGroup() const return m_parent; } +void Group::emitModifiedEx(bool preserveTimeinfo) { + bool prevUpdateTimeinfo = m_updateTimeinfo; + if (preserveTimeinfo) { + m_updateTimeinfo = false; // prevent update of LastModificationTime + } + emitModified(); + m_updateTimeinfo = prevUpdateTimeinfo; +} + void Group::setParent(Group* parent, int index, bool trackPrevious) { Q_ASSERT(parent); @@ -496,11 +505,7 @@ void Group::setParent(Group* parent, int index, bool trackPrevious) m_data.timeInfo.setLocationChanged(Clock::currentDateTimeUtc()); } - bool prevUpdateTimeInfo = m_updateTimeinfo; - m_updateTimeinfo = false; // prevent update of LastModificationTime - emitModified(); - m_updateTimeinfo = prevUpdateTimeInfo; - + emitModifiedEx(true); if (!moveWithinDatabase) { emit groupAdded(); @@ -990,7 +995,7 @@ void Group::addEntry(Entry* entry) connect(entry, &Entry::modified, m_db, &Database::markAsModified); } - emitModified(); + emitModifiedEx(true); emit entryAdded(entry); } @@ -1007,7 +1012,7 @@ void Group::removeEntry(Entry* entry) entry->disconnect(m_db); } m_entries.removeAll(entry); - emitModified(); + emitModifiedEx(true); emit entryRemoved(entry); } @@ -1078,12 +1083,7 @@ void Group::cleanupParent() if (m_parent) { emit groupAboutToRemove(this); m_parent->m_children.removeAll(this); - - bool prevUpdateTimeinfo = m_updateTimeinfo; - m_updateTimeinfo = false; // prevent update of LastModificationTime - emitModified(); - m_updateTimeinfo = prevUpdateTimeinfo; - + emitModifiedEx(true); emit groupRemoved(); } } @@ -1234,7 +1234,7 @@ void Group::sortChildrenRecursively(bool reverse) child->sortChildrenRecursively(reverse); } - emitModified(); + emitModifiedEx(true); } const Group* Group::previousParentGroup() const @@ -1252,10 +1252,7 @@ QUuid Group::previousParentGroupUuid() const void Group::setPreviousParentGroupUuid(const QUuid& uuid) { - bool prevUpdateTimeinfo = m_updateTimeinfo; - m_updateTimeinfo = false; // prevent update of LastModificationTime - set(m_data.previousParentGroupUuid, uuid); - m_updateTimeinfo = prevUpdateTimeinfo; + set(m_data.previousParentGroupUuid, uuid, true); } void Group::setPreviousParentGroup(const Group* group) diff --git a/src/core/Group.h b/src/core/Group.h index f1d93825d..e10aafd87 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -210,8 +210,9 @@ private slots: void updateTimeinfo(); private: - template bool set(P& property, const V& value); + template bool set(P& property, const V& value, bool preserveTimeinfo = false); + void emitModifiedEx(bool preserveTimeinfo); void setParent(Database* db); void connectDatabaseSignalsRecursive(Database* db); diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index cd1dcd7d6..7b5daf803 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -1367,4 +1367,17 @@ void TestGroup::testTimeinfoChanges() QCOMPARE(subgroup2->timeInfo().lastModificationTime(), startTime); QCOMPARE(subgroup2->timeInfo().locationChanged(), Clock::currentDateTimeUtc()); QCOMPARE(db2.rootGroup()->timeInfo(), startTimeinfo); + + QScopedPointer entry1(new Entry()); + entry1->setGroup(subgroup1); + // adding/removing an entry should not affect the LastModificationTime + QCOMPARE(subgroup1->timeInfo().lastModificationTime(), startTime); + entry1.reset(); // delete + QCOMPARE(subgroup1->timeInfo().lastModificationTime(), startTime); + + // sorting should not affect the LastModificationTime + root->sortChildrenRecursively(true); + root->sortChildrenRecursively(false); + QCOMPARE(root->timeInfo().lastModificationTime(), startTime); + QCOMPARE(subgroup1->timeInfo().lastModificationTime(), startTime); }