@@ -30,6 +30,12 @@ WorkspaceModel::WorkspaceModel(QObject *parent)
3030{
3131}
3232
33+WorkspaceModel::~WorkspaceModel()
34+{
35+ qDeleteAll(m_workspaces.toList()); // make a copy so the list doesnt edit itself during delete.
36+ m_workspaces.clear();
37+}
38+
3339void WorkspaceModel::append(Workspace *workspace)
3440{
3541 insert(m_workspaces.count(), workspace);
@@ -55,18 +61,10 @@ void WorkspaceModel::remove(Workspace *workspace)
5561 beginRemoveRows(QModelIndex(), index, index);
5662
5763 m_workspaces.removeAt(index);
64+ insertUnassigned(workspace);
5865
5966 endRemoveRows();
6067
61− m_unassignedWorkspaces.insert(workspace);
62− connect(workspace, &Workspace::assigned, this, [=]() {
63− m_unassignedWorkspaces.remove(workspace);
64− disconnect(workspace, &Workspace::assigned, this, 0);
65− });
66− connect(workspace, &QObject::destroyed, this, [=]() {
67− m_unassignedWorkspaces.remove(workspace);
68− });
69−
7068 Q_EMIT workspaceRemoved(workspace);
7169 Q_EMIT countChanged();
7270}
@@ -195,6 +193,19 @@ void WorkspaceModel::finishSync()
195193 m_unassignedWorkspaces.clear();
196194}
197195
196+void WorkspaceModel::insertUnassigned(Workspace *workspace)
197+{
198+ m_unassignedWorkspaces.insert(workspace);
199+ connect(workspace, &Workspace::assigned, this, [=]() {
200+ m_unassignedWorkspaces.remove(workspace);
201+ disconnect(workspace, &Workspace::assigned, this, 0);
202+ });
203+ connect(workspace, &QObject::destroyed, this, [=]() {
204+ m_unassignedWorkspaces.remove(workspace);
205+ });
206+}
207+
208+
198209ProxyWorkspaceModel::ProxyWorkspaceModel(WorkspaceModel * const model)
199210 : m_original(model)
200211{
@@ -227,12 +238,6 @@ ProxyWorkspaceModel::ProxyWorkspaceModel(WorkspaceModel * const model)
227238 });
228239}
229240
230−ProxyWorkspaceModel::~ProxyWorkspaceModel()
231−{
232− qDeleteAll(m_workspaces.toList()); // make a copy so the list doesnt edit itself during delete.
233− m_workspaces.clear();
234−}
235−
236241void ProxyWorkspaceModel::move(int from, int to)
237242{
238243 WorkspaceModel::move(from, to);
@@ -241,7 +246,7 @@ void ProxyWorkspaceModel::move(int from, int to)
241246void ProxyWorkspaceModel::addWorkspace()
242247{
243248 auto newWorkspace = WorkspaceManager::instance()->createWorkspace();
244− m_original->m_unassignedWorkspaces.insert(newWorkspace);
249+ m_original->insertUnassigned(newWorkspace);
245250
246251 (new ProxyWorkspace(newWorkspace))->assign(this);
247252}