KPublicTransport

pathmodel.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "pathmodel.h"
8
9using namespace KPublicTransport;
10
11PathModel::PathModel(QObject *parent)
12 : QAbstractListModel(parent)
13{
14}
15
16PathModel::~PathModel() = default;
17
18Path PathModel::path() const
19{
20 return m_path;
21}
22
23void PathModel::setPath(const Path &path)
24{
26 m_path = path;
28}
29
30int PathModel::rowCount(const QModelIndex &parent) const
31{
32 if (parent.isValid()) {
33 return 0;
34 }
35 return m_path.sections().size();
36}
37
38QVariant PathModel::data(const QModelIndex &index, int role) const
39{
40 switch (role) {
41 case PathSectionRole:
42 return m_path.sections()[index.row()];
43 case TurnDirectionRole:
44 {
45 const auto curDir = m_path.sections()[index.row()].direction();
46 if (index.row() == 0) {
47 return curDir;
48 }
49 const auto prevDir = m_path.sections()[index.row() - 1].direction();
50 if (prevDir >= 0 && curDir >= 0) {
51 return (360 + curDir - prevDir) % 360;
52 }
53 return curDir;
54 }
55 }
56
57 return {};
58}
59
60QHash<int, QByteArray> PathModel::roleNames() const
61{
63 r.insert(PathSectionRole, "section");
64 r.insert(TurnDirectionRole, "turnDirection");
65 return r;
66}
A path followed by any kind of location change.
Definition path.h:113
std::vector< KPublicTransport::PathSection > sections
Access to path sections for QML.
Definition path.h:117
QString path(const QString &relativePath)
Query operations and data types for accessing realtime public transport information from online servi...
virtual QHash< int, QByteArray > roleNames() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
int row() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:57:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.