summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@nokia.com>2012-01-24 07:34:09 +0100
committerJens Bache-Wiig <jens.bache-wiig@nokia.com>2012-01-24 07:38:02 +0100
commit4d5e5cd2bd853ca9e9751abd184dade43dacc5f2 (patch)
treeac082ff633455ec1fb60505390c82bb9a3d4f6b6
parent73a0a7c2eaadd65bf0933f7bf63d62d4c17f3231 (diff)
downloadqtquickcontrols-4d5e5cd2bd853ca9e9751abd184dade43dacc5f2.tar.gz
Ensure we disconnect old menu model to prevent redundant updates
-rw-r--r--src/qtmenu.cpp19
-rw-r--r--src/qtmenu.h17
2 files changed, 20 insertions, 16 deletions
diff --git a/src/qtmenu.cpp b/src/qtmenu.cpp
index 689cc022..98ac4deb 100644
--- a/src/qtmenu.cpp
+++ b/src/qtmenu.cpp
@@ -188,7 +188,6 @@ int QtMenu::modelCount() const
return -1;
}
-
void QtMenu::append_qmenuItem(QDeclarativeListProperty<QtMenuBase> *list, QtMenuBase *menuItem)
{
QtMenu *menu = qobject_cast<QtMenu *>(list->object);
@@ -199,4 +198,22 @@ void QtMenu::append_qmenuItem(QDeclarativeListProperty<QtMenuBase> *list, QtMenu
}
}
+void QtMenu::setModel(const QVariant &newModel) {
+ if (m_model != newModel) {
+
+ // Clean up any existing connections
+ if (QAbstractItemModel *oldModel = qobject_cast<QAbstractItemModel*>(m_model.value<QObject*>())) {
+ disconnect(oldModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SIGNAL(rebuildMenu()));
+ }
+ m_hasNativeModel = false;
+ m_model = newModel;
+ if (QAbstractItemModel *model = qobject_cast<QAbstractItemModel*>(newModel.value<QObject*>())) {
+ m_hasNativeModel = true;
+ connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SIGNAL(rebuildMenu()));
+ } else if (arg.canConvert(QVariant::StringList)) {
+ m_hasNativeModel = true;
+ }
+ emit modelChanged(m_model);
+ }
+}
diff --git a/src/qtmenu.h b/src/qtmenu.h
index 6d5a4740..3d149433 100644
--- a/src/qtmenu.h
+++ b/src/qtmenu.h
@@ -74,27 +74,14 @@ public:
Q_INVOKABLE bool hasNativeModel() const { return m_hasNativeModel; }
public slots:
-
- void setModel(const QVariant arg) {
- if (m_model != arg) {
- m_hasNativeModel = false;
- m_model = arg;
- if (QAbstractItemModel *model = qobject_cast<QAbstractItemModel*>(arg.value<QObject*>())) {
- m_hasNativeModel = true;
- connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SIGNAL(rebuildMenu()));
- } else if (arg.canConvert(QVariant::StringList)) {
- m_hasNativeModel = true;
- }
- emit modelChanged(m_model);
- }
- }
+ void setModel(const QVariant &newModel);
public:
Q_SIGNALS:
void menuClosed();
void selectedIndexChanged();
void hoveredIndexChanged();
- void modelChanged(const QVariant&);
+ void modelChanged(const QVariant &newModel);
void rebuldMenu();
private Q_SLOTS: