From f17fce9461521e1927c07da799917e520ab7538f Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 23 Aug 2020 12:21:59 -0400 Subject: [PATCH] Fix Paperclip and Totp columns not saving state * Work around Qt bug that causes isSectionHidden to return false after restoring state due to the section actually only being set to 0 width. * Fixes #5317 --- src/gui/entry/EntryView.cpp | 21 +++++++++++++++------ src/gui/entry/EntryView.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index 18a69687d..a387575e9 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -379,8 +379,7 @@ void EntryView::showHeaderMenu(const QPoint& position) continue; } int columnIndex = action->data().toInt(); - bool hidden = header()->isSectionHidden(columnIndex) || (header()->sectionSize(columnIndex) == 0); - action->setChecked(!hidden); + action->setChecked(!isColumnHidden(columnIndex)); } m_headerMenu->popup(mapToGlobal(position)); @@ -408,6 +407,7 @@ void EntryView::toggleColumnVisibility(QAction* action) if (header()->sectionSize(columnIndex) == 0) { header()->resizeSection(columnIndex, header()->defaultSectionSize()); } + resetFixedColumns(); return; } if ((header()->count() - header()->hiddenSectionCount()) > 1) { @@ -460,11 +460,15 @@ void EntryView::fitColumnsToContents() */ void EntryView::resetFixedColumns() { - header()->setSectionResizeMode(EntryModel::Paperclip, QHeaderView::Fixed); - header()->resizeSection(EntryModel::Paperclip, header()->minimumSectionSize()); + if (!isColumnHidden(EntryModel::Paperclip)) { + header()->setSectionResizeMode(EntryModel::Paperclip, QHeaderView::Fixed); + header()->resizeSection(EntryModel::Paperclip, header()->minimumSectionSize()); + } - header()->setSectionResizeMode(EntryModel::Totp, QHeaderView::Fixed); - header()->resizeSection(EntryModel::Totp, header()->minimumSectionSize()); + if (!isColumnHidden(EntryModel::Totp)) { + header()->setSectionResizeMode(EntryModel::Totp, QHeaderView::Fixed); + header()->resizeSection(EntryModel::Totp, header()->minimumSectionSize()); + } } /** @@ -533,3 +537,8 @@ void EntryView::showEvent(QShowEvent* event) m_columnsNeedRelayout = false; } } + +bool EntryView::isColumnHidden(int logicalIndex) +{ + return header()->isSectionHidden(logicalIndex) || header()->sectionSize(logicalIndex) == 0; +} diff --git a/src/gui/entry/EntryView.h b/src/gui/entry/EntryView.h index e32aa4729..65cbf104a 100644 --- a/src/gui/entry/EntryView.h +++ b/src/gui/entry/EntryView.h @@ -80,6 +80,7 @@ private slots: private: void resetFixedColumns(); + bool isColumnHidden(int logicalIndex); EntryModel* const m_model; SortFilterHideProxyModel* const m_sortModel;