on xenial help sign in
Add overrideCategory method to Categories
commitbd3b453dfa4751e753604fff988646d94bc8ff1f authorMichal Hruby <michal.mhr@gmail.com> dateWed 7 Aug 2013, 11:05 (13 years ago) parenta97b1ba
2 files changed+33
plugins/Unity/categories.cpp+30 plugins/Unity/categories.h+3
plugins/Unity/categories.cpp+30
@@ -123,6 +123,24 @@ Categories::roleNames() const
123123 return m_roles;
124124}
125125
126+void Categories::overrideCategory(const QString& categoryId, QAbstractItemModel* model)
127+{
128+ m_overriddenCategories[categoryId] = model;
129+ // TODO: change the parent of the model?
130+
131+ // emit the dataChanged signal if the category is already in the model
132+ for (int i = 0; i < rowCount(); i++) {
133+ auto id = data(index(i), RoleCategoryId).toString();
134+ if (id != categoryId) continue;
135+ QVector<int> roles;
136+ roles.append(RoleCount);
137+ roles.append(RoleResults);
138+ QModelIndex changedIndex = index(i);
139+ Q_EMIT dataChanged(changedIndex, changedIndex, roles);
140+ break;
141+ }
142+}
143+
126144QVariant
127145Categories::data(const QModelIndex& index, int role) const
128146{
@@ -147,8 +165,20 @@ Categories::data(const QModelIndex& index, int role) const
147165 case RoleHints:
148166 return DeeListModel::data(index, CategoryColumn::HINTS);
149167 case RoleResults:
168+ if (m_overriddenCategories.size() > 0)
169+ {
170+ auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
171+ if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
172+ return QVariant::fromValue(m_overriddenCategories[id]);
173+ }
150174 return QVariant::fromValue(getResults(index.row()));
151175 case RoleCount:
176+ if (m_overriddenCategories.size() > 0)
177+ {
178+ auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
179+ if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
180+ return QVariant::fromValue(m_overriddenCategories[id]->rowCount());
181+ }
152182 return QVariant::fromValue(getResults(index.row())->rowCount());
153183 case RoleCategoryIndex:
154184 return QVariant::fromValue(index.row());
plugins/Unity/categories.h+3
@@ -53,6 +53,8 @@ public:
5353 RoleCategoryIndex
5454 };
5555
56+ Q_INVOKABLE void overrideCategory(const QString& categoryId, QAbstractItemModel* model);
57+
5658 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
5759
5860 QHash<int, QByteArray> roleNames() const;
@@ -73,6 +75,7 @@ private:
7375 QTimer m_timer;
7476 QSet<int> m_updatedCategories;
7577 QHash<int, QByteArray> m_roles;
78+ QMap<QString, QAbstractItemModel*> m_overriddenCategories;
7679 mutable QMap<int, DeeListModel*> m_results;
7780 sigc::connection m_categoriesChangedConnection;
7881};