1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2025-04-21 12:27:27 +03:00

Fix dynamic allocation of IconButton instances

Previously, IconButton instances to be added to button boxes were
allocated with new, but never freed with delete.

unique_ptr makes sure the buttons will be freed along with the button
box that owns them, or when code calls ButtonBox::clear.

The destructor of ButtonBox has been made redundant by this change, so
it's gone.
This commit is contained in:
Nebuleon Fumika
2014-08-15 21:52:48 +00:00
committed by Maarten ter Huurne
parent 004c41e2ef
commit 891525aa94
12 changed files with 118 additions and 102 deletions

View File

@@ -26,6 +26,8 @@
#include "iconbutton.h"
using std::string;
using std::unique_ptr;
using std::move;
MenuSettingFile::MenuSettingFile(
GMenu2X *gmenu2x, Touchscreen &ts_,
@@ -35,15 +37,15 @@ MenuSettingFile::MenuSettingFile(
, ts(ts_)
, filter(filter_)
{
IconButton *btn;
unique_ptr<IconButton> btnClear(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Clear"]));
btnClear->setAction(BIND(&MenuSettingFile::clear));
buttonBox.add(move(btnClear));
btn = new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Clear"]);
btn->setAction(BIND(&MenuSettingFile::clear));
buttonBox.add(btn);
btn = new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select"]);
btn->setAction(BIND(&MenuSettingFile::edit));
buttonBox.add(btn);
unique_ptr<IconButton> btnSelect(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select"]));
btnSelect->setAction(BIND(&MenuSettingFile::edit));
buttonBox.add(move(btnSelect));
}
void MenuSettingFile::edit()