##// END OF EJS Templates
Fix sorting with event products
trabillard -
r1288:15741afd69db
parent child
Show More
@@ -115,6 +115,14 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
115 Q_ASSERT(false);
115 Q_ASSERT(false);
116 return QStringLiteral("Unknown Data");
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 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
128 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
@@ -170,10 +178,14 CatalogueEventsModel::getEventProduct(const QModelIndex &index) const
170
178
171 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
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 impl->m_Events.append(event);
182 impl->m_Events.append(event);
175 impl->parseEventProduct(event);
183 impl->parseEventProduct(event);
176 endInsertRows();
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 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
191 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
@@ -203,8 +215,7 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event)
203 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
215 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
204
216
205 // Also refreshes its children event products
217 // Also refreshes its children event products
206 auto childCount = rowCount(eventIndex);
218 impl->refreshChildrenOfIndex(this, eventIndex);
207 emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex));
208 }
219 }
209 else {
220 else {
210 qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found.";
221 qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found.";
@@ -355,6 +366,7 QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientati
355
366
356 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
367 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
357 {
368 {
369 beginResetModel();
358 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
370 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
359 [this, column, order](auto e1, auto e2) {
371 [this, column, order](auto e1, auto e2) {
360 auto data1 = impl->sortData(column, e1);
372 auto data1 = impl->sortData(column, e1);
@@ -365,7 +377,7 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
365 return order == Qt::AscendingOrder ? result : !result;
377 return order == Qt::AscendingOrder ? result : !result;
366 });
378 });
367
379
368 emit dataChanged(QModelIndex(), QModelIndex());
380 endResetModel();
369 emit modelSorted();
381 emit modelSorted();
370 }
382 }
371
383
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now