on xenial help sign in
Make things safe
527a91eMichal Hruby
plugins/Unity/categories.cpp+15−23
@@ -49,26 +49,26 @@ Categories::~Categories()
49DeeListModel*
49DeeListModel*
50Categories::getFilter(int index) const
50Categories::getFilter(int index) const
51{
51{
52− if (!m_filters.contains(index)) {
52+ if (!m_results.contains(index) || m_results[index].isNull()) {
53− auto results = std::make_shared<CategoryResults> ();
53+ auto results = new CategoryResults;
54 results->setCategoryIndex(index);
54 results->setCategoryIndex(index);
55− connect(results.get(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
55+ connect(results, &DeeListModel::countChanged, this, &Categories::onCountChanged);
56
56
57 unsigned cat_index = static_cast<unsigned>(index);
57 unsigned cat_index = static_cast<unsigned>(index);
58 auto unity_results = m_unityScope->GetResultsForCategory(cat_index);
58 auto unity_results = m_unityScope->GetResultsForCategory(cat_index);
59 results->setModel(unity_results->model());
59 results->setModel(unity_results->model());
60
60
61− m_filters.insert(index, results);
61+ m_results.insert(index, results);
62 }
62 }
63
63
64− return m_filters[index].get();
64+ return m_results[index];
65}
65}
66
66
67void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
67void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
68{
68{
69− m_timerFilters.clear();
69+ m_updatedCategories.clear();
70− m_filters.clear();
70+ // FIXME: this might destroy the renderer view and re-create it, optimize?
71−
71+ m_results.clear();
72 setModel(model);
72 setModel(model);
73}
73}
74
74
@@ -81,22 +81,14 @@ Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
81 //setModel(m_unityScope->categories()->model());
81 //setModel(m_unityScope->categories()->model());
82
82
83 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
83 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− */
92}
84}
93
85
94void
86void
95Categories::onCountChanged()
87Categories::onCountChanged()
96{
88{
97− DeeListModel* filter = qobject_cast<DeeListModel*>(sender());
89+ CategoryResults* results = qobject_cast<CategoryResults*>(sender());
98− if (filter) {
90+ if (results) {
99− m_timerFilters << filter;
91+ m_updatedCategories << results->categoryIndex();
100 m_timer.start();
92 m_timer.start();
101 }
93 }
102}
94}
@@ -106,12 +98,12 @@ Categories::onEmitCountChanged()
106{
98{
107 QVector<int> roles;
99 QVector<int> roles;
108 roles.append(Categories::RoleCount);
100 roles.append(Categories::RoleCount);
109− Q_FOREACH(DeeListModel* results, m_timerFilters) {
101+ Q_FOREACH(int cat_index, m_updatedCategories) {
110− auto cat_results = qobject_cast<CategoryResults*>(results);
102+ if (m_results[cat_index].isNull()) continue;
111− QModelIndex changedIndex = index(cat_results->categoryIndex());
103+ QModelIndex changedIndex = index(cat_index);
112 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
104 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
113 }
105 }
114− m_timerFilters.clear();
106+ m_updatedCategories.clear();
115}
107}
116
108
117QHash<int, QByteArray>
109QHash<int, QByteArray>
plugins/Unity/categories.h+3−2
@@ -27,6 +27,7 @@
27// dee-qt
27// dee-qt
28#include "deelistmodel.h"
28#include "deelistmodel.h"
29
29
30+#include <QPointer>
30#include <QSet>
31#include <QSet>
31#include <QTimer>
32#include <QTimer>
32
33
@@ -69,9 +70,9 @@ private:
69
70
70 unity::dash::Scope::Ptr m_unityScope;
71 unity::dash::Scope::Ptr m_unityScope;
71 QTimer m_timer;
72 QTimer m_timer;
72− QSet<DeeListModel*> m_timerFilters;
73+ QSet<int> m_updatedCategories;
73 QHash<int, QByteArray> m_roles;
74 QHash<int, QByteArray> m_roles;
74− mutable QMap<int, std::shared_ptr<DeeListModel>> m_filters;
75+ mutable QMap<int, QPointer<DeeListModel>> m_results;
75};
76};
76
77
77#endif // CATEGORIES_H
78#endif // CATEGORIES_H