on 86331ae help sign in
unity8/plugins/Unity/Indicators/visibleindicatorsmodel.cpp
92 lines 3.0 kB history raw
1/*
2 * Copyright (C) 2012, 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17// self
18#include "visibleindicatorsmodel.h"
19#include "indicators.h"
21VisibleIndicatorsModel::VisibleIndicatorsModel(QObject *parent)
22 : QIdentityProxyModel(parent),
23 m_inserting(false)
25 QObject::connect(this, SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(onBeginRowInserted(QModelIndex, int, int)));
26 QObject::connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(onRowInserted(QModelIndex, int, int)));
29QHash<int, QByteArray> VisibleIndicatorsModel::roleNames() const
31 static QHash<int, QByteArray> roles;
32 if (roles.isEmpty())
33 {
34 roles[IndicatorsModelRole::Identifier] = "identifier";
35 roles[IndicatorsModelRole::Position] = "position";
36 roles[IndicatorsModelRole::WidgetSource] = "widgetSource";
37 roles[IndicatorsModelRole::PageSource] = "pageSource";
38 roles[IndicatorsModelRole::IndicatorProperties] = "indicatorProperties";
39 roles[IndicatorsModelRole::IsVisible] = "isVisible";
40 }
41 return roles;
44void VisibleIndicatorsModel::setSourceModel(QAbstractItemModel *model)
46 if (sourceModel() != model) {
47 QIdentityProxyModel::setSourceModel(model);
48 Q_EMIT modelChanged();
49 }
52QVariantMap VisibleIndicatorsModel::visible() const
54 return m_visible;
57void VisibleIndicatorsModel::onBeginRowInserted(const QModelIndex&, int, int)
59 m_inserting = true;
62void VisibleIndicatorsModel::onRowInserted(const QModelIndex&, int, int)
64 m_inserting = false;
67void VisibleIndicatorsModel::setVisible(const QVariantMap& visible)
69 if (m_visible != visible) {
70 m_visible = visible;
71 Q_EMIT visibleChanged();
73 // need to tell the view that the visible data has changed.
74 if (!m_inserting && rowCount() > 0) {
75 Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), QVector<int>() << IndicatorsModelRole::IsVisible);
76 }
77 }
80QVariant VisibleIndicatorsModel::data(const QModelIndex &index, int role) const
82 if (role != IndicatorsModelRole::IsVisible) {
83 return QIdentityProxyModel::data(index, role);
84 }
86 if (!index.isValid()) {
87 return false;
88 }
90 QString ident = QIdentityProxyModel::data(index, IndicatorsModelRole::Identifier).toString();
91 return m_visible.value(ident, false).toBool();