on xenial help sign in
Update count when overridden model count changes
commit98cdd952754cd7af7fcd087700b2e462ba56d096 authorMichal Hruby <michal.mhr@gmail.com> dateFri 9 Aug 2013, 16:11 (13 years ago) parent956eaba
2 files changed+22
plugins/Unity/categories.cpp+21 plugins/Unity/categories.h+1
plugins/Unity/categories.cpp+21
@@ -104,6 +104,25 @@ Categories::onCountChanged()
104104 }
105105}
106106
107+void Categories::onRowCountChanged()
108+{
109+ QAbstractItemModel* model = qobject_cast<QAbstractItemModel*>(sender());
110+ // find the corresponding category index
111+ for (auto iter = m_overriddenCategories.begin(); iter != m_overriddenCategories.end(); ++iter) {
112+ if (iter.value() == model) {
113+ for (int i = 0; i < rowCount(); i++) {
114+ auto id = data(index(i), RoleCategoryId).toString();
115+ if (id != iter.key()) continue;
116+ QVector<int> roles;
117+ roles.append(RoleCount);
118+ QModelIndex changedIndex = index(i);
119+ Q_EMIT dataChanged(changedIndex, changedIndex, roles);
120+ break;
121+ }
122+ }
123+ }
124+}
125+
107126void
108127Categories::onEmitCountChanged()
109128{
@@ -127,6 +146,8 @@ void Categories::overrideResults(const QString& categoryId, QAbstractItemModel*
127146{
128147 m_overriddenCategories[categoryId] = model;
129148 // TODO: change the parent of the model?
149+ connect(model, &QAbstractItemModel::rowsInserted, this, &Categories::onRowCountChanged);
150+ connect(model, &QAbstractItemModel::rowsRemoved, this, &Categories::onRowCountChanged);
130151
131152 // emit the dataChanged signal if the category is already in the model
132153 for (int i = 0; i < rowCount(); i++) {
plugins/Unity/categories.h+1
@@ -64,6 +64,7 @@ public:
6464
6565private Q_SLOTS:
6666 void onCountChanged();
67+ void onRowCountChanged();
6768 void onEmitCountChanged();
6869
6970private: