on xenial help sign in
Keep the PreviewStack around

The PreviewStack ownership is handled from the C++ plugin to QML so we need to keep it around otherwise it may be deleted (depends on the garbage collection) when we're still using the preview models that are its child and they'll be garbage collected too. This did not happen yet because the plugin had a bug that caused the preview stacks to never be deleted.

commit55ebcf27c61a920b0034b963c4860ce4d83ff17e authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 14 Sep 2015, 13:07 (11 years ago) parent0097739
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