diff --git a/src/gui/entry/EntryAttachmentsModel.cpp b/src/gui/entry/EntryAttachmentsModel.cpp index 332ed754c..608744841 100644 --- a/src/gui/entry/EntryAttachmentsModel.cpp +++ b/src/gui/entry/EntryAttachmentsModel.cpp @@ -86,17 +86,20 @@ QVariant EntryAttachmentsModel::data(const QModelIndex& index, int role) const return QVariant(); } - if (role == Qt::DisplayRole) { - QString key = keyByIndex(index); - switch (index.column()) { - case Columns::NameColumn: + if (role == Qt::DisplayRole || role == Qt::EditRole) { + const QString key = keyByIndex(index); + const int column = index.column(); + if (column == Columns::NameColumn) { return key; - case Columns::SizeColumn: - return Tools::humanReadableFileSize(m_entryAttachments->value(key).size()); - default: - break; + } else if (column == SizeColumn) { + const int attachmentSize = m_entryAttachments->value(key).size(); + if (role == Qt::DisplayRole) { + return Tools::humanReadableFileSize(attachmentSize); + } + return attachmentSize; } } + return QVariant(); } diff --git a/tests/TestEntryModel.cpp b/tests/TestEntryModel.cpp index e0c8bb490..ad7c9060a 100644 --- a/tests/TestEntryModel.cpp +++ b/tests/TestEntryModel.cpp @@ -122,9 +122,11 @@ void TestEntryModel::testAttachmentsModel() entryAttachments->set("first", QByteArray("123")); entryAttachments->set("2nd", QByteArray("456")); - entryAttachments->set("2nd", QByteArray("789")); + entryAttachments->set("2nd", QByteArray("7890")); - QCOMPARE(model->data(model->index(0, 0)).toString().left(4), QString("2nd ")); + const int firstRow = 0; + QCOMPARE(model->data(model->index(firstRow, EntryAttachmentsModel::NameColumn)).toString(), QString("2nd")); + QCOMPARE(model->data(model->index(firstRow, EntryAttachmentsModel::SizeColumn), Qt::EditRole).toInt(), 4); entryAttachments->remove("first");