on xenial help sign in
Added model submneu re-initialisation on disconnected proxy.
a788c1fNick Dedekind
Panel/Indicators/client/IndicatorsList.qml+2−5
@@ -41,7 +41,6 @@ Page {
41 delegate: Indicators.MenuItem {
41 delegate: Indicators.MenuItem {
42 anchors.left: parent.left
42 anchors.left: parent.left
43 anchors.right: parent.right
43 anchors.right: parent.right
44− progression: isValid
45 objectName: identifier
44 objectName: identifier
46
45
47 Label {
46 Label {
@@ -52,10 +51,8 @@ Page {
52 }
51 }
53
52
54 onClicked: {
53 onClicked: {
55− if (progression) {
56− var new_page = Qt.createComponent("IndicatorsPage.qml");
54+ var new_page = Qt.createComponent("IndicatorsPage.qml");
57− page.pageStack.push(new_page.createObject(pages), {"indicatorProperties" : model.indicatorProperties, "pageSource" : model.pageSource});
55+ page.pageStack.push(new_page.createObject(pages), {"indicatorProperties" : model.indicatorProperties, "pageSource" : model.pageSource});
58− }
59 }
56 }
60 }
57 }
61 }
58 }
plugins/Unity/Indicators/qml/IndicatorPage.qml+1−1
@@ -113,7 +113,7 @@ IndicatorBase {
113
113
114 onLoaded: {
114 onLoaded: {
115 if (model.type === rootMenuType) {
115 if (model.type === rootMenuType) {
116− menuStack.push(mainMenu.model.submenu(index));
116+ menuStack.push(mainMenu.model.submenu(index), index);
117 }
117 }
118
118
119 if (item.hasOwnProperty("menuSelected")) {
119 if (item.hasOwnProperty("menuSelected")) {
plugins/Unity/Indicators/unitymenumodelstack.cpp+92−7
@@ -19,6 +19,65 @@
19
19
20#include "unitymenumodelstack.h"
20#include "unitymenumodelstack.h"
21
21
22+#include <QDebug>
23+#include <unitymenumodel.h>
24+
25+class UnityMenuModelEntry : public QObject {
26+ Q_OBJECT
27+public:
28+ UnityMenuModelEntry(UnityMenuModel* model, UnityMenuModel* parentModel, int index)
29+ : m_model(model),
30+ m_parentModel(parentModel),
31+ m_index(index)
32+ {
33+ if (m_parentModel) {
34+ QObject::connect(m_parentModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(onRowsInserted(QModelIndex, int, int)));
35+ QObject::connect(m_parentModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(countChanged(QModelIndex, int, int)));
36+ QObject::connect(m_parentModel, SIGNAL(modelReset()), this, SLOT(onModelReset()));
37+ }
38+ }
39+
40+ UnityMenuModel* model() const { return m_model; }
41+
42+private Q_SLOTS:
43+ void onRowsInserted(const QModelIndex&, int start, int end)
44+ {
45+ int delta = end-start + 1;
46+ if (start <= m_index) {
47+ m_index += delta;
48+ }
49+ }
50+
51+ void onRowsRemoved(const QModelIndex&, int start, int end)
52+ {
53+ int delta = end-start + 1;
54+ if (start <= m_index) {
55+ if (start + delta >= m_index) {
56+ // in the range removed
57+ Q_EMIT remove();
58+ disconnect(m_parentModel, 0, this, 0);
59+ } else {
60+ m_index -= delta;
61+ }
62+ }
63+ }
64+
65+Q_SIGNALS:
66+ void remove();
67+
68+private Q_SLOTS:
69+ void onModelReset()
70+ {
71+ Q_EMIT remove();
72+ disconnect(m_parentModel, 0, this, 0);
73+ }
74+
75+private:
76+ UnityMenuModel* m_model;
77+ UnityMenuModel* m_parentModel;
78+ int m_index;
79+};
80+
22UnityMenuModelStack::UnityMenuModelStack(QObject* parent)
81UnityMenuModelStack::UnityMenuModelStack(QObject* parent)
23 : QObject(parent)
82 : QObject(parent)
24{
83{
@@ -26,30 +85,37 @@ UnityMenuModelStack::UnityMenuModelStack(QObject* parent)
26
85
27UnityMenuModelStack::~UnityMenuModelStack()
86UnityMenuModelStack::~UnityMenuModelStack()
28{
87{
88+ qDeleteAll(m_menuModels);
89+ m_menuModels.clear();
29}
90}
30
91
31UnityMenuModel* UnityMenuModelStack::head() const
92UnityMenuModel* UnityMenuModelStack::head() const
32{
93{
33− return !m_menuModels.isEmpty() ? m_menuModels.first() : NULL;
94+ return !m_menuModels.isEmpty() ? m_menuModels.first()->model() : NULL;
34}
95}
35
96
36void UnityMenuModelStack::setHead(UnityMenuModel* model)
97void UnityMenuModelStack::setHead(UnityMenuModel* model)
37{
98{
38 if (head() != model) {
99 if (head() != model) {
100+ qDeleteAll(m_menuModels);
39 m_menuModels.clear();
101 m_menuModels.clear();
102+
40− push(model);
103+ push(model, 0);
41 Q_EMIT headChanged(model);
104 Q_EMIT headChanged(model);
42 }
105 }
43}
106}
44
107
45UnityMenuModel* UnityMenuModelStack::tail() const
108UnityMenuModel* UnityMenuModelStack::tail() const
46{
109{
47− return !m_menuModels.isEmpty() ? m_menuModels.last() : NULL;
110+ return !m_menuModels.isEmpty() ? m_menuModels.last()->model() : NULL;
48}
111}
49
112
50−void UnityMenuModelStack::push(UnityMenuModel* model)
113+void UnityMenuModelStack::push(UnityMenuModel* model, int index)
51{
114{
115+ UnityMenuModelEntry* entry = new UnityMenuModelEntry(model, tail(), index);
116+ QObject::connect(entry, SIGNAL(remove()), SLOT(onRemove()));
117+
52− m_menuModels << model;
118+ m_menuModels << entry;
53 Q_EMIT tailChanged(model);
119 Q_EMIT tailChanged(model);
54}
120}
55
121
@@ -58,7 +124,9 @@ UnityMenuModel* UnityMenuModelStack::pop()
58 if (m_menuModels.isEmpty()) {
124 if (m_menuModels.isEmpty()) {
59 return NULL;
125 return NULL;
60 }
126 }
61− UnityMenuModel* model = m_menuModels.takeLast();
127+ UnityMenuModelEntry* entry = m_menuModels.takeLast();
128+ UnityMenuModel* model = entry->model();
129+ entry->deleteLater();
62
130
63 Q_EMIT tailChanged(tail());
131 Q_EMIT tailChanged(tail());
64 if (m_menuModels.isEmpty()) {
132 if (m_menuModels.isEmpty()) {
@@ -66,4 +134,21 @@ UnityMenuModel* UnityMenuModelStack::pop()
66 }
134 }
67
135
68 return model;
136 return model;
69−}
137+}
138+
139+void UnityMenuModelStack::onRemove()
140+{
141+ UnityMenuModelEntry* removed = qobject_cast<UnityMenuModelEntry*>(sender());
142+ if (!m_menuModels.contains(removed))
143+ return;
144+
145+ for (int i = m_menuModels.count() -1; i >= 0; i--) {
146+ UnityMenuModelEntry* entry = m_menuModels[i];
147+ pop();
148+ if (entry == removed) {
149+ break;
150+ }
151+ }
152+}
153+
154+#include "unitymenumodelstack.moc"
plugins/Unity/Indicators/unitymenumodelstack.h+6−2
@@ -25,6 +25,7 @@
25#include <QObject>
25#include <QObject>
26#include <QList>
26#include <QList>
27
27
28+class UnityMenuModelEntry;
28class UnityMenuModel;
29class UnityMenuModel;
29
30
30// A LIFO queue for storing the current submenu of a UnityMenuModel.
31// A LIFO queue for storing the current submenu of a UnityMenuModel.
@@ -46,15 +47,18 @@ public:
46
47
47 UnityMenuModel* tail() const;
48 UnityMenuModel* tail() const;
48
49
49− Q_INVOKABLE void push(UnityMenuModel* model);
50+ Q_INVOKABLE void push(UnityMenuModel* model, int menuIndex);
50 Q_INVOKABLE UnityMenuModel* pop();
51 Q_INVOKABLE UnityMenuModel* pop();
51
52
52Q_SIGNALS:
53Q_SIGNALS:
53 void headChanged(UnityMenuModel* head);
54 void headChanged(UnityMenuModel* head);
54 void tailChanged(UnityMenuModel* tail);
55 void tailChanged(UnityMenuModel* tail);
55
56
57+private Q_SLOTS:
58+ void onRemove();
59+
56private:
60private:
57− QList<UnityMenuModel*> m_menuModels;
61+ QList<UnityMenuModelEntry*> m_menuModels;
58};
62};
59
63
60#endif // UNITYMENUMODELSTACK_H
64#endif // UNITYMENUMODELSTACK_H