Use QMap to store attributes and attachments.

QMap keeps the keys in a consistent order (sorted).
This commit is contained in:
Felix Geyer 2012-04-09 22:20:11 +02:00
parent d527e63f1f
commit 57a953476a
2 changed files with 9 additions and 21 deletions

View File

@ -135,9 +135,9 @@ const QList<AutoTypeAssociation>& Entry::autoTypeAssociations() const
return m_autoTypeAssociations;
}
const QList<QString>& Entry::attributes() const
const QList<QString> Entry::attributes() const
{
return m_attributesKeys;
return m_attributes.keys();
}
QString Entry::attributeValue(const QString& key) const
@ -145,9 +145,9 @@ QString Entry::attributeValue(const QString& key) const
return m_attributes.value(key);
}
const QList<QString>& Entry::attachments() const
const QList<QString> Entry::attachments() const
{
return m_binariesKeys;
return m_binaries.keys();
}
QByteArray Entry::attachmentValue(const QString& key) const
@ -264,10 +264,6 @@ void Entry::addAutoTypeAssociation(const AutoTypeAssociation& assoc)
void Entry::setAttribute(const QString& key, const QString& value, bool protect)
{
if (!m_attributes.contains(key)) {
m_attributesKeys.append(key);
}
m_attributes.insert(key, value);
if (protect) {
@ -286,17 +282,12 @@ void Entry::removeAttribute(const QString& key)
{
Q_ASSERT(!isDefaultAttribute(key));
m_attributesKeys.removeOne(key);
m_attributes.remove(key);
m_protectedAttributes.remove(key);
}
void Entry::setAttachment(const QString& key, const QByteArray& value, bool protect)
{
if (!m_binaries.contains(key)) {
m_binariesKeys.append(key);
}
m_binaries.insert(key, value);
if (protect) {
@ -309,7 +300,6 @@ void Entry::setAttachment(const QString& key, const QByteArray& value, bool prot
void Entry::removeAttachment(const QString& key)
{
m_binariesKeys.removeOne(key);
m_binaries.remove(key);
m_protectedAttachments.remove(key);
}

View File

@ -18,7 +18,7 @@
#ifndef KEEPASSX_ENTRY_H
#define KEEPASSX_ENTRY_H
#include <QtCore/QHash>
#include <QtCore/QMap>
#include <QtCore/QPointer>
#include <QtCore/QSet>
#include <QtCore/QUrl>
@ -60,9 +60,9 @@ public:
int autoTypeObfuscation() const;
QString defaultAutoTypeSequence() const;
const QList<AutoTypeAssociation>& autoTypeAssociations() const;
const QList<QString>& attributes() const;
const QList<QString> attributes() const;
QString attributeValue(const QString& key) const;
const QList<QString>& attachments() const;
const QList<QString> attachments() const;
QByteArray attachmentValue(const QString& key) const;
bool isAttributeProtected(const QString& key) const;
bool isAttachmentProtected(const QString& key) const;
@ -122,10 +122,8 @@ private:
int m_autoTypeObfuscation;
QString m_defaultAutoTypeSequence;
QList<AutoTypeAssociation> m_autoTypeAssociations;
QHash<QString, QString> m_attributes;
QList<QString> m_attributesKeys;
QHash<QString, QByteArray> m_binaries;
QList<QString> m_binariesKeys;
QMap<QString, QString> m_attributes;
QMap<QString, QByteArray> m_binaries;
QSet<QString> m_protectedAttributes;
QSet<QString> m_protectedAttachments;