2 * Copyright (C) 2014 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/>.
17#include "fake_department.h"
19#include "fake_scope.h"
23Department::Department(const QString& departmentId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope)
24 : m_departmentId(departmentId)
26 , m_allLabel(allLabel)
27 , m_parentId(parentId)
28 , m_parentLabel(parentLabel)
32 QTimer::singleShot(1500, this, SLOT(slotLoaded()));
33 connect(scope, SIGNAL(currentDepartmentIdChanged()), this, SLOT(slotCurrentDepartmentChanged()));
36QString Department::departmentId() const
38 return m_departmentId;
41QString Department::label() const
46QString Department::allLabel() const
51QString Department::parentDepartmentId() const
56QString Department::parentLabel() const
61void Department::slotLoaded()
64 Q_EMIT loadedChanged();
67bool Department::loaded() const
72int Department::count() const
77bool Department::isRoot() const
79 return m_departmentId == "root";
82int Department::rowCount(const QModelIndex & /*parent*/) const
84 if (!m_loaded || m_departmentId.startsWith("child") || m_departmentId == "middle3")
90QHash<int, QByteArray> Department::roleNames() const
92 QHash<int, QByteArray> res;
93 res[RoleDepartmentId] = "departmentId";
94 res[RoleLabel] = "label";
95 res[RoleHasChildren] = "hasChildren";
96 res[RoleIsActive] = "isActive";
100QVariant Department::data(const QModelIndex &index, int role) const
103 case RoleDepartmentId:
104 if (m_departmentId == "root")
105 return QString("middle%1").arg(index.row());
106 else if (m_departmentId.startsWith("middle"))
107 return QString("child%1%2").arg(m_departmentId).arg(index.row());
110 return QString("%1Child%2").arg(m_departmentId).arg(index.row());
112 case RoleHasChildren:
113 return m_departmentId == "root" && index.row() != 3;
116 return m_scope->currentDepartmentId() == data(index, RoleDepartmentId);
122void Department::slotCurrentDepartmentChanged()
124 // This is wasteful, should only emit it if really something changed in this
125 // deparment, but this is a mock, so no need to optimize
126 Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), QVector<int>() << RoleIsActive);
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