X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=blobdiff_plain;f=src%2Fjourneymodel.cpp;h=2919d83388c47fe3cd520936c4e8d12f8d47c12d;hp=1dc7d58685d1e61e3a06921934b10d56c6ef570b;hb=70180c4c4fd2807d16f90562d6876f3f07d388b1;hpb=d8058e5edcec89d8103ead111f87dc9040323685 diff --git a/src/journeymodel.cpp b/src/journeymodel.cpp index 1dc7d58..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(); } @@ -126,3 +135,25 @@ QDateTime JourneyModel::epochToDateTime(quint64 epoch) { 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; + } +} +