Only emit signals from clear() when the internal data is non-empty.

Also make sure that m_attributes always contains the default attributes.
This commit is contained in:
Felix Geyer 2012-04-14 18:47:40 +02:00
parent 8f79e914f4
commit 51854a7a45
2 changed files with 13 additions and 3 deletions

View File

@ -112,6 +112,10 @@ void EntryAttachments::copyFrom(const EntryAttachments* other)
void EntryAttachments::clear() void EntryAttachments::clear()
{ {
if (m_attachments.isEmpty()) {
return;
}
Q_EMIT aboutToBeReset(); Q_EMIT aboutToBeReset();
m_attachments.clear(); m_attachments.clear();

View File

@ -22,9 +22,7 @@ const QStringList EntryAttributes::m_defaultAttibutes(QStringList() << "Title" <
EntryAttributes::EntryAttributes(QObject* parent) EntryAttributes::EntryAttributes(QObject* parent)
: QObject(parent) : QObject(parent)
{ {
Q_FOREACH (const QString& key, m_defaultAttibutes) { clear();
set(key, "");
}
} }
QList<QString> EntryAttributes::keys() const QList<QString> EntryAttributes::keys() const
@ -123,11 +121,19 @@ void EntryAttributes::copyFrom(const EntryAttributes* other)
void EntryAttributes::clear() void EntryAttributes::clear()
{ {
if (m_attributes.keys().size() == m_defaultAttibutes.size() && m_protectedAttributes.isEmpty()) {
return;
}
Q_EMIT aboutToBeReset(); Q_EMIT aboutToBeReset();
m_attributes.clear(); m_attributes.clear();
m_protectedAttributes.clear(); m_protectedAttributes.clear();
Q_FOREACH (const QString& key, m_defaultAttibutes) {
m_attributes.insert(key, "");
}
Q_EMIT reset(); Q_EMIT reset();
Q_EMIT modified(); Q_EMIT modified();
} }