Add support for working with multiple entry attachments at once

This commit is contained in:
frostasm
2017-10-22 21:15:25 +03:00
parent 2987895370
commit f34b090b42
6 changed files with 265 additions and 72 deletions

View File

@@ -17,6 +17,8 @@
#include "EntryAttachments.h"
#include <QStringList>
EntryAttachments::EntryAttachments(QObject* parent)
: QObject(parent)
{
@@ -71,7 +73,8 @@ void EntryAttachments::set(const QString& key, const QByteArray& value)
void EntryAttachments::remove(const QString& key)
{
if (!m_attachments.contains(key)) {
Q_ASSERT(false);
Q_ASSERT_X(false, "EntryAttachments::remove",
qPrintable(QString("Can't find attachment for key %1").arg(key)));
return;
}
@@ -83,6 +86,31 @@ void EntryAttachments::remove(const QString& key)
emit modified();
}
void EntryAttachments::remove(const QStringList &keys)
{
if (keys.isEmpty()) {
return;
}
bool isModified = false;
for (const QString &key: keys) {
if (!m_attachments.contains(key)) {
Q_ASSERT_X(false, "EntryAttachments::remove",
qPrintable(QString("Can't find attachment for key %1").arg(key)));
continue;
}
isModified = true;
emit aboutToBeRemoved(key);
m_attachments.remove(key);
emit removed(key);
}
if (isModified) {
emit modified();
}
}
void EntryAttachments::clear()
{
if (m_attachments.isEmpty()) {