on xenial help sign in
Make things safe
commit527a91e4d051617560e532f3ef1670981644236f authorMichal Hruby <michal.mhr@gmail.com> dateMon 1 Jul 2013, 16:18 (13 years ago) parentaa2134a
2 files changed+18−25
plugins/Unity/categories.cpp+15−23 plugins/Unity/categories.h+3−2
plugins/Unity/categories.cpp+15−23
@@ -49,26 +49,26 @@ Categories::~Categories()
4949DeeListModel*
5050Categories::getFilter(int index) const
5151{
52− if (!m_filters.contains(index)) {
53− auto results = std::make_shared<CategoryResults> ();
52+ if (!m_results.contains(index) || m_results[index].isNull()) {
53+ auto results = new CategoryResults;
5454 results->setCategoryIndex(index);
55− connect(results.get(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
55+ connect(results, &DeeListModel::countChanged, this, &Categories::onCountChanged);
5656
5757 unsigned cat_index = static_cast<unsigned>(index);
5858 auto unity_results = m_unityScope->GetResultsForCategory(cat_index);
5959 results->setModel(unity_results->model());
6060
61− m_filters.insert(index, results);
61+ m_results.insert(index, results);
6262 }
6363
64− return m_filters[index].get();
64+ return m_results[index];
6565}
6666
6767void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
6868{
69− m_timerFilters.clear();
70− m_filters.clear();
71−
69+ m_updatedCategories.clear();
70+ // FIXME: this might destroy the renderer view and re-create it, optimize?
71+ m_results.clear();
7272 setModel(model);
7373}
7474
@@ -81,22 +81,14 @@ Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
8181 //setModel(m_unityScope->categories()->model());
8282
8383 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
84−
85− /*
86− if (model != m_resultModel) {
87− Q_FOREACH(CategoryFilter* filter, m_filters) {
88− filter->setModel(m_resultModel);
89− }
90− }
91− */
9284}
9385
9486void
9587Categories::onCountChanged()
9688{
97− DeeListModel* filter = qobject_cast<DeeListModel*>(sender());
98− if (filter) {
99− m_timerFilters << filter;
89+ CategoryResults* results = qobject_cast<CategoryResults*>(sender());
90+ if (results) {
91+ m_updatedCategories << results->categoryIndex();
10092 m_timer.start();
10193 }
10294}
@@ -106,12 +98,12 @@ Categories::onEmitCountChanged()
10698{
10799 QVector<int> roles;
108100 roles.append(Categories::RoleCount);
109− Q_FOREACH(DeeListModel* results, m_timerFilters) {
110− auto cat_results = qobject_cast<CategoryResults*>(results);
111− QModelIndex changedIndex = index(cat_results->categoryIndex());
101+ Q_FOREACH(int cat_index, m_updatedCategories) {
102+ if (m_results[cat_index].isNull()) continue;
103+ QModelIndex changedIndex = index(cat_index);
112104 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
113105 }
114− m_timerFilters.clear();
106+ m_updatedCategories.clear();
115107}
116108
117109QHash<int, QByteArray>
plugins/Unity/categories.h+3−2
@@ -27,6 +27,7 @@
2727// dee-qt
2828#include "deelistmodel.h"
2929
30+#include <QPointer>
3031#include <QSet>
3132#include <QTimer>
3233
@@ -69,9 +70,9 @@ private:
6970
7071 unity::dash::Scope::Ptr m_unityScope;
7172 QTimer m_timer;
72− QSet<DeeListModel*> m_timerFilters;
73+ QSet<int> m_updatedCategories;
7374 QHash<int, QByteArray> m_roles;
74− mutable QMap<int, std::shared_ptr<DeeListModel>> m_filters;
75+ mutable QMap<int, QPointer<DeeListModel>> m_results;
7576};
7677
7778#endif // CATEGORIES_H