[Marble-commits] KDE/kdeedu/marble/src/lib/routing
Dennis Nienhüser
earthwings at gentoo.org
Sun Mar 21 21:44:14 CET 2010
SVN commit 1106096 by nienhueser:
Routing preferences (car, bicycle, pedestrian, avoid highways / toll roads)
M +40 -6 OrsRoutingProvider.cpp
M +3 -8 OrsRoutingProvider.h
M +33 -0 RouteSkeleton.cpp
M +27 -0 RouteSkeleton.h
M +0 -1 RoutingInputWidget.cpp
M +36 -1 RoutingWidget.cpp
M +3 -0 RoutingWidget.h
M +90 -2 RoutingWidget.ui
--- trunk/KDE/kdeedu/marble/src/lib/routing/OrsRoutingProvider.cpp #1106095:1106096
@@ -37,7 +37,29 @@
GeoDataCoordinates destination = route->destination();
QString request = xmlHeader();
- request += requestHeader(Meter, Fastest);
+ QString unit = "KM";
+ QString preference = "Fastest";
+
+ switch (route->routePreference()) {
+ case RouteSkeleton::CarFastest:
+ unit = "KM";
+ preference = "Fastest";
+ break;
+ case RouteSkeleton::CarShortest:
+ unit = "KM";
+ preference = "Shortest";
+ break;
+ case RouteSkeleton::Bicycle:
+ unit = "M";
+ preference = "Bicycle";
+ break;
+ case RouteSkeleton::Pedestrian:
+ unit = "M";
+ preference = "Pedestrian";
+ break;
+ }
+
+ request += requestHeader(unit, preference);
request += requestPoint(StartPoint, source);
if (route->size() > 2) {
@@ -47,7 +69,7 @@
}
request += requestPoint(EndPoint, destination);
- request += requestFooter();
+ request += requestFooter(route->avoidFeatures());
request += xmlFooter();
//mDebug() << "POST: " << request;
@@ -85,15 +107,14 @@
return result.arg(MarbleLocale::languageCode());
}
-QString OrsRoutingProvider::requestHeader(DistanceUnit unit, Preference preference) const
+QString OrsRoutingProvider::requestHeader(const QString &unit, const QString &routePreference ) const
{
QString result = "<xls:Request methodName=\"RouteRequest\" requestID=\"123456789\" version=\"1.1\">\n";
result += "<xls:DetermineRouteRequest distanceUnit=\"%1\">\n";
result += "<xls:RoutePlan>\n";
result += "<xls:RoutePreference>%2</xls:RoutePreference>\n";
result += "<xls:WayPointList>\n";
- QString pref = preference == Fastest ? "Fastest" : preference == Shortest ? "Shortest" : "Pedestrian";
- return result.arg(unit == MilesFeet ? "M" : "KM").arg( pref );
+ return result.arg( unit ).arg( routePreference );
}
QString OrsRoutingProvider::requestPoint(PointType pointType, const GeoDataCoordinates &coordinates) const
@@ -112,9 +133,22 @@
return result;
}
-QString OrsRoutingProvider::requestFooter() const
+QString OrsRoutingProvider::requestFooter(RouteSkeleton::AvoidFeatures avoidFeatures) const
{
QString result = "</xls:WayPointList>\n";
+
+ if (avoidFeatures != RouteSkeleton::AvoidNone)
+ {
+ result += "<xls:AvoidList>\n"; {
+ if (avoidFeatures & RouteSkeleton::AvoidTollWay)
+ result += "<xls:AvoidFeature>Tollway</xls:AvoidFeature>";
+ }
+ if (avoidFeatures & RouteSkeleton::AvoidHighway) {
+ result += "<xls:AvoidFeature>Highway</xls:AvoidFeature>";
+ }
+ result += "</xls:AvoidList>\n";
+ }
+
result += "</xls:RoutePlan>\n";
result += "<xls:RouteInstructionsRequest provideGeometry=\"true\" />\n";
result += "<xls:RouteGeometryRequest/>\n";
--- trunk/KDE/kdeedu/marble/src/lib/routing/OrsRoutingProvider.h #1106095:1106096
@@ -12,6 +12,7 @@
#define ORS_ROUTING_PROVIDER_H
#include "AbstractRoutingProvider.h"
+#include "RouteSkeleton.h"
#include <QtNetwork/QNetworkReply>
@@ -27,12 +28,6 @@
{
Q_OBJECT
- enum Preference {
- Fastest,
- Shortest,
- Pedestrian
- };
-
enum PointType {
StartPoint,
ViaPoint,
@@ -58,13 +53,13 @@
QString xmlHeader() const;
/** Builds the route request header in the xml request. */
- QString requestHeader(DistanceUnit unit = Meter, Preference preference = Fastest ) const;
+ QString requestHeader(const QString &unit, const QString &routePreference ) const;
/** Builds a route point substring. */
QString requestPoint(PointType pointType, const GeoDataCoordinates &coordinates) const;
/** Builds the route request footer in the xml request. */
- QString requestFooter() const;
+ QString requestFooter( RouteSkeleton::AvoidFeatures avoidFeatures ) const;
/** Builds the xml request footer. */
QString xmlFooter() const;
--- trunk/KDE/kdeedu/marble/src/lib/routing/RouteSkeleton.cpp #1106095:1106096
@@ -25,10 +25,23 @@
QMap<int,QPixmap> m_pixmapCache;
+ RouteSkeleton::RoutePreference m_routePreference;
+
+ RouteSkeleton::AvoidFeatures m_avoidFeatures;
+
/** Determines a suitable index for inserting a via point */
int viaIndex(const GeoDataCoordinates &position) const;
+
+ RouteSkeletonPrivate();
};
+RouteSkeletonPrivate::RouteSkeletonPrivate() :
+ m_routePreference(RouteSkeleton::CarFastest),
+ m_avoidFeatures(RouteSkeleton::AvoidNone)
+{
+ // nothing to do
+}
+
int RouteSkeletonPrivate::viaIndex(const GeoDataCoordinates &position) const
{
/** @todo: Works, but does not look elegant at all */
@@ -182,6 +195,26 @@
}
}
+void RouteSkeleton::setAvoidFeatures(RouteSkeleton::AvoidFeatures features)
+{
+ d->m_avoidFeatures = features;
+}
+
+RouteSkeleton::AvoidFeatures RouteSkeleton::avoidFeatures() const
+{
+ return d->m_avoidFeatures;
+}
+
+void RouteSkeleton::setRoutePreference(RouteSkeleton::RoutePreference preference)
+{
+ d->m_routePreference = preference;
+}
+
+RouteSkeleton::RoutePreference RouteSkeleton::routePreference() const
+{
+ return d->m_routePreference;
+}
+
} // namespace Marble
#include "RouteSkeleton.moc"
--- trunk/KDE/kdeedu/marble/src/lib/routing/RouteSkeleton.h #1106095:1106096
@@ -14,6 +14,8 @@
#include "GeoDataCoordinates.h"
#include "GeoDataPlacemark.h"
+#include <QtCore/QFlags>
+
namespace Marble {
class RouteSkeletonPrivate;
@@ -28,6 +30,21 @@
Q_OBJECT
public:
+ enum RoutePreference {
+ CarFastest,
+ CarShortest,
+ Bicycle,
+ Pedestrian
+ };
+
+ enum AvoidFeature {
+ AvoidNone = 0x0,
+ AvoidHighway = 0x1,
+ AvoidTollWay = 0x2,
+ };
+
+ Q_DECLARE_FLAGS(AvoidFeatures, AvoidFeature)
+
/** Constructor */
explicit RouteSkeleton(QObject *parent = 0);
@@ -75,6 +92,14 @@
/** Returns a pixmap which indicates the position of the element */
QPixmap pixmap(int index) const;
+ void setAvoidFeatures(AvoidFeatures features);
+
+ AvoidFeatures avoidFeatures() const;
+
+ void setRoutePreference(RoutePreference preference);
+
+ RoutePreference routePreference() const;
+
Q_SIGNALS:
/** The value of the n-th element was changed */
void positionChanged(int index, const GeoDataCoordinates &position);
@@ -88,4 +113,6 @@
} // namespace Marble
+Q_DECLARE_OPERATORS_FOR_FLAGS(Marble::RouteSkeleton::AvoidFeatures)
+
#endif // MARBLE_ROUTE_SKELETON_H
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingInputWidget.cpp #1106095:1106096
@@ -236,7 +236,6 @@
void RoutingInputWidget::setSimple(bool simple)
{
d->m_removeButton->setVisible(!simple);
- d->m_stateButton->setVisible(!simple);
d->m_pickButton->setVisible(!simple);
}
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.cpp #1106095:1106096
@@ -88,6 +88,7 @@
m_inputWidgets[i]->setIndex(i);
}
+ m_ui.optionsLabel->setVisible(!simple);
adjustSearchButton();
}
@@ -165,8 +166,15 @@
this, SLOT( retrieveRoute ( ) ) );
connect( d->m_ui.moreLabel, SIGNAL(linkActivated(QString)),
this, SLOT(addInputWidget()));
+ connect( d->m_ui.optionsLabel, SIGNAL(linkActivated(QString)),
+ this, SLOT(toggleOptionsVisibility()));
addInputWidget(); // Need at least one input field
+ d->m_ui.routePreferenceComboBox->setVisible(false);
+ d->m_ui.highwaysCheckBox->setVisible(false);
+ d->m_ui.tollWaysCheckBox->setVisible(false);
+ d->m_ui.preferenceLabel->setVisible(false);
+ d->m_ui.avoidLabel->setVisible(false);
}
RoutingWidget::~RoutingWidget()
@@ -182,6 +190,23 @@
return;
}
+ int index = d->m_ui.routePreferenceComboBox->currentIndex();
+ RouteSkeleton::RoutePreference pref = RouteSkeleton::CarFastest;
+ if (index == 1)
+ pref = RouteSkeleton::CarShortest;
+ if (index == 2)
+ pref = RouteSkeleton::Bicycle;
+ if (index == 3)
+ pref = RouteSkeleton::Pedestrian;
+ RouteSkeleton::AvoidFeatures avoid = RouteSkeleton::AvoidNone;
+ if (d->m_ui.highwaysCheckBox->isChecked())
+ avoid |= RouteSkeleton::AvoidHighway;
+ if (d->m_ui.tollWaysCheckBox->isChecked())
+ avoid |= RouteSkeleton::AvoidTollWay;
+
+ d->m_routeSkeleton->setRoutePreference(pref);
+ d->m_routeSkeleton->setAvoidFeatures(avoid);
+
Q_ASSERT(d->m_routeSkeleton->size() == d->m_inputWidgets.size());
for (int i=0; i<d->m_inputWidgets.size(); ++i) {
RoutingInputWidget* widget = d->m_inputWidgets.at(i);
@@ -266,7 +291,7 @@
void RoutingWidget::addInputWidget()
{
- int index = d->m_ui.routingLayout->count()-2;
+ int index = d->m_ui.routingLayout->count()-3;
d->m_routeSkeleton->append(GeoDataCoordinates());
insertInputWidget(index);
}
@@ -363,6 +388,16 @@
}
}
+void RoutingWidget::toggleOptionsVisibility()
+{
+ bool visible = !d->m_ui.routePreferenceComboBox->isVisible();
+ d->m_ui.routePreferenceComboBox->setVisible(visible);
+ d->m_ui.highwaysCheckBox->setVisible(visible);
+ d->m_ui.tollWaysCheckBox->setVisible(visible);
+ d->m_ui.preferenceLabel->setVisible(visible);
+ d->m_ui.avoidLabel->setVisible(visible);
+}
+
} // namespace Marble
#include "RoutingWidget.moc"
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.h #1106095:1106096
@@ -86,6 +86,9 @@
/** The user canceled point selection from the map */
void pointSelectionCanceled();
+ /** Show or hide routing options */
+ void toggleOptionsVisibility();
+
private:
RoutingWidgetPrivate* const d;
};
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.ui #1106095:1106096
@@ -6,12 +6,83 @@
<rect>
<x>0</x>
<y>0</y>
- <width>312</width>
- <height>305</height>
+ <width>267</width>
+ <height>270</height>
</rect>
</property>
<layout class="QVBoxLayout" name="routingLayout">
<item>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::ExpandingFieldsGrow</enum>
+ </property>
+ <item row="1" column="1">
+ <widget class="QCheckBox" name="highwaysCheckBox">
+ <property name="toolTip">
+ <string>When checked, highways will be avoided in car routing</string>
+ </property>
+ <property name="text">
+ <string>Highways</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QCheckBox" name="tollWaysCheckBox">
+ <property name="toolTip">
+ <string>When checked, toll roads will be avoided</string>
+ </property>
+ <property name="text">
+ <string>Toll Roads</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="routePreferenceComboBox">
+ <item>
+ <property name="text">
+ <string>Car (fastest)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Car (shortest)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Bicycle</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Pedestrian</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="preferenceLabel">
+ <property name="text">
+ <string>Preference</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="avoidLabel">
+ <property name="text">
+ <string>Avoid</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="moreLabel">
@@ -44,6 +115,23 @@
</spacer>
</item>
<item>
+ <widget class="QLabel" name="optionsLabel">
+ <property name="toolTip">
+ <string>Show or hide routing options</string>
+ </property>
+ <property name="text">
+ <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+<html><head><meta name="qrichtext" content="1" /><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-family:'DejaVu Sans'; font-size:8pt; font-weight:400; font-style:normal;">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://edu.kde.org/marble"><span style=" text-decoration: underline; color:#0057ae;">Options</span></a></p></body></html></string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QPushButton" name="searchButton">
<property name="text">
<string>Search</string>
More information about the Marble-commits
mailing list