Commit 6a18c8df authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

delete workspace when needed

parent 099af312
......@@ -195,16 +195,17 @@ signals:
void indexDeleted(int);
public:
void createWorkspace(const QColor &, const QString &, bool display_destroy);
void createWorkspace(const QColor &, const QString &, dtkWidgetsWorkspace *workspace, bool display_destroy);
public:
QList<QColor> colors;
QList<QMenu *> submenus;
QStringList workspaces;
QStringList workspaces; // list of all available workspaces by name (not instanciated)
QMap<dtkWidgetsWorkspaceBarItem*, dtkWidgetsWorkspace *> workspace_map; // map of created workspaces
dtkWidgetsWorkspace *current_workspace = nullptr;
};
void dtkWidgetsWorkspaceBarPrivate::createWorkspace(const QColor & color, const QString& name, bool display_destroy)
void dtkWidgetsWorkspaceBarPrivate::createWorkspace(const QColor & color, const QString& name, dtkWidgetsWorkspace *workspace, bool display_destroy)
{
dtkWidgetsWorkspaceBarItem *item = new dtkWidgetsWorkspaceBarItem(color, name, q, display_destroy);
......@@ -216,6 +217,7 @@ void dtkWidgetsWorkspaceBarPrivate::createWorkspace(const QColor & color, const
this->layout->insertWidget(this->layout->count()-1, item);
this->items << item;
this->workspace_map.insert(item, workspace);
connect(item, &dtkWidgetsWorkspaceBarItem::clicked, [=] () {
int index = this->items.indexOf(item);
......@@ -233,6 +235,8 @@ void dtkWidgetsWorkspaceBarPrivate::createWorkspace(const QColor & color, const
delete separator;
}
this->layout->removeWidget(item);
dtkWidgetsWorkspace *w = this->workspace_map.take(item);
delete w;
delete item;
emit indexDeleted(index);
});
......@@ -366,7 +370,7 @@ void dtkWidgetsWorkspaceBar::createWorkspace(const QString &name, const QString&
int index = d->workspaces.indexOf(name) % d->colors.count();
QColor color = d->colors.at(index) ;
d->createWorkspace(color, name, display_destroy);
d->createWorkspace(color, name, workspace, display_destroy);
d->stack->addWidget(workspace);
d->stack->setCurrentWidget(workspace);
......@@ -381,6 +385,7 @@ dtkWidgetsWorkspaceBar::~dtkWidgetsWorkspaceBar(void)
d->colors.clear();
d->submenus.clear();
d->workspaces.clear();
d->workspace_map.clear();
delete d;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment