Skip to content

Commit

Permalink
Refactor|MenuWidget|Client: Handling deletion of sub-widgets
Browse files Browse the repository at this point in the history
When a widget is being deleted, only the de::Widget instance
remains; a dynamic cast to a subclass will fail.
  • Loading branch information
skyjake committed Dec 18, 2013
1 parent 5381ab8 commit 184d442
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions doomsday/client/src/ui/widgets/menuwidget.cpp
Expand Up @@ -154,7 +154,7 @@ DENG2_PIMPL(MenuWidget)
ListData defaultItems;
Data const *items;
ChildWidgetOrganizer organizer;
QSet<PopupWidget *> openSubs;
QSet<PanelWidget *> openSubs;

SizePolicy colPolicy;
SizePolicy rowPolicy;
Expand Down Expand Up @@ -296,16 +296,18 @@ DENG2_PIMPL(MenuWidget)

void panelBeingClosed(PanelWidget &popup)
{
openSubs.remove(&popup.as<PopupWidget>());
openSubs.remove(&popup);
}

void widgetBeingDeleted(Widget &widget)
{
openSubs.remove(&widget.as<PopupWidget>());
openSubs.remove(static_cast<PanelWidget *>(&widget));
}

void keepTrackOfSubWidget(PopupWidget *w)
void keepTrackOfSubWidget(PanelWidget *w)
{
DENG2_ASSERT(w->is<PanelWidget>());

openSubs.insert(w);

w->audienceForClose += this;
Expand Down Expand Up @@ -452,7 +454,7 @@ bool MenuWidget::handleEvent(Event const &event)

void MenuWidget::dismissPopups()
{
foreach(PopupWidget *pop, d->openSubs)
foreach(PanelWidget *pop, d->openSubs)
{
pop->close();
}
Expand Down

0 comments on commit 184d442

Please sign in to comment.