on 17872af help sign in
63 lines 1.5 kB history raw
1/*
2 * Copyright (C) 2017 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#include "Workspace.h"
18#include "WorkspaceModel.h"
20Workspace::Workspace(QObject *parent)
21 : QObject(parent)
22 , m_model(nullptr)
27Workspace::~Workspace()
29 unassign();
32void Workspace::assign(WorkspaceModel *model)
34 bool wasAssinged = false;
35 if (m_model) {
36 disconnect(model);
37 m_model->remove(this);
38 wasAssinged = true;
39 }
41 m_model = model;
42 if (model) {
43 model->append(this);
45 connect(model, &QObject::destroyed, this, [this]() {
46 m_model = nullptr;
47 Q_EMIT unassigned();
48 });
49 Q_EMIT assigned();
50 } else if (wasAssinged) {
51 Q_EMIT unassigned();
52 }
55void Workspace::unassign()
57 if (m_model) {
58 m_model->remove(this);
59 m_model = nullptr;
61 Q_EMIT unassigned();
62 }