summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-08-27 15:57:04 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-08-27 16:11:32 (GMT)
commitfb24641f79c48609c6dcc879f55184447e4b23b7 (patch)
tree4744d5ed971e677c75ab5c559f904b87647609aa
parent56fcd260014ddcc7b9b62116bbd11bd8340d6c90 (diff)
Add GeoPainter::drawPolyline overload for linestrings without labels
almost all calls do not pass a label text, so avoid the extra argument objects and code overhead
-rw-r--r--src/lib/marble/GeoPainter.cpp40
-rw-r--r--src/lib/marble/GeoPainter.h13
2 files changed, 44 insertions, 9 deletions
diff --git a/src/lib/marble/GeoPainter.cpp b/src/lib/marble/GeoPainter.cpp
index d1b1087..2ba7dcd 100644
--- a/src/lib/marble/GeoPainter.cpp
+++ b/src/lib/marble/GeoPainter.cpp
@@ -551,6 +551,15 @@ void GeoPainter::drawPolyline ( const GeoDataLineString & lineString,
LabelPositionFlags labelPositionFlags,
const QColor& labelColor,const QFont& labelFont)
{
+ // no labels to draw?
+ // TODO: !labelColor.isValid() || labelColor.alpha() == 0 does not work,
+ // something injects invalid labelColor for city streets
+ if (labelText.isEmpty() || labelPositionFlags.testFlag(NoLabel) ||
+ labelColor == Qt::transparent) {
+ drawPolyline(lineString);
+ return;
+ }
+
// Immediately leave this method now if:
// - the object is not visible in the viewport or if
// - the size of the object is below the resolution of the viewport
@@ -565,12 +574,7 @@ void GeoPainter::drawPolyline ( const GeoDataLineString & lineString,
QVector<QPolygonF*> polygons;
d->m_viewport->screenCoordinates( lineString, polygons );
- if ( labelText.isEmpty() || labelPositionFlags.testFlag( NoLabel ) ) {
- foreach( QPolygonF* itPolygon, polygons ) {
- ClipPainter::drawPolyline( *itPolygon );
- }
- }
- else if ( labelPositionFlags.testFlag( FollowLine ) ) {
+ if (labelPositionFlags.testFlag(FollowLine)) {
const qreal maximumLabelFontSize = 20;
qreal fontSize = pen().widthF() * 0.45;
fontSize = qMin( fontSize, maximumLabelFontSize );
@@ -662,7 +666,7 @@ void GeoPainter::drawPolyline ( const GeoDataLineString & lineString,
foreach( QPolygonF* itPolygon, polygons ) {
labelNodes.clear();
ClipPainter::drawPolyline( *itPolygon, labelNodes, labelPositionFlags );
- if ( !labelNodes.isEmpty() && labelColor != Qt::transparent ) {
+ if (!labelNodes.isEmpty()) {
QPen const oldPen = pen();
setPen(labelColor);
foreach ( const QPointF& labelNode, labelNodes ) {
@@ -686,6 +690,28 @@ void GeoPainter::drawPolyline ( const GeoDataLineString & lineString,
}
+void GeoPainter::drawPolyline(const GeoDataLineString& lineString)
+{
+ // Immediately leave this method now if:
+ // - the object is not visible in the viewport or if
+ // - the size of the object is below the resolution of the viewport
+ if (!d->m_viewport->viewLatLonAltBox().intersects(lineString.latLonAltBox()) ||
+ !d->m_viewport->resolves(lineString.latLonAltBox())) {
+ // mDebug() << "LineString doesn't get displayed on the viewport";
+ return;
+ }
+
+ QVector<QPolygonF*> polygons;
+ d->m_viewport->screenCoordinates(lineString, polygons);
+
+ foreach(const QPolygonF* itPolygon, polygons) {
+ ClipPainter::drawPolyline(*itPolygon);
+ }
+
+ qDeleteAll(polygons);
+}
+
+
QRegion GeoPainter::regionFromPolyline ( const GeoDataLineString & lineString,
qreal strokeWidth ) const
{
diff --git a/src/lib/marble/GeoPainter.h b/src/lib/marble/GeoPainter.h
index 2e752af..6239c9e 100644
--- a/src/lib/marble/GeoPainter.h
+++ b/src/lib/marble/GeoPainter.h
@@ -305,7 +305,7 @@ class MARBLE_EXPORT GeoPainter : public ClipPainter
int margin = 0) const;
/*!
- \brief Draws a given line string (a "polyline").
+ \brief Draws a given line string (a "polyline") with a label.
The \a lineString is drawn using the current pen. It's possible to
provide a \a labelText for the \a lineString. The text is rendered using
@@ -316,10 +316,19 @@ class MARBLE_EXPORT GeoPainter : public ClipPainter
\see GeoDataLineString
*/
void drawPolyline ( const GeoDataLineString & lineString,
- const QString& labelText = QString(),
+ const QString& labelText,
LabelPositionFlags labelPositionFlags = LineCenter,
const QColor& labelcolor = Qt::black, const QFont& labelFont = QFont(QLatin1String("Arial")));
+/*!
+ \brief Draws a given line string (a "polyline").
+
+ The \a lineString is drawn using the current pen.
+
+ \see GeoDataLineString
+*/
+ void drawPolyline(const GeoDataLineString & lineString);
+
/*!
\brief Creates a region for a given line string (a "polyline").