2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "appdrawerproxymodel.h"
19#include <unity/shell/launcher/LauncherItemInterface.h>
23AppDrawerProxyModel::AppDrawerProxyModel(QObject *parent):
24 QSortFilterProxyModel(parent)
26 setSortRole(AppDrawerModelInterface::RoleName);
27 setSortLocaleAware(true);
30 connect(this, &QAbstractListModel::rowsInserted, this, &AppDrawerProxyModel::countChanged);
31 connect(this, &QAbstractListModel::rowsRemoved, this, &AppDrawerProxyModel::countChanged);
32 connect(this, &QAbstractListModel::layoutChanged, this, &AppDrawerProxyModel::countChanged);
35QAbstractItemModel *AppDrawerProxyModel::source() const
40void AppDrawerProxyModel::setSource(QAbstractItemModel *source)
42 if (m_source != source) {
44 setSourceModel(m_source);
45 setSortRole(m_sortBy == SortByAToZ ? AppDrawerModelInterface::RoleName : AppDrawerModelInterface::RoleUsage);
46 connect(m_source, &QAbstractItemModel::rowsRemoved, this, &AppDrawerProxyModel::invalidate);
47 connect(m_source, &QAbstractItemModel::rowsInserted, this, &AppDrawerProxyModel::invalidate);
48 Q_EMIT sourceChanged();
52AppDrawerProxyModel::GroupBy AppDrawerProxyModel::group() const
57void AppDrawerProxyModel::setGroup(AppDrawerProxyModel::GroupBy group)
59 if (m_group != group) {
61 Q_EMIT groupChanged();
66QString AppDrawerProxyModel::filterLetter() const
68 return m_filterLetter;
71void AppDrawerProxyModel::setFilterLetter(const QString &filterLetter)
73 if (m_filterLetter != filterLetter) {
74 m_filterLetter = filterLetter;
75 Q_EMIT filterLetterChanged();
80QString AppDrawerProxyModel::filterString() const
82 return m_filterString;
85void AppDrawerProxyModel::setFilterString(const QString &filterString)
87 if (m_filterString != filterString) {
88 m_filterString = filterString;
89 Q_EMIT filterStringChanged();
94AppDrawerProxyModel::SortBy AppDrawerProxyModel::sortBy() const
99void AppDrawerProxyModel::setSortBy(AppDrawerProxyModel::SortBy sortBy)
101 if (m_sortBy != sortBy) {
103 Q_EMIT sortByChanged();
104 setSortRole(m_sortBy == SortByAToZ ? AppDrawerModelInterface::RoleName : AppDrawerModelInterface::RoleUsage);
109int AppDrawerProxyModel::count() const
114QVariant AppDrawerProxyModel::data(const QModelIndex &index, int role) const
116 QModelIndex idx = mapToSource(index);
117 if (role == Qt::UserRole) {
118 QString name = m_source->data(idx, AppDrawerModelInterface::RoleName).toString();
119 return name.length() > 0 ? QString(name.at(0)).toUpper() : QChar();
121 return m_source->data(idx, role);
124QHash<int, QByteArray> AppDrawerProxyModel::roleNames() const
127 QHash<int, QByteArray> roles = m_source->roleNames();
128 roles.insert(Qt::UserRole, "letter");
131 return QHash<int, QByteArray>();
134bool AppDrawerProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
136 Q_UNUSED(source_parent)
138 if (m_group == GroupByAToZ && source_row > 0) {
139 QString currentName = m_source->data(m_source->index(source_row, 0), AppDrawerModelInterface::RoleName).toString();
140 QChar currentLetter = currentName.length() > 0 ? currentName.at(0) : QChar();
141 QString previousName = m_source->data(m_source->index(source_row - 1,0 ), AppDrawerModelInterface::RoleName).toString();
142 QChar previousLetter = previousName.length() > 0 ? previousName.at(0) : QChar();
143 if (currentLetter.toLower() == previousLetter.toLower()) {
146 } else if(m_group == GroupByAll && source_row > 0) {
149 if (!m_filterLetter.isEmpty()) {
150 QString currentName = m_source->data(m_source->index(source_row, 0), AppDrawerModelInterface::RoleName).toString();
151 QString currentLetter = currentName.length() > 0 ? QString(currentName.at(0)) : QString();
152 if (currentLetter.toLower() != m_filterLetter.toLower()) {
156 if (!m_filterString.isEmpty()) {
157 QStringList allWords = m_source->data(m_source->index(source_row, 0), AppDrawerModelInterface::RoleKeywords).toStringList();
158 allWords.prepend(m_source->data(m_source->index(source_row, 0), AppDrawerModelInterface::RoleName).toString());
160 Q_FOREACH (const QString ¤tWord, allWords) {
161 if (currentWord.startsWith(m_filterString, Qt::CaseInsensitive)) {
173QString AppDrawerProxyModel::appId(int index) const
175 if (index >= 0 && index < rowCount()) {
176 QModelIndex sourceIndex = mapToSource(this->index(index, 0));
178 AppDrawerModelInterface* adm = dynamic_cast<AppDrawerModelInterface*>(m_source);
180 return adm->data(sourceIndex, AppDrawerModelInterface::RoleAppId).toString();
183 AppDrawerProxyModel* adpm = qobject_cast<AppDrawerProxyModel*>(m_source);
185 return adpm->appId(sourceIndex.row());
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