on xenial help sign in
Keep the PreviewStack around to avoid mem leaks Fixes: #1495467

Approved by: Michał Sawicz

commit787234e6ec03c93ddfa24b7bca69d409795c1dc9 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 22 Sep 2015, 12:57 (11 years ago) parent56ed36455ebcf2
4 files changed+16−10
qml/Dash/PreviewListView.qml+12−4 tests/mocks/Unity/fake_previewstack.cpp+2−2 tests/mocks/Unity/fake_previewstack.h+1−1 tests/mocks/Unity/fake_scope.cpp+1−3
qml/Dash/PreviewListView.qml+12−4
@@ -101,18 +101,26 @@ Item {
101101
102102 isCurrent: ListView.isCurrentItem
103103
104− previewModel: {
104+ readonly property var previewStack: {
105105 if (root.open) {
106106 if (index === root.initialIndex) {
107− return root.initialIndexPreviewStack.getPreviewModel(0);
107+ return root.initialIndexPreviewStack;
108108 } else {
109− var previewStack = root.scope.preview(result, root.categoryId);
110− return previewStack.getPreviewModel(0);
109+ return root.scope.preview(result, root.categoryId);
111110 }
112111 } else {
113112 return null;
114113 }
115114 }
115+
116+ previewModel: {
117+ if (previewStack) {
118+ return previewStack.getPreviewModel(0);
119+ } else {
120+ return null;
121+ }
122+ }
123+
116124 scopeStyle: root.scopeStyle
117125 }
118126 }
tests/mocks/Unity/fake_previewstack.cpp+2−2
@@ -21,8 +21,8 @@
2121#include "fake_previewmodel.h"
2222#include "fake_scope.h"
2323
24−PreviewStack::PreviewStack(QObject* parent, Scope *scope)
25− : unity::shell::scopes::PreviewStackInterface(parent)
24+PreviewStack::PreviewStack(Scope *scope)
25+ : unity::shell::scopes::PreviewStackInterface(nullptr)
2626{
2727 m_previews << new PreviewModel(this, scope);
2828}
tests/mocks/Unity/fake_previewstack.h+1−1
@@ -32,7 +32,7 @@ class PreviewStack : public unity::shell::scopes::PreviewStackInterface
3232 Q_OBJECT
3333
3434public:
35− explicit PreviewStack(QObject* parent = 0, Scope* scope = 0);
35+ explicit PreviewStack(Scope* scope = 0);
3636 virtual ~PreviewStack();
3737
3838 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
201201 if (m_returnNullPreview) {
202202 return nullptr;
203203 } 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);
207205 }
208206}
209207