QFile file;
file.setFileName(Settings::getConfigDir() + "/journeys.csv");
journeys.importFromFile(file);
+ journeys.sort(JourneyModel::StartRole, Qt::DescendingOrder);
QScopedPointer<QQuickView> view(SailfishApp::createView());
view->engine()->addImageProvider(QLatin1String("pedalo"), new ImageProvider(Settings::getInstance()));
qDebug() << "VERSION_MAJOR: " << VERSION_MAJOR;
qDebug() << "VERSION_MINOR: " << VERSION_MINOR;
qDebug() << "VERSION_BUILD: " << VERSION_BUILD;
+
ctxt->setContextProperty("journeymodel", &journeys);
ctxt->setContextProperty("currentStatus", ¤tStatus);
class Journey
{
public:
+ friend class JourneyTimeDescending;
+ friend class JourneyTimeAscending;
+
Journey();
Journey(quint64 start, quint32 duration, quint32 overtook, quint32 overtakenby);
quint32 overtakenby;
};
+class JourneyTimeAscending : std::binary_function<Journey,Journey, bool> {
+public:
+ bool operator() (Journey const &lhs, Journey const &rhs) const {
+ return lhs.start < rhs.start;
+ }
+};
+
+class JourneyTimeDescending : std::binary_function<Journey,Journey, bool> {
+public:
+ bool operator() (Journey const &lhs, Journey const &rhs) const {
+ return lhs.start > rhs.start;
+ }
+};
+
#endif // JOURNEY_H
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();
}
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;
+ }
+}
+
Q_INVOKABLE static QDateTime epochToDateTime(quint64 epoch);
QList<Journey> const & getData() const;
+
+ void sort(int column, Qt::SortOrder order);
signals:
// General signals
void journeysChanged();