KPublicTransport

pathmodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "pathmodel.h"
8 
9 using namespace KPublicTransport;
10 
11 PathModel::PathModel(QObject *parent)
12  : QAbstractListModel(parent)
13 {
14 }
15 
16 PathModel::~PathModel() = default;
17 
18 Path PathModel::path() const
19 {
20  return m_path;
21 }
22 
23 void PathModel::setPath(const Path &path)
24 {
25  beginResetModel();
26  m_path = path;
27  endResetModel();
28 }
29 
30 int PathModel::rowCount(const QModelIndex &parent) const
31 {
32  if (parent.isValid()) {
33  return 0;
34  }
35  return m_path.sections().size();
36 }
37 
38 QVariant 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 
60 QHash<int, QByteArray> PathModel::roleNames() const
61 {
63  r.insert(PathSectionRole, "section");
64  r.insert(TurnDirectionRole, "turnDirection");
65  return r;
66 }
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
virtual QHash< int, QByteArray > roleNames() const const
bool isValid() const const
Definition: location.h:16
int row() const const
A path followed by any kind of location change.
Definition: path.h:88
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:05:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.