libosmscout  1.1.1
QmlRoutingProfile.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_QMLROUTINGPROFILE_H
2 #define OSMSCOUT_CLIENT_QT_QMLROUTINGPROFILE_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2021 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
24 
25 #include <osmscout/OSMScoutTypes.h>
26 #include <osmscout/util/Distance.h>
28 #include <osmscout/TypeConfig.h>
29 
30 #include <QObject>
31 #include <QVariant>
32 
33 #include <cmath>
34 
35 namespace osmscout {
36 
43  Q_OBJECT
44  Q_PROPERTY(QmlVehicle vehicle READ getQmlVehicle WRITE setVehicle NOTIFY update)
45  Q_PROPERTY(double maxSpeed READ getMaxSpeed WRITE setMaxSpeed NOTIFY update)
46  Q_PROPERTY(QVariantMap speedTable READ getSpeedTable WRITE setSpeedTable NOTIFY update)
47 
48  Q_PROPERTY(bool applyJunctionPenalty READ getJunctionPenalty WRITE setJunctionPenalty NOTIFY update)
49  // meters
50  Q_PROPERTY(double penaltySameType READ getPenaltySameType WRITE setPenaltySameType NOTIFY update)
51  // meters
52  Q_PROPERTY(double penaltyDifferentType READ getPenaltyDifferentType WRITE setPenaltyDifferentType NOTIFY update)
53  // seconds
54  Q_PROPERTY(double maxPenalty READ getMaxPenalty WRITE setMaxPenalty NOTIFY update)
55 
56 public:
57  // enums fields exported to qml have to start with uppercase...
58  enum QmlVehicle: uint8_t
59  {
60  FootVehicle = Vehicle::vehicleFoot,
61  BicycleVehicle = Vehicle::vehicleBicycle,
62  CarVehicle = Vehicle::vehicleCar
63  };
64 
65  Q_ENUM(QmlVehicle);
66 
67 signals:
68  void update();
69 
70 public:
71  Q_INVOKABLE explicit QmlRoutingProfile(QObject *parent = nullptr);
72  explicit QmlRoutingProfile(Vehicle vehicle);
73  ~QmlRoutingProfile() override = default;
74 
76  QmlRoutingProfile& operator=(const QmlRoutingProfile& other);
77 
78  Vehicle getVehicle() const;
79  QmlVehicle getQmlVehicle() const;
80  void setVehicle(QmlVehicle vehicle);
81 
82  double getMaxSpeed() const;
83  void setMaxSpeed(double);
84 
85  QVariantMap getSpeedTable() const;
86  void setSpeedTable(const QVariantMap &);
87 
88  bool getJunctionPenalty() const;
89  void setJunctionPenalty(bool);
90 
91  double getPenaltySameType() const;
92  void setPenaltySameType(double);
93 
94  double getPenaltyDifferentType() const;
95  void setPenaltyDifferentType(double);
96 
97  double getMaxPenalty() const;
98  void setMaxPenalty(double);
99 
100  RoutingProfileRef MakeInstance(TypeConfigRef typeConfig) const;
101 
102 private:
103  void setDefaults();
104 
105 private:
106  QmlVehicle vehicle=QmlVehicle::CarVehicle;
107  double maxSpeed=160;
108  std::map<std::string,SpeedVariant> speedTable;
109  bool applyJunctionPenalty=true;
110  Distance costLimitDistance=Kilometers(20);
111  double costLimitFactor=7.5;
112  osmscout::Distance penaltySameType=Meters(160);
113  osmscout::Distance penaltyDifferentType=Meters(250);
114  std::chrono::seconds maxPenalty=std::chrono::seconds(10);
115 };
116 
117 using QmlRoutingProfileRef = std::shared_ptr<QmlRoutingProfile>;
118 
119 }
120 
121 Q_DECLARE_METATYPE(osmscout::QmlRoutingProfileRef)
122 
123 #endif //OSMSCOUT_CLIENT_QT_QMLROUTINGPROFILE_H
Definition: OSMScoutTypes.h:59
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
std::shared_ptr< RoutingProfile > RoutingProfileRef
Definition: RoutingProfile.h:171
Vehicle
Definition: OSMScoutTypes.h:55
QmlVehicle
Definition: QmlRoutingProfile.h:58
Distance Kilometers(double km)
Definition: Distance.h:362
std::shared_ptr< QmlRoutingProfile > QmlRoutingProfileRef
Definition: QmlRoutingProfile.h:117
Definition: OSMScoutTypes.h:57
Definition: Area.h:38
Definition: QmlRoutingProfile.h:42
Distance Meters(double m)
Definition: Distance.h:358
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227
Definition: OSMScoutTypes.h:58