summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Rahn <rahn@kde.org>2016-11-11 18:14:14 (GMT)
committerTorsten Rahn <trahn@testo.de>2016-11-11 18:16:27 (GMT)
commit9d90adc92799eb12ade6280b7ec65caf7ba01cd1 (patch)
tree228624abfdf3daacd272f60ab9feb5a1393f5c1d
parente2091b15cebe0d7de5e4d1f8df25ef1c9112d58a (diff)
Refactoring of the Routing element:
QQuickPaintedItem -> QQuickItem This improves performance.
-rw-r--r--src/apps/marble-maps/MainScreen.qml2
-rw-r--r--src/lib/marble/declarative/Routing.cpp87
-rw-r--r--src/lib/marble/declarative/Routing.h11
3 files changed, 65 insertions, 35 deletions
diff --git a/src/apps/marble-maps/MainScreen.qml b/src/apps/marble-maps/MainScreen.qml
index e535909..a8f5590 100644
--- a/src/apps/marble-maps/MainScreen.qml
+++ b/src/apps/marble-maps/MainScreen.qml
@@ -119,7 +119,7 @@ ApplicationWindow {
anchors.fill: parent
marbleItem: marbleMaps
routingProfile: routeEditor.routingProfile
- visible: routeEditor.visible
+// visible: hasRoute // TODO: make this work
}
PositionMarker {
diff --git a/src/lib/marble/declarative/Routing.cpp b/src/lib/marble/declarative/Routing.cpp
index 0b5bb88..12fc7d0 100644
--- a/src/lib/marble/declarative/Routing.cpp
+++ b/src/lib/marble/declarative/Routing.cpp
@@ -25,8 +25,10 @@
#include <PositionTracking.h>
#include <QDebug>
-#include <QPainter>
#include <QQmlContext>
+#include <QOpenGLPaintDevice>
+#include <QSGGeometryNode>
+#include <QSGFlatColorMaterial>
namespace Marble {
@@ -44,6 +46,7 @@ public:
QObject * m_parent;
QVector<Placemark *> m_searchResultPlacemarks;
QMap<int, QQuickItem*> m_searchResultItems;
+ QVector<QPolygonF*> m_cachedPolygons;
};
RoutingPrivate::RoutingPrivate(QObject *parent) :
@@ -56,15 +59,16 @@ RoutingPrivate::RoutingPrivate(QObject *parent) :
}
Routing::Routing( QQuickItem *parent) :
- QQuickPaintedItem( parent ), d( new RoutingPrivate(this) )
+ QQuickItem( parent ), d( new RoutingPrivate(this) )
{
- setRenderTarget(QQuickPaintedItem::FramebufferObject);
+ setFlag(ItemHasContents, true);
d->m_routeRequestModel->setRouting(this);
connect(d->m_routeRequestModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(updateWaypointItems()));
connect(d->m_routeRequestModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(updateWaypointItems()));
connect(d->m_routeRequestModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(updateWaypointItems()));
emit routeRequestModelChanged(d->m_routeRequestModel);
+ update();
}
Routing::~Routing()
@@ -72,37 +76,64 @@ Routing::~Routing()
delete d;
}
-void Routing::paint(QPainter *painter)
-{
+QSGNode * Routing::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) {
if (!d->m_marbleMap) {
- return;
+ return 0;
}
- QPaintDevice *paintDevice = painter->device();
- painter->end();
- {
- Marble::GeoPainter geoPainter(paintDevice, d->m_marbleMap->viewport(), d->m_marbleMap->mapQuality());
-
- RoutingManager const * const routingManager = d->m_marbleMap->model()->routingManager();
- GeoDataLineString const waypoints = routingManager->routingModel()->route().path();
-
- int const dpi = qMax(paintDevice->logicalDpiX(), paintDevice->logicalDpiY());
- QPen standardRoutePen( routingManager->routeColorStandard().darker( 200 ) );
- qreal const width = 2.5 * MM2M * M2IN * dpi;
- standardRoutePen.setWidthF( width );
- geoPainter.setPen( standardRoutePen );
- geoPainter.drawPolyline( waypoints );
-
- standardRoutePen.setColor( routingManager->routeColorStandard() );
- standardRoutePen.setWidthF( width - 4.0 );
- if ( routingManager->state() == RoutingManager::Downloading ) {
- standardRoutePen.setStyle( Qt::DotLine );
+ QOpenGLPaintDevice paintDevice(QSize(width(), height()));
+ Marble::GeoPainter geoPainter(&paintDevice, d->m_marbleMap->viewport(), d->m_marbleMap->mapQuality());
+
+ RoutingManager const * const routingManager = d->m_marbleMap->model()->routingManager();
+ GeoDataLineString const waypoints = routingManager->routingModel()->route().path();
+
+ if (waypoints.isEmpty()) {
+ return 0;
+ }
+
+ int const dpi = qMax(paintDevice.logicalDpiX(), paintDevice.logicalDpiY());
+ qreal const width = 2.5 * MM2M * M2IN * dpi - 4;
+
+ QColor standardRouteColor = routingManager->state() == RoutingManager::Downloading ?
+ routingManager->routeColorStandard() :
+ routingManager->routeColorStandard().darker( 200 );
+
+ geoPainter.polygonsFromLineString( waypoints, d->m_cachedPolygons);
+
+ if (!d->m_cachedPolygons.isEmpty()) {
+ delete oldNode;
+ oldNode = new QSGNode;
+ QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
+ material->setColor(standardRouteColor);
+
+ foreach(const QPolygonF* itPolygon, d->m_cachedPolygons) {
+
+ int segmentCount = itPolygon->size() - 1;
+
+ QSGGeometryNode * lineNode = new QSGGeometryNode;
+
+ QSGGeometry * lineNodeGeo = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2*segmentCount);
+ lineNodeGeo->setLineWidth(width);
+ lineNodeGeo->setDrawingMode(GL_LINE_STRIP);
+ lineNodeGeo->allocate(2*segmentCount);
+
+ lineNode->setGeometry(lineNodeGeo);
+ lineNode->setFlag(QSGNode::OwnsGeometry);
+ lineNode->setMaterial(material);
+ lineNode->setFlag(QSGNode::OwnsMaterial);
+
+ for(int i = 0; i < segmentCount; ++i) {
+ lineNodeGeo->vertexDataAsPoint2D()[2*i].set(itPolygon->at(i).x(), itPolygon->at(i).y());
+ lineNodeGeo->vertexDataAsPoint2D()[2*i+1].set(itPolygon->at(i+1).x(), itPolygon->at(i+1).y());
+ }
+ oldNode->appendChildNode(lineNode);
}
- geoPainter.setPen( standardRoutePen );
- geoPainter.drawPolyline( waypoints );
}
- painter->begin(paintDevice);
+ qDeleteAll(d->m_cachedPolygons);
+ d->m_cachedPolygons.clear();
+
+ return oldNode;
}
QObject* Routing::waypointModel()
diff --git a/src/lib/marble/declarative/Routing.h b/src/lib/marble/declarative/Routing.h
index 24f5500..1e18ee2 100644
--- a/src/lib/marble/declarative/Routing.h
+++ b/src/lib/marble/declarative/Routing.h
@@ -11,7 +11,7 @@
#ifndef MARBLE_DECLARATIVE_ROUTING_H
#define MARBLE_DECLARATIVE_ROUTING_H
-#include <QQuickPaintedItem>
+#include <QQuickItem>
#include <Placemark.h>
#include <routing/RoutingModel.h>
@@ -22,7 +22,7 @@ namespace Marble {
class MarbleMap;
class RoutingPrivate;
-class Routing : public QQuickPaintedItem
+class Routing : public QQuickItem
{
Q_OBJECT
Q_PROPERTY( MarbleMap* marbleMap READ marbleMap WRITE setMarbleMap NOTIFY marbleMapChanged)
@@ -39,10 +39,6 @@ public:
~Routing();
- // Implements QQuickPaintedItem interface
- void paint(QPainter * painter);
-
-public:
void setMarbleMap( MarbleMap* marbleMap );
MarbleMap *marbleMap();
@@ -107,6 +103,9 @@ Q_SIGNALS:
void routeRequestModelChanged(RouteRequestModel* routeRequestModel);
+protected:
+ // Implements QQuickItem interface
+ QSGNode * updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);
private Q_SLOTS:
void updateWaypointItems();