6#include "RoutingProfilesModel.h"
8#include "PluginManager.h"
9#include "RoutingRunnerPlugin.h"
14RoutingProfilesModel::RoutingProfilesModel(
const PluginManager *pluginManager,
QObject *parent)
16 , m_pluginManager(pluginManager)
28 if (index.
row() >= m_profiles.count()) {
32 return m_profiles.at(index.
row()).name();
37int RoutingProfilesModel::rowCount(
const QModelIndex &parent)
const
42 return m_profiles.count();
45bool RoutingProfilesModel::removeRows(
int row,
int count,
const QModelIndex &parent)
50 if (row + count > m_profiles.count()) {
53 beginRemoveRows(parent, row, row + count);
54 for (
int i = 0; i < count; ++i) {
55 m_profiles.removeAt(row + i);
64 m_profiles = profiles;
73void RoutingProfilesModel::addProfile(
const QString &name)
75 beginInsertRows(
QModelIndex(), m_profiles.count(), m_profiles.count());
76 m_profiles << RoutingProfile(name);
80bool RoutingProfilesModel::moveUp(
int row)
85 if (row >= m_profiles.count()) {
92 m_profiles.swapItemsAt(row, row - 1);
97bool RoutingProfilesModel::moveDown(
int row)
99 return moveUp(row + 1);
102bool RoutingProfilesModel::setProfileName(
int row,
const QString &name)
107 if (row >= m_profiles.count()) {
110 m_profiles[row].setName(name);
111 Q_EMIT dataChanged(index(row, 0), index(row, 0));
120 if (row >= m_profiles.count()) {
123 m_profiles[row].pluginSettings() = pluginSettings;
127QString templateName(RoutingProfilesModel::ProfileTemplate profileTemplate)
129 switch (profileTemplate) {
130 case RoutingProfilesModel::CarFastestTemplate:
131 return RoutingProfilesModel::tr(
"Car (fastest)");
132 case RoutingProfilesModel::CarShortestTemplate:
133 return RoutingProfilesModel::tr(
"Car (shortest)");
134 case RoutingProfilesModel::CarEcologicalTemplate:
135 return RoutingProfilesModel::tr(
"Car (ecological)");
136 case RoutingProfilesModel::BicycleTemplate:
137 return RoutingProfilesModel::tr(
"Bicycle");
138 case RoutingProfilesModel::PedestrianTemplate:
139 return RoutingProfilesModel::tr(
"Pedestrian");
140 case RoutingProfilesModel::LastTemplate:
143 return RoutingProfilesModel::tr(
"Unknown");
146void RoutingProfilesModel::loadDefaultProfiles()
148 beginInsertRows(
QModelIndex(), m_profiles.count(), m_profiles.count() +
int(LastTemplate) - 1);
149 for (
int i = 0; i < LastTemplate; ++i) {
150 auto tpl =
static_cast<ProfileTemplate
>(i);
151 RoutingProfile profile(templateName(tpl));
152 bool profileSupportedByAtLeastOnePlugin =
false;
153 for (RoutingRunnerPlugin *plugin : m_pluginManager->routingRunnerPlugins()) {
154 if (plugin->supportsTemplate(tpl)) {
155 profileSupportedByAtLeastOnePlugin =
true;
159 if (!profileSupportedByAtLeastOnePlugin) {
162 for (RoutingRunnerPlugin *plugin : m_pluginManager->routingRunnerPlugins()) {
163 if (plugin->supportsTemplate(tpl)) {
164 profile.pluginSettings()[plugin->nameId()] = plugin->templateSettings(tpl);
169 case CarFastestTemplate:
170 case CarShortestTemplate:
171 case CarEcologicalTemplate:
172 profile.setTransportType(RoutingProfile::Motorcar);
174 case BicycleTemplate:
175 profile.setTransportType(RoutingProfile::Bicycle);
177 case PedestrianTemplate:
178 profile.setTransportType(RoutingProfile::Pedestrian);
181 Q_ASSERT(
false &&
"LastTemplate is an internal enum not to be used as a profile template");
185 m_profiles << profile;
192#include "moc_RoutingProfilesModel.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
bool isValid() const const
QModelIndex parent() const const