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/>.
26#include "genericoptionsmodel.h"
31Filters::Filters(unity::dash::Filters::Ptr unityFilters, QObject *parent) :
32 QAbstractListModel(parent), m_unityFilters(unityFilters)
34 for (unsigned int i=0; i<m_unityFilters->count(); i++) {
35 unity::dash::Filter::Ptr unityFilter = m_unityFilters->FilterAtIndex(i);
36 addFilter(unityFilter, i);
38 m_unityFilters->filter_added.connect(sigc::mem_fun(this, &Filters::onFilterAdded));
39 m_unityFilters->filter_changed.connect(sigc::mem_fun(this, &Filters::onFilterChanged));
40 m_unityFilters->filter_removed.connect(sigc::mem_fun(this, &Filters::onFilterRemoved));
45 while (!m_filters.isEmpty()) {
46 delete m_filters.takeFirst();
50int Filters::rowCount(const QModelIndex& parent) const
54 return m_unityFilters->count();
57QVariant Filters::data(const QModelIndex& index, int role) const
59 if (!index.isValid()) {
63 Filter* filter = m_filters.at(index.row());
68 case Filters::RoleName:
70 return filter->name();
71 case Filters::RoleIconHint:
72 return filter->iconHint();
73 case Filters::RoleRendererName:
74 return filter->rendererName();
75 case Filters::RoleVisible:
76 return filter->visible();
77 case Filters::RoleCollapsed:
78 return filter->collapsed();
79 case Filters::RoleFiltering:
80 return filter->filtering();
81 case Filters::RoleOptions:
82 return QVariant::fromValue(filter->options());
89QHash<int, QByteArray> Filters::roleNames() const
91 QHash<int, QByteArray> roles;
92 roles[Filters::RoleId] = "id";
93 roles[Filters::RoleName] = "name";
94 roles[Filters::RoleIconHint] = "iconHint";
95 roles[Filters::RoleRendererName] = "rendererName";
96 roles[Filters::RoleVisible] = "visible";
97 roles[Filters::RoleCollapsed] = "collapsed";
98 roles[Filters::RoleFiltering] = "filtering";
99 roles[Filters::RoleOptions] = "options";
103Filter* Filters::getFilter(const QString& id) const
105 Q_FOREACH (Filter* filter, m_filters) {
106 if (filter->id() == id) {
113void Filters::onFilterAdded(unity::dash::Filter::Ptr unityFilter)
115 if (unityFilter == nullptr) {
119 int index = m_filters.count();
120 addFilter(unityFilter, index);
123void Filters::onFilterChanged(unity::dash::Filter::Ptr unityFilter)
125 if (unityFilter == nullptr) {
129 QModelIndex filterIndex = index(indexForFilter(unityFilter));
130 Q_EMIT dataChanged(filterIndex, filterIndex);
133void Filters::onFilterRemoved(unity::dash::Filter::Ptr unityFilter)
135 removeFilter(indexForFilter(unityFilter));
138void Filters::addFilter(unity::dash::Filter::Ptr unityFilter, int index)
140 beginInsertRows(QModelIndex(), index, index);
141 Filter* filter = Filter::newFromUnityFilter(unityFilter);
142 if (filter != nullptr) {
143 m_filters.insert(index, filter);
148void Filters::removeFilter(int index)
150 beginRemoveRows(QModelIndex(), index, index);
151 Filter* filter = m_filters.takeAt(index);
156int Filters::indexForFilter(unity::dash::Filter::Ptr unityFilter)
158 for (int index=0; index<m_filters.count(); index++) {
159 if (m_filters[index]->hasUnityFilter(unityFilter)) {
163 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