2 * Copyright (C) 2011, 2013 Canonical, Ltd.
5 * Florian Boucault <florian.boucault@canonical.com>
6 * Pawel Stolowski <pawel.stolowski@canonical.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 3.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30Filters::Filters(unity::dash::Filters::Ptr unityFilters, QObject *parent) :
31 QAbstractListModel(parent), m_unityFilters(unityFilters)
33 for (unsigned int i=0; i<m_unityFilters->count(); i++) {
34 unity::dash::Filter::Ptr unityFilter = m_unityFilters->FilterAtIndex(i);
35 addFilter(unityFilter, i);
37 m_unityFilters->filter_added.connect(sigc::mem_fun(this, &Filters::onFilterAdded));
38 m_unityFilters->filter_changed.connect(sigc::mem_fun(this, &Filters::onFilterChanged));
39 m_unityFilters->filter_removed.connect(sigc::mem_fun(this, &Filters::onFilterRemoved));
44 while (!m_filters.isEmpty()) {
45 delete m_filters.takeFirst();
49int Filters::rowCount(const QModelIndex& parent) const
53 return m_unityFilters->count();
56QVariant Filters::data(const QModelIndex& index, int role) const
58 if (!index.isValid()) {
62 Filter* filter = m_filters.at(index.row());
67 case Filters::RoleName:
69 return filter->name();
70 case Filters::RoleIconHint:
71 return filter->iconHint();
72 case Filters::RoleRendererName:
73 return filter->rendererName();
74 case Filters::RoleVisible:
75 return filter->visible();
76 case Filters::RoleCollapsed:
77 return filter->collapsed();
78 case Filters::RoleFiltering:
79 return filter->filtering();
86QHash<int, QByteArray> Filters::roleNames() const
88 QHash<int, QByteArray> roles;
89 roles[Filters::RoleId] = "id";
90 roles[Filters::RoleName] = "name";
91 roles[Filters::RoleIconHint] = "iconHint";
92 roles[Filters::RoleRendererName] = "rendererName";
93 roles[Filters::RoleVisible] = "visible";
94 roles[Filters::RoleCollapsed] = "collapsed";
95 roles[Filters::RoleFiltering] = "filtering";
99Filter* Filters::getFilter(const QString& id) const
101 Q_FOREACH (Filter* filter, m_filters) {
102 if (filter->id() == id) {
109void Filters::onFilterAdded(unity::dash::Filter::Ptr unityFilter)
111 if (unityFilter == nullptr) {
115 int index = m_filters.count();
116 addFilter(unityFilter, index);
119void Filters::onFilterChanged(unity::dash::Filter::Ptr unityFilter)
121 if (unityFilter == nullptr) {
125 QModelIndex filterIndex = index(indexForFilter(unityFilter));
126 Q_EMIT dataChanged(filterIndex, filterIndex);
129void Filters::onFilterRemoved(unity::dash::Filter::Ptr unityFilter)
131 removeFilter(indexForFilter(unityFilter));
134void Filters::addFilter(unity::dash::Filter::Ptr unityFilter, int index)
136 beginInsertRows(QModelIndex(), index, index);
137 Filter* filter = Filter::newFromUnityFilter(unityFilter);
138 if (filter != nullptr) {
139 m_filters.insert(index, filter);
144void Filters::removeFilter(int index)
146 beginRemoveRows(QModelIndex(), index, index);
147 Filter* filter = m_filters.takeAt(index);
152int Filters::indexForFilter(unity::dash::Filter::Ptr unityFilter)
154 for (int index=0; index<m_filters.count(); index++) {
155 if (m_filters[index]->hasUnityFilter(unityFilter)) {
159 qWarning() << "Filter" << QString::fromStdString(unityFilter->name()) << "not found in local cache.";
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