Fix additional cases of incorrectly handling of a Group's LastModificationTime

Cases:
- Entry is added to a Group
- Entry is removed from a Group
- The Group list is sorted
This commit is contained in:
vuurvlieg 2024-03-30 13:36:54 +01:00
parent ca4ae86eb6
commit 22a1a82e5b
3 changed files with 32 additions and 21 deletions

View File

@ -77,11 +77,11 @@ Group::~Group()
cleanupParent();
}
template <class P, class V> inline bool Group::set(P& property, const V& value)
template <class P, class V> 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)

View File

@ -210,8 +210,9 @@ private slots:
void updateTimeinfo();
private:
template <class P, class V> bool set(P& property, const V& value);
template <class P, class V> bool set(P& property, const V& value, bool preserveTimeinfo = false);
void emitModifiedEx(bool preserveTimeinfo);
void setParent(Database* db);
void connectDatabaseSignalsRecursive(Database* db);

View File

@ -1367,4 +1367,17 @@ void TestGroup::testTimeinfoChanges()
QCOMPARE(subgroup2->timeInfo().lastModificationTime(), startTime);
QCOMPARE(subgroup2->timeInfo().locationChanged(), Clock::currentDateTimeUtc());
QCOMPARE(db2.rootGroup()->timeInfo(), startTimeinfo);
QScopedPointer<Entry> 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);
}