on xenial help sign in
Throw away references if override model is destroyed
commitd8f94b0aabcbacc47ccf855341d620f4abaf1a79 authorMichal Hruby <michal.mhr@gmail.com> dateFri 9 Aug 2013, 16:22 (13 years ago) parent98cdd95
2 files changed+16−1
plugins/Unity/categories.cpp+15−1 plugins/Unity/categories.h+1
plugins/Unity/categories.cpp+15−1
@@ -142,10 +142,24 @@ Categories::roleNames() const
142142 return m_roles;
143143}
144144
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+
145158void Categories::overrideResults(const QString& categoryId, QAbstractItemModel* model)
146159{
147160 m_overriddenCategories[categoryId] = model;
148− // TODO: change the parent of the model?
161+ // watch the model
162+ connect(model, &QObject::destroyed, this, &Categories::onOverrideModelDestroyed);
149163 connect(model, &QAbstractItemModel::rowsInserted, this, &Categories::onRowCountChanged);
150164 connect(model, &QAbstractItemModel::rowsRemoved, this, &Categories::onRowCountChanged);
151165
plugins/Unity/categories.h+1
@@ -66,6 +66,7 @@ private Q_SLOTS:
6666 void onCountChanged();
6767 void onRowCountChanged();
6868 void onEmitCountChanged();
69+ void onOverrideModelDestroyed();
6970
7071private:
7172 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);