2 * Copyright (C) 2013 Canonical, Ltd.
5 * Pawel Stolowski <pawel.stolowski@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 "genericoptionsmodel.h"
24#include "abstractfilteroption.h"
26GenericOptionsModel::GenericOptionsModel(QObject *parent)
27 : QAbstractListModel(parent)
31GenericOptionsModel::~GenericOptionsModel()
33 Q_FOREACH(auto opt, m_options)
39QHash<int, QByteArray> GenericOptionsModel::roleNames() const
41 QHash<int, QByteArray> roles;
42 roles[GenericOptionsModel::RoleId] = "id";
43 roles[GenericOptionsModel::RoleName] = "name";
44 roles[GenericOptionsModel::RoleIconHint] = "iconHint";
45 roles[GenericOptionsModel::RoleActive] = "active";
49QVariant GenericOptionsModel::data(const QModelIndex& index, int role) const
51 if (!index.isValid()) {
55 auto filterOption = m_options[index.row()];
58 case GenericOptionsModel::RoleId:
59 return filterOption->id();
60 case GenericOptionsModel::RoleName:
62 return filterOption->name();
63 case GenericOptionsModel::RoleIconHint:
64 return filterOption->iconHint();
65 case GenericOptionsModel::RoleActive:
66 return filterOption->active();
74int GenericOptionsModel::rowCount(const QModelIndex& /* parent */) const
76 return m_options.size ();
79void GenericOptionsModel::setActive(QVector<AbstractFilterOption *>::size_type idx, bool value)
81 if (idx < m_options.size())
83 m_options[idx]->setActive(value);
87AbstractFilterOption* GenericOptionsModel::getRawOption(QVector<AbstractFilterOption *>::size_type idx) const
89 if (idx < m_options.size())
91 return m_options[idx];
96void GenericOptionsModel::ensureTheOnlyActive(AbstractFilterOption *activeOption)
98 if (activeOption->active()) {
99 // disable all other options
100 Q_FOREACH(auto opt, m_options) {
101 if (opt != activeOption && opt->active()) {
102 opt->setActive(false);
108void GenericOptionsModel::addOption(AbstractFilterOption *option, int index)
110 m_options.insert(index, option);
112 connect(option, SIGNAL(idChanged(const QString &)), this, SLOT(onOptionChanged()));
113 connect(option, SIGNAL(nameChanged(const QString &)), this, SLOT(onOptionChanged()));
114 connect(option, SIGNAL(iconHintChanged(const QString &)), this, SLOT(onOptionChanged()));
115 connect(option, SIGNAL(activeChanged(bool)), this, SLOT(onOptionChanged()));
116 connect(option, SIGNAL(activeChanged(bool)), this, SLOT(onActiveChanged()));
119void GenericOptionsModel::removeOption(int index)
121 m_options[index]->deleteLater();
122 m_options.remove(index);
125int GenericOptionsModel::indexOf(const QString &option_id)
128 Q_FOREACH(auto opt, m_options)
130 if (opt->id() == option_id)
139void GenericOptionsModel::onOptionChanged()
141 AbstractFilterOption *option = dynamic_cast<AbstractFilterOption*>(QObject::sender());
144 int idx = indexOf(option->id());
147 QModelIndex optionIndex = index(idx);
148 Q_EMIT dataChanged(optionIndex, optionIndex);
153void GenericOptionsModel::onActiveChanged()
155 AbstractFilterOption *option = dynamic_cast<AbstractFilterOption*>(QObject::sender());
158 Q_EMIT activeChanged(option);
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