Commit cf80db1d authored by SZPYRKA Jean-Luc's avatar SZPYRKA Jean-Luc

adding insertMenu() and insertItem() on menus

parent 99f77727
......@@ -76,6 +76,32 @@ dtkWidgetsMenu *dtkWidgetsMenu::addMenu(int icon_id, const QString& title)
return m;
}
dtkWidgetsMenu *dtkWidgetsMenu::insertMenu(int pos, dtkWidgetsMenu *menu)
{
if (pos < 0 || pos > d->menu_list.size() || !menu ) {
return nullptr;
}
menu->setParent(this);
d->menu_list.insert(pos, menu);
d->object_list.insert(pos, menu);
return menu;
}
dtkWidgetsMenu *dtkWidgetsMenu::insertMenu(int pos, int icon_id, const QString &title)
{
dtkWidgetsMenu *menu = new dtkWidgetsMenu(icon_id, title);
auto m = this->insertMenu(pos, menu);
if (m != menu)
delete menu;
return m;
}
void dtkWidgetsMenu::clear(void)
{
d->object_hash.clear();
......@@ -107,6 +133,30 @@ dtkWidgetsMenuItem *dtkWidgetsMenu::addItem(int icon_id, const QString& title)
return it;
}
dtkWidgetsMenuItem *dtkWidgetsMenu::insertItem(int pos, dtkWidgetsMenuItem *item)
{
if (item && !d->object_hash.contains(item->title())) {
d->object_hash.insert(item->title(), item);
d->object_list.insert(pos, item);
return item;
}
return nullptr;
}
dtkWidgetsMenuItem *dtkWidgetsMenu::insertItem(int pos, int icon_id, const QString& title)
{
dtkWidgetsMenuItem *item = new dtkWidgetsMenuItem(icon_id, title);
auto it = this->insertItem(pos, item);
if (it != item) {
delete item;
}
return it;
}
dtkWidgetsMenuItem *dtkWidgetsMenu::addSeparator(void)
{
static int count = 0;
......
......@@ -54,6 +54,12 @@ public:
dtkWidgetsMenuItem *addItem(dtkWidgetsMenuItem *item);
dtkWidgetsMenuItem *addItem(int, const QString& title);
dtkWidgetsMenu *insertMenu(int, dtkWidgetsMenu *menu);
dtkWidgetsMenu *insertMenu(int, int, const QString& title);
dtkWidgetsMenuItem *insertItem(int, dtkWidgetsMenuItem *item);
dtkWidgetsMenuItem *insertItem(int, int, const QString& title);
dtkWidgetsMenuItem *addSeparator(void);
dtkWidgetsMenuItem *addParameter(dtkWidgetsMenuItem *item);
......
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