Merge lp:~nick-dedekind/qmenumodel/unitymenuaction.lp1334203 into lp:qmenumodel

Proposed by Nick Dedekind
Status: Merged
Approved by: Nick Dedekind
Approved revision: 108
Merged at revision: 107
Proposed branch: lp:~nick-dedekind/qmenumodel/unitymenuaction.lp1334203
Merge into: lp:qmenumodel
Diff against target: 177 lines (+77/-7)
4 files modified
libqmenumodel/src/unitymenuaction.cpp (+3/-7)
libqmenumodel/src/unitymenumodel.cpp (+11/-0)
tests/client/CMakeLists.txt (+1/-0)
tests/client/unitymenuactiontest.cpp (+62/-0)
To merge this branch: bzr merge lp:~nick-dedekind/qmenumodel/unitymenuaction.lp1334203
Reviewer Review Type Date Requested Status
Andrea Cimitan (community) Approve
Lars Karlitski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+225063@code.launchpad.net

Commit message

Unset the UnityMenuActions::model when destroying UnityMenuModel

Description of the change

Unset the UnityMenuActions::model when destroying UnityMenuModel

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Looks good to me, thanks.

review: Approve
Revision history for this message
Andrea Cimitan (cimi) wrote :

Fixes for me, thx

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libqmenumodel/src/unitymenuaction.cpp'
2--- libqmenumodel/src/unitymenuaction.cpp 2013-09-03 10:02:47 +0000
3+++ libqmenumodel/src/unitymenuaction.cpp 2014-07-01 10:17:47 +0000
4@@ -33,9 +33,7 @@
5
6 UnityMenuAction::~UnityMenuAction()
7 {
8- if (m_model) {
9- m_model->unregisterAction(this);
10- }
11+ unregisterAction();
12 }
13
14 QString UnityMenuAction::name() const
15@@ -59,9 +57,7 @@
16 void UnityMenuAction::setModel(UnityMenuModel* model)
17 {
18 if (m_model != model) {
19- if (!model) {
20- unregisterAction();
21- }
22+ unregisterAction();
23 m_model = model;
24 registerAction();
25 Q_EMIT modelChanged(model);
26@@ -107,7 +103,7 @@
27 }
28 }
29
30-int UnityMenuAction::index() const
31+int UnityMenuAction::index() const
32 {
33 return m_index;
34 }
35
36=== modified file 'libqmenumodel/src/unitymenumodel.cpp'
37--- libqmenumodel/src/unitymenumodel.cpp 2014-04-02 10:19:02 +0000
38+++ libqmenumodel/src/unitymenumodel.cpp 2014-07-01 10:17:47 +0000
39@@ -79,6 +79,7 @@
40 QHash<QByteArray, int> roles;
41 ActionStateParser* actionStateParser;
42 QHash<UnityMenuAction*, GtkSimpleActionObserver*> registeredActions;
43+ bool destructorGuard;
44
45 static void nameAppeared(GDBusConnection *connection, const gchar *name, const gchar *owner, gpointer user_data);
46 static void nameVanished(GDBusConnection *connection, const gchar *name, gpointer user_data);
47@@ -113,6 +114,7 @@
48 this->connection = NULL;
49 this->nameWatchId = 0;
50 this->actionStateParser = new ActionStateParser(model);
51+ this->destructorGuard = false;
52
53 this->muxer = gtk_action_muxer_new ();
54
55@@ -126,6 +128,7 @@
56 this->connection = NULL;
57 this->nameWatchId = 0;
58 this->actionStateParser = new ActionStateParser(model);
59+ this->destructorGuard = false;
60
61 this->muxer = GTK_ACTION_MUXER( g_object_ref(other.muxer));
62
63@@ -134,6 +137,7 @@
64
65 UnityMenuModelPrivate::~UnityMenuModelPrivate()
66 {
67+ this->destructorGuard = true;
68 this->clearItems(false);
69
70 g_sequence_free(this->items);
71@@ -144,6 +148,7 @@
72 QHash<UnityMenuAction*, GtkSimpleActionObserver*>::const_iterator it = this->registeredActions.constBegin();
73 for (; it != this->registeredActions.constEnd(); ++it) {
74 g_object_unref(it.value());
75+ it.key()->setModel(NULL);
76 }
77 this->registeredActions.clear();
78
79@@ -787,6 +792,9 @@
80
81 void UnityMenuModel::registerAction(UnityMenuAction* action)
82 {
83+ if (priv->destructorGuard)
84+ return;
85+
86 if (!priv->registeredActions.contains(action)) {
87 GtkSimpleActionObserver* observer_item;
88 observer_item = gtk_simple_action_observer_new(GTK_ACTION_OBSERVABLE (priv->muxer),
89@@ -808,6 +816,9 @@
90
91 void UnityMenuModel::unregisterAction(UnityMenuAction* action)
92 {
93+ if (priv->destructorGuard)
94+ return;
95+
96 if (priv->registeredActions.contains(action)) {
97 GtkSimpleActionObserver* observer_item;
98 observer_item = priv->registeredActions[action];
99
100=== modified file 'tests/client/CMakeLists.txt'
101--- tests/client/CMakeLists.txt 2013-08-27 16:20:22 +0000
102+++ tests/client/CMakeLists.txt 2014-07-01 10:17:47 +0000
103@@ -60,6 +60,7 @@
104 declare_test(convertertest)
105 declare_test(modelsignalstest)
106 declare_test(treetest)
107+declare_test(unitymenuactiontest)
108
109 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qmlfiles.h.in
110 ${CMAKE_CURRENT_BINARY_DIR}/qmlfiles.h)
111
112=== added file 'tests/client/unitymenuactiontest.cpp'
113--- tests/client/unitymenuactiontest.cpp 1970-01-01 00:00:00 +0000
114+++ tests/client/unitymenuactiontest.cpp 2014-07-01 10:17:47 +0000
115@@ -0,0 +1,62 @@
116+/*
117+ * Copyright 2014 Canonical Ltd.
118+ *
119+ * This program is free software; you can redistribute it and/or modify
120+ * it under the terms of the GNU Lesser General Public License as published by
121+ * the Free Software Foundation; version 3.
122+ *
123+ * This program is distributed in the hope that it will be useful,
124+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
125+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
126+ * GNU Lesser General Public License for more details.
127+ *
128+ * You should have received a copy of the GNU Lesser General Public License
129+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
130+ *
131+ * Authors:
132+ * Nick Dedekind <nick.dedekind@canonical.com>
133+ */
134+
135+#include "unitymenumodel.h"
136+#include "unitymenuaction.h"
137+
138+#include <QObject>
139+#include <QtTest>
140+
141+class UnityMenuActionTest : public QObject
142+{
143+ Q_OBJECT
144+private:
145+
146+private Q_SLOTS:
147+
148+ /*
149+ * Test if the propety busType handle correct integer values
150+ */
151+ void testDestroyAfterModel()
152+ {
153+ UnityMenuModel* model = new UnityMenuModel;
154+ UnityMenuAction* action = new UnityMenuAction;
155+ action->setModel(model);
156+
157+ delete model;
158+ delete action;
159+ }
160+
161+ /*
162+ * Test if the propety busType handle correct integer values
163+ */
164+ void testDestroyBeforeModel()
165+ {
166+ UnityMenuModel* model = new UnityMenuModel;
167+ UnityMenuAction* action = new UnityMenuAction;
168+ action->setModel(model);
169+
170+ delete action;
171+ delete model;
172+ }
173+};
174+
175+QTEST_MAIN(UnityMenuActionTest)
176+
177+#include "unitymenuactiontest.moc"

Subscribers

People subscribed via source and target branches