diff --git a/src/core/AutoTypeAssociations.cpp b/src/core/AutoTypeAssociations.cpp index 5ec4eb3b..3d7a2c36 100644 --- a/src/core/AutoTypeAssociations.cpp +++ b/src/core/AutoTypeAssociations.cpp @@ -103,6 +103,15 @@ int AutoTypeAssociations::size() const return m_associations.size(); } +int AutoTypeAssociations::associationsSize() const +{ + int size = 0; + foreach (const Association &association, m_associations) { + size += association.sequence.toUtf8().size() + association.window.toUtf8().size(); + } + return size; +} + void AutoTypeAssociations::clear() { m_associations.clear(); diff --git a/src/core/AutoTypeAssociations.h b/src/core/AutoTypeAssociations.h index 61ef3fd4..31e58cda 100644 --- a/src/core/AutoTypeAssociations.h +++ b/src/core/AutoTypeAssociations.h @@ -43,6 +43,7 @@ public: AutoTypeAssociations::Association get(int index) const; QList getAll() const; int size() const; + int associationsSize() const; void clear(); private: diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index ed886083..b8e58929 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -582,7 +582,7 @@ void Entry::truncateHistory() int histMaxSize = db->metadata()->historyMaxSize(); if (histMaxSize > -1) { int size = 0; - QSet foundAttachments = attachments()->values().toSet(); + QSet foundAttachments = attachments()->values(); QMutableListIterator i(m_history); i.toBack(); @@ -592,12 +592,12 @@ void Entry::truncateHistory() // don't calculate size if it's already above the maximum if (size <= histMaxSize) { size += historyItem->attributes()->attributesSize(); - - const QSet newAttachments = historyItem->attachments()->values().toSet() - foundAttachments; - for (const QByteArray& attachment : newAttachments) { - size += attachment.size(); + size += historyItem->autoTypeAssociations()->associationsSize(); + size += historyItem->attachments()->attachmentsSize(foundAttachments); + foreach( const QString &tag, historyItem->tags().split(QRegExp(",|;|:"), QString::SkipEmptyParts)){ + size += tag.toUtf8().size(); } - foundAttachments += newAttachments; + foundAttachments += historyItem->attachments()->values(); } if (size > histMaxSize) { diff --git a/src/core/EntryAttachments.cpp b/src/core/EntryAttachments.cpp index 95755860..6d3e38bb 100644 --- a/src/core/EntryAttachments.cpp +++ b/src/core/EntryAttachments.cpp @@ -18,6 +18,7 @@ #include "EntryAttachments.h" #include +#include EntryAttachments::EntryAttachments(QObject* parent) : QObject(parent) @@ -34,9 +35,9 @@ bool EntryAttachments::hasKey(const QString& key) const return m_attachments.contains(key); } -QList EntryAttachments::values() const +QSet EntryAttachments::values() const { - return m_attachments.values(); + return m_attachments.values().toSet(); } QByteArray EntryAttachments::value(const QString& key) const @@ -151,3 +152,13 @@ bool EntryAttachments::operator!=(const EntryAttachments& other) const { return m_attachments != other.m_attachments; } + +int EntryAttachments::attachmentsSize(const QSet &ignoredAttachments) const +{ + int size = 0; + const QSet consideredAttachments = m_attachments.values().toSet() - ignoredAttachments; + for (const QByteArray& attachment : consideredAttachments) { + size += attachment.size(); + } + return size; +} diff --git a/src/core/EntryAttachments.h b/src/core/EntryAttachments.h index 0dba9543..835a13dc 100644 --- a/src/core/EntryAttachments.h +++ b/src/core/EntryAttachments.h @@ -31,7 +31,7 @@ public: explicit EntryAttachments(QObject* parent = nullptr); QList keys() const; bool hasKey(const QString& key) const; - QList values() const; + QSet values() const; QByteArray value(const QString& key) const; void set(const QString& key, const QByteArray& value); void remove(const QString& key); @@ -41,6 +41,7 @@ public: void copyDataFrom(const EntryAttachments* other); bool operator==(const EntryAttachments& other) const; bool operator!=(const EntryAttachments& other) const; + int attachmentsSize(const QSet &ignoredAttachments) const; signals: void modified(); diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index 8cc7f2f0..4297f10a 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -283,14 +283,14 @@ void EntryAttributes::clear() emit modified(); } -int EntryAttributes::attributesSize() +int EntryAttributes::attributesSize() const { int size = 0; QMapIterator i(m_attributes); while (i.hasNext()) { i.next(); - size += i.value().toUtf8().size(); + size += i.key().toUtf8().size() + i.value().toUtf8().size(); } return size; } diff --git a/src/core/EntryAttributes.h b/src/core/EntryAttributes.h index f483b8a9..3eca9171 100644 --- a/src/core/EntryAttributes.h +++ b/src/core/EntryAttributes.h @@ -45,7 +45,7 @@ public: void copyCustomKeysFrom(const EntryAttributes* other); bool areCustomKeysDifferent(const EntryAttributes* other); void clear(); - int attributesSize(); + int attributesSize() const; void copyDataFrom(const EntryAttributes* other); bool operator==(const EntryAttributes& other) const; bool operator!=(const EntryAttributes& other) const;