on xenial help sign in
Only use the root action state as a unitymenumodel ActionStateParser when needed.
879cf9eNick Dedekind
plugins/Unity/Indicators/rootactionstate.cpp+15−1
@@ -57,7 +57,7 @@ void RootActionState::setMenu(UnityMenuModel* menu)
57 connect(m_menu, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(onModelRowsRemoved(const QModelIndex&, int, int)));
57 connect(m_menu, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(onModelRowsRemoved(const QModelIndex&, int, int)));
58 connect(m_menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
58 connect(m_menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
59
59
60− m_menu->setActionStateParser(this);
60+ connect(m_menu, SIGNAL(destroyed()), SLOT(reset()));
61 }
61 }
62 updateActionState();
62 updateActionState();
63 Q_EMIT menuChanged();
63 Q_EMIT menuChanged();
@@ -92,10 +92,24 @@ void RootActionState::onModelDataChanged(const QModelIndex& topLeft, const QMode
92 }
92 }
93}
93}
94
94
95+void RootActionState::reset()
96+{
97+ m_cachedState.clear();
98+ m_menu = NULL;
99+
100+ Q_EMIT menuChanged();
101+ Q_EMIT updated();
102+}
103+
95void RootActionState::updateActionState()
104void RootActionState::updateActionState()
96{
105{
97 if (m_menu && m_menu->rowCount() > 0) {
106 if (m_menu && m_menu->rowCount() > 0) {
107+ ActionStateParser* oldParser = m_menu->actionStateParser();
108+ m_menu->setActionStateParser(this);
109+
98 m_cachedState = m_menu->get(0, "actionState").toMap();
110 m_cachedState = m_menu->get(0, "actionState").toMap();
111+
112+ m_menu->setActionStateParser(oldParser);
99 } else {
113 } else {
100 m_cachedState.clear();
114 m_cachedState.clear();
101 }
115 }
plugins/Unity/Indicators/rootactionstate.h+1
@@ -77,6 +77,7 @@ private Q_SLOTS:
77 void onModelRowsAdded(const QModelIndex& parent, int start, int end);
77 void onModelRowsAdded(const QModelIndex& parent, int start, int end);
78 void onModelRowsRemoved(const QModelIndex& parent, int start, int end);
78 void onModelRowsRemoved(const QModelIndex& parent, int start, int end);
79 void onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>&);
79 void onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>&);
80+ void reset();
80
81
81private:
82private:
82 void updateActionState();
83 void updateActionState();
tests/plugins/Unity/Indicators/CMakeLists.txt+5
@@ -1,6 +1,9 @@
1+pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
2+
1include_directories(
3include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}
4 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_CURRENT_SOURCE_DIR}/../../../../plugins/Unity/Indicators
5 ${CMAKE_CURRENT_SOURCE_DIR}/../../../../plugins/Unity/Indicators
6+ ${QMENUMODEL_INCLUDE_DIRS}
4 )
7 )
5
8
6macro(run_tests)
9macro(run_tests)
@@ -16,6 +19,7 @@ macro(run_tests)
16 qt5_use_modules(${_test}Exec Test Core Qml)
19 qt5_use_modules(${_test}Exec Test Core Qml)
17 target_link_libraries(${_test}Exec
20 target_link_libraries(${_test}Exec
18 IndicatorsQml
21 IndicatorsQml
22+ ${QMENUMODEL_LDFLAGS}
19 )
23 )
20 set(_test_list "${_test_list};${_test}")
24 set(_test_list "${_test_list};${_test}")
21 endforeach()
25 endforeach()
@@ -25,4 +29,5 @@ run_tests(
25 indicatorsmanagertest
29 indicatorsmanagertest
26 indicatorsmodeltest
30 indicatorsmodeltest
27 menucontentactivatortest
31 menucontentactivatortest
32+ rootactionstatetest
28 )
33 )
tests/plugins/Unity/Indicators/rootactionstatetest.cppnew file+58
@@ -0,0 +1,58 @@
1+/*
2+ * Copyright 2013 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Nick Dedekind <nick.dedekind@canonical.com>
18+ */
19+
20+#include "rootactionstate.h"
21+
22+#include <unitymenumodel.h>
23+#include <QtTest>
24+
25+class RootActionStateTest : public QObject
26+{
27+ Q_OBJECT
28+private Q_SLOTS:
29+
30+ void testDeleteRootActionState()
31+ {
32+ UnityMenuModel* menuModel = new UnityMenuModel();
33+ ActionStateParser* originalParser = menuModel->actionStateParser();
34+ RootActionState* rootState = new RootActionState();
35+
36+ rootState->setMenu(menuModel);
37+
38+ delete rootState;
39+ QCOMPARE(menuModel->actionStateParser(), originalParser);
40+ delete menuModel;
41+ }
42+
43+ void testDeleteUnityMenuModel()
44+ {
45+ UnityMenuModel* menuModel = new UnityMenuModel();
46+ RootActionState* rootState = new RootActionState();
47+
48+ rootState->setMenu(menuModel);
49+
50+ QCOMPARE(rootState->menu(), menuModel);
51+ delete menuModel;
52+ QVERIFY(rootState->menu() == NULL);
53+ delete rootState;
54+ }
55+};
56+
57+QTEST_GUILESS_MAIN(RootActionStateTest)
58+#include "rootactionstatetest.moc"