diff options
Diffstat (limited to 'src/gui/entry/EntryView.cpp')
-rw-r--r-- | src/gui/entry/EntryView.cpp | 103 |
1 files changed, 22 insertions, 81 deletions
diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index 18a69687d..54c1547c7 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -32,7 +32,7 @@ EntryView::EntryView(QWidget* parent) , m_sortModel(new SortFilterHideProxyModel(this)) , m_lastIndex(-1) , m_lastOrder(Qt::AscendingOrder) - , m_inSearchMode(false) + , m_headerMenu(new QMenu(this)) { m_sortModel->setSourceModel(m_model); m_sortModel->setDynamicSortFilter(true); @@ -55,22 +55,10 @@ EntryView::EntryView(QWidget* parent) // clang-format off connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(emitEntryActivated(QModelIndex))); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(emitEntrySelectionChanged())); - connect(m_model, SIGNAL(usernamesHiddenChanged()), SIGNAL(viewStateChanged())); - connect(m_model, SIGNAL(passwordsHiddenChanged()), SIGNAL(viewStateChanged())); // clang-format on new QShortcut(Qt::CTRL + Qt::Key_F10, this, SLOT(contextMenuShortcutPressed()), nullptr, Qt::WidgetShortcut); - m_headerMenu = new QMenu(this); - m_headerMenu->setTitle(tr("Customize View")); - m_headerMenu->addSection(tr("Customize View")); - - m_hideUsernamesAction = m_headerMenu->addAction(tr("Hide Usernames"), this, SLOT(setUsernamesHidden(bool))); - m_hideUsernamesAction->setCheckable(true); - m_hidePasswordsAction = m_headerMenu->addAction(tr("Hide Passwords"), this, SLOT(setPasswordsHidden(bool))); - m_hidePasswordsAction->setCheckable(true); - m_headerMenu->addSeparator(); - resetViewToDefaults(); // Actions to toggle column visibility, each carrying the corresponding @@ -109,21 +97,12 @@ EntryView::EntryView(QWidget* parent) header()->setContextMenuPolicy(Qt::CustomContextMenu); connect(header(), SIGNAL(customContextMenuRequested(QPoint)), SLOT(showHeaderMenu(QPoint))); - // clang-format off - connect(header(), SIGNAL(sectionCountChanged(int,int)), SIGNAL(viewStateChanged())); - // clang-format on - - // clang-format off - connect(header(), SIGNAL(sectionMoved(int,int,int)), SIGNAL(viewStateChanged())); - // clang-format on - - // clang-format off - connect(header(), SIGNAL(sectionResized(int,int,int)), SIGNAL(viewStateChanged())); - // clang-format on + connect(header(), SIGNAL(sectionCountChanged(int, int)), SIGNAL(viewStateChanged())); + connect(header(), SIGNAL(sectionMoved(int, int, int)), SIGNAL(viewStateChanged())); + connect(header(), SIGNAL(sectionResized(int, int, int)), SIGNAL(viewStateChanged())); + connect(header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), SLOT(sortIndicatorChanged(int, Qt::SortOrder))); // clang-format off - connect(header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), SLOT(sortIndicatorChanged(int,Qt::SortOrder))); - // clang-format on } void EntryView::contextMenuShortcutPressed() @@ -302,50 +281,6 @@ int EntryView::currentEntryIndex() } /** - * Get current state of 'Hide Usernames' setting (NOTE: just pass-through for - * m_model) - */ -bool EntryView::isUsernamesHidden() const -{ - return m_model->isUsernamesHidden(); -} - -/** - * Set state of 'Hide Usernames' setting (NOTE: just pass-through for m_model) - */ -void EntryView::setUsernamesHidden(bool hide) -{ - bool block = m_hideUsernamesAction->signalsBlocked(); - m_hideUsernamesAction->blockSignals(true); - m_hideUsernamesAction->setChecked(hide); - m_hideUsernamesAction->blockSignals(block); - - m_model->setUsernamesHidden(hide); -} - -/** - * Get current state of 'Hide Passwords' setting (NOTE: just pass-through for - * m_model) - */ -bool EntryView::isPasswordsHidden() const -{ - return m_model->isPasswordsHidden(); -} - -/** - * Set state of 'Hide Passwords' setting (NOTE: just pass-through for m_model) - */ -void EntryView::setPasswordsHidden(bool hide) -{ - bool block = m_hidePasswordsAction->signalsBlocked(); - m_hidePasswordsAction->blockSignals(true); - m_hidePasswordsAction->setChecked(hide); - m_hidePasswordsAction->blockSignals(block); - - m_model->setPasswordsHidden(hide); -} - -/** * Get current view state */ QByteArray EntryView::viewState() const @@ -358,6 +293,8 @@ QByteArray EntryView::viewState() const */ bool EntryView::setViewState(const QByteArray& state) { + // Reset to unsorted first (https://bugreports.qt.io/browse/QTBUG-86694) + header()->setSortIndicator(-1, Qt::AscendingOrder); bool status = header()->restoreState(state); resetFixedColumns(); m_columnsNeedRelayout = state.isEmpty(); @@ -370,8 +307,6 @@ bool EntryView::setViewState(const QByteArray& state) */ void EntryView::showHeaderMenu(const QPoint& position) { - m_hideUsernamesAction->setChecked(m_model->isUsernamesHidden()); - m_hidePasswordsAction->setChecked(m_model->isPasswordsHidden()); const QList<QAction*> actions = m_columnActions->actions(); for (auto& action : actions) { Q_ASSERT(static_cast<QMetaType::Type>(action->data().type()) == QMetaType::Int); @@ -379,8 +314,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 +342,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 +395,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()); + } } /** @@ -472,9 +411,6 @@ void EntryView::resetFixedColumns() */ void EntryView::resetViewToDefaults() { - m_model->setUsernamesHidden(false); - m_model->setPasswordsHidden(true); - // Reduce number of columns that are shown by default if (m_inSearchMode) { header()->showSection(EntryModel::ParentGroup); @@ -533,3 +469,8 @@ void EntryView::showEvent(QShowEvent* event) m_columnsNeedRelayout = false; } } + +bool EntryView::isColumnHidden(int logicalIndex) +{ + return header()->isSectionHidden(logicalIndex) || header()->sectionSize(logicalIndex) == 0; +} |