Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/entry/EntryAttachmentsModel.cpp')
-rw-r--r--src/gui/entry/EntryAttachmentsModel.cpp36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/gui/entry/EntryAttachmentsModel.cpp b/src/gui/entry/EntryAttachmentsModel.cpp
index 082641380..608744841 100644
--- a/src/gui/entry/EntryAttachmentsModel.cpp
+++ b/src/gui/entry/EntryAttachmentsModel.cpp
@@ -26,6 +26,8 @@ EntryAttachmentsModel::EntryAttachmentsModel(QObject* parent)
: QAbstractListModel(parent)
, m_entryAttachments(nullptr)
{
+ m_headers << tr("Name")
+ << tr("Size");
}
void EntryAttachmentsModel::setEntryAttachments(EntryAttachments* entryAttachments)
@@ -65,7 +67,17 @@ int EntryAttachmentsModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
- return 1;
+ return Columns::ColumnsCount;
+}
+
+QVariant EntryAttachmentsModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
+ Q_ASSERT(m_headers.size() == columnCount());
+ return m_headers[section];
+ }
+
+ return QAbstractListModel::headerData(section, orientation, role);
}
QVariant EntryAttachmentsModel::data(const QModelIndex& index, int role) const
@@ -74,15 +86,21 @@ QVariant EntryAttachmentsModel::data(const QModelIndex& index, int role) const
return QVariant();
}
- if (role == Qt::DisplayRole && index.column() == 0) {
- QString key = keyByIndex(index);
-
- return QString("%1 (%2)").arg(key,
- Tools::humanReadableFileSize(m_entryAttachments->value(key).size()));
- }
- else {
- return QVariant();
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ const QString key = keyByIndex(index);
+ const int column = index.column();
+ if (column == Columns::NameColumn) {
+ return key;
+ } else if (column == SizeColumn) {
+ const int attachmentSize = m_entryAttachments->value(key).size();
+ if (role == Qt::DisplayRole) {
+ return Tools::humanReadableFileSize(attachmentSize);
+ }
+ return attachmentSize;
+ }
}
+
+ return QVariant();
}
QString EntryAttachmentsModel::keyByIndex(const QModelIndex& index) const