Add signals for attribute and attachment changes.

This commit is contained in:
Felix Geyer 2012-04-09 23:52:06 +02:00
parent 57a953476a
commit 9aaec3499d
2 changed files with 57 additions and 1 deletions

View File

@ -264,6 +264,13 @@ void Entry::addAutoTypeAssociation(const AutoTypeAssociation& assoc)
void Entry::setAttribute(const QString& key, const QString& value, bool protect)
{
bool addAttribute = !m_attributes.contains(key);
bool defaultAttribute = isDefaultAttribute(key);
if (addAttribute && !defaultAttribute) {
Q_EMIT attributeAboutToBeAdded(key);
}
m_attributes.insert(key, value);
if (protect) {
@ -273,21 +280,42 @@ void Entry::setAttribute(const QString& key, const QString& value, bool protect)
m_protectedAttributes.remove(key);
}
if (isDefaultAttribute(key)) {
if (defaultAttribute) {
Q_EMIT dataChanged(this);
}
else if (addAttribute) {
Q_EMIT attributeAdded(key);
}
else {
Q_EMIT attributeChanged(key);
}
}
void Entry::removeAttribute(const QString& key)
{
Q_ASSERT(!isDefaultAttribute(key));
if (!m_attributes.contains(key)) {
Q_ASSERT(false);
return;
}
Q_EMIT attributeAboutToBeRemoved(key);
m_attributes.remove(key);
m_protectedAttributes.remove(key);
Q_EMIT attributeRemoved(key);
}
void Entry::setAttachment(const QString& key, const QByteArray& value, bool protect)
{
bool addAttachment = !m_binaries.contains(key);
if (addAttachment) {
Q_EMIT attachmentAboutToBeAdded(key);
}
m_binaries.insert(key, value);
if (protect) {
@ -296,12 +324,28 @@ void Entry::setAttachment(const QString& key, const QByteArray& value, bool prot
else {
m_protectedAttachments.remove(key);
}
if (addAttachment) {
Q_EMIT attachmentAdded(key);
}
else {
Q_EMIT attachmentChanged(key);
}
}
void Entry::removeAttachment(const QString& key)
{
if (!m_binaries.contains(key)) {
Q_ASSERT(false);
return;
}
Q_EMIT attachmentAboutToBeRemoved(key);
m_binaries.remove(key);
m_protectedAttachments.remove(key);
Q_EMIT attachmentRemoved(key);
}
void Entry::setTitle(const QString& title)

View File

@ -109,6 +109,18 @@ Q_SIGNALS:
*/
void dataChanged(Entry* entry);
void attributeChanged(QString key);
void attributeAboutToBeAdded(QString key);
void attributeAdded(QString key);
void attributeAboutToBeRemoved(QString key);
void attributeRemoved(QString key);
void attachmentChanged(QString key);
void attachmentAboutToBeAdded(QString key);
void attachmentAdded(QString key);
void attachmentAboutToBeRemoved(QString key);
void attachmentRemoved(QString key);
private:
Uuid m_uuid;
int m_iconNumber;