Changeset View
Changeset View
Standalone View
Standalone View
src/lib/marble/declarative/RouteRelationModel.cpp
- This file was added.
1 | // | ||||
---|---|---|---|---|---|
2 | // This file is part of the Marble Virtual Globe. | ||||
3 | // | ||||
4 | // This program is free software licensed under the GNU LGPL. You can | ||||
5 | // find a copy of this license in LICENSE.txt in the top directory of | ||||
6 | // the source code. | ||||
7 | // | ||||
8 | // Copyright 2017 Sergey Popov <sergobot@protonmail.com> | ||||
9 | // | ||||
10 | | ||||
11 | #include "RouteRelationModel.h" | ||||
12 | | ||||
13 | namespace Marble { | ||||
14 | | ||||
15 | RouteRelationModel::RouteRelationModel(QObject *parent) : | ||||
16 | QAbstractListModel(parent) | ||||
17 | { | ||||
18 | // nothing to do | ||||
19 | } | ||||
20 | | ||||
21 | void RouteRelationModel::setRelations(const QVector<const Marble::GeoDataRelation*> &relations) | ||||
22 | { | ||||
23 | beginRemoveRows(QModelIndex(), 0, m_relations.count() - 1); | ||||
24 | m_relations.clear(); | ||||
25 | endRemoveRows(); | ||||
26 | | ||||
27 | beginInsertRows(QModelIndex(), 0, relations.count() - 1); | ||||
28 | m_relations = relations; | ||||
29 | endInsertRows(); | ||||
30 | } | ||||
31 | | ||||
32 | int RouteRelationModel::rowCount(const QModelIndex & parent) const | ||||
33 | { | ||||
34 | Q_UNUSED(parent); | ||||
35 | return m_relations.count(); | ||||
36 | } | ||||
37 | | ||||
38 | QVariant RouteRelationModel::data(const QModelIndex & index, int role) const | ||||
39 | { | ||||
40 | if (!index.isValid() || index.row() < 0 || index.row() >= m_relations.count()) | ||||
41 | return QVariant(); | ||||
42 | | ||||
43 | return m_relations.at(index.row())->name(); | ||||
44 | } | ||||
45 | | ||||
46 | QHash<int, QByteArray> RouteRelationModel::roleNames() const { | ||||
47 | QHash<int, QByteArray> roles; | ||||
48 | roles[RelationName] = "name"; | ||||
49 | return roles; | ||||
50 | } | ||||
51 | | ||||
52 | } |