From 161d0ea50fdd544fb5a64fd3b19297615d5a53f2 Mon Sep 17 00:00:00 2001 From: Fonic Date: Mon, 15 Jan 2018 10:06:45 +0100 Subject: [PATCH] Add column 'Paperclip' to entry view table Add additional column 'Paperclip' to entry view table: - add column itself - add display role data provider - add sort role data provider - update total column count --- src/gui/entry/EntryModel.cpp | 45 ++++++++++++++++++++++++++++-------- src/gui/entry/EntryModel.h | 12 ++++++++-- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index 18d6f1a00..12d85e499 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -42,9 +42,9 @@ * Decide which of the proposed options should be used (stars, bullet, black * circle) */ -//const QString EntryModel::HiddenContent("******"); -//const QString EntryModel::HiddenContent(QString(QChar(0x2022)).repeated(6)); -const QString EntryModel::HiddenContent(QString(QChar(0x25CF)).repeated(6)); +//const QString EntryModel::HiddenContentDisplay("******"); +//const QString EntryModel::HiddenContentDisplay(QString(QChar(0x2022)).repeated(6)); +const QString EntryModel::HiddenContentDisplay(QString(QChar(0x25CF)).repeated(6)); /** * @author Fonic @@ -53,6 +53,18 @@ const QString EntryModel::HiddenContent(QString(QChar(0x25CF)).repeated(6)); */ const Qt::DateFormat EntryModel::DateFormat = Qt::DefaultLocaleShortDate; +/** + * @author Fonic + * Define constant string used to display header and data of column 'Paper- + * clip' + * + * TODO: + * When using unicode, ASAN reports memory leaks, but when using a plain + * string like 'x', no leaks are reported. Check if this is something to + * worry about, might as well be a Qt bug + */ +const QString EntryModel::PaperClipDisplay(QString("\U0001f4ce")); + /** * @author Fonic * Initialize 'Hide Usernames' and 'Hide Passwords' settings using sane @@ -152,14 +164,15 @@ int EntryModel::columnCount(const QModelIndex& parent) const /** * @author Fonic * Change column count to include additional columns 'Password', 'Notes', - * 'Expires', 'Created', 'Modified', 'Accessed' and 'Attachments'. Also, - * return 0 when parent is valid as advised by Qt documentation + * 'Expires', 'Created', 'Modified', 'Accessed', 'Paperclip' and + * 'Attachments'. Also, return 0 when parent is valid as advised by Qt + * documentation */ if (parent.isValid()) { return 0; } else { - return 11; + return 12; } } @@ -176,7 +189,8 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const * @author Fonic * * Add display data providers for additional columns 'Password', 'Notes', - * 'Expires', 'Created', 'Modified', 'Accessed' and 'Attachments' + * 'Expires', 'Created', 'Modified', 'Accessed', 'Paperclip' and + * 'Attachments' * * Add ability to display usernames and passwords hidden or visible * depending on current state of 'Hide Usernames' and 'Hide Passwords' @@ -211,7 +225,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const * of 'Hide Usernames' setting */ if (m_hideUsernames) { - result = EntryModel::HiddenContent; + result = EntryModel::HiddenContentDisplay; } else { //result = entry->username(); @@ -227,7 +241,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const * of 'Hide Passwords' setting */ if (m_hidePasswords) { - result = EntryModel::HiddenContent; + result = EntryModel::HiddenContentDisplay; } else { //result = entry->resolveMultiplePlaceholders(entry->password()); @@ -270,6 +284,9 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const case Accessed: result = entry->timeInfo().lastAccessTime().toLocalTime().toString(EntryModel::DateFormat); return result; + case Paperclip: + result = entry->attachments()->keys().isEmpty() ? QString() : EntryModel::PaperClipDisplay; + return result; case Attachments: /* * Display comma-separated list of attachments @@ -308,6 +325,10 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const * sorting would be based on string representation of dates, yielding un- * desired results) * + * Add sort data provider for column 'Paperclip', required to display + * entries with attachments above those without when sorting ascendingly + * (and vice versa when sorting descendingly) + * * NOTE: * Qt::UserRole is used as sort role, using 'm_sortModel->setSortRole(Qt:: * UserRole)' in EntryView.cpp, EntryView::EntryView() @@ -333,6 +354,8 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const return entry->timeInfo().lastModificationTime(); case Accessed: return entry->timeInfo().lastAccessTime(); + case Paperclip: + return entry->attachments()->keys().isEmpty() ? 1 : 0; default: /* * For all other columns, simply use data provided by Qt::Display- @@ -379,7 +402,7 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro /** * @author Fonic * Add captions for additional columns 'Password', 'Notes', 'Expires', - * 'Created', 'Modified', 'Accessed' and 'Attachments' + * 'Created', 'Modified', 'Accessed', 'Paperclip' and 'Attachments' */ if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { switch (section) { @@ -403,6 +426,8 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro return tr("Modified"); case Accessed: return tr("Accessed"); + case Paperclip: + return EntryModel::PaperClipDisplay; case Attachments: return tr("Attachments"); } diff --git a/src/gui/entry/EntryModel.h b/src/gui/entry/EntryModel.h index 7540df986..75243e52f 100644 --- a/src/gui/entry/EntryModel.h +++ b/src/gui/entry/EntryModel.h @@ -45,7 +45,8 @@ public: Created = 7, Modified = 8, Accessed = 9, - Attachments = 10 + Paperclip = 10, + Attachments = 11 }; explicit EntryModel(QObject* parent = nullptr); @@ -130,7 +131,7 @@ private: * Constant string used to display hidden content in columns 'Username' * and 'Password' */ - static const QString HiddenContent; + static const QString HiddenContentDisplay; /** * @author Fonic @@ -138,6 +139,13 @@ private: * 'Modified' and 'Accessed' */ static const Qt::DateFormat DateFormat; + + /** + * @author Fonic + * Constant string used to display header and data of column 'Paper- + * clip' + */ + static const QString PaperClipDisplay; }; #endif // KEEPASSX_ENTRYMODEL_H