2 * Copyright (C) 2017 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 "WorkspaceModel.h"
20Q_LOGGING_CATEGORY(WORKSPACES, "Workspaces", QtInfoMsg)
22#define DEBUG_MSG qCDebug(WORKSPACES).nospace().noquote() << __func__
23#define INFO_MSG qCInfo(WORKSPACES).nospace().noquote() << __func__
25WorkspaceModel::WorkspaceModel(QObject *parent)
26 : QAbstractListModel(parent)
30void WorkspaceModel::append(Workspace *workspace)
32 insert(m_workspaces.count(), workspace);
35void WorkspaceModel::insert(int index, Workspace *workspace)
37 beginInsertRows(QModelIndex(), index, index);
38 m_workspaces.append(workspace);
40 Q_EMIT countChanged();
43void WorkspaceModel::remove(Workspace *workspace)
45 int index = m_workspaces.indexOf(workspace);
46 if (index < 0) return;
48 beginRemoveRows(QModelIndex(), index, index);
49 m_workspaces.removeAt(index);
51 Q_EMIT countChanged();
54void WorkspaceModel::move(int from, int to)
56 if (from == to) return;
57 DEBUG_MSG << " from=" << from << " to=" << to;
59 if (from >= 0 && from < m_workspaces.size() && to >= 0 && to < m_workspaces.size()) {
62 beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
63#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
64 const auto &window = m_windowModel.takeAt(from);
65 m_workspaces.insert(to, window);
67 m_workspaces.move(from, to);
70 Q_EMIT countChanged();
74int WorkspaceModel::rowCount(const QModelIndex &) const
76 return m_workspaces.count();
79QVariant WorkspaceModel::data(const QModelIndex &index, int role) const
81 if (index.row() < 0 || index.row() >= m_workspaces.size())
84 if (role == WorkspaceRole) {
85 Workspace *workspace = m_workspaces.at(index.row());
86 return QVariant::fromValue(workspace);
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