on xenial help sign in
Keep the PreviewStack around to avoid mem leaks Fixes: #1495467
787234eAlbert Astals Cid
qml/Dash/PreviewListView.qml+12−4
@@ -101,18 +101,26 @@ Item {
101
101
102 isCurrent: ListView.isCurrentItem
102 isCurrent: ListView.isCurrentItem
103
103
104− previewModel: {
104+ readonly property var previewStack: {
105 if (root.open) {
105 if (root.open) {
106 if (index === root.initialIndex) {
106 if (index === root.initialIndex) {
107− return root.initialIndexPreviewStack.getPreviewModel(0);
107+ return root.initialIndexPreviewStack;
108 } else {
108 } else {
109− var previewStack = root.scope.preview(result, root.categoryId);
109+ return root.scope.preview(result, root.categoryId);
110− return previewStack.getPreviewModel(0);
111 }
110 }
112 } else {
111 } else {
113 return null;
112 return null;
114 }
113 }
115 }
114 }
115+
116+ previewModel: {
117+ if (previewStack) {
118+ return previewStack.getPreviewModel(0);
119+ } else {
120+ return null;
121+ }
122+ }
123+
116 scopeStyle: root.scopeStyle
124 scopeStyle: root.scopeStyle
117 }
125 }
118 }
126 }
tests/mocks/Unity/fake_previewstack.cpp+2−2
@@ -21,8 +21,8 @@
21#include "fake_previewmodel.h"
21#include "fake_previewmodel.h"
22#include "fake_scope.h"
22#include "fake_scope.h"
23
23
24−PreviewStack::PreviewStack(QObject* parent, Scope *scope)
24+PreviewStack::PreviewStack(Scope *scope)
25− : unity::shell::scopes::PreviewStackInterface(parent)
25+ : unity::shell::scopes::PreviewStackInterface(nullptr)
26{
26{
27 m_previews << new PreviewModel(this, scope);
27 m_previews << new PreviewModel(this, scope);
28}
28}
tests/mocks/Unity/fake_previewstack.h+1−1
@@ -32,7 +32,7 @@ class PreviewStack : public unity::shell::scopes::PreviewStackInterface
32 Q_OBJECT
32 Q_OBJECT
33
33
34public:
34public:
35− explicit PreviewStack(QObject* parent = 0, Scope* scope = 0);
35+ explicit PreviewStack(Scope* scope = 0);
36 virtual ~PreviewStack();
36 virtual ~PreviewStack();
37
37
38 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
38 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
tests/mocks/Unity/fake_scope.cpp+1−3
@@ -201,9 +201,7 @@ PreviewStack* Scope::preview(QVariant const& result, QString const& /*categoryId
201 if (m_returnNullPreview) {
201 if (m_returnNullPreview) {
202 return nullptr;
202 return nullptr;
203 } else {
203 } else {
204− // This probably leaks, do we don't care
205− // it's a test after all
206− return new PreviewStack(this, this);
204+ return new PreviewStack(this);
207 }
205 }
208}
206}
209
207