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/>.
31#include <UnityCore/Filters.h>
33Filters::Filters(unity::dash::Filters::Ptr unityFilters, QObject *parent) :
34 QAbstractListModel(parent), m_unityFilters(unityFilters)
36 for (unsigned int i=0; i<m_unityFilters->count(); i++) {
37 unity::dash::Filter::Ptr unityFilter = m_unityFilters->FilterAtIndex(i);
38 addFilter(unityFilter, i);
40 m_unityFilters->filter_added.connect(sigc::mem_fun(this, &Filters::onFilterAdded));
41 m_unityFilters->filter_changed.connect(sigc::mem_fun(this, &Filters::onFilterChanged));
42 m_unityFilters->filter_removed.connect(sigc::mem_fun(this, &Filters::onFilterRemoved));
47 while (!m_filters.isEmpty()) {
48 delete m_filters.takeFirst();
52int Filters::rowCount(const QModelIndex& parent) const
56 return m_unityFilters->count();
59QVariant Filters::data(const QModelIndex& index, int role) const
63 if (!index.isValid()) {
67 Filter* filter = m_filters.at(index.row());
69 if (role == Filters::RoleFilter) {
70 return QVariant::fromValue(filter);
76QHash<int, QByteArray> Filters::roleNames() const
78 QHash<int, QByteArray> roles;
79 roles[Filters::RoleFilter] = "filter";
83Filter* Filters::getFilter(const QString& id) const
85 Q_FOREACH (Filter* filter, m_filters) {
86 if (filter->id() == id) {
93void Filters::onFilterAdded(unity::dash::Filter::Ptr unityFilter)
95 if (unityFilter == nullptr) {
99 int index = m_filters.count();
100 addFilter(unityFilter, index);
103void Filters::onFilterChanged(unity::dash::Filter::Ptr unityFilter)
105 if (unityFilter == nullptr) {
109 QModelIndex filterIndex = index(indexForFilter(unityFilter));
110 Q_EMIT dataChanged(filterIndex, filterIndex);
113void Filters::onFilterRemoved(unity::dash::Filter::Ptr unityFilter)
115 removeFilter(indexForFilter(unityFilter));
118void Filters::addFilter(unity::dash::Filter::Ptr unityFilter, int index)
120 beginInsertRows(QModelIndex(), index, index);
121 Filter* filter = Filter::newFromUnityFilter(unityFilter);
122 m_filters.insert(index, filter);
126void Filters::removeFilter(int index)
128 beginRemoveRows(QModelIndex(), index, index);
129 Filter* filter = m_filters.takeAt(index);
134int Filters::indexForFilter(unity::dash::Filter::Ptr unityFilter)
137 for (index=0; index<m_filters.count(); index++) {
138 if (m_filters[index]->hasUnityFilter(unityFilter)) {
142 qWarning() << "Filter" << QString::fromStdString(unityFilter->name()) << "not found in local cache.";
147#include "filters.moc"
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