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
This commit is contained in:
Jonathan White 2020-08-23 12:21:59 -04:00
parent 639e44e182
commit f17fce9461
2 changed files with 16 additions and 6 deletions

View File

@ -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;
}

View File

@ -80,6 +80,7 @@ private slots:
private:
void resetFixedColumns();
bool isColumnHidden(int logicalIndex);
EntryModel* const m_model;
SortFilterHideProxyModel* const m_sortModel;