on xenial help sign in
Only use the root action state as a unitymenumodel ActionStateParser when needed.

Approved by Michael Terry.

commit879cf9e6f5cc771bd44a5f99730aa684c72cc50e authorNick Dedekind <nicholas.dedekind@gmail.com> dateFri 11 Oct 2013, 12:06 (13 years ago) parent273c20f501fa53
4 files changed+79−1
plugins/Unity/Indicators/rootactionstate.cpp+15−1 plugins/Unity/Indicators/rootactionstate.h+1 tests/plugins/Unity/Indicators/CMakeLists.txt+5 tests/plugins/Unity/Indicators/rootactionstatetest.cpp+58
plugins/Unity/Indicators/rootactionstate.cpp+15−1
@@ -57,7 +57,7 @@ void RootActionState::setMenu(UnityMenuModel* menu)
5757 connect(m_menu, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(onModelRowsRemoved(const QModelIndex&, int, int)));
5858 connect(m_menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
5959
60− m_menu->setActionStateParser(this);
60+ connect(m_menu, SIGNAL(destroyed()), SLOT(reset()));
6161 }
6262 updateActionState();
6363 Q_EMIT menuChanged();
@@ -92,10 +92,24 @@ void RootActionState::onModelDataChanged(const QModelIndex& topLeft, const QMode
9292 }
9393}
9494
95+void RootActionState::reset()
96+{
97+ m_cachedState.clear();
98+ m_menu = NULL;
99+
100+ Q_EMIT menuChanged();
101+ Q_EMIT updated();
102+}
103+
95104void RootActionState::updateActionState()
96105{
97106 if (m_menu && m_menu->rowCount() > 0) {
107+ ActionStateParser* oldParser = m_menu->actionStateParser();
108+ m_menu->setActionStateParser(this);
109+
98110 m_cachedState = m_menu->get(0, "actionState").toMap();
111+
112+ m_menu->setActionStateParser(oldParser);
99113 } else {
100114 m_cachedState.clear();
101115 }
plugins/Unity/Indicators/rootactionstate.h+1
@@ -77,6 +77,7 @@ private Q_SLOTS:
7777 void onModelRowsAdded(const QModelIndex& parent, int start, int end);
7878 void onModelRowsRemoved(const QModelIndex& parent, int start, int end);
7979 void onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>&);
80+ void reset();
8081
8182private:
8283 void updateActionState();
tests/plugins/Unity/Indicators/CMakeLists.txt+5
@@ -1,6 +1,9 @@
1+pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
2+
13include_directories(
24 ${CMAKE_CURRENT_BINARY_DIR}
35 ${CMAKE_CURRENT_SOURCE_DIR}/../../../../plugins/Unity/Indicators
6+ ${QMENUMODEL_INCLUDE_DIRS}
47 )
58
69macro(run_tests)
@@ -16,6 +19,7 @@ macro(run_tests)
1619 qt5_use_modules(${_test}Exec Test Core Qml)
1720 target_link_libraries(${_test}Exec
1821 IndicatorsQml
22+ ${QMENUMODEL_LDFLAGS}
1923 )
2024 set(_test_list "${_test_list};${_test}")
2125 endforeach()
@@ -25,4 +29,5 @@ run_tests(
2529 indicatorsmanagertest
2630 indicatorsmodeltest
2731 menucontentactivatortest
32+ rootactionstatetest
2833 )
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"