##// END OF EJS Templates
Fix sorting with event products
trabillard -
r1233:15741afd69db
parent child
Show More
@@ -115,6 +115,14 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
115 115 Q_ASSERT(false);
116 116 return QStringLiteral("Unknown Data");
117 117 }
118
119 void refreshChildrenOfIndex(CatalogueEventsModel *model, const QModelIndex &index) const
120 {
121 auto childCount = model->rowCount(index);
122 auto colCount = model->columnCount();
123 emit model->dataChanged(model->index(0, 0, index),
124 model->index(childCount, colCount, index));
125 }
118 126 };
119 127
120 128 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
@@ -170,10 +178,14 CatalogueEventsModel::getEventProduct(const QModelIndex &index) const
170 178
171 179 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
172 180 {
173 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
181 beginInsertRows(QModelIndex(), impl->m_Events.count(), impl->m_Events.count());
174 182 impl->m_Events.append(event);
175 183 impl->parseEventProduct(event);
176 184 endInsertRows();
185
186 // Also refreshes its children event products
187 auto eventIndex = index(impl->m_Events.count(), 0);
188 impl->refreshChildrenOfIndex(this, eventIndex);
177 189 }
178 190
179 191 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
@@ -203,8 +215,7 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event)
203 215 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
204 216
205 217 // Also refreshes its children event products
206 auto childCount = rowCount(eventIndex);
207 emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex));
218 impl->refreshChildrenOfIndex(this, eventIndex);
208 219 }
209 220 else {
210 221 qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found.";
@@ -355,6 +366,7 QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientati
355 366
356 367 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
357 368 {
369 beginResetModel();
358 370 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
359 371 [this, column, order](auto e1, auto e2) {
360 372 auto data1 = impl->sortData(column, e1);
@@ -365,7 +377,7 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
365 377 return order == Qt::AscendingOrder ? result : !result;
366 378 });
367 379
368 emit dataChanged(QModelIndex(), QModelIndex());
380 endResetModel();
369 381 emit modelSorted();
370 382 }
371 383
General Comments 0
You need to be logged in to leave comments. Login now