From 258438f01fdf4c33fee41fd242e561acff3ef9fa Mon Sep 17 00:00:00 2001 From: Christian Kieschnick Date: Tue, 16 Jan 2018 08:34:56 +0100 Subject: [PATCH] Fix code-style issues Fixed issues pointed out during review --- src/core/AutoTypeAssociations.cpp | 2 +- src/core/Entry.cpp | 4 +++- src/core/EntryAttachments.cpp | 13 +++++-------- src/core/EntryAttachments.h | 2 +- src/core/EntryAttributes.cpp | 7 ++----- tests/TestModified.cpp | 20 ++++++++++++-------- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/core/AutoTypeAssociations.cpp b/src/core/AutoTypeAssociations.cpp index 3d7a2c36f..04221733f 100644 --- a/src/core/AutoTypeAssociations.cpp +++ b/src/core/AutoTypeAssociations.cpp @@ -106,7 +106,7 @@ int AutoTypeAssociations::size() const int AutoTypeAssociations::associationsSize() const { int size = 0; - foreach (const Association &association, m_associations) { + for (const Association &association : m_associations) { size += association.sequence.toUtf8().size() + association.window.toUtf8().size(); } return size; diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 0e327dc40..53e27a6a8 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -586,6 +586,7 @@ void Entry::truncateHistory() QMutableListIterator i(m_history); i.toBack(); + const QRegularExpression delimiter(",|:|;"); while (i.hasPrevious()) { Entry* historyItem = i.previous(); @@ -594,7 +595,8 @@ void Entry::truncateHistory() size += historyItem->attributes()->attributesSize(); size += historyItem->autoTypeAssociations()->associationsSize(); size += historyItem->attachments()->attachmentsSize(foundAttachments); - foreach( const QString &tag, historyItem->tags().split(QRegExp(",|;|:"), QString::SkipEmptyParts)){ + const QStringList tags = historyItem->tags().split(delimiter, QString::SkipEmptyParts); + for (const QString& tag : tags) { size += tag.toUtf8().size(); } foundAttachments += historyItem->attachments()->values(); diff --git a/src/core/EntryAttachments.cpp b/src/core/EntryAttachments.cpp index 625cbd424..70fe86ddf 100644 --- a/src/core/EntryAttachments.cpp +++ b/src/core/EntryAttachments.cpp @@ -153,16 +153,13 @@ bool EntryAttachments::operator!=(const EntryAttachments& other) const return m_attachments != other.m_attachments; } -int EntryAttachments::attachmentsSize(const QSet &ignoredAttachments) const +int EntryAttachments::attachmentsSize(const QSet& ignoredAttachments) const { int size = 0; - - QMapIterator i(m_attachments); - while (i.hasNext()) { - i.next(); - if( ! ignoredAttachments.contains( i.value() )){ - size += i.key().toUtf8().size() + i.value().size(); - } + for (auto it = m_attachments.constBegin(); it != m_attachments.constEnd(); ++it) { + if (!ignoredAttachments.contains(it.value())) { + size += it.key().toUtf8().size() + it.value().size(); + } } return size; } diff --git a/src/core/EntryAttachments.h b/src/core/EntryAttachments.h index 835a13dc8..3cdd43253 100644 --- a/src/core/EntryAttachments.h +++ b/src/core/EntryAttachments.h @@ -41,7 +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; + int attachmentsSize(const QSet& ignoredAttachments) const; signals: void modified(); diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index 4297f10ac..629d8e802 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -286,11 +286,8 @@ void EntryAttributes::clear() int EntryAttributes::attributesSize() const { int size = 0; - - QMapIterator i(m_attributes); - while (i.hasNext()) { - i.next(); - size += i.key().toUtf8().size() + i.value().toUtf8().size(); + for (auto it = m_attributes.constBegin(); it != m_attributes.constEnd(); ++it) { + size += it.key().toUtf8().size() + it.value().toUtf8().size(); } return size; } diff --git a/tests/TestModified.cpp b/tests/TestModified.cpp index 9ae28b80c..4c5ce1c2b 100644 --- a/tests/TestModified.cpp +++ b/tests/TestModified.cpp @@ -400,8 +400,10 @@ void TestModified::testHistoryItem() entry2->endUpdate(); QCOMPARE(entry2->historyItems().size(), 0); + const int historyMaxSize = 17000; + db->metadata()->setHistoryMaxItems(-1); - db->metadata()->setHistoryMaxSize(17000); + db->metadata()->setHistoryMaxSize(historyMaxSize); entry2->beginUpdate(); entry2->attachments()->set("test", QByteArray(18000, 'X')); @@ -469,19 +471,21 @@ void TestModified::testHistoryItem() entry4->setGroup(root); QCOMPARE(entry4->historyItems().size(), 0); + const QString key("test"); + int reservedSize = entry4->attributes()->attributesSize(); entry4->beginUpdate(); - entry4->attachments()->set("test1", QByteArray(17000 - 5 - reservedSize + 1, 'a')); + entry4->attachments()->set(key, QByteArray(historyMaxSize - key.size() - reservedSize + 1, 'a')); entry4->endUpdate(); QCOMPARE(entry4->historyItems().size(), 1); entry4->beginUpdate(); - entry4->attachments()->remove("test1"); + entry4->attachments()->remove(key); entry4->endUpdate(); QCOMPARE(entry4->historyItems().size(), 0); entry4->beginUpdate(); - entry4->setTags(QByteArray(17000 - reservedSize + 1, 'a')); + entry4->setTags(QByteArray(historyMaxSize - reservedSize + 1, 'a')); entry4->endUpdate(); QCOMPARE(entry4->historyItems().size(), 1); @@ -491,19 +495,19 @@ void TestModified::testHistoryItem() QCOMPARE(entry4->historyItems().size(), 0); entry4->beginUpdate(); - entry4->attributes()->set("test3", QByteArray(17000 - 5 - reservedSize + 1, 'a')); + entry4->attributes()->set(key, QByteArray(historyMaxSize - key.size() - reservedSize + 1, 'a')); entry4->endUpdate(); QCOMPARE(entry4->historyItems().size(), 1); entry4->beginUpdate(); - entry4->attributes()->remove("test3"); + entry4->attributes()->remove(key); entry4->endUpdate(); QCOMPARE(entry4->historyItems().size(), 0); entry4->beginUpdate(); AutoTypeAssociations::Association association; - association.window = "test3"; - association.sequence = QByteArray(17000 - 5 - reservedSize + 1, 'a'); + association.window = key; + association.sequence = QByteArray(historyMaxSize - key.size() - reservedSize + 1, 'a'); entry4->autoTypeAssociations()->add(association); entry4->endUpdate(); QCOMPARE(entry4->historyItems().size(), 1);