summaryrefslogtreecommitdiffstats
path: root/src/controls/qtmenuitem.cpp
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-03-12 17:15:02 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-13 15:33:53 +0100
commit8cc52b9d1e2638f0636f2817dffeccd623063718 (patch)
tree0498fe65c48bbd4383b68315cecc4ec4efe6cb47 /src/controls/qtmenuitem.cpp
parent15c57038d9ac4720f4bc4b476d978a3824ed71ab (diff)
Menu: Remove 'model' property, ContextMenu
In the near future, we hope that QML types like Creator/Instantiator (currently under review) will help simplify model binding, and object creation and deletion. Also, given the differences between QML models and QAbstractItemModel APIs, it's hard to provide a unified and elegant solution for this right now. ComboBox gets the part of the logic that ContextMenu was responsible for, extended to support string list and number models. Auto-tests updated and XFAIL removed where applicable. Change-Id: I9f5d4059644c495bffff76fb7c353e6fe7fde62e Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'src/controls/qtmenuitem.cpp')
-rw-r--r--src/controls/qtmenuitem.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/controls/qtmenuitem.cpp b/src/controls/qtmenuitem.cpp
index 839a3b2d6..2e01cb6ab 100644
--- a/src/controls/qtmenuitem.cpp
+++ b/src/controls/qtmenuitem.cpp
@@ -42,6 +42,7 @@
#include "qtmenuitem_p.h"
#include "qtaction_p.h"
#include "qtmenu_p.h"
+#include "qtmenuitemcontainer_p.h"
#include <private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformtheme.h>
@@ -51,15 +52,18 @@
QT_BEGIN_NAMESPACE
QtMenuBase::QtMenuBase(QObject *parent)
- : QObject(parent), m_visible(true),
- m_parentMenu(0), m_visualItem(0)
+ : QObject(parent), m_visible(true), m_parentMenu(0), m_container(0), m_visualItem(0)
{
m_platformItem = QGuiApplicationPrivate::platformTheme()->createPlatformMenuItem();
}
QtMenuBase::~QtMenuBase()
{
- delete m_platformItem;
+ setParentMenu(0);
+ if (m_platformItem) {
+ delete m_platformItem;
+ m_platformItem = 0;
+ }
}
void QtMenuBase::setVisible(bool v)
@@ -83,14 +87,27 @@ QtMenu *QtMenuBase::parentMenu() const
void QtMenuBase::setParentMenu(QtMenu *parentMenu)
{
+ if (m_parentMenu && m_parentMenu->platformMenu())
+ m_parentMenu->platformMenu()->removeMenuItem(m_platformItem);
+
m_parentMenu = parentMenu;
}
+QtMenuItemContainer *QtMenuBase::container() const
+{
+ return m_container;
+}
+
+void QtMenuBase::setContainer(QtMenuItemContainer *c)
+{
+ m_container = c;
+}
+
void QtMenuBase::syncWithPlatformMenu()
{
- QtMenu *menu = qobject_cast<QtMenu *>(parent());
+ QtMenu *menu = parentMenu();
if (menu && menu->platformMenu() && platformItem()
- && menu->m_menuItems.contains(this)) // If not, it'll be added later and then sync'ed
+ && menu->contains(this)) // If not, it'll be added later and then sync'ed
menu->platformMenu()->syncMenuItem(platformItem());
}
@@ -379,7 +396,8 @@ QtMenuItem::~QtMenuItem()
void QtMenuItem::setParentMenu(QtMenu *parentMenu)
{
QtMenuText::setParentMenu(parentMenu);
- connect(this, SIGNAL(triggered()), parentMenu, SLOT(updateSelectedIndex()));
+ if (parentMenu)
+ connect(this, SIGNAL(triggered()), parentMenu, SLOT(updateSelectedIndex()));
}
void QtMenuItem::bindToAction(QtAction *action)
@@ -541,6 +559,7 @@ void QtMenuItem::updateChecked()
platformItem()->setChecked(checked);
syncWithPlatformMenu();
}
+
emit toggled(checked);
}