void JourneyModel::addJourney(const Journey &journey)
{
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- journeys << journey;
+ // Find position to add it
+ QList<Journey>::const_iterator it = journeys.constBegin();
+
+ unsigned int position = 0;
+ while ((it != journeys.constEnd()) && (journey.getStart() < (*it).getStart())) {
+ position++;
+ it++;
+ }
+
+ beginInsertRows(QModelIndex(), position, position);
+ journeys.insert(position, journey);
endInsertRows();
}
emit dataChanged(createIndex(index, 0), createIndex(index, 0));
}
+void JourneyModel::deleteJourney(quint32 index) {
+ beginRemoveRows(QModelIndex(), index, index);
+ journeys.removeAt(index);
+ endRemoveRows();
+}
+
int JourneyModel::rowCount(const QModelIndex & parent) const {
Q_UNUSED(parent)
return journeys.count();
QDate JourneyModel::epochToDate(quint64 epoch) {
QDateTime date;
- qDebug() << "Epoch: " << epoch;
date.setMSecsSinceEpoch(epoch);
- qDebug() << "Date: " << date.date();
return date.date();
}
date.setMSecsSinceEpoch(epoch);
return date;
}
+
+QList<Journey> const & JourneyModel::getData() const {
+ return journeys;
+}
+
+void JourneyModel::sort(int column, Qt::SortOrder order) {
+ switch (column) {
+ case JourneyRoles::StartRole:
+ switch (order) {
+ case Qt::SortOrder::AscendingOrder:
+ std::sort(journeys.begin(), journeys.end(), JourneyTimeAscending());
+ break;
+ case Qt::SortOrder::DescendingOrder:
+ std::sort(journeys.begin(), journeys.end(), JourneyTimeDescending());
+ break;
+ default:
+ // Do nothing
+ break;
+ }
+ break;
+ default:
+ // Do nothing
+ break;
+ }
+}
+