on xenial help sign in
Throw away references if override model is destroyed
d8f94b0Michal Hruby
plugins/Unity/categories.cpp+15−1
@@ -142,10 +142,24 @@ Categories::roleNames() const
142 return m_roles;
142 return m_roles;
143}
143}
144
144
145+void Categories::onOverrideModelDestroyed()
146+{
147+ QObject* model = sender();
148+ auto iter = m_overriddenCategories.begin();
149+ while (iter != m_overriddenCategories.end()) {
150+ if (iter.value() == model) {
151+ iter = m_overriddenCategories.erase(iter);
152+ continue;
153+ }
154+ ++iter;
155+ }
156+}
157+
145void Categories::overrideResults(const QString& categoryId, QAbstractItemModel* model)
158void Categories::overrideResults(const QString& categoryId, QAbstractItemModel* model)
146{
159{
147 m_overriddenCategories[categoryId] = model;
160 m_overriddenCategories[categoryId] = model;
148− // TODO: change the parent of the model?
161+ // watch the model
162+ connect(model, &QObject::destroyed, this, &Categories::onOverrideModelDestroyed);
149 connect(model, &QAbstractItemModel::rowsInserted, this, &Categories::onRowCountChanged);
163 connect(model, &QAbstractItemModel::rowsInserted, this, &Categories::onRowCountChanged);
150 connect(model, &QAbstractItemModel::rowsRemoved, this, &Categories::onRowCountChanged);
164 connect(model, &QAbstractItemModel::rowsRemoved, this, &Categories::onRowCountChanged);
151
165
plugins/Unity/categories.h+1
@@ -66,6 +66,7 @@ private Q_SLOTS:
66 void onCountChanged();
66 void onCountChanged();
67 void onRowCountChanged();
67 void onRowCountChanged();
68 void onEmitCountChanged();
68 void onEmitCountChanged();
69+ void onOverrideModelDestroyed();
69
70
70private:
71private:
71 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
72 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);