2 * Copyright (C) 2013 Canonical, Ltd.
5 * Michał Sawicz <michal.sawicz@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include "categories.h"
22#include "categoryfilter.h"
24Categories::Categories(QObject* parent)
25 : DeeListModel(parent)
28 // FIXME: need to clean up unused filters on countChanged
29 m_roles[Categories::RoleId] = "id";
30 m_roles[Categories::RoleName] = "name";
31 m_roles[Categories::RoleIcon] = "icon";
32 m_roles[Categories::RoleRenderer] = "renderer";
33 m_roles[Categories::RoleContentType] = "content_type";
34 m_roles[Categories::RoleHints] = "hints";
35 m_roles[Categories::RoleResults] = "results";
36 m_roles[Categories::RoleCount] = "count";
38 // TODO This should not be needed but accumulatting the count changes
39 // makes the visualization more stable and also makes crashes on fast
40 // change of the search term harder to reproduce
41 m_timer.setSingleShot(true);
42 m_timer.setInterval(50);
43 connect(&m_timer, SIGNAL(timeout()), this, SLOT(onEmitCountChanged()));
46Categories::~Categories()
48 qDeleteAll(m_filters);
52Categories::getFilter(int index) const
54 if (!m_filters.contains(index)) {
55 CategoryFilter* filter = new CategoryFilter();
56 connect(filter, SIGNAL(countChanged()), this, SLOT(onCountChanged()));
57 filter->setModel(m_resultModel);
58 filter->setIndex(index);
60 m_filters.insert(index, filter);
63 return m_filters[index];
67Categories::setResultModel(DeeListModel* model)
69 if (model != m_resultModel) {
70 m_resultModel = model;
72 Q_FOREACH(CategoryFilter* filter, m_filters) {
73 filter->setModel(m_resultModel);
76 Q_EMIT resultModelChanged(m_resultModel);
81Categories::onCountChanged()
83 CategoryFilter* filter = qobject_cast<CategoryFilter*>(sender());
85 m_timerFilters << filter;
91Categories::onEmitCountChanged()
94 roles.append(Categories::RoleCount);
95 Q_FOREACH(CategoryFilter* filter, m_timerFilters) {
96 QModelIndex changedIndex = index(filter->index());
97 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
99 m_timerFilters.clear();
102QHash<int, QByteArray>
103Categories::roleNames() const
109Categories::data(const QModelIndex& index, int role) const
111 if (!index.isValid()) {
117 return QVariant::fromValue(index.row());
119 return QVariant::fromValue(DeeListModel::data(index, 1)); //DISPLAY_NAME
121 return QVariant::fromValue(DeeListModel::data(index, 2)); //ICON_HINT
123 return QVariant::fromValue(DeeListModel::data(index, 3)); //RENDERER_NAME
124 case RoleContentType:
126 auto hints = QVariant::fromValue(DeeListModel::data(index, 4)).toHash();
127 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
130 return QVariant::fromValue(DeeListModel::data(index, 4)); //HINTS
132 return QVariant::fromValue(getFilter(index.row()));
135 CategoryFilter* filter = getFilter(index.row());
136 return QVariant::fromValue(filter->rowCount());
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