@@ -30,6 +30,12 @@ WorkspaceModel::WorkspaceModel(QObject *parent)
33+WorkspaceModel::~WorkspaceModel()
35+ qDeleteAll(m_workspaces.toList()); // make a copy so the list doesnt edit itself during delete.
36+ m_workspaces.clear();
33void WorkspaceModel::append(Workspace *workspace)
39void WorkspaceModel::append(Workspace *workspace)
35 insert(m_workspaces.count(), workspace);
41 insert(m_workspaces.count(), workspace);
@@ -55,18 +61,10 @@ void WorkspaceModel::remove(Workspace *workspace)
55 beginRemoveRows(QModelIndex(), index, index);
61 beginRemoveRows(QModelIndex(), index, index);
57 m_workspaces.removeAt(index);
63 m_workspaces.removeAt(index);
64+ insertUnassigned(workspace);
59 endRemoveRows();
66 endRemoveRows();
61− m_unassignedWorkspaces.insert(workspace);
62− connect(workspace, &Workspace::assigned, this, [=]() {
63− m_unassignedWorkspaces.remove(workspace);
64− disconnect(workspace, &Workspace::assigned, this, 0);
66− connect(workspace, &QObject::destroyed, this, [=]() {
67− m_unassignedWorkspaces.remove(workspace);
70 Q_EMIT workspaceRemoved(workspace);
68 Q_EMIT workspaceRemoved(workspace);
71 Q_EMIT countChanged();
69 Q_EMIT countChanged();
@@ -195,6 +193,19 @@ void WorkspaceModel::finishSync()
195 m_unassignedWorkspaces.clear();
193 m_unassignedWorkspaces.clear();
196+void WorkspaceModel::insertUnassigned(Workspace *workspace)
198+ m_unassignedWorkspaces.insert(workspace);
199+ connect(workspace, &Workspace::assigned, this, [=]() {
200+ m_unassignedWorkspaces.remove(workspace);
201+ disconnect(workspace, &Workspace::assigned, this, 0);
203+ connect(workspace, &QObject::destroyed, this, [=]() {
204+ m_unassignedWorkspaces.remove(workspace);
198ProxyWorkspaceModel::ProxyWorkspaceModel(WorkspaceModel * const model)
209ProxyWorkspaceModel::ProxyWorkspaceModel(WorkspaceModel * const model)
199 : m_original(model)
210 : m_original(model)
@@ -227,12 +238,6 @@ ProxyWorkspaceModel::ProxyWorkspaceModel(WorkspaceModel * const model)
230−ProxyWorkspaceModel::~ProxyWorkspaceModel()
232− qDeleteAll(m_workspaces.toList()); // make a copy so the list doesnt edit itself during delete.
233− m_workspaces.clear();
236void ProxyWorkspaceModel::move(int from, int to)
241void ProxyWorkspaceModel::move(int from, int to)
238 WorkspaceModel::move(from, to);
243 WorkspaceModel::move(from, to);
@@ -241,7 +246,7 @@ void ProxyWorkspaceModel::move(int from, int to)
241void ProxyWorkspaceModel::addWorkspace()
246void ProxyWorkspaceModel::addWorkspace()
243 auto newWorkspace = WorkspaceManager::instance()->createWorkspace();
248 auto newWorkspace = WorkspaceManager::instance()->createWorkspace();
244− m_original->m_unassignedWorkspaces.insert(newWorkspace);
249+ m_original->insertUnassigned(newWorkspace);
246 (new ProxyWorkspace(newWorkspace))->assign(this);
251 (new ProxyWorkspace(newWorkspace))->assign(this);