1#include "appdrawerproxymodel.h"
5AppDrawerProxyModel::AppDrawerProxyModel(QObject *parent):
6 QSortFilterProxyModel(parent)
8 setSortRole(AppDrawerModelInterface::RoleName);
9 setSortLocaleAware(true);
12 connect(this, &QAbstractListModel::rowsInserted, this, &AppDrawerProxyModel::countChanged);
13 connect(this, &QAbstractListModel::rowsRemoved, this, &AppDrawerProxyModel::countChanged);
14 connect(this, &QAbstractListModel::layoutChanged, this, &AppDrawerProxyModel::countChanged);
17QAbstractItemModel *AppDrawerProxyModel::source() const
22void AppDrawerProxyModel::setSource(QAbstractItemModel *source)
24 if (m_source != source) {
26 setSourceModel(m_source);
27 setSortRole(m_sortBy == SortByAToZ ? AppDrawerModelInterface::RoleName : AppDrawerModelInterface::RoleUsage);
28 connect(m_source, &QAbstractItemModel::rowsRemoved, this, &AppDrawerProxyModel::invalidateFilter);
29 connect(m_source, &QAbstractItemModel::rowsInserted, this, &AppDrawerProxyModel::invalidateFilter);
30 Q_EMIT sourceChanged();
34AppDrawerProxyModel::GroupBy AppDrawerProxyModel::group() const
39void AppDrawerProxyModel::setGroup(AppDrawerProxyModel::GroupBy group)
41 if (m_group != group) {
43 Q_EMIT groupChanged();
48QString AppDrawerProxyModel::filterLetter() const
50 return m_filterLetter;
53void AppDrawerProxyModel::setFilterLetter(const QString &filterLetter)
55 if (m_filterLetter != filterLetter) {
56 m_filterLetter = filterLetter;
57 Q_EMIT filterLetterChanged();
62QString AppDrawerProxyModel::filterString() const
64 return m_filterString;
67void AppDrawerProxyModel::setFilterString(const QString &filterString)
69 if (m_filterString != filterString) {
70 m_filterString = filterString;
71 Q_EMIT filterStringChanged();
76AppDrawerProxyModel::SortBy AppDrawerProxyModel::sortBy() const
81void AppDrawerProxyModel::setSortBy(AppDrawerProxyModel::SortBy sortBy)
83 if (m_sortBy != sortBy) {
85 Q_EMIT sortByChanged();
86 setSortRole(m_sortBy == SortByAToZ ? AppDrawerModelInterface::RoleName : AppDrawerModelInterface::RoleUsage);
91int AppDrawerProxyModel::count() const
96QVariant AppDrawerProxyModel::data(const QModelIndex &index, int role) const
98 QModelIndex idx = mapToSource(index);
99 if (role == Qt::UserRole) {
100 QString name = m_source->data(idx, AppDrawerModelInterface::RoleName).toString();
101 return name.length() > 0 ? QString(name.at(0)).toUpper() : QChar();
103 return m_source->data(idx, role);
106QHash<int, QByteArray> AppDrawerProxyModel::roleNames() const
109 QHash<int, QByteArray> roles = m_source->roleNames();
110 roles.insert(Qt::UserRole, "letter");
113 return QHash<int, QByteArray>();
116bool AppDrawerProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
118 Q_UNUSED(source_parent)
120 if (m_group == GroupByAToZ && source_row > 0) {
121 QString currentName = m_source->data(m_source->index(source_row, 0), AppDrawerModelInterface::RoleName).toString();
122 QChar currentLetter = currentName.length() > 0 ? currentName.at(0) : QChar();
123 QString previousName = m_source->data(m_source->index(source_row - 1,0 ), AppDrawerModelInterface::RoleName).toString();
124 QChar previousLetter = previousName.length() > 0 ? previousName.at(0) : QChar();
125 if (currentLetter.toLower() == previousLetter.toLower()) {
128 } else if(m_group == GroupByAll && source_row > 0) {
131 if (!m_filterLetter.isEmpty()) {
132 QString currentName = m_source->data(m_source->index(source_row, 0), AppDrawerModelInterface::RoleName).toString();
133 QString currentLetter = currentName.length() > 0 ? QString(currentName.at(0)) : QString();
134 if (currentLetter.toLower() != m_filterLetter.toLower()) {
138 if (!m_filterString.isEmpty()) {
139 QString currentLabel = m_source->data(m_source->index(source_row, 0), AppDrawerModelInterface::RoleName).toString().toLower();
140 if (!currentLabel.startsWith(m_filterString.toLower())) {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list