2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
16 * Authors: Nick Dedekind <nick.dedekind@canonical.com>
19#include "unitymenumodel.h"
22 LabelRole = Qt::DisplayRole + 1,
27 ExtendedAttributesRole,
35UnityMenuModel::UnityMenuModel(QObject *parent)
36: QAbstractListModel(parent)
40UnityMenuModel::~UnityMenuModel()
44QVariant UnityMenuModel::modelData() const
49void UnityMenuModel::setModelData(const QVariant& data)
53 m_modelData = data.toList();
54 Q_EMIT modelDataChanged();
59void UnityMenuModel::insertRow(int row, const QVariant& data)
61 row = qMin(row, rowCount());
63 beginInsertRows(QModelIndex(), row, row);
65 m_modelData.insert(row, data);
70void UnityMenuModel::appendRow(const QVariant& data)
72 insertRow(rowCount(), data);
75void UnityMenuModel::removeRow(int row)
77 if (row < 0 || rowCount() <= row) {
81 beginRemoveRows(QModelIndex(), row, row);
83 m_modelData.removeAt(row);
88QByteArray UnityMenuModel::busName() const
93void UnityMenuModel::setBusName(const QByteArray &busName)
95 this->m_busName = busName;
98QVariantMap UnityMenuModel::actions() const
103void UnityMenuModel::setActions(const QVariantMap &actions)
105 this->m_actions = actions;
108QByteArray UnityMenuModel::menuObjectPath() const
110 return m_menuObjectPath;
113void UnityMenuModel::setMenuObjectPath(const QByteArray &path)
115 this->m_menuObjectPath = path;
118ActionStateParser* UnityMenuModel::actionStateParser() const
123void UnityMenuModel::setActionStateParser(ActionStateParser*)
127QString UnityMenuModel::nameOwner() const
132int UnityMenuModel::rowCount(const QModelIndex&) const
134 return m_modelData.count();
137int UnityMenuModel::columnCount(const QModelIndex&) const
142QVariant UnityMenuModel::data(const QModelIndex &index, int role) const
144 return rowData(index.row())[roleNames()[role]];
147QVariantMap UnityMenuModel::rowData(int row) const
149 if (m_modelData.count() <= row) {
150 return QVariantMap();
152 return m_modelData[row].toMap()["rowData"].toMap();
155QVariant UnityMenuModel::subMenuData(int row) const
157 return m_modelData[row].toMap()["submenu"];
160QModelIndex UnityMenuModel::index(int row, int column, const QModelIndex&) const
162 return createIndex(row, column);
165QModelIndex UnityMenuModel::parent(const QModelIndex &) const
167 return QModelIndex();
170QHash<int, QByteArray> UnityMenuModel::roleNames() const
172 QHash<int, QByteArray> names;
174 names[LabelRole] = "label";
175 names[SensitiveRole] = "sensitive";
176 names[IsSeparatorRole] = "isSeparator";
177 names[IconRole] = "icon";
178 names[TypeRole] = "type";
179 names[ExtendedAttributesRole] = "ext";
180 names[ActionRole] = "action";
181 names[ActionStateRole] = "actionState";
182 names[IsCheckRole] = "isCheck";
183 names[IsRadioRole] = "isRadio";
184 names[IsToggledRole] = "isToggled";
189QObject * UnityMenuModel::submenu(int position, QQmlComponent*)
191 if (position < 0 || m_modelData.count() < position) {
195 while (submenus.count() <= position) {
196 submenus.append(nullptr);
199 QVariant submenuData = subMenuData(position);
200 if (submenuData.type() == (int)QMetaType::QVariantList) {
201 UnityMenuModel*& model = submenus[position];
203 model = new UnityMenuModel(this);
205 if (model->modelData() != submenuData) {
206 model->setModelData(submenuData);
214bool UnityMenuModel::loadExtendedAttributes(int, const QVariantMap &)
219QVariant UnityMenuModel::get(int row, const QByteArray &role)
221 static QHash<QByteArray, int> roles;
222 if (roles.isEmpty()) {
223 QHash<int, QByteArray> names = roleNames();
224 Q_FOREACH (int role, names.keys())
225 roles.insert(names[role], role);
228 return this->data(this->index(row, 0), roles[role]);
231void UnityMenuModel::activate(int, const QVariant&)
235void UnityMenuModel::changeState(int, const QVariant&)
239void UnityMenuModel::registerAction(UnityMenuAction*)
243void UnityMenuModel::unregisterAction(UnityMenuAction*)
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