From b369ffacef33130dd47d4a844682fed2a4a3b8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 14 Sep 2016 22:37:12 +0200 Subject: [PATCH] Some more performance improvement magic --- src/gui.cpp | 3 +++ src/routeitem.cpp | 9 ++++++--- src/trackitem.cpp | 10 ++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index 4b8d6ebe..a4fa9749 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "config.h" #include "icons.h" #include "keys.h" @@ -90,6 +91,8 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent) _exportOrientation = QPrinter::Portrait; _exportFileName = QString("%1/export.pdf").arg(QDir::currentPath()); _exportMargins = MarginsF(5.0, 5.0, 5.0, 5.0); + + QPixmapCache::setCacheLimit(65536); } GUI::~GUI() diff --git a/src/routeitem.cpp b/src/routeitem.cpp index a5e97636..931628ed 100644 --- a/src/routeitem.cpp +++ b/src/routeitem.cpp @@ -26,6 +26,11 @@ void RouteItem::updateShape() QPainterPathStroker s; s.setWidth(HOVER_WIDTH * 1.0/scale()); _shape = s.createStroke(_path); + + if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768) + setCacheMode(QGraphicsItem::DeviceCoordinateCache); + else + setCacheMode(QGraphicsItem::NoCache); } RouteItem::RouteItem(const Route &route, QGraphicsItem *parent) @@ -53,7 +58,6 @@ RouteItem::RouteItem(const Route &route, QGraphicsItem *parent) setToolTip(toolTip()); setCursor(Qt::ArrowCursor); setAcceptHoverEvents(true); - setCacheMode(QGraphicsItem::DeviceCoordinateCache); updateShape(); @@ -74,8 +78,7 @@ void RouteItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawPath(_path); /* - QPen p = QPen(Qt::red); - p.setWidthF(1.0/scale()); + QPen p = QPen(QBrush(Qt::red), 0); painter->setPen(p); painter->drawRect(boundingRect()); */ diff --git a/src/trackitem.cpp b/src/trackitem.cpp index 24bedead..69166bc2 100644 --- a/src/trackitem.cpp +++ b/src/trackitem.cpp @@ -30,6 +30,11 @@ void TrackItem::updateShape() QPainterPathStroker s; s.setWidth(HOVER_WIDTH * 1.0/scale()); _shape = s.createStroke(_path); + + if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768) + setCacheMode(QGraphicsItem::DeviceCoordinateCache); + else + setCacheMode(QGraphicsItem::NoCache); } TrackItem::TrackItem(const Track &track, QGraphicsItem *parent) @@ -53,7 +58,6 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent) setToolTip(toolTip()); setCursor(Qt::ArrowCursor); setAcceptHoverEvents(true); - setCacheMode(QGraphicsItem::DeviceCoordinateCache); updateShape(); @@ -74,10 +78,8 @@ void TrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawPath(_path); /* - QPen p = QPen(Qt::red); - p.setWidthF(1.0/scale()); + QPen p = QPen(QBrush(Qt::red), 0); painter->setPen(p); - painter->setBrush(Qt::NoBrush); painter->drawRect(boundingRect()); */ }