X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=blobdiff_plain;f=src%2Fjourneymodel.cpp;h=2919d83388c47fe3cd520936c4e8d12f8d47c12d;hp=5b7b5dab1e9bd1b7d1eb4c6d4ffd952edb62afa7;hb=70180c4c4fd2807d16f90562d6876f3f07d388b1;hpb=4248fa25458b2d282d4e0ed4447e4bc7570046eb diff --git a/src/journeymodel.cpp b/src/journeymodel.cpp index 5b7b5da..2919d83 100644 --- a/src/journeymodel.cpp +++ b/src/journeymodel.cpp @@ -14,8 +14,17 @@ QHash JourneyModel::roleNames() const { void JourneyModel::addJourney(const Journey &journey) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - journeys << journey; + // Find position to add it + QList::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(); } @@ -122,3 +131,29 @@ QDateTime JourneyModel::epochToDateTime(quint64 epoch) { date.setMSecsSinceEpoch(epoch); return date; } + +QList 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; + } +} +