mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-09-18 03:44:49 -04:00
Subclass QSortFilterProxyModel to hide the group column in EntryView.
QTreeView::hideColumn() does not work well with keyboard search.
This commit is contained in:
parent
edb644baef
commit
9ad4cc8783
8 changed files with 138 additions and 11 deletions
|
@ -79,6 +79,7 @@ set(keepassx_SOURCES
|
|||
gui/LineEdit.cpp
|
||||
gui/MainWindow.cpp
|
||||
gui/SettingsWidget.cpp
|
||||
gui/SortFilterHideProxyModel.cpp
|
||||
gui/WelcomeWidget.cpp
|
||||
gui/entry/AutoTypeAssociationsModel.cpp
|
||||
gui/entry/EditEntryWidget.cpp
|
||||
|
@ -133,6 +134,7 @@ set(keepassx_MOC
|
|||
gui/LineEdit.h
|
||||
gui/MainWindow.h
|
||||
gui/SettingsWidget.h
|
||||
gui/SortFilterHideProxyModel.h
|
||||
gui/WelcomeWidget.h
|
||||
gui/entry/AutoTypeAssociationsModel.h
|
||||
gui/entry/EditEntryWidget.h
|
||||
|
|
38
src/gui/SortFilterHideProxyModel.cpp
Normal file
38
src/gui/SortFilterHideProxyModel.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "SortFilterHideProxyModel.h"
|
||||
|
||||
SortFilterHideProxyModel::SortFilterHideProxyModel(QObject* parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void SortFilterHideProxyModel::hideColumn(int column, bool hide)
|
||||
{
|
||||
m_hiddenColumns.resize(column + 1);
|
||||
m_hiddenColumns[column] = hide;
|
||||
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
bool SortFilterHideProxyModel::filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const
|
||||
{
|
||||
Q_UNUSED(sourceParent);
|
||||
|
||||
return sourceColumn >= m_hiddenColumns.size() || !m_hiddenColumns.at(sourceColumn);
|
||||
}
|
41
src/gui/SortFilterHideProxyModel.h
Normal file
41
src/gui/SortFilterHideProxyModel.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSX_SORTFILTERHIDEPROXYMODEL_H
|
||||
#define KEEPASSX_SORTFILTERHIDEPROXYMODEL_H
|
||||
|
||||
#include <QtCore/QBitArray>
|
||||
#include <QtGui/QSortFilterProxyModel>
|
||||
|
||||
#include "core/Global.h"
|
||||
|
||||
class SortFilterHideProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SortFilterHideProxyModel(QObject* parent = Q_NULLPTR);
|
||||
void hideColumn(int column, bool hide);
|
||||
|
||||
protected:
|
||||
bool filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QBitArray m_hiddenColumns;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_SORTFILTERHIDEPROXYMODEL_H
|
|
@ -41,7 +41,7 @@ QModelIndex EntryModel::indexFromEntry(Entry* entry) const
|
|||
{
|
||||
int row = m_entries.indexOf(entry);
|
||||
Q_ASSERT(row != -1);
|
||||
return index(row, 0);
|
||||
return index(row, 1);
|
||||
}
|
||||
|
||||
void EntryModel::setGroup(Group* group)
|
||||
|
@ -83,6 +83,7 @@ void EntryModel::setEntryList(const QList<Entry*>& entries)
|
|||
}
|
||||
|
||||
Q_FOREACH (Database* db, databases) {
|
||||
Q_ASSERT(db);
|
||||
m_allGroups.append(db->rootGroup()->groupsRecursive(true));
|
||||
}
|
||||
|
||||
|
|
|
@ -17,14 +17,13 @@
|
|||
|
||||
#include "EntryView.h"
|
||||
|
||||
#include <QtGui/QSortFilterProxyModel>
|
||||
|
||||
#include "gui/SortFilterHideProxyModel.h"
|
||||
#include "gui/entry/EntryModel.h"
|
||||
|
||||
EntryView::EntryView(QWidget* parent)
|
||||
: QTreeView(parent)
|
||||
, m_model(new EntryModel(this))
|
||||
, m_sortModel(new QSortFilterProxyModel(this))
|
||||
, m_sortModel(new SortFilterHideProxyModel(this))
|
||||
, m_inEntryListMode(false)
|
||||
{
|
||||
m_sortModel->setSourceModel(m_model);
|
||||
|
@ -45,8 +44,6 @@ EntryView::EntryView(QWidget* parent)
|
|||
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(entrySelectionChanged()));
|
||||
connect(m_model, SIGNAL(switchedToEntryListMode()), SLOT(switchToEntryListMode()));
|
||||
connect(m_model, SIGNAL(switchedToGroupMode()), SLOT(switchToGroupMode()));
|
||||
|
||||
sortByColumn(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
void EntryView::setGroup(Group* group)
|
||||
|
@ -110,15 +107,15 @@ Entry* EntryView::entryFromIndex(const QModelIndex& index)
|
|||
|
||||
void EntryView::switchToEntryListMode()
|
||||
{
|
||||
m_sortModel->hideColumn(0, false);
|
||||
sortByColumn(1, Qt::AscendingOrder); // TODO: should probably be improved
|
||||
sortByColumn(0, Qt::AscendingOrder);
|
||||
showColumn(0);
|
||||
m_inEntryListMode = true;
|
||||
}
|
||||
|
||||
void EntryView::switchToGroupMode()
|
||||
{
|
||||
sortByColumn(1, Qt::AscendingOrder);
|
||||
hideColumn(0);
|
||||
m_sortModel->hideColumn(0, true);
|
||||
sortByColumn(0, Qt::AscendingOrder);
|
||||
m_inEntryListMode = false;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
class Entry;
|
||||
class EntryModel;
|
||||
class Group;
|
||||
class QSortFilterProxyModel;
|
||||
class SortFilterHideProxyModel;
|
||||
|
||||
class EntryView : public QTreeView
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
EntryModel* const m_model;
|
||||
QSortFilterProxyModel* const m_sortModel;
|
||||
SortFilterHideProxyModel* const m_sortModel;
|
||||
bool m_inEntryListMode;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue