This fixes the issue we were having for good. :)
From 10ad6d547df7a4be48e76a82d2b5eda139e1709a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Wed, 14 Jan 2015 12:52:23 -0200 Subject: [PATCH 1/2] Major speedup when mousemoving in the profile
After looking with great care at the result of the mouse movement at the profile, and also playing a bit with callgrind I'v found out that the only thing that we were doing it wrong was the way we looked at the items in the scene, by calling scene()->items with Qt::ItemIntersectsShape, our shapes are very complex curves with thousends of points and we have lots of them. and it usually doesn't matter because *most* of the time we are getting the tooltip information from 'get_plot_details_new', so no accessing to items was necessary. By changing the access from Qt::ItemIntersectsShape to Qt::IntersectsItemBoundingRect we had a speedup of almost 500x in a code that's very important, and the good thing, nothing bad happened because one of the only things that we are using this code is to get information from the events, not the curves. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/divetooltipitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index 78bdc71..7f76273 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -264,7 +264,7 @@ void ToolTipItem::refresh(const QPointF &pos) } free_buffer(&mb); - Q_FOREACH (QGraphicsItem *item, scene()->items(pos, Qt::IntersectsItemShape + Q_FOREACH (QGraphicsItem *item, scene()->items(pos, Qt::IntersectsItemBoundingRect ,Qt::DescendingOrder, scene()->views().first()->transform())) { if (!item->toolTip().isEmpty()) addToolTip(item->toolTip()); -- 2.2.2
From 79e0989a1214f2b1a76c09a4fa388311253fbe06 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Wed, 14 Jan 2015 13:02:18 -0200 Subject: [PATCH 2/2] Fix memory leak The QPainter and the QPixmap were being created but never freed, but a QPixmap and a QPainter doesn't need to be created by new, it can be safely created in the stack. So, create it on the stack, pass it via const-reference and use it correctly. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/divetooltipitem.cpp | 36 ++++++++++++++++++------------------ qt-ui/profile/divetooltipitem.h | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index 7f76273..dbef866 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -19,7 +19,7 @@ #include "display.h" #endif -void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap *pixmap) +void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap) { const IconMetrics& iconMetrics = defaultIconMetrics(); @@ -32,8 +32,8 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QP iconItem = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small), this); iconItem->setPos(iconMetrics.spacing, yValue); } else { - if (pixmap && !pixmap->isNull()) { - pixmapItem = new QGraphicsPixmapItem(*pixmap, this); + if (!pixmap.isNull()) { + pixmapItem = new QGraphicsPixmapItem(pixmap, this); pixmapItem->setPos(iconMetrics.spacing, yValue); } } @@ -232,8 +232,8 @@ void ToolTipItem::refresh(const QPointF &pos) { int i; struct plot_data *entry; - static QPixmap *tissues = new QPixmap(16,60); - static QPainter *painter = new QPainter(tissues); + static QPixmap tissues(16,60); + static QPainter painter(&tissues); int time = timeAxis->valueAt(pos); if (time == lastTime) return; @@ -244,21 +244,21 @@ void ToolTipItem::refresh(const QPointF &pos) entry = get_plot_details_new(&pInfo, time, &mb); if (entry) { - tissues->fill(); - painter->setPen(QColor(0, 0, 0, 0)); - painter->setBrush(QColor(LIMENADE1)); - painter->drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2); - painter->setBrush(QColor(SPRINGWOOD1)); - painter->drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2); - painter->setBrush(QColor("Red")); - painter->drawRect(0,0,16,10); - painter->setPen(QColor(0, 0, 0, 255)); - painter->drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2); - painter->drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2, + tissues.fill(); + painter.setPen(QColor(0, 0, 0, 0)); + painter.setBrush(QColor(LIMENADE1)); + painter.drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2); + painter.setBrush(QColor(SPRINGWOOD1)); + painter.drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2); + painter.setBrush(QColor(Qt::red)); + painter.drawRect(0,0,16,10); + painter.setPen(QColor(0, 0, 0, 255)); + painter.drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2); + painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2, 16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2); - painter->setPen(QColor(0, 0, 0, 127)); + painter.setPen(QColor(0, 0, 0, 127)); for (i=0; i<16; i++) { - painter->drawLine(i, 60, i, 60 - entry->percentages[i] / 2); + painter.drawLine(i, 60, i, 60 - entry->percentages[i] / 2); } addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues); } diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h index 51e8ecc..bb3ad84 100644 --- a/qt-ui/profile/divetooltipitem.h +++ b/qt-ui/profile/divetooltipitem.h @@ -34,7 +34,7 @@ public: void collapse(); void expand(); void clear(); - void addToolTip(const QString &toolTip, const QIcon &icon = QIcon(), const QPixmap *pixmap = NULL); + void addToolTip(const QString &toolTip, const QIcon &icon = QIcon(), const QPixmap &pixmap = QPixmap()); void refresh(const QPointF &pos); bool isExpanded() const; void persistPos(); -- 2.2.2
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
