Skip to content

Commit

Permalink
Fix Paperclip and Totp columns not saving state
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
droidmonkey committed Aug 30, 2020
1 parent 9a35bba commit 750a74a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/gui/entry/EntryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
}

/**
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/gui/entry/EntryView.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private slots:

private:
void resetFixedColumns();
bool isColumnHidden(int logicalIndex);

EntryModel* const m_model;
SortFilterHideProxyModel* const m_sortModel;
Expand Down

0 comments on commit 750a74a

Please sign in to comment.