update the menu at childAdded/removed

This commit is contained in:
Marco Martin 2011-12-30 17:48:14 +01:00
parent edf08a8cdb
commit e121edf7d8

View File

@ -83,7 +83,7 @@ void QMenuProxy::setVisualParent(QObject *parent)
action->setMenu(m_menu); action->setMenu(m_menu);
m_menu->clear(); m_menu->clear();
foreach(QMenuItem* item, m_items) { foreach(QMenuItem* item, m_items) {
m_menu->addAction (item); m_menu->addAction(item);
} }
m_menu->updateGeometry(); m_menu->updateGeometry();
} }
@ -100,6 +100,7 @@ bool QMenuProxy::event(QEvent *event)
QMenuItem *mi = qobject_cast<QMenuItem *>(ce->child()); QMenuItem *mi = qobject_cast<QMenuItem *>(ce->child());
//FIXME: linear complexity here //FIXME: linear complexity here
if (mi && !m_items.contains(mi)) { if (mi && !m_items.contains(mi)) {
m_menu->addAction(mi);
m_items << mi; m_items << mi;
} }
break; break;
@ -111,6 +112,7 @@ bool QMenuProxy::event(QEvent *event)
//FIXME: linear complexity here //FIXME: linear complexity here
if (mi) { if (mi) {
m_menu->removeAction(mi);
m_items.removeAll(mi); m_items.removeAll(mi);
} }
break; break;
@ -133,11 +135,13 @@ void QMenuProxy::addMenuItem(const QString &text)
{ {
QMenuItem *item = new QMenuItem(this); QMenuItem *item = new QMenuItem(this);
item->setText(text); item->setText(text);
m_menu->addAction(item);
m_items << item; m_items << item;
} }
void QMenuProxy::addMenuItem(QMenuItem *item) void QMenuProxy::addMenuItem(QMenuItem *item)
{ {
m_menu->addAction(item);
m_items << item; m_items << item;
} }